-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gateway contract to make calls to external contracts (#72)
* Add jsonrpc call() method * Introduce the Gateway contract
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.8; | ||
|
||
import "./protocols/EthJsonRPC.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
contract Gateway { | ||
EthJsonRPC ethjsonrpc; | ||
address target; | ||
|
||
constructor(string memory _jsonrpc, address _target) { | ||
ethjsonrpc = new EthJsonRPC(_jsonrpc); | ||
target = _target; | ||
} | ||
|
||
fallback() external { | ||
bytes memory ret = ethjsonrpc.call(target, msg.data); | ||
|
||
assembly { | ||
let location := ret | ||
let length := mload(ret) | ||
return(add(location, 0x20), length) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.13; | ||
|
||
import "forge-std/Test.sol"; | ||
import "src/Gateway.sol"; | ||
import "src/Test.sol"; | ||
|
||
contract TestGateway is Test, SuaveEnabled { | ||
function testGateway() public { | ||
string memory endpoint = getEthJsonRPC(); | ||
Gateway gateway = new Gateway(endpoint, address(0x00000000219ab540356cBB839Cbe05303d7705Fa)); | ||
DepositContract depositContract = DepositContract(address(gateway)); | ||
|
||
bytes memory count = depositContract.get_deposit_count(); | ||
require(count.length > 0, "count is empty"); | ||
} | ||
|
||
function getEthJsonRPC() public returns (string memory) { | ||
try vm.envString("JSONRPC_ENDPOINT") returns (string memory endpoint) { | ||
return endpoint; | ||
} catch { | ||
vm.skip(true); | ||
} | ||
} | ||
} | ||
|
||
interface DepositContract { | ||
function get_deposit_count() external view returns (bytes memory); | ||
} |