diff --git a/core/tests/protocols/aave.spec.ts b/core/tests/protocols/aave.spec.ts index bedd1de..bb23111 100644 --- a/core/tests/protocols/aave.spec.ts +++ b/core/tests/protocols/aave.spec.ts @@ -1,88 +1,20 @@ import { test } from "vitest"; -import { generateTransaction } from "core/src/transaction/generate-transaction"; -import { AssetStore } from "core/src/transaction/types"; -import { loadConfig } from "core/src/config/load-config"; -import { simulateRouterOperation } from "core/src/path/tx-simulator"; -import { getProvider } from "core/src/utils/get-provider"; +import { simulateSingleAssetToSingleAsset } from "./utils"; test("generateTransaction: USDC to aPolUSDC (aaveV3Deposit)", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountStr: "1000000000", - }, - ], - outputAllocation: [ - { - assetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), + inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + outputAssetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", amountIn: "1000000000", - buyAsset: assetStore.getAssetById("371b83f1-3301-4c69-b3ad-8d199c6d1774"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test.skip("generateTransaction: aPolUSDC (aaveV3Deposit) to USDC", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", - amountStr: "1000000000", - }, - ], - outputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("371b83f1-3301-4c69-b3ad-8d199c6d1774"), + inputAssetId: "371b83f1-3301-4c69-b3ad-8d199c6d1774", + outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", amountIn: "1000000000", - buyAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); diff --git a/core/tests/protocols/beefy.spec.ts b/core/tests/protocols/beefy.spec.ts index 4a58e36..4d5b7c0 100644 --- a/core/tests/protocols/beefy.spec.ts +++ b/core/tests/protocols/beefy.spec.ts @@ -1,88 +1,20 @@ import { test } from "vitest"; -import { generateTransaction } from "core/src/transaction/generate-transaction"; -import { AssetStore } from "core/src/transaction/types"; -import { loadConfig } from "core/src/config/load-config"; -import { simulateRouterOperation } from "core/src/path/tx-simulator"; -import { getProvider } from "core/src/utils/get-provider"; +import { simulateSingleAssetToSingleAsset } from "./utils"; test("generateTransaction: USDC to QUICK (beefyDeposit)", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountStr: "1000000000", - }, - ], - outputAllocation: [ - { - assetId: "37819023-9c6a-4848-8cf5-24a95350f001", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), + inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + outputAssetId: "37819023-9c6a-4848-8cf5-24a95350f001", amountIn: "1000000000", - buyAsset: assetStore.getAssetById("37819023-9c6a-4848-8cf5-24a95350f001"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test.skip("generateTransaction: beefy.finance (beefyDeposit) to USDC", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "fecfd33d-e6a7-476b-89cb-910a0058fa48", - amountStr: "1000000", - }, - ], - outputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("fecfd33d-e6a7-476b-89cb-910a0058fa48"), + inputAssetId: "fecfd33d-e6a7-476b-89cb-910a0058fa48", + outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", amountIn: "1000000", - buyAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); diff --git a/core/tests/protocols/gamma.spec.ts b/core/tests/protocols/gamma.spec.ts index 9322066..d164ec9 100644 --- a/core/tests/protocols/gamma.spec.ts +++ b/core/tests/protocols/gamma.spec.ts @@ -1,293 +1,65 @@ import { test } from "vitest"; -import { generateTransaction } from "core/src/transaction/generate-transaction"; -import { AssetStore } from "core/src/transaction/types"; -import { loadConfig } from "core/src/config/load-config"; -import { simulateRouterOperation } from "core/src/path/tx-simulator"; -import { getProvider } from "core/src/utils/get-provider"; +import { simulateSingleAssetToSingleAsset } from "./utils"; test("generateTransaction: USDC to USDC/WETH (gammaDeposit)", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountStr: "1000000000", - }, - ], - outputAllocation: [ - { - assetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), + inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + outputAssetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", amountIn: "1000000000", - buyAsset: assetStore.getAssetById("8da84d12-9e9d-4c04-831d-7b93f1cd822f"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test("generateTransaction: USDC to WMATIC/WETH (gammaDeposit)", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountStr: "1000000000", - }, - ], - outputAllocation: [ - { - assetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", - fraction: 1.0, - }, - ], - assetStore, - chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ + simulateSingleAssetToSingleAsset({ chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), + inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + outputAssetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", amountIn: "1000000000", - buyAsset: assetStore.getAssetById("3c42b7d3-555b-41a4-96b6-ce4fadd62f83"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test("generateTransaction: USDC to WMATIC/MaticX (gammaDeposit)", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - amountStr: "1000000000", - }, - ], - outputAllocation: [ - { - assetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", - fraction: 1.0, - }, - ], - assetStore, - chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ + simulateSingleAssetToSingleAsset({ chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), + inputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", + outputAssetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", amountIn: "1000000000", - buyAsset: assetStore.getAssetById("5a5cd640-b972-43b6-9bb2-24e6711ab1db"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test("generateTransaction: WMATIC/MaticX (gammaDeposit) to USDC", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", - amountStr: "1000000000000000000000", - }, - ], - outputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("5a5cd640-b972-43b6-9bb2-24e6711ab1db"), + inputAssetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", + outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", amountIn: "1000000000000000000000", - buyAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test("generateTransaction: WMATIC/WETH (gammaDeposit) to USDC", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", - amountStr: "1000000000000000000", - }, - ], - outputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("3c42b7d3-555b-41a4-96b6-ce4fadd62f83"), + inputAssetId: "3c42b7d3-555b-41a4-96b6-ce4fadd62f83", + outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", amountIn: "1000000000000000000", - buyAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test("generateTransaction: USDC/WETH (gammaDeposit) to USDC", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", - amountStr: "1000000000000000000", - }, - ], - outputAllocation: [ - { - assetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("8da84d12-9e9d-4c04-831d-7b93f1cd822f"), + inputAssetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", + outputAssetId: "e251ecf6-48c2-4538-afcd-fbb92424054d", amountIn: "1000000000000000000", - buyAsset: assetStore.getAssetById("e251ecf6-48c2-4538-afcd-fbb92424054d"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); test("generateTransaction: USDC/WETH (gammaDeposit) to WMATIC/MaticX (gammaDeposit)", async () => { - const assetStore = new AssetStore(); - const config = await loadConfig(); - const provider = await getProvider({ chainId: 137 }); - - const routerOperation = await generateTransaction({ - inputAllocation: [ - { - assetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", - amountStr: "1000000000000000000", - }, - ], - outputAllocation: [ - { - assetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", - fraction: 1.0, - }, - ], - assetStore, + simulateSingleAssetToSingleAsset({ chainId: 137, - walletAddress: config.networks[137].routerSimulatorAddress, - }); - - const result = await simulateRouterOperation({ - chainId: 137, - routerOperation, - provider, - sellAsset: assetStore.getAssetById("8da84d12-9e9d-4c04-831d-7b93f1cd822f"), + inputAssetId: "8da84d12-9e9d-4c04-831d-7b93f1cd822f", + outputAssetId: "5a5cd640-b972-43b6-9bb2-24e6711ab1db", amountIn: "1000000000000000000", - buyAsset: assetStore.getAssetById("5a5cd640-b972-43b6-9bb2-24e6711ab1db"), }); - - console.dir( - { - encodedTransactionData: routerOperation.getEncodedTransactionData(), - result, - }, - { depth: null, maxStringLength: null } - ); }); diff --git a/core/tests/protocols/utils.ts b/core/tests/protocols/utils.ts new file mode 100644 index 0000000..30f9d81 --- /dev/null +++ b/core/tests/protocols/utils.ts @@ -0,0 +1,46 @@ +import { AssetStore, generateTransaction, loadConfig } from "core"; +import { simulateRouterOperation } from "core/src/path/tx-simulator"; +import { getProvider } from "core/src/utils/get-provider"; + +export async function simulateSingleAssetToSingleAsset({ + chainId, + inputAssetId, + outputAssetId, + amountIn, +}: { + chainId: number; + inputAssetId: string; + outputAssetId: string; + amountIn: string; +}) { + const assetStore = new AssetStore(); + const config = await loadConfig(); + const provider = await getProvider({ chainId: 137 }); + + const routerOperation = await generateTransaction({ + inputAllocation: [{ assetId: inputAssetId, amountStr: amountIn }], + outputAllocation: [{ assetId: outputAssetId, fraction: 1.0 }], + assetStore, + chainId, + walletAddress: config.networks[chainId].routerSimulatorAddress, + }); + + const result = await simulateRouterOperation({ + chainId, + routerOperation, + provider, + sellAsset: assetStore.getAssetById(inputAssetId), + amountIn, + buyAsset: assetStore.getAssetById(outputAssetId), + }); + + console.dir( + { + encodedTransactionData: routerOperation.getEncodedTransactionData(), + result, + }, + { depth: null, maxStringLength: null } + ); + + return result; +}