From 0e07baacb225bae6af6d37dff531a21dd06e0665 Mon Sep 17 00:00:00 2001 From: ross <92001561+z0r0z@users.noreply.github.com> Date: Fri, 16 Feb 2024 06:11:20 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20V1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gas-snapshot | 6 +- README.md | 17 +- docs/book.toml | 2 +- docs/src/README.md | 17 +- docs/src/SUMMARY.md | 2 +- docs/src/src/IE.sol/contract.IE.md | 208 +++++++++++++------ docs/src/src/IE.sol/interface.IENSHelper.md | 14 +- docs/src/src/IE.sol/interface.IExecutor.md | 2 +- docs/src/src/IE.sol/interface.ISwapRouter.md | 10 +- docs/src/src/IE.sol/interface.IToken.md | 2 +- docs/src/src/README.md | 2 +- src/IE.sol | 4 +- 12 files changed, 187 insertions(+), 99 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 4324dce..014eb7a 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -3,10 +3,10 @@ IETest:testBalanceInETH() (gas: 40280) IETest:testCommandSendERC0() (gas: 102922) IETest:testCommandSendETH() (gas: 69404) IETest:testCommandSendUSDC() (gas: 135652) -IETest:testCommandSwapDAI() (gas: 101147) +IETest:testCommandSwapDAI() (gas: 110787) IETest:testCommandSwapETH() (gas: 113487) -IETest:testCommandSwapForETH() (gas: 122654) -IETest:testCommandSwapUSDC() (gas: 157172) +IETest:testCommandSwapForETH() (gas: 130366) +IETest:testCommandSwapUSDC() (gas: 157128) IETest:testCommandSwapUSDCForWBTC() (gas: 165068) IETest:testDeploy() (gas: 2643012) IETest:testENSNameOwnership() (gas: 83907) diff --git a/README.md b/README.md index 3bd7125..2841814 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ From natural language: IE should deterministically and transparently operate to provide these utilities in an uncensorable medium like a Solidity smart contract. -[V0](./src/IE.sol) is a POC of this. +[V1](./src/IE.sol) is a POC of this. ## Command Syntax (⌘) IE is approaching things from first-principles and a "show" rather than "tell" approach. There will be some experimentation. -Some things in V0 are likely very underoptimized for this particular use case. +Some things in V1 are likely very underoptimized for this particular use case. The bigger project is to identify syntax and phrasing for common types of onchain transactions in English to start. The following are identified as categories and phrases that should demonstrate this for many if not most natural language commands to generate txs. @@ -34,10 +34,10 @@ As you might notice, there are patterns. Because after all this is typical langu Also, let's try and be as helpful as possible. If there is `msg.value` in a command, then we will 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 "transfer" and "give" when it comes to onchain assets. +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. ### Send -- *V0* +- *V1* *Words: 4* @@ -49,11 +49,18 @@ Actions should also have aliases to catch more cases. Though it will be cheaper [action] [value] [asset] [to/for] [object] - **send 1 ETH to/for vitalik** -aliases: *transfer*, *give* +aliases: *transfer* ### Swap - *V1* +*Words: 5* + +[action] [value] [asset] [to/for] [object] +- **swap 1 ETH to/for DAI** + +aliases: *exchange* + ## Getting Started Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup` diff --git a/docs/book.toml b/docs/book.toml index b1e9336..b92d39c 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -6,7 +6,7 @@ title = "" no-section-label = true additional-js = ["solidity.min.js"] additional-css = ["book.css"] -git-repository-url = "https://github.com/NaniDAO/IE" +git-repository-url = "https://github.com/NaniDAO/ie" [output.html.fold] enable = true diff --git a/docs/src/README.md b/docs/src/README.md index 3bd7125..2841814 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -12,13 +12,13 @@ From natural language: IE should deterministically and transparently operate to provide these utilities in an uncensorable medium like a Solidity smart contract. -[V0](./src/IE.sol) is a POC of this. +[V1](./src/IE.sol) is a POC of this. ## Command Syntax (⌘) IE is approaching things from first-principles and a "show" rather than "tell" approach. There will be some experimentation. -Some things in V0 are likely very underoptimized for this particular use case. +Some things in V1 are likely very underoptimized for this particular use case. The bigger project is to identify syntax and phrasing for common types of onchain transactions in English to start. The following are identified as categories and phrases that should demonstrate this for many if not most natural language commands to generate txs. @@ -34,10 +34,10 @@ As you might notice, there are patterns. Because after all this is typical langu Also, let's try and be as helpful as possible. If there is `msg.value` in a command, then we will 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 "transfer" and "give" when it comes to onchain assets. +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. ### Send -- *V0* +- *V1* *Words: 4* @@ -49,11 +49,18 @@ Actions should also have aliases to catch more cases. Though it will be cheaper [action] [value] [asset] [to/for] [object] - **send 1 ETH to/for vitalik** -aliases: *transfer*, *give* +aliases: *transfer* ### Swap - *V1* +*Words: 5* + +[action] [value] [asset] [to/for] [object] +- **swap 1 ETH to/for DAI** + +aliases: *exchange* + ## Getting Started Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup` diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 775d99b..1ff6b86 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -2,7 +2,7 @@ - [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) - - [IENSHelper](src/IE.sol/interface.IENSHelper.md) - [ISwapRouter](src/IE.sol/interface.ISwapRouter.md) diff --git a/docs/src/src/IE.sol/contract.IE.md b/docs/src/src/IE.sol/contract.IE.md index befbe40..676fc96 100644 --- a/docs/src/src/IE.sol/contract.IE.md +++ b/docs/src/src/IE.sol/contract.IE.md @@ -1,13 +1,13 @@ # IE -[Git Source](https://github.com/NaniDAO/IE/blob/fe9aa8f819c0b0c1f1baab80820f73546caaabc2/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/55a636250a2f0bfbb6be0be4bcc7c046924d719c/src/IE.sol) **Author:** nani.eth (https://github.com/NaniDAO/ie) Simple helper contract for turning transactional intents into executable code. -*V0 simulates the output of typical commands (sending tokens) and allows execution. -IE also has workflow to verify the intent of ERC-4337 account userOps against calldata.* +*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.* ## State Variables @@ -85,15 +85,6 @@ address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; ``` -### ENS_HELPER -*ENS name normalizer contract.* - - -```solidity -IENSHelper internal constant ENS_HELPER = IENSHelper(0x4A5cae3EC0b144330cf1a6CeAD187D8F6B891758); -``` - - ### ENS_REGISTRY *ENS fallback registry contract.* @@ -131,21 +122,22 @@ bytes32 internal constant UNISWAP_V3_POOL_INIT_CODE_HASH = ``` -### MIN_SQRT_RATIO -*The minimum value that can be returned from `getSqrtRatioAtTick`.* +### MIN_SQRT_RATIO_PLUS_ONE +*The minimum value that can be returned from `getSqrtRatioAtTick` (plus one).* ```solidity -uint160 internal constant MIN_SQRT_RATIO = 4295128739; +uint160 internal constant MIN_SQRT_RATIO_PLUS_ONE = 4295128740; ``` -### MAX_SQRT_RATIO -*The maximum value that can be returned from `getSqrtRatioAtTick`.* +### MAX_SQRT_RATIO_MINUS_ONE +*The maximum value that can be returned from `getSqrtRatioAtTick` (minus one).* ```solidity -uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; +uint160 internal constant MAX_SQRT_RATIO_MINUS_ONE = + 1461446703485210103287273052203988822378723970341; ``` @@ -160,17 +152,29 @@ 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).* + + +```solidity +bytes1[] internal _idnamap; +``` + + ## Functions ### constructor ======================== CONSTRUCTOR ======================== /// -*Constructs -this implementation.* +*Constructs this IE with `asciimap`.* ```solidity -constructor() payable; +constructor(bytes memory asciimap) payable; ``` ### previewCommand @@ -179,7 +183,7 @@ constructor() payable; Preview natural language smart contract command. The `send` syntax uses ENS naming: 'send vitalik 20 DAI'. -`swap` syntax uses common command: 'swap 100 DAI for WETH'. +`swap` syntax uses common format: 'swap 100 DAI for WETH'. ```solidity @@ -198,7 +202,7 @@ function previewCommand(string calldata intent) ### previewSend -*Previews a send command from the parts of a matched intent string.* +*Previews a `send` command from the parts of a matched intent string.* ```solidity @@ -217,7 +221,7 @@ function previewSend(string memory to, string memory amount, string memory token ### previewSwap -*Previews a swap command from the parts of a matched intent string.* +*Previews a `swap` command from the parts of a matched intent string.* ```solidity @@ -254,20 +258,20 @@ function checkPackedUserOp(string calldata intent, PackedUserOperation calldata returns (bool); ``` -### _returnConstant +### _returnTokenConstant -*Checks and returns the canonical constant for a matched intent string.* +*Checks and returns the canonical token address constant for a matched intent string.* ```solidity -function _returnConstant(bytes32 token) internal view virtual returns (address _token); +function _returnTokenConstant(bytes32 token) internal view virtual returns (address _token); ``` ### command ===================== COMMAND EXECUTION ===================== /// -*Executes a command from an intent string.* +*Executes a text command from an intent string.* ```solidity @@ -276,7 +280,7 @@ function command(string calldata intent) public payable virtual; ### send -*Executes a send command from the parts of a matched intent string.* +*Executes a `send` command from the parts of a matched intent string.* ```solidity @@ -285,7 +289,7 @@ function send(string memory to, string memory amount, string memory token) publi ### swap -*Executes a swap command from the parts of a matched intent string.* +*Executes a `swap` command from the parts of a matched intent string.* ```solidity @@ -295,46 +299,73 @@ function swap(string memory amountIn, string memory tokenIn, string memory token virtual; ``` -### uniswapV3SwapCallback +### fallback -*Callback for IUniswapV3PoolActions#swap.* +*Fallback `uniswapV3SwapCallback`. +If ETH is swapped, WETH is forwarded.* ```solidity -function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) - public - payable - virtual; +fallback() external payable virtual; ``` ### _computePoolAddress +*Computes the create2 address for given token pair.* + ```solidity function _computePoolAddress(address tokenA, address tokenB) internal view virtual + returns (address pool, bool zeroForOne); +``` + +### _computePairHash + +*Computes the create2 deployment hash for given token pair.* + + +```solidity +function _computePairHash(address token0, address token1, uint24 fee) + internal + pure + virtual returns (address pool); ``` -### whatIsMyBalanceIn +### _wrapETH -================== BALANCE & SUPPLY HELPERS ================== /// +*Wraps an `amount` of ETH to WETH and funds pool caller for swap.* + + +```solidity +function _wrapETH(uint256 amount) internal virtual; +``` -*Returns your balance in a named token.* +### _unwrapETH + +*Unwraps an `amount` of ETH from WETH for return.* ```solidity -function whatIsMyBalanceIn(string calldata token) - public - view - virtual - returns (uint256 balance, uint256 balanceAdjusted); +function _unwrapETH(uint256 amount) internal virtual; +``` + +### receive + +*ETH receiver fallback.* + + +```solidity +receive() external payable virtual; ``` ### whatIsTheBalanceOf +================== BALANCE & SUPPLY HELPERS ================== /// + *Returns the balance of a named account in a named token.* @@ -359,41 +390,41 @@ function whatIsTheTotalSupplyOf(string calldata token) returns (uint256 supply, uint256 supplyAdjusted); ``` -### _balanceOf +### whatIsTheAddressOf -*Returns the amount of ERC20/721 `token` owned by `account`.* +====================== ENS VERIFICATION ====================== /// + +*Returns ENS name ownership details.* ```solidity -function _balanceOf(address token, address account) - internal +function whatIsTheAddressOf(string memory name) + public view virtual - returns (uint256 amount); + returns (address owner, address receiver, bytes32 node); ``` -### _totalSupply +### _namehash -*Returns the total supply of ERC20/721 `token`.* +*Computes an ENS domain namehash.* ```solidity -function _totalSupply(address token) internal view virtual returns (uint256 supply); +function _namehash(string memory domain) internal view virtual returns (bytes32 node); ``` -### whatIsTheAddressOf - -====================== ENS VERIFICATION ====================== /// +### _labelhash -*Returns ENS name ownership details.* +*Computes an ENS domain labelhash given its start and end.* ```solidity -function whatIsTheAddressOf(string memory name) - public - view +function _labelhash(string memory domain, uint256 start, uint256 end) + internal + pure virtual - returns (address owner, address receiver, bytes32 node); + returns (bytes32 hash); ``` ### setName @@ -407,9 +438,28 @@ function whatIsTheAddressOf(string memory name) function setName(address token, string calldata name) public payable virtual; ``` -### _extraction +### setNameAndTicker + +*Sets a public name and ticker for a given `token` address.* + + +```solidity +function setNameAndTicker(address token) public payable virtual; +``` + +### _lowercase -================= INTERNAL STRING OPERATIONS ================= /// +===================== STRING OPERATIONS ===================== /// + +*Returns copy of string in lowercase. +Modified from Solady LibString `toCase`.* + + +```solidity +function _lowercase(string memory subject) internal pure virtual returns (string memory result); +``` + +### _extraction *Extracts the first word (action) as bytes32.* @@ -486,7 +536,7 @@ event NameSet(address indexed token, string name); ``` ## Errors -### Unauthorized +### Overflow ======================= LIBRARY USAGE ======================= /// *Metadata reader library.* @@ -494,6 +544,14 @@ event NameSet(address indexed token, string name); *Safe token transfer library. ======================= CUSTOM ERRORS ======================= ///* +*Bad math.* + + +```solidity +error Overflow(); +``` + +### Unauthorized *Caller fails.* @@ -501,8 +559,16 @@ event NameSet(address indexed token, string name); error Unauthorized(); ``` +### InvalidSwap +*0-liquidity.* + + +```solidity +error InvalidSwap(); +``` + ### InvalidSyntax -*Invalid command form.* +*Invalid command.* ```solidity @@ -558,3 +624,17 @@ struct PackedUserOperation { } ``` +## Enums +### Rule +=========================== ENUMS =========================== /// + +*ENSAsciiNormalizer rules.* + + +```solidity +enum Rule { + DISALLOWED, + VALID +} +``` + diff --git a/docs/src/src/IE.sol/interface.IENSHelper.md b/docs/src/src/IE.sol/interface.IENSHelper.md index d5634ab..bd13b0e 100644 --- a/docs/src/src/IE.sol/interface.IENSHelper.md +++ b/docs/src/src/IE.sol/interface.IENSHelper.md @@ -1,5 +1,5 @@ # IENSHelper -[Git Source](https://github.com/NaniDAO/IE/blob/fe9aa8f819c0b0c1f1baab80820f73546caaabc2/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/55a636250a2f0bfbb6be0be4bcc7c046924d719c/src/IE.sol) *ENS name resolution helper contracts interface.* @@ -12,24 +12,24 @@ function addr(bytes32) external view returns (address); ``` -### ownerOf +### owner ```solidity -function ownerOf(uint256) external view returns (address); +function owner(bytes32) external view returns (address); ``` -### resolver +### ownerOf ```solidity -function resolver(bytes32) external view returns (address); +function ownerOf(uint256) external view returns (address); ``` -### owner +### resolver ```solidity -function owner(string calldata) external view returns (address, bytes32); +function resolver(bytes32) external view returns (address); ``` diff --git a/docs/src/src/IE.sol/interface.IExecutor.md b/docs/src/src/IE.sol/interface.IExecutor.md index 5dd1619..f2c77d2 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/fe9aa8f819c0b0c1f1baab80820f73546caaabc2/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/55a636250a2f0bfbb6be0be4bcc7c046924d719c/src/IE.sol) Simple calldata executor interface. diff --git a/docs/src/src/IE.sol/interface.ISwapRouter.md b/docs/src/src/IE.sol/interface.ISwapRouter.md index 2a93579..2c06c78 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/fe9aa8f819c0b0c1f1baab80820f73546caaabc2/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/55a636250a2f0bfbb6be0be4bcc7c046924d719c/src/IE.sol) *Simple Uniswap V3 swapping interface.* @@ -9,12 +9,6 @@ ```solidity -function swap( - address recipient, - bool zeroForOne, - int256 amountSpecified, - uint160 sqrtPriceLimitX96, - bytes calldata data -) external returns (int256 amount0, int256 amount1); +function swap(address, bool, int256, uint160, bytes calldata) external returns (int256, int256); ``` diff --git a/docs/src/src/IE.sol/interface.IToken.md b/docs/src/src/IE.sol/interface.IToken.md index 22de96d..6d10b22 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/fe9aa8f819c0b0c1f1baab80820f73546caaabc2/src/IE.sol) +[Git Source](https://github.com/NaniDAO/ie/blob/55a636250a2f0bfbb6be0be4bcc7c046924d719c/src/IE.sol) *Simple token transfer interface.* diff --git a/docs/src/src/README.md b/docs/src/src/README.md index 03480d7..55ca2ad 100644 --- a/docs/src/src/README.md +++ b/docs/src/src/README.md @@ -2,7 +2,7 @@ # 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) -- [IENSHelper](IE.sol/interface.IENSHelper.md) - [ISwapRouter](IE.sol/interface.ISwapRouter.md) diff --git a/src/IE.sol b/src/IE.sol index 54d26f0..597dff7 100644 --- a/src/IE.sol +++ b/src/IE.sol @@ -320,7 +320,7 @@ contract IE { /// @dev Fallback `uniswapV3SwapCallback`. /// If ETH is swapped, WETH is forwarded. - fallback() external payable { + fallback() external payable virtual { int256 amount0Delta; int256 amount1Delta; bool ETHIn; @@ -413,7 +413,7 @@ contract IE { } /// @dev ETH receiver fallback. - receive() external payable { + receive() external payable virtual { if (msg.sender != WETH) revert Unauthorized(); }