From 18752d76a22f88c7a92eb91bc61089c1f330ac31 Mon Sep 17 00:00:00 2001 From: Shivanshi Date: Thu, 22 Feb 2024 19:00:42 +0530 Subject: [PATCH 1/7] add .env --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7639b71..42c4870 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ cache ui/node_modules ui/.next -ui/.env \ No newline at end of file +ui/.env + +.env \ No newline at end of file From d3ab2180c48718f219c6706781d9e64ccfc94d1a Mon Sep 17 00:00:00 2001 From: Shivanshi Date: Thu, 22 Feb 2024 19:19:17 +0530 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=99=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/components/header.tsx | 3 ++- ui/components/providers.tsx | 5 +++-- ui/components/shell.tsx | 16 +++++++++++----- ui/components/version.tsx | 18 ++++++++++++++++++ ui/lib/constants.ts | 10 +++++++++- 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 ui/components/version.tsx diff --git a/ui/components/header.tsx b/ui/components/header.tsx index 6bf9b7c..eeadd7b 100644 --- a/ui/components/header.tsx +++ b/ui/components/header.tsx @@ -1,9 +1,10 @@ import { Account } from "./account"; +import { Version } from "./version"; export const Header = () => { return (
-

Nani Intents Shell {"[ Version 1.0.0 ]"}

+

Nani Intents Shell

(c) 2024 Nani Kotoba DAO LLC. All rights reserved.

diff --git a/ui/components/providers.tsx b/ui/components/providers.tsx index 31a6718..da9987e 100644 --- a/ui/components/providers.tsx +++ b/ui/components/providers.tsx @@ -2,7 +2,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { WagmiProvider } from "wagmi"; -import { mainnet, sepolia } from "wagmi/chains"; +import { arbitrum, mainnet, sepolia } from "wagmi/chains"; import { getDefaultConfig, RainbowKitProvider } from "@rainbow-me/rainbowkit"; import { siteConfig } from "@/lib/site"; @@ -12,7 +12,8 @@ const config = getDefaultConfig({ projectId: process.env.NEXT_PUBLIC_WC_ID!, chains: [ mainnet, - sepolia + sepolia, + arbitrum ], ssr: true, }); diff --git a/ui/components/shell.tsx b/ui/components/shell.tsx index 50449ae..29acfa3 100644 --- a/ui/components/shell.tsx +++ b/ui/components/shell.tsx @@ -57,7 +57,10 @@ export const Shell = () => { chainId: mainnet.id, }); const { writeContractAsync } = useWriteContract(); - const client = usePublicClient(); + + const client = usePublicClient({ + chainId: chain ? chain.id : mainnet.id, + }); const addLine = useShellStore((state) => state.addLine); @@ -90,10 +93,12 @@ export const Shell = () => { if (!address) throw new Error("No wallet connected"); if (!chain) throw new Error("No chain connected"); + const ieAddress = IE_ADDRESS[chain.id]; + let value = 0n; const preview = await client.readContract({ - address: IE_ADDRESS, + address: ieAddress, abi: IntentsEngineAbi, functionName: "previewCommand", args: [command], @@ -115,7 +120,7 @@ export const Shell = () => { address: preview[2], abi: erc20Abi, functionName: "allowance", - args: [address, IE_ADDRESS], + args: [address, ieAddress], }); if (allowance < preview[1]) { @@ -124,7 +129,7 @@ export const Shell = () => { address: preview[2], abi: erc20Abi, functionName: "approve", - args: [IE_ADDRESS, maxUint256], + args: [ieAddress, maxUint256], }); addLine( @@ -150,7 +155,7 @@ export const Shell = () => { } const commandTxHash = await writeContractAsync({ - address: IE_ADDRESS, + address: ieAddress, abi: IntentsEngineAbi, functionName: "command", value, @@ -173,6 +178,7 @@ export const Shell = () => { const commandReceipt = await client.waitForTransactionReceipt({ hash: commandTxHash, confirmations: 1, + }); addLine( diff --git a/ui/components/version.tsx b/ui/components/version.tsx new file mode 100644 index 0000000..fda4813 --- /dev/null +++ b/ui/components/version.tsx @@ -0,0 +1,18 @@ +'use client' +import { useAccount } from "wagmi" + +const versions: { + [key: number]: string +} = { + 1: "1.0.0", + 42161: "1.0.1 (nightly)", +} + +export const Version = () => { + const { chain } = useAccount(); + + return + {`[ Version ${versions[chain ? chain.id : 1]} ]`} + +} + diff --git a/ui/lib/constants.ts b/ui/lib/constants.ts index dabcc99..8e90eb1 100644 --- a/ui/lib/constants.ts +++ b/ui/lib/constants.ts @@ -1,2 +1,10 @@ -export const IE_ADDRESS = "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00"; +import { Address } from "viem"; + +export const IE_ADDRESS: { + [key: number]: Address +} = { + 1: "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00", + 42161: "0x000000001e202b5b84e56400f409800065cb6d3c" +}; + export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; From eb16d98896d34b75f7f456adc8a3253fc4e588cb Mon Sep 17 00:00:00 2001 From: ross <92001561+z0r0z@users.noreply.github.com> Date: Sun, 25 Feb 2024 07:34:24 +0000 Subject: [PATCH 3/7] ~~ . --- ui/lib/abi/IntentsEngineAbiArb.ts | 550 ++++++++++++++++++++++++++++++ 1 file changed, 550 insertions(+) create mode 100644 ui/lib/abi/IntentsEngineAbiArb.ts diff --git a/ui/lib/abi/IntentsEngineAbiArb.ts b/ui/lib/abi/IntentsEngineAbiArb.ts new file mode 100644 index 0000000..b59158c --- /dev/null +++ b/ui/lib/abi/IntentsEngineAbiArb.ts @@ -0,0 +1,550 @@ +export const IntentsEngineAbiArb = [ + { + "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": "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": "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": "error", + "name": "InsufficientSwap", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidCharacter", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidSwap", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidSyntax", + "inputs": [] + }, + { + "type": "error", + "name": "Overflow", + "inputs": [] + } + ] as const; + \ No newline at end of file From f5c1b4fbb471cb1bf68998e7af84b2c80caaa8ed Mon Sep 17 00:00:00 2001 From: ross <92001561+z0r0z@users.noreply.github.com> Date: Sun, 25 Feb 2024 07:36:58 +0000 Subject: [PATCH 4/7] ~~ --- .gas-snapshot | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 3c644ac..5d47b59 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -3,11 +3,11 @@ IETest:testBalanceInETH() (gas: 40280) IETest:testCommandSendERC0() (gas: 102922) IETest:testCommandSendETH() (gas: 69404) 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: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) From 05e05ece35f9acf8247a7d033b232d8ecd5a9236 Mon Sep 17 00:00:00 2001 From: Shivanshi Date: Sun, 25 Feb 2024 14:03:16 +0530 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/components/header.tsx | 4 +- ui/components/providers.tsx | 6 +- ui/components/shell.tsx | 290 +++++--- ui/components/version.tsx | 21 +- ui/lib/abi/IntentsEngineAbiArb.ts | 1097 ++++++++++++++--------------- ui/lib/constants.ts | 6 +- 6 files changed, 767 insertions(+), 657 deletions(-) diff --git a/ui/components/header.tsx b/ui/components/header.tsx index eeadd7b..824989a 100644 --- a/ui/components/header.tsx +++ b/ui/components/header.tsx @@ -4,7 +4,9 @@ import { Version } from "./version"; export const Header = () => { return (
-

Nani Intents Shell

+

+ Nani Intents Shell +

(c) 2024 Nani Kotoba DAO LLC. All rights reserved.

diff --git a/ui/components/providers.tsx b/ui/components/providers.tsx index da9987e..395bbc9 100644 --- a/ui/components/providers.tsx +++ b/ui/components/providers.tsx @@ -10,11 +10,7 @@ const config = getDefaultConfig({ appName: siteConfig.name, appDescription: siteConfig.description, projectId: process.env.NEXT_PUBLIC_WC_ID!, - chains: [ - mainnet, - sepolia, - arbitrum - ], + chains: [mainnet, sepolia, arbitrum], ssr: true, }); diff --git a/ui/components/shell.tsx b/ui/components/shell.tsx index 29acfa3..22df8d2 100644 --- a/ui/components/shell.tsx +++ b/ui/components/shell.tsx @@ -10,7 +10,6 @@ import { usePublicClient, useWriteContract, } from "wagmi"; -import { IntentsEngineAbi } from "../lib/abi/IntentsEngineAbi"; import { ETH_ADDRESS, IE_ADDRESS } from "../lib/constants"; import { erc20Abi, @@ -19,10 +18,12 @@ import { maxUint256, zeroAddress, } from "viem"; -import { mainnet } from "viem/chains"; +import { arbitrum, mainnet } from "viem/chains"; import useShellStore from "@/lib/use-shell-store"; import { ShellHistory } from "./shell-history"; import { cn } from "@/lib/utils"; +import { IntentsEngineAbi } from "@/lib/abi/IntentsEngineAbi"; +import { IntentsEngineAbiArb } from "@/lib/abi/IntentsEngineAbiArb"; const formSchema = z.object({ command: z.string().min(2), @@ -57,7 +58,7 @@ export const Shell = () => { chainId: mainnet.id, }); const { writeContractAsync } = useWriteContract(); - + const client = usePublicClient({ chainId: chain ? chain.id : mainnet.id, }); @@ -85,105 +86,217 @@ export const Shell = () => { addLine(

{error.message}

); }; - async function onSubmit({ command }: z.infer) { - try { - form.reset(); - addCommand({ chainId: chain?.id, user: name ?? address, command }); - if (!client) throw new Error("No client available"); - if (!address) throw new Error("No wallet connected"); - if (!chain) throw new Error("No chain connected"); + async function handleArbCommand(command: string) { + if (!client) throw new Error("No client available"); + if (!address) throw new Error("No wallet connected"); - const ieAddress = IE_ADDRESS[chain.id]; + const ieAddress = IE_ADDRESS[arbitrum.id]; - let value = 0n; + let value = 0n; - const preview = await client.readContract({ - address: ieAddress, - abi: IntentsEngineAbi, - functionName: "previewCommand", - args: [command], + const preview = await client.readContract({ + address: ieAddress, + abi: IntentsEngineAbiArb, + functionName: "previewCommand", + args: [command], + }); + const previewedToken = preview[3]; + + addLine(

Preview: {serialize(preview)}

); + + if (isAddressEqual(previewedToken, zeroAddress)) { + // invalid token + throw new Error( + "This token is not supported by the Intents Engine. Did you misspell the token symbol?", + ); + } + + if (isAddressEqual(previewedToken, ETH_ADDRESS)) { + // sending ether directly + value = preview[1]; + } else { + // consent to spend tokens + const allowance = await client.readContract({ + address: previewedToken, + abi: erc20Abi, + functionName: "allowance", + args: [address, ieAddress], }); - addLine(

Preview: {serialize(preview)}

); + if (allowance < preview[1]) { + // we do a lil approve dance + const approveTxHash = await writeContractAsync({ + address: previewedToken, + abi: erc20Abi, + functionName: "approve", + args: [ieAddress, maxUint256], + }); + + addLine( +

+ Approve TX Hash:{" "} + + {approveTxHash} + +

, + ); + + const allowanceReceipt = await client.waitForTransactionReceipt({ + hash: approveTxHash, + confirmations: 1, + }); - if (isAddressEqual(preview[2], zeroAddress)) { - // invalid token - throw new Error("This token is not supported by the Intents Engine. Did you misspell the token symbol?"); + addLine(

Allowance Set. Receipt: {serialize(allowanceReceipt)}

); } + } + + const commandTxHash = await writeContractAsync({ + address: ieAddress, + abi: IntentsEngineAbiArb, + functionName: "command", + value, + args: [command], + }); + + addLine( +

+ Command TX Hash:{" "} + + {commandTxHash} + +

, + ); + + const commandReceipt = await client.waitForTransactionReceipt({ + hash: commandTxHash, + confirmations: 1, + }); + + addLine(

Command Executed. Receipt: {JSON.stringify(commandReceipt)}

); + } + + async function handleMainnetCommand(command: string) { + if (!client) throw new Error("No client available"); + if (!address) throw new Error("No wallet connected"); + + const ieAddress = IE_ADDRESS[mainnet.id]; + + let value = 0n; - if (isAddressEqual(preview[2], ETH_ADDRESS)) { - // sending ether directly - value = preview[1]; - } else { - // consent to spend tokens - const allowance = await client.readContract({ + const preview = await client.readContract({ + address: ieAddress, + abi: IntentsEngineAbi, + functionName: "previewCommand", + args: [command], + }); + + addLine(

Preview: {serialize(preview)}

); + + if (isAddressEqual(preview[2], zeroAddress)) { + // invalid token + throw new Error( + "This token is not supported by the Intents Engine. Did you misspell the token symbol?", + ); + } + + if (isAddressEqual(preview[2], ETH_ADDRESS)) { + // sending ether directly + value = preview[1]; + } else { + // consent to spend tokens + const allowance = await client.readContract({ + address: preview[2], + abi: erc20Abi, + functionName: "allowance", + args: [address, ieAddress], + }); + + if (allowance < preview[1]) { + // we do a lil approve dance + const approveTxHash = await writeContractAsync({ address: preview[2], abi: erc20Abi, - functionName: "allowance", - args: [address, ieAddress], + functionName: "approve", + args: [ieAddress, maxUint256], }); - - if (allowance < preview[1]) { - // we do a lil approve dance - const approveTxHash = await writeContractAsync({ - address: preview[2], - abi: erc20Abi, - functionName: "approve", - args: [ieAddress, maxUint256], - }); - - addLine( -

- Approve TX Hash:{" "} - - {approveTxHash} - -

, - ); - - const allowanceReceipt = await client.waitForTransactionReceipt({ - hash: approveTxHash, - confirmations: 1, - }); - - addLine(

Allowance Set. Receipt: {serialize(allowanceReceipt)}

); - } + + addLine( +

+ Approve TX Hash:{" "} + + {approveTxHash} + +

, + ); + + const allowanceReceipt = await client.waitForTransactionReceipt({ + hash: approveTxHash, + confirmations: 1, + }); + + addLine(

Allowance Set. Receipt: {serialize(allowanceReceipt)}

); } + } - const commandTxHash = await writeContractAsync({ - address: ieAddress, - abi: IntentsEngineAbi, - functionName: "command", - value, - args: [command], - }); + const commandTxHash = await writeContractAsync({ + address: ieAddress, + abi: IntentsEngineAbi, + functionName: "command", + value, + args: [command], + }); - addLine( -

- Command TX Hash:{" "} - - {commandTxHash} - -

, - ); + addLine( +

+ Command TX Hash:{" "} + + {commandTxHash} + +

, + ); - const commandReceipt = await client.waitForTransactionReceipt({ - hash: commandTxHash, - confirmations: 1, - - }); + const commandReceipt = await client.waitForTransactionReceipt({ + hash: commandTxHash, + confirmations: 1, + }); - addLine( -

Command Executed. Receipt: {JSON.stringify(commandReceipt)}

, - ); + addLine(

Command Executed. Receipt: {JSON.stringify(commandReceipt)}

); + } + + async function onSubmit({ command }: z.infer) { + try { + form.reset(); + addCommand({ chainId: chain?.id, user: name ?? address, command }); + if (!client) throw new Error("No client available"); + if (!address) throw new Error("No wallet connected"); + if (!chain) throw new Error("No chain connected"); + + switch (chain.id) { + case arbitrum.id: + await handleArbCommand(command); + break; + case mainnet.id: + await handleMainnetCommand(command); + break; + default: + throw new Error("Unsupported chain"); + } } catch (error) { console.error(error); error instanceof Error @@ -212,7 +325,10 @@ export const Shell = () => { {id} diff --git a/ui/components/version.tsx b/ui/components/version.tsx index fda4813..ca051ca 100644 --- a/ui/components/version.tsx +++ b/ui/components/version.tsx @@ -1,18 +1,15 @@ -'use client' -import { useAccount } from "wagmi" +"use client"; +import { useAccount } from "wagmi"; const versions: { - [key: number]: string + [key: number]: string; } = { - 1: "1.0.0", - 42161: "1.0.1 (nightly)", -} + 1: "1.0.0", + 42161: "1.0.1 (nightly)", +}; export const Version = () => { - const { chain } = useAccount(); - - return - {`[ Version ${versions[chain ? chain.id : 1]} ]`} - -} + const { chain } = useAccount(); + return {`[ Version ${versions[chain ? chain.id : 1]} ]`}; +}; diff --git a/ui/lib/abi/IntentsEngineAbiArb.ts b/ui/lib/abi/IntentsEngineAbiArb.ts index b59158c..000b698 100644 --- a/ui/lib/abi/IntentsEngineAbiArb.ts +++ b/ui/lib/abi/IntentsEngineAbiArb.ts @@ -1,550 +1,549 @@ export const IntentsEngineAbiArb = [ - { - "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": "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": "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": "error", - "name": "InsufficientSwap", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidCharacter", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidSwap", - "inputs": [] - }, - { - "type": "error", - "name": "InvalidSyntax", - "inputs": [] - }, - { - "type": "error", - "name": "Overflow", - "inputs": [] - } - ] as const; - \ 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: "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: "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: "error", + name: "InsufficientSwap", + inputs: [], + }, + { + type: "error", + name: "InvalidCharacter", + inputs: [], + }, + { + type: "error", + name: "InvalidSwap", + inputs: [], + }, + { + type: "error", + name: "InvalidSyntax", + inputs: [], + }, + { + type: "error", + name: "Overflow", + inputs: [], + }, +] as const; diff --git a/ui/lib/constants.ts b/ui/lib/constants.ts index 8e90eb1..690a9e5 100644 --- a/ui/lib/constants.ts +++ b/ui/lib/constants.ts @@ -1,10 +1,10 @@ import { Address } from "viem"; export const IE_ADDRESS: { - [key: number]: Address + [key: number]: Address; } = { - 1: "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00", - 42161: "0x000000001e202b5b84e56400f409800065cb6d3c" + 1: "0x1E00000000Cf8ba83e0005c59c1Bf1C4682C8E00", + 42161: "0x000000001e202b5b84e56400f409800065cb6d3c", }; export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; From 92b74d1e937094c14257e24e47ff469a857c0bc9 Mon Sep 17 00:00:00 2001 From: Shivanshi Date: Mon, 26 Feb 2024 23:15:21 +0530 Subject: [PATCH 6/7] nits --- ui/components/account.tsx | 2 +- ui/components/providers.tsx | 44 +++++++++++++++++++++++++++++++++++-- ui/components/shell.tsx | 12 ++++++---- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/ui/components/account.tsx b/ui/components/account.tsx index c1b78e9..2526e95 100644 --- a/ui/components/account.tsx +++ b/ui/components/account.tsx @@ -26,7 +26,7 @@ export const Account = () => { Connected to{" "}