Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indigo-labs/indigo-sdk",
"version": "0.2.25",
"version": "0.2.28",
"description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/cdp-creator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const CDPCreatorRedeemer =
export function serialiseCDPCreatorRedeemer(
params: CDPCreatorRedeemer,
): Redeemer {
return Data.to<CDPCreatorRedeemer>(params, CDPCreatorRedeemer);
return Data.to<CDPCreatorRedeemer>(params, CDPCreatorRedeemer, {
canonical: true,
});
}

export function serialiseCDPCreatorDatum(): Datum {
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/cdp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export type CDPRedeemer = Data.Static<typeof CDPRedeemerSchema>;
const CDPRedeemer = CDPRedeemerSchema as unknown as CDPRedeemer;

export function serialiseCdpRedeemer(r: CDPRedeemer): Redeemer {
return Data.to<CDPRedeemer>(r, CDPRedeemer);
return Data.to<CDPRedeemer>(r, CDPRedeemer, { canonical: true });
}

export function parseCdpDatum(datum: Datum): O.Option<CDPContent> {
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/collector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ const CollectorRedeemer =
export function serialiseCollectorRedeemer(
redeemer: CollectorRedeemer,
): Redeemer {
return Data.to<CollectorRedeemer>(redeemer, CollectorRedeemer);
return Data.to<CollectorRedeemer>(redeemer, CollectorRedeemer, {
canonical: true,
});
}
2 changes: 1 addition & 1 deletion src/contracts/leverage/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
calculateTotalAdaForRedemption,
lrpRedeemableLovelacesInclReimb,
} from '../lrp/helpers';
import { LRPDatum } from '../lrp/types';
import { LRPDatum } from '../lrp/types-new';

/**
* How many LRP redemptions can we fit into a TX with CDP open.
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/leverage/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
calculateLeverageFromCollateralRatio,
MAX_REDEMPTIONS_WITH_CDP_OPEN,
} from './helpers';
import { LRPDatum } from '../lrp/types';
import { LRPDatum } from '../lrp/types-new';
import {
buildRedemptionsTx,
randomLrpsSubsetSatisfyingTargetLovelaces,
Expand Down
22 changes: 12 additions & 10 deletions src/contracts/lrp/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { addAssets, TxBuilder, UTxO } from '@lucid-evolution/lucid';
import {
LRPDatum,
parseLrpDatumOrThrow,
serialiseLrpDatum,
serialiseLrpRedeemer,
} from './types';
addAssets,
fromHex,
toHex,
TxBuilder,
UTxO,
} from '@lucid-evolution/lucid';
import { LRPDatum, parseLrpDatumOrThrow, serialiseLrpDatum } from './types-new';
import { ocdMul, OnChainDecimal } from '../../types/on-chain-decimal';
import {
lovelacesAmt,
Expand All @@ -18,6 +19,7 @@ import { insertSorted, shuffle } from '../../utils/array-utils';
import { LrpParamsSP, SystemParams } from '../../types/system-params';
import { match, P } from 'ts-pattern';
import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
import { serialiseLrpRedeemer } from './types-new';

export const MIN_LRP_COLLATERAL_AMT = 2_000_000n;

Expand Down Expand Up @@ -102,7 +104,7 @@ export function buildRedemptionsTx(
{
currencySymbol:
sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
tokenName: mainLrpDatum.iasset,
tokenName: toHex(mainLrpDatum.iasset),
},
redeemIAssetAmt,
),
Expand All @@ -122,7 +124,7 @@ export function buildRedemptionsTx(
RedeemAuxiliary: {
continuingOutputIdx: txOutputsBeforeCount + BigInt(idx),
mainRedeemOutRef: {
txHash: { hash: mainLrpUtxo.txHash },
txHash: { hash: fromHex(mainLrpUtxo.txHash) },
outputIndex: BigInt(mainLrpUtxo.outputIndex),
},
asset: mainLrpDatum.iasset,
Expand Down Expand Up @@ -168,7 +170,7 @@ export function calculateTotalAdaForRedemption(
allLrps,
A.filterMap(([utxo, datum]) => {
if (
datum.iasset !== iasset ||
toHex(datum.iasset) !== iasset ||
datum.maxPrice.getOnChainInt < iassetPrice.getOnChainInt
) {
return O.none;
Expand Down Expand Up @@ -216,7 +218,7 @@ export function randomLrpsSubsetSatisfyingTargetLovelaces(
allLrps,
A.filter(
([_, datum]) =>
datum.iasset === iasset &&
toHex(datum.iasset) === iasset &&
datum.maxPrice.getOnChainInt >= iassetPrice.getOnChainInt,
),
),
Expand Down
22 changes: 11 additions & 11 deletions src/contracts/lrp/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
addAssets,
unixTimeToSlot,
slotToUnixTime,
fromHex,
fromText,

Check failure on line 10 in src/contracts/lrp/transactions.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'fromText' is defined but never used. Allowed unused vars must match /^_/u
toHex,
toText,

Check failure on line 12 in src/contracts/lrp/transactions.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'toText' is defined but never used. Allowed unused vars must match /^_/u
} from '@lucid-evolution/lucid';
import {
addrDetails,
createScriptAddress,
getInlineDatumOrThrow,
} from '../../utils/lucid-utils';
import { unzip, zip } from 'fp-ts/lib/Array';
import {
LRPDatum,
parseLrpDatumOrThrow,
serialiseLrpDatum,
serialiseLrpRedeemer,
} from './types';
import { LRPDatum, parseLrpDatumOrThrow, serialiseLrpDatum } from './types-new';
import { parsePriceOracleDatum } from '../price-oracle/types';
import { OnChainDecimal } from '../../types/on-chain-decimal';
import { parseIAssetDatumOrThrow } from '../cdp/types';
Expand All @@ -34,6 +33,7 @@
SystemParams,
} from '../../types/system-params';
import { buildRedemptionsTx, MIN_LRP_COLLATERAL_AMT } from './helpers';
import { serialiseLrpRedeemer } from './types-new';

export async function openLrp(
assetTokenName: string,
Expand All @@ -48,8 +48,8 @@
const [ownPkh, _] = await addrDetails(lucid);

const newDatum: LRPDatum = {
owner: ownPkh.hash,
iasset: assetTokenName,
owner: fromHex(ownPkh.hash),
iasset: fromHex(assetTokenName),
maxPrice: maxPrice,
lovelacesToSpend: lovelacesAmt,
};
Expand Down Expand Up @@ -91,7 +91,7 @@
.newTx()
.readFrom([lrpScriptRefUtxo])
.collectFrom([lrpUtxo], serialiseLrpRedeemer('Cancel'))
.addSignerKey(lrpDatum.owner);
.addSignerKey(toHex(lrpDatum.owner));
}

export async function redeemLrp(
Expand Down Expand Up @@ -192,7 +192,7 @@

const rewardAssetClass: AssetClass = {
currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
tokenName: lrpDatum.iasset,
tokenName: toHex(lrpDatum.iasset),
};
const rewardAssetsAmt = assetClassValueOf(lrpUtxo.assets, rewardAssetClass);

Expand Down Expand Up @@ -237,7 +237,7 @@
mkLovelacesOf(lovelacesAdjustAmt),
),
)
.addSignerKey(lrpDatum.owner);
.addSignerKey(toHex(lrpDatum.owner));
}

/**
Expand Down
100 changes: 100 additions & 0 deletions src/contracts/lrp/types-new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Core } from '@evolution-sdk/evolution';
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
import { option as O, function as F } from 'fp-ts';
import { AIKEN_DEFAULT_OPTIONS } from '@evolution-sdk/evolution/core/CBOR';

Check failure on line 4 in src/contracts/lrp/types-new.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'AIKEN_DEFAULT_OPTIONS' is defined but never used. Allowed unused vars must match /^_/u

const TSchema = Core.TSchema;

const LRPDatumSchema = TSchema.Struct({
owner: TSchema.ByteArray,
iasset: TSchema.ByteArray,
maxPrice: Core.TSchema.Struct({
getOnChainInt: Core.TSchema.Integer,
}),
/**
* The amount of lovelaces that is available to be spent.
* This doesn't correspond to the lovelaces in UTXO's value,
* since that can contain fees, too.
*/
lovelacesToSpend: TSchema.Integer,
});

export type LRPDatum = typeof LRPDatumSchema.Type;

const LRPRedeemerSchema = TSchema.Union(
TSchema.Struct(
{
Redeem: TSchema.Struct(
{ continuingOutputIdx: TSchema.Integer },
{ flatFields: true },
),
},
{ flatInUnion: true },
),
TSchema.Struct(
{
RedeemAuxiliary: TSchema.Struct(
{
continuingOutputIdx: TSchema.Integer,
mainRedeemOutRef: TSchema.Struct({
txHash: TSchema.Struct({ hash: TSchema.ByteArray }),
outputIndex: TSchema.Integer,
}),
asset: TSchema.ByteArray,
assetPrice: Core.TSchema.Struct({
getOnChainInt: Core.TSchema.Integer,
}),
redemptionReimbursementPercentage: Core.TSchema.Struct({
getOnChainInt: Core.TSchema.Integer,
}),
},
{ flatFields: true },
),
},
{ flatInUnion: true },
),
TSchema.Literal('Cancel', { flatInUnion: true }),
TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
);

export type LRPRedeemer = typeof LRPRedeemerSchema.Type;

export function parseLrpDatum(datum: string): O.Option<LRPDatum> {
try {
return O.some(
Core.Data.withSchema(LRPDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
datum,
),
);
} catch (_) {
return O.none;
}
}

export function parseLrpDatumOrThrow(datum: string): LRPDatum {
return F.pipe(
parseLrpDatum(datum),
O.match(() => {
throw new Error('Expected an LRP datum.');
}, F.identity),
);
}

export function serialiseLrpDatum(d: LRPDatum): string {
let datum = Core.Data.withSchema(LRPDatumSchema, {
mode: 'canonical',
}).toCBORHex(d);

datum = datum.replace('d87984', 'd8799f');
datum = datum + 'ff';

return datum;
}

export function serialiseLrpRedeemer(r: LRPRedeemer): string {
const redeemer = Core.Data.withSchema(LRPRedeemerSchema, {
mode: 'canonical',
}).toCBORHex(r);

return redeemer;
}
62 changes: 2 additions & 60 deletions src/contracts/lrp/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Data, Datum, Redeemer, UTxO } from '@lucid-evolution/lucid';
import { AssetClassSchema, OutputReferenceSchema } from '../../types/generic';
import { Data, Datum, UTxO } from '@lucid-evolution/lucid';

Check failure on line 1 in src/contracts/lrp/types.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'UTxO' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 1 in src/contracts/lrp/types.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'Datum' is defined but never used. Allowed unused vars must match /^_/u
import { AssetClassSchema } from '../../types/generic';
import { OnChainDecimalSchema } from '../../types/on-chain-decimal';

Check failure on line 3 in src/contracts/lrp/types.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'OnChainDecimalSchema' is defined but never used. Allowed unused vars must match /^_/u
import { option as O, function as F } from 'fp-ts';

Check failure on line 4 in src/contracts/lrp/types.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'F' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 4 in src/contracts/lrp/types.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'O' is defined but never used. Allowed unused vars must match /^_/u

Expand All @@ -12,64 +12,6 @@
export type LRPParams = Data.Static<typeof LRPParamsSchema>;
const LRPParams = LRPParamsSchema as unknown as LRPParams;

export const LRPDatumSchema = Data.Object({
owner: Data.Bytes(),
iasset: Data.Bytes(),
maxPrice: OnChainDecimalSchema,
/**
* The amount of lovelaces that is available to be spent.
* This doesn't correspond to the lovelaces in UTXO's value,
* since that can contain fees, too.
*/
lovelacesToSpend: Data.Integer(),
});
export type LRPDatum = Data.Static<typeof LRPDatumSchema>;
const LRPDatum = LRPDatumSchema as unknown as LRPDatum;

export const LRPRedeemerSchema = Data.Enum([
Data.Object({ Redeem: Data.Object({ continuingOutputIdx: Data.Integer() }) }),
Data.Object({
RedeemAuxiliary: Data.Object({
continuingOutputIdx: Data.Integer(),
mainRedeemOutRef: OutputReferenceSchema,
asset: Data.Bytes(),
assetPrice: OnChainDecimalSchema,
redemptionReimbursementPercentage: OnChainDecimalSchema,
}),
}),
Data.Literal('Cancel'),
Data.Literal('UpgradeVersion'),
]);
export type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
const LRPRedeemer = LRPRedeemerSchema as unknown as LRPRedeemer;

export function parseLrpDatum(datum: Datum): O.Option<LRPDatum> {
try {
return O.some(Data.from<LRPDatum>(datum, LRPDatum));
} catch (_) {
return O.none;
}
}

export function parseLrpDatumOrThrow(datum: Datum): LRPDatum {
return F.pipe(
parseLrpDatum(datum),
O.match(() => {
throw new Error('Expected an LRP datum.');
}, F.identity),
);
}

export function serialiseLrpDatum(datum: LRPDatum): Datum {
return Data.to<LRPDatum>(datum, LRPDatum);
}

export function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer {
return Data.to<LRPRedeemer>(redeemer, LRPRedeemer);
}

export function castLrpParams(params: LRPParams): Data {
return Data.castTo(params, LRPParams);
}

export type LrpOutput = { datum: LRPDatum; utxo: UTxO };
9 changes: 6 additions & 3 deletions src/contracts/stability-pool/types-new.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Core as EvoCore } from '@evolution-sdk/evolution';
import { match, P } from 'ts-pattern';
import { AddressSchema } from '@3rd-eye-labs/cardano-offchain-common';
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
import {
DEFAULT_SCHEMA_OPTIONS,
STABILITY_POOL_SCHEMA_OPTIONS,
} from '../../types/evolution-schema-options';

export const SPIntegerSchema = EvoCore.TSchema.Struct({
value: EvoCore.TSchema.Integer,
Expand Down Expand Up @@ -123,7 +126,7 @@ export function serialiseStabilityPoolRedeemer(
): string {
return EvoCore.Data.withSchema(
StabilityPoolRedeemerSchema,
DEFAULT_SCHEMA_OPTIONS,
STABILITY_POOL_SCHEMA_OPTIONS,
).toCBORHex(r);
}

Expand All @@ -135,7 +138,7 @@ export function serialiseStabilityPoolDatum(
useIndefiniteMaps: boolean = false,
): string {
return EvoCore.Data.withSchema(StabilityPoolDatumSchema, {
...DEFAULT_SCHEMA_OPTIONS,
...STABILITY_POOL_SCHEMA_OPTIONS,
useIndefiniteMaps: useIndefiniteMaps,
}).toCBORHex(d);
}
Expand Down
Loading
Loading