Skip to content

Commit

Permalink
🔎 EOA helper
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed May 25, 2024
1 parent f14d701 commit 83941e8
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 24 deletions.
34 changes: 17 additions & 17 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 15 additions & 1 deletion docs/src/src/IE.sol/contract.IE.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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`.*
Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.IExecutor.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.INAMI.md
Original file line number Diff line number Diff line change
@@ -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.*

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.ISwapRouter.md
Original file line number Diff line number Diff line change
@@ -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.*

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.IToken.md
Original file line number Diff line number Diff line change
@@ -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.*

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/NAMI.sol/contract.NAMI.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/NAMI.sol/interface.IToken.md
Original file line number Diff line number Diff line change
@@ -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.*

Expand Down
28 changes: 28 additions & 0 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83941e8

Please sign in to comment.