From 1b2a79bff6dc76817ce759f5264172c4d3293033 Mon Sep 17 00:00:00 2001 From: pseudoelement Date: Wed, 25 Dec 2024 01:13:00 +0300 Subject: [PATCH 1/5] fix-dedust --- .../dedust/dedust-swap-payload_test.spec.ts | 213 ++++++++++++++++++ package.json | 5 +- .../on-chain-manager-aggregators-types.ts | 3 +- .../dedust/services/dedust-api-service.ts | 8 +- .../dedust/services/dedust-swap-service.ts | 70 +++--- 5 files changed, 263 insertions(+), 36 deletions(-) create mode 100644 __tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts diff --git a/__tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts b/__tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts new file mode 100644 index 00000000000..5da97055ca3 --- /dev/null +++ b/__tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts @@ -0,0 +1,213 @@ +import { SwapStep } from '@dedust/sdk'; +import { Address } from '@ton/core'; +import { DedustSwapService } from '../../../src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service'; + +interface TestCase { + caseName: string; + payload: SwapStep; + expects: boolean; +} + +describe('dedust', () => { + const swapSrv = new DedustSwapService(); + const testCases = [ + { + caseName: '1_item_payload_correct', + expects: true, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1) + } + }, + { + caseName: '1_item_payload_empty_next', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: {} + } + }, + { + caseName: '2_item_payload_empty_next', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: {} + } + } + }, + { + caseName: '2_item_payload_empty_poolAddress', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: '', + limit: BigInt(1) + } + } + }, + { + caseName: '2_item_payload_undefined_poolAddress', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: undefined, + limit: BigInt(1) + } + } + }, + { + caseName: '2_item_payload_correct', + expects: true, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1) + } + } + }, + { + caseName: '3_item_payload_correct', + expects: true, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1) + } + } + } + }, + { + caseName: '3_item_payload_empty_next', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1), + next: {} + } + } + } + }, + { + caseName: '3_item_payload_empty_poolAddress', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: '', + limit: BigInt(1), + next: {} + } + } + } + }, + { + caseName: '4_item_payload_correct', + expects: true, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1) + } + } + } + } + }, + { + caseName: '4_item_payload_empty_next', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1), + next: {} + } + } + } + } + }, + { + caseName: '4_item_payload_null_poolAddress', + expects: false, + payload: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), + limit: BigInt(1), + next: { + poolAddress: Address.parse( + 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' + ), + limit: BigInt(1), + next: { + poolAddress: null, + limit: BigInt(1) + } + } + } + } + } + ] as TestCase[]; + + it('tt', () => { + for (const testCase of testCases) { + const answer = swapSrv.checkSwapPayloadValid(testCase.payload); + expect(answer).toBe(testCase.expects); + } + }); +}); diff --git a/package.json b/package.json index 4baff5c1cd2..2089dbdbfc8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "5.49.6", + "version": "5.49.7-alpha.ton.3", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -67,7 +67,8 @@ "analyze": "webpack --profile --json > stats.json && webpack-bundle-analyzer stats.json", "docs": "yarn create-index && typedoc && yarn delete-index", "publish": "yarn publish --access public", - "publish:alpha": "yarn publish --access public --tag alpha" + "publish:alpha": "yarn publish --access public --tag alpha", + "test:file": "jest -- __tests__/unit-tests/dedust" }, "dependencies": { "@1inch/limit-order-protocol-utils": "3.0.1", diff --git a/src/features/on-chain/calculation-manager/models/on-chain-manager-aggregators-types.ts b/src/features/on-chain/calculation-manager/models/on-chain-manager-aggregators-types.ts index 17c6f2dceb1..05ed243cc90 100644 --- a/src/features/on-chain/calculation-manager/models/on-chain-manager-aggregators-types.ts +++ b/src/features/on-chain/calculation-manager/models/on-chain-manager-aggregators-types.ts @@ -3,6 +3,7 @@ import { DlnOnChainProvider } from 'src/features/on-chain/calculation-manager/pr import { PiteasProvider } from 'src/features/on-chain/calculation-manager/providers/aggregators/piteas/piteas-provider'; import { CoffeeSwapProvider } from '../providers/aggregators/coffee-swap/coffee-swap-on-chain-provider'; +import { DedustOnChainProvider } from '../providers/aggregators/dedust/dedust-on-chain-provider'; import { LifiProvider } from '../providers/aggregators/lifi/lifi-provider'; import { NativeRouterProvider } from '../providers/aggregators/native-router/native-router-provider'; import { OdosOnChainProvider } from '../providers/aggregators/odos/odos-on-chain-provider'; @@ -28,7 +29,7 @@ export const AGGREGATORS_ON_CHAIN = { ONE_INCH: OneInchProvider, ZETA_SWAP: ZetaSwapProvider, NATIVE_ROUTER: NativeRouterProvider, - // DEDUST: DedustOnChainProvider, + DEDUST: DedustOnChainProvider, //STONFI: StonfiOnChainProvider, COFFEE_SWAP: CoffeeSwapProvider, SQUIDROUTER: SquidRouterOnChainProvider, diff --git a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-api-service.ts b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-api-service.ts index b1e80ad9808..d1e3c29f159 100644 --- a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-api-service.ts +++ b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-api-service.ts @@ -1,4 +1,5 @@ import { Address } from '@ton/core'; +import { RubicSdkError } from 'src/common/errors'; import { PriceTokenAmount, Token } from 'src/common/tokens'; import { TonWeb3Pure } from 'src/core/blockchain/web3-pure/typed-web3-pure/ton-web3-pure/ton-web3-pure'; import { Injector } from 'src/core/injector/injector'; @@ -17,7 +18,7 @@ export class DedustApiService { const fromRawAddress = from.isNative ? 'native' : `jetton:${fromAddresses.raw_form}`; const toRawAddress = to.isNative ? 'native' : `jetton:${toAddresses.raw_form}`; - const [pools] = await Injector.httpClient.post( + const resp = await Injector.httpClient.post( `${this.apiUrl}/routing/plan`, { from: fromRawAddress, @@ -26,6 +27,11 @@ export class DedustApiService { } ); + if (resp.length > 1) { + throw new RubicSdkError('Multihop swaps are forbidden in dedust.'); + } + const pools = resp[0]; + return pools.map(p => ({ amountOut: p.amountOut, poolAddress: Address.parse(p.pool.address), diff --git a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts index af8de334ee0..010647dcb80 100644 --- a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts +++ b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts @@ -260,18 +260,19 @@ export class DedustSwapService { const jettonRoot = this.tonClient.open(JettonRoot.createFromAddress(parsedAddress)); const jettonWallet = this.tonClient.open(await jettonRoot.getWallet(sender.address!)); - const initParams = { - poolAddress: this.txSteps[0]!.poolAddress, - limit: BigInt(this.txSteps[0]!.amountOut), - next: {} - } as SwapStep; - - const swapPayloadParams = this.makeSwapPayloadParams( - initParams, - initParams.next!, - this.txSteps, - slippage - ); + const payloadParams = {} as SwapStep; + this.fillPayloadParams(this.txSteps, slippage, payloadParams); + + if (!this.checkSwapPayloadValid(payloadParams)) { + console.log( + '%cInvalid_swapPayloadParams', + 'color: red; font-size: 20px;', + payloadParams + ); + throw new RubicSdkError( + 'Swap payload for dedust has empty `next` property or undefined `poolAddress`.' + ); + } await jettonWallet.sendTransfer(sender, toNano(DEDUST_GAS_NON_WEI), { amount: BigInt(from.stringWeiAmount), @@ -279,38 +280,43 @@ export class DedustSwapService { responseAddress: sender.address, forwardAmount: toNano(0.15), queryId: RUBIC_REF_NAME_FOR_DEDUST, - forwardPayload: VaultJetton.createSwapPayload(swapPayloadParams) + forwardPayload: VaultJetton.createSwapPayload(payloadParams) }); } - private makeSwapPayloadParams( - payloadParams: SwapStep, - next: SwapStep, - txSteps: DedustTxStep[], - slippage: number - ): SwapStep { - if (!txSteps.length) return payloadParams; + /** + * @param next on first iteration - it's payloadParams, then .next + * @param payloadParams + * @returns + */ + private fillPayloadParams(steps: DedustTxStep[], slippage: number, next: SwapStep): void { + if (!steps.length) return; - const step = txSteps[0]!; - const isFirstStep = txSteps.length === this.txSteps.length; + const step = steps[0]!; const minAmountOut = BigInt( new BigNumber(step.amountOut).multipliedBy(1 - slippage).toFixed(0) ); - if (isFirstStep) { - payloadParams.poolAddress = step.poolAddress; - payloadParams.limit = minAmountOut; - } else { - next.poolAddress = step.poolAddress; - next.limit = minAmountOut; - } + next.poolAddress = step.poolAddress; + next.limit = minAmountOut; - const slicedSteps = txSteps.slice(1); - if (slicedSteps.length && !isFirstStep) { + steps.shift(); + if (steps.length) { next.next = {} as SwapStep; next = next.next; } - return this.makeSwapPayloadParams(payloadParams, next, slicedSteps, slippage); + return this.fillPayloadParams(steps, slippage, next); + } + + public checkSwapPayloadValid(payloadParams: SwapStep): boolean { + let next: SwapStep | undefined = payloadParams; + while (next) { + if (!next.poolAddress) return false; + if (next.next && !Object.keys(next.next).length) return false; + next = next.next; + } + + return true; } } From a8b07437d7020a34cd05d5a0fb93dbe7557960f4 Mon Sep 17 00:00:00 2001 From: pseudoelement Date: Wed, 25 Dec 2024 15:41:44 +0300 Subject: [PATCH 2/5] fix-dedust, add log --- package.json | 2 +- .../aggregators/dedust/services/dedust-swap-service.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2089dbdbfc8..e6c7b5ec134 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "5.49.7-alpha.ton.3", + "version": "5.49.7-alpha.ton.4", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts index 010647dcb80..f3eaed420a5 100644 --- a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts +++ b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts @@ -262,6 +262,7 @@ export class DedustSwapService { const payloadParams = {} as SwapStep; this.fillPayloadParams(this.txSteps, slippage, payloadParams); + console.log('%cDedust_Params', 'color: green; font-size: 20px;', payloadParams); if (!this.checkSwapPayloadValid(payloadParams)) { console.log( From 286a6c638879d13b91684ab51da8ee2af0133aed Mon Sep 17 00:00:00 2001 From: pseudoelement Date: Wed, 25 Dec 2024 17:54:25 +0300 Subject: [PATCH 3/5] fix-dedust, add utility logger --- package.json | 2 +- .../aggregators/dedust/services/dedust-swap-service.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e6c7b5ec134..78cccfa8d1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "5.49.7-alpha.ton.4", + "version": "5.49.7-alpha.ton.5", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts index f3eaed420a5..68882110147 100644 --- a/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts +++ b/src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service.ts @@ -57,6 +57,11 @@ export class DedustSwapService { } this.cacheStepsOnCalculation(pools); + console.log( + '%cDedust_TransitTokensCount', + 'color: blue; font-size: 20px;', + pools.length - 1 + ); const outputWeiAmountString = pools.at(-1)!.amountOut; return outputWeiAmountString; From b6f45096070461a8122de240e5f8ee3d3909dbde Mon Sep 17 00:00:00 2001 From: pseudoelement Date: Thu, 26 Dec 2024 10:43:11 +0300 Subject: [PATCH 4/5] fix-dedust, release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78cccfa8d1f..bb63745d220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubic-sdk", - "version": "5.49.7-alpha.ton.5", + "version": "5.49.7", "description": "Simplify dApp creation", "main": "lib/index.js", "types": "lib/index.d.ts", From c5300df96eae545716755e9a613cd4fd87dfde4b Mon Sep 17 00:00:00 2001 From: pseudoelement Date: Thu, 26 Dec 2024 11:30:19 +0300 Subject: [PATCH 5/5] fix-dedust, remove tests --- .../dedust/dedust-swap-payload_test.spec.ts | 213 ------------------ 1 file changed, 213 deletions(-) delete mode 100644 __tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts diff --git a/__tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts b/__tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts deleted file mode 100644 index 5da97055ca3..00000000000 --- a/__tests__/unit-tests/dedust/dedust-swap-payload_test.spec.ts +++ /dev/null @@ -1,213 +0,0 @@ -import { SwapStep } from '@dedust/sdk'; -import { Address } from '@ton/core'; -import { DedustSwapService } from '../../../src/features/on-chain/calculation-manager/providers/aggregators/dedust/services/dedust-swap-service'; - -interface TestCase { - caseName: string; - payload: SwapStep; - expects: boolean; -} - -describe('dedust', () => { - const swapSrv = new DedustSwapService(); - const testCases = [ - { - caseName: '1_item_payload_correct', - expects: true, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1) - } - }, - { - caseName: '1_item_payload_empty_next', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: {} - } - }, - { - caseName: '2_item_payload_empty_next', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: {} - } - } - }, - { - caseName: '2_item_payload_empty_poolAddress', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: '', - limit: BigInt(1) - } - } - }, - { - caseName: '2_item_payload_undefined_poolAddress', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: undefined, - limit: BigInt(1) - } - } - }, - { - caseName: '2_item_payload_correct', - expects: true, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1) - } - } - }, - { - caseName: '3_item_payload_correct', - expects: true, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1) - } - } - } - }, - { - caseName: '3_item_payload_empty_next', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1), - next: {} - } - } - } - }, - { - caseName: '3_item_payload_empty_poolAddress', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: '', - limit: BigInt(1), - next: {} - } - } - } - }, - { - caseName: '4_item_payload_correct', - expects: true, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1) - } - } - } - } - }, - { - caseName: '4_item_payload_empty_next', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1), - next: {} - } - } - } - } - }, - { - caseName: '4_item_payload_null_poolAddress', - expects: false, - payload: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse('EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW'), - limit: BigInt(1), - next: { - poolAddress: Address.parse( - 'EQBGCoxXu8a_CdJ5r1u2iiWUvJAAHvVU7qZgEmfKRSfBf2CW' - ), - limit: BigInt(1), - next: { - poolAddress: null, - limit: BigInt(1) - } - } - } - } - } - ] as TestCase[]; - - it('tt', () => { - for (const testCase of testCases) { - const answer = swapSrv.checkSwapPayloadValid(testCase.payload); - expect(answer).toBe(testCase.expects); - } - }); -});