-
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
10 changed files
with
549 additions
and
0 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
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
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,62 @@ | ||
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'; | ||
import { Spectrum } from '@dex/spectrum'; | ||
|
||
export class SpectrumApi 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-balanced.spectrum.fi/cardano`, | ||
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( | ||
Spectrum.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)) * 10; | ||
liquidityPool.identifier = liquidityPool.lpToken.identifier(); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { DatumParameterKey } from '@app/constants'; | ||
import { DatumParameters, DefinitionField } from '@app/types'; | ||
|
||
export default { | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.SwapInTokenPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.SwapInTokenAssetName | ||
} | ||
], | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.SwapOutTokenPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.SwapOutTokenAssetName | ||
} | ||
], | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.TokenPolicyId // Pool NFT | ||
}, | ||
{ | ||
bytes: DatumParameterKey.TokenAssetName | ||
} | ||
], | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFee | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFeeNumerator // Execution fee numerator | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFeeDenominator // Execution fee denominator | ||
}, | ||
{ | ||
bytes: DatumParameterKey.SenderPubKeyHash | ||
}, | ||
(field: DefinitionField, parameters: DatumParameters, shouldExtract: boolean = true) => { | ||
if (! shouldExtract) { | ||
const stakeKeyHash: string = parameters[DatumParameterKey.SenderStakingKeyHash] as string ?? null; | ||
|
||
if (! stakeKeyHash) return; | ||
|
||
return { | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: stakeKeyHash, | ||
} | ||
], | ||
}; | ||
} | ||
|
||
if ('fields' in field) { | ||
if (field.constructor === 1) return; | ||
|
||
if (field.fields.length > 0 && 'bytes' in field.fields[0]) { | ||
parameters[DatumParameterKey.SenderStakingKeyHash] = field.fields[0].bytes; | ||
} | ||
} | ||
|
||
return; | ||
}, | ||
{ | ||
int: DatumParameterKey.SwapInAmount | ||
}, | ||
{ | ||
int: DatumParameterKey.MinReceive | ||
} | ||
], | ||
} |
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,62 @@ | ||
import { DatumParameterKey } from '@app/constants'; | ||
|
||
export default { | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.TokenPolicyId // Pool NFT | ||
}, | ||
{ | ||
bytes: DatumParameterKey.TokenAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.PoolAssetAPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.PoolAssetAAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.PoolAssetBPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.PoolAssetBAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
constructor: 0, | ||
fields: [ | ||
{ | ||
bytes: DatumParameterKey.LpTokenPolicyId | ||
}, | ||
{ | ||
bytes: DatumParameterKey.LpTokenAssetName | ||
} | ||
] | ||
}, | ||
{ | ||
int: DatumParameterKey.LpFee | ||
}, | ||
[ | ||
{ | ||
bytes: DatumParameterKey.StakeAdminPolicy | ||
} | ||
], | ||
{ | ||
int: DatumParameterKey.LqBound | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.