Skip to content

Commit

Permalink
add some more comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jun 19, 2024
1 parent 704382b commit 5e4766c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions contracts/prototypes/ERC20CustodyNew.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ contract ERC20CustodyNew {
gateway = Gateway(_gateway);
}

// Withdraw is called by TSS address, it directly transfers the tokens to the destination address without contract call
function withdraw(address token, address to, uint256 amount) external {
IERC20(token).transfer(to, amount);

emit Withdraw(token, to, amount);
}

// WithdrawAndCall is called by TSS address, it transfers the tokens and call a contract
// For this, it passes through the Gateway contract, it transfers the tokens to the Gateway contract and then calls the contract
function withdrawAndCall(address token, address to, uint256 amount, bytes calldata data) external {
// Transfer the tokens to the Gateway contract
IERC20(token).transfer(address(gateway), amount);
Expand Down
9 changes: 8 additions & 1 deletion contracts/prototypes/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ contract Gateway {
if (!success) {
revert ExecutionFailed();
}

return result;
}

// Called by the TSS
// Execution without ERC20 tokens, it is payable and can be used in the case of WithdrawAndCall for Gas ZRC20
// It can be also used for contract call without asset movement
function execute(address destination, bytes calldata data) external payable returns (bytes memory) {
bytes memory result = _execute(destination, data);

Expand All @@ -30,6 +33,10 @@ contract Gateway {
return result;
}

// Called by the ERC20Custody contract
// It call a function using ERC20 transfer
// Since the goal is to allow calling contract not designed for ZetaChain specifically, it uses ERC20 allowance system
// It provides allowance to destination contract and call destination contract. In the end, it remove remaining allowance and transfer remaining tokens back to the custody contract for security purposes
function executeWithERC20(
address token,
address to,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5e4766c

Please sign in to comment.