TON-EVM token bridge - FunC smart contracts.
Bridge supports ERC-20-compatible tokens:
-
Bridge is not responsible for the unusual and unexpected internal functionality of ERC-20 tokens.
We can guarantee the correct operation of the bridge if
balanceOf,approve,transferandtransferFrommethods do what is expected. For exampletransfermethod must transfer tokens with the specified amount to the specified address.In the case that an ERC-20 token has unusual functionality, you need to contact the developers of that token to resolve the issues.
-
No more than (2^120 - 1) token units can be transferred to the TON network.
uint256is used for amounts in Ethereum, TON jettons usesVarUInteger 16 = Coinsfor amounts, maximum is2^120 - 1(124 bit in serialized form).Since in practice all useful tokens fit into this limit, we decided not to change the jettons.
-
0 <= Decimals <= 255
ERC-20 has
uint8decimals so all valid ERC-20 tokens are supported.
-
User calls
lockmethod on the EVM smart contract, indicating the address of the ERC-20 token, the token amount and destination TON address to receive jettons. -
EVM smart contract emits
Lockevent. -
export const MULTISIG_QUERY_TIMEOUT = 30 * 24 * 60 * 60; // 30 days const VERSION = 2; const timeout = evmTransaction.blockTime + MULTISIG_QUERY_TIMEOUT + VERSION; const queryId = timeout << 32 + first 32 bits of sha256(evmTransaction.blockHash + '_' + evmTransaction.transactionHash + '_' + evmTransaction.logIndex) -
User pays
bridgeMintFeein Toncoins by sendingop::pay_swaptojetton-bridgeTON smart contract with correspondingqueryId. -
Oracles detects new
Lockevent andswap_paidlog, check its validity and submits votes tomultisigTON smart contract with correspondingqueryId. -
When enough oracles votes are collected in the multisig, the multisig sends
op::execute_voting::swapmessage to thejetton-bridge. -
jetton-bridgecreates (if it doesn't already exist)jetton-mintersmart contract corresponding this ERC-20 token and fill-up user'sjetton-wallet.
-
User send
burnmessage to hisjetton-wallet, indicating the destination EVM address to receive ERC-20 tokens. -
jetton-walletsendsburn-notificationtojetton-minterandjetton-minterforward it tojetton-bridge. -
jetton-bridgeproduceburnlog on validburn-notification. -
Oracles detects new
burnlog, check its validity and submits EVM-signatures tovotes-collectorTON Smart Contract. -
When enough oracles signature are collected, user call
unlockmethod of the EVM smart contract, indicating these signatures, and get ERC-20 tokens.
Token bridge based on code of Toncoin Bridge and Standard Jetton.
Jettons:
-
dicovery-params.fc,op-codes.fc,params.fc,stdlib.fc,utils.fc- changes do not affect functionality. -
jetton-wallet.fc- same, butuint160 destination_address(destination address in EVM network) added incustom_payloadofburnmessage and toburn_notificationmessage.min_tons_for_storageandgas_consumptionconstants moved to config.3 additional
burnchecks:throw_if( error::operation_suspended, state_flags & 1);throw_unless(error::burn_fee_not_matched, msg_value == bridge_burn_fee);-bridge_burn_feemust include network fees ;throw_unless(error::not_enough_funds, jetton_amount > 0);- forbid zero burns; -
jetton-minter.fc- same withjetton-minter-discoverable.fcbut:-
no
admin_addressin data - admin isbridge_addressfrom network config -
mint - different mint message structure, sending fees deducted from message
-
burn_notificationwithcontentis forwarded to the jetton-bridge, no burn response message is sent -
no
change_admin,change_content -
get_jetton_dataconstructs semi-chain data in runtime -
provide_address_gas_consumptionandmin_tons_for_storageconstants moved to config
-
Bridge:
-
config.fc- similar, but additional fields added. -
multisig.fc- same, just another config, fixedget_messages_unsigned_by_idget-method, prevent send non-bounceable messages to bridge. -
votes-collector.fc- same, just another config and inability to remove old votes if config.state & 8