Skip to content

Commit

Permalink
feat: integrate simulate method
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiHaoLu committed Oct 11, 2024
1 parent c9a9b00 commit 90d8f3a
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"start": "next start"
},
"dependencies": {
"@consenlabs/imaccount-sdk": "^0.1.0",
"@consenlabs/imaccount-sdk": "^0.1.8",
"next": "^13.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"viem": "^2.21.12"
"viem": "^2.21.19"
},
"devDependencies": {
"@types/react": "18.3.7"
Expand Down
46 changes: 40 additions & 6 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PackedUserOperation,
unwrap,
wrap,
SimulateType,
} from "@consenlabs/imaccount-sdk";
import { Address } from "viem";

Expand All @@ -17,6 +18,10 @@ const Home = () => {
"0x4d7f573039fddc84fdb28515ba20d75ef6b987ff"
);
const [network, setNetwork] = useState("11155111");
const [blockNumber, setBlockNumber] = useState("latest");
const [simulateType, setSimulateType] = useState<SimulateType>(
SimulateType.Send
);

// userOp input
const [input, setInput] = useState(`{
Expand Down Expand Up @@ -60,14 +65,15 @@ const Home = () => {

setLoading(true);
try {
console.log(input);
const simulationResult = await simulate(
simulateType,
TENDERLY_ACCESS_KEY,
richBundlerEOA,
parsedInput?.wrapped,
parsedInput.wrapped,
projectOwner,
projectName,
network
network,
blockNumber
);

setResult(JSON.stringify(simulationResult, null, 2));
Expand Down Expand Up @@ -117,6 +123,7 @@ const Home = () => {
}

const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setResult("");
const text = e.target.value;
setInput(text);
try {
Expand Down Expand Up @@ -154,7 +161,7 @@ const Home = () => {
setParsedInput(null);
}
};

const handleResultClick = () => {
const url = result.startsWith('"') ? JSON.parse(result) : result;
window.open(url, "_blank");
Expand Down Expand Up @@ -240,7 +247,6 @@ const Home = () => {
/>
</label>
</div>

<div>
<label>
Chain ID:
Expand All @@ -253,7 +259,35 @@ const Home = () => {
</label>
</div>

<div>
<label>
Block Number:
<input
type="text"
value={blockNumber}
onChange={(e) => setBlockNumber(e.target.value)}
required
/>
</label>
</div>

<h2>2. Give your userOp</h2>
<h3>Simulate Usage</h3>
<div>
<label>
Simulate Type (where you meet the problem?):{" "}
<select
value={simulateType}
onChange={(e) => setSimulateType(e.target.value as SimulateType)}
>
{Object.values(SimulateType).map((type) => (
<option key={type} value={type}>
{type}
</option>
))}
</select>
</label>
</div>
<h3>UserOp Input</h3>
<div>
<label>
Expand Down Expand Up @@ -291,4 +325,4 @@ const Home = () => {
);
};

export default Home;
export default Home;
68 changes: 60 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069"
integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==

"@adraffy/[email protected]":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.11.0.tgz#42cc67c5baa407ac25059fcd7d405cc5ecdb0c33"
integrity sha512-/3DDPKHqqIqxUULp8yP4zODUY1i+2xvVWsv8A79xGWdCAG+8sb0hRh0Rk2QyOJUnnbyPUAZYcpBuRe3nS2OIUg==

"@ampproject/remapping@^2.2.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.3.0.tgz#ed441b6fa600072520ce18b43d2c8cc8caecc7f4"
Expand Down Expand Up @@ -301,10 +306,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@consenlabs/imaccount-sdk@^0.1.0":
version "0.1.2"
resolved "https://npm.pkg.github.com/download/@consenlabs/imaccount-sdk/0.1.2/65bc5ebab5b96a66a985ba476118207b67edfa52#65bc5ebab5b96a66a985ba476118207b67edfa52"
integrity sha512-zalj3jFUTlMjbIQqdI2vO1XBY6VcKJNcnF6E7JK8qqgnWVrbsrmW62xHIrn0BQLROr/ZkRPBVAFFXPMg0lwn9w==
"@consenlabs/imaccount-sdk@^0.1.8":
version "0.1.8"
resolved "https://npm.pkg.github.com/download/@consenlabs/imaccount-sdk/0.1.8/30c4f0b1137d5a2be55aec3f5ffe236798868eae#30c4f0b1137d5a2be55aec3f5ffe236798868eae"
integrity sha512-s3hmst0exY9LgaSuPmf4aZebMhlylnypKDGt5n3U4Az05qISUX3ZTs407/pPOzbv2xpq2Ec8hqpLOkir40Hr5w==
dependencies:
dotenv "^16.4.5"
ethers "^6.13.1"
Expand Down Expand Up @@ -636,7 +641,7 @@
dependencies:
"@noble/hashes" "1.4.0"

"@noble/curves@^1.4.0":
"@noble/curves@1.6.0", "@noble/curves@^1.4.0", "@noble/curves@~1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.6.0.tgz#be5296ebcd5a1730fccea4786d420f87abfeb40b"
integrity sha512-TlaHRXDehJuRNR9TfZDNQ45mMEd5dwUwmicsafcIX4SsNiqnCHKjE/1alYPd/lDRVhxdhUAlv8uEhMCI5zjIJQ==
Expand Down Expand Up @@ -665,7 +670,7 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.5.0.tgz#abadc5ca20332db2b1b2aa3e496e9af1213570b0"
integrity sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==

"@scure/base@~1.1.6", "@scure/base@~1.1.8":
"@scure/base@~1.1.6", "@scure/base@~1.1.7", "@scure/base@~1.1.8":
version "1.1.9"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.9.tgz#e5e142fbbfe251091f9c5f1dd4c834ac04c3dbd1"
integrity sha512-8YKhl8GHiNI/pU2VMaofa2Tor7PJRAjwQLBBuilkJ9L5+13yVbC7JO/wS7piioAvPSwR3JKM1IJ/u4xQzbcXKg==
Expand All @@ -679,6 +684,15 @@
"@noble/hashes" "~1.4.0"
"@scure/base" "~1.1.6"

"@scure/[email protected]":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.5.0.tgz#dd4a2e1b8a9da60e012e776d954c4186db6328e6"
integrity sha512-8EnFYkqEQdnkuGBVpCzKxyIwDCBLDVj3oiX0EKUFre/tOjL/Hqba1D6n/8RcmaQy4f95qQFrO2A8Sr6ybh4NRw==
dependencies:
"@noble/curves" "~1.6.0"
"@noble/hashes" "~1.5.0"
"@scure/base" "~1.1.7"

"@scure/[email protected]":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.4.0.tgz#664d4f851564e2e1d4bffa0339f9546ea55960a6"
Expand Down Expand Up @@ -839,6 +853,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/abitype/-/abitype-1.0.5.tgz#29d0daa3eea867ca90f7e4123144c1d1270774b6"
integrity sha512-YzDhti7cjlfaBhHutMaboYB21Ha3rXR9QTkNJFzYC4kC8YclaiwPBBBJY8ejFdu2wnJeZCVZSMlQJ7fi8S6hsw==

[email protected]:
version "1.0.6"
resolved "https://registry.yarnpkg.com/abitype/-/abitype-1.0.6.tgz#76410903e1d88e34f1362746e2d407513c38565b"
integrity sha512-MMSqYh4+C/aVqI2RQaWqbvI4Kxo5cQV40WQ4QFtDnNzCkqChm8MuENhElmynZlO0qUy/ObkEUaXtKqYnx1Kp3A==

acorn-walk@^8.1.1:
version "8.3.4"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.4.tgz#794dd169c3977edf4ba4ea47583587c5866236b7"
Expand Down Expand Up @@ -1271,7 +1290,7 @@ esprima@^4.0.0:
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==

ethers@^6.13.1, ethers@^6.13.2:
ethers@^6.13.1:
version "6.13.2"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.13.2.tgz#4b67d4b49e69b59893931a032560999e5e4419fe"
integrity sha512-9VkriTTed+/27BGuY1s0hf441kqwHJ1wtN2edksEtiRvXx+soxRX3iSXTfFqq2+YwrOqbDoTHjIhQnjJRlzKmg==
Expand Down Expand Up @@ -1514,6 +1533,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.4.tgz#810cd0d90cc4995c26395d2aa4cfa4037ebdf061"
integrity sha512-hEzjY+x9u9hPmBom9IIAqdJCwNLax+xrPb51vEPpERoFlIxgmZcHzsT5jKG06nvInKOBGvReAVz80Umed5CczQ==

[email protected]:
version "1.0.6"
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.6.tgz#0da29d706fa51551c663c627ace42769850f86e7"
integrity sha512-lPHCayd40oW98/I0uvgaHKWCSvkzY27LjWLbtzOm64yQ+G3Q5npjjbdppU65iZXkK1Zt+kH9pfegli0AYfwYYw==

istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz#2d166c4b0644d43a39f04bf6c2edd1e585f31756"
Expand Down Expand Up @@ -2576,7 +2600,7 @@ v8-to-istanbul@^9.0.1:
"@types/istanbul-lib-coverage" "^2.0.1"
convert-source-map "^2.0.0"

viem@^2.15.1, viem@^2.21.12:
viem@^2.15.1:
version "2.21.13"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.13.tgz#88d07c7c59be6f583dc659535de406c713d36820"
integrity sha512-XBeZEMngw2PNGocLOpL1IEJembuSK+TC8fme5fsZgyh9M+m3MYAc2u1WIyE7X2ZpU0XZm0IM3rpyE8H4RsWsNg==
Expand All @@ -2591,6 +2615,21 @@ viem@^2.15.1, viem@^2.21.12:
webauthn-p256 "0.0.5"
ws "8.17.1"

viem@^2.21.19:
version "2.21.19"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.19.tgz#5e1a7efc45903d83306416ffa2e3a11ed23cd924"
integrity sha512-FdlkN+UI1IU5sYOmzvygkxsUNjDRD5YHht3gZFu2X9xFv6Z3h9pXq9ycrYQ3F17lNfb41O2Ot4/aqbUkwOv9dA==
dependencies:
"@adraffy/ens-normalize" "1.11.0"
"@noble/curves" "1.6.0"
"@noble/hashes" "1.5.0"
"@scure/bip32" "1.5.0"
"@scure/bip39" "1.4.0"
abitype "1.0.6"
isows "1.0.6"
webauthn-p256 "0.0.10"
ws "8.18.0"

walker@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.8.tgz#bd498db477afe573dc04185f011d3ab8a8d7653f"
Expand All @@ -2606,6 +2645,14 @@ [email protected]:
glob-to-regexp "^0.4.1"
graceful-fs "^4.1.2"

[email protected]:
version "0.0.10"
resolved "https://registry.yarnpkg.com/webauthn-p256/-/webauthn-p256-0.0.10.tgz#877e75abe8348d3e14485932968edf3325fd2fdd"
integrity sha512-EeYD+gmIT80YkSIDb2iWq0lq2zbHo1CxHlQTeJ+KkCILWpVy3zASH3ByD4bopzfk0uCwXxLqKGLqp2W4O28VFA==
dependencies:
"@noble/curves" "^1.4.0"
"@noble/hashes" "^1.4.0"

[email protected]:
version "0.0.5"
resolved "https://registry.yarnpkg.com/webauthn-p256/-/webauthn-p256-0.0.5.tgz#0baebd2ba8a414b21cc09c0d40f9dd0be96a06bd"
Expand Down Expand Up @@ -2666,6 +2713,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b"
integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==

[email protected]:
version "8.18.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==

y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
Expand Down

0 comments on commit 90d8f3a

Please sign in to comment.