It consists of a CrossTrade-related proxy and logic contract in L1, and a CrossTrade-related proxy and logic contract in L2.
CrossTrade requests can be made in L2, and editing, canceling, and providing can only be done in L1.
One thing to note is that L1 cannot check the information in L2. So, when creating a transaction in L1, the hash value generated in L2 is also included and goes through a process to check whether the information entered in L1 is the correct value.
If you have already called the provideCT function, but the transaction failed in L2 and you paid in L1 but did not receive the money in L2, you can call the function in L2 again using reprovideCT.
And after providingCT is called, you cannot edit or cancel.
- L1CrossTradeProxy: 0x23DDf582c26Da5FDb7514aD22e7D74A369faD117
- L1CrossTrade: 0x26947c3dc054c5220fe3f999e2f9109eaea17e26
- L2CrossTradeProxy: 0xD6e99ec486Afc8ae26d36a6Ab6240D1e0ecf0271
- L2CrossTrade: 0xC597fE33d2066c9929a4AF3a0004f5ec55d39E06
- L1CrossTradeProx: 0x57BD88F20003185CB136f859e7724DD75910FD75
- L1CrossTrade : 0xA3139764F343f44A7809dA51DC3a34C3d94450d0
- L2CrossTradeProxy: 0x2270BF371160810DfE48777987De96E641952144
- L2CrossTrade: 0x656Cd3f9fe074a71Cb19707CDEd5e020F71db097
Store information about chainId (onlyOwner)
Parameters:
_crossDomainMessenger
: crossDomainMessenger address for chainId_l2CrossTrade
: L2CrossTradeProxy address for chainId_legacyERC20
: legacyERC20 address for chainId_l1legacyERC20
: l1legacyERC20 address for chainId_l2chainId
: store chainId
function chainInfo(
address _crossDomainMessenger,
address _l2CrossTrade,
address _legacyERC20,
address _l1legacyERC20,
uint256 _l2chainId
)
external
onlyOwner
Provides information that matches the hash value requested in L2
Parameters:
_l1token
: Address of requested l1token_l2token
: Address of requested l2token_to
: requester's address_totalAmount
: Total amount requested by l2_fwAmount
: The amount the requester wants to receive in l1_salecount
: Number generated upon request_l2chainId
: request requested chainId_minGasLimit
: minGasLimit_hash
: Hash value generated upon request
function provideCT(
address _l1token,
address _l2token,
address _to,
uint256 _totalAmount,
uint256 _fwAmount,
uint256 _salecount,
uint256 _l2chainId,
uint32 _minGasLimit,
bytes32 _hash
)
external
payable
nonReentrant
If provide is successful in L1 but the transaction fails in L2, this is a function that can recreate the transaction in L2.
Parameters:
_fwAmount
: The amount the requester wants to receive in l1_salecount
: Number generated upon request_l2chainId
: request requested chainId_minGasLimit
: minGasLimit_hash
: Hash value generated upon request
function reprovideCT(
uint256 _fwAmount,
uint256 _salecount,
uint256 _l2chainId,
uint32 _minGasLimit,
bytes32 _hash
)
external
nonReentrant
Cancels the request requested by the requester.
Parameters:
_l1token
: Address of requested l1token_l2token
: Address of requested l2token_totalAmount
: Total amount requested by l2_salecount
: Number generated upon request_l2chainId
: request requested chainId_minGasLimit
: minGasLimit_hash
: Hash value generated upon request
function cancel(
address _l1token,
address _l2token,
uint256 _totalAmount,
uint256 _salecount,
uint256 _l2chainId,
uint32 _minGasLimit,
bytes32 _hash
)
external
nonReentrant
If the cancel function succeeds in L1 but fails in L2, this function calls the transaction in L2 again.
Parameters:
_salecount
: Number generated upon request_l2chainId
: request requested chainId_minGasLimit
: minGasLimit_hash
: Hash value generated upon request
function resendCancel(
uint256 _salecount,
uint256 _l2chainId,
uint32 _minGasLimit,
bytes32 _hash
)
external
nonReentrant
This is a function that changes the value that the requester wants to receive.
Parameters:
_l1token
: Address of requested l1token_l2token
: Address of requested l2token_totalAmount
: Total amount requested by l2_fwAmount
: The amount the requester wants to receive in l1_salecount
: Number generated upon request_l2chainId
: request requested chainId_hash
: Hash value generated upon request
function edit(
address _l1token,
address _l2token,
uint256 _totalAmount,
uint256 _fwAmount,
uint256 _salecount,
uint256 _l2chainId,
bytes32 _hash
)
external
payable
nonReentrant
Create a Hash value and check if it matches the Hash value created upon request in L2.
Parameters:
_l1token
: Address of requested l1token_l2token
: Address of requested l2token_to
: This is the address of the request._totalAmount
: Total amount requested by l2_salecount
: Number generated upon request_l2chainId
: request requested chainId
function getHash(
address _l1token,
address _l2token,
address _to,
uint256 _totalAmount,
uint256 _saleCount,
uint256 _l2chainId
)
public
view
returns (bytes32)
This is a function that creates encodeWithSignature according to each function.
Parameters:
number
: A number that determines what type of function to createto
: This is the address of the request.amount
: The amount the requester wants to receive in l1saleCount
: Number generated upon requestbyteValue
: Hash value generated upon request_edit
: Check whether the edit function was executed
function makeEncodeWithSignature(
uint8 number,
address to,
uint256 amount,
uint256 saleCount,
bytes32 byteValue,
bool _edit
)
public
view
returns (bytes memory)
Function that returns the chainId of the current contract
Parameters:
_sender
: sender applying to provide_l1token
: l1token address applying to provide_fwAmount
: Amount provided
function _approve(
address _sender,
address _l1token,
uint256 _fwAmount
)
internal
view
L2CrossTrade initial settings (onlyOwner)
Parameters:
_crossDomainMessenger
: crossDomainMessenger address for chainId_legacyERC20
: legacyERC20 address for chainId
function initialize(
address _crossDomainMessenger,
address _legacyERC20
)
external
onlyOwner
Store addresses for chainId (onlyOwner)
Parameters:
_l1CrossTrade
: L1CrossTradeProxy address for chainId_l1legacyERC20
: l1legacyERC20 address for chainId_chainId
: store chainId
function chainInfo(
address _l1CrossTrade,
address _l1legacyERC20,
uint256 _chainId
)
external
onlyOwner
Register L1token and L2token and use them in requestRegisteredToken (onlyOwner)
Parameters:
_l1token
: l1token Address_l2token
: l2token Address_l1chainId
: store chainId
function registerToken(
address _l1token,
address _l2token,
uint256 _l1chainId
)
external
onlyOwner
Function to delete registered token (onlyOwner)
Parameters:
_l1token
: l1token Address_l2token
: l2token Address_l1chainId
: chainId of l1token
function deleteToken(
address _l1token,
address _l2token,
uint256 _l1chainId
)
external
onlyOwner
Token transaction request registered in register
Parameters:
_l2token
: l2token Address_totalAmount
: Amount provided to L2_fwAmount
: Amount to be received from L1_l1chainId
: chainId of l1token
function requestRegisteredToken(
address _l2token,
uint256 _totalAmount,
uint256 _fwAmount,
uint256 _l1chainId
)
external
payable
nonReentrant
Token transaction request not registered in register
Parameters:
_l1token
: l1token Address_l2token
: l2token Address_totalAmount
: Amount provided to L2_fwAmount
: Amount to be received from L1_l1chainId
: chainId of l1token
function requestNonRegisteredToken(
address _l2token,
uint256 _totalAmount,
uint256 _fwAmount,
uint256 _l1chainId
)
external
payable
nonReentrant
When providing a function called from L1, the amount is given to the provider.
Parameters:
_from
: provider Address_amount
: Amount paid by L1_saleCount
: Number generated upon request_chainId
: chainId of l1token_hash
: Hash value generated upon request_edit
: Whether edit was executed in L1
function claimCT(
address _from,
uint256 _amount,
uint256 _saleCount,
uint256 _chainId,
bytes32 _hash,
bool _edit
)
external
payable
nonReentrant
checkL1(_chainId)
providerCheck(_saleCount)
When canceling a function called from L1, the amount is given to the requester.
Parameters:
_msgSender
: Address where cancellation was requested_saleCount
: Number generated upon request_chainId
: chainId of l1token
function cancelCT(
address _msgSender,
uint256 _salecount,
uint256 _chainId
)
external
payable
nonReentrant
checkL1(_chainId)
providerCheck(_salecount)
Function that calculates hash value in L2CrossTradeContract
Parameters:
_l1token
: l1token Address_l2token
: l2token Address_to
: requester's address_totalAmount
: Amount provided to L2_saleCount
: Number generated upon request_l1chainId
: chainId of l1token
function getHash(
address _l1token,
address _l2token,
address _to,
uint256 _totalAmount,
uint256 _saleCount,
uint256 _l1chainId
)
public
view
returns (bytes32)
Function to calculate l1token, l2token register hash value
Parameters:
_l1token
: l1token Address_l2token
: l2token Address_l1chainId
: chainId of l1token
function getEnterHash(
address _l1token,
address _l2token,
uint256 _l1chainId
)
public
pure
returns (bytes32)
Function to check approve
Parameters:
_sender
: sender applying to provide_l1token
: l1token address applying to provide_fwAmount
: Amount provided
function _approve(
address _sender,
address _l1token,
uint256 _fwAmount
)
internal
view
Token transaction request not registered in register
Parameters:
_l1token
: l1token Address_l2token
: l2token Address_fwAmount
: Amount to be received from L1_totalAmount
: Amount provided to L2_saleCount
: Number generated upon request_l1chainId
: chainId of l1token
function _request(
address _l1token,
address _l2token,
uint256 _fwAmount,
uint256 _totalAmount,
uint256 _saleCount,
uint256 _l1chainId
)
internal
-
docker environment configuration
- git clone https://github.com/tokamak-network/tokamak-thanos/tree/OR-1257-Update-smart-contracts-for-deposit-TON-in-L1
- make build
- make devnet-up
- Check execution results
-
crossTrade Test
- git clone https://github.com/tokamak-network/crossTrade/tree/2nd_Audit
- npm install --force
- .env.example copy .env and setting
- update json
#tokamak-thanos git repository tokamak/contracts-bedrock/deployments folder copy #crossTrade git repository contracts-bedrock/deployments folder paste #tokamak-thanos git repository tokamak/contracts-bedrock/deployments/devnetL1/.deploy contents of the file copy #crossTrade git repository test/data/deployed.devnetL1.json contents of the file paste
- start the test
# get L1 ETH cast send --from 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 --rpc-url http://127.0.0.1:8545 --unlocked --value 9ether YOUR_PUBLICKEY cast send --from 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 --rpc-url http://127.0.0.1:8545 --unlocked --value 9ether YOUR_PUBLICKEY2 # run test # 0. request, provide, reprovide test npx hardhat test test/addTest/0.reprovideCrossTradeTest.ts --network devnetL1 # 1. request, edit, provide test npx hardhat test test/addTest/1.EditingCrossTradeTest.ts --network devnetL1 # 2. registerToken, requestEnterToken, provide, deleteToken test npx hardhat test test/addTest/2.MappingCrossTradeTest.ts --network devnetL1