diff --git a/src/constants.ts b/src/constants.ts index 98bbb4f..dbb74da 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 { diff --git a/src/dex/api/wingriders-api.ts b/src/dex/api/wingriders-api.ts index ffa267f..e1f13d8 100644 --- a/src/dex/api/wingriders-api.ts +++ b/src/dex/api/wingriders-api.ts @@ -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, diff --git a/src/dex/definitions/wingriders/pool.ts b/src/dex/definitions/wingriders/pool.ts new file mode 100644 index 0000000..8d08d9b --- /dev/null +++ b/src/dex/definitions/wingriders/pool.ts @@ -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, + } + ] + } + ] +}; \ No newline at end of file diff --git a/src/dex/minswap.ts b/src/dex/minswap.ts index d03dc88..f00cfd6 100644 --- a/src/dex/minswap.ts +++ b/src/dex/minswap.ts @@ -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); diff --git a/src/dex/wingriders.ts b/src/dex/wingriders.ts index 9430250..1f5e8ba 100644 --- a/src/dex/wingriders.ts +++ b/src/dex/wingriders.ts @@ -3,6 +3,8 @@ import { AssetAddress, AssetBalance, DatumParameters, + DefinitionConstr, + DefinitionField, PayToAddress, RequestConfig, SwapFee, @@ -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. @@ -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; }