Skip to content

Commit

Permalink
Merge branch 'main' into dilshan/add-more-filter-options-to-accounthi…
Browse files Browse the repository at this point in the history
…storycount
  • Loading branch information
helloscoopa authored Jan 20, 2023
2 parents 8b12991 + e07aad2 commit e45bcc3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/legacy-api/src/pipes/NetworkValidationPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
PipeTransform
} from '@nestjs/common'

export type SupportedNetwork = 'mainnet' | 'testnet' | 'regtest'
export type SupportedNetwork = 'mainnet' | 'testnet' | 'devnet' | 'regtest'

@Injectable()
export class NetworkValidationPipe implements PipeTransform {
private static readonly VALID_NETWORKS: Set<undefined | SupportedNetwork> = new Set([
undefined, // defaults to 'mainnet'
'mainnet',
'testnet',
'devnet',
'regtest'
])

Expand Down
32 changes: 32 additions & 0 deletions apps/whale-api/src/module.api/poolpair.controller.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,38 @@ describe('get best path', () => {
})
})

it('should return direct path even if composite swap paths has greater return', async () => {
// 1 J = 7 K
// 1 J = 2 L = 8 K
const response = await controller.getBestPath('10', '11')
expect(response).toStrictEqual({
fromToken: {
id: '10',
name: 'J',
symbol: 'J',
displaySymbol: 'dJ'
},
toToken: {
id: '11',
name: 'K',
symbol: 'K',
displaySymbol: 'dK'
},
bestPath: [
{
symbol: 'J-K',
poolPairId: '23',
priceRatio: { ab: '0.14285714', ba: '7.00000000' },
tokenA: { id: '10', name: 'J', symbol: 'J', displaySymbol: 'dJ' },
tokenB: { id: '11', name: 'K', symbol: 'K', displaySymbol: 'dK' },
commissionFeeInPct: '0.25000000'
}
],
estimatedReturn: '7.00000000',
estimatedReturnLessDexFees: '5.25000000'
})
})

it('should deduct commission fee - 1 leg', async () => {
const response = await controller.getBestPath('10', '12')
expect(response).toStrictEqual({
Expand Down
14 changes: 14 additions & 0 deletions apps/whale-api/src/module.api/poolswap.pathfinding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ export class PoolSwapPathFindingService {
paths
} = await this.getAllSwapPaths(fromTokenId, toTokenId)

// always use direct path if available
for (const path of paths) {
const { estimatedReturn, estimatedReturnLessDexFees } = computeReturnLessDexFeesInDestinationToken(path, fromTokenId)
if (path.length === 1) {
return {
fromToken: fromToken,
toToken: toToken,
bestPath: path,
estimatedReturn: formatNumber(estimatedReturn), // denoted in toToken
estimatedReturnLessDexFees: formatNumber(estimatedReturnLessDexFees) // denoted in toToken
}
}
}

// otherwise, search for the best path based on return
let bestPath: SwapPathPoolPair[] = []
let bestReturnLessDexFees = new BigNumber(0)
Expand Down
5 changes: 5 additions & 0 deletions packages/jellyfish-network/__tests__/Network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ describe('getNetwork', () => {
expect(getNetwork('testnet').bech32.hrp).toStrictEqual('tf')
})

it('should get devnet', () => {
expect(getNetwork('devnet').name).toStrictEqual('devnet')
expect(getNetwork('devnet').bech32.hrp).toStrictEqual('tf')
})

it('should get regtest', () => {
expect(getNetwork('regtest').name).toStrictEqual('regtest')
expect(getNetwork('regtest').bech32.hrp).toStrictEqual('bcrt')
Expand Down
2 changes: 2 additions & 0 deletions packages/jellyfish-network/src/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function getNetwork (network: NetworkName): Network {
return MainNet
case 'testnet':
return TestNet
case 'devnet':
return DevNet
case 'regtest':
return RegTest
default:
Expand Down
2 changes: 1 addition & 1 deletion packages/ocean-api-client/src/OceanApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface OceanApiClientOptions {
/**
* Network that ocean client is configured to
*/
network?: 'mainnet' | 'testnet' | 'regtest' | string
network?: 'mainnet' | 'testnet' | 'devnet' | 'regtest' | string
}

/**
Expand Down

0 comments on commit e45bcc3

Please sign in to comment.