Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Aug 9, 2024
1 parent fa2bab7 commit 8636214
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
72 changes: 36 additions & 36 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
IETest:testCommandSendDAIRawAddr() (gas: 74309)
IETest:testCommandSendDAIRawAddr100Percent() (gas: 78235)
IETest:testCommandSendDAIRawAddr5Percent() (gas: 102755)
IETest:testCommandSendETHRawAddr() (gas: 70307)
IETest:testCommandSendETHRawAddr100Percent() (gas: 75950)
IETest:testCommandSendETHRawAddr20PointOnePercent() (gas: 76806)
IETest:testCommandSendETHRawAddr50Percent() (gas: 75693)
IETest:testCommandSendETHRawAddr51PointOnePercent() (gas: 77466)
IETest:testCommandSendETHRawAddrPrecisePercent() (gas: 79698)
IETest:testCommandSendUSDCRawAddr() (gas: 91906)
IETest:testCommandSendUSDCRawAddr100Percent() (gas: 95421)
IETest:testCommandSendUSDCRawAddr50Percent() (gas: 120673)
IETest:testCommandStakeETH() (gas: 146529)
IETest:testCommandSwapAllETH() (gas: 148585)
IETest:testCommandSwapAllETHSend() (gas: 172034)
IETest:testCommandSwapDAI() (gas: 130738)
IETest:testCommandSwapDAI100Percent() (gas: 111659)
IETest:testCommandSwapDAI50Percent() (gas: 136643)
IETest:testCommandSwapDAIExactOut() (gas: 156869)
IETest:testCommandSwapDAIExactOutSendETH() (gas: 202976)
IETest:testCommandSwapDAIExactOutSendWETH() (gas: 201585)
IETest:testCommandSwapDAIMinOut() (gas: 160172)
IETest:testCommandSwapDAIMinOutAll() (gas: 8687887)
IETest:testCommandSwapDAIMinOutPercentage() (gas: 8688512)
IETest:testCommandSwapDAIPercentageExactOutSendUSDC() (gas: 208510)
IETest:testCommandSwapETH() (gas: 184650)
IETest:testCommandSwapForETH() (gas: 137771)
IETest:testCommandSwapUSDC() (gas: 170458)
IETest:testCommandSwapUSDC50Percent() (gas: 155212)
IETest:testCommandSwapUSDCForWBTC() (gas: 192305)
IETest:testDeploy() (gas: 3917476)
IETest:testFailCommandSendETHRawAddr1000Percent() (gas: 76790)
IETest:testPreviewCommandSendDecimals() (gas: 121386)
IETest:testPreviewCommandSendUSDC() (gas: 61625)
IETest:testPreviewSendAllCommandRawAddr() (gas: 122657)
IETest:testPreviewSendCommandRawAddr() (gas: 61455)
IETest:testCommandSendDAIRawAddr() (gas: 74241)
IETest:testCommandSendDAIRawAddr100Percent() (gas: 78150)
IETest:testCommandSendDAIRawAddr5Percent() (gas: 102670)
IETest:testCommandSendETHRawAddr() (gas: 70222)
IETest:testCommandSendETHRawAddr100Percent() (gas: 75865)
IETest:testCommandSendETHRawAddr20PointOnePercent() (gas: 76721)
IETest:testCommandSendETHRawAddr50Percent() (gas: 75608)
IETest:testCommandSendETHRawAddr51PointOnePercent() (gas: 77381)
IETest:testCommandSendETHRawAddrPrecisePercent() (gas: 79613)
IETest:testCommandSendUSDCRawAddr() (gas: 91821)
IETest:testCommandSendUSDCRawAddr100Percent() (gas: 95336)
IETest:testCommandSendUSDCRawAddr50Percent() (gas: 120588)
IETest:testCommandStakeETH() (gas: 146444)
IETest:testCommandSwapAllETH() (gas: 148593)
IETest:testCommandSwapAllETHSend() (gas: 172042)
IETest:testCommandSwapDAI() (gas: 130653)
IETest:testCommandSwapDAI100Percent() (gas: 111574)
IETest:testCommandSwapDAI50Percent() (gas: 136558)
IETest:testCommandSwapDAIExactOut() (gas: 156784)
IETest:testCommandSwapDAIExactOutSendETH() (gas: 202891)
IETest:testCommandSwapDAIExactOutSendWETH() (gas: 201500)
IETest:testCommandSwapDAIMinOut() (gas: 160002)
IETest:testCommandSwapDAIMinOutAll() (gas: 8687810)
IETest:testCommandSwapDAIMinOutPercentage() (gas: 8688342)
IETest:testCommandSwapDAIPercentageExactOutSendUSDC() (gas: 208425)
IETest:testCommandSwapETH() (gas: 184480)
IETest:testCommandSwapForETH() (gas: 137703)
IETest:testCommandSwapUSDC() (gas: 170299)
IETest:testCommandSwapUSDC50Percent() (gas: 155138)
IETest:testCommandSwapUSDCForWBTC() (gas: 192200)
IETest:testDeploy() (gas: 3916665)
IETest:testFailCommandSendETHRawAddr1000Percent() (gas: 76705)
IETest:testPreviewCommandSendDecimals() (gas: 121216)
IETest:testPreviewCommandSendUSDC() (gas: 61540)
IETest:testPreviewSendAllCommandRawAddr() (gas: 122673)
IETest:testPreviewSendCommandRawAddr() (gas: 61370)
IETest:testTokenNameSetting() (gas: 12262)
IETest:testTranslateCommand() (gas: 10740)
IETest:testTranslateExecuteSend0_0_1ETH() (gas: 30053)
Expand Down
7 changes: 6 additions & 1 deletion src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -941,14 +941,17 @@ contract IE {
returns (uint256 result)
{
unchecked {
if (bytes32(s) == "all" || bytes32(s) == "100%") {
// Check for "all" or "100%" first.
bytes32 sBytes32 = bytes32(s);
if (sBytes32 == bytes32("all") || sBytes32 == bytes32("100%")) {
return token == ETH ? msg.sender.balance + msg.value : _balanceOf(token, msg.sender);
}

uint256 len = s.length;
bool hasDecimal;
uint256 decimalPlaces;
bool isPercentage;

for (uint256 i; i < len; ++i) {
bytes1 c = s[i];
if (c >= 0x30 && c <= 0x39) {
Expand All @@ -965,12 +968,14 @@ contract IE {
}
}

// Adjust for decimals.
if (!hasDecimal) {
result *= 10 ** decimals;
} else if (decimalPlaces < decimals) {
result *= 10 ** (decimals - decimalPlaces);
}

// Handle percentage.
if (isPercentage) {
uint256 balance =
token == ETH ? msg.sender.balance + msg.value : _balanceOf(token, msg.sender);
Expand Down

0 comments on commit 8636214

Please sign in to comment.