Skip to content

Commit

Permalink
✔️ Adjust output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 21, 2024
1 parent 0b0749c commit cd8407b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 31 deletions.
14 changes: 7 additions & 7 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ IETest:testBalanceInERC20() (gas: 49154)
IETest:testBalanceInETH() (gas: 40280)
IETest:testCommandSendERC0() (gas: 102922)
IETest:testCommandSendETH() (gas: 69404)
IETest:testCommandSendUSDC() (gas: 135652)
IETest:testCommandSwapDAI() (gas: 105596)
IETest:testCommandSwapETH() (gas: 119738)
IETest:testCommandSwapForETH() (gas: 124044)
IETest:testCommandSwapUSDC() (gas: 165660)
IETest:testCommandSwapUSDCForWBTC() (gas: 166523)
IETest:testDeploy() (gas: 2842077)
IETest:testCommandSendUSDC() (gas: 118552)
IETest:testCommandSwapDAI() (gas: 105520)
IETest:testCommandSwapETH() (gas: 119728)
IETest:testCommandSwapForETH() (gas: 123983)
IETest:testCommandSwapUSDC() (gas: 164744)
IETest:testCommandSwapUSDCForWBTC() (gas: 166495)
IETest:testDeploy() (gas: 2831664)
IETest:testENSNameOwnership() (gas: 83841)
IETest:testIENameSetting() (gas: 8142)
IETest:testPreviewCommandSendDecimals() (gas: 91938)
Expand Down
15 changes: 13 additions & 2 deletions docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ From natural language:

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)
[`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.

Some things in V1 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.

Expand Down Expand Up @@ -58,11 +58,22 @@ aliases: *transfer*

aliases: *exchange*

#### < A >
*Words: 5*

**[action] [value] [asset] [to/for] [object]**
> *swap 1 ETH to/for DAI*
#### < B >
*Words: 6*

[action] [value] [asset] [to/for] [minOutputAmount] [object]
- **swap 1 ETH to/for 2500 DAI**

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`.

------------------------------------

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).
Expand Down
51 changes: 43 additions & 8 deletions docs/src/src/IE.sol/contract.IE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IE
[Git Source](https://github.com/NaniDAO/ie/blob/0bb0aa250ea653d6a1968dac7f12b7bc67fd1e97/src/IE.sol)
[Git Source](https://github.com/NaniDAO/ie/blob/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol)

**Author:**
nani.eth (https://github.com/NaniDAO/ie)
Expand Down Expand Up @@ -204,6 +204,7 @@ function previewCommand(string calldata intent)
returns (
address to,
uint256 amount,
uint256 minAmountOut,
address token,
bytes memory callData,
bytes memory executeCallData
Expand Down Expand Up @@ -235,11 +236,16 @@ function previewSend(string memory to, string memory amount, string memory token


```solidity
function previewSwap(string memory amountIn, string memory tokenIn, string memory tokenOut)
function previewSwap(
string memory amountIn,
string memory amountOutMinimum,
string memory tokenIn,
string memory tokenOut
)
public
view
virtual
returns (uint256 _amountIn, address _tokenIn, address _tokenOut);
returns (uint256 _amountIn, uint256 _amountOut, address _tokenIn, address _tokenOut);
```

### checkUserOp
Expand Down Expand Up @@ -303,10 +309,12 @@ function send(string memory to, string memory amount, string memory token) publi


```solidity
function swap(string memory amountIn, string memory tokenIn, string memory tokenOut)
public
payable
virtual;
function swap(
string memory amountIn,
string memory amountOutMinimum,
string memory tokenIn,
string memory tokenOut
) public payable virtual;
```

### fallback
Expand Down Expand Up @@ -505,7 +513,12 @@ function _extractSwap(string memory normalizedIntent)
internal
pure
virtual
returns (string memory amountIn, string memory tokenIn, string memory tokenOut);
returns (
string memory amountIn,
string memory amountOutMinimum,
string memory tokenIn,
string memory tokenOut
);
```

### _split
Expand Down Expand Up @@ -593,6 +606,14 @@ error InvalidSyntax();
error InvalidCharacter();
```

### InsufficientSwap
*Insufficient swap output.*


```solidity
error InsufficientSwap();
```

## Structs
### UserOperation
========================== STRUCTS ========================== ///
Expand Down Expand Up @@ -634,6 +655,20 @@ struct PackedUserOperation {
}
```

### SwapDetails
*The `swap` command details.*


```solidity
struct SwapDetails {
address tokenIn;
address tokenOut;
uint256 amountIn;
bool ETHIn;
bool ETHOut;
}
```

## Enums
### Rule
=========================== ENUMS =========================== ///
Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.IENSHelper.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IENSHelper
[Git Source](https://github.com/NaniDAO/ie/blob/0bb0aa250ea653d6a1968dac7f12b7bc67fd1e97/src/IE.sol)
[Git Source](https://github.com/NaniDAO/ie/blob/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol)

*ENS name resolution helper contracts interface.*

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.IExecutor.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IExecutor
[Git Source](https://github.com/NaniDAO/ie/blob/0bb0aa250ea653d6a1968dac7f12b7bc67fd1e97/src/IE.sol)
[Git Source](https://github.com/NaniDAO/ie/blob/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol)

Simple calldata executor interface.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.ISwapRouter.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ISwapRouter
[Git Source](https://github.com/NaniDAO/ie/blob/0bb0aa250ea653d6a1968dac7f12b7bc67fd1e97/src/IE.sol)
[Git Source](https://github.com/NaniDAO/ie/blob/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol)

*Simple Uniswap V3 swapping interface.*

Expand Down
2 changes: 1 addition & 1 deletion docs/src/src/IE.sol/interface.IToken.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IToken
[Git Source](https://github.com/NaniDAO/ie/blob/0bb0aa250ea653d6a1968dac7f12b7bc67fd1e97/src/IE.sol)
[Git Source](https://github.com/NaniDAO/ie/blob/0b0749cff67e97744a0dff4a7a94d72f73ddcbd4/src/IE.sol)

*Simple token transfer interface.*

Expand Down
2 changes: 1 addition & 1 deletion lib/solady
12 changes: 6 additions & 6 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ contract IE {
/// @dev Non-numeric character.
error InvalidCharacter();

/// @dev Insufficient swap output.
error InsufficientSwap();

/// =========================== EVENTS =========================== ///

/// @dev Logs the registration of a token name.
Expand Down Expand Up @@ -353,13 +356,10 @@ contract IE {
details.ETHIn, details.ETHOut, msg.sender, details.tokenIn, details.tokenOut
)
);
require(
if (
uint256(-(zeroForOne ? amount1 : amount0))
>= _stringToUint(
amountOutMinimum, details.ETHOut ? 18 : details.tokenOut.readDecimals()
),
"Too little received"
);
< _stringToUint(amountOutMinimum, details.ETHOut ? 18 : details.tokenOut.readDecimals())
) revert InsufficientSwap();
}

/// @dev Fallback `uniswapV3SwapCallback`.
Expand Down
6 changes: 3 additions & 3 deletions test/IE.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ contract IETest is Test {
}

function testCommandSwapETH() public payable {
vm.prank(VITALIK_DOT_ETH);
ie.command{value: 10 ether}("swap 10 eth for 25000 dai"); //price might change in the future.
vm.prank(VITALIK_DOT_ETH); // Note: price might change in the future.
ie.command{value: 10 ether}("swap 10 eth for 25000 dai");
}

function testCommandSwapForETH() public payable {
Expand All @@ -200,7 +200,7 @@ contract IETest is Test {
vm.prank(USDC_WHALE);
IERC20(USDC).approve(address(ie), 100 ether);
vm.prank(USDC_WHALE);
ie.command("swap 100 usdc for 0.035 weth");
ie.command("swap 100 usdc for 0.025 weth");
}

function testCommandSwapUSDCForWBTC() public payable {
Expand Down

0 comments on commit cd8407b

Please sign in to comment.