From a210c08167f87c9429eac711c68a8fd12bb2b8b9 Mon Sep 17 00:00:00 2001 From: Lopes Date: Fri, 20 Sep 2024 15:24:41 -0300 Subject: [PATCH] CU-86dunk072 - Swap Multi Invoke - Fixes for the swap between bNEO and NEO --- .../CU-86dunk072-2_2024-09-20-18-24.json | 10 +++++ .../handlers/FlamingoSwapRouteHandler.spec.ts | 38 +++++++++++++++++++ .../swap/handlers/FlamingoSwapRouteHandler.ts | 17 +++++++++ 3 files changed, 65 insertions(+) create mode 100644 common/changes/@cityofzion/bs-neo3/CU-86dunk072-2_2024-09-20-18-24.json diff --git a/common/changes/@cityofzion/bs-neo3/CU-86dunk072-2_2024-09-20-18-24.json b/common/changes/@cityofzion/bs-neo3/CU-86dunk072-2_2024-09-20-18-24.json new file mode 100644 index 0000000..c129cb9 --- /dev/null +++ b/common/changes/@cityofzion/bs-neo3/CU-86dunk072-2_2024-09-20-18-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-neo3", + "comment": "update route displayed", + "type": "patch" + } + ], + "packageName": "@cityofzion/bs-neo3" +} \ No newline at end of file diff --git a/packages/bs-neo3/src/__tests__/services/swap/handlers/FlamingoSwapRouteHandler.spec.ts b/packages/bs-neo3/src/__tests__/services/swap/handlers/FlamingoSwapRouteHandler.spec.ts index 9bf364b..7b172ab 100644 --- a/packages/bs-neo3/src/__tests__/services/swap/handlers/FlamingoSwapRouteHandler.spec.ts +++ b/packages/bs-neo3/src/__tests__/services/swap/handlers/FlamingoSwapRouteHandler.spec.ts @@ -35,6 +35,25 @@ describe('FlamingoSwapRouteHandler', () => { expect(response).toEqual(expectedResponse) }) + it('should calculate best route for swap - bNEO to NEO', async () => { + const expectedResponse: SwapRoute[] = [ + { + tokenToUse: FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO'), + reserveTokenToUse: '0', + tokenToReceive: FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO'), + reserveTokenToReceive: '0', + }, + ] + + const response = await FlamingoSwapRouteHandler.calculateBestRouteForSwap({ + network, + tokenToReceive: FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO'), + tokenToUse: FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO'), + }) + + expect(response).toEqual(expectedResponse) + }) + it('should calculate best route for swap - NEO to GAS', async () => { const expectedResponse: SwapRoute[] = [ { @@ -60,6 +79,25 @@ describe('FlamingoSwapRouteHandler', () => { expect(response).toEqual(expectedResponse) }) + it('should calculate best route for swap - NEO to bNEO', async () => { + const expectedResponse: SwapRoute[] = [ + { + tokenToUse: FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO'), + reserveTokenToUse: '0', + tokenToReceive: FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO'), + reserveTokenToReceive: '0', + }, + ] + + const response = await FlamingoSwapRouteHandler.calculateBestRouteForSwap({ + network, + tokenToReceive: FlamingoSwapHelper.getFlamingoSwapToken(network, 'bNEO'), + tokenToUse: FlamingoSwapHelper.getFlamingoSwapToken(network, 'NEO'), + }) + + expect(response).toEqual(expectedResponse) + }) + it('should calculate best route for swap - GAS to SWTH', async () => { const expectedResponse: SwapRoute[] = [ { diff --git a/packages/bs-neo3/src/services/swap/handlers/FlamingoSwapRouteHandler.ts b/packages/bs-neo3/src/services/swap/handlers/FlamingoSwapRouteHandler.ts index 432bf9c..1afa5d5 100644 --- a/packages/bs-neo3/src/services/swap/handlers/FlamingoSwapRouteHandler.ts +++ b/packages/bs-neo3/src/services/swap/handlers/FlamingoSwapRouteHandler.ts @@ -60,6 +60,23 @@ export class FlamingoSwapRouteHandler { if (routePath.length === 0) return [] + const isWrapOrUnwrapNeo = + FlamingoSwapHelper.isWrapNeo(network, [tokenToUse, tokenToReceive]) || + FlamingoSwapHelper.isUnwrapNeo(network, [tokenToReceive, tokenToUse]) + + if (isWrapOrUnwrapNeo) { + const swapRoute: SwapRoute[] = [ + { + reserveTokenToReceive: '0', + reserveTokenToUse: '0', + tokenToReceive, + tokenToUse, + }, + ] + + return swapRoute + } + const { stack: reservesStack } = await this.#invokeReserves({ network, routePath }) return this.#createSwapRoute({ network, routePath, reservesStack })