@indigo-labs/indigo-sdk
Version:
Indigo SDK for interacting with Indigo endpoints via lucid-evolution
59 lines (52 loc) • 1.73 kB
text/typescript
import { fromText, TxBuilder } from '@lucid-evolution/lucid';
import { LucidContext } from '../test-helpers';
import { fromSystemParamsAsset, redeemRob, SystemParams } from '../../src';
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
import { RobOutput } from '../../src/contracts/rob/types-new';
import { findCollateralAsset, findIAsset } from '../queries/iasset-queries';
import { findPriceOracleFromCollateralAsset } from '../cdp/cdp-queries';
export async function runRedeemRob(
context: LucidContext,
sysParams: SystemParams,
redemptionRobsData: [RobOutput, bigint][],
iasset: string,
collateralAsset: AssetClass,
currentSlot: number,
pythMessage?: string,
): Promise<TxBuilder> {
if (redemptionRobsData.length === 0) throw new Error('No ROBs to redeem');
const collateral = await findCollateralAsset(
context.lucid,
sysParams,
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
iasset,
collateralAsset,
);
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
context.lucid,
collateral,
);
const iassetOut = await findIAsset(
context.lucid,
sysParams.validatorHashes.iassetHash,
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
iasset,
);
const pythStateOutRef = pythMessage
? await context.lucid.utxoByUnit(
sysParams.pythConfig.pythStateAssetClass[0].unCurrencySymbol +
fromText('Pyth State'),
)
: undefined;
return redeemRob(
redemptionRobsData.map(([out, amt]) => [out.utxo, amt]),
priceOracleUtxo,
iassetOut.utxo,
collateral.utxo,
context.lucid,
sysParams,
currentSlot,
pythMessage,
pythStateOutRef,
);
}