Giter Site home page Giter Site logo

wrapped-ft's Introduction

Example with wNEAR on testnet

  • $CONTRACT_ID - the account ID of the new token fNEAR
  • $OWNER_ID - the account ID of the controller/owner.
  • wrap.testnet - the token ID that is being wrapped/locked. wNEAR is used for the example.
  • $ACCOUNT_ID - the account ID of a test account.

Init

near call $CONTRACT_ID --accountId=$OWNER_ID new '{
  "locked_token_account_id": "wrap.testnet",
  "meta": {"spec": "ft-1.0.0", "name": "Future NEAR", "symbol": "fNEAR", "decimals": 24},
  "owner_id": "'$OWNER_ID'"
}'

Wrap 20 NEAR into wNEAR (optional)

near call wrap.testnet --accountId=$OWNER_ID storage_deposit '' --amount=0.00125
near call wrap.testnet --accountId=$OWNER_ID near_deposit --amount=20

Storage deposit

near call wrap.testnet --accountId=$OWNER_ID storage_deposit '{"account_id": "'$CONTRACT_ID'"}' --amount=0.00125

Lock 10 wNEAR into fNEAR

near call wrap.testnet --accountId=$OWNER_ID --depositYocto=1 --gas=100000000000000 ft_transfer_call '{
  "receiver_id": "'$CONTRACT_ID'",
  "amount": "10000000000000000000000000",
  "msg": ""
}'

View methods

near view $CONTRACT_ID get_info
near view $CONTRACT_ID ft_metadata
near view $CONTRACT_ID ft_total_supply
near view $CONTRACT_ID ft_balance_of '{"account_id": "'$OWNER_ID'"}' 

Storage for the new account

near call $CONTRACT_ID --accountId=$ACCOUNT_ID storage_deposit '' --amount=0.00125

Transfer 1 fNEAR from the owner

near call $CONTRACT_ID --accountId=$OWNER_ID --depositYocto=1 ft_transfer '{
  "receiver_id": "'$ACCOUNT_ID'",
  "amount": "1000000000000000000000000"
}' 

Check balance

near view $CONTRACT_ID ft_balance_of '{"account_id": "'$OWNER_ID'"}' 
near view $CONTRACT_ID ft_balance_of '{"account_id": "'$ACCOUNT_ID'"}' 

Attempt to transfer back (should fail, because not whitelisted)

near call $CONTRACT_ID --accountId=$ACCOUNT_ID --depositYocto=1 ft_transfer '{
  "receiver_id": "'$OWNER_ID'",
  "amount": "1000000000000000000000000"
}' 

Expected error:

'Not whitelisted for transfers'

Attempt to unwrap (should fail, still locked)

near call $CONTRACT_ID --accountId=$ACCOUNT_ID --depositYocto=1 --gas=100000000000000 unwrap ''

Expected error:

'The token is still locked'

Whitelist transfers for the account

near call $CONTRACT_ID --accountId=$OWNER_ID --depositYocto=1 add_transfer_whitelist '{
  "account_id": "'$ACCOUNT_ID'"
}'

Transfer of 0.1 by the account to the owner

near call $CONTRACT_ID --accountId=$ACCOUNT_ID --depositYocto=1 ft_transfer '{
  "receiver_id": "'$OWNER_ID'",
  "amount": "100000000000000000000000"
}' 

Unlock the unwrapping by the owner

near call $CONTRACT_ID --accountId=$OWNER_ID --depositYocto=1 unlock ''

Attempt to unwrap the token (should fail, no wNEAR storage)

near call $CONTRACT_ID --accountId=$ACCOUNT_ID --depositYocto=1 --gas=100000000000000 unwrap ''

Expected error:

'The account is not registered'

Verify balances didn't change

near view $CONTRACT_ID ft_balance_of '{"account_id": "'$OWNER_ID'"}' 
near view $CONTRACT_ID ft_balance_of '{"account_id": "'$ACCOUNT_ID'"}' 

Storage deposit for wNEAR

near call wrap.testnet --accountId=$ACCOUNT_ID storage_deposit '' --amount=0.00125

Unwrap the token

near call $CONTRACT_ID --accountId=$ACCOUNT_ID --depositYocto=1 --gas=100000000000000 unwrap ''

Verify balances of the account for fNEAR and wNEAR

near view $CONTRACT_ID ft_balance_of '{"account_id": "'$ACCOUNT_ID'"}' 
near view wrap.testnet ft_balance_of '{"account_id": "'$ACCOUNT_ID'"}' 

wrapped-ft's People

Contributors

evgenykuzyakov avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dlpigpen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.