-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dab0a6f
commit 48e36da
Showing
8 changed files
with
109 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/solady"] | ||
path = lib/solady | ||
url = https://github.com/Vectorized/solady |
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,3 @@ | ||
ds-test/=lib/solady/lib/ds-test/src/ | ||
forge-std/=lib/forge-std/src/ | ||
solady/=lib/solady/ |
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,2 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; |
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
import { LibString } from "lib/solady/src/Milady.sol"; | ||
|
||
contract ethers_sol { | ||
using LibString for *; | ||
|
||
function _request(string memory method) internal pure returns (string memory) { | ||
return string.concat( | ||
'await window.ethereum.request({"method": "', | ||
method, | ||
'","params": []});' | ||
); | ||
} | ||
|
||
function _request(string memory method, string memory params) internal pure returns (string memory) { | ||
return string.concat( | ||
'await window.ethereum.request({"method": "', | ||
method, | ||
'","params": [', | ||
params, | ||
']});' | ||
); | ||
} | ||
|
||
function _request(string memory _method, string memory _params, string memory _promise) internal pure returns (string memory) { | ||
return string.concat( | ||
'await window.ethereum.request({"method": "', | ||
_method, | ||
'","params": [', | ||
_params, | ||
']}).then(', | ||
_promise, | ||
');' | ||
); | ||
} | ||
|
||
function _request(string memory _method, string memory _params, string memory _promise, string memory _catch) internal pure returns (string memory) { | ||
return string.concat( | ||
'await window.ethereum.request({"method": "', | ||
_method, | ||
'","params": [', | ||
_params, | ||
']}).then(', | ||
_promise, | ||
').catch(', | ||
_catch, | ||
');' | ||
); | ||
} | ||
|
||
function eth_accounts() public pure returns (string memory) { | ||
return _request('eth_accounts'); | ||
} | ||
|
||
enum subscriptionType { logs, newHeads, newPendingTransactions, syncing } | ||
|
||
function _subscriptionTypeToString(subscriptionType _type) internal pure returns (string memory) { | ||
string memory _typeString; | ||
if(_type == subscriptionType.logs) { | ||
_typeString = '"logs"'; | ||
} else if(_type == subscriptionType.newHeads) { | ||
_typeString = '"newHeads"'; | ||
} else if(_type == subscriptionType.newPendingTransactions) { | ||
_typeString = '"newPendingTransactions"'; | ||
} else if(_type == subscriptionType.syncing) { | ||
_typeString = '"syncing"'; | ||
} | ||
return _typeString; | ||
} | ||
|
||
function eth_subscribe(subscriptionType _type) public pure returns (string memory) { | ||
return _request('eth_subscribe', string.concat(_subscriptionTypeToString(_type), ', null')); | ||
} | ||
|
||
function eth_subscribe(subscriptionType _type, address _address) public pure returns (string memory) { | ||
return _request('eth_subscribe', string.concat(_subscriptionTypeToString(_type), ',', _address.toHexString())); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import "forge-std/Test.sol"; | ||
import "src/ethers.sol"; | ||
|
||
contract ethersTest is Test { | ||
|
||
ethers_sol public ethers; | ||
|
||
function setUp() public { | ||
ethers = new ethers_sol(); | ||
} | ||
|
||
function test_eth_accounts() public { | ||
assertEq(ethers.eth_accounts(), 'await window.ethereum.request({"method": "eth_accounts","params": []});'); | ||
} | ||
|
||
} |