cargo wasm
to build the smart contractcargo test
to run smart contract unit testscargo fmt
to fmt rust code
We want you to build a simple Sei smart contract that allows 1-to-2 transfer of the usei token.
Please create a Sei smart contract (using Cosmwasm 1.0) with the following requirements:
-
you should be able to instantiate the contract and set the owner. Code. Set owner in
InstantiateMsg
. Ifowner=None
, then assumeowner=info.sender
. -
you should support a read query to get the owner of the smart contract. Code. Load
CONFIG
and get theconfig.owner
value. One design choice I made here was to returnOwnerResponse
singleton struct instead of justAddr
. The reason was because other example contracts typically define a Response struct type so I wanted consistency across queries. -
you should support an execute message where an account can send coins to the contract and specify two accounts that can withdraw the coins (for simplicity, split coins evenly across the two destination accounts). Code. Validate that the caller only sent usei token to
execute(...)
. Then split the usei tokens sent between addr1 and addr2. If the amount is odd, give the extra token to addr1 (this edge case could be resolved many other ways - Eg. burn token or give the extra token to contract owner etc). -
you should store the withdrawable coins for every account who has non-zero coins in the contract. Code.
-
you should support an execute message where an account can withdraw some or all of its withdrawable coins. Code. If the caller sets
amount=?
, try to withdrawamount
. Otherwise, if the caller setsamount=None
, assume the caller is trying to withdraw the entire balance. During the execute, checkWALLETS
and updatekey=info.sender
based on how much the caller is trying to withdraw and error check accordingly. -
you should support a read query to get the withdrawable coins of any specified account. Code.
-
you should write unit tests for all of these scenarios (we should be able to run cargo test and all of the unit tests should pass). Code. The test naming and comments should indicate what each test case is testing for. The tests should cover both valid and invalid cases for each individual functionality.
Bonus
- Implement a fee structure for the transfer contract, where each send incurs fees that are collectable by the contract owner. Code. Allow the contract owner to define the
fee_percent
to be collected on initialization. Due to clunkiness ofcosmowasm_std::Decimal
and sincef64
is unserializable bydeps.storage
, assumed that fee_percent [0%-100%] granularity would suffice. Set defaultfee_percent=0
if contract owner putfee_percent=None
. Store the fees collected inWALLETS
atconfig.cw20_address
- defined on Instantiation. This allows us to leverageExecuteMsg::WithdrawCoins
to easily withdraw fees collected.
Resources