This repository demonstrates sending ICA message from smart contract running on Cronos EVM to Crypto.org Chain.
It uses the precompile feature on Ethermint to enable smart contract interacting with Cosmos layer and uses the ICA middleware for contract notification via calling the callback methods. You can refer to the example contracts in ./hardhat/contracts folder for more details.
All the mnemonics and private keys used in this repository are considered NOT SAFE. Never use them other than this repository or you may lost your funds.
make init
make build
make start-network
Mnemonics: banner spread envelope side kite person disagree path silver will brother under couch edit food venture squirrel civil budget number acquire point work mass HD Path: m/44'/60'/0'/0/0 Address: 0xCdEf4A3e3350EE111f2c48030ee956483143E288 Public Key: 0x02f9373eb5a88fc021539e8f35d53cbd8d2abf5cbd399e9a77459857bae5050235 Private Key: 0xd5b31e2d217cdf224aa8ec8603125b91b4cf45939d4ec78ed4f33b81ea7fdea0
Refer to ./network/wallets.md for wallet details.
- Open https://remix.ethereum.org/
- Load the contract
./hardhat/contracts/Staking.sol
- Deploy with Wallet 1 with the following constructor arguments:
- CONNECTIONID_:
connection-0
- VALIDATORADDRESS_:
tcrocncl1qrcgju2vdr9w3hfh072g73khnzprfw9akrh75g
- BASECROREWARDRATE_:
10
- CONNECTIONID_:
On Remix, wait for 1 minute and call the method setup
with owner account. This method will revert if the Staking contract Interchain account is not registered yet.
If the last step is successful, the contract should now be associated with an account.
On Remix, call the view method getInterchainAccount
and you should see an tcro
-prefixed address.
-
On MetaMask, send 10000TCRO to the Staking contract
-
On Remix, verify the contract has the balance by calling the view method
balance
-
Run the following command, replace
${INTERCHAIN_ACCOUNT}
with the result from last step./cryptoorgchain/chain-maind --home=./data/cryptoorgchaindevnet-2 \ tx bank send \ tcro1yademsjml2m7zsjrn6hpwkug9eqv76k5dexhps \ ${INTERCHAIN_ACCOUNT} \ 100tcro \ --keyring-backend=test \ --chain-id=cryptoorgchaindevnet-2 -y
-
Verify the Staking contract Interchain Account has the balance by running
./cryptoorgchain/chain-maind --node=http://127.0.0.1:26657 \ query bank balances ${INTERCHAIN_ACCOUNT}
- Send 10TCRO a new Cronos wallet (named it User Wallet) with MetaMask.
- On Remix, call the view method
queryInterchainAccount
with User Wallet address. It should return an empty string. - On Remix, use the User Wallet to call the method
registerInterchainAccount
- On Remix, call the view method
queryInterchainAccount
with User Wallet address. It should now return the User Wallet Interchain account
-
Query the validator delegations before user stake by running
./cryptoorgchain/chain-maind --node=http://127.0.0.1:26657 \ query staking delegations-to tcrocncl1qrcgju2vdr9w3hfh072g73khnzprfw9akrh75g
-
Send 10TCRO a new Cronos wallet (named it User Wallet) with MetaMask
-
On Remix, use the User Wallet to call the method
stake
with the 1TCRO -
Wait for 1 minute, query the validator delegations again. You should see the contract Interchan account has delegated 1TCRO
./cryptoorgchain/chain-maind --node=http://127.0.0.1:26657 \ query staking delegations-to tcrocncl1qrcgju2vdr9w3hfh072g73khnzprfw9akrh75g
-
On Remix, call the view method
stakeOf
with the User Wallet address. You should see 1TCRO. You can also play around other view methods.
- On Remix, use the User Wallet to call the method
unstake
with the argument- uint256 amount:
100000000000000000
(0.1TCRO)
- uint256 amount:
- You should see the User Wallet is credited with 0.1TCRO + reward. The reward follows the simple interest formula:
Stake Amount * Reward Rate / 100 * (Current Block Height - Stake Height)
cd hardhat
npm i
npx hardhat watch compile
make init-network
make start-network
make stop-all
make start-all
All data will be gone. Please run it with caution.
make unsafe-clean-all
This repository is under MIT License