diff --git a/tests/__snapshots__/partialSdk.test.ts.snap b/tests/__snapshots__/partialSdk.test.ts.snap index 31754031..c4388cf7 100644 --- a/tests/__snapshots__/partialSdk.test.ts.snap +++ b/tests/__snapshots__/partialSdk.test.ts.snap @@ -61,6 +61,85 @@ Object { } `; +exports[`ParaSwap SDK: fetching methods: axiosFetcher Get_SwapTxData: Get_SwapTxData::priceRoute 1`] = ` +Object { + "bestRoute": Array [ + Object { + "percent": 100, + "swaps": Array [ + Object { + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "swapExchanges": Array [ + Object { + "data": Object { + "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", + "feeFactor": 10000, + "gasUSD": "dynamic_number", + "initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f", + "path": Array [ + "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "0x6b175474e89094c44da98b954eedeac495271d0f", + ], + "pools": Array [ + Object { + "address": "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + "direction": false, + "fee": 30, + }, + ], + "router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07", + }, + "destAmount": "dynamic_number", + "exchange": "UniswapV2", + "percent": 100, + "poolAddresses": Array [ + "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + ], + "srcAmount": "1000000000000000000", + }, + ], + }, + ], + }, + ], + "blockNumber": "dynamic_number", + "contractAddress": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "contractMethod": "swapOnUniswapV2Fork", + "destAmount": "dynamic_number", + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "destUSD": "dynamic_number", + "gasCost": "dynamic_number", + "gasCostUSD": "dynamic_number", + "hmac": "dynamic_number", + "maxImpactReached": false, + "network": 1, + "partner": "anon", + "partnerFee": 0, + "side": "SELL", + "srcAmount": "1000000000000000000", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "srcUSD": "dynamic_number", + "tokenTransferProxy": "0x216b4b4ba9f3e719726886d34a177484278bfcae", + "version": "5", +} +`; + +exports[`ParaSwap SDK: fetching methods: axiosFetcher Get_SwapTxData: Get_SwapTxData::txParams 1`] = ` +Object { + "chainId": 1, + "data": "dynamic_string", + "from": "dynamic_string", + "gasPrice": "dynamic_number", + "to": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "value": "1000000000000000000", +} +`; + exports[`ParaSwap SDK: fetching methods: fetchFetcher Get_Adapters: Get_Adapters 1`] = ` Array [ "Bancor", @@ -121,3 +200,82 @@ Object { "TokenTransferProxy": "0x216b4b4ba9f3e719726886d34a177484278bfcae", } `; + +exports[`ParaSwap SDK: fetching methods: fetchFetcher Get_SwapTxData: Get_SwapTxData::priceRoute 1`] = ` +Object { + "bestRoute": Array [ + Object { + "percent": 100, + "swaps": Array [ + Object { + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "swapExchanges": Array [ + Object { + "data": Object { + "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", + "feeFactor": 10000, + "gasUSD": "dynamic_number", + "initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f", + "path": Array [ + "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "0x6b175474e89094c44da98b954eedeac495271d0f", + ], + "pools": Array [ + Object { + "address": "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + "direction": false, + "fee": 30, + }, + ], + "router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07", + }, + "destAmount": "dynamic_number", + "exchange": "UniswapV2", + "percent": 100, + "poolAddresses": Array [ + "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + ], + "srcAmount": "1000000000000000000", + }, + ], + }, + ], + }, + ], + "blockNumber": "dynamic_number", + "contractAddress": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "contractMethod": "swapOnUniswapV2Fork", + "destAmount": "dynamic_number", + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "destUSD": "dynamic_number", + "gasCost": "dynamic_number", + "gasCostUSD": "dynamic_number", + "hmac": "dynamic_number", + "maxImpactReached": false, + "network": 1, + "partner": "anon", + "partnerFee": 0, + "side": "SELL", + "srcAmount": "1000000000000000000", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "srcUSD": "dynamic_number", + "tokenTransferProxy": "0x216b4b4ba9f3e719726886d34a177484278bfcae", + "version": "5", +} +`; + +exports[`ParaSwap SDK: fetching methods: fetchFetcher Get_SwapTxData: Get_SwapTxData::txParams 1`] = ` +Object { + "chainId": 1, + "data": "dynamic_string", + "from": "dynamic_string", + "gasPrice": "dynamic_number", + "to": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "value": "1000000000000000000", +} +`; diff --git a/tests/__snapshots__/simpleSdk.test.ts.snap b/tests/__snapshots__/simpleSdk.test.ts.snap index 93752eb5..247e4f15 100644 --- a/tests/__snapshots__/simpleSdk.test.ts.snap +++ b/tests/__snapshots__/simpleSdk.test.ts.snap @@ -51,6 +51,85 @@ Array [ ] `; +exports[`ParaSwap SDK: fetcher made with: axios Get_SwapTxData: Get_SwapTxData::priceRoute 1`] = ` +Object { + "bestRoute": Array [ + Object { + "percent": 100, + "swaps": Array [ + Object { + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "swapExchanges": Array [ + Object { + "data": Object { + "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", + "feeFactor": 10000, + "gasUSD": "dynamic_number", + "initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f", + "path": Array [ + "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "0x6b175474e89094c44da98b954eedeac495271d0f", + ], + "pools": Array [ + Object { + "address": "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + "direction": false, + "fee": 30, + }, + ], + "router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07", + }, + "destAmount": "dynamic_number", + "exchange": "UniswapV2", + "percent": 100, + "poolAddresses": Array [ + "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + ], + "srcAmount": "1000000000000000000", + }, + ], + }, + ], + }, + ], + "blockNumber": "dynamic_number", + "contractAddress": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "contractMethod": "swapOnUniswapV2Fork", + "destAmount": "dynamic_number", + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "destUSD": "dynamic_number", + "gasCost": "dynamic_number", + "gasCostUSD": "dynamic_number", + "hmac": "dynamic_number", + "maxImpactReached": false, + "network": 1, + "partner": "anon", + "partnerFee": 0, + "side": "SELL", + "srcAmount": "1000000000000000000", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "srcUSD": "dynamic_number", + "tokenTransferProxy": "0x216b4b4ba9f3e719726886d34a177484278bfcae", + "version": "5", +} +`; + +exports[`ParaSwap SDK: fetcher made with: axios Get_SwapTxData: Get_SwapTxData::txParams 1`] = ` +Object { + "chainId": 1, + "data": "dynamic_string", + "from": "dynamic_string", + "gasPrice": "dynamic_number", + "to": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "value": "1000000000000000000", +} +`; + exports[`ParaSwap SDK: fetcher made with: fetch Get_Adapters: Get_Adapters 1`] = ` Array [ "Bancor", @@ -101,3 +180,82 @@ Array [ "AugustusRFQ", ] `; + +exports[`ParaSwap SDK: fetcher made with: fetch Get_SwapTxData: Get_SwapTxData::priceRoute 1`] = ` +Object { + "bestRoute": Array [ + Object { + "percent": 100, + "swaps": Array [ + Object { + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "swapExchanges": Array [ + Object { + "data": Object { + "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", + "feeFactor": 10000, + "gasUSD": "dynamic_number", + "initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f", + "path": Array [ + "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "0x6b175474e89094c44da98b954eedeac495271d0f", + ], + "pools": Array [ + Object { + "address": "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + "direction": false, + "fee": 30, + }, + ], + "router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07", + }, + "destAmount": "dynamic_number", + "exchange": "UniswapV2", + "percent": 100, + "poolAddresses": Array [ + "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", + ], + "srcAmount": "1000000000000000000", + }, + ], + }, + ], + }, + ], + "blockNumber": "dynamic_number", + "contractAddress": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "contractMethod": "swapOnUniswapV2Fork", + "destAmount": "dynamic_number", + "destDecimals": 18, + "destToken": "0x6b175474e89094c44da98b954eedeac495271d0f", + "destUSD": "dynamic_number", + "gasCost": "dynamic_number", + "gasCostUSD": "dynamic_number", + "hmac": "dynamic_number", + "maxImpactReached": false, + "network": 1, + "partner": "anon", + "partnerFee": 0, + "side": "SELL", + "srcAmount": "1000000000000000000", + "srcDecimals": 18, + "srcToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "srcUSD": "dynamic_number", + "tokenTransferProxy": "0x216b4b4ba9f3e719726886d34a177484278bfcae", + "version": "5", +} +`; + +exports[`ParaSwap SDK: fetcher made with: fetch Get_SwapTxData: Get_SwapTxData::txParams 1`] = ` +Object { + "chainId": 1, + "data": "dynamic_string", + "from": "dynamic_string", + "gasPrice": "dynamic_number", + "to": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57", + "value": "1000000000000000000", +} +`; diff --git a/tests/partialSdk.test.ts b/tests/partialSdk.test.ts index 8be67356..5b01abce 100644 --- a/tests/partialSdk.test.ts +++ b/tests/partialSdk.test.ts @@ -29,6 +29,8 @@ import { GetRateFunctions, isAllowance, SwapSide, + GetSwapTxFunctions, + constructSwapTx, } from '../src'; import BigNumber from 'bignumber.js'; @@ -119,7 +121,8 @@ describe.each([ GetTokensFunctions & GetRateFunctions & GetSpenderFunctions & - BuildTxFunctions; + BuildTxFunctions & + GetSwapTxFunctions; beforeAll(() => { paraSwap = constructPartialSDK( @@ -129,7 +132,8 @@ describe.each([ constructGetTokens, constructGetRate, constructGetSpender, - constructBuildTx + constructBuildTx, + constructSwapTx ); }); test('getBalance', async () => { @@ -207,6 +211,59 @@ describe.each([ ); }); + test('Get_SwapTxData', async () => { + const { priceRoute, txParams } = await paraSwap.getSwapTxData({ + srcToken: ETH, + destToken: DAI, + amount: srcAmount, + userAddress: senderAddress, + side: SwapSide.SELL, + slippage: 500, + options: { + includeDEXS: ['UniswapV2'], + }, + }); + + const bestRouteStable = priceRoute.bestRoute.map((b) => ({ + ...b, + swaps: b.swaps.map((s) => ({ + ...s, + swapExchanges: s.swapExchanges.map((se) => ({ + ...se, + destAmount: 'dynamic_number', + data: { + ...se.data, + gasUSD: 'dynamic_number', + }, + })), + })), + })); + + const priceRouteStable = { + ...priceRoute, + gasCost: 'dynamic_number', + gasCostUSD: 'dynamic_number', + hmac: 'dynamic_number', + destAmount: 'dynamic_number', + blockNumber: 'dynamic_number', + srcUSD: 'dynamic_number', + destUSD: 'dynamic_number', + bestRoute: bestRouteStable, + }; + + const txParamsStable = { + ...txParams, + data: 'dynamic_string', + from: 'dynamic_string', + gasPrice: 'dynamic_number', + }; + + expect(txParams.from).toEqual(senderAddress); + + expect(priceRouteStable).toMatchSnapshot('Get_SwapTxData::priceRoute'); + expect(txParamsStable).toMatchSnapshot('Get_SwapTxData::txParams'); + }); + test('Get_Spender', async () => { const spender = await paraSwap.getSpender(); expect(web3provider.utils.isAddress(spender)).toBe(true); diff --git a/tests/simpleSdk.test.ts b/tests/simpleSdk.test.ts index 21879aec..36a2da6c 100644 --- a/tests/simpleSdk.test.ts +++ b/tests/simpleSdk.test.ts @@ -144,6 +144,59 @@ describe.each([ ); }); + test('Get_SwapTxData', async () => { + const { priceRoute, txParams } = await paraSwap.swap.getSwapTxData({ + srcToken: ETH, + destToken: DAI, + amount: srcAmount, + userAddress: senderAddress, + side: SwapSide.SELL, + slippage: 500, + options: { + includeDEXS: ['UniswapV2'], + }, + }); + + const bestRouteStable = priceRoute.bestRoute.map((b) => ({ + ...b, + swaps: b.swaps.map((s) => ({ + ...s, + swapExchanges: s.swapExchanges.map((se) => ({ + ...se, + destAmount: 'dynamic_number', + data: { + ...se.data, + gasUSD: 'dynamic_number', + }, + })), + })), + })); + + const priceRouteStable = { + ...priceRoute, + gasCost: 'dynamic_number', + gasCostUSD: 'dynamic_number', + hmac: 'dynamic_number', + destAmount: 'dynamic_number', + blockNumber: 'dynamic_number', + srcUSD: 'dynamic_number', + destUSD: 'dynamic_number', + bestRoute: bestRouteStable, + }; + + const txParamsStable = { + ...txParams, + data: 'dynamic_string', + from: 'dynamic_string', + gasPrice: 'dynamic_number', + }; + + expect(txParams.from).toEqual(senderAddress); + + expect(priceRouteStable).toMatchSnapshot('Get_SwapTxData::priceRoute'); + expect(txParamsStable).toMatchSnapshot('Get_SwapTxData::txParams'); + }); + test('Get_Spender', async () => { const spender = await paraSwap.swap.getSpender(); expect(web3provider.utils.isAddress(spender));