Skip to content

Commit

Permalink
Tidy up & include wallet in funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed May 13, 2024
1 parent 0e7a53b commit b8e1bef
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/dex/api/sundaeswap-v3-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export class SundaeSwapV3Api extends BaseApi {
BigInt(pool.current.quantityA),
BigInt(pool.current.quantityB),
this.dex.poolAddress,
this.dex.getDynamicOrderAddress(''), // TODO Need to get sender stake key hash.
this.dex.getDynamicOrderAddress(''), // TODO Need to get sender stake key hash.
'',
'',
);

liquidityPool.identifier = pool.id;
Expand Down
9 changes: 5 additions & 4 deletions src/dex/base-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AssetBalance, DatumParameters, PayToAddress, SpendUTxO, SwapFee, UTxO }
import { DatumParameterKey } from '@app/constants';
import { tokensMatch } from '@app/utils';
import { BaseApi } from '@dex/api/base-api';
import { BaseWalletProvider } from '@providers/wallet/base-wallet-provider';

export abstract class BaseDex {

Expand All @@ -16,17 +17,17 @@ export abstract class BaseDex {
/**
* Fetch addresses mapped to a liquidity pool.
*/
abstract liquidityPoolAddresses(provider: BaseDataProvider): Promise<string[]>;
abstract liquidityPoolAddresses(provider?: BaseDataProvider): Promise<string[]>;

/**
* Fetch all liquidity pools.
*/
abstract liquidityPools(provider: BaseDataProvider): Promise<LiquidityPool[]>;
abstract liquidityPools(provider: BaseDataProvider, wallet?: BaseWalletProvider): Promise<LiquidityPool[]>;

/**
* Craft liquidity pool state from a valid UTxO.
*/
abstract liquidityPoolFromUtxo(provider: BaseDataProvider, utxo: UTxO): Promise<LiquidityPool | undefined>;
abstract liquidityPoolFromUtxo(provider: BaseDataProvider, utxo: UTxO, wallet?: BaseWalletProvider): Promise<LiquidityPool | undefined>;

/**
* Estimated swap in amount given for a swap out token & amount on a liquidity pool.
Expand All @@ -51,7 +52,7 @@ export abstract class BaseDex {
/**
* Craft a swap order cancellation for this DEX.
*/
abstract buildCancelSwapOrder(txOutputs: UTxO[], returnAddress: string): Promise<PayToAddress[]>;
abstract buildCancelSwapOrder(txOutputs: UTxO[], returnAddress: string, wallet?: BaseWalletProvider): Promise<PayToAddress[]>;

/**
* Fees associated with submitting a swap order.
Expand Down
7 changes: 2 additions & 5 deletions src/dex/definitions/sundaeswap-v3/order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DatumParameterKey } from '@app/constants';
import { DefinitionField } from '@app/types';

const datum = {
export default {
constructor: 0,
fields: [
{
Expand Down Expand Up @@ -93,7 +92,5 @@ const datum = {
{
bytes: DatumParameterKey.CancelDatum,
},
] as DefinitionField[],
],
};

export default datum;
57 changes: 46 additions & 11 deletions src/dex/definitions/sundaeswap-v3/pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DatumParameterKey } from '@app/constants';
import { DefinitionField, DefinitionList } from '@app/types';

export default {
constructor: 0,
Expand All @@ -10,26 +9,62 @@ export default {
{
list: [
{
list: [{ bytes: DatumParameterKey.PoolAssetAPolicyId }, { bytes: DatumParameterKey.PoolAssetAAssetName }] as DefinitionList,
list: [
{
bytes: DatumParameterKey.PoolAssetAPolicyId
},
{
bytes: DatumParameterKey.PoolAssetAAssetName
}
],
},
{
list: [{ bytes: DatumParameterKey.PoolAssetBPolicyId }, { bytes: DatumParameterKey.PoolAssetBAssetName }] as DefinitionList,
list: [
{
bytes: DatumParameterKey.PoolAssetBPolicyId
},
{
bytes: DatumParameterKey.PoolAssetBAssetName
}
],
},
] as unknown as DefinitionList,
],
},
{ int: DatumParameterKey.TotalLpTokens },
{
list: [{ int: DatumParameterKey.OpeningFee }, { int: DatumParameterKey.FinalFee }] as DefinitionList, // Need to confirm these?
int: DatumParameterKey.TotalLpTokens
},
{
list: [{ int: DatumParameterKey.OpeningFee }, { int: DatumParameterKey.FinalFee }] as DefinitionList, // Need to confirm these?
list: [
{
int: DatumParameterKey.OpeningFee
},
{
int: DatumParameterKey.FinalFee
}
],
},
{
list: [
{
int: DatumParameterKey.OpeningFee
},
{
int: DatumParameterKey.FinalFee
}
],
},
{
fields: [],
constructor: 1,
},
{ int: DatumParameterKey.MarketOpen },
{ int: DatumParameterKey.FeesFinalized },
{ int: DatumParameterKey.ProtocolFee },
] as DefinitionField[],
{
int: DatumParameterKey.MarketOpen
},
{
int: DatumParameterKey.FeesFinalized
},
{
int: DatumParameterKey.ProtocolFee
},
],
};
1 change: 1 addition & 0 deletions src/dex/sundaeswap-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class SundaeSwapV1 extends BaseDex {
const datum: DefinitionField = await provider.datumValue(utxo.datumHash);
const parameters: DatumParameters = builder.pullParameters(datum as DefinitionConstr);

liquidityPool.lpToken = lpToken;
liquidityPool.identifier = typeof parameters.PoolIdentifier === 'string'
? parameters.PoolIdentifier
: '';
Expand Down
93 changes: 53 additions & 40 deletions src/dex/sundaeswap-v3.ts

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ export type DefinitionInt = {
int: number | DatumParameterKey;
};

export type DefinitionField = DefinitionConstr | DefinitionBytes | DefinitionInt | DefinitionField[] | DefinitionList | DefinitionList[] | Function;
export type DefinitionList = DefinitionBytes | DefinitionInt | DefinitionList[] | Function;
export type DefinitionList = {
list: DefinitionField[] | DefinitionList[];
};

export type DefinitionField = DefinitionConstr | DefinitionBytes | DefinitionInt | DefinitionList| Function | DefinitionField[];

export type DefinitionConstr = {
constructor: number | DatumParameterKey;
Expand Down

0 comments on commit b8e1bef

Please sign in to comment.