Skip to content

Commit

Permalink
Merge pull request #52 from IndigoProtocol/sluder/issue-50
Browse files Browse the repository at this point in the history
Include WR treasury
  • Loading branch information
Sluder authored Jul 18, 2023
2 parents 863f460 + 62a8b01 commit e76fb14
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ export enum DatumParameterKey {
LpFeeDenominator = 'LpFeeDenominator',
PoolAssetAPolicyId = 'PoolAssetAPolicyId',
PoolAssetAAssetName = 'PoolAssetAAssetName',
PoolAssetATreasury = 'PoolAssetATreasury',
PoolAssetABarFee = 'PoolAssetABarFee',
PoolAssetBBarFee = 'PoolAssetBBarFee',
PoolAssetBPolicyId = 'PoolAssetBPolicyId',
PoolAssetBAssetName = 'PoolAssetBAssetName',
PoolAssetBTreasury = 'PoolAssetBTreasury',
PoolAssetBBarFee = 'PoolAssetBBarFee',
RootKLast = 'RootKLast',
LastInteraction = 'LastInteraction',
RequestScriptHash = 'RequestScriptHash',
}

export enum TransactionStatus {
Expand Down
4 changes: 2 additions & 2 deletions src/dex/api/wingriders-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export class WingRidersApi extends BaseApi {
this.dex.name,
tokenA,
tokenB,
BigInt(pool.treasuryA),
BigInt(pool.treasuryB),
BigInt(pool.tokenA.quantity) - BigInt(pool.treasuryA),
BigInt(pool.tokenB.quantity) - BigInt(pool.treasuryB),
pool._utxo.address,
this.dex.orderAddress,
this.dex.orderAddress,
Expand Down
54 changes: 54 additions & 0 deletions src/dex/definitions/wingriders/pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { DatumParameterKey } from '@app/constants';

/**
* https://github.com/WingRiders/dex-serializer/blob/main/src/LiquidityPoolDatum.ts
*/
export default {
constructor: 0,
fields: [
{
bytes: DatumParameterKey.RequestScriptHash
},
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.PoolAssetAPolicyId,
},
{
bytes: DatumParameterKey.PoolAssetAAssetName,
}
]
},
{
constructor: 0,
fields: [
{
bytes: DatumParameterKey.PoolAssetBPolicyId,
},
{
bytes: DatumParameterKey.PoolAssetBAssetName,
}
]
}
]
},
{
int: DatumParameterKey.LastInteraction,
},
{
int: DatumParameterKey.PoolAssetATreasury,
},
{
int: DatumParameterKey.PoolAssetBTreasury,
}
]
}
]
};
4 changes: 2 additions & 2 deletions src/dex/minswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export class Minswap extends BaseDex {
liquidityPool.identifier = possibleLpTokens[0].policyId;
}

try {
liquidityPool.poolFeePercent = 0.3;
liquidityPool.poolFeePercent = 0.3;

try {
const builder: DefinitionBuilder = await (new DefinitionBuilder())
.loadDefinition(pool);
const datum: DefinitionField = await provider.datumValue(utxo.datumHash);
Expand Down
19 changes: 19 additions & 0 deletions src/dex/wingriders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
AssetAddress,
AssetBalance,
DatumParameters,
DefinitionConstr,
DefinitionField,
PayToAddress,
RequestConfig,
SwapFee,
Expand All @@ -17,6 +19,7 @@ import { DefinitionBuilder } from '@app/definition-builder';
import order from '@dex/definitions/wingriders/order';
import { BaseApi } from '@dex/api/base-api';
import { WingRidersApi } from '@dex/api/wingriders-api';
import pool from "@dex/definitions/wingriders/pool";

/**
* WingRiders constants.
Expand Down Expand Up @@ -130,6 +133,22 @@ export class WingRiders extends BaseDex {
}
liquidityPool.poolFeePercent = 0.35;

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

liquidityPool.reserveA = typeof parameters.PoolAssetATreasury === 'number'
? (liquidityPool.reserveA - BigInt(parameters.PoolAssetATreasury))
: liquidityPool.reserveA;
liquidityPool.reserveB = typeof parameters.PoolAssetBTreasury === 'number'
? (liquidityPool.reserveB - BigInt(parameters.PoolAssetBTreasury))
: liquidityPool.reserveB;
} catch (e) {
return liquidityPool;
}

return liquidityPool;
}

Expand Down

0 comments on commit e76fb14

Please sign in to comment.