diff --git a/.gas-snapshot b/.gas-snapshot index 5d47b59..c0fa0d3 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,19 +1,22 @@ -IETest:testBalanceInERC20() (gas: 49154) -IETest:testBalanceInETH() (gas: 40280) -IETest:testCommandSendERC0() (gas: 102922) -IETest:testCommandSendETH() (gas: 69404) -IETest:testCommandSendUSDC() (gas: 118552) -IETest:testCommandSwapDAI() (gas: 105526) -IETest:testCommandSwapETH() (gas: 119716) -IETest:testCommandSwapForETH() (gas: 123988) -IETest:testCommandSwapUSDC() (gas: 165762) -IETest:testCommandSwapUSDCForWBTC() (gas: 166485) -IETest:testDeploy() (gas: 2831664) -IETest:testENSNameOwnership() (gas: 83841) -IETest:testIENameSetting() (gas: 8142) -IETest:testPreviewCommandSendDecimals() (gas: 91938) -IETest:testPreviewCommandSendUSDC() (gas: 66075) -IETest:testPreviewSend() (gas: 42620) -IETest:testPreviewSendCommand() (gas: 54533) -IETest:testSendETH() (gas: 59642) -IETest:testTotalSupply() (gas: 14808) \ No newline at end of file +IETest:testCommandDepositETH() (gas: 155598) +IETest:testCommandSendETH() (gas: 75320) +IETest:testCommandSendETHRawAddr() (gas: 75755) +IETest:testCommandStakeETH() (gas: 147756) +IETest:testCommandSwapDAI() (gas: 138503) +IETest:testCommandSwapETH() (gas: 138209) +IETest:testCommandSwapForETH() (gas: 145404) +IETest:testCommandSwapUSDC() (gas: 171497) +IETest:testCommandSwapUSDCForWBTC() (gas: 196200) +IETest:testCommandUnstakeETH() (gas: 263506) +IETest:testCommandWithdrawETH() (gas: 266209) +IETest:testDeploy() (gas: 2563979) +IETest:testENSNameOwnership() (gas: 48424) +IETest:testIENameSetting() (gas: 11105) +IETest:testPreviewCommandSendDecimals() (gas: 108639) +IETest:testPreviewCommandSendUSDC() (gas: 67684) +IETest:testPreviewSend() (gas: 53800) +IETest:testPreviewSendCommand() (gas: 67248) +IETest:testPreviewSendCommandRawAddr() (gas: 67151) +IETest:testPreviewSendRawAddr() (gas: 30543) +NAMITest:testFailRegister() (gas: 9471) +NAMITest:testRegister() (gas: 58853) \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index eec29fd..0f07815 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ +[submodule "lib/forge-std"] + path = lib/forge-std + url = https://github.com/foundry-rs/forge-std [submodule "lib/solady"] path = lib/solady url = https://github.com/vectorized/solady -[submodule "lib/forge-std"] - path = lib/forge-std - url = https://github.com/foundry-rs/forge-std \ No newline at end of file diff --git a/README.md b/README.md index ecec0dd..7910b4a 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ -# [IE](https://github.com/NaniDAO/IE) [![License: AGPL-3.0-only](https://img.shields.io/badge/License-AGPL-black.svg)](https://opensource.org/license/agpl-v3/) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.24-black)](https://docs.soliditylang.org/en/v0.8.24/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml/badge.svg) +# [`IE`](https://github.com/NaniDAO/IE) [![License: AGPL-3.0-only](https://img.shields.io/badge/License-AGPL-black.svg)](https://opensource.org/license/agpl-v3/) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.25-black)](https://docs.soliditylang.org/en/v0.8.25/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml/badge.svg) -The **Intents Engine** (IE): A Basic *Text-to-tx* Simulator Contract. +The **Intents Engine** (`IE`): A Basic *Text-to-tx* Simulator Contract. -## Deployment +## Deployments -### IE V1 +### Mainnet -#### Ethereum Mainnet (L1) +`V1:` [`0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00`](https://etherscan.io/address/0x1e00000000cf8ba83e0005c59c1bf1c4682c8e00#code) -[`0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00`](https://etherscan.io/address/0x1e00000000cf8ba83e0005c59c1bf1c4682c8e00#code) +### Arbitrum -##### Deployed Bytecode +`V1.2:` [`0x1e00003a669bb466d6B49800000099E1abDD6600`](https://arbiscan.io/address/0x1e00003a669bb466d6b49800000099e1abdd6600#code) -[`QmZVdxJyTCJBF7gfE5BrSavCHtMDScZjpLYH5qaMExhW49`](https://content.wrappr.wtf/ipfs/QmZVdxJyTCJBF7gfE5BrSavCHtMDScZjpLYH5qaMExhW49) +`Note:` L2 will be used to rapidly prototype a stable and sufficient `IE` for common crypto commands. Many dev resources here will cater to the current L2 prototype until the release of `V2` on L1. ## Uses @@ -22,13 +22,13 @@ From natural language: - Security checkpoint (forbid tx) - Command translation (make tx) -IE should deterministically and transparently operate to provide these utilities in an uncensorable medium like a Solidity smart contract. +`IE` should deterministically and transparently operate to provide these utilities in an uncensorable medium like a Solidity smart contract. [`V1`](./src/IE.sol) is a POC of this. [*Short demo and explainer thread on X.*](https://x.com/z0r0zzz/status/1758392014737920209?s=20) ## Command Syntax (⌘) -IE is approaching things from first-principles and a "show" rather than "tell" approach. There will be some experimentation. +`IE` is approaching things from first-principles and a "show" rather than "tell" approach. There will be some experimentation. Some things in `V1` are likely very underoptimized for this particular use case. @@ -72,21 +72,21 @@ aliases: *exchange* aliases: *exchange* -Note: In `V1.1` on Arbitrum, a `minOutputAmount` can be specified for swaps. It ensures that you receive a minimum output amount of `object` at the end of the swap, otherwise the transaction will revert. The default value is set to `0`. +`Note:` In `V1.2` on Arbitrum, a `minOutputAmount` can be specified for swaps. It ensures that you receive a minimum output amount of `object` at the end of the swap, otherwise the transaction will revert. The default value is set to `0`. ------------------------------------ -Phrases are provided in the order in which they are most expected. They are "naturalized" to lower case. The IE contract automatically does this, but front-ends should nonetheless try and format as close as possible (*i.e.*, through a simple LLM trained or prompted on these examples below). +Phrases are provided in the order in which they are most expected. They are "naturalized" to lower case. The `IE` contract automatically does this, but front-ends should nonetheless try and format as close as possible (*i.e.*, through a simple LLM trained or prompted on these examples below). -In terms of usual English, we assume the subject of each command is the user account which is more explicit in the case of checking an ERC4337 userOp (where `sender` is the user). And the `object` receives assets or contract calls. `value` is the token or ETH amount involved in the action and the `asset` is the particular item sent or issued from (initially ETH or ERC20 to cover fungibles and most immediate security needs that could benefit from IE). +In terms of usual English, we assume the subject of each command is the user account which is more explicit in the case of checking an ERC4337 userOp (where `sender` is the user). And the `object` receives assets or contract calls. `value` is the token or ETH amount involved in the action and the `asset` is the particular item sent or issued from (initially ETH or ERC20 to cover fungibles and most immediate security needs that could benefit from `IE`). -You MUST include spaces in the string provided to IE in order for it to understand word separation. +You **MUST** include spaces in the string provided to `IE` in order for it to understand word separation. -Note: `to/for` is an identified filler word common to most of the transactions we will cover so it is highlighted. +`Note:` `to/for` is an identified filler word common to most of the transactions we will cover so it is highlighted. As you might notice, there are patterns. Because after all this is typical language and logic we are talking about here. For example, `value` will precede `asset`. `object` will either follow the `action` or be at the end. If at the end, there will be a filler of `for/to`. (Yeah I know this is what people learn in grammar schools but the exercise will likely yield good results.) -Also, let's try and be as helpful as possible at the top of the command funnel. E.g., if there is `msg.value` in a command, then we should assume ETH is involved. +Also, let's try and be as helpful as possible at the top of the command funnel. *E.g.*, if there is `msg.value` in a command, then we should assume ETH is involved. Actions should also have aliases to catch more cases. Though it will be cheaper to use the primary word (for example, 'send' or 'swap' with preference to familiarity, and if there indecision, the shorter), it is helpful to do more and catch different ways of phrasing transactional commands, like "send" can equate to "transfer" when it comes to onchain assets. Adhering to Solidity and smart contract functions themselves in word choice makes the most sense as well (*e.g.*, ETH.*send*/*transfer*, IERC20.*transfer*, UNI.*swap*, CURVE.*exchange*). @@ -96,7 +96,7 @@ Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundry Build the foundry project with `forge build`. Run tests with `forge test`. Measure gas with `forge snapshot`. Format with `forge fmt`. -*Note:* Tests currently run on a fork of mainnet to check ENS properly. +`Note:` Tests currently run on a virtual blockchain fork to check ENS properly. ## Blueprint diff --git a/abi/DeploymentV1.json b/abi/DeploymentV1.json deleted file mode 100644 index 23d0bf4..0000000 --- a/abi/DeploymentV1.json +++ /dev/null @@ -1,539 +0,0 @@ -{ - "contracts": [ - { - "name": "IE", - "address": "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00", - "version": "1.0.0", - "abi": [ - { - "type": "constructor", - "inputs": [], - "stateMutability": "payable" - }, - { - "type": "fallback", - "stateMutability": "payable" - }, - { - "type": "receive", - "stateMutability": "payable" - }, - { - "type": "function", - "name": "checkPackedUserOp", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - }, - { - "name": "userOp", - "type": "tuple", - "internalType": "struct IE.PackedUserOperation", - "components": [ - { - "name": "sender", - "type": "address", - "internalType": "address" - }, - { - "name": "nonce", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "initCode", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "accountGasLimits", - "type": "bytes32", - "internalType": "bytes32" - }, - { - "name": "preVerificationGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "gasFees", - "type": "bytes32", - "internalType": "bytes32" - }, - { - "name": "paymasterAndData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "signature", - "type": "bytes", - "internalType": "bytes" - } - ] - } - ], - "outputs": [ - { - "name": "", - "type": "bool", - "internalType": "bool" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "checkUserOp", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - }, - { - "name": "userOp", - "type": "tuple", - "internalType": "struct IE.UserOperation", - "components": [ - { - "name": "sender", - "type": "address", - "internalType": "address" - }, - { - "name": "nonce", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "initCode", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "callGasLimit", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "verificationGasLimit", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "preVerificationGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "maxFeePerGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "maxPriorityFeePerGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "paymasterAndData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "signature", - "type": "bytes", - "internalType": "bytes" - } - ] - } - ], - "outputs": [ - { - "name": "", - "type": "bool", - "internalType": "bool" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "command", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "previewCommand", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "to", - "type": "address", - "internalType": "address" - }, - { - "name": "amount", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "token", - "type": "address", - "internalType": "address" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "executeCallData", - "type": "bytes", - "internalType": "bytes" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "previewSend", - "inputs": [ - { - "name": "to", - "type": "string", - "internalType": "string" - }, - { - "name": "amount", - "type": "string", - "internalType": "string" - }, - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "_to", - "type": "address", - "internalType": "address" - }, - { - "name": "_amount", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "_token", - "type": "address", - "internalType": "address" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "executeCallData", - "type": "bytes", - "internalType": "bytes" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "previewSwap", - "inputs": [ - { - "name": "amountIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenOut", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "_amountIn", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "_tokenIn", - "type": "address", - "internalType": "address" - }, - { - "name": "_tokenOut", - "type": "address", - "internalType": "address" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "send", - "inputs": [ - { - "name": "to", - "type": "string", - "internalType": "string" - }, - { - "name": "amount", - "type": "string", - "internalType": "string" - }, - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "setName", - "inputs": [ - { - "name": "token", - "type": "address", - "internalType": "address" - }, - { - "name": "name", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "setNameAndTicker", - "inputs": [ - { - "name": "token", - "type": "address", - "internalType": "address" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "swap", - "inputs": [ - { - "name": "amountIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenOut", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "tokens", - "inputs": [ - { - "name": "name", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "", - "type": "address", - "internalType": "address" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "whatIsTheAddressOf", - "inputs": [ - { - "name": "name", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "owner", - "type": "address", - "internalType": "address" - }, - { - "name": "receiver", - "type": "address", - "internalType": "address" - }, - { - "name": "node", - "type": "bytes32", - "internalType": "bytes32" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "whatIsTheBalanceOf", - "inputs": [ - { - "name": "name", - "type": "string", - "internalType": "string" - }, - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "balance", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "balanceAdjusted", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "whatIsTheTotalSupplyOf", - "inputs": [ - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "supply", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "supplyAdjusted", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "view" - }, - { - "type": "event", - "name": "NameSet", - "inputs": [ - { - "name": "token", - "type": "address", - "indexed": true, - "internalType": "address" - }, - { - "name": "name", - "type": "string", - "indexed": false, - "internalType": "string" - } - ], - "anonymous": false - }, - { - "type": "error", - "name": "InvalidCharacter", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidSwap", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidSyntax", - "inputs": [] - }, - { - "type": "error", - "name": "Overflow", - "inputs": [] - }, - { - "type": "error", - "name": "Unauthorized", - "inputs": [] - } - ] - } - ] - } - \ No newline at end of file diff --git a/abi/IE.json b/abi/IE.json index 10b8ccc..da2aad5 100644 --- a/abi/IE.json +++ b/abi/IE.json @@ -1,529 +1,621 @@ [ - { - "type": "constructor", - "inputs": [], - "stateMutability": "payable" - }, - { - "type": "fallback", - "stateMutability": "payable" - }, - { - "type": "receive", - "stateMutability": "payable" - }, - { - "type": "function", - "name": "checkPackedUserOp", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - }, - { - "name": "userOp", - "type": "tuple", - "internalType": "struct IE.PackedUserOperation", - "components": [ - { - "name": "sender", - "type": "address", - "internalType": "address" - }, - { - "name": "nonce", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "initCode", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "accountGasLimits", - "type": "bytes32", - "internalType": "bytes32" - }, - { - "name": "preVerificationGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "gasFees", - "type": "bytes32", - "internalType": "bytes32" - }, - { - "name": "paymasterAndData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "signature", - "type": "bytes", - "internalType": "bytes" - } - ] - } - ], - "outputs": [ - { - "name": "", - "type": "bool", - "internalType": "bool" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "checkUserOp", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - }, - { - "name": "userOp", - "type": "tuple", - "internalType": "struct IE.UserOperation", - "components": [ - { - "name": "sender", - "type": "address", - "internalType": "address" - }, - { - "name": "nonce", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "initCode", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "callGasLimit", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "verificationGasLimit", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "preVerificationGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "maxFeePerGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "maxPriorityFeePerGas", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "paymasterAndData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "signature", - "type": "bytes", - "internalType": "bytes" - } - ] - } - ], - "outputs": [ - { - "name": "", - "type": "bool", - "internalType": "bool" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "command", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "previewCommand", - "inputs": [ - { - "name": "intent", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "to", - "type": "address", - "internalType": "address" - }, - { - "name": "amount", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "token", - "type": "address", - "internalType": "address" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "executeCallData", - "type": "bytes", - "internalType": "bytes" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "previewSend", - "inputs": [ - { - "name": "to", - "type": "string", - "internalType": "string" - }, - { - "name": "amount", - "type": "string", - "internalType": "string" - }, - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "_to", - "type": "address", - "internalType": "address" - }, - { - "name": "_amount", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "_token", - "type": "address", - "internalType": "address" - }, - { - "name": "callData", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "executeCallData", - "type": "bytes", - "internalType": "bytes" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "previewSwap", - "inputs": [ - { - "name": "amountIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenOut", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "_amountIn", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "_tokenIn", - "type": "address", - "internalType": "address" - }, - { - "name": "_tokenOut", - "type": "address", - "internalType": "address" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "send", - "inputs": [ - { - "name": "to", - "type": "string", - "internalType": "string" - }, - { - "name": "amount", - "type": "string", - "internalType": "string" - }, - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "setName", - "inputs": [ - { - "name": "token", - "type": "address", - "internalType": "address" - }, - { - "name": "name", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "setNameAndTicker", - "inputs": [ - { - "name": "token", - "type": "address", - "internalType": "address" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "swap", - "inputs": [ - { - "name": "amountIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenIn", - "type": "string", - "internalType": "string" - }, - { - "name": "tokenOut", - "type": "string", - "internalType": "string" - } - ], - "outputs": [], - "stateMutability": "payable" - }, - { - "type": "function", - "name": "tokens", - "inputs": [ - { - "name": "name", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "", - "type": "address", - "internalType": "address" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "whatIsTheAddressOf", - "inputs": [ - { - "name": "name", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "owner", - "type": "address", - "internalType": "address" - }, - { - "name": "receiver", - "type": "address", - "internalType": "address" - }, - { - "name": "node", - "type": "bytes32", - "internalType": "bytes32" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "whatIsTheBalanceOf", - "inputs": [ - { - "name": "name", - "type": "string", - "internalType": "string" - }, - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "balance", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "balanceAdjusted", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "view" - }, - { - "type": "function", - "name": "whatIsTheTotalSupplyOf", - "inputs": [ - { - "name": "token", - "type": "string", - "internalType": "string" - } - ], - "outputs": [ - { - "name": "supply", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "supplyAdjusted", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "view" - }, - { - "type": "event", - "name": "NameSet", - "inputs": [ - { - "name": "token", - "type": "address", - "indexed": true, - "internalType": "address" - }, - { - "name": "name", - "type": "string", - "indexed": false, - "internalType": "string" - } - ], - "anonymous": false - }, - { - "type": "error", - "name": "InvalidCharacter", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidSwap", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidSyntax", - "inputs": [] - }, - { - "type": "error", - "name": "Overflow", - "inputs": [] - }, - { - "type": "error", - "name": "Unauthorized", - "inputs": [] - } - ] \ No newline at end of file + { + "type": "constructor", + "inputs": [], + "stateMutability": "payable" + }, + { + "type": "fallback", + "stateMutability": "payable" + }, + { + "type": "receive", + "stateMutability": "payable" + }, + { + "type": "function", + "name": "checkPackedUserOp", + "inputs": [ + { + "name": "intent", + "type": "string", + "internalType": "string" + }, + { + "name": "userOp", + "type": "tuple", + "internalType": "struct IE.PackedUserOperation", + "components": [ + { + "name": "sender", + "type": "address", + "internalType": "address" + }, + { + "name": "nonce", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "initCode", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "callData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "accountGasLimits", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "preVerificationGas", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "gasFees", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "paymasterAndData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "signature", + "type": "bytes", + "internalType": "bytes" + } + ] + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "checkUserOp", + "inputs": [ + { + "name": "intent", + "type": "string", + "internalType": "string" + }, + { + "name": "userOp", + "type": "tuple", + "internalType": "struct IE.UserOperation", + "components": [ + { + "name": "sender", + "type": "address", + "internalType": "address" + }, + { + "name": "nonce", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "initCode", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "callData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "callGasLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "verificationGasLimit", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "preVerificationGas", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "maxFeePerGas", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "maxPriorityFeePerGas", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "paymasterAndData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "signature", + "type": "bytes", + "internalType": "bytes" + } + ] + } + ], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "command", + "inputs": [ + { + "name": "intent", + "type": "string", + "internalType": "string" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "pairs", + "inputs": [ + { + "name": "token0", + "type": "address", + "internalType": "address" + }, + { + "name": "token1", + "type": "address", + "internalType": "address" + } + ], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "previewCommand", + "inputs": [ + { + "name": "intent", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "to", + "type": "address", + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "minAmountOut", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "callData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "executeCallData", + "type": "bytes", + "internalType": "bytes" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "previewSend", + "inputs": [ + { + "name": "to", + "type": "string", + "internalType": "string" + }, + { + "name": "amount", + "type": "string", + "internalType": "string" + }, + { + "name": "token", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "_to", + "type": "address", + "internalType": "address" + }, + { + "name": "_amount", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_token", + "type": "address", + "internalType": "address" + }, + { + "name": "callData", + "type": "bytes", + "internalType": "bytes" + }, + { + "name": "executeCallData", + "type": "bytes", + "internalType": "bytes" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "previewSwap", + "inputs": [ + { + "name": "amountIn", + "type": "string", + "internalType": "string" + }, + { + "name": "amountOutMinimum", + "type": "string", + "internalType": "string" + }, + { + "name": "tokenIn", + "type": "string", + "internalType": "string" + }, + { + "name": "tokenOut", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "_amountIn", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_amountOut", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "_tokenIn", + "type": "address", + "internalType": "address" + }, + { + "name": "_tokenOut", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "send", + "inputs": [ + { + "name": "to", + "type": "string", + "internalType": "string" + }, + { + "name": "amount", + "type": "string", + "internalType": "string" + }, + { + "name": "token", + "type": "string", + "internalType": "string" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "setName", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "name", + "type": "string", + "internalType": "string" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "setNameAndTicker", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "setPair", + "inputs": [ + { + "name": "tokenA", + "type": "address", + "internalType": "address" + }, + { + "name": "tokenB", + "type": "address", + "internalType": "address" + }, + { + "name": "pair", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "swap", + "inputs": [ + { + "name": "amountIn", + "type": "string", + "internalType": "string" + }, + { + "name": "amountOutMinimum", + "type": "string", + "internalType": "string" + }, + { + "name": "tokenIn", + "type": "string", + "internalType": "string" + }, + { + "name": "tokenOut", + "type": "string", + "internalType": "string" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "tokens", + "inputs": [ + { + "name": "name", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "whatIsTheAddressOf", + "inputs": [ + { + "name": "name", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "owner", + "type": "address", + "internalType": "address" + }, + { + "name": "receiver", + "type": "address", + "internalType": "address" + }, + { + "name": "node", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "whatIsTheBalanceOf", + "inputs": [ + { + "name": "name", + "type": "string", + "internalType": "string" + }, + { + "name": "token", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "balance", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "balanceAdjusted", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "whatIsTheTotalSupplyOf", + "inputs": [ + { + "name": "token", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ + { + "name": "supply", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "supplyAdjusted", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "event", + "name": "NameSet", + "inputs": [ + { + "name": "token", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "name", + "type": "string", + "indexed": false, + "internalType": "string" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "PairSet", + "inputs": [ + { + "name": "token0", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "token1", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "pair", + "type": "address", + "indexed": false, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "error", + "name": "InsufficientSwap", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidCharacter", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidSwap", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidSyntax", + "inputs": [] + }, + { + "type": "error", + "name": "Overflow", + "inputs": [] + } +] \ No newline at end of file diff --git a/docs/src/README.md b/docs/src/README.md index ecec0dd..7910b4a 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -1,18 +1,18 @@ -# [IE](https://github.com/NaniDAO/IE) [![License: AGPL-3.0-only](https://img.shields.io/badge/License-AGPL-black.svg)](https://opensource.org/license/agpl-v3/) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.24-black)](https://docs.soliditylang.org/en/v0.8.24/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml/badge.svg) +# [`IE`](https://github.com/NaniDAO/IE) [![License: AGPL-3.0-only](https://img.shields.io/badge/License-AGPL-black.svg)](https://opensource.org/license/agpl-v3/) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.25-black)](https://docs.soliditylang.org/en/v0.8.25/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml/badge.svg) -The **Intents Engine** (IE): A Basic *Text-to-tx* Simulator Contract. +The **Intents Engine** (`IE`): A Basic *Text-to-tx* Simulator Contract. -## Deployment +## Deployments -### IE V1 +### Mainnet -#### Ethereum Mainnet (L1) +`V1:` [`0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00`](https://etherscan.io/address/0x1e00000000cf8ba83e0005c59c1bf1c4682c8e00#code) -[`0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00`](https://etherscan.io/address/0x1e00000000cf8ba83e0005c59c1bf1c4682c8e00#code) +### Arbitrum -##### Deployed Bytecode +`V1.2:` [`0x1e00003a669bb466d6B49800000099E1abDD6600`](https://arbiscan.io/address/0x1e00003a669bb466d6b49800000099e1abdd6600#code) -[`QmZVdxJyTCJBF7gfE5BrSavCHtMDScZjpLYH5qaMExhW49`](https://content.wrappr.wtf/ipfs/QmZVdxJyTCJBF7gfE5BrSavCHtMDScZjpLYH5qaMExhW49) +`Note:` L2 will be used to rapidly prototype a stable and sufficient `IE` for common crypto commands. Many dev resources here will cater to the current L2 prototype until the release of `V2` on L1. ## Uses @@ -22,13 +22,13 @@ From natural language: - Security checkpoint (forbid tx) - Command translation (make tx) -IE should deterministically and transparently operate to provide these utilities in an uncensorable medium like a Solidity smart contract. +`IE` should deterministically and transparently operate to provide these utilities in an uncensorable medium like a Solidity smart contract. [`V1`](./src/IE.sol) is a POC of this. [*Short demo and explainer thread on X.*](https://x.com/z0r0zzz/status/1758392014737920209?s=20) ## Command Syntax (⌘) -IE is approaching things from first-principles and a "show" rather than "tell" approach. There will be some experimentation. +`IE` is approaching things from first-principles and a "show" rather than "tell" approach. There will be some experimentation. Some things in `V1` are likely very underoptimized for this particular use case. @@ -72,21 +72,21 @@ aliases: *exchange* aliases: *exchange* -Note: In `V1.1` on Arbitrum, a `minOutputAmount` can be specified for swaps. It ensures that you receive a minimum output amount of `object` at the end of the swap, otherwise the transaction will revert. The default value is set to `0`. +`Note:` In `V1.2` on Arbitrum, a `minOutputAmount` can be specified for swaps. It ensures that you receive a minimum output amount of `object` at the end of the swap, otherwise the transaction will revert. The default value is set to `0`. ------------------------------------ -Phrases are provided in the order in which they are most expected. They are "naturalized" to lower case. The IE contract automatically does this, but front-ends should nonetheless try and format as close as possible (*i.e.*, through a simple LLM trained or prompted on these examples below). +Phrases are provided in the order in which they are most expected. They are "naturalized" to lower case. The `IE` contract automatically does this, but front-ends should nonetheless try and format as close as possible (*i.e.*, through a simple LLM trained or prompted on these examples below). -In terms of usual English, we assume the subject of each command is the user account which is more explicit in the case of checking an ERC4337 userOp (where `sender` is the user). And the `object` receives assets or contract calls. `value` is the token or ETH amount involved in the action and the `asset` is the particular item sent or issued from (initially ETH or ERC20 to cover fungibles and most immediate security needs that could benefit from IE). +In terms of usual English, we assume the subject of each command is the user account which is more explicit in the case of checking an ERC4337 userOp (where `sender` is the user). And the `object` receives assets or contract calls. `value` is the token or ETH amount involved in the action and the `asset` is the particular item sent or issued from (initially ETH or ERC20 to cover fungibles and most immediate security needs that could benefit from `IE`). -You MUST include spaces in the string provided to IE in order for it to understand word separation. +You **MUST** include spaces in the string provided to `IE` in order for it to understand word separation. -Note: `to/for` is an identified filler word common to most of the transactions we will cover so it is highlighted. +`Note:` `to/for` is an identified filler word common to most of the transactions we will cover so it is highlighted. As you might notice, there are patterns. Because after all this is typical language and logic we are talking about here. For example, `value` will precede `asset`. `object` will either follow the `action` or be at the end. If at the end, there will be a filler of `for/to`. (Yeah I know this is what people learn in grammar schools but the exercise will likely yield good results.) -Also, let's try and be as helpful as possible at the top of the command funnel. E.g., if there is `msg.value` in a command, then we should assume ETH is involved. +Also, let's try and be as helpful as possible at the top of the command funnel. *E.g.*, if there is `msg.value` in a command, then we should assume ETH is involved. Actions should also have aliases to catch more cases. Though it will be cheaper to use the primary word (for example, 'send' or 'swap' with preference to familiarity, and if there indecision, the shorter), it is helpful to do more and catch different ways of phrasing transactional commands, like "send" can equate to "transfer" when it comes to onchain assets. Adhering to Solidity and smart contract functions themselves in word choice makes the most sense as well (*e.g.*, ETH.*send*/*transfer*, IERC20.*transfer*, UNI.*swap*, CURVE.*exchange*). @@ -96,7 +96,7 @@ Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundry Build the foundry project with `forge build`. Run tests with `forge test`. Measure gas with `forge snapshot`. Format with `forge fmt`. -*Note:* Tests currently run on a fork of mainnet to check ENS properly. +`Note:` Tests currently run on a virtual blockchain fork to check ENS properly. ## Blueprint diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 1ff6b86..80d45d8 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -2,7 +2,9 @@ - [Home](README.md) # src - [IE](src/IE.sol/contract.IE.md) - - [IENSHelper](src/IE.sol/interface.IENSHelper.md) - [IToken](src/IE.sol/interface.IToken.md) - [IExecutor](src/IE.sol/interface.IExecutor.md) + - [INAMI](src/IE.sol/interface.INAMI.md) - [ISwapRouter](src/IE.sol/interface.ISwapRouter.md) + - [NAMI](src/NAMI.sol/contract.NAMI.md) + - [IToken](src/NAMI.sol/interface.IToken.md) diff --git a/docs/src/src/IE.sol/contract.IE.md b/docs/src/src/IE.sol/contract.IE.md index 482fbd1..ccb90ab 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/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/src/IE.sol) **Author:** nani.eth (https://github.com/NaniDAO/ie) @@ -27,7 +27,7 @@ address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA; ```solidity -address internal constant NANI = 0x00000000000025824328358250920B271f348690; +address internal constant NANI = 0x000000000000C6A645b0E51C9eCAA4CA580Ed8e8; ``` @@ -45,7 +45,7 @@ address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; ```solidity -address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; +address internal constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; ``` @@ -54,7 +54,7 @@ address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; ```solidity -address internal constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599; +address internal constant WBTC = 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f; ``` @@ -63,7 +63,7 @@ address internal constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599; ```solidity -address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; +address internal constant USDC = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831; ``` @@ -72,7 +72,7 @@ address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; ```solidity -address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7; +address internal constant USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9; ``` @@ -81,25 +81,34 @@ address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7; ```solidity -address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; +address internal constant DAI = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; ``` -### ENS_REGISTRY -*ENS fallback registry contract.* +### ARB +*The Arbitrum DAO governance token address.* ```solidity -IENSHelper internal constant ENS_REGISTRY = IENSHelper(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e); +address internal constant ARB = 0x912CE59144191C1204E64559FE8253a0e49E6548; ``` -### ENS_WRAPPER -*ENS name wrapper token contract.* +### WSTETH +*The Lido Wrapped Staked ETH token address.* ```solidity -IENSHelper internal constant ENS_WRAPPER = IENSHelper(0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401); +address internal constant WSTETH = 0x5979D7b546E38E414F7E9822514be443A4800529; +``` + + +### RETH +*The Rocket Pool Staked ETH token address.* + + +```solidity +address internal constant RETH = 0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8; ``` @@ -141,13 +150,12 @@ uint160 internal constant MAX_SQRT_RATIO_MINUS_ONE = ``` -### ASCII_MAP -*String mapping for `ENSAsciiNormalizer` logic.* +### NAMI +*The NAMI naming system on Arbitrum.* ```solidity -bytes internal constant ASCII_MAP = - hex"2d00020101000a010700016101620163016401650166016701680169016a016b016c016d016e016f0170017101720173017401750176017701780179017a06001a010500"; +INAMI internal constant NAMI = INAMI(0x000000006641B4C250AEA6B62A1e0067D300697a); ``` @@ -162,16 +170,12 @@ mapping(string name => address) public tokens; ``` -### _idnamap -*Each index in idnamap refers to an ascii code point. -If idnamap[char] > 2, char maps to a valid ascii character. -Otherwise, idna[char] returns Rule.DISALLOWED or Rule.VALID. -Modified from `ENSAsciiNormalizer` deployed by royalfork.eth -(0x4A5cae3EC0b144330cf1a6CeAD187D8F6B891758).* +### pairs +*DAO-governed token swap pool routing on Uniswap V3.* ```solidity -bytes1[] internal _idnamap; +mapping(address token0 => mapping(address token1 => address)) public pairs; ``` @@ -180,7 +184,7 @@ bytes1[] internal _idnamap; ======================== CONSTRUCTOR ======================== /// -*Constructs this IE with `ASCII_MAP`.* +*Constructs this IE on the Arbitrum L2 of Ethereum.* ```solidity @@ -191,9 +195,9 @@ constructor() payable; ====================== COMMAND PREVIEW ====================== /// -Preview natural language smart contract command. +*Preview natural language smart contract command. The `send` syntax uses ENS naming: 'send vitalik 20 DAI'. -`swap` syntax uses common format: 'swap 100 DAI for WETH'. +`swap` syntax uses common format: 'swap 100 DAI for WETH'.* ```solidity @@ -274,13 +278,30 @@ function checkPackedUserOp(string calldata intent, PackedUserOperation calldata returns (bool); ``` -### _returnTokenConstant +### _returnTokenConstants *Checks and returns the canonical token address constant for a matched intent string.* ```solidity -function _returnTokenConstant(bytes32 token) internal view virtual returns (address _token); +function _returnTokenConstants(bytes32 token) + internal + pure + virtual + returns (address _token, uint256 _decimals); +``` + +### _returnPoolConstants + +*Checks and returns popular pool pairs for WETH swaps.* + + +```solidity +function _returnPoolConstants(address token0, address token1) + internal + pure + virtual + returns (address pool); ``` ### command @@ -329,7 +350,8 @@ fallback() external payable virtual; ### _computePoolAddress -*Computes the create2 address for given token pair.* +*Computes the create2 address for given token pair. +note: This process checks all available pools for price.* ```solidity @@ -342,7 +364,7 @@ function _computePoolAddress(address tokenA, address tokenB) ### _computePairHash -*Computes the create2 deployment hash for given token pair.* +*Computes the create2 deployment hash for a given token pair.* ```solidity @@ -371,9 +393,23 @@ function _wrapETH(uint256 amount) internal virtual; function _unwrapETH(uint256 amount) internal virtual; ``` +### _balanceOf + +*Returns the amount of ERC20 `token` owned by `account`.* + + +```solidity +function _balanceOf(address token, address account) + internal + view + virtual + returns (uint256 amount); +``` + ### receive -*ETH receiver fallback.* +*ETH receiver fallback. +Only canonical WETH can call.* ```solidity @@ -423,28 +459,6 @@ function whatIsTheAddressOf(string memory name) returns (address owner, address receiver, bytes32 node); ``` -### _namehash - -*Computes an ENS domain namehash.* - - -```solidity -function _namehash(string memory domain) internal view virtual returns (bytes32 node); -``` - -### _labelhash - -*Computes an ENS domain labelhash given its start and end.* - - -```solidity -function _labelhash(string memory domain, uint256 start, uint256 end) - internal - pure - virtual - returns (bytes32 hash); -``` - ### setName ========================= GOVERNANCE ========================= /// @@ -465,6 +479,15 @@ function setName(address token, string calldata name) public payable virtual; function setNameAndTicker(address token) public payable virtual; ``` +### setPair + +*Sets a public pool `pair` for swapping. Governed by DAO.* + + +```solidity +function setPair(address tokenA, address tokenB, address pair) public payable virtual; +``` + ### _lowercase ===================== STRING OPERATIONS ===================== /// @@ -534,19 +557,47 @@ function _split(string memory base, bytes1 delimiter) returns (string[] memory parts); ``` -### _stringToUint +### _toUint *Convert string to decimalized numerical value.* ```solidity -function _stringToUint(string memory s, uint8 decimals) +function _toUint(string memory s, uint256 decimals) internal pure virtual returns (uint256 result); ``` +### _toAddress + +*Converts a hexadecimal string to its `address` representation. +Modified from Stack (https://ethereum.stackexchange.com/a/156916).* + + +```solidity +function _toAddress(string memory s) internal pure virtual returns (address addr); +``` + +### _hexStringToAddress + +*Converts a hexadecimal string into its bytes representation.* + + +```solidity +function _hexStringToAddress(string memory s) internal pure virtual returns (bytes memory r); +``` + +### _fromHexChar + +*Converts a single hexadecimal character into its numerical value.* + + +```solidity +function _fromHexChar(uint8 c) internal pure virtual returns (uint8 result); +``` + ## Events ### NameSet =========================== EVENTS =========================== /// @@ -558,6 +609,14 @@ function _stringToUint(string memory s, uint8 decimals) event NameSet(address indexed token, string name); ``` +### PairSet +*Logs the registration of a token swap pool pair route on Uniswap V3.* + + +```solidity +event PairSet(address indexed token0, address indexed token1, address pair); +``` + ## Errors ### Overflow ======================= LIBRARY USAGE ======================= /// @@ -574,14 +633,6 @@ event NameSet(address indexed token, string name); error Overflow(); ``` -### Unauthorized -*Caller fails.* - - -```solidity -error Unauthorized(); -``` - ### InvalidSwap *0-liquidity.* @@ -638,7 +689,7 @@ struct UserOperation { ``` ### PackedUserOperation -*The packed ERC4337 user operation (userOp) struct.* +*The packed ERC4337 userOp struct.* ```solidity @@ -655,12 +706,12 @@ struct PackedUserOperation { } ``` -### SwapDetails -*The `swap` command details.* +### SwapInfo +*The `swap` command information struct.* ```solidity -struct SwapDetails { +struct SwapInfo { address tokenIn; address tokenOut; uint256 amountIn; @@ -669,17 +720,14 @@ struct SwapDetails { } ``` -## Enums -### Rule -=========================== ENUMS =========================== /// - -*`ENSAsciiNormalizer` rules.* +### SwapLiq +*The `swap` pool liquidity struct.* ```solidity -enum Rule { - DISALLOWED, - VALID +struct SwapLiq { + address pool; + uint256 liq; } ``` diff --git a/docs/src/src/IE.sol/interface.IExecutor.md b/docs/src/src/IE.sol/interface.IExecutor.md index e8078f1..5aaf28f 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/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/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 new file mode 100644 index 0000000..3b13333 --- /dev/null +++ b/docs/src/src/IE.sol/interface.INAMI.md @@ -0,0 +1,14 @@ +# INAMI +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/src/IE.sol) + +*Simple NAMI names interface for resolving L2 ENS ownership.* + + +## Functions +### whatIsTheAddressOf + + +```solidity +function whatIsTheAddressOf(string calldata) external view returns (address, address, bytes32); +``` + diff --git a/docs/src/src/IE.sol/interface.ISwapRouter.md b/docs/src/src/IE.sol/interface.ISwapRouter.md index 240d4fc..b4801cd 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/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/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 4fc6d3b..c57ed0e 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/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/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 new file mode 100644 index 0000000..bfdfd92 --- /dev/null +++ b/docs/src/src/NAMI.sol/contract.NAMI.md @@ -0,0 +1,296 @@ +# NAMI +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/src/NAMI.sol) + +**Author:** +nani.eth (https://github.com/NaniDAO/ie) + +A contract for managing ENS domain name ownership and resolution on Arbitrum L2. + +*Provides logic for registering names, verifying ownership, and resolving addresses.* + + +## State Variables +### DAO +========================= CONSTANTS ========================= /// + +*The governing DAO address.* + + +```solidity +address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA; +``` + + +### L1_DEPLOYER +*L1_DEPLOYER represents the address responsible for deploying ENS proxy contracts on Ethereum Layer 1. +This address is typically used in conjunction with create2 operations for deterministic deployment.* + + +```solidity +address internal constant L1_DEPLOYER = 0x000000008B009D81C933a72545Ed7500cbB5B9D1; +``` + + +### L2_DEPLOYER +*L2_DEPLOYER denotes the address that performs bridged ENS deployments on Arbitrum Layer 2. +Similar to L1_DEPLOYER, it's crucial for deterministic deployment but within the Arbitrum L2 context.* + + +```solidity +address internal constant L2_DEPLOYER = 0x3fE38087A94903A9D946fa1915e1772fe611000f; +``` + + +### IMPLEMENTATION +*IMPLEMENTATION refers to the address of the contract serving as the implementation for ENS proxies.* + + +```solidity +address internal constant IMPLEMENTATION = 0xEBb49317E567a40cF468c409409aD59a8f67ddE6; +``` + + +### COUNTERPART_GATEWAY +*COUNTERPART_GATEWAY is the address of the gateway contract on Arbitrum Layer 2 that pairs with a corresponding +gateway on Ethereum Layer 1. This gateway facilitates the bridging of tokens between L1 and L2, managing the +lock/mint and burn/release mechanics across layers.* + + +```solidity +address internal constant COUNTERPART_GATEWAY = 0x09e9222E96E7B4AE2a407B98d48e330053351EEe; +``` + + +### L2_HASH +*L2_HASH is a unique identifier, used as part of the create2 address computation for contracts on Arbitrum Layer 2.* + + +```solidity +bytes32 internal constant L2_HASH = + 0x4b11cb57b978697e0aec0c18581326376d6463fd3f6699cbe78ee5935617082d; +``` + + +### ASCII_MAP +*String mapping for `ENSAsciiNormalizer` logic.* + + +```solidity +bytes internal constant ASCII_MAP = + hex"2d00020101000a010700016101620163016401650166016701680169016a016b016c016d016e016f0170017101720173017401750176017701780179017a06001a010500"; +``` + + +### _idnamap +========================== STORAGE ========================== /// + +*Each index in idnamap refers to an ascii code point. +If idnamap[char] > 2, char maps to a valid ascii character. +Otherwise, idna[char] returns Rule.DISALLOWED or Rule.VALID. +Modified from `ENSAsciiNormalizer` deployed by royalfork.eth +(0x4A5cae3EC0b144330cf1a6CeAD187D8F6B891758).* + + +```solidity +bytes1[] internal _idnamap; +``` + + +### _owners +*Internal mapping of registered node owners.* + + +```solidity +mapping(bytes32 node => Ownership) internal _owners; +``` + + +## Functions +### constructor + +======================== CONSTRUCTOR ======================== /// + +*Constructs this IE with `ASCII_MAP`.* + + +```solidity +constructor() payable; +``` + +### whatIsTheAddressOf + +====================== ENS VERIFICATION ====================== /// + +*Returns ENS name ownership information.* + + +```solidity +function whatIsTheAddressOf(string calldata name) + public + view + virtual + returns (address _owner, address _receiver, bytes32 _node); +``` + +### _namehash + +*Computes an ENS domain namehash.* + + +```solidity +function _namehash(string memory domain) internal view virtual returns (bytes32 node); +``` + +### _labelhash + +*Computes an ENS domain labelhash given its start and end.* + + +```solidity +function _labelhash(string memory domain, uint256 start, uint256 end) + internal + pure + virtual + returns (bytes32 hash); +``` + +### register + +======================== REGISTRATION ======================== /// + +*Registers a name node under an owner. ENS L1 node must be bridged.* + + +```solidity +function register(address _owner, bytes32 _node) public payable virtual; +``` + +### registerSub + +*Registers a name subnode under an owner. Only the DAO may call this function.* + + +```solidity +function registerSub(address _owner, string calldata _subname) public payable virtual; +``` + +### owner + +====================== OWNERSHIP LOGIC ====================== /// + +*Returns the registered owner of a given ENS L1 node. Must be bridged. +note: Alternatively, NAMI provides subdomains issued under `nani.eth` node.* + + +```solidity +function owner(bytes32 _node) public view virtual returns (address _owner); +``` + +### isOwner + +*Checks if an address is the owner of a given ENS L1 node represented as `l2Token`. +note: NAMI operates under the assumption that the proper owner-receiver holds majority.* + + +```solidity +function isOwner(address _owner, bytes32 _node) public view virtual returns (bool); +``` + +### predictDeterministicAddresses + +*Returns the deterministic create2 addresses for ENS node tokens on L1 & L2.* + + +```solidity +function predictDeterministicAddresses(bytes32 _node) + public + pure + virtual + returns (address l1Token, address l2Token); +``` + +### _predictDeterministicAddress + +*Returns the predicted address on L1 using CWIA pattern.* + + +```solidity +function _predictDeterministicAddress(bytes32 hash, bytes32 salt) + internal + pure + virtual + returns (address predicted); +``` + +### _initCodeHash + +*Returns the initCodeHash for the predicted address on L1 using CWIA pattern.* + + +```solidity +function _initCodeHash(bytes memory data) internal pure virtual returns (bytes32 hash); +``` + +### _calculateL2TokenAddress + +*Returns the predicted `l2Token` address using Arbitrum create2 bridge preview methods on `l1Token`.* + + +```solidity +function _calculateL2TokenAddress(address l1Token) + internal + pure + virtual + returns (address l2Token); +``` + +## Events +### Registered +=========================== EVENTS =========================== /// + +*Logs the registration of a name node into ownership.* + + +```solidity +event Registered(bytes32 indexed node, Ownership ownership); +``` + +## Errors +### Unregistered +======================= CUSTOM ERRORS ======================= /// + +*Unregistered.* + + +```solidity +error Unregistered(); +``` + +## Structs +### Ownership +========================== STRUCTS ========================== /// + +*The name node ownership information struct.* + + +```solidity +struct Ownership { + address owner; + bool subnode; +} +``` + +## Enums +### Rule +=========================== ENUMS =========================== /// + +*`ENSAsciiNormalizer` rules.* + + +```solidity +enum Rule { + DISALLOWED, + VALID +} +``` + diff --git a/docs/src/src/NAMI.sol/interface.IToken.md b/docs/src/src/NAMI.sol/interface.IToken.md new file mode 100644 index 0000000..526fecb --- /dev/null +++ b/docs/src/src/NAMI.sol/interface.IToken.md @@ -0,0 +1,21 @@ +# IToken +[Git Source](https://github.com/NaniDAO/ie/blob/f061f69f55a660146bbc3247dded252faef04a99/src/NAMI.sol) + +*Simple token balance & supply interface.* + + +## Functions +### totalSupply + + +```solidity +function totalSupply() external view returns (uint256); +``` + +### balanceOf + + +```solidity +function balanceOf(address) external view returns (uint256); +``` + diff --git a/docs/src/src/README.md b/docs/src/src/README.md index 55ca2ad..79936c6 100644 --- a/docs/src/src/README.md +++ b/docs/src/src/README.md @@ -2,7 +2,9 @@ # Contents - [IE](IE.sol/contract.IE.md) -- [IENSHelper](IE.sol/interface.IENSHelper.md) - [IToken](IE.sol/interface.IToken.md) - [IExecutor](IE.sol/interface.IExecutor.md) +- [INAMI](IE.sol/interface.INAMI.md) - [ISwapRouter](IE.sol/interface.ISwapRouter.md) +- [NAMI](NAMI.sol/contract.NAMI.md) +- [IToken](NAMI.sol/interface.IToken.md) diff --git a/etherscan.json b/etherscan.json new file mode 100644 index 0000000..c34feb4 --- /dev/null +++ b/etherscan.json @@ -0,0 +1 @@ +{"language":"Solidity","sources":{"src/IE.sol":{"content":"// ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘\n// SPDX-License-Identifier: AGPL-3.0-only\npragma solidity ^0.8.19;\n\nimport {SafeTransferLib} from \"../lib/solady/src/utils/SafeTransferLib.sol\";\nimport {MetadataReaderLib} from \"../lib/solady/src/utils/MetadataReaderLib.sol\";\n\n/// @title Intents Engine (IE)\n/// @notice Simple helper contract for turning transactional intents into executable code.\n/// @dev V1 simulates typical commands (sending and swapping tokens) and includes execution.\n/// IE also has a workflow to verify the intent of ERC4337 account userOps against calldata.\n/// @author nani.eth (https://github.com/NaniDAO/ie)\n/// @custom:version 1.2.0\ncontract IE {\n /// ======================= LIBRARY USAGE ======================= ///\n\n /// @dev Metadata reader library.\n using MetadataReaderLib for address;\n\n /// @dev Safe token transfer library.\n using SafeTransferLib for address;\n\n /// ======================= CUSTOM ERRORS ======================= ///\n\n /// @dev Bad math.\n error Overflow();\n\n /// @dev 0-liquidity.\n error InvalidSwap();\n\n /// @dev Invalid command.\n error InvalidSyntax();\n\n /// @dev Non-numeric character.\n error InvalidCharacter();\n\n /// @dev Insufficient swap output.\n error InsufficientSwap();\n\n /// =========================== EVENTS =========================== ///\n\n /// @dev Logs the registration of a token name.\n event NameSet(address indexed token, string name);\n\n /// @dev Logs the registration of a token swap pool pair route on Uniswap V3.\n event PairSet(address indexed token0, address indexed token1, address pair);\n\n /// ========================== STRUCTS ========================== ///\n\n /// @dev The ERC4337 user operation (userOp) struct.\n struct UserOperation {\n address sender;\n uint256 nonce;\n bytes initCode;\n bytes callData;\n uint256 callGasLimit;\n uint256 verificationGasLimit;\n uint256 preVerificationGas;\n uint256 maxFeePerGas;\n uint256 maxPriorityFeePerGas;\n bytes paymasterAndData;\n bytes signature;\n }\n\n /// @dev The packed ERC4337 userOp struct.\n struct PackedUserOperation {\n address sender;\n uint256 nonce;\n bytes initCode;\n bytes callData;\n bytes32 accountGasLimits;\n uint256 preVerificationGas;\n bytes32 gasFees;\n bytes paymasterAndData;\n bytes signature;\n }\n\n /// @dev The `swap` command information struct.\n struct SwapInfo {\n address tokenIn;\n address tokenOut;\n uint256 amountIn;\n bool ETHIn;\n bool ETHOut;\n }\n\n /// @dev The `swap` pool liquidity struct.\n struct SwapLiq {\n address pool;\n uint256 liq;\n }\n\n /// ========================= CONSTANTS ========================= ///\n\n /// @dev The governing DAO address.\n address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA;\n\n /// @dev The NANI token address.\n address internal constant NANI = 0x000000000000C6A645b0E51C9eCAA4CA580Ed8e8;\n\n /// @dev The conventional ERC7528 ETH address.\n address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n /// @dev The canonical wrapped ETH address.\n address internal constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;\n\n /// @dev The popular wrapped BTC address.\n address internal constant WBTC = 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f;\n\n /// @dev The Circle USD stablecoin address.\n address internal constant USDC = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831;\n\n /// @dev The Tether USD stablecoin address.\n address internal constant USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9;\n\n /// @dev The Maker DAO USD stablecoin address.\n address internal constant DAI = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1;\n\n /// @dev The Arbitrum DAO governance token address.\n address internal constant ARB = 0x912CE59144191C1204E64559FE8253a0e49E6548;\n\n /// @dev The Lido Wrapped Staked ETH token address.\n address internal constant WSTETH = 0x5979D7b546E38E414F7E9822514be443A4800529;\n\n /// @dev The Rocket Pool Staked ETH token address.\n address internal constant RETH = 0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8;\n\n /// @dev The address of the Uniswap V3 Factory.\n address internal constant UNISWAP_V3_FACTORY = 0x1F98431c8aD98523631AE4a59f267346ea31F984;\n\n /// @dev The Uniswap V3 Pool `initcodehash`.\n bytes32 internal constant UNISWAP_V3_POOL_INIT_CODE_HASH =\n 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;\n\n /// @dev The minimum value that can be returned from `getSqrtRatioAtTick` (plus one).\n uint160 internal constant MIN_SQRT_RATIO_PLUS_ONE = 4295128740;\n\n /// @dev The maximum value that can be returned from `getSqrtRatioAtTick` (minus one).\n uint160 internal constant MAX_SQRT_RATIO_MINUS_ONE =\n 1461446703485210103287273052203988822378723970341;\n\n /// @dev The NAMI naming system on Arbitrum.\n INAMI internal constant NAMI = INAMI(0x000000006641B4C250AEA6B62A1e0067D300697a);\n\n /// ========================== STORAGE ========================== ///\n\n /// @dev DAO-governed token address naming.\n mapping(string name => address) public tokens;\n\n /// @dev DAO-governed token swap pool routing on Uniswap V3.\n mapping(address token0 => mapping(address token1 => address)) public pairs;\n\n /// ======================== CONSTRUCTOR ======================== ///\n\n /// @dev Constructs this IE on the Arbitrum L2 of Ethereum.\n constructor() payable {}\n\n /// ====================== COMMAND PREVIEW ====================== ///\n\n /// @dev Preview natural language smart contract command.\n /// The `send` syntax uses ENS naming: 'send vitalik 20 DAI'.\n /// `swap` syntax uses common format: 'swap 100 DAI for WETH'.\n function previewCommand(string calldata intent)\n public\n view\n virtual\n returns (\n address to, // Receiver address.\n uint256 amount, // Formatted amount.\n uint256 minAmountOut, // Formatted amount.\n address token, // Asset to send `to`.\n bytes memory callData, // Raw calldata for send transaction.\n bytes memory executeCallData // Anticipates common execute API.\n )\n {\n string memory normalized = _lowercase(intent);\n bytes32 action = _extraction(normalized);\n if (action == \"send\" || action == \"transfer\" || action == \"pay\" || action == \"grant\") {\n (string memory _to, string memory _amount, string memory _token) =\n _extractSend(normalized);\n (to, amount, token, callData, executeCallData) = previewSend(_to, _amount, _token);\n } else if (\n action == \"swap\" || action == \"exchange\" || action == \"stake\" || action == \"deposit\"\n || action == \"unstake\" || action == \"withdraw\"\n ) {\n (\n string memory amountIn,\n string memory amountOutMinimum,\n string memory tokenIn,\n string memory tokenOut\n ) = _extractSwap(normalized);\n (amount, minAmountOut, token, to) =\n previewSwap(amountIn, amountOutMinimum, tokenIn, tokenOut);\n } else {\n revert InvalidSyntax(); // Invalid command format.\n }\n }\n\n /// @dev Previews a `send` command from the parts of a matched intent string.\n function previewSend(string memory to, string memory amount, string memory token)\n public\n view\n virtual\n returns (\n address _to,\n uint256 _amount,\n address _token,\n bytes memory callData,\n bytes memory executeCallData\n )\n {\n uint256 decimals;\n (_token, decimals) = _returnTokenConstants(bytes32(bytes(token)));\n if (_token == address(0)) _token = tokens[token]; // Check storage.\n bool isETH = _token == ETH; // Memo whether the token is ETH or not.\n (, _to,) = whatIsTheAddressOf(to); // Fetch receiver address from ENS.\n _amount = _toUint(amount, decimals != 0 ? decimals : _token.readDecimals());\n if (!isETH) callData = abi.encodeCall(IToken.transfer, (_to, _amount));\n executeCallData =\n abi.encodeCall(IExecutor.execute, (isETH ? _to : _token, isETH ? _amount : 0, callData));\n }\n\n /// @dev Previews a `swap` command from the parts of a matched intent string.\n function previewSwap(\n string memory amountIn,\n string memory amountOutMinimum,\n string memory tokenIn,\n string memory tokenOut\n )\n public\n view\n virtual\n returns (uint256 _amountIn, uint256 _amountOut, address _tokenIn, address _tokenOut)\n {\n uint256 decimalsIn;\n uint256 decimalsOut;\n (_tokenIn, decimalsIn) = _returnTokenConstants(bytes32(bytes(tokenIn)));\n if (_tokenIn == address(0)) _tokenIn = tokens[tokenIn];\n (_tokenOut, decimalsOut) = _returnTokenConstants(bytes32(bytes(tokenOut)));\n if (_tokenOut == address(0)) _tokenOut = tokens[tokenOut];\n _amountIn = _toUint(amountIn, decimalsIn != 0 ? decimalsIn : _tokenIn.readDecimals());\n _amountOut =\n _toUint(amountOutMinimum, decimalsOut != 0 ? decimalsOut : _tokenOut.readDecimals());\n }\n\n /// @dev Checks ERC4337 userOp against the output of the command intent.\n function checkUserOp(string calldata intent, UserOperation calldata userOp)\n public\n view\n virtual\n returns (bool)\n {\n (,,,,, bytes memory executeCallData) = previewCommand(intent);\n if (executeCallData.length != userOp.callData.length) return false;\n return keccak256(executeCallData) == keccak256(userOp.callData);\n }\n\n /// @dev Checks packed ERC4337 userOp against the output of the command intent.\n function checkPackedUserOp(string calldata intent, PackedUserOperation calldata userOp)\n public\n view\n virtual\n returns (bool)\n {\n (,,,,, bytes memory executeCallData) = previewCommand(intent);\n if (executeCallData.length != userOp.callData.length) return false;\n return keccak256(executeCallData) == keccak256(userOp.callData);\n }\n\n /// @dev Checks and returns the canonical token address constant for a matched intent string.\n function _returnTokenConstants(bytes32 token)\n internal\n pure\n virtual\n returns (address _token, uint256 _decimals)\n {\n if (token == \"eth\" || token == \"ether\") return (ETH, 18);\n if (token == \"usdc\") return (USDC, 6);\n if (token == \"usdt\" || token == \"tether\") return (USDT, 6);\n if (token == \"dai\") return (DAI, 18);\n if (token == \"arb\" || token == \"arbitrum\") return (ARB, 18);\n if (token == \"weth\") return (WETH, 18);\n if (token == \"wbtc\" || token == \"btc\" || token == \"bitcoin\") return (WBTC, 8);\n if (token == \"steth\" || token == \"wsteth\" || token == \"lido\") return (WSTETH, 18);\n if (token == \"reth\") return (RETH, 18);\n if (token == \"nani\") return (NANI, 18);\n }\n\n /// @dev Checks and returns popular pool pairs for WETH swaps.\n function _returnPoolConstants(address token0, address token1)\n internal\n pure\n virtual\n returns (address pool)\n {\n if (token0 == WSTETH && token1 == WETH) return 0x35218a1cbaC5Bbc3E57fd9Bd38219D37571b3537;\n if (token0 == WETH && token1 == RETH) return 0x09ba302A3f5ad2bF8853266e271b005A5b3716fe;\n if (token0 == WETH && token1 == USDC) return 0xC6962004f452bE9203591991D15f6b388e09E8D0;\n if (token0 == WETH && token1 == USDT) return 0x641C00A822e8b671738d32a431a4Fb6074E5c79d;\n if (token0 == WETH && token1 == DAI) return 0xA961F0473dA4864C5eD28e00FcC53a3AAb056c1b;\n if (token0 == WETH && token1 == ARB) return 0xC6F780497A95e246EB9449f5e4770916DCd6396A;\n if (token0 == WBTC && token1 == WETH) return 0x2f5e87C9312fa29aed5c179E456625D79015299c;\n }\n\n /// ===================== COMMAND EXECUTION ===================== ///\n\n /// @dev Executes a text command from an intent string.\n function command(string calldata intent) public payable virtual {\n string memory normalized = _lowercase(intent);\n bytes32 action = _extraction(normalized);\n if (action == \"send\" || action == \"transfer\" || action == \"pay\" || action == \"grant\") {\n (string memory to, string memory amount, string memory token) = _extractSend(normalized);\n send(to, amount, token);\n } else if (\n action == \"swap\" || action == \"exchange\" || action == \"stake\" || action == \"deposit\"\n || action == \"unstake\" || action == \"withdraw\"\n ) {\n (\n string memory amountIn,\n string memory amountOutMinimum,\n string memory tokenIn,\n string memory tokenOut\n ) = _extractSwap(normalized);\n swap(amountIn, amountOutMinimum, tokenIn, tokenOut);\n } else {\n revert InvalidSyntax(); // Invalid command format.\n }\n }\n\n /// @dev Executes a `send` command from the parts of a matched intent string.\n function send(string memory to, string memory amount, string memory token)\n public\n payable\n virtual\n {\n (address _token, uint256 decimals) = _returnTokenConstants(bytes32(bytes(token)));\n if (_token == address(0)) _token = tokens[token];\n (, address _to,) = whatIsTheAddressOf(to);\n if (_token == ETH) {\n _to.safeTransferETH(_toUint(amount, decimals));\n } else {\n _token.safeTransferFrom(\n msg.sender, _to, _toUint(amount, decimals != 0 ? decimals : _token.readDecimals())\n );\n }\n }\n\n /// @dev Executes a `swap` command from the parts of a matched intent string.\n function swap(\n string memory amountIn,\n string memory amountOutMinimum,\n string memory tokenIn,\n string memory tokenOut\n ) public payable virtual {\n SwapInfo memory info;\n uint256 decimalsIn;\n uint256 decimalsOut;\n (info.tokenIn, decimalsIn) = _returnTokenConstants(bytes32(bytes(tokenIn)));\n if (info.tokenIn == address(0)) info.tokenIn = tokens[tokenIn];\n (info.tokenOut, decimalsOut) = _returnTokenConstants(bytes32(bytes(tokenOut)));\n if (info.tokenOut == address(0)) info.tokenOut = tokens[tokenOut];\n info.ETHIn = info.tokenIn == ETH;\n if (info.ETHIn) info.tokenIn = WETH;\n info.ETHOut = info.tokenOut == ETH;\n if (info.ETHOut) info.tokenOut = WETH;\n info.amountIn =\n _toUint(amountIn, decimalsIn != 0 ? decimalsIn : info.tokenIn.readDecimals());\n if (info.amountIn >= 1 << 255) revert Overflow();\n (address pool, bool zeroForOne) = _computePoolAddress(info.tokenIn, info.tokenOut);\n (int256 amount0, int256 amount1) = ISwapRouter(pool).swap(\n !info.ETHOut ? msg.sender : address(this),\n zeroForOne,\n int256(info.amountIn),\n zeroForOne ? MIN_SQRT_RATIO_PLUS_ONE : MAX_SQRT_RATIO_MINUS_ONE,\n abi.encodePacked(info.ETHIn, info.ETHOut, msg.sender, info.tokenIn, info.tokenOut)\n );\n if (\n uint256(-(zeroForOne ? amount1 : amount0))\n < _toUint(\n amountOutMinimum, decimalsOut != 0 ? decimalsOut : info.tokenOut.readDecimals()\n )\n ) revert InsufficientSwap();\n }\n\n /// @dev Fallback `uniswapV3SwapCallback`.\n /// If ETH is swapped, WETH is forwarded.\n fallback() external payable virtual {\n int256 amount0Delta;\n int256 amount1Delta;\n bool ETHIn;\n bool ETHOut;\n address payer;\n address tokenIn;\n address tokenOut;\n assembly (\"memory-safe\") {\n amount0Delta := calldataload(0x4)\n amount1Delta := calldataload(0x24)\n ETHIn := byte(0, calldataload(0x84))\n ETHOut := byte(0, calldataload(add(0x84, 1)))\n payer := shr(96, calldataload(add(0x84, 2)))\n tokenIn := shr(96, calldataload(add(0x84, 22)))\n tokenOut := shr(96, calldataload(add(0x84, 42)))\n }\n if (amount0Delta <= 0 && amount1Delta <= 0) revert InvalidSwap();\n (address pool, bool zeroForOne) = _computePoolAddress(tokenIn, tokenOut);\n assembly (\"memory-safe\") {\n if iszero(eq(caller(), pool)) { revert(codesize(), 0x00) }\n }\n if (ETHIn) {\n _wrapETH(uint256(zeroForOne ? amount0Delta : amount1Delta));\n } else {\n tokenIn.safeTransferFrom(\n payer, msg.sender, uint256(zeroForOne ? amount0Delta : amount1Delta)\n );\n }\n if (ETHOut) {\n uint256 amount = uint256(-(zeroForOne ? amount1Delta : amount0Delta));\n _unwrapETH(amount);\n payer.safeTransferETH(amount);\n }\n }\n\n /// @dev Computes the create2 address for given token pair.\n /// note: This process checks all available pools for price.\n function _computePoolAddress(address tokenA, address tokenB)\n internal\n view\n virtual\n returns (address pool, bool zeroForOne)\n {\n if (tokenA < tokenB) zeroForOne = true;\n else (tokenA, tokenB) = (tokenB, tokenA);\n pool = _returnPoolConstants(tokenA, tokenB);\n if (pool == address(0)) {\n pool = pairs[tokenA][tokenB];\n if (pool == address(0)) {\n address pool100 = _computePairHash(tokenA, tokenB, 100); // Lowest fee.\n address pool500 = _computePairHash(tokenA, tokenB, 500); // Lower fee.\n address pool3000 = _computePairHash(tokenA, tokenB, 3000); // Mid fee.\n address pool10000 = _computePairHash(tokenA, tokenB, 10000); // Hi fee.\n // Initialize an array to hold the liquidity information for each pool.\n SwapLiq[5] memory pools = [\n SwapLiq(pool100, pool100.code.length != 0 ? _balanceOf(tokenA, pool100) : 0),\n SwapLiq(pool500, pool500.code.length != 0 ? _balanceOf(tokenA, pool500) : 0),\n SwapLiq(pool3000, pool3000.code.length != 0 ? _balanceOf(tokenA, pool3000) : 0),\n SwapLiq(pool10000, pool10000.code.length != 0 ? _balanceOf(tokenA, pool10000) : 0),\n SwapLiq(pool, 0) // Placeholder for top pool. This will hold outputs for comparison.\n ];\n // Iterate through the array to find the top pool with the highest liquidity in `tokenA`.\n for (uint256 i; i != 4; ++i) {\n if (pools[i].liq > pools[4].liq) {\n pools[4].liq = pools[i].liq;\n pools[4].pool = pools[i].pool;\n }\n }\n pool = pools[4].pool; // Return the top pool with likely best liquidity.\n }\n }\n }\n\n /// @dev Computes the create2 deployment hash for a given token pair.\n function _computePairHash(address token0, address token1, uint24 fee)\n internal\n pure\n virtual\n returns (address pool)\n {\n bytes32 salt = keccak256(abi.encode(token0, token1, fee));\n assembly (\"memory-safe\") {\n mstore8(0x00, 0xff) // Write the prefix.\n mstore(0x35, UNISWAP_V3_POOL_INIT_CODE_HASH)\n mstore(0x01, shl(96, UNISWAP_V3_FACTORY))\n mstore(0x15, salt)\n pool := keccak256(0x00, 0x55)\n mstore(0x35, 0) // Restore overwritten.\n }\n }\n\n /// @dev Wraps an `amount` of ETH to WETH and funds pool caller for swap.\n function _wrapETH(uint256 amount) internal virtual {\n assembly (\"memory-safe\") {\n pop(call(gas(), WETH, amount, codesize(), 0x00, codesize(), 0x00))\n mstore(0x14, caller()) // Store the `pool` argument.\n mstore(0x34, amount) // Store the `amount` argument.\n mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n pop(call(gas(), WETH, 0, 0x10, 0x44, codesize(), 0x00))\n mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n }\n }\n\n /// @dev Unwraps an `amount` of ETH from WETH for return.\n function _unwrapETH(uint256 amount) internal virtual {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x2e1a7d4d) // `withdraw(uint256)`.\n mstore(0x20, amount) // Store the `amount` argument.\n pop(call(gas(), WETH, 0, 0x1c, 0x24, codesize(), 0x00))\n }\n }\n\n /// @dev Returns the amount of ERC20 `token` owned by `account`.\n function _balanceOf(address token, address account)\n internal\n view\n virtual\n returns (uint256 amount)\n {\n assembly (\"memory-safe\") {\n mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n mstore(0x14, account) // Store the `account` argument.\n pop(staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20))\n amount := mload(0x20)\n }\n }\n\n /// @dev ETH receiver fallback.\n /// Only canonical WETH can call.\n receive() external payable virtual {\n assembly (\"memory-safe\") {\n if iszero(eq(caller(), WETH)) { revert(codesize(), 0x00) }\n }\n }\n\n /// ================== BALANCE & SUPPLY HELPERS ================== ///\n\n /// @dev Returns the balance of a named account in a named token.\n function whatIsTheBalanceOf(string calldata name, /*(bob)*/ /*in*/ string calldata token)\n public\n view\n virtual\n returns (uint256 balance, uint256 balanceAdjusted)\n {\n (, address _name,) = whatIsTheAddressOf(name);\n (address _token, uint256 decimals) =\n _returnTokenConstants(bytes32(bytes(_lowercase(token))));\n if (_token == address(0)) _token = tokens[token];\n balance = _token == ETH ? _name.balance : _token.balanceOf(_name);\n balanceAdjusted = balance / 10 ** (decimals != 0 ? decimals : _token.readDecimals());\n }\n\n /// @dev Returns the total supply of a named token.\n function whatIsTheTotalSupplyOf(string calldata token)\n public\n view\n virtual\n returns (uint256 supply, uint256 supplyAdjusted)\n {\n (address _token, uint256 decimals) =\n _returnTokenConstants(bytes32(bytes(_lowercase(token))));\n if (_token == address(0)) _token = tokens[token];\n assembly (\"memory-safe\") {\n mstore(0x00, 0x18160ddd) // `totalSupply()`.\n if iszero(staticcall(gas(), _token, 0x1c, 0x04, 0x20, 0x20)) {\n revert(codesize(), 0x00)\n }\n supply := mload(0x20)\n }\n supplyAdjusted = supply / 10 ** (decimals != 0 ? decimals : _token.readDecimals());\n }\n\n /// ====================== ENS VERIFICATION ====================== ///\n\n /// @dev Returns ENS name ownership details.\n function whatIsTheAddressOf(string memory name)\n public\n view\n virtual\n returns (address owner, address receiver, bytes32 node)\n {\n // If address length, convert.\n if (bytes(name).length == 42) {\n receiver = _toAddress(name);\n } else {\n (owner, receiver, node) = NAMI.whatIsTheAddressOf(name);\n }\n }\n\n /// ========================= GOVERNANCE ========================= ///\n\n /// @dev Sets a public `name` tag for a given `token` address. Governed by DAO.\n function setName(address token, string calldata name) public payable virtual {\n assembly (\"memory-safe\") {\n if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) } // Optimized for repeat.\n }\n string memory normalized = _lowercase(name);\n emit NameSet(tokens[normalized] = token, normalized);\n }\n\n /// @dev Sets a public name and ticker for a given `token` address.\n function setNameAndTicker(address token) public payable virtual {\n string memory normalizedName = _lowercase(token.readName());\n string memory normalizedSymbol = _lowercase(token.readSymbol());\n emit NameSet(tokens[normalizedName] = token, normalizedName);\n emit NameSet(tokens[normalizedSymbol] = token, normalizedSymbol);\n }\n\n /// @dev Sets a public pool `pair` for swapping. Governed by DAO.\n function setPair(address tokenA, address tokenB, address pair) public payable virtual {\n assembly (\"memory-safe\") {\n if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) } // Optimized for repeat.\n }\n if (tokenB < tokenA) (tokenA, tokenB) = (tokenB, tokenA);\n emit PairSet(tokenA, tokenB, pairs[tokenA][tokenB] = pair);\n }\n\n /// ===================== STRING OPERATIONS ===================== ///\n\n /// @dev Returns copy of string in lowercase.\n /// Modified from Solady LibString `toCase`.\n function _lowercase(string memory subject)\n internal\n pure\n virtual\n returns (string memory result)\n {\n assembly (\"memory-safe\") {\n let length := mload(subject)\n if length {\n result := add(mload(0x40), 0x20)\n subject := add(subject, 1)\n let flags := shl(add(70, shl(5, 0)), 0x3ffffff)\n let w := not(0)\n for { let o := length } 1 {} {\n o := add(o, w)\n let b := and(0xff, mload(add(subject, o)))\n mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20)))\n if iszero(o) { break }\n }\n result := mload(0x40)\n mstore(result, length) // Store the length.\n let last := add(add(result, 0x20), length)\n mstore(last, 0) // Zeroize the slot after the string.\n mstore(0x40, add(last, 0x20)) // Allocate the memory.\n }\n }\n }\n\n /// @dev Extracts the first word (action) as bytes32.\n function _extraction(string memory normalizedIntent)\n internal\n pure\n virtual\n returns (bytes32 result)\n {\n assembly (\"memory-safe\") {\n let str := add(normalizedIntent, 0x20)\n for { let i } lt(i, 0x20) { i := add(i, 1) } {\n let char := byte(0, mload(add(str, i)))\n if eq(char, 0x20) { break }\n result := or(result, shl(sub(248, mul(i, 8)), char))\n }\n }\n }\n\n /// @dev Extract the key words of normalized `send` intent.\n function _extractSend(string memory normalizedIntent)\n internal\n pure\n virtual\n returns (string memory to, string memory amount, string memory token)\n {\n string[] memory parts = _split(normalizedIntent, \" \");\n if (parts.length == 4) return (parts[1], parts[2], parts[3]);\n if (parts.length == 5) return (parts[4], parts[1], parts[2]);\n else revert InvalidSyntax(); // Command is not formatted.\n }\n\n /// @dev Extract the key words of normalized `swap` intent.\n function _extractSwap(string memory normalizedIntent)\n internal\n pure\n virtual\n returns (\n string memory amountIn,\n string memory amountOutMinimum,\n string memory tokenIn,\n string memory tokenOut\n )\n {\n string[] memory parts = _split(normalizedIntent, \" \");\n if (parts.length == 5) return (parts[1], \"\", parts[2], parts[4]);\n if (parts.length == 6) return (parts[1], parts[4], parts[2], parts[5]);\n else revert InvalidSyntax(); // Command is not formatted.\n }\n\n /// @dev Split the intent into an array of words.\n function _split(string memory base, bytes1 delimiter)\n internal\n pure\n virtual\n returns (string[] memory parts)\n {\n unchecked {\n bytes memory baseBytes = bytes(base);\n uint256 count = 1;\n for (uint256 i; i != baseBytes.length; ++i) {\n if (baseBytes[i] == delimiter) {\n ++count;\n }\n }\n parts = new string[](count);\n uint256 partIndex;\n uint256 start;\n for (uint256 i; i <= baseBytes.length; ++i) {\n if (i == baseBytes.length || baseBytes[i] == delimiter) {\n bytes memory part = new bytes(i - start);\n for (uint256 j = start; j != i; ++j) {\n part[j - start] = baseBytes[j];\n }\n parts[partIndex] = string(part);\n ++partIndex;\n start = i + 1;\n }\n }\n }\n }\n\n /// @dev Convert string to decimalized numerical value.\n function _toUint(string memory s, uint256 decimals)\n internal\n pure\n virtual\n returns (uint256 result)\n {\n unchecked {\n bool hasDecimal;\n uint256 decimalPlaces;\n bytes memory b = bytes(s);\n for (uint256 i; i != b.length; ++i) {\n if (b[i] >= \"0\" && b[i] <= \"9\") {\n result = result * 10 + uint8(b[i]) - 48;\n if (hasDecimal) {\n ++decimalPlaces;\n if (decimalPlaces > decimals) break;\n }\n } else if (b[i] == \".\" && !hasDecimal) {\n hasDecimal = true;\n } else {\n revert InvalidCharacter();\n }\n }\n if (decimalPlaces < decimals) {\n result *= 10 ** (decimals - decimalPlaces);\n }\n }\n }\n\n /// @dev Converts a hexadecimal string to its `address` representation.\n /// Modified from Stack (https://ethereum.stackexchange.com/a/156916).\n function _toAddress(string memory s) internal pure virtual returns (address addr) {\n bytes memory _bytes = _hexStringToAddress(s);\n if (_bytes.length < 21) revert InvalidSyntax();\n assembly (\"memory-safe\") {\n addr := div(mload(add(add(_bytes, 0x20), 1)), 0x1000000000000000000000000)\n }\n }\n\n /// @dev Converts a hexadecimal string into its bytes representation.\n function _hexStringToAddress(string memory s) internal pure virtual returns (bytes memory r) {\n unchecked {\n bytes memory ss = bytes(s);\n if (ss.length % 2 != 0) revert InvalidSyntax(); // Length must be even.\n r = new bytes(ss.length / 2);\n for (uint256 i; i != ss.length / 2; ++i) {\n r[i] =\n bytes1(_fromHexChar(uint8(ss[2 * i])) * 16 + _fromHexChar(uint8(ss[2 * i + 1])));\n }\n }\n }\n\n /// @dev Converts a single hexadecimal character into its numerical value.\n function _fromHexChar(uint8 c) internal pure virtual returns (uint8 result) {\n unchecked {\n if (bytes1(c) >= bytes1(\"0\") && bytes1(c) <= bytes1(\"9\")) return c - uint8(bytes1(\"0\"));\n if (bytes1(c) >= bytes1(\"a\") && bytes1(c) <= bytes1(\"f\")) {\n return 10 + c - uint8(bytes1(\"a\"));\n }\n if (bytes1(c) >= bytes1(\"A\") && bytes1(c) <= bytes1(\"F\")) {\n return 10 + c - uint8(bytes1(\"A\"));\n }\n }\n }\n}\n\n/// @dev Simple token transfer interface.\ninterface IToken {\n function transfer(address, uint256) external returns (bool);\n}\n\n/// @notice Simple calldata executor interface.\ninterface IExecutor {\n function execute(address, uint256, bytes calldata) external payable returns (bytes memory);\n}\n\n/// @dev Simple NAMI names interface for resolving L2 ENS ownership.\ninterface INAMI {\n function whatIsTheAddressOf(string calldata)\n external\n view\n returns (address, address, bytes32);\n}\n\n/// @dev Simple Uniswap V3 swapping interface.\ninterface ISwapRouter {\n function swap(address, bool, int256, uint160, bytes calldata)\n external\n returns (int256, int256);\n}\n"},"lib/solady/src/utils/SafeTransferLib.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)\n/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)\n///\n/// @dev Note:\n/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.\n/// - For ERC20s, this implementation won't check that a token has code,\n/// responsibility is delegated to the caller.\nlibrary SafeTransferLib {\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* CUSTOM ERRORS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev The ETH transfer has failed.\n error ETHTransferFailed();\n\n /// @dev The ERC20 `transferFrom` has failed.\n error TransferFromFailed();\n\n /// @dev The ERC20 `transfer` has failed.\n error TransferFailed();\n\n /// @dev The ERC20 `approve` has failed.\n error ApproveFailed();\n\n /// @dev The Permit2 operation has failed.\n error Permit2Failed();\n\n /// @dev The Permit2 amount must be less than `2**160 - 1`.\n error Permit2AmountOverflow();\n\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* CONSTANTS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.\n uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;\n\n /// @dev Suggested gas stipend for contract receiving ETH to perform a few\n /// storage reads and writes, but low enough to prevent griefing.\n uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;\n\n /// @dev The unique EIP-712 domain domain separator for the DAI token contract.\n bytes32 internal constant DAI_DOMAIN_SEPARATOR =\n 0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;\n\n /// @dev The address for the WETH9 contract on Ethereum mainnet.\n address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;\n\n /// @dev The canonical Permit2 address.\n /// [Github](https://github.com/Uniswap/permit2)\n /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)\n address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;\n\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* ETH OPERATIONS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.\n //\n // The regular variants:\n // - Forwards all remaining gas to the target.\n // - Reverts if the target reverts.\n // - Reverts if the current contract has insufficient balance.\n //\n // The force variants:\n // - Forwards with an optional gas stipend\n // (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).\n // - If the target reverts, or if the gas stipend is exhausted,\n // creates a temporary contract to force send the ETH via `SELFDESTRUCT`.\n // Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.\n // - Reverts if the current contract has insufficient balance.\n //\n // The try variants:\n // - Forwards with a mandatory gas stipend.\n // - Instead of reverting, returns whether the transfer succeeded.\n\n /// @dev Sends `amount` (in wei) ETH to `to`.\n function safeTransferETH(address to, uint256 amount) internal {\n /// @solidity memory-safe-assembly\n assembly {\n if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {\n mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n revert(0x1c, 0x04)\n }\n }\n }\n\n /// @dev Sends all the ETH in the current contract to `to`.\n function safeTransferAllETH(address to) internal {\n /// @solidity memory-safe-assembly\n assembly {\n // Transfer all the ETH and check if it succeeded or not.\n if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n revert(0x1c, 0x04)\n }\n }\n }\n\n /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.\n function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {\n /// @solidity memory-safe-assembly\n assembly {\n if lt(selfbalance(), amount) {\n mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n revert(0x1c, 0x04)\n }\n if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {\n mstore(0x00, to) // Store the address in scratch space.\n mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n }\n }\n }\n\n /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.\n function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {\n /// @solidity memory-safe-assembly\n assembly {\n if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n mstore(0x00, to) // Store the address in scratch space.\n mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n }\n }\n }\n\n /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.\n function forceSafeTransferETH(address to, uint256 amount) internal {\n /// @solidity memory-safe-assembly\n assembly {\n if lt(selfbalance(), amount) {\n mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n revert(0x1c, 0x04)\n }\n if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {\n mstore(0x00, to) // Store the address in scratch space.\n mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n }\n }\n }\n\n /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.\n function forceSafeTransferAllETH(address to) internal {\n /// @solidity memory-safe-assembly\n assembly {\n // forgefmt: disable-next-item\n if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n mstore(0x00, to) // Store the address in scratch space.\n mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n }\n }\n }\n\n /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.\n function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)\n internal\n returns (bool success)\n {\n /// @solidity memory-safe-assembly\n assembly {\n success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)\n }\n }\n\n /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.\n function trySafeTransferAllETH(address to, uint256 gasStipend)\n internal\n returns (bool success)\n {\n /// @solidity memory-safe-assembly\n assembly {\n success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)\n }\n }\n\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* ERC20 OPERATIONS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n /// Reverts upon failure.\n ///\n /// The `from` account must have at least `amount` approved for\n /// the current contract to manage.\n function safeTransferFrom(address token, address from, address to, uint256 amount) internal {\n /// @solidity memory-safe-assembly\n assembly {\n let m := mload(0x40) // Cache the free memory pointer.\n mstore(0x60, amount) // Store the `amount` argument.\n mstore(0x40, to) // Store the `to` argument.\n mstore(0x2c, shl(96, from)) // Store the `from` argument.\n mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.\n // Perform the transfer, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n )\n ) {\n mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x60, 0) // Restore the zero slot to zero.\n mstore(0x40, m) // Restore the free memory pointer.\n }\n }\n\n /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n ///\n /// The `from` account must have at least `amount` approved for the current contract to manage.\n function trySafeTransferFrom(address token, address from, address to, uint256 amount)\n internal\n returns (bool success)\n {\n /// @solidity memory-safe-assembly\n assembly {\n let m := mload(0x40) // Cache the free memory pointer.\n mstore(0x60, amount) // Store the `amount` argument.\n mstore(0x40, to) // Store the `to` argument.\n mstore(0x2c, shl(96, from)) // Store the `from` argument.\n mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.\n success :=\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n )\n mstore(0x60, 0) // Restore the zero slot to zero.\n mstore(0x40, m) // Restore the free memory pointer.\n }\n }\n\n /// @dev Sends all of ERC20 `token` from `from` to `to`.\n /// Reverts upon failure.\n ///\n /// The `from` account must have their entire balance approved for the current contract to manage.\n function safeTransferAllFrom(address token, address from, address to)\n internal\n returns (uint256 amount)\n {\n /// @solidity memory-safe-assembly\n assembly {\n let m := mload(0x40) // Cache the free memory pointer.\n mstore(0x40, to) // Store the `to` argument.\n mstore(0x2c, shl(96, from)) // Store the `from` argument.\n mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n // Read the balance, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)\n )\n ) {\n mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.\n amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.\n // Perform the transfer, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n )\n ) {\n mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x60, 0) // Restore the zero slot to zero.\n mstore(0x40, m) // Restore the free memory pointer.\n }\n }\n\n /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.\n /// Reverts upon failure.\n function safeTransfer(address token, address to, uint256 amount) internal {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x14, to) // Store the `to` argument.\n mstore(0x34, amount) // Store the `amount` argument.\n mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n // Perform the transfer, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n )\n ) {\n mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n }\n }\n\n /// @dev Sends all of ERC20 `token` from the current contract to `to`.\n /// Reverts upon failure.\n function safeTransferAll(address token, address to) internal returns (uint256 amount) {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.\n mstore(0x20, address()) // Store the address of the current contract.\n // Read the balance, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)\n )\n ) {\n mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x14, to) // Store the `to` argument.\n amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.\n mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n // Perform the transfer, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n )\n ) {\n mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n }\n }\n\n /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.\n /// Reverts upon failure.\n function safeApprove(address token, address to, uint256 amount) internal {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x14, to) // Store the `to` argument.\n mstore(0x34, amount) // Store the `amount` argument.\n mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n // Perform the approval, reverting upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n )\n ) {\n mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.\n revert(0x1c, 0x04)\n }\n mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n }\n }\n\n /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.\n /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,\n /// then retries the approval again (some tokens, e.g. USDT, requires this).\n /// Reverts upon failure.\n function safeApproveWithRetry(address token, address to, uint256 amount) internal {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x14, to) // Store the `to` argument.\n mstore(0x34, amount) // Store the `amount` argument.\n mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n // Perform the approval, retrying upon failure.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n )\n ) {\n mstore(0x34, 0) // Store 0 for the `amount`.\n mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.\n mstore(0x34, amount) // Store back the original `amount`.\n // Retry the approval, reverting upon failure.\n if iszero(\n and(\n or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n )\n ) {\n mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.\n revert(0x1c, 0x04)\n }\n }\n mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n }\n }\n\n /// @dev Returns the amount of ERC20 `token` owned by `account`.\n /// Returns zero if the `token` does not exist.\n function balanceOf(address token, address account) internal view returns (uint256 amount) {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x14, account) // Store the `account` argument.\n mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n amount :=\n mul( // The arguments of `mul` are evaluated from right to left.\n mload(0x20),\n and( // The arguments of `and` are evaluated from right to left.\n gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)\n )\n )\n }\n }\n\n /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n /// If the initial attempt fails, try to use Permit2 to transfer the token.\n /// Reverts upon failure.\n ///\n /// The `from` account must have at least `amount` approved for the current contract to manage.\n function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {\n if (!trySafeTransferFrom(token, from, to, amount)) {\n permit2TransferFrom(token, from, to, amount);\n }\n }\n\n /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.\n /// Reverts upon failure.\n function permit2TransferFrom(address token, address from, address to, uint256 amount)\n internal\n {\n /// @solidity memory-safe-assembly\n assembly {\n let m := mload(0x40)\n mstore(add(m, 0x74), shr(96, shl(96, token)))\n mstore(add(m, 0x54), amount)\n mstore(add(m, 0x34), to)\n mstore(add(m, 0x20), shl(96, from))\n // `transferFrom(address,address,uint160,address)`.\n mstore(m, 0x36c78516000000000000000000000000)\n let p := PERMIT2\n let exists := eq(chainid(), 1)\n if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }\n if iszero(and(call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), exists)) {\n mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.\n revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)\n }\n }\n }\n\n /// @dev Permit a user to spend a given amount of\n /// another user's tokens via native EIP-2612 permit if possible, falling\n /// back to Permit2 if native permit fails or is not implemented on the token.\n function permit2(\n address token,\n address owner,\n address spender,\n uint256 amount,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n bool success;\n /// @solidity memory-safe-assembly\n assembly {\n for {} shl(96, xor(token, WETH9)) {} {\n mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.\n // Gas stipend to limit gas burn for tokens that don't refund gas when\n // an non-existing function is called. 5K should be enough for a SLOAD.\n staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)\n )\n ) { break }\n // After here, we can be sure that token is a contract.\n let m := mload(0x40)\n mstore(add(m, 0x34), spender)\n mstore(add(m, 0x20), shl(96, owner))\n mstore(add(m, 0x74), deadline)\n if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {\n mstore(0x14, owner)\n mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.\n mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))\n mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.\n // `nonces` is already at `add(m, 0x54)`.\n // `1` is already stored at `add(m, 0x94)`.\n mstore(add(m, 0xb4), and(0xff, v))\n mstore(add(m, 0xd4), r)\n mstore(add(m, 0xf4), s)\n success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)\n break\n }\n mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.\n mstore(add(m, 0x54), amount)\n mstore(add(m, 0x94), and(0xff, v))\n mstore(add(m, 0xb4), r)\n mstore(add(m, 0xd4), s)\n success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)\n break\n }\n }\n if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);\n }\n\n /// @dev Simple permit on the Permit2 contract.\n function simplePermit2(\n address token,\n address owner,\n address spender,\n uint256 amount,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n /// @solidity memory-safe-assembly\n assembly {\n let m := mload(0x40)\n mstore(m, 0x927da105) // `allowance(address,address,address)`.\n {\n let addressMask := shr(96, not(0))\n mstore(add(m, 0x20), and(addressMask, owner))\n mstore(add(m, 0x40), and(addressMask, token))\n mstore(add(m, 0x60), and(addressMask, spender))\n mstore(add(m, 0xc0), and(addressMask, spender))\n }\n let p := mul(PERMIT2, iszero(shr(160, amount)))\n if iszero(\n and( // The arguments of `and` are evaluated from right to left.\n gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.\n staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)\n )\n ) {\n mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.\n revert(add(0x18, shl(2, iszero(p))), 0x04)\n }\n mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).\n // `owner` is already `add(m, 0x20)`.\n // `token` is already at `add(m, 0x40)`.\n mstore(add(m, 0x60), amount)\n mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.\n // `nonce` is already at `add(m, 0xa0)`.\n // `spender` is already at `add(m, 0xc0)`.\n mstore(add(m, 0xe0), deadline)\n mstore(add(m, 0x100), 0x100) // `signature` offset.\n mstore(add(m, 0x120), 0x41) // `signature` length.\n mstore(add(m, 0x140), r)\n mstore(add(m, 0x160), s)\n mstore(add(m, 0x180), shl(248, v))\n if iszero(call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00)) {\n mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.\n revert(0x1c, 0x04)\n }\n }\n }\n}\n"},"lib/solady/src/utils/MetadataReaderLib.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Library for reading contract metadata robustly.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MetadataReaderLib.sol)\nlibrary MetadataReaderLib {\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* CONSTANTS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev Default gas stipend for contract reads. High enough for most practical use cases\n /// (able to SLOAD about 1000 bytes of data), but low enough to prevent griefing.\n uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;\n\n /// @dev Default string byte length limit.\n uint256 internal constant STRING_LIMIT_DEFAULT = 1000;\n\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* METADATA READING OPERATIONS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n // Best-effort string reading operations.\n // Should NOT revert as long as sufficient gas is provided.\n //\n // Performs the following in order:\n // 1. Returns the empty string for the following cases:\n // - Reverts.\n // - No returndata (e.g. function returns nothing, EOA).\n // - Returns empty string.\n // 2. Attempts to `abi.decode` the returndata into a string.\n // 3. With any remaining gas, scans the returndata from start to end for the\n // null byte '\\0', to interpret the returndata as a null-terminated string.\n\n /// @dev Equivalent to `readString(abi.encodeWithSignature(\"name()\"))`.\n function readName(address target) internal view returns (string memory) {\n return _string(target, _ptr(0x06fdde03), STRING_LIMIT_DEFAULT, GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Equivalent to `readString(abi.encodeWithSignature(\"name()\"), limit)`.\n function readName(address target, uint256 limit) internal view returns (string memory) {\n return _string(target, _ptr(0x06fdde03), limit, GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Equivalent to `readString(abi.encodeWithSignature(\"name()\"), limit, gasStipend)`.\n function readName(address target, uint256 limit, uint256 gasStipend)\n internal\n view\n returns (string memory)\n {\n return _string(target, _ptr(0x06fdde03), limit, gasStipend);\n }\n\n /// @dev Equivalent to `readString(abi.encodeWithSignature(\"symbol()\"))`.\n function readSymbol(address target) internal view returns (string memory) {\n return _string(target, _ptr(0x95d89b41), STRING_LIMIT_DEFAULT, GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Equivalent to `readString(abi.encodeWithSignature(\"symbol()\"), limit)`.\n function readSymbol(address target, uint256 limit) internal view returns (string memory) {\n return _string(target, _ptr(0x95d89b41), limit, GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Equivalent to `readString(abi.encodeWithSignature(\"symbol()\"), limit, gasStipend)`.\n function readSymbol(address target, uint256 limit, uint256 gasStipend)\n internal\n view\n returns (string memory)\n {\n return _string(target, _ptr(0x95d89b41), limit, gasStipend);\n }\n\n /// @dev Performs a best-effort string query on `target` with `data` as the calldata.\n /// The string will be truncated to `STRING_LIMIT_DEFAULT` (1000) bytes.\n function readString(address target, bytes memory data) internal view returns (string memory) {\n return _string(target, _ptr(data), STRING_LIMIT_DEFAULT, GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Performs a best-effort string query on `target` with `data` as the calldata.\n /// The string will be truncated to `limit` bytes.\n function readString(address target, bytes memory data, uint256 limit)\n internal\n view\n returns (string memory)\n {\n return _string(target, _ptr(data), limit, GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Performs a best-effort string query on `target` with `data` as the calldata.\n /// The string will be truncated to `limit` bytes.\n function readString(address target, bytes memory data, uint256 limit, uint256 gasStipend)\n internal\n view\n returns (string memory)\n {\n return _string(target, _ptr(data), limit, gasStipend);\n }\n\n // Best-effort unsigned integer reading operations.\n // Should NOT revert as long as sufficient gas is provided.\n //\n // Performs the following in order:\n // 1. Attempts to `abi.decode` the result into a uint256\n // (equivalent across all Solidity uint types, downcast as needed).\n // 2. Returns zero for the following cases:\n // - Reverts.\n // - No returndata (e.g. function returns nothing, EOA).\n // - Returns zero.\n // - `abi.decode` failure.\n\n /// @dev Equivalent to `uint8(readUint(abi.encodeWithSignature(\"decimal()\")))`.\n function readDecimals(address target) internal view returns (uint8) {\n return uint8(_uint(target, _ptr(0x313ce567), GAS_STIPEND_NO_GRIEF));\n }\n\n /// @dev Equivalent to `uint8(readUint(abi.encodeWithSignature(\"decimal()\"), gasStipend))`.\n function readDecimals(address target, uint256 gasStipend) internal view returns (uint8) {\n return uint8(_uint(target, _ptr(0x313ce567), gasStipend));\n }\n\n /// @dev Performs a best-effort uint query on `target` with `data` as the calldata.\n function readUint(address target, bytes memory data) internal view returns (uint256) {\n return _uint(target, _ptr(data), GAS_STIPEND_NO_GRIEF);\n }\n\n /// @dev Performs a best-effort uint query on `target` with `data` as the calldata.\n function readUint(address target, bytes memory data, uint256 gasStipend)\n internal\n view\n returns (uint256)\n {\n return _uint(target, _ptr(data), gasStipend);\n }\n\n /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n /* PRIVATE HELPERS */\n /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n /// @dev Attempts to read and return a string at `target`.\n function _string(address target, bytes32 ptr, uint256 limit, uint256 gasStipend)\n private\n view\n returns (string memory result)\n {\n /// @solidity memory-safe-assembly\n assembly {\n function min(x_, y_) -> _z {\n _z := xor(x_, mul(xor(x_, y_), lt(y_, x_)))\n }\n for {} staticcall(gasStipend, target, add(ptr, 0x20), mload(ptr), 0x00, 0x20) {} {\n let m := mload(0x40) // Grab the free memory pointer.\n let s := add(0x20, m) // Start of the string's bytes in memory.\n // Attempt to `abi.decode` if the returndatasize is greater or equal to 64.\n if iszero(lt(returndatasize(), 0x40)) {\n let o := mload(0x00) // Load the string's offset in the returndata.\n // If the string's offset is within bounds.\n if iszero(gt(o, sub(returndatasize(), 0x20))) {\n returndatacopy(m, o, 0x20) // Copy the string's length.\n // If the full string's end is within bounds.\n // Note: If the full string doesn't fit, the `abi.decode` must be aborted\n // for compliance purposes, regardless if the truncated string can fit.\n if iszero(gt(mload(m), sub(returndatasize(), add(o, 0x20)))) {\n let n := min(mload(m), limit) // Truncate if needed.\n mstore(m, n) // Overwrite the length.\n returndatacopy(s, add(o, 0x20), n) // Copy the string's bytes.\n mstore(add(s, n), 0) // Zeroize the slot after the string.\n mstore(0x40, add(0x20, add(s, n))) // Allocate memory for the string.\n result := m\n break\n }\n }\n }\n // Try interpreting as a null-terminated string.\n let n := min(returndatasize(), limit) // Truncate if needed.\n returndatacopy(s, 0, n) // Copy the string's bytes.\n mstore8(add(s, n), 0) // Place a '\\0' at the end.\n let i := s // Pointer to the next byte to scan.\n for {} byte(0, mload(i)) { i := add(i, 1) } {} // Scan for '\\0'.\n mstore(m, sub(i, s)) // Store the string's length.\n mstore(i, 0) // Zeroize the slot after the string.\n mstore(0x40, add(0x20, i)) // Allocate memory for the string.\n result := m\n break\n }\n }\n }\n\n /// @dev Attempts to read and return a uint at `target`.\n function _uint(address target, bytes32 ptr, uint256 gasStipend)\n private\n view\n returns (uint256 result)\n {\n /// @solidity memory-safe-assembly\n assembly {\n result :=\n mul(\n mload(0x20),\n and( // The arguments of `and` are evaluated from right to left.\n gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n staticcall(gasStipend, target, add(ptr, 0x20), mload(ptr), 0x20, 0x20)\n )\n )\n }\n }\n\n /// @dev Casts the function selector `s` into a pointer.\n function _ptr(uint256 s) private pure returns (bytes32 result) {\n /// @solidity memory-safe-assembly\n assembly {\n // Layout the calldata in the scratch space for temporary usage.\n mstore(0x04, s) // Store the function selector.\n mstore(result, 4) // Store the length.\n }\n }\n\n /// @dev Casts the `data` into a pointer.\n function _ptr(bytes memory data) private pure returns (bytes32 result) {\n /// @solidity memory-safe-assembly\n assembly {\n result := data\n }\n }\n}\n"}},"settings":{"remappings":["ds-test/=lib/forge-std/lib/ds-test/src/","forge-std/=lib/forge-std/src/","solady/=lib/solady/src/"],"optimizer":{"enabled":true,"runs":9999999},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs","appendCBOR":true},"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata"]}},"evmVersion":"cancun","viaIR":true,"libraries":{}}} diff --git a/foundry.toml b/foundry.toml index cf54955..22929b7 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,10 +1,12 @@ [profile.default] -solc_version = "0.8.24" -evm_version = "shanghai" +solc_version = "0.8.25" +evm_version = "cancun" optimizer = true optimizer_runs = 9_999_999 +via_ir = true + [fmt] line_length = 100 diff --git a/lib/forge-std b/lib/forge-std index 1d0766b..e4aef94 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 1d0766bc5d814f117c7b1e643828f7d85024fb51 +Subproject commit e4aef94c1768803a16fe19f7ce8b65defd027cfd diff --git a/lib/solady b/lib/solady index 1372606..e4a14a5 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit 1372606383445c0a247e6c58eb255a529734258a +Subproject commit e4a14a5b365b353352f7c38e699a2bc9363d6576 diff --git a/scripts/initCode.sh b/scripts/initCode.sh new file mode 100644 index 0000000..3abfab2 --- /dev/null +++ b/scripts/initCode.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo $(cast concat-hex "$(forge inspect $1 bytecode)" "$(cast abi-encode "constructor($(forge inspect $1 abi \ + | jq -r '.[] | select(.type == "constructor") | .inputs | map(.type) | join(",")'))" ${@:2})") \ No newline at end of file diff --git a/scripts/initCodeHash.sh b/scripts/initCodeHash.sh new file mode 100644 index 0000000..d053302 --- /dev/null +++ b/scripts/initCodeHash.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo $(cast keccak $(cast concat-hex "$(forge inspect $1 bytecode)" "$(cast abi-encode "constructor($(forge inspect $1 abi \ + | jq -r '.[] | select(.type == "constructor") | .inputs | map(.type) | join(",")'))" ${@:2})")) \ No newline at end of file diff --git a/src/IE.sol b/src/IE.sol index 07b695f..7b857de 100644 --- a/src/IE.sol +++ b/src/IE.sol @@ -10,7 +10,7 @@ import {MetadataReaderLib} from "../lib/solady/src/utils/MetadataReaderLib.sol"; /// @dev V1 simulates typical commands (sending and swapping tokens) and includes execution. /// IE also has a workflow to verify the intent of ERC4337 account userOps against calldata. /// @author nani.eth (https://github.com/NaniDAO/ie) -/// @custom:version 1.0.0 +/// @custom:version 1.2.0 contract IE { /// ======================= LIBRARY USAGE ======================= /// @@ -25,9 +25,6 @@ contract IE { /// @dev Bad math. error Overflow(); - /// @dev Caller fails. - error Unauthorized(); - /// @dev 0-liquidity. error InvalidSwap(); @@ -45,6 +42,9 @@ contract IE { /// @dev Logs the registration of a token name. event NameSet(address indexed token, string name); + /// @dev Logs the registration of a token swap pool pair route on Uniswap V3. + event PairSet(address indexed token0, address indexed token1, address pair); + /// ========================== STRUCTS ========================== /// /// @dev The ERC4337 user operation (userOp) struct. @@ -62,7 +62,7 @@ contract IE { bytes signature; } - /// @dev The packed ERC4337 user operation (userOp) struct. + /// @dev The packed ERC4337 userOp struct. struct PackedUserOperation { address sender; uint256 nonce; @@ -70,13 +70,13 @@ contract IE { bytes callData; bytes32 accountGasLimits; uint256 preVerificationGas; - bytes32 gasFees; // `maxPriorityFee` and `maxFeePerGas`. + bytes32 gasFees; bytes paymasterAndData; bytes signature; } - /// @dev The `swap` command details. - struct SwapDetails { + /// @dev The `swap` command information struct. + struct SwapInfo { address tokenIn; address tokenOut; uint256 amountIn; @@ -84,12 +84,10 @@ contract IE { bool ETHOut; } - /// =========================== ENUMS =========================== /// - - /// @dev `ENSAsciiNormalizer` rules. - enum Rule { - DISALLOWED, - VALID + /// @dev The `swap` pool liquidity struct. + struct SwapLiq { + address pool; + uint256 liq; } /// ========================= CONSTANTS ========================= /// @@ -98,33 +96,34 @@ contract IE { address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA; /// @dev The NANI token address. - address internal constant NANI = 0x00000000000025824328358250920B271f348690; + address internal constant NANI = 0x000000000000C6A645b0E51C9eCAA4CA580Ed8e8; /// @dev The conventional ERC7528 ETH address. address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; /// @dev The canonical wrapped ETH address. - address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; + address internal constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; /// @dev The popular wrapped BTC address. - address internal constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599; + address internal constant WBTC = 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f; /// @dev The Circle USD stablecoin address. - address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; + address internal constant USDC = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831; /// @dev The Tether USD stablecoin address. - address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7; + address internal constant USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9; /// @dev The Maker DAO USD stablecoin address. - address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; + address internal constant DAI = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; - /// @dev ENS fallback registry contract. - IENSHelper internal constant ENS_REGISTRY = - IENSHelper(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e); + /// @dev The Arbitrum DAO governance token address. + address internal constant ARB = 0x912CE59144191C1204E64559FE8253a0e49E6548; - /// @dev ENS name wrapper token contract. - IENSHelper internal constant ENS_WRAPPER = - IENSHelper(0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401); + /// @dev The Lido Wrapped Staked ETH token address. + address internal constant WSTETH = 0x5979D7b546E38E414F7E9822514be443A4800529; + + /// @dev The Rocket Pool Staked ETH token address. + address internal constant RETH = 0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8; /// @dev The address of the Uniswap V3 Factory. address internal constant UNISWAP_V3_FACTORY = 0x1F98431c8aD98523631AE4a59f267346ea31F984; @@ -140,39 +139,25 @@ contract IE { uint160 internal constant MAX_SQRT_RATIO_MINUS_ONE = 1461446703485210103287273052203988822378723970341; - /// @dev String mapping for `ENSAsciiNormalizer` logic. - bytes internal constant ASCII_MAP = - hex"2d00020101000a010700016101620163016401650166016701680169016a016b016c016d016e016f0170017101720173017401750176017701780179017a06001a010500"; + /// @dev The NAMI naming system on Arbitrum. + INAMI internal constant NAMI = INAMI(0x000000006641B4C250AEA6B62A1e0067D300697a); /// ========================== STORAGE ========================== /// /// @dev DAO-governed token address naming. mapping(string name => address) public tokens; - /// @dev Each index in idnamap refers to an ascii code point. - /// If idnamap[char] > 2, char maps to a valid ascii character. - /// Otherwise, idna[char] returns Rule.DISALLOWED or Rule.VALID. - /// Modified from `ENSAsciiNormalizer` deployed by royalfork.eth - /// (0x4A5cae3EC0b144330cf1a6CeAD187D8F6B891758). - bytes1[] internal _idnamap; + /// @dev DAO-governed token swap pool routing on Uniswap V3. + mapping(address token0 => mapping(address token1 => address)) public pairs; /// ======================== CONSTRUCTOR ======================== /// - /// @dev Constructs this IE with `ASCII_MAP`. - constructor() payable { - unchecked { - for (uint256 i; i != ASCII_MAP.length; i += 2) { - bytes1 r = ASCII_MAP[i + 1]; - for (uint8 j; j != uint8(ASCII_MAP[i]); ++j) { - _idnamap.push(r); - } - } - } - } + /// @dev Constructs this IE on the Arbitrum L2 of Ethereum. + constructor() payable {} /// ====================== COMMAND PREVIEW ====================== /// - /// @notice Preview natural language smart contract command. + /// @dev Preview natural language smart contract command. /// The `send` syntax uses ENS naming: 'send vitalik 20 DAI'. /// `swap` syntax uses common format: 'swap 100 DAI for WETH'. function previewCommand(string calldata intent) @@ -190,11 +175,14 @@ contract IE { { string memory normalized = _lowercase(intent); bytes32 action = _extraction(normalized); - if (action == "send" || action == "transfer") { + if (action == "send" || action == "transfer" || action == "pay" || action == "grant") { (string memory _to, string memory _amount, string memory _token) = _extractSend(normalized); (to, amount, token, callData, executeCallData) = previewSend(_to, _amount, _token); - } else if (action == "swap" || action == "exchange") { + } else if ( + action == "swap" || action == "exchange" || action == "stake" || action == "deposit" + || action == "unstake" || action == "withdraw" + ) { ( string memory amountIn, string memory amountOutMinimum, @@ -221,11 +209,12 @@ contract IE { bytes memory executeCallData ) { - _token = _returnTokenConstant(bytes32(bytes(token))); // Check constant. + uint256 decimals; + (_token, decimals) = _returnTokenConstants(bytes32(bytes(token))); if (_token == address(0)) _token = tokens[token]; // Check storage. bool isETH = _token == ETH; // Memo whether the token is ETH or not. (, _to,) = whatIsTheAddressOf(to); // Fetch receiver address from ENS. - _amount = _stringToUint(amount, isETH ? 18 : _token.readDecimals()); + _amount = _toUint(amount, decimals != 0 ? decimals : _token.readDecimals()); if (!isETH) callData = abi.encodeCall(IToken.transfer, (_to, _amount)); executeCallData = abi.encodeCall(IExecutor.execute, (isETH ? _to : _token, isETH ? _amount : 0, callData)); @@ -243,13 +232,15 @@ contract IE { virtual returns (uint256 _amountIn, uint256 _amountOut, address _tokenIn, address _tokenOut) { - _tokenIn = _returnTokenConstant(bytes32(bytes(tokenIn))); + uint256 decimalsIn; + uint256 decimalsOut; + (_tokenIn, decimalsIn) = _returnTokenConstants(bytes32(bytes(tokenIn))); if (_tokenIn == address(0)) _tokenIn = tokens[tokenIn]; - _tokenOut = _returnTokenConstant(bytes32(bytes(tokenOut))); + (_tokenOut, decimalsOut) = _returnTokenConstants(bytes32(bytes(tokenOut))); if (_tokenOut == address(0)) _tokenOut = tokens[tokenOut]; - _amountIn = _stringToUint(amountIn, _tokenIn == ETH ? 18 : _tokenIn.readDecimals()); + _amountIn = _toUint(amountIn, decimalsIn != 0 ? decimalsIn : _tokenIn.readDecimals()); _amountOut = - _stringToUint(amountOutMinimum, _tokenOut == ETH ? 18 : _tokenOut.readDecimals()); + _toUint(amountOutMinimum, decimalsOut != 0 ? decimalsOut : _tokenOut.readDecimals()); } /// @dev Checks ERC4337 userOp against the output of the command intent. @@ -277,14 +268,38 @@ contract IE { } /// @dev Checks and returns the canonical token address constant for a matched intent string. - function _returnTokenConstant(bytes32 token) internal view virtual returns (address _token) { - if (token == "eth" || token == "ether") return ETH; - if (token == "usdc") return USDC; - if (token == "usdt") return USDT; - if (token == "dai") return DAI; - if (token == "nani") return NANI; - if (token == "weth") return WETH; - if (token == "wbtc" || token == "btc" || token == "bitcoin") return WBTC; + function _returnTokenConstants(bytes32 token) + internal + pure + virtual + returns (address _token, uint256 _decimals) + { + if (token == "eth" || token == "ether") return (ETH, 18); + if (token == "usdc") return (USDC, 6); + if (token == "usdt" || token == "tether") return (USDT, 6); + if (token == "dai") return (DAI, 18); + if (token == "arb" || token == "arbitrum") return (ARB, 18); + if (token == "weth") return (WETH, 18); + if (token == "wbtc" || token == "btc" || token == "bitcoin") return (WBTC, 8); + if (token == "steth" || token == "wsteth" || token == "lido") return (WSTETH, 18); + if (token == "reth") return (RETH, 18); + if (token == "nani") return (NANI, 18); + } + + /// @dev Checks and returns popular pool pairs for WETH swaps. + function _returnPoolConstants(address token0, address token1) + internal + pure + virtual + returns (address pool) + { + if (token0 == WSTETH && token1 == WETH) return 0x35218a1cbaC5Bbc3E57fd9Bd38219D37571b3537; + if (token0 == WETH && token1 == RETH) return 0x09ba302A3f5ad2bF8853266e271b005A5b3716fe; + if (token0 == WETH && token1 == USDC) return 0xC6962004f452bE9203591991D15f6b388e09E8D0; + if (token0 == WETH && token1 == USDT) return 0x641C00A822e8b671738d32a431a4Fb6074E5c79d; + if (token0 == WETH && token1 == DAI) return 0xA961F0473dA4864C5eD28e00FcC53a3AAb056c1b; + if (token0 == WETH && token1 == ARB) return 0xC6F780497A95e246EB9449f5e4770916DCd6396A; + if (token0 == WBTC && token1 == WETH) return 0x2f5e87C9312fa29aed5c179E456625D79015299c; } /// ===================== COMMAND EXECUTION ===================== /// @@ -293,10 +308,13 @@ contract IE { function command(string calldata intent) public payable virtual { string memory normalized = _lowercase(intent); bytes32 action = _extraction(normalized); - if (action == "send" || action == "transfer") { + if (action == "send" || action == "transfer" || action == "pay" || action == "grant") { (string memory to, string memory amount, string memory token) = _extractSend(normalized); send(to, amount, token); - } else if (action == "swap" || action == "exchange") { + } else if ( + action == "swap" || action == "exchange" || action == "stake" || action == "deposit" + || action == "unstake" || action == "withdraw" + ) { ( string memory amountIn, string memory amountOutMinimum, @@ -315,13 +333,15 @@ contract IE { payable virtual { - address _token = _returnTokenConstant(bytes32(bytes(token))); + (address _token, uint256 decimals) = _returnTokenConstants(bytes32(bytes(token))); if (_token == address(0)) _token = tokens[token]; (, address _to,) = whatIsTheAddressOf(to); if (_token == ETH) { - _to.safeTransferETH(_stringToUint(amount, 18)); + _to.safeTransferETH(_toUint(amount, decimals)); } else { - _token.safeTransferFrom(msg.sender, _to, _stringToUint(amount, _token.readDecimals())); + _token.safeTransferFrom( + msg.sender, _to, _toUint(amount, decimals != 0 ? decimals : _token.readDecimals()) + ); } } @@ -332,33 +352,33 @@ contract IE { string memory tokenIn, string memory tokenOut ) public payable virtual { - SwapDetails memory details; - details.tokenIn = _returnTokenConstant(bytes32(bytes(tokenIn))); - if (details.tokenIn == address(0)) details.tokenIn = tokens[tokenIn]; - details.tokenOut = _returnTokenConstant(bytes32(bytes(tokenOut))); - if (details.tokenOut == address(0)) details.tokenOut = tokens[tokenOut]; - - details.ETHIn = details.tokenIn == ETH; - if (details.ETHIn) details.tokenIn = WETH; - details.ETHOut = details.tokenOut == ETH; - if (details.ETHOut) details.tokenOut = WETH; - - details.amountIn = - _stringToUint(amountIn, details.ETHIn ? 18 : details.tokenIn.readDecimals()); - if (details.amountIn >= 1 << 255) revert Overflow(); - (address pool, bool zeroForOne) = _computePoolAddress(details.tokenIn, details.tokenOut); + SwapInfo memory info; + uint256 decimalsIn; + uint256 decimalsOut; + (info.tokenIn, decimalsIn) = _returnTokenConstants(bytes32(bytes(tokenIn))); + if (info.tokenIn == address(0)) info.tokenIn = tokens[tokenIn]; + (info.tokenOut, decimalsOut) = _returnTokenConstants(bytes32(bytes(tokenOut))); + if (info.tokenOut == address(0)) info.tokenOut = tokens[tokenOut]; + info.ETHIn = info.tokenIn == ETH; + if (info.ETHIn) info.tokenIn = WETH; + info.ETHOut = info.tokenOut == ETH; + if (info.ETHOut) info.tokenOut = WETH; + info.amountIn = + _toUint(amountIn, decimalsIn != 0 ? decimalsIn : info.tokenIn.readDecimals()); + if (info.amountIn >= 1 << 255) revert Overflow(); + (address pool, bool zeroForOne) = _computePoolAddress(info.tokenIn, info.tokenOut); (int256 amount0, int256 amount1) = ISwapRouter(pool).swap( - !details.ETHOut ? msg.sender : address(this), + !info.ETHOut ? msg.sender : address(this), zeroForOne, - int256(details.amountIn), + int256(info.amountIn), zeroForOne ? MIN_SQRT_RATIO_PLUS_ONE : MAX_SQRT_RATIO_MINUS_ONE, - abi.encodePacked( - details.ETHIn, details.ETHOut, msg.sender, details.tokenIn, details.tokenOut - ) + abi.encodePacked(info.ETHIn, info.ETHOut, msg.sender, info.tokenIn, info.tokenOut) ); if ( uint256(-(zeroForOne ? amount1 : amount0)) - < _stringToUint(amountOutMinimum, details.ETHOut ? 18 : details.tokenOut.readDecimals()) + < _toUint( + amountOutMinimum, decimalsOut != 0 ? decimalsOut : info.tokenOut.readDecimals() + ) ) revert InsufficientSwap(); } @@ -383,7 +403,9 @@ contract IE { } if (amount0Delta <= 0 && amount1Delta <= 0) revert InvalidSwap(); (address pool, bool zeroForOne) = _computePoolAddress(tokenIn, tokenOut); - if (msg.sender != pool) revert Unauthorized(); // Only pair pool can call. + assembly ("memory-safe") { + if iszero(eq(caller(), pool)) { revert(codesize(), 0x00) } + } if (ETHIn) { _wrapETH(uint256(zeroForOne ? amount0Delta : amount1Delta)); } else { @@ -399,6 +421,7 @@ contract IE { } /// @dev Computes the create2 address for given token pair. + /// note: This process checks all available pools for price. function _computePoolAddress(address tokenA, address tokenB) internal view @@ -407,17 +430,35 @@ contract IE { { if (tokenA < tokenB) zeroForOne = true; else (tokenA, tokenB) = (tokenB, tokenA); - pool = _computePairHash(tokenA, tokenB, 3000); // Mid fee. - if (pool.code.length != 0) return (pool, zeroForOne); - else pool = _computePairHash(tokenA, tokenB, 500); // Low fee. - if (pool.code.length != 0) return (pool, zeroForOne); - else pool = _computePairHash(tokenA, tokenB, 100); // Lowest fee. - if (pool.code.length != 0) return (pool, zeroForOne); - else pool = _computePairHash(tokenA, tokenB, 10000); // Highest fee. - if (pool.code.length != 0) return (pool, zeroForOne); + pool = _returnPoolConstants(tokenA, tokenB); + if (pool == address(0)) { + pool = pairs[tokenA][tokenB]; + if (pool == address(0)) { + address pool100 = _computePairHash(tokenA, tokenB, 100); // Lowest fee. + address pool500 = _computePairHash(tokenA, tokenB, 500); // Lower fee. + address pool3000 = _computePairHash(tokenA, tokenB, 3000); // Mid fee. + address pool10000 = _computePairHash(tokenA, tokenB, 10000); // Hi fee. + // Initialize an array to hold the liquidity information for each pool. + SwapLiq[5] memory pools = [ + SwapLiq(pool100, pool100.code.length != 0 ? _balanceOf(tokenA, pool100) : 0), + SwapLiq(pool500, pool500.code.length != 0 ? _balanceOf(tokenA, pool500) : 0), + SwapLiq(pool3000, pool3000.code.length != 0 ? _balanceOf(tokenA, pool3000) : 0), + SwapLiq(pool10000, pool10000.code.length != 0 ? _balanceOf(tokenA, pool10000) : 0), + SwapLiq(pool, 0) // Placeholder for top pool. This will hold outputs for comparison. + ]; + // Iterate through the array to find the top pool with the highest liquidity in `tokenA`. + for (uint256 i; i != 4; ++i) { + if (pools[i].liq > pools[4].liq) { + pools[4].liq = pools[i].liq; + pools[4].pool = pools[i].pool; + } + } + pool = pools[4].pool; // Return the top pool with likely best liquidity. + } + } } - /// @dev Computes the create2 deployment hash for given token pair. + /// @dev Computes the create2 deployment hash for a given token pair. function _computePairHash(address token0, address token1, uint24 fee) internal pure @@ -456,9 +497,27 @@ contract IE { } } + /// @dev Returns the amount of ERC20 `token` owned by `account`. + function _balanceOf(address token, address account) + internal + view + virtual + returns (uint256 amount) + { + assembly ("memory-safe") { + mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`. + mstore(0x14, account) // Store the `account` argument. + pop(staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)) + amount := mload(0x20) + } + } + /// @dev ETH receiver fallback. + /// Only canonical WETH can call. receive() external payable virtual { - if (msg.sender != WETH) revert Unauthorized(); + assembly ("memory-safe") { + if iszero(eq(caller(), WETH)) { revert(codesize(), 0x00) } + } } /// ================== BALANCE & SUPPLY HELPERS ================== /// @@ -471,12 +530,11 @@ contract IE { returns (uint256 balance, uint256 balanceAdjusted) { (, address _name,) = whatIsTheAddressOf(name); - string memory normalized = _lowercase(token); - address _token = _returnTokenConstant(bytes32(bytes(normalized))); + (address _token, uint256 decimals) = + _returnTokenConstants(bytes32(bytes(_lowercase(token)))); if (_token == address(0)) _token = tokens[token]; - bool isETH = _token == ETH; - balance = isETH ? _name.balance : _token.balanceOf(_name); - balanceAdjusted = balance / 10 ** (isETH ? 18 : _token.readDecimals()); + balance = _token == ETH ? _name.balance : _token.balanceOf(_name); + balanceAdjusted = balance / 10 ** (decimals != 0 ? decimals : _token.readDecimals()); } /// @dev Returns the total supply of a named token. @@ -486,9 +544,9 @@ contract IE { virtual returns (uint256 supply, uint256 supplyAdjusted) { - address _token = _returnTokenConstant(bytes32(bytes(token))); + (address _token, uint256 decimals) = + _returnTokenConstants(bytes32(bytes(_lowercase(token)))); if (_token == address(0)) _token = tokens[token]; - if (_token == ETH) revert InvalidSyntax(); assembly ("memory-safe") { mstore(0x00, 0x18160ddd) // `totalSupply()`. if iszero(staticcall(gas(), _token, 0x1c, 0x04, 0x20, 0x20)) { @@ -496,7 +554,7 @@ contract IE { } supply := mload(0x20) } - supplyAdjusted = supply / 10 ** _token.readDecimals(); + supplyAdjusted = supply / 10 ** (decimals != 0 ? decimals : _token.readDecimals()); } /// ====================== ENS VERIFICATION ====================== /// @@ -508,45 +566,11 @@ contract IE { virtual returns (address owner, address receiver, bytes32 node) { - node = _namehash(string(abi.encodePacked(name, ".eth"))); - owner = ENS_REGISTRY.owner(node); - if (IENSHelper(owner) == ENS_WRAPPER) owner = ENS_WRAPPER.ownerOf(uint256(node)); - receiver = IENSHelper(ENS_REGISTRY.resolver(node)).addr(node); // Fails on misname. - } - - /// @dev Computes an ENS domain namehash. - function _namehash(string memory domain) internal view virtual returns (bytes32 node) { - // Process labels (in reverse order for namehash). - uint256 i = bytes(domain).length; - uint256 lastDot = i; - unchecked { - for (; i != 0; --i) { - bytes1 c = bytes(domain)[i - 1]; - if (c == ".") { - node = keccak256(abi.encodePacked(node, _labelhash(domain, i, lastDot))); - lastDot = i - 1; - continue; - } - require(c < 0x80); - bytes1 r = _idnamap[uint8(c)]; - require(uint8(r) != uint8(Rule.DISALLOWED)); - if (uint8(r) > 1) { - bytes(domain)[i - 1] = r; - } - } - } - return keccak256(abi.encodePacked(node, _labelhash(domain, i, lastDot))); - } - - /// @dev Computes an ENS domain labelhash given its start and end. - function _labelhash(string memory domain, uint256 start, uint256 end) - internal - pure - virtual - returns (bytes32 hash) - { - assembly ("memory-safe") { - hash := keccak256(add(add(domain, 0x20), start), sub(end, start)) + // If address length, convert. + if (bytes(name).length == 42) { + receiver = _toAddress(name); + } else { + (owner, receiver, node) = NAMI.whatIsTheAddressOf(name); } } @@ -554,7 +578,9 @@ contract IE { /// @dev Sets a public `name` tag for a given `token` address. Governed by DAO. function setName(address token, string calldata name) public payable virtual { - if (msg.sender != DAO) revert Unauthorized(); + assembly ("memory-safe") { + if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) } // Optimized for repeat. + } string memory normalized = _lowercase(name); emit NameSet(tokens[normalized] = token, normalized); } @@ -567,6 +593,15 @@ contract IE { emit NameSet(tokens[normalizedSymbol] = token, normalizedSymbol); } + /// @dev Sets a public pool `pair` for swapping. Governed by DAO. + function setPair(address tokenA, address tokenB, address pair) public payable virtual { + assembly ("memory-safe") { + if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) } // Optimized for repeat. + } + if (tokenB < tokenA) (tokenA, tokenB) = (tokenB, tokenA); + emit PairSet(tokenA, tokenB, pairs[tokenA][tokenB] = pair); + } + /// ===================== STRING OPERATIONS ===================== /// /// @dev Returns copy of string in lowercase. @@ -680,7 +715,7 @@ contract IE { } /// @dev Convert string to decimalized numerical value. - function _stringToUint(string memory s, uint8 decimals) + function _toUint(string memory s, uint256 decimals) internal pure virtual @@ -695,9 +730,7 @@ contract IE { result = result * 10 + uint8(b[i]) - 48; if (hasDecimal) { ++decimalPlaces; - if (decimalPlaces > decimals) { - break; - } + if (decimalPlaces > decimals) break; } } else if (b[i] == "." && !hasDecimal) { hasDecimal = true; @@ -710,14 +743,42 @@ contract IE { } } } -} -/// @dev ENS name resolution helper contracts interface. -interface IENSHelper { - function addr(bytes32) external view returns (address); - function owner(bytes32) external view returns (address); - function ownerOf(uint256) external view returns (address); - function resolver(bytes32) external view returns (address); + /// @dev Converts a hexadecimal string to its `address` representation. + /// Modified from Stack (https://ethereum.stackexchange.com/a/156916). + function _toAddress(string memory s) internal pure virtual returns (address addr) { + bytes memory _bytes = _hexStringToAddress(s); + if (_bytes.length < 21) revert InvalidSyntax(); + assembly ("memory-safe") { + addr := div(mload(add(add(_bytes, 0x20), 1)), 0x1000000000000000000000000) + } + } + + /// @dev Converts a hexadecimal string into its bytes representation. + function _hexStringToAddress(string memory s) internal pure virtual returns (bytes memory r) { + unchecked { + bytes memory ss = bytes(s); + if (ss.length % 2 != 0) revert InvalidSyntax(); // Length must be even. + r = new bytes(ss.length / 2); + for (uint256 i; i != ss.length / 2; ++i) { + r[i] = + bytes1(_fromHexChar(uint8(ss[2 * i])) * 16 + _fromHexChar(uint8(ss[2 * i + 1]))); + } + } + } + + /// @dev Converts a single hexadecimal character into its numerical value. + function _fromHexChar(uint8 c) internal pure virtual returns (uint8 result) { + unchecked { + if (bytes1(c) >= bytes1("0") && bytes1(c) <= bytes1("9")) return c - uint8(bytes1("0")); + if (bytes1(c) >= bytes1("a") && bytes1(c) <= bytes1("f")) { + return 10 + c - uint8(bytes1("a")); + } + if (bytes1(c) >= bytes1("A") && bytes1(c) <= bytes1("F")) { + return 10 + c - uint8(bytes1("A")); + } + } + } } /// @dev Simple token transfer interface. @@ -730,6 +791,14 @@ interface IExecutor { function execute(address, uint256, bytes calldata) external payable returns (bytes memory); } +/// @dev Simple NAMI names interface for resolving L2 ENS ownership. +interface INAMI { + function whatIsTheAddressOf(string calldata) + external + view + returns (address, address, bytes32); +} + /// @dev Simple Uniswap V3 swapping interface. interface ISwapRouter { function swap(address, bool, int256, uint160, bytes calldata) diff --git a/src/NAMI.sol b/src/NAMI.sol new file mode 100644 index 0000000..a9258d9 --- /dev/null +++ b/src/NAMI.sol @@ -0,0 +1,271 @@ +// ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ ⌘ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.19; + +/// @title NANI ARBITRUM MAGIC INVOICING (NAMI) +/// @notice A contract for managing ENS domain name ownership and resolution on Arbitrum L2. +/// @dev Provides logic for registering names, verifying ownership, and resolving addresses. +/// @author nani.eth (https://github.com/NaniDAO/ie) +/// @custom:version 1.0.0 +contract NAMI { + /// ======================= CUSTOM ERRORS ======================= /// + + /// @dev Unregistered. + error Unregistered(); + + /// =========================== EVENTS =========================== /// + + /// @dev Logs the registration of a name node into ownership. + event Registered(bytes32 indexed node, Ownership ownership); + + /// ========================== STRUCTS ========================== /// + + /// @dev The name node ownership information struct. + struct Ownership { + address owner; + bool subnode; + } + + /// =========================== ENUMS =========================== /// + + /// @dev `ENSAsciiNormalizer` rules. + enum Rule { + DISALLOWED, + VALID + } + + /// ========================= CONSTANTS ========================= /// + + /// @dev The governing DAO address. + address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA; + + /// @dev L1_DEPLOYER represents the address responsible for deploying ENS proxy contracts on Ethereum Layer 1. + /// This address is typically used in conjunction with create2 operations for deterministic deployment. + address internal constant L1_DEPLOYER = 0x000000008B009D81C933a72545Ed7500cbB5B9D1; + + /// @dev L2_DEPLOYER denotes the address that performs bridged ENS deployments on Arbitrum Layer 2. + /// Similar to L1_DEPLOYER, it's crucial for deterministic deployment but within the Arbitrum L2 context. + address internal constant L2_DEPLOYER = 0x3fE38087A94903A9D946fa1915e1772fe611000f; + + /// @dev IMPLEMENTATION refers to the address of the contract serving as the implementation for ENS proxies. + address internal constant IMPLEMENTATION = 0xEBb49317E567a40cF468c409409aD59a8f67ddE6; + + /// @dev COUNTERPART_GATEWAY is the address of the gateway contract on Arbitrum Layer 2 that pairs with a corresponding + /// gateway on Ethereum Layer 1. This gateway facilitates the bridging of tokens between L1 and L2, managing the + /// lock/mint and burn/release mechanics across layers. + address internal constant COUNTERPART_GATEWAY = 0x09e9222E96E7B4AE2a407B98d48e330053351EEe; + + /// @dev L2_HASH is a unique identifier, used as part of the create2 address computation for contracts on Arbitrum Layer 2. + bytes32 internal constant L2_HASH = + 0x4b11cb57b978697e0aec0c18581326376d6463fd3f6699cbe78ee5935617082d; + + /// @dev String mapping for `ENSAsciiNormalizer` logic. + bytes internal constant ASCII_MAP = + hex"2d00020101000a010700016101620163016401650166016701680169016a016b016c016d016e016f0170017101720173017401750176017701780179017a06001a010500"; + + /// ========================== STORAGE ========================== /// + + /// @dev Each index in idnamap refers to an ascii code point. + /// If idnamap[char] > 2, char maps to a valid ascii character. + /// Otherwise, idna[char] returns Rule.DISALLOWED or Rule.VALID. + /// Modified from `ENSAsciiNormalizer` deployed by royalfork.eth + /// (0x4A5cae3EC0b144330cf1a6CeAD187D8F6B891758). + bytes1[] internal _idnamap; + + /// @dev Internal mapping of registered node owners. + mapping(bytes32 node => Ownership) internal _owners; + + /// ======================== CONSTRUCTOR ======================== /// + + /// @dev Constructs this IE with `ASCII_MAP`. + constructor() payable { + unchecked { + for (uint256 i; i != ASCII_MAP.length; i += 2) { + bytes1 r = ASCII_MAP[i + 1]; + for (uint8 j; j != uint8(ASCII_MAP[i]); ++j) { + _idnamap.push(r); + } + } + } + } + + /// ====================== ENS VERIFICATION ====================== /// + + /// @dev Returns ENS name ownership information. + function whatIsTheAddressOf(string calldata name) + public + view + virtual + returns (address _owner, address _receiver, bytes32 _node) + { + _node = _namehash(string(abi.encodePacked(name, ".eth"))); + _owner = owner(_node); + _receiver = _owner; // On L2, owner receives for simplicity. + } + + /// @dev Computes an ENS domain namehash. + function _namehash(string memory domain) internal view virtual returns (bytes32 node) { + uint256 i = bytes(domain).length; + uint256 lastDot = i; + unchecked { + for (; i != 0; --i) { + bytes1 c = bytes(domain)[i - 1]; + if (c == ".") { + node = keccak256(abi.encodePacked(node, _labelhash(domain, i, lastDot))); + lastDot = i - 1; + continue; + } + require(c < 0x80); + bytes1 r = _idnamap[uint8(c)]; + require(uint8(r) != uint8(Rule.DISALLOWED)); + if (uint8(r) > 1) { + bytes(domain)[i - 1] = r; + } + } + } + return keccak256(abi.encodePacked(node, _labelhash(domain, i, lastDot))); + } + + /// @dev Computes an ENS domain labelhash given its start and end. + function _labelhash(string memory domain, uint256 start, uint256 end) + internal + pure + virtual + returns (bytes32 hash) + { + assembly ("memory-safe") { + hash := keccak256(add(add(domain, 0x20), start), sub(end, start)) + } + } + + /// ======================== REGISTRATION ======================== /// + + /// @dev Registers a name node under an owner. ENS L1 node must be bridged. + function register(address _owner, bytes32 _node) public payable virtual { + if (!isOwner(_owner, _node)) revert Unregistered(); + emit Registered(_node, _owners[_node] = Ownership(_owner, false)); + } + + /// @dev Registers a name subnode under an owner. Only the DAO may call this function. + function registerSub(address _owner, string calldata _subname) public payable virtual { + assembly ("memory-safe") { + if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) } // Optimized for repeat. + } + bytes32 subnode = _namehash(string(abi.encodePacked(_subname, ".nani.eth"))); + emit Registered(subnode, _owners[subnode] = Ownership(_owner, true)); // Yay. + } + + /// ====================== OWNERSHIP LOGIC ====================== /// + + /// @dev Returns the registered owner of a given ENS L1 node. Must be bridged. + /// note: Alternatively, NAMI provides subdomains issued under `nani.eth` node. + function owner(bytes32 _node) public view virtual returns (address _owner) { + Ownership storage ownership = _owners[_node]; + if (ownership.owner == address(0)) revert Unregistered(); + if (ownership.subnode) return ownership.owner; + if (isOwner(ownership.owner, _node)) return ownership.owner; + else revert Unregistered(); // Reverts for safety measure. + } + + /// @dev Checks if an address is the owner of a given ENS L1 node represented as `l2Token`. + /// note: NAMI operates under the assumption that the proper owner-receiver holds majority. + function isOwner(address _owner, bytes32 _node) public view virtual returns (bool) { + (, address l2Token) = predictDeterministicAddresses(_node); + unchecked { + return IToken(l2Token).balanceOf(_owner) > (IToken(l2Token).totalSupply() / 2); + } + } + + /// @dev Returns the deterministic create2 addresses for ENS node tokens on L1 & L2. + function predictDeterministicAddresses(bytes32 _node) + public + pure + virtual + returns (address l1Token, address l2Token) + { + l1Token = _predictDeterministicAddress(_initCodeHash(bytes.concat(_node)), _node); + l2Token = _calculateL2TokenAddress(l1Token); + } + + /// @dev Returns the predicted address on L1 using CWIA pattern. + function _predictDeterministicAddress(bytes32 hash, bytes32 salt) + internal + pure + virtual + returns (address predicted) + { + assembly ("memory-safe") { + // Compute and store the bytecode hash. + mstore8(0x00, 0xff) // Write the prefix. + mstore(0x35, hash) + mstore(0x01, shl(96, L1_DEPLOYER)) + mstore(0x15, salt) + predicted := keccak256(0x00, 0x55) + mstore(0x35, 0) // Restore the overwritten part of the free memory pointer. + } + } + + /// @dev Returns the initCodeHash for the predicted address on L1 using CWIA pattern. + function _initCodeHash(bytes memory data) internal pure virtual returns (bytes32 hash) { + assembly ("memory-safe") { + let mBefore3 := mload(sub(data, 0x60)) + let mBefore2 := mload(sub(data, 0x40)) + let mBefore1 := mload(sub(data, 0x20)) + let dataEnd := add(add(data, 0x20), 0x20) + let mAfter1 := mload(dataEnd) + returndatacopy(returndatasize(), returndatasize(), gt(0x20, 0xff9b)) + let extraLength := add(0x20, 2) + mstore(data, 0x5af43d3d93803e606057fd5bf3) + mstore(sub(data, 0x0d), IMPLEMENTATION) + mstore( + sub(data, 0x21), + or(shl(0x48, extraLength), 0x593da1005b363d3d373d3d3d3d610000806062363936013d73) + ) + mstore( + sub(data, 0x3a), 0x9e4ac34f21c619cefc926c8bd93b54bf5a39c7ab2127a895af1cc0691d7e3dff + ) + mstore( + sub(data, 0x5a), + or(shl(0x78, add(extraLength, 0x62)), 0x6100003d81600a3d39f336602c57343d527f) + ) + mstore(dataEnd, shl(0xf0, extraLength)) + hash := keccak256(sub(data, 0x4c), add(extraLength, 0x6c)) + mstore(dataEnd, mAfter1) + mstore(data, 0x20) + mstore(sub(data, 0x20), mBefore1) + mstore(sub(data, 0x40), mBefore2) + mstore(sub(data, 0x60), mBefore3) + } + } + + /// @dev Returns the predicted `l2Token` address using Arbitrum create2 bridge preview methods on `l1Token`. + function _calculateL2TokenAddress(address l1Token) + internal + pure + virtual + returns (address l2Token) + { + return address( + uint160( + uint256( + keccak256( + abi.encodePacked( + bytes1(0xff), + L2_DEPLOYER, + keccak256( + abi.encode(COUNTERPART_GATEWAY, keccak256(abi.encode(l1Token))) + ), + L2_HASH + ) + ) + ) + ) + ); + } +} + +/// @dev Simple token balance & supply interface. +interface IToken { + function totalSupply() external view returns (uint256); + function balanceOf(address) external view returns (uint256); +} diff --git a/test/IE.t.sol b/test/IE.t.sol index b7d22b7..2b6a1e8 100644 --- a/test/IE.t.sol +++ b/test/IE.t.sol @@ -1,28 +1,29 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.19; -import {IENSHelper, IE} from "../src/IE.sol"; +import {IE} from "../src/IE.sol"; import {Test} from "../lib/forge-std/src/Test.sol"; contract IETest is Test { address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA; + address internal constant NANI = 0x00000000000025824328358250920B271f348690; address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; - address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; - address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; - address internal constant SUSHI = 0x6B3595068778DD592e39A122f4f5a5cF09C90fE2; - address internal constant UNI = 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984; - address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7; - address internal constant OMG = 0xd26114cd6EE289AccF82350c8d8487fedB8A0C07; - address internal constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599; + address internal constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; + address internal constant WBTC = 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f; + address internal constant USDC = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831; + address internal constant USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9; + address internal constant DAI = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; + address internal constant ARB = 0x912CE59144191C1204E64559FE8253a0e49E6548; + address internal constant WSTETH = 0x5979D7b546E38E414F7E9822514be443A4800529; + address internal constant RETH = 0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8; address internal constant VITALIK_DOT_ETH = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045; address internal constant Z0R0Z_DOT_ETH = 0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20; address internal constant NANI_DOT_ETH = 0x7AF890Ca7262D6accdA5c9D24AC42e35Bb293188; - address internal constant USDC_WHALE = 0xD6153F5af5679a75cC85D8974463545181f48772; - address internal constant DAI_WHALE = 0x075e72a5eDf65F0A5f44699c7654C1a76941Ddc8; + address internal constant USDC_WHALE = 0x62383739D68Dd0F844103Db8dFb05a7EdED5BBE6; + address internal constant DAI_WHALE = 0x2d070ed1321871841245D8EE5B84bD2712644322; bytes internal constant ASCII_MAP = hex"2d00020101000a010700016101620163016401650166016701680169016a016b016c016d016e016f0170017101720173017401750176017701780179017a06001a010500"; @@ -30,7 +31,7 @@ contract IETest is Test { IE internal ie; // Intents Engine. function setUp() public payable { - vm.createSelectFork(vm.rpcUrl("main")); // Ethereum mainnet fork. + vm.createSelectFork(vm.rpcUrl("arbi")); // Arbitrum fork. ie = new IE(); vm.prank(DAO); ie.setName(ETH, "ETH"); @@ -49,15 +50,9 @@ contract IETest is Test { vm.prank(DAO); ie.setName(WETH, "wrapped ether"); vm.prank(DAO); - ie.setName(SUSHI, "SUSHI"); - vm.prank(DAO); - ie.setName(UNI, "UNI"); - vm.prank(DAO); ie.setName(USDT, "USDT"); vm.prank(DAO); ie.setName(USDT, "tether"); - vm.prank(DAO); - ie.setName(OMG, "omg"); } function testDeploy() public payable { @@ -65,25 +60,37 @@ contract IETest is Test { } function testENSNameOwnership() public payable { - (, address receiver,) = ie.whatIsTheAddressOf("vitalik"); - assertEq(receiver, VITALIK_DOT_ETH); - (, receiver,) = ie.whatIsTheAddressOf("z0r0z"); + (, address receiver,) = ie.whatIsTheAddressOf("z0r0z"); assertEq(receiver, Z0R0Z_DOT_ETH); - (, receiver,) = ie.whatIsTheAddressOf("nani"); - assertEq(receiver, NANI_DOT_ETH); } function testPreviewSendCommand() public payable { - string memory command = "send vitalik 20 dai"; + string memory command = "send z0r0z 20 dai"; + (address to, uint256 amount,, address asset,,) = ie.previewCommand(command); + assertEq(to, Z0R0Z_DOT_ETH); + assertEq(amount, 20 ether); + 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, VITALIK_DOT_ETH); + assertEq(to, Z0R0Z_DOT_ETH); assertEq(amount, 20 ether); assertEq(asset, DAI); } function testPreviewSend() public payable { - (address to, uint256 amount, address asset,,) = ie.previewSend("vitalik", "20", "dai"); - assertEq(to, VITALIK_DOT_ETH); + (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); } @@ -97,85 +104,61 @@ contract IETest is Test { } function testPreviewCommandSendDecimals() public payable { - string memory command = "send vitalik 20.2 dai"; + string memory command = "send z0r0z 20.2 dai"; (address to, uint256 amount,, address asset,,) = ie.previewCommand(command); - assertEq(to, VITALIK_DOT_ETH); + assertEq(to, Z0R0Z_DOT_ETH); assertEq(amount, 20.2 ether); assertEq(asset, DAI); - command = "send vitalik 20.23345 eth"; + command = "send z0r0z 20.23345 eth"; (to, amount,, asset,,) = ie.previewCommand(command); - assertEq(to, VITALIK_DOT_ETH); + assertEq(to, Z0R0Z_DOT_ETH); assertEq(amount, 20.23345 ether); assertEq(asset, ETH); } function testIENameSetting() public payable { - assertEq(ie.tokens("uni"), UNI); + assertEq(ie.tokens("usdc"), USDC); } - function testTotalSupply() public payable { - (uint256 supply, uint256 adjustedSupply) = ie.whatIsTheTotalSupplyOf("uni"); - assertEq(supply, 1000000000000000000000000000); - assertEq(adjustedSupply, 1000000000); + function testCommandSendETH() public payable { + ie.command{value: 1 ether}("send z0r0z 1 ETH"); } - function testBalanceInERC20() public payable { - uint256 vBal = IERC20(OMG).balanceOf(VITALIK_DOT_ETH); - (uint256 balance, uint256 adjustedBalance) = ie.whatIsTheBalanceOf("VITALIK", "omg"); - assertEq(balance, vBal); - assertEq(adjustedBalance, vBal / 10 ** 18); + function testCommandSendETHRawAddr() public payable { + ie.command{value: 1 ether}("send 0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20 1 ETH"); } - function testBalanceInETH() public payable { - uint256 vBal = VITALIK_DOT_ETH.balance; - (uint256 balance, uint256 adjustedBalance) = ie.whatIsTheBalanceOf("VITALIK", "eth"); - assertEq(balance, vBal); - assertEq(adjustedBalance, vBal / 10 ** 18); + 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 testCommandSendETH() public payable { - uint256 vBal = VITALIK_DOT_ETH.balance; - uint256 zBal = Z0R0Z_DOT_ETH.balance; + function testCommandStakeETH() public payable { vm.prank(VITALIK_DOT_ETH); - ie.command{value: 1 ether}("send z0r0z 1 ETH"); - assertEq(VITALIK_DOT_ETH.balance, vBal - 1 ether); - assertEq(Z0R0Z_DOT_ETH.balance, zBal + 1 ether); + ie.command{value: 1 ether}("stake 1 eth into lido"); } - function testCommandSendERC0() public payable { + function testCommandDepositETH() public payable { vm.prank(VITALIK_DOT_ETH); - IERC20(OMG).approve(address(ie), 100 ether); - uint256 vBal = IERC20(OMG).balanceOf(VITALIK_DOT_ETH); - uint256 zBal = IERC20(OMG).balanceOf(Z0R0Z_DOT_ETH); - vm.prank(VITALIK_DOT_ETH); - ie.command("send z0r0z 100 OMG"); - assertEq(IERC20(OMG).balanceOf(VITALIK_DOT_ETH), vBal - 100 ether); - assertEq(IERC20(OMG).balanceOf(Z0R0Z_DOT_ETH), zBal + 100 ether); - } - - function testCommandSendUSDC() public payable { - vm.prank(USDC_WHALE); - IERC20(USDC).approve(address(ie), 100 ether); - uint256 wBal = IERC20(USDC).balanceOf(USDC_WHALE); - uint256 zBal = IERC20(USDC).balanceOf(Z0R0Z_DOT_ETH); - vm.prank(USDC_WHALE); - ie.command("send z0r0z 100 USDC"); - assertEq(IERC20(USDC).balanceOf(USDC_WHALE), wBal - 100000000); - assertEq(IERC20(USDC).balanceOf(Z0R0Z_DOT_ETH), zBal + 100000000); + ie.command{value: 1 ether}("deposit 1 eth into reth"); } - function testSendETH() public payable { - uint256 vBal = VITALIK_DOT_ETH.balance; - uint256 zBal = Z0R0Z_DOT_ETH.balance; + function testCommandWithdrawETH() public payable { + vm.prank(VITALIK_DOT_ETH); + ie.command{value: 1 ether}("deposit 1 eth into reth"); vm.prank(VITALIK_DOT_ETH); - ie.send{value: 1 ether}("z0r0z", "1", "eth"); - assertEq(VITALIK_DOT_ETH.balance, vBal - 1 ether); - assertEq(Z0R0Z_DOT_ETH.balance, zBal + 1 ether); + IERC20(RETH).approve(address(ie), 100 ether); + vm.prank(VITALIK_DOT_ETH); + ie.command("withdraw 0.8 reth into eth"); } - function testCommandSwapETH() public payable { - vm.prank(VITALIK_DOT_ETH); // Note: price might change in the future. - ie.command{value: 10 ether}("swap 10 eth for 25000 dai"); + 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 { diff --git a/test/NAMI.t.sol b/test/NAMI.t.sol new file mode 100644 index 0000000..b776663 --- /dev/null +++ b/test/NAMI.t.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.19; + +import {NAMI} from "../src/NAMI.sol"; +import {Test} from "../lib/forge-std/src/Test.sol"; + +contract NAMITest is Test { + NAMI internal nami; + + string internal constant zname = "z0r0z"; + address internal constant Z0R0Z_DOT_ETH = 0x1C0Aa8cCD568d90d61659F060D1bFb1e6f855A20; + bytes32 internal constant znode = + 0xa5b4d411903b3ea236b2defe1f96e5a68505e58362e3d8d323fde0b6f8be8ad5; + + string internal constant vname = "vitalik"; + address internal constant VITALIK_DOT_ETH = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045; + bytes32 internal constant vnode = + 0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835; + + function setUp() public payable { + vm.createSelectFork(vm.rpcUrl("arbi")); // Arbitrum fork. + nami = new NAMI(); + } + + function testRegister() public payable { + nami.register(Z0R0Z_DOT_ETH, znode); + assertEq(Z0R0Z_DOT_ETH, nami.owner(znode)); + } + + function testFailRegister() public payable { + nami.register(VITALIK_DOT_ETH, vnode); + } +} diff --git a/ui/components/version.tsx b/ui/components/version.tsx index 059410f..be58219 100644 --- a/ui/components/version.tsx +++ b/ui/components/version.tsx @@ -5,7 +5,7 @@ const versions: { [key: number]: string; } = { 1: "1.0.0", - 42161: "1.1.1 (nightly)", + 42161: "1.2.0 (nightly)", }; export const Version = () => { diff --git a/ui/lib/abi/IntentsEngineAbiArb.ts b/ui/lib/abi/IntentsEngineAbiArb.ts index 000b698..ad14ef0 100644 --- a/ui/lib/abi/IntentsEngineAbiArb.ts +++ b/ui/lib/abi/IntentsEngineAbiArb.ts @@ -1,549 +1,621 @@ export const IntentsEngineAbiArb = [ { - type: "constructor", - inputs: [], - stateMutability: "payable", + "type": "constructor", + "inputs": [], + "stateMutability": "payable" }, { - type: "fallback", - stateMutability: "payable", + "type": "fallback", + "stateMutability": "payable" }, { - type: "receive", - stateMutability: "payable", + "type": "receive", + "stateMutability": "payable" }, { - type: "function", - name: "checkPackedUserOp", - inputs: [ + "type": "function", + "name": "checkPackedUserOp", + "inputs": [ { - name: "intent", - type: "string", - internalType: "string", + "name": "intent", + "type": "string", + "internalType": "string" }, { - name: "userOp", - type: "tuple", - internalType: "struct IE.PackedUserOperation", - components: [ + "name": "userOp", + "type": "tuple", + "internalType": "struct IE.PackedUserOperation", + "components": [ { - name: "sender", - type: "address", - internalType: "address", + "name": "sender", + "type": "address", + "internalType": "address" }, { - name: "nonce", - type: "uint256", - internalType: "uint256", + "name": "nonce", + "type": "uint256", + "internalType": "uint256" }, { - name: "initCode", - type: "bytes", - internalType: "bytes", + "name": "initCode", + "type": "bytes", + "internalType": "bytes" }, { - name: "callData", - type: "bytes", - internalType: "bytes", + "name": "callData", + "type": "bytes", + "internalType": "bytes" }, { - name: "accountGasLimits", - type: "bytes32", - internalType: "bytes32", + "name": "accountGasLimits", + "type": "bytes32", + "internalType": "bytes32" }, { - name: "preVerificationGas", - type: "uint256", - internalType: "uint256", + "name": "preVerificationGas", + "type": "uint256", + "internalType": "uint256" }, { - name: "gasFees", - type: "bytes32", - internalType: "bytes32", + "name": "gasFees", + "type": "bytes32", + "internalType": "bytes32" }, { - name: "paymasterAndData", - type: "bytes", - internalType: "bytes", + "name": "paymasterAndData", + "type": "bytes", + "internalType": "bytes" }, { - name: "signature", - type: "bytes", - internalType: "bytes", - }, - ], - }, + "name": "signature", + "type": "bytes", + "internalType": "bytes" + } + ] + } ], - outputs: [ + "outputs": [ { - name: "", - type: "bool", - internalType: "bool", - }, + "name": "", + "type": "bool", + "internalType": "bool" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "checkUserOp", - inputs: [ + "type": "function", + "name": "checkUserOp", + "inputs": [ { - name: "intent", - type: "string", - internalType: "string", + "name": "intent", + "type": "string", + "internalType": "string" }, { - name: "userOp", - type: "tuple", - internalType: "struct IE.UserOperation", - components: [ + "name": "userOp", + "type": "tuple", + "internalType": "struct IE.UserOperation", + "components": [ { - name: "sender", - type: "address", - internalType: "address", + "name": "sender", + "type": "address", + "internalType": "address" }, { - name: "nonce", - type: "uint256", - internalType: "uint256", + "name": "nonce", + "type": "uint256", + "internalType": "uint256" }, { - name: "initCode", - type: "bytes", - internalType: "bytes", + "name": "initCode", + "type": "bytes", + "internalType": "bytes" }, { - name: "callData", - type: "bytes", - internalType: "bytes", + "name": "callData", + "type": "bytes", + "internalType": "bytes" }, { - name: "callGasLimit", - type: "uint256", - internalType: "uint256", + "name": "callGasLimit", + "type": "uint256", + "internalType": "uint256" }, { - name: "verificationGasLimit", - type: "uint256", - internalType: "uint256", + "name": "verificationGasLimit", + "type": "uint256", + "internalType": "uint256" }, { - name: "preVerificationGas", - type: "uint256", - internalType: "uint256", + "name": "preVerificationGas", + "type": "uint256", + "internalType": "uint256" }, { - name: "maxFeePerGas", - type: "uint256", - internalType: "uint256", + "name": "maxFeePerGas", + "type": "uint256", + "internalType": "uint256" }, { - name: "maxPriorityFeePerGas", - type: "uint256", - internalType: "uint256", + "name": "maxPriorityFeePerGas", + "type": "uint256", + "internalType": "uint256" }, { - name: "paymasterAndData", - type: "bytes", - internalType: "bytes", + "name": "paymasterAndData", + "type": "bytes", + "internalType": "bytes" }, { - name: "signature", - type: "bytes", - internalType: "bytes", - }, - ], - }, + "name": "signature", + "type": "bytes", + "internalType": "bytes" + } + ] + } ], - outputs: [ + "outputs": [ { - name: "", - type: "bool", - internalType: "bool", - }, + "name": "", + "type": "bool", + "internalType": "bool" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "command", - inputs: [ - { - name: "intent", - type: "string", - internalType: "string", - }, + "type": "function", + "name": "command", + "inputs": [ + { + "name": "intent", + "type": "string", + "internalType": "string" + } ], - outputs: [], - stateMutability: "payable", + "outputs": [], + "stateMutability": "payable" }, { - type: "function", - name: "previewCommand", - inputs: [ + "type": "function", + "name": "pairs", + "inputs": [ { - name: "intent", - type: "string", - internalType: "string", + "name": "token0", + "type": "address", + "internalType": "address" }, + { + "name": "token1", + "type": "address", + "internalType": "address" + } ], - outputs: [ + "outputs": [ { - name: "to", - type: "address", - internalType: "address", - }, + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "previewCommand", + "inputs": [ + { + "name": "intent", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ { - name: "amount", - type: "uint256", - internalType: "uint256", + "name": "to", + "type": "address", + "internalType": "address" }, { - name: "minAmountOut", - type: "uint256", - internalType: "uint256", + "name": "amount", + "type": "uint256", + "internalType": "uint256" }, { - name: "token", - type: "address", - internalType: "address", + "name": "minAmountOut", + "type": "uint256", + "internalType": "uint256" }, { - name: "callData", - type: "bytes", - internalType: "bytes", + "name": "token", + "type": "address", + "internalType": "address" }, { - name: "executeCallData", - type: "bytes", - internalType: "bytes", + "name": "callData", + "type": "bytes", + "internalType": "bytes" }, + { + "name": "executeCallData", + "type": "bytes", + "internalType": "bytes" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "previewSend", - inputs: [ + "type": "function", + "name": "previewSend", + "inputs": [ { - name: "to", - type: "string", - internalType: "string", + "name": "to", + "type": "string", + "internalType": "string" }, { - name: "amount", - type: "string", - internalType: "string", + "name": "amount", + "type": "string", + "internalType": "string" }, { - name: "token", - type: "string", - internalType: "string", - }, + "name": "token", + "type": "string", + "internalType": "string" + } ], - outputs: [ + "outputs": [ { - name: "_to", - type: "address", - internalType: "address", + "name": "_to", + "type": "address", + "internalType": "address" }, { - name: "_amount", - type: "uint256", - internalType: "uint256", + "name": "_amount", + "type": "uint256", + "internalType": "uint256" }, { - name: "_token", - type: "address", - internalType: "address", + "name": "_token", + "type": "address", + "internalType": "address" }, { - name: "callData", - type: "bytes", - internalType: "bytes", + "name": "callData", + "type": "bytes", + "internalType": "bytes" }, { - name: "executeCallData", - type: "bytes", - internalType: "bytes", - }, + "name": "executeCallData", + "type": "bytes", + "internalType": "bytes" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "previewSwap", - inputs: [ + "type": "function", + "name": "previewSwap", + "inputs": [ { - name: "amountIn", - type: "string", - internalType: "string", + "name": "amountIn", + "type": "string", + "internalType": "string" }, { - name: "amountOutMinimum", - type: "string", - internalType: "string", + "name": "amountOutMinimum", + "type": "string", + "internalType": "string" }, { - name: "tokenIn", - type: "string", - internalType: "string", + "name": "tokenIn", + "type": "string", + "internalType": "string" }, { - name: "tokenOut", - type: "string", - internalType: "string", - }, + "name": "tokenOut", + "type": "string", + "internalType": "string" + } ], - outputs: [ + "outputs": [ { - name: "_amountIn", - type: "uint256", - internalType: "uint256", + "name": "_amountIn", + "type": "uint256", + "internalType": "uint256" }, { - name: "_amountOut", - type: "uint256", - internalType: "uint256", + "name": "_amountOut", + "type": "uint256", + "internalType": "uint256" }, { - name: "_tokenIn", - type: "address", - internalType: "address", + "name": "_tokenIn", + "type": "address", + "internalType": "address" }, { - name: "_tokenOut", - type: "address", - internalType: "address", - }, + "name": "_tokenOut", + "type": "address", + "internalType": "address" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "send", - inputs: [ + "type": "function", + "name": "send", + "inputs": [ { - name: "to", - type: "string", - internalType: "string", + "name": "to", + "type": "string", + "internalType": "string" }, { - name: "amount", - type: "string", - internalType: "string", + "name": "amount", + "type": "string", + "internalType": "string" }, { - name: "token", - type: "string", - internalType: "string", - }, + "name": "token", + "type": "string", + "internalType": "string" + } ], - outputs: [], - stateMutability: "payable", + "outputs": [], + "stateMutability": "payable" }, { - type: "function", - name: "setName", - inputs: [ + "type": "function", + "name": "setName", + "inputs": [ { - name: "token", - type: "address", - internalType: "address", + "name": "token", + "type": "address", + "internalType": "address" }, { - name: "name", - type: "string", - internalType: "string", - }, + "name": "name", + "type": "string", + "internalType": "string" + } ], - outputs: [], - stateMutability: "payable", + "outputs": [], + "stateMutability": "payable" }, { - type: "function", - name: "setNameAndTicker", - inputs: [ + "type": "function", + "name": "setNameAndTicker", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "setPair", + "inputs": [ + { + "name": "tokenA", + "type": "address", + "internalType": "address" + }, { - name: "token", - type: "address", - internalType: "address", + "name": "tokenB", + "type": "address", + "internalType": "address" }, + { + "name": "pair", + "type": "address", + "internalType": "address" + } ], - outputs: [], - stateMutability: "payable", + "outputs": [], + "stateMutability": "payable" }, { - type: "function", - name: "swap", - inputs: [ + "type": "function", + "name": "swap", + "inputs": [ { - name: "amountIn", - type: "string", - internalType: "string", + "name": "amountIn", + "type": "string", + "internalType": "string" }, { - name: "amountOutMinimum", - type: "string", - internalType: "string", + "name": "amountOutMinimum", + "type": "string", + "internalType": "string" }, { - name: "tokenIn", - type: "string", - internalType: "string", + "name": "tokenIn", + "type": "string", + "internalType": "string" }, { - name: "tokenOut", - type: "string", - internalType: "string", - }, + "name": "tokenOut", + "type": "string", + "internalType": "string" + } ], - outputs: [], - stateMutability: "payable", + "outputs": [], + "stateMutability": "payable" }, { - type: "function", - name: "tokens", - inputs: [ - { - name: "name", - type: "string", - internalType: "string", - }, + "type": "function", + "name": "tokens", + "inputs": [ + { + "name": "name", + "type": "string", + "internalType": "string" + } ], - outputs: [ + "outputs": [ { - name: "", - type: "address", - internalType: "address", - }, + "name": "", + "type": "address", + "internalType": "address" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "whatIsTheAddressOf", - inputs: [ - { - name: "name", - type: "string", - internalType: "string", - }, + "type": "function", + "name": "whatIsTheAddressOf", + "inputs": [ + { + "name": "name", + "type": "string", + "internalType": "string" + } ], - outputs: [ + "outputs": [ { - name: "owner", - type: "address", - internalType: "address", + "name": "owner", + "type": "address", + "internalType": "address" }, { - name: "receiver", - type: "address", - internalType: "address", + "name": "receiver", + "type": "address", + "internalType": "address" }, { - name: "node", - type: "bytes32", - internalType: "bytes32", - }, + "name": "node", + "type": "bytes32", + "internalType": "bytes32" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "whatIsTheBalanceOf", - inputs: [ + "type": "function", + "name": "whatIsTheBalanceOf", + "inputs": [ { - name: "name", - type: "string", - internalType: "string", + "name": "name", + "type": "string", + "internalType": "string" }, { - name: "token", - type: "string", - internalType: "string", - }, + "name": "token", + "type": "string", + "internalType": "string" + } ], - outputs: [ + "outputs": [ { - name: "balance", - type: "uint256", - internalType: "uint256", + "name": "balance", + "type": "uint256", + "internalType": "uint256" }, { - name: "balanceAdjusted", - type: "uint256", - internalType: "uint256", - }, + "name": "balanceAdjusted", + "type": "uint256", + "internalType": "uint256" + } ], - stateMutability: "view", + "stateMutability": "view" }, { - type: "function", - name: "whatIsTheTotalSupplyOf", - inputs: [ + "type": "function", + "name": "whatIsTheTotalSupplyOf", + "inputs": [ + { + "name": "token", + "type": "string", + "internalType": "string" + } + ], + "outputs": [ { - name: "token", - type: "string", - internalType: "string", + "name": "supply", + "type": "uint256", + "internalType": "uint256" }, + { + "name": "supplyAdjusted", + "type": "uint256", + "internalType": "uint256" + } ], - outputs: [ + "stateMutability": "view" + }, + { + "type": "event", + "name": "NameSet", + "inputs": [ { - name: "supply", - type: "uint256", - internalType: "uint256", + "name": "token", + "type": "address", + "indexed": true, + "internalType": "address" }, { - name: "supplyAdjusted", - type: "uint256", - internalType: "uint256", - }, + "name": "name", + "type": "string", + "indexed": false, + "internalType": "string" + } ], - stateMutability: "view", + "anonymous": false }, { - type: "event", - name: "NameSet", - inputs: [ + "type": "event", + "name": "PairSet", + "inputs": [ { - name: "token", - type: "address", - indexed: true, - internalType: "address", + "name": "token0", + "type": "address", + "indexed": true, + "internalType": "address" }, { - name: "name", - type: "string", - indexed: false, - internalType: "string", + "name": "token1", + "type": "address", + "indexed": true, + "internalType": "address" }, + { + "name": "pair", + "type": "address", + "indexed": false, + "internalType": "address" + } ], - anonymous: false, + "anonymous": false }, { - type: "error", - name: "InsufficientSwap", - inputs: [], + "type": "error", + "name": "InsufficientSwap", + "inputs": [] }, { - type: "error", - name: "InvalidCharacter", - inputs: [], + "type": "error", + "name": "InvalidCharacter", + "inputs": [] }, { - type: "error", - name: "InvalidSwap", - inputs: [], + "type": "error", + "name": "InvalidSwap", + "inputs": [] }, { - type: "error", - name: "InvalidSyntax", - inputs: [], + "type": "error", + "name": "InvalidSyntax", + "inputs": [] }, { - type: "error", - name: "Overflow", - inputs: [], - }, + "type": "error", + "name": "Overflow", + "inputs": [] + } ] as const; diff --git a/ui/lib/constants.ts b/ui/lib/constants.ts index 690a9e5..7231fc4 100644 --- a/ui/lib/constants.ts +++ b/ui/lib/constants.ts @@ -4,7 +4,7 @@ export const IE_ADDRESS: { [key: number]: Address; } = { 1: "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00", - 42161: "0x000000001e202b5b84e56400f409800065cb6d3c", + 42161: "0x1e00003a669bb466d6B49800000099E1abDD6600", }; export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";