@indigo-labs/indigo-sdk 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +337 -772
- package/dist/index.d.ts +337 -772
- package/dist/index.js +1194 -557
- package/dist/index.mjs +1091 -451
- package/package.json +1 -1
- package/src/contracts/cdp/helpers.ts +12 -0
- package/src/contracts/cdp/transactions.ts +32 -8
- package/src/contracts/gov/helpers.ts +58 -0
- package/src/contracts/gov/transactions.ts +35 -14
- package/src/contracts/iasset/helpers.ts +3 -0
- package/src/contracts/price-oracle/types-new.ts +1 -1
- package/src/contracts/rob/helpers.ts +274 -196
- package/src/contracts/rob/transactions.ts +11 -5
- package/src/contracts/rob-leverage/helpers.ts +379 -371
- package/src/contracts/rob-leverage/transactions.ts +176 -104
- package/src/contracts/staking/transactions.ts +3 -0
- package/src/contracts/treasury/transactions.ts +58 -36
- package/src/contracts/treasury/types-new.ts +1 -1
- package/src/index.ts +0 -2
- package/src/utils/utils.ts +0 -3
- package/src/validators/cdp-creator-validator.ts +1 -1
- package/src/validators/cdp-redeem-validator.ts +1 -1
- package/src/validators/cdp-validator.ts +1 -1
- package/src/validators/collector-validator.ts +1 -1
- package/src/validators/execute-validator.ts +1 -1
- package/src/validators/governance-validator.ts +1 -1
- package/src/validators/interest-collection-validator.ts +1 -1
- package/src/validators/interest-oracle-validator.ts +1 -1
- package/src/validators/poll-manager-validator.ts +1 -1
- package/src/validators/poll-shard-validator.ts +1 -1
- package/src/validators/stability-pool-validator.ts +1 -1
- package/src/validators/stableswap-validator.ts +1 -1
- package/src/validators/staking-validator.ts +1 -1
- package/src/validators/treasury-validator.ts +1 -1
- package/tests/cdp/actions.ts +87 -6
- package/tests/cdp/cdp-queries.ts +1 -1
- package/tests/cdp/cdp.test.ts +949 -94
- package/tests/endpoints/initialize.ts +14 -2
- package/tests/gov/gov.test.ts +864 -1
- package/tests/interest-collection/interest-collector-queries.ts +2 -1
- package/tests/queries/collector-queries.ts +2 -1
- package/tests/queries/poll-queries.ts +2 -1
- package/tests/queries/treasury-queries.ts +8 -2
- package/tests/rob/rob-leverage.test.ts +1646 -612
- package/tests/rob/rob.test.ts +35 -19
- package/tests/rob/transactions-mutated.ts +6 -4
- package/tests/stability-pool.test.ts +251 -25
package/package.json
CHANGED
|
@@ -17,6 +17,18 @@ import {
|
|
|
17
17
|
rationalSub,
|
|
18
18
|
} from '../../types/rational';
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Amount of iasset equal in value to the given number of collateral amount.
|
|
22
|
+
*/
|
|
23
|
+
export function iassetValueOfCollateral(
|
|
24
|
+
collateralAmt: bigint,
|
|
25
|
+
oraclePrice: Rational,
|
|
26
|
+
): bigint {
|
|
27
|
+
return rationalFloor(
|
|
28
|
+
rationalDiv(rationalFromInt(collateralAmt), oraclePrice),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
/**
|
|
21
33
|
* This is mostly for debugging purposes.
|
|
22
34
|
*/
|
|
@@ -84,7 +84,10 @@ export async function openCdp(
|
|
|
84
84
|
collateralAssetOref: OutRef,
|
|
85
85
|
priceOracleOref: OutRef | undefined,
|
|
86
86
|
interestOracleOref: OutRef,
|
|
87
|
-
|
|
87
|
+
/**
|
|
88
|
+
* `undefined` in case using direct treasury payment.
|
|
89
|
+
*/
|
|
90
|
+
treasuryOref: OutRef | undefined,
|
|
88
91
|
lucid: LucidEvolution,
|
|
89
92
|
currentSlot: number,
|
|
90
93
|
pythMessage: string | undefined = undefined,
|
|
@@ -310,7 +313,10 @@ export async function adjustCdp(
|
|
|
310
313
|
collateralAssetOref: OutRef,
|
|
311
314
|
priceOracleOref: OutRef | undefined,
|
|
312
315
|
interestOracleOref: OutRef,
|
|
313
|
-
|
|
316
|
+
/**
|
|
317
|
+
* `undefined` in case using direct treasury payment.
|
|
318
|
+
*/
|
|
319
|
+
treasuryOref: OutRef | undefined,
|
|
314
320
|
interestCollectorOref: OutRef,
|
|
315
321
|
sysParams: SystemParams,
|
|
316
322
|
lucid: LucidEvolution,
|
|
@@ -542,7 +548,10 @@ export async function depositCdp(
|
|
|
542
548
|
iassetOref: OutRef,
|
|
543
549
|
collateralAssetOref: OutRef,
|
|
544
550
|
interestOracleOref: OutRef,
|
|
545
|
-
|
|
551
|
+
/**
|
|
552
|
+
* `undefined` in case using direct treasury payment.
|
|
553
|
+
*/
|
|
554
|
+
treasuryOref: OutRef | undefined,
|
|
546
555
|
interestCollectorOref: OutRef,
|
|
547
556
|
params: SystemParams,
|
|
548
557
|
lucid: LucidEvolution,
|
|
@@ -571,7 +580,10 @@ export async function withdrawCdp(
|
|
|
571
580
|
collateralAssetOref: OutRef,
|
|
572
581
|
priceOracleOref: OutRef | undefined,
|
|
573
582
|
interestOracleOref: OutRef,
|
|
574
|
-
|
|
583
|
+
/**
|
|
584
|
+
* `undefined` in case using direct treasury payment.
|
|
585
|
+
*/
|
|
586
|
+
treasuryOref: OutRef | undefined,
|
|
575
587
|
interestCollectorOref: OutRef,
|
|
576
588
|
params: SystemParams,
|
|
577
589
|
lucid: LucidEvolution,
|
|
@@ -604,7 +616,10 @@ export async function mintCdp(
|
|
|
604
616
|
collateralAssetOref: OutRef,
|
|
605
617
|
priceOracleOref: OutRef | undefined,
|
|
606
618
|
interestOracleOref: OutRef,
|
|
607
|
-
|
|
619
|
+
/**
|
|
620
|
+
* `undefined` in case using direct treasury payment.
|
|
621
|
+
*/
|
|
622
|
+
treasuryOref: OutRef | undefined,
|
|
608
623
|
interestCollectorOref: OutRef,
|
|
609
624
|
params: SystemParams,
|
|
610
625
|
lucid: LucidEvolution,
|
|
@@ -636,7 +651,10 @@ export async function burnCdp(
|
|
|
636
651
|
iassetOref: OutRef,
|
|
637
652
|
collateralAssetOref: OutRef,
|
|
638
653
|
interestOracleOref: OutRef,
|
|
639
|
-
|
|
654
|
+
/**
|
|
655
|
+
* `undefined` in case using direct treasury payment.
|
|
656
|
+
*/
|
|
657
|
+
treasuryOref: OutRef | undefined,
|
|
640
658
|
interestCollectorOref: OutRef,
|
|
641
659
|
params: SystemParams,
|
|
642
660
|
lucid: LucidEvolution,
|
|
@@ -805,7 +823,10 @@ export async function redeemCdp(
|
|
|
805
823
|
priceOracleOref: OutRef | undefined,
|
|
806
824
|
interestOracleOref: OutRef,
|
|
807
825
|
interestCollectorOref: OutRef,
|
|
808
|
-
|
|
826
|
+
/**
|
|
827
|
+
* `undefined` in case using direct treasury payment.
|
|
828
|
+
*/
|
|
829
|
+
treasuryOref: OutRef | undefined,
|
|
809
830
|
govOref: OutRef,
|
|
810
831
|
sysParams: SystemParams,
|
|
811
832
|
lucid: LucidEvolution,
|
|
@@ -1290,7 +1311,10 @@ export async function liquidateCdp(
|
|
|
1290
1311
|
cdpOref: OutRef,
|
|
1291
1312
|
stabilityPoolOref: OutRef,
|
|
1292
1313
|
interestCollectorOref: OutRef,
|
|
1293
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* `undefined` in case using direct treasury payment.
|
|
1316
|
+
*/
|
|
1317
|
+
treasuryOref: OutRef | undefined,
|
|
1294
1318
|
sysParams: SystemParams,
|
|
1295
1319
|
lucid: LucidEvolution,
|
|
1296
1320
|
): Promise<TxBuilder> {
|
|
@@ -159,6 +159,64 @@ export async function findRelativeCollateralAssetForInsertion(
|
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
/**
|
|
163
|
+
* A generic solution for iassets and collateral assets chain.
|
|
164
|
+
*/
|
|
165
|
+
async function findFirstAsset<
|
|
166
|
+
T extends Uint8Array<ArrayBufferLike> | AssetClass,
|
|
167
|
+
K,
|
|
168
|
+
>(
|
|
169
|
+
allIAssetOrefs: OutRef[],
|
|
170
|
+
lucid: LucidEvolution,
|
|
171
|
+
assetOrd: Ord.Ord<T>,
|
|
172
|
+
getComparisonAsset: (datum: K) => T,
|
|
173
|
+
parseDatum: (utxo: UTxO) => K,
|
|
174
|
+
): Promise<O.Option<ParsedOutput<K>>> {
|
|
175
|
+
const parsedUtxos = await Promise.all(
|
|
176
|
+
allIAssetOrefs.map(async (oref) => {
|
|
177
|
+
const utxo = matchSingle(
|
|
178
|
+
await lucid.utxosByOutRef([oref]),
|
|
179
|
+
(_) => new Error('Expected a single UTXO'),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const datum = parseDatum(utxo);
|
|
183
|
+
|
|
184
|
+
return { datum: datum, utxo: utxo };
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// The iasset just before the new token name based on assets ordering
|
|
189
|
+
return pipe(
|
|
190
|
+
parsedUtxos,
|
|
191
|
+
// Sort by the asset names
|
|
192
|
+
A.sort(
|
|
193
|
+
Ord.contramap<T, ParsedOutput<K>>((a) => getComparisonAsset(a.datum))(
|
|
194
|
+
assetOrd,
|
|
195
|
+
),
|
|
196
|
+
),
|
|
197
|
+
A.head,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Find the collateral asset that is first in the distributed list.
|
|
203
|
+
* In case there are no collateral assets, none should be returned.
|
|
204
|
+
*/
|
|
205
|
+
export async function findFirstCollateralAsset(
|
|
206
|
+
allCollateralAssetOrefs: OutRef[],
|
|
207
|
+
lucid: LucidEvolution,
|
|
208
|
+
): Promise<O.Option<CollateralAssetOutput>> {
|
|
209
|
+
return findFirstAsset(
|
|
210
|
+
allCollateralAssetOrefs,
|
|
211
|
+
lucid,
|
|
212
|
+
Ord.contramap<string, AssetClass>((x) => getAssetClassComparisonStr(x))(
|
|
213
|
+
S.Ord,
|
|
214
|
+
),
|
|
215
|
+
(d) => d.collateralAsset,
|
|
216
|
+
(utxo) => parseCollateralAssetDatumOrThrow(getInlineDatumOrThrow(utxo)),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
162
220
|
type IAssetCreationDatumHelperReturnType = {
|
|
163
221
|
newIAsset: IAssetContent;
|
|
164
222
|
newReferencedIAsset: O.Option<IAssetContent>;
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from '../../utils/lucid-utils';
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
|
+
adaAssetClass,
|
|
23
24
|
assetClassValueOf,
|
|
24
25
|
isAssetsZero,
|
|
25
26
|
isSameAssetClass,
|
|
@@ -50,6 +51,7 @@ import { pollPassQuorum } from '../poll/helpers';
|
|
|
50
51
|
import {
|
|
51
52
|
collateralAssetCreationDatumHelper,
|
|
52
53
|
createValueFromWithdrawal,
|
|
54
|
+
findFirstCollateralAsset,
|
|
53
55
|
findRelativeCollateralAssetForInsertion,
|
|
54
56
|
findRelativeIAssetForInsertion,
|
|
55
57
|
iassetCreationDatumHelper,
|
|
@@ -252,11 +254,7 @@ export async function createProposal(
|
|
|
252
254
|
),
|
|
253
255
|
)
|
|
254
256
|
.validFrom(Number(currentTime) - ONE_SECOND)
|
|
255
|
-
.validTo(
|
|
256
|
-
Number(currentTime) +
|
|
257
|
-
Number(sysParams.govParams.gBiasTime) -
|
|
258
|
-
ONE_SECOND,
|
|
259
|
-
)
|
|
257
|
+
.validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND)
|
|
260
258
|
.addSigner(ownAddr),
|
|
261
259
|
newPollId,
|
|
262
260
|
];
|
|
@@ -325,9 +323,7 @@ export async function createShardsChunks(
|
|
|
325
323
|
.newTx()
|
|
326
324
|
.validFrom(Number(currentTime) - ONE_SECOND)
|
|
327
325
|
.validTo(
|
|
328
|
-
Number(currentTime)
|
|
329
|
-
Number(sysParams.pollManagerParams.pBiasTime) -
|
|
330
|
-
ONE_SECOND,
|
|
326
|
+
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND,
|
|
331
327
|
)
|
|
332
328
|
.mintAssets(mkAssetsOf(pollNft, shardsCount), Data.void())
|
|
333
329
|
// Ref scripts
|
|
@@ -580,9 +576,7 @@ export async function mergeShards(
|
|
|
580
576
|
.newTx()
|
|
581
577
|
.validFrom(Number(currentTime) - ONE_SECOND)
|
|
582
578
|
.validTo(
|
|
583
|
-
Number(currentTime)
|
|
584
|
-
Number(sysParams.pollManagerParams.pBiasTime) -
|
|
585
|
-
ONE_SECOND,
|
|
579
|
+
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND,
|
|
586
580
|
)
|
|
587
581
|
.readFrom([
|
|
588
582
|
pollShardRefScriptUtxo,
|
|
@@ -1188,6 +1182,11 @@ export async function executeProposal(
|
|
|
1188
1182
|
1n,
|
|
1189
1183
|
);
|
|
1190
1184
|
|
|
1185
|
+
const firstCollateralAsset = await findFirstCollateralAsset(
|
|
1186
|
+
allCollateralAssetsOrefsOfIAsset,
|
|
1187
|
+
lucid,
|
|
1188
|
+
);
|
|
1189
|
+
|
|
1191
1190
|
tx.readFrom([
|
|
1192
1191
|
iassetRefScriptUtxo,
|
|
1193
1192
|
collateralAssetTokenPolicyRefScriptUtxo,
|
|
@@ -1270,6 +1269,30 @@ export async function executeProposal(
|
|
|
1270
1269
|
},
|
|
1271
1270
|
),
|
|
1272
1271
|
);
|
|
1272
|
+
|
|
1273
|
+
// Provide proof of existence or non-existence of ADA collateral.
|
|
1274
|
+
if (
|
|
1275
|
+
!isSameAssetClass(newCollateralAsset.collateralAsset, adaAssetClass)
|
|
1276
|
+
) {
|
|
1277
|
+
F.pipe(
|
|
1278
|
+
newReferencedCollateralAsset,
|
|
1279
|
+
O.match(
|
|
1280
|
+
() => {},
|
|
1281
|
+
(referencedAsset) =>
|
|
1282
|
+
referencedAsset.firstCollateralAsset
|
|
1283
|
+
? {}
|
|
1284
|
+
: F.pipe(
|
|
1285
|
+
firstCollateralAsset,
|
|
1286
|
+
O.match(
|
|
1287
|
+
() => {},
|
|
1288
|
+
(firstAsset) => {
|
|
1289
|
+
tx.readFrom([firstAsset.utxo]);
|
|
1290
|
+
},
|
|
1291
|
+
),
|
|
1292
|
+
),
|
|
1293
|
+
),
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1273
1296
|
})
|
|
1274
1297
|
.with(
|
|
1275
1298
|
{ UpdateCollateralAsset: P.select() },
|
|
@@ -1561,9 +1584,7 @@ export async function executeProposal(
|
|
|
1561
1584
|
|
|
1562
1585
|
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo])
|
|
1563
1586
|
.validFrom(Number(currentTime) - ONE_SECOND)
|
|
1564
|
-
.validTo(
|
|
1565
|
-
Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND,
|
|
1566
|
-
)
|
|
1587
|
+
.validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND)
|
|
1567
1588
|
.collectFrom([executeUtxo], Data.void())
|
|
1568
1589
|
.mintAssets(
|
|
1569
1590
|
mkAssetsOf(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
|
|
@@ -32,6 +32,8 @@ import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
|
32
32
|
import * as Core from '@evolution-sdk/evolution';
|
|
33
33
|
import { decodePriceUpdate, decodePythMessage } from '../../utils/pyth';
|
|
34
34
|
|
|
35
|
+
export const MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 8;
|
|
36
|
+
|
|
35
37
|
type Interval = {
|
|
36
38
|
validFrom: number;
|
|
37
39
|
validTo: number;
|
|
@@ -95,6 +97,7 @@ export function attachOracle(
|
|
|
95
97
|
.with(
|
|
96
98
|
{ DeferredValidation: { feedValHash: P.select() } },
|
|
97
99
|
async (feedValHash) => {
|
|
100
|
+
if (priceOracleOref) throw new Error('Cannot pass price oracle oref');
|
|
98
101
|
if (!pythMessage) throw new Error('Missing Pyth message');
|
|
99
102
|
if (!pythStateOref) throw new Error('Missing pyth state out ref');
|
|
100
103
|
|
|
@@ -20,7 +20,7 @@ export const OracleIdxSchema = TSchema.Union(
|
|
|
20
20
|
TSchema.Literal('OracleVoid', { flatInUnion: true }),
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
export type OracleIdx = typeof OracleIdxSchema;
|
|
23
|
+
export type OracleIdx = typeof OracleIdxSchema.Type;
|
|
24
24
|
|
|
25
25
|
const PriceOracleDatumSchema = TSchema.Struct({
|
|
26
26
|
price: RationalSchema,
|