Skip to content

Commit

Permalink
Add total LP tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Dec 13, 2023
1 parent df3140a commit 96fe59c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to Dexter will be documented in this file.
- Add export for SplitSwapRequest
- Add tests for DexTransaction events
- Fix `withSwapOutAmountMappings` for split swap requests
- Add fetching for total LP tokens for liquidity pools

## [v4.1.0]
- Support for multi-dex swap requests.
Expand Down
1 change: 1 addition & 0 deletions src/dex/api/minswap-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class MinswapApi extends BaseApi {
);

liquidityPool.lpToken = new Asset(poolData.lpAsset.currencySymbol, poolData.lpAsset.tokenName);
liquidityPool.totalLpTokens = BigInt(poolData.totalLiquidity);
liquidityPool.poolFeePercent = 0.3;
liquidityPool.identifier = liquidityPool.lpToken.identifier();

Expand Down
1 change: 1 addition & 0 deletions src/dex/api/muesliswap-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class MuesliSwapApi extends BaseApi {
liquidityPool.identifier = pool.poolId;
liquidityPool.lpToken = new Asset(pool.lpToken.address.policyId, pool.lpToken.address.name);
liquidityPool.poolFeePercent = Number(pool.poolFee);
liquidityPool.totalLpTokens = BigInt(pool.lpToken.amount);

return liquidityPool;
});
Expand Down
1 change: 1 addition & 0 deletions src/dex/api/sundaeswap-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class SundaeSwapApi extends BaseApi {
liquidityPool.identifier = pool.ident;
liquidityPool.lpToken = Asset.fromIdentifier(pool.assetLP.assetId);
liquidityPool.poolFeePercent = Number(pool.fee);
liquidityPool.totalLpTokens = BigInt(pool.quantityLP);

return liquidityPool;
});
Expand Down
1 change: 1 addition & 0 deletions src/dex/api/wingriders-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class WingRidersApi extends BaseApi {
liquidityPool.lpToken = new Asset(pool.issuedShareToken.policyId, pool.issuedShareToken.assetName);
liquidityPool.poolFeePercent = 0.35;
liquidityPool.identifier = liquidityPool.lpToken.identifier();
liquidityPool.totalLpTokens = BigInt(pool.issuedShareToken.quantity);

return liquidityPool;
}).filter((pool: LiquidityPool | undefined) => pool !== undefined);
Expand Down
24 changes: 22 additions & 2 deletions src/dex/minswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseDex } from './base-dex';
import {
AssetAddress,
AssetBalance,
DatumParameters,
DatumParameters, DefinitionConstr, DefinitionField,
PayToAddress,
RequestConfig,
SwapFee,
Expand All @@ -17,6 +17,7 @@ import { AddressType, DatumParameterKey } from '@app/constants';
import order from '@dex/definitions/minswap/order';
import { BaseApi } from '@dex/api/base-api';
import { MinswapApi } from '@dex/api/minswap-api';
import pool from '@dex/definitions/minswap/pool';

export class Minswap extends BaseDex {

Expand Down Expand Up @@ -111,9 +112,28 @@ export class Minswap extends BaseDex {

liquidityPool.lpToken = new Asset(this.lpTokenPolicyId, poolNft.nameHex);
liquidityPool.identifier = liquidityPool.lpToken.identifier();

liquidityPool.poolFeePercent = 0.3;

try {
liquidityPool.poolFeePercent = 0.3;

const builder: DefinitionBuilder = await (new DefinitionBuilder())
.loadDefinition(pool);
const datum: DefinitionField = await provider.datumValue(utxo.datumHash);
const parameters: DatumParameters = builder.pullParameters(datum as DefinitionConstr);

// Ignore Zap orders
if (typeof parameters.PoolAssetBPolicyId === 'string' && parameters.PoolAssetBPolicyId === this.lpTokenPolicyId) {
return undefined;
}

liquidityPool.totalLpTokens = typeof parameters.TotalLpTokens === 'number'
? BigInt(parameters.TotalLpTokens)
: 0n;
} catch (e) {
return liquidityPool;
}

return liquidityPool;
}

Expand Down
1 change: 1 addition & 0 deletions src/dex/models/liquidity-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class LiquidityPool {
lpToken: Asset;
identifier: string = '';
poolFeePercent: number = 0;
totalLpTokens: bigint = 0n;
extra: any = {};

constructor(dex: string, assetA: Token, assetB: Token, reserveA: bigint, reserveB: bigint, address: string, marketOrderAddress: string = '', limitOrderAddress: string = '') {
Expand Down
3 changes: 3 additions & 0 deletions src/dex/muesliswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export class MuesliSwap extends BaseDex {
const datum: DefinitionField = await provider.datumValue(utxo.datumHash);
const parameters: DatumParameters = builder.pullParameters(datum as DefinitionConstr);

liquidityPool.totalLpTokens = typeof parameters.TotalLpTokens === 'number'
? BigInt(parameters.TotalLpTokens)
: 0n;
liquidityPool.poolFeePercent = typeof parameters.LpFee === 'number'
? parameters.LpFee / 100
: 0;
Expand Down
3 changes: 3 additions & 0 deletions src/dex/sundaeswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export class SundaeSwap extends BaseDex {
liquidityPool.poolFeePercent = typeof parameters.LpFeeNumerator === 'number' && typeof parameters.LpFeeDenominator === 'number'
? (parameters.LpFeeNumerator / parameters.LpFeeDenominator) * 100
: 0;
liquidityPool.totalLpTokens = typeof parameters.TotalLpTokens === 'number'
? BigInt(parameters.TotalLpTokens)
: 0n;
} catch (e) {
return liquidityPool;
}
Expand Down
1 change: 1 addition & 0 deletions src/dex/wingriders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class WingRiders extends BaseDex {
if (lpTokenBalance) {
liquidityPool.lpToken = lpTokenBalance.asset as Asset;
liquidityPool.identifier = liquidityPool.lpToken.identifier();
liquidityPool.totalLpTokens = MAX_INT - lpTokenBalance.quantity;
}
liquidityPool.poolFeePercent = 0.35;

Expand Down

0 comments on commit 96fe59c

Please sign in to comment.