@indigo-labs/indigo-sdk
Version:
Indigo SDK for interacting with Indigo endpoints via lucid-evolution
71 lines (68 loc) • 2.56 kB
text/typescript
import {
applyParamsToScript,
SpendingValidator,
WithdrawalValidator,
} from '@lucid-evolution/lucid';
import {
CdpParamsSP,
CdpRedeemParamsSP,
fromSystemParamsAssetLucid,
} from '../../types/system-params';
import { castCdpParams, castCdpRedeemParams } from './types';
import { _cdpValidator } from '../../validators/cdp-validator';
import { _cdpRedeemValidator } from '../../validators/cdp-redeem-validator';
export const mkCdpValidatorFromSP = (
params: CdpParamsSP,
): SpendingValidator => {
return {
type: 'PlutusV3',
script: applyParamsToScript(_cdpValidator.cborHex, [
castCdpParams({
cdp_auth_token: fromSystemParamsAssetLucid(params.cdpAuthToken),
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
iasset_auth_token: fromSystemParamsAssetLucid(params.iAssetAuthToken),
collateral_asset_auth_token: fromSystemParamsAssetLucid(
params.collateralAssetAuthToken,
),
stability_pool_auth_token: fromSystemParamsAssetLucid(
params.stabilityPoolAuthToken,
),
upgrade_token: fromSystemParamsAssetLucid(params.upgradeToken),
version_record_token: fromSystemParamsAssetLucid(
params.versionRecordToken,
),
interest_collector_val_hash: params.interestCollectorValHash,
sp_val_hash: params.spValHash,
iasset_val_hash: params.iassetValHash,
treasury_val_hash: params.treasuryValHash,
cdp_redeem_val_hash: params.cdpRedeemValHash,
bias_time: BigInt(params.biasTime),
}),
]),
};
};
export const mkCdpRedeemValidatorFromSP = (
params: CdpRedeemParamsSP,
): WithdrawalValidator => {
return {
type: 'PlutusV3',
script: applyParamsToScript(_cdpRedeemValidator.cborHex, [
castCdpRedeemParams({
cdp_auth_token: fromSystemParamsAssetLucid(params.cdpAuthToken),
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
iasset_auth_token: fromSystemParamsAssetLucid(params.iAssetAuthToken),
collateral_asset_auth_token: fromSystemParamsAssetLucid(
params.collateralAssetAuthToken,
),
interest_collector_val_hash: params.interestCollectorValHash,
iasset_val_hash: params.iassetValHash,
treasury_val_hash: params.treasuryValHash,
gov_nft: fromSystemParamsAssetLucid(params.govNFT),
partial_redemption_extra_fee_lovelace: BigInt(
params.partialRedemptionExtraFeeLovelace,
),
bias_time: BigInt(params.biasTime),
}),
]),
};
};