diff --git a/package.json b/package.json index 44c9213..f1eb113 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spectrumlabs/cardano-dex-sdk", - "version": "0.1.195", + "version": "0.1.196", "description": "ErgoDEX SDK for Cardano", "main": "build/main/index.js", "typings": "build/main/index.d.ts", diff --git a/src/amm/interpreters/ammActions.ts b/src/amm/interpreters/ammActions.ts index bf9b161..9ff36a1 100644 --- a/src/amm/interpreters/ammActions.ts +++ b/src/amm/interpreters/ammActions.ts @@ -41,6 +41,7 @@ class DefaultAmmActions implements AmmActions { return { inputs: ctx.inputs, outputs: outputs, + collateral: ctx.collateralInputs, changeAddr: ctx.changeAddr, mintingScripts: mintAssets, ttl: ctx.ttl diff --git a/src/amm/interpreters/ammTxBuilder/ammTxBuilder.ts b/src/amm/interpreters/ammTxBuilder/ammTxBuilder.ts index d9efcc7..fb8ec0c 100644 --- a/src/amm/interpreters/ammTxBuilder/ammTxBuilder.ts +++ b/src/amm/interpreters/ammTxBuilder/ammTxBuilder.ts @@ -11,6 +11,7 @@ import {PoolCreationParams, PoolCreationTxBuilder, PoolCreationTxInfo} from "./p import {RedeemAmmTxBuilder, RedeemParams, RedeemTxInfo} from "./redeemAmmTxBuilder" import {SwapAmmTxBuilder, SwapParams, SwapTxInfo} from "./swapAmmTxBuilder" import {FullTxIn} from "../../../cardano/entities/txIn" +import {CollateralSelector} from "../../../cardano/wallet/collateralSelector" export interface AmmTxBuilder { swap(params: SwapParams): Promise<[Transaction | null, TxCandidate, SwapTxInfo, Error | null]>; @@ -39,13 +40,14 @@ export class DefaultAmmTxCandidateBuilder implements AmmTxBuilder { ammActions: AmmActions, inputSelector: InputSelector, private inputCollector: InputCollector, + collateralSelector: CollateralSelector, R: CardanoWasm, private txAsm: TxAsm ) { this.swapAmmTxBuilder = new SwapAmmTxBuilder(txMath, ammOuptuts, ammActions, inputSelector, R) this.redeemAmmTxBuilder = new RedeemAmmTxBuilder(txMath, ammOuptuts, ammActions, inputSelector, R) this.depositAmmTxBuilder = new DepositAmmTxBuilder(txMath, ammOuptuts, ammActions, inputSelector, R) - this.poolTxBuilder = new PoolCreationTxBuilder(txMath, ammOuptuts, ammActions, inputSelector) + this.poolTxBuilder = new PoolCreationTxBuilder(txMath, ammOuptuts, ammActions, inputSelector, collateralSelector) } async swap( diff --git a/src/amm/interpreters/ammTxBuilder/poolCreationTxBuilder.ts b/src/amm/interpreters/ammTxBuilder/poolCreationTxBuilder.ts index 71b1600..de63eac 100644 --- a/src/amm/interpreters/ammTxBuilder/poolCreationTxBuilder.ts +++ b/src/amm/interpreters/ammTxBuilder/poolCreationTxBuilder.ts @@ -13,6 +13,7 @@ import {OrderKind} from "../../models/opRequests" import {AmmActions} from "../ammActions" import {AmmOutputs} from "../ammOutputs" import {selectInputs} from "./selectInputs" +import {CollateralSelector} from "../../../cardano/wallet/collateralSelector" export interface PoolCreationParams { readonly x: AssetAmount @@ -27,6 +28,7 @@ export interface PoolCreationParams { readonly txFees: AmmTxFeeMapping readonly changeAddress: Addr readonly pk: PubKeyHash + readonly collateralAmount: bigint; } export interface PoolCreationTxInfo { @@ -43,6 +45,7 @@ export class PoolCreationTxBuilder { private ammOutputs: AmmOutputs, private ammActions: AmmActions, private inputSelector: InputSelector, + private collateralSelector: CollateralSelector ) { } @@ -51,6 +54,7 @@ export class PoolCreationTxBuilder { const totalOrderBudget = add(orderBudget, AdaEntry(userTxFee || params.txFees.poolCreation)) + const collateralOrError = await this.collateralSelector.getCollateral(params.collateralAmount); const inputsOrError = await selectInputs(totalOrderBudget, params.changeAddress, this.inputSelector, allInputs, this.txMath) const inputForMinting = await this .inputSelector @@ -59,6 +63,9 @@ export class PoolCreationTxBuilder { if (inputForMinting instanceof Error) { throw inputForMinting } + if (collateralOrError instanceof Error) { + throw collateralOrError; + } const inputs: FullTxIn[] = inputsOrError instanceof Error ? [] : inputsOrError @@ -101,7 +108,7 @@ export class PoolCreationTxBuilder { }, { changeAddr: params.changeAddress, - collateralInputs: [], + collateralInputs: collateralOrError, inputs: Object.values(inputsDictionary) } ), diff --git a/src/cardano/wallet/entities/txContext.ts b/src/cardano/wallet/entities/txContext.ts index 86df78a..d82daa5 100644 --- a/src/cardano/wallet/entities/txContext.ts +++ b/src/cardano/wallet/entities/txContext.ts @@ -1,10 +1,9 @@ import {Addr} from "../../entities/address" import {FullTxIn} from "../../entities/txIn" -import {TxOut} from "../../entities/txOut" export type TxContext = { inputs: FullTxIn[] - collateralInputs: TxOut[] + collateralInputs: FullTxIn[] changeAddr: Addr ttl?: number }