Skip to content

Commit

Permalink
🧹 Tidy / Raw cases
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 21, 2024
1 parent b7a5915 commit e54d721
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
23 changes: 14 additions & 9 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
IETest:testCommandDepositETH() (gas: 188523)
IETest:testCommandSendETH() (gas: 71778)
IETest:testCommandSwapDAI() (gas: 169019)
IETest:testCommandSwapETH() (gas: 195733)
IETest:testCommandSwapForETH() (gas: 172378)
IETest:testCommandSwapUSDC() (gas: 203883)
IETest:testCommandSwapUSDCForWBTC() (gas: 204423)
IETest:testDeploy() (gas: 2775620)
IETest:testENSNameOwnership() (gas: 44476)
IETest:testCommandSendETHRawAddr() (gas: 99310)
IETest:testCommandStakeETH() (gas: 184104)
IETest:testCommandSwapDAI() (gas: 169036)
IETest:testCommandSwapETH() (gas: 165652)
IETest:testCommandSwapForETH() (gas: 172373)
IETest:testCommandSwapUSDC() (gas: 203905)
IETest:testCommandSwapUSDCForWBTC() (gas: 235400)
IETest:testCommandUnstakeETH() (gas: 312227)
IETest:testCommandWithdrawETH() (gas: 314737)
IETest:testDeploy() (gas: 2783837)
IETest:testENSNameOwnership() (gas: 44454)
IETest:testIENameSetting() (gas: 8208)
IETest:testPreviewCommandSendDecimals() (gas: 100925)
IETest:testPreviewCommandSendUSDC() (gas: 74300)
IETest:testPreviewCommandSendUSDC() (gas: 74278)
IETest:testPreviewSend() (gas: 53627)
IETest:testPreviewSendCommand() (gas: 64537)
IETest:testPreviewSendCommand() (gas: 64515)
NAMITest:testFailRegister() (gas: 9392)
NAMITest:testRegister() (gas: 55668)
6 changes: 3 additions & 3 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ contract IE {
(to, amount, token, callData, executeCallData) = previewSend(_to, _amount, _token);
} else if (
action == "swap" || action == "exchange" || action == "stake" || action == "deposit"
|| action == "withdraw"
|| action == "unstake" || action == "withdraw"
) {
(
string memory amountIn,
Expand Down Expand Up @@ -295,7 +295,7 @@ contract IE {
if (token == "weth") return WETH;
if (token == "wbtc" || token == "btc" || token == "bitcoin") return WBTC;
if (token == "wsteth" || token == "lido") return WSTETH;
if (token == "reth" || token == "rocket pool") return RETH;
if (token == "reth") return RETH;
}

/// ===================== COMMAND EXECUTION ===================== ///
Expand All @@ -309,7 +309,7 @@ contract IE {
send(to, amount, token);
} else if (
action == "swap" || action == "exchange" || action == "stake" || action == "deposit"
|| action == "withdraw"
|| action == "unstake" || action == "withdraw"
) {
(
string memory amountIn,
Expand Down
48 changes: 48 additions & 0 deletions test/IE.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,29 @@ contract IETest is Test {
assertEq(asset, DAI);
}

function testPreviewSendCommandRawAddr() public payable {
string memory command = "send 0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20 20 dai";
(address to, uint256 amount,, address asset,,) = ie.previewCommand(command);
assertEq(to, Z0R0Z_DOT_ETH);
assertEq(amount, 20 ether);
assertEq(asset, DAI);
}

function testPreviewSend() public payable {
(address to, uint256 amount, address asset,,) = ie.previewSend("z0r0z", "20", "dai");
assertEq(to, Z0R0Z_DOT_ETH);
assertEq(amount, 20 ether);
assertEq(asset, DAI);
}

function testPreviewSendRawAddr() public payable {
(address to, uint256 amount, address asset,,) =
ie.previewSend("0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20", "20", "dai");
assertEq(to, Z0R0Z_DOT_ETH);
assertEq(amount, 20 ether);
assertEq(asset, DAI);
}

function testPreviewCommandSendUSDC() public payable {
string memory command = "send z0r0z 20 usdc";
(address to, uint256 amount,, address asset,,) = ie.previewCommand(command);
Expand Down Expand Up @@ -108,11 +124,43 @@ contract IETest is Test {
ie.command{value: 1 ether}("send z0r0z 1 ETH");
}

function testCommandSendETHRawAddr() public payable {
ie.command{value: 1 ether}("send 0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20 1 ETH");
}

function testCommandSwapETH() public payable {
vm.prank(VITALIK_DOT_ETH); // Note: price might change in the future.
ie.command{value: 1 ether}("swap 1 eth for 2800 dai");
}

function testCommandStakeETH() public payable {
vm.prank(VITALIK_DOT_ETH);
ie.command{value: 1 ether}("stake 1 eth into lido");
}

function testCommandDepositETH() public payable {
vm.prank(VITALIK_DOT_ETH);
ie.command{value: 1 ether}("deposit 1 eth into reth");
}

function testCommandWithdrawETH() public payable {
vm.prank(VITALIK_DOT_ETH);
ie.command{value: 1 ether}("deposit 1 eth into reth");
vm.prank(VITALIK_DOT_ETH);
IERC20(RETH).approve(address(ie), 100 ether);
vm.prank(VITALIK_DOT_ETH);
ie.command("withdraw 0.8 reth into eth");
}

function testCommandUnstakeETH() public payable {
vm.prank(VITALIK_DOT_ETH);
ie.command{value: 1 ether}("stake 1 eth into reth");
vm.prank(VITALIK_DOT_ETH);
IERC20(RETH).approve(address(ie), 100 ether);
vm.prank(VITALIK_DOT_ETH);
ie.command("unstake 0.8 reth for eth");
}

function testCommandSwapForETH() public payable {
uint256 startBalETH = DAI_WHALE.balance;
uint256 startBalDAI = IERC20(DAI).balanceOf(DAI_WHALE);
Expand Down

0 comments on commit e54d721

Please sign in to comment.