Skip to content

Commit

Permalink
refactor: crosschain bridge call (PundiAI#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulnut authored May 10, 2024
1 parent c0f4e53 commit e49f1eb
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 54 deletions.
2 changes: 1 addition & 1 deletion contract/FIP20Upgradable.go

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions contract/ICrossChain.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contract/WFXUpgradable.go

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions solidity/contracts/crosschain/CrossChainCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,25 @@ library Encode {

function bridgeCall(
string memory _dstChainId,
uint256 _gasLimit,
address _receiver,
address[] memory _tokens,
uint256[] memory _amounts,
address _to,
bytes calldata _message,
bytes memory _data,
uint256 _value,
bytes memory _asset
bytes memory _memo
) internal pure returns (bytes memory) {
return
abi.encodeWithSignature(
"bridgeCall(string,uint256,address,address,bytes,uint256,bytes)",
"bridgeCall(string,address,address[],uint256[],address,bytes,uint256,bytes)",
_dstChainId,
_gasLimit,
_receiver,
_tokens,
_amounts,
_to,
_message,
_data,
_value,
_asset
_memo
);
}
}
Expand Down Expand Up @@ -240,24 +242,26 @@ library CrossChainCall {

function bridgeCall(
string memory _dstChainId,
uint256 _gasLimit,
address _receiver,
address[] memory _tokens,
uint256[] memory _amounts,
address _to,
bytes calldata _message,
bytes memory _data,
uint256 _value,
bytes memory _asset
bytes memory _memo
) internal returns (bool) {
(bool result, bytes memory data) = CROSS_CHAIN_ADDRESS.call{
value: msg.value
}(
Encode.bridgeCall(
_dstChainId,
_gasLimit,
_receiver,
_tokens,
_amounts,
_to,
_message,
_data,
_value,
_asset
_memo
)
);
Decode.ok(result, data, "bridge call failed");
Expand Down
17 changes: 9 additions & 8 deletions solidity/contracts/crosschain/ICrossChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ interface ICrossChain {

function bridgeCall(
string memory _dstChain,
uint256 _gasLimit,
address _receiver,
address _to,
address[] memory _tokens,
uint256[] memory _amounts,
bytes calldata _message,
uint256 _value
address _to,
bytes memory _data,
uint256 _value,
bytes memory _memo
) external payable returns (bool _result);

event CrossChain(
Expand Down Expand Up @@ -79,12 +79,13 @@ interface ICrossChain {
address indexed _sender,
address indexed _receiver,
address indexed _to,
address _txOrigin,
uint256 _value,
uint256 _eventNonce,
string _dstChain,
uint256 _gasLimit,
uint256 _value,
bytes _message,
address[] _tokens,
uint256[] _amounts
uint256[] _amounts,
bytes _data,
bytes _memo
);
}
18 changes: 10 additions & 8 deletions solidity/contracts/test/CrossChainTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,25 @@ contract CrossChainTest {
}

function bridgeCall(
string memory _dstChainId,
uint256 _gasLimit,
string memory _dstChain,
address _receiver,
address[] memory _tokens,
uint256[] memory _amounts,
address _to,
bytes calldata _message,
bytes memory _data,
uint256 _value,
bytes memory _asset
bytes memory _memo
) internal returns (bool) {
return
CrossChainCall.bridgeCall(
_dstChainId,
_gasLimit,
_dstChain,
_receiver,
_tokens,
_amounts,
_to,
_message,
_data,
_value,
_asset
_memo
);
}
}
2 changes: 1 addition & 1 deletion tests/contract/CrossChainTest.go

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

0 comments on commit e49f1eb

Please sign in to comment.