Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Commit

Permalink
feat(swap-pathfinding): get all paths between tokens (#822)
Browse files Browse the repository at this point in the history
* feat(swap-pathfinding): add all-paths and best-path endpoint

* fix(swap-pathfinding): fix test failing due to generated token IDs having greater-than-expected offset

* chore(swap-pathfinding): change graph synchronisation polling interval to 120s given infrequency of poolpair updates

* fix(swap-pathfinding): dont recompute fromToken and toToken

* chore(swap-pathfinding): rebase onto main

* chore(swap-pathfinding): update package-lock.json
  • Loading branch information
eli-lim authored Mar 14, 2022
1 parent cf4f2a5 commit 86360ac
Show file tree
Hide file tree
Showing 7 changed files with 773 additions and 17 deletions.
100 changes: 97 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"defichain": "^2.29.0",
"graphology": "^0.24.1",
"graphology-simple-path": "^0.1.2",
"level": "7.0.0",
"level-js": "6.0.0",
"level-packager": "6.0.0",
Expand Down
42 changes: 42 additions & 0 deletions packages/whale-api-client/src/api/poolpairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,45 @@ export enum PoolSwapAggregatedInterval {
ONE_HOUR = 60 * 60,
ONE_DAY = ONE_HOUR * 24
}

export interface BestSwapPathResult {
fromToken: {
id: string
symbol: string
}
toToken: {
id: string
symbol: string
}
bestPath: SwapPathPoolPair[]
estimatedReturn: string
}

export interface SwapPathsResult {
fromToken: {
id: string
symbol: string
}
toToken: {
id: string
symbol: string
}
paths: SwapPathPoolPair[][]
}

export interface SwapPathPoolPair {
poolPairId: string
symbol: string
tokenA: {
id: string
symbol: string
}
tokenB: {
id: string
symbol: string
}
priceRatio: {
ab: string
ba: string
}
}
3 changes: 2 additions & 1 deletion src/module.api/_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TransactionController } from '@src/module.api/transaction.controller'
import { ApiValidationPipe } from '@src/module.api/pipes/api.validation.pipe'
import { AddressController } from '@src/module.api/address.controller'
import { PoolPairController } from '@src/module.api/poolpair.controller'
import { PoolPairService } from '@src/module.api/poolpair.service'
import { PoolPairService, PoolSwapPathFindingService } from '@src/module.api/poolpair.service'
import { MasternodeService } from '@src/module.api/masternode.service'
import { DeFiDCache } from '@src/module.api/cache/defid.cache'
import { SemaphoreCache } from '@src/module.api/cache/semaphore.cache'
Expand Down Expand Up @@ -66,6 +66,7 @@ import { LoanVaultService } from '@src/module.api/loan.vault.service'
DeFiDCache,
SemaphoreCache,
PoolPairService,
PoolSwapPathFindingService,
MasternodeService,
LoanVaultService,
{
Expand Down
Loading

0 comments on commit 86360ac

Please sign in to comment.