Skip to content

Commit

Permalink
add simulation to cover usdb
Browse files Browse the repository at this point in the history
  • Loading branch information
novaliu86 committed Jun 29, 2024
1 parent f46d1e8 commit 6c8e4b4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/simulations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@swapnet-xyz/sdk": "^1.0.7",
"@swapnet-xyz/sdk": "^1.0.9",
"ethers": "^6.7.0"
},
"devDependencies": {
Expand Down
70 changes: 70 additions & 0 deletions examples/simulations/src/assets/usdbToWeth10k.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"aggregator": "swapnet",
"sell": {
"referenceId": 0,
"amount": "10000000000000000000000"
},
"buy": {
"referenceId": 1,
"amount": "2943559867392674295"
},
"nativeTokenUsdPrice": 3396.275304220612,
"tokens": [
{
"referenceId": 0,
"address": "0x4300000000000000000000000000000000000003",
"name": "USDB",
"symbol": "USDB",
"decimals": 18,
"usdPrice": 1
},
{
"referenceId": 1,
"address": "0x4300000000000000000000000000000000000004",
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": 18,
"usdPrice": 3396.275304220612
}
],
"routes": [
{
"address": "0xf5A23bDD36a56EDe75D503F6f643d5eaF25B1a8F",
"name": "UniswapV3",
"details": {
"fee": 500
},
"fromTokens": [
{
"referenceId": 0,
"amount": "4083042240667266137755"
}
],
"toTokens": [
{
"referenceId": 1,
"amount": "1202090587291106525"
}
]
},
{
"address": "0x7f0DB0D77d0694F29c3f940b5B1F589FFf6EF2e0",
"name": "ThrusterV3",
"details": {
"fee": 500
},
"fromTokens": [
{
"referenceId": 0,
"amount": "5916957759332733862245"
}
],
"toTokens": [
{
"referenceId": 1,
"amount": "1741469280101567770"
}
]
}
]
}
6 changes: 5 additions & 1 deletion examples/simulations/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { type BlockTag, JsonRpcProvider, Network } from "ethers";
import { IEncodeOptions, ISwapResponse, SettlementSimulation, UniversalRouter, parse, resolveEncodeOptions } from "@swapnet-xyz/sdk";
// import { IEncodeOptions, ISwapResponse, SettlementSimulation, UniversalRouter, parse, resolveEncodeOptions } from "../../../src/index.js";

import orbitToPac10k from './assets/orbitToPac10k.json' assert { type: "json" };
import orbitToEth30k from './assets/orbitToEth30k.json' assert { type: "json" };
import ethToOrbit10 from './assets/ethToOrbit10.json' assert { type: "json" };
import usdbToWeth10k from './assets/usdbToWeth10k.json' assert { type: "json" };

const chainId = 81457;
const network = { chainId, name: "Blast Mainnet" };
Expand Down Expand Up @@ -37,6 +39,7 @@ const simulateAsync = async (
// simulate the calldata with an `eth_call` RPC call, with additional state override to assume sufficient token balances and approvals
const { amountOut } = await SettlementSimulation
.from(blockTag)
// @ts-ignore
.connect(provider)
.runAsync(
senderAddress,
Expand All @@ -59,4 +62,5 @@ const simulateAsync = async (

await simulateAsync('10k ORBIT to PAC', orbitToPac10k, { slippageTolerance: 0.01 }, 5358636);
await simulateAsync('30k ORBIT to ETH', orbitToEth30k, { unwrapOutput: true, slippageTolerance: 0.01 }, 5364002);
await simulateAsync('10 ETH to ORBIT', ethToOrbit10, { wrapInput: true, slippageTolerance: 0.01 }, 5371440);
await simulateAsync('10 ETH to ORBIT', ethToOrbit10, { wrapInput: true, slippageTolerance: 0.01 }, 5371440);
await simulateAsync('10k USDB to WETH', usdbToWeth10k, { slippageTolerance: 0.01 }, 5439322);

0 comments on commit 6c8e4b4

Please sign in to comment.