Last active
August 6, 2021 06:40
-
-
Save yihuang/f072e6d91d4845105b7698f52171053a to your computer and use it in GitHub Desktop.
some pseudocode to demonstrate interaction between evm contract and host system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract ERC20 { | |
map[address][uint256] _balances; | |
// deposit through native module | |
// native module will first move user's native tokens to contract address, | |
// then mint on evm directly | |
function deposit(receipient, amount) { | |
require(msg.sender == native_module_address) | |
_balances[receipient] += amount; | |
} | |
// withdraw to native token | |
function withdraw(amount) { | |
_balances[msg.sender] -= amount | |
emit CosmosNative("bank.send", msg.sender, amount) | |
} | |
// or send to ethereum through gravity bridge | |
function withdraw_to_eth(amount, eth_dest) { | |
_balances[msg.sender] -= amount | |
emit CosmosNative("gravity.send", msg.sender, amount, eth_dest) | |
} | |
} | |
contract ERC20Manager { | |
map[string][ERC20] _contracts | |
function deploy(denom) { | |
require(msg.sender == native_module_address) | |
if denom not in _contracts { | |
_contracts[denom] = new ERC20(); | |
} | |
} | |
function query(denom) address { | |
return _contracts[denom] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// native module logic | |
var erc20_manager_contract | |
func on_gravity_receive(receipent, amount, denom) { | |
erc20_manager_contract.deploy(denom) | |
contract = erc20_manager_contract.query(denom) | |
bank.SendFromAccountToAccount(receipent, contract, amount, denom); | |
contract.deposit(receipient, amount) | |
} |
for SendFromModuleToAccount, is it
minting native token
?
from where, funds are deducted?
Hmm, I think at this stage, the gravity already moved the native tokens to the receipent, so we actually need to move it from receipient
to contract
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for SendFromModuleToAccount, is it
minting native token
?from where, funds are deducted?