User can create vault which stores PGCoin(CW20).
User can deposit their PGCoin(CW20) to vault.
- All coin deposits are recorded in amount and deposit time
# when you query vault info
data:
# all coins vault have
collected: "300"
# all deposits recoreded when you despoits coins to vault
# receive time is UNIX time nanos
ledger_list:
- coin_amount: "100"
# 22.12.16 08:04:16 GMT+00:00
receive_time: "1671177856257807410"
- coin_amount: "200"
# 22.12.16 08:21.33 GMT+00:00
receive_time: "1671178893141157818"
# vault owner
owner_addr: juno1sulm4ga8jgd73zs5q9wsumszu7ns6nkgxxvf3lUser can withdraw their PGCoin from vault in some condition.
Withdrawing can be executed after 1 minute of coin deposit.
coins to be withdrawn are determined in order of deposit.
- If you try to withdraw 200 coin from above vault at 22.12.16 08:06:00, it will fail
- If you try to withdraw 100 coin from above vault at 22.12.16 08:06:00, it will success
- If you try to withdraw 300 coin from above vault at 22.12.16 08:30:00, it will success
- If you try to withdraw 500 coin from above vault at 22.12.16 08:30:00, it will fail
network: Juno test network(uni-5)
code_id: 3420
address: juno1cx3rj8qpxtzd8efqgjfxd2xjq6d0j5te3y7amzurp8upgwnyk43q44zljq
network: Juno test network(uni-5)
address: juno1ka5p7mm8rfat7zs89xeegxyu9kxtljszckkdqfgv4e5x023c3hws7wjxaw
name: PGCoin
symbol: PGCoin
total_supply: 1000000000000
decimals: 6
you can modify contract command in sourceme.sh
source sourceme.shAfter you source the above variables, you should set the variables to junod
junod config chain-id $CHAIN_ID
junod config node $RPC# Get balance info for juno1sulm4ga8jgd73zs5q9wsumszu7ns6nkgxxvf3l
junod query wasm contract-state smart $COIN_CONTRACT "$QUERY_OWNER_BALANCE" $NODE
# Get Token Info
junod query wasm contract-state smart $COIN_CONTRACT "$QUERY_TOKEN_INFO" $NODEjunod tx wasm execute $VAULT_CONTRACT $CREATE $TXFLAG --from {account} # Send 200 cw20 token to "juno1sulm4ga8jgd73zs5q9wsumszu7ns6nkgxxvf3l" vault
junod tx wasm execute $COIN_CONTRACT $SEND_TO_VAULT $TXFLAG --from testAccount1If you want to modify msg, you should create binary message like below
// If cw20-vault contract receive cw20 token, cw20-vault contract transfer cw20 token to "juno1sulm4ga8jgd73zs5q9wsumszu7ns6nkgxxvf3l" vault
let binmsg = to_binary(&ReceiveMsg { vault_owner_addr: Addr::unchecked("juno1sulm4ga8jgd73zs5q9wsumszu7ns6nkgxxvf3l") }).unwrap();
println!("{}", binmsg);junod tx wasm execute $VAULT_CONTRACT $WITHDRAW $TXFLAG --from testAccount1# Get Vault of juno1sulm4ga8jgd73zs5q9wsumszu7ns6nkgxxvf3l
junod query wasm contract-state smart $VAULT_CONTRACT $QUERY_VAULT $NODEUnit test
cargo unit-testCompiling
cargo wasmOptimize for arm-64
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer-arm64:0.12.8
Please refer to the link below for help