Skip to content

Commit

Permalink
Minswap v2 swap direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Jul 25, 2024
1 parent c3f2eaa commit fcd3441
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum DatumParameterKey {
MinReceive = 'MinReceive',
Expiration = 'Expiration',
AllowPartialFill = 'AllowPartialFill',
Direction = 'Direction',

/**
* Trading fees.
Expand Down
2 changes: 1 addition & 1 deletion src/dex/definitions/minswap-v2/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default {
constructor: 0,
fields: [
{
constructor: 0,
constructor: DatumParameterKey.Direction,
fields: []
},
{
Expand Down
7 changes: 7 additions & 0 deletions src/dex/minswap-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,18 @@ export class MinswapV2 extends BaseDex {
return Promise.reject('Parameters for datum are not set.');
}

const swapInToken: string = (swapParameters.SwapInTokenPolicyId as string) + (swapParameters.SwapInTokenAssetName as string);
const swapOutToken: string = (swapParameters.SwapOutTokenPolicyId as string) + (swapParameters.SwapOutTokenAssetName as string);
const swapDirection: number = [swapInToken, swapOutToken].sort((a: string, b: string) => {
return a.localeCompare(b);
})[0] === swapInToken ? 1 : 0;

swapParameters = {
...swapParameters,
[DatumParameterKey.BatcherFee]: batcherFee.value,
[DatumParameterKey.LpTokenPolicyId]: liquidityPool.lpToken.policyId,
[DatumParameterKey.LpTokenAssetName]: liquidityPool.lpToken.nameHex,
[DatumParameterKey.Direction]: swapDirection,
};

const datumBuilder: DefinitionBuilder = new DefinitionBuilder();
Expand Down

0 comments on commit fcd3441

Please sign in to comment.