Skip to content

Commit

Permalink
Merge pull request #73 from IndigoProtocol/sluder/cancel-orders
Browse files Browse the repository at this point in the history
Cancel Orders
  • Loading branch information
Sluder authored Jan 20, 2024
2 parents 553abe6 + 7f4aa51 commit 3bec031
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 64 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"bottleneck": "^2.19.5",
"crypto-js": "^4.1.1",
"lodash": "^4.17.21",
"lucid-cardano": "^0.8.7"
"lucid-cardano": "^0.10.7"
},
"devDependencies": {
"@babel/core": "^7.21.4",
Expand Down
4 changes: 2 additions & 2 deletions src/dex/api/base-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export abstract class BaseApi {
/**
* Fetch all liquidity pools matching assetA & assetB.
*/
abstract liquidityPools(assetA: Token, assetB?: Token): Promise<LiquidityPool[]>;
abstract liquidityPools(assetA?: Token, assetB?: Token): Promise<LiquidityPool[]>;

}
}
5 changes: 2 additions & 3 deletions src/dex/api/spectrum-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { LiquidityPool } from '../models/liquidity-pool';
import axios, { AxiosInstance } from 'axios';
import { RequestConfig } from '@app/types';
import { appendSlash, tokensMatch } from '@app/utils';
import { TeddySwap } from '@dex/teddyswap';
import { Spectrum } from '@dex/spectrum';

export class SpectrumApi extends BaseApi {

protected readonly api: AxiosInstance;
protected readonly dex: TeddySwap;
protected readonly dex: Spectrum;

constructor(dex: TeddySwap, requestConfig: RequestConfig) {
constructor(dex: Spectrum, requestConfig: RequestConfig) {
super();

this.dex = dex;
Expand Down
19 changes: 11 additions & 8 deletions src/dex/api/vyfinance-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export class VyfinanceApi extends BaseApi {
});
}

liquidityPools(assetA: Token, assetB?: Token): Promise<LiquidityPool[]> {
const assetAId: string = (assetA === 'lovelace')
? 'lovelace'
: assetA.identifier();
liquidityPools(assetA?: Token, assetB?: Token): Promise<LiquidityPool[]> {
const assetAId: string = (assetA && assetA !== 'lovelace')
? assetA.identifier()
: 'lovelace';
let assetBId: string = (assetB && assetB !== 'lovelace')
? assetB.identifier()
: 'lovelace';

const url: string = assetB
const url: string = assetA && assetB
? `/lp?networkId=1&v2=true&tokenAUnit=${assetAId}&tokenBUnit=${assetBId}`
: '/lp?networkId=1&v2=true';

Expand All @@ -48,12 +48,13 @@ export class VyfinanceApi extends BaseApi {
? new Asset(poolDetails['bAsset']['currencySymbol'], Buffer.from(poolDetails['bAsset']['tokenName']).toString('hex'))
: 'lovelace';


let liquidityPool: LiquidityPool = new LiquidityPool(
VyFinance.identifier,
tokenA,
tokenB,
BigInt(pool['tokenAQuantity']),
BigInt(pool['tokenBQuantity']),
BigInt(pool['tokenAQuantity'] ?? 0),
BigInt(pool['tokenBQuantity'] ?? 0),
pool['poolValidatorUtxoAddress'],
pool['orderValidatorUtxoAddress'],
pool['orderValidatorUtxoAddress'],
Expand All @@ -63,10 +64,12 @@ export class VyfinanceApi extends BaseApi {
liquidityPool.lpToken = new Asset(lpTokenDetails[0], lpTokenDetails[1]);
liquidityPool.poolFeePercent = (poolDetails['feesSettings']['barFee'] + poolDetails['feesSettings']['liqFee']) / 100;
liquidityPool.identifier = liquidityPool.lpToken.identifier();
liquidityPool.extra.nft = new Asset(poolDetails['mainNFT']['currencySymbol'], poolDetails['mainNFT']['tokenName']);

return liquidityPool;
}).filter((pool: LiquidityPool | undefined) => pool !== undefined) as LiquidityPool[];
}).catch(() => {
}).catch((e) => {
console.error(e)
return [];
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/dex/base-dex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LiquidityPool } from './models/liquidity-pool';
import { BaseDataProvider } from '@providers/data/base-data-provider';
import { Asset, Token } from './models/asset';
import { AssetBalance, DatumParameters, PayToAddress, SwapFee, UTxO } from '@app/types';
import { AssetBalance, DatumParameters, PayToAddress, SpendUTxO, SwapFee, UTxO } from '@app/types';
import { DatumParameterKey } from '@app/constants';
import { tokensMatch } from '@app/utils';
import { BaseApi } from '@dex/api/base-api';
Expand Down Expand Up @@ -46,7 +46,7 @@ export abstract class BaseDex {
/**
* Craft a swap order for this DEX.
*/
abstract buildSwapOrder(liquidityPool: LiquidityPool, swapParameters: DatumParameters, spendUtxos?: UTxO[]): Promise<PayToAddress[]>;
abstract buildSwapOrder(liquidityPool: LiquidityPool, swapParameters: DatumParameters, spendUtxos?: SpendUTxO[]): Promise<PayToAddress[]>;

/**
* Craft a swap order cancellation for this DEX.
Expand Down
17 changes: 14 additions & 3 deletions src/dex/minswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AssetBalance,
DatumParameters, DefinitionConstr, DefinitionField,
PayToAddress,
RequestConfig,
RequestConfig, SpendUTxO,
SwapFee,
UTxO
} from '@app/types';
Expand All @@ -18,6 +18,7 @@ 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';
import { Script } from 'lucid-cardano';

export class Minswap extends BaseDex {

Expand All @@ -32,6 +33,11 @@ export class Minswap extends BaseDex {
public readonly lpTokenPolicyId: string = 'e4214b7cce62ac6fbba385d164df48e157eae5863521b4b67ca71d86';
public readonly poolNftPolicyId: string = '0be55d262b29f564998ff81efe21bdc0022621c12f15af08d0f2ddb1';
public readonly poolValidityAsset: string = '13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f4d494e53574150';
public readonly cancelDatum: string = 'd87a80';
public readonly orderScript: Script = {
type: 'PlutusV1',
script: '59014f59014c01000032323232323232322223232325333009300e30070021323233533300b3370e9000180480109118011bae30100031225001232533300d3300e22533301300114a02a66601e66ebcc04800400c5288980118070009bac3010300c300c300c300c300c300c300c007149858dd48008b18060009baa300c300b3754601860166ea80184ccccc0288894ccc04000440084c8c94ccc038cd4ccc038c04cc030008488c008dd718098018912800919b8f0014891ce1317b152faac13426e6a83e06ff88a4d62cce3c1634ab0a5ec133090014a0266008444a00226600a446004602600a601a00626600a008601a006601e0026ea8c03cc038dd5180798071baa300f300b300e3754601e00244a0026eb0c03000c92616300a001375400660106ea8c024c020dd5000aab9d5744ae688c8c0088cc0080080048c0088cc00800800555cf2ba15573e6e1d200201',
};

constructor(requestConfig: RequestConfig = {}) {
super();
Expand Down Expand Up @@ -177,7 +183,7 @@ export class Minswap extends BaseDex {
return Number(priceImpactNumerator * 100n) / Number(priceImpactDenominator);
}

public async buildSwapOrder(liquidityPool: LiquidityPool, swapParameters: DatumParameters, spendUtxos: UTxO[] = []): Promise<PayToAddress[]> {
public async buildSwapOrder(liquidityPool: LiquidityPool, swapParameters: DatumParameters, spendUtxos: SpendUTxO[] = []): Promise<PayToAddress[]> {
const batcherFee: SwapFee | undefined = this.swapOrderFees().find((fee: SwapFee) => fee.id === 'batcherFee');
const deposit: SwapFee | undefined = this.swapOrderFees().find((fee: SwapFee) => fee.id === 'deposit');

Expand Down Expand Up @@ -232,7 +238,12 @@ export class Minswap extends BaseDex {
addressType: AddressType.Base,
assetBalances: relevantUtxo.assetBalances,
isInlineDatum: false,
spendUtxos: [relevantUtxo],
spendUtxos: [{
utxo: relevantUtxo,
redeemer: this.cancelDatum,
validator: this.orderScript,
signer: returnAddress,
}],
}
];
}
Expand Down
Loading

0 comments on commit 3bec031

Please sign in to comment.