diff --git a/.gas-snapshot b/.gas-snapshot index 352b093..d01fc8a 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,22 +1,22 @@ -IETest:testCommandDepositETH() (gas: 164220) -IETest:testCommandSendETH() (gas: 77505) -IETest:testCommandSendETHRawAddr() (gas: 75196) -IETest:testCommandStakeETH() (gas: 146991) -IETest:testCommandSwapDAI() (gas: 138570) -IETest:testCommandSwapETH() (gas: 233185) -IETest:testCommandSwapForETH() (gas: 145463) -IETest:testCommandSwapUSDC() (gas: 171664) -IETest:testCommandSwapUSDCForWBTC() (gas: 196531) -IETest:testCommandUnstakeETH() (gas: 297247) -IETest:testCommandWithdrawETH() (gas: 299993) -IETest:testDeploy() (gas: 3669933) -IETest:testENSNameOwnership() (gas: 50652) +IETest:testCommandDepositETH() (gas: 155637) +IETest:testCommandSendETH() (gas: 77576) +IETest:testCommandSendETHRawAddr() (gas: 75267) +IETest:testCommandStakeETH() (gas: 147090) +IETest:testCommandSwapDAI() (gas: 168609) +IETest:testCommandSwapETH() (gas: 233248) +IETest:testCommandSwapForETH() (gas: 175502) +IETest:testCommandSwapUSDC() (gas: 171665) +IETest:testCommandSwapUSDCForWBTC() (gas: 196670) +IETest:testCommandUnstakeETH() (gas: 287967) +IETest:testCommandWithdrawETH() (gas: 290713) +IETest:testDeploy() (gas: 3703025) +IETest:testENSNameOwnership() (gas: 50674) IETest:testIENameSetting() (gas: 11118) -IETest:testPreviewCommandSendDecimals() (gas: 111274) -IETest:testPreviewCommandSendUSDC() (gas: 70021) +IETest:testPreviewCommandSendDecimals() (gas: 111416) +IETest:testPreviewCommandSendUSDC() (gas: 70092) IETest:testPreviewSend() (gas: 55972) -IETest:testPreviewSendCommand() (gas: 69547) -IETest:testPreviewSendCommandRawAddr() (gas: 66729) +IETest:testPreviewSendCommand() (gas: 69618) +IETest:testPreviewSendCommandRawAddr() (gas: 66800) IETest:testPreviewSendRawAddr() (gas: 29973) NAMITest:testFailRegister() (gas: 9532) NAMITest:testRegister() (gas: 59011) \ No newline at end of file diff --git a/docs/src/src/IE.sol/contract.IE.md b/docs/src/src/IE.sol/contract.IE.md index 8fa9c1b..f5eea24 100644 --- a/docs/src/src/IE.sol/contract.IE.md +++ b/docs/src/src/IE.sol/contract.IE.md @@ -1,5 +1,5 @@ # IE -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/IE.sol) **Author:** nani.eth (https://github.com/NaniDAO/ie) @@ -450,6 +450,20 @@ note: The function selector technically doesn't need to be `execute()` but param function translate(bytes calldata callData) public view virtual returns (string memory intent); ``` +### translateTokenTransfer + +*Translates the `intent` for `token` send action from the solution `tokenCalldata`. +note: Designed for EOAs and raw verification. Token alias is checked against storage.* + + +```solidity +function translateTokenTransfer(address token, bytes calldata tokenCalldata) + public + view + virtual + returns (string memory intent); +``` + ### translateUserOp *Translate ERC4337 userOp `callData` into readable send `intent`.* diff --git a/docs/src/src/IE.sol/interface.IExecutor.md b/docs/src/src/IE.sol/interface.IExecutor.md index 6a0c600..437c8b7 100644 --- a/docs/src/src/IE.sol/interface.IExecutor.md +++ b/docs/src/src/IE.sol/interface.IExecutor.md @@ -1,5 +1,5 @@ # IExecutor -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/IE.sol) Simple calldata executor interface. diff --git a/docs/src/src/IE.sol/interface.INAMI.md b/docs/src/src/IE.sol/interface.INAMI.md index c6541ce..8d11399 100644 --- a/docs/src/src/IE.sol/interface.INAMI.md +++ b/docs/src/src/IE.sol/interface.INAMI.md @@ -1,5 +1,5 @@ # INAMI -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/IE.sol) *Simple NAMI names interface for resolving L2 ENS ownership.* diff --git a/docs/src/src/IE.sol/interface.ISwapRouter.md b/docs/src/src/IE.sol/interface.ISwapRouter.md index f9f4492..bef63dc 100644 --- a/docs/src/src/IE.sol/interface.ISwapRouter.md +++ b/docs/src/src/IE.sol/interface.ISwapRouter.md @@ -1,5 +1,5 @@ # ISwapRouter -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/IE.sol) *Simple Uniswap V3 swapping interface.* diff --git a/docs/src/src/IE.sol/interface.IToken.md b/docs/src/src/IE.sol/interface.IToken.md index 4f4eb6c..2130254 100644 --- a/docs/src/src/IE.sol/interface.IToken.md +++ b/docs/src/src/IE.sol/interface.IToken.md @@ -1,5 +1,5 @@ # IToken -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/IE.sol) *Simple token transfer interface.* diff --git a/docs/src/src/NAMI.sol/contract.NAMI.md b/docs/src/src/NAMI.sol/contract.NAMI.md index 4f5f5a5..81a32ff 100644 --- a/docs/src/src/NAMI.sol/contract.NAMI.md +++ b/docs/src/src/NAMI.sol/contract.NAMI.md @@ -1,5 +1,5 @@ # NAMI -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/NAMI.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/NAMI.sol) **Author:** nani.eth (https://github.com/NaniDAO/ie) diff --git a/docs/src/src/NAMI.sol/interface.IToken.md b/docs/src/src/NAMI.sol/interface.IToken.md index 23f74e2..ca8862d 100644 --- a/docs/src/src/NAMI.sol/interface.IToken.md +++ b/docs/src/src/NAMI.sol/interface.IToken.md @@ -1,5 +1,5 @@ # IToken -[Git Source](https://github.com/NaniDAO/ie/blob/d47449524e79a44fee3444e5d49a8256f0cc4165/src/NAMI.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f14d7018eb9d8e0d134c41b44e0923f915c5a573/src/NAMI.sol) *Simple token balance & supply interface.* diff --git a/src/IE.sol b/src/IE.sol index 7fb6a91..77f30ea 100644 --- a/src/IE.sol +++ b/src/IE.sol @@ -586,6 +586,34 @@ contract IE { } } + /// @dev Translates the `intent` for `token` send action from the solution `tokenCalldata`. + /// note: Designed for EOAs and raw verification. Token alias is checked against storage. + function translateTokenTransfer(address token, bytes calldata tokenCalldata) + public + view + virtual + returns (string memory intent) + { + // The token calldata must be a call to the ERC20 `transfer()` method. + if (bytes4(tokenCalldata) != IToken.transfer.selector) revert InvalidSelector(); + + (string memory tokenAlias, uint256 decimals) = _returnTokenAliasConstants(token); + if (bytes(tokenAlias).length == 0) tokenAlias = aliases[token]; + if (decimals == 0) decimals = token.readDecimals(); // Sanity check. + (address target, uint256 value) = abi.decode(tokenCalldata[4:], (address, uint256)); + + return string( + abi.encodePacked( + "send ", + _toString(value / 10 ** decimals), + " ", + token, + " to 0x", + _toAsciiString(target) + ) + ); + } + /// @dev Translate ERC4337 userOp `callData` into readable send `intent`. function translateUserOp(UserOperation calldata userOp) public