Skip to content

Commit

Permalink
Merge & reject if no LP token
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Dec 14, 2023
2 parents 0a0e678 + 2643b7e commit 2e1835f
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
All notable changes to Dexter will be documented in this file.

## [UNRELEASED]
- TeddySwap integration

## [v4.2.0]
- Fix WR price impact formula for 0 decimals
- Rename Asset identifier function
- Include '/' helper function for proxy URLs
- Add export for SplitSwapRequest
- Add tests for DexTransaction events
- Fix `withSwapOutAmountMappings` for split swap requests
- Allow non-existing staking key hash when constructing order
- TeddySwap integration
- Add fetching for total LP tokens for liquidity pools

## [v4.1.0]
- Support for multi-dex swap requests.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indigo-labs/dexter",
"version": "4.1.0",
"version": "4.2.1",
"license": "MIT",
"author": "Zachary Sluder",
"keywords": [
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
9 changes: 6 additions & 3 deletions src/dex/teddyswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ export class TeddySwap extends BaseDex {
&& assetBalance.asset.nameHex === lpTokenAssetName;
});

if (lpTokenBalance) {
liquidityPool.lpToken = lpTokenBalance.asset as Asset;
liquidityPool.totalLpTokens = Number(MAX_INT - lpTokenBalance.quantity);
if (! lpTokenBalance) {
return Promise.resolve(undefined);
}

liquidityPool.lpToken = lpTokenBalance.asset as Asset;
liquidityPool.totalLpTokens = MAX_INT - lpTokenBalance.quantity;

} 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
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function correspondingReserves(liquidityPool: LiquidityPool, token: Token
}

export function appendSlash(value?: string) {
if (! value) return;
if (! value) return '';
if (value.endsWith('/')) return;

return `${value}/`;
Expand Down

0 comments on commit 2e1835f

Please sign in to comment.