Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native token interface. #36

Closed
zie1ony opened this issue Aug 17, 2022 · 0 comments
Closed

Native token interface. #36

zie1ony opened this issue Aug 17, 2022 · 0 comments
Labels
feature Full feature description

Comments

@zie1ony
Copy link
Contributor

zie1ony commented Aug 17, 2022

Handle native token:

  • standard transfers,
  • passing tokens with contract calls when calling contract from the outside,
  • passing tokens with contract to contract call.
  • proper gas metering in tests that allows testing token transfers. The best would be zero-cost gas table.
  • #[odra(payable)] to mark entrypoint that accept tokens. (also in #[odra::external_contract]?).
  • TestEnv check of token.
  • Handle potential different types of integers for native tokens in backends (Casper has u512, Ethereum u256).

In test script.

let one = TestEnv::one_token();
TestEnv::with_tokens(1000 * one);
TestEnv::set_caller(user1);
contract.deposit();

assert_eq!(
    TestEnv::token_balance(user1),
    TestEnv::token_balance(contract.address())
)

In contract.

#[odra(init)]
#[odra(payable)]
pub fn start() {
    let caller = ContracEnv::caller();
    let contract_balance = ContracEnv::self_balance();
    let transfered_amount = ContracEnv::attached_value();
    let threshold = ContractEnv::one_token() * 100;
    if contract_balance > threshold {
        ContractEnv::transfer_tokens(caller, transfered_amount);
    } else {
        ContracEnv::with_tokens(contract_balance);
        AnotherContract::at(caller).do_something();
    }
}
@zie1ony zie1ony added the feature Full feature description label Aug 17, 2022
@zie1ony zie1ony added this to the Release 0.2.0 milestone Aug 17, 2022
@kpob kpob closed this as completed Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Full feature description
Projects
None yet
Development

No branches or pull requests

2 participants