-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { BaseApi } from './base-api'; | ||
import { Asset, Token } from '../models/asset'; | ||
import { LiquidityPool } from '../models/liquidity-pool'; | ||
import axios, { AxiosInstance } from 'axios'; | ||
import { RequestConfig } from '@app/types'; | ||
import { appendSlash, tokensMatch } from '@app/utils'; | ||
import { TeddySwap } from '@dex/teddyswap'; | ||
|
||
export class TeddyswapApi extends BaseApi { | ||
|
||
protected readonly api: AxiosInstance; | ||
protected readonly dex: TeddySwap; | ||
|
||
constructor(dex: TeddySwap, requestConfig: RequestConfig) { | ||
super(); | ||
|
||
this.dex = dex; | ||
this.api = axios.create({ | ||
timeout: requestConfig.timeout, | ||
baseURL: `${appendSlash(requestConfig.proxyUrl)}https://analytics.teddyswap.org/v1`, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
} | ||
}); | ||
} | ||
|
||
liquidityPools(assetA: Token, assetB?: Token): Promise<LiquidityPool[]> { | ||
return this.api.get('/front/pools', ).then((response: any) => { | ||
return response.data.map((poolResponse: any) => { | ||
const tokenA: Token = poolResponse.lockedX.asset.currencySymbol !== '' | ||
? new Asset(poolResponse.lockedX.asset.currencySymbol, Buffer.from(poolResponse.lockedX.asset.tokenName, 'utf8').toString('hex')) | ||
: 'lovelace'; | ||
const tokenB: Token = poolResponse.lockedY.asset.currencySymbol !== '' | ||
? new Asset(poolResponse.lockedY.asset.currencySymbol, Buffer.from(poolResponse.lockedY.asset.tokenName, 'utf8').toString('hex')) | ||
: 'lovelace'; | ||
|
||
if (! tokensMatch(tokenA, assetA) || (assetB && ! tokensMatch(tokenB, assetB))) { | ||
return undefined; | ||
} | ||
|
||
let liquidityPool: LiquidityPool = new LiquidityPool( | ||
TeddySwap.identifier, | ||
tokenA, | ||
tokenB, | ||
BigInt(poolResponse.lockedX.amount), | ||
BigInt(poolResponse.lockedY.amount), | ||
'', // Not supplied | ||
this.dex.orderAddress, | ||
this.dex.orderAddress, | ||
); | ||
|
||
liquidityPool.lpToken = new Asset(poolResponse.lockedLQ.asset.currencySymbol, Buffer.from(poolResponse.lockedLQ.asset.tokenName, 'utf8').toString('hex')); | ||
liquidityPool.poolFeePercent = (1 - (poolResponse.poolFeeNum / poolResponse.poolFeeDenum)) * 100; | ||
liquidityPool.identifier = poolResponse.id; | ||
|
||
return liquidityPool; | ||
}).filter((pool: LiquidityPool | undefined) => pool !== undefined) as LiquidityPool[]; | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters