Skip to content

Commit

Permalink
Merge pull request #99 from CityOfZion/CU-86dunk072-2
Browse files Browse the repository at this point in the history
CU-86dunk072 - Swap Multi Invoke - Fixes for the swap between bNEO an…
  • Loading branch information
raulduartep authored Sep 20, 2024
2 parents 3781fec + a210c08 commit 649cf0e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "update route displayed",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-neo3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand All @@ -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[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 649cf0e

Please sign in to comment.