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 a7ee9e1 commit 597a3dc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 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: 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: 170308)
IETest:testCommandSwapUSDC50Percent() (gas: 155147)
IETest:testCommandSwapUSDCForWBTC() (gas: 192198)
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:testCommandSendDAIRawAddr() (gas: 74269)
IETest:testCommandSendDAIRawAddr100Percent() (gas: 78185)
IETest:testCommandSendDAIRawAddr5Percent() (gas: 102705)
IETest:testCommandSendETHRawAddr() (gas: 70257)
IETest:testCommandSendETHRawAddr100Percent() (gas: 75900)
IETest:testCommandSendETHRawAddr20PointOnePercent() (gas: 76756)
IETest:testCommandSendETHRawAddr50Percent() (gas: 75643)
IETest:testCommandSendETHRawAddr51PointOnePercent() (gas: 77416)
IETest:testCommandSendETHRawAddrPrecisePercent() (gas: 79648)
IETest:testCommandSendUSDCRawAddr() (gas: 91856)
IETest:testCommandSendUSDCRawAddr100Percent() (gas: 95371)
IETest:testCommandSendUSDCRawAddr50Percent() (gas: 120623)
IETest:testCommandStakeETH() (gas: 145671)
IETest:testCommandSwapAllETH() (gas: 147104)
IETest:testCommandSwapAllETHSend() (gas: 169101)
IETest:testCommandSwapDAI() (gas: 138684)
IETest:testCommandSwapDAI100Percent() (gas: 109845)
IETest:testCommandSwapDAI50Percent() (gas: 134909)
IETest:testCommandSwapDAIExactOut() (gas: 157206)
IETest:testCommandSwapDAIExactOutSendETH() (gas: 201891)
IETest:testCommandSwapDAIExactOutSendWETH() (gas: 200470)
IETest:testCommandSwapDAIMinOut() (gas: 159193)
IETest:testCommandSwapDAIMinOutAll() (gas: 8686961)
IETest:testCommandSwapDAIMinOutPercentage() (gas: 8687463)
IETest:testCommandSwapDAIPercentageExactOutSendUSDC() (gas: 206296)
IETest:testCommandSwapETH() (gas: 153548)
IETest:testCommandSwapForETH() (gas: 145655)
IETest:testCommandSwapUSDC() (gas: 168429)
IETest:testCommandSwapUSDC50Percent() (gas: 153492)
IETest:testCommandSwapUSDCForWBTC() (gas: 192521)
IETest:testDeploy() (gas: 3923895)
IETest:testFailCommandSendETHRawAddr1000Percent() (gas: 76740)
IETest:testPreviewCommandSendDecimals() (gas: 121286)
IETest:testPreviewCommandSendUSDC() (gas: 61575)
IETest:testPreviewSendAllCommandRawAddr() (gas: 122743)
IETest:testPreviewSendCommandRawAddr() (gas: 61405)
IETest:testTokenNameSetting() (gas: 12262)
IETest:testTranslateCommand() (gas: 10740)
IETest:testTranslateExecuteSend0_0_1ETH() (gas: 30053)
Expand Down
13 changes: 11 additions & 2 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -863,26 +863,35 @@ contract IE {

/// @dev Validate whether a given bytes string is a number or percentage.
function _isNumber(bytes memory s) internal pure virtual returns (bool) {
if (bytes32(s) == "all") return true;
uint256 len = s.length;
if (len == 0) return false;
if (len == 3 && s[0] == "a" && s[1] == "l" && s[2] == "l") return true;

// Early exit for single digit.
if (len == 1) return (s[0] >= 0x30 && s[0] <= 0x39);
if (s[0] < 0x30 || s[0] > 0x39) return false;

bool hasDecimal;
bool hasPercent;

unchecked {
for (uint256 i = 1; i != len; ++i) {
bytes1 currentByte = s[i];
if (currentByte == 0x2E) {
if (hasDecimal || hasPercent) return false;
// '.'
if (hasDecimal || hasPercent || i == len - 1) return false;
hasDecimal = true;
} else if (currentByte == 0x25) {
// '%'
if (hasPercent || i != len - 1) return false;
hasPercent = true;
} else if (currentByte < 0x30 || currentByte > 0x39) {
// '0'-'9'
return false;
}
}
}

return true;
}

Expand Down

0 comments on commit 597a3dc

Please sign in to comment.