@indigo-labs/indigo-sdk 0.4.3 → 0.5.0
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/.claude/settings.local.json +7 -0
- package/dist/index.d.mts +992 -905
- package/dist/index.d.ts +992 -905
- package/dist/index.js +2346 -2155
- package/dist/index.mjs +1925 -1750
- package/package.json +13 -21
- package/scripts/bench.sh +0 -0
- package/src/contracts/cdp/helpers.ts +7 -6
- package/src/contracts/cdp/transactions.ts +8 -29
- package/src/contracts/gov/transactions.ts +15 -17
- package/src/contracts/iasset/helpers.ts +2 -7
- package/src/contracts/initialize/actions.ts +0 -2
- package/src/contracts/initialize/helpers.ts +0 -4
- package/src/contracts/interest-collection/transactions.ts +2 -5
- package/src/contracts/interest-oracle/helpers.ts +4 -0
- package/src/contracts/interest-oracle/transactions.ts +1 -4
- package/src/contracts/price-oracle/helpers.ts +5 -11
- package/src/contracts/price-oracle/transactions.ts +2 -7
- package/src/contracts/rob/transactions.ts +0 -2
- package/src/contracts/rob-leverage/transactions.ts +1 -4
- package/{tests/queries/stability-pool-queries.ts → src/contracts/stability-pool/queries.ts} +22 -14
- package/src/contracts/stability-pool/transactions.ts +2 -8
- package/src/contracts/stableswap/helpers.ts +369 -1
- package/src/contracts/stableswap/transactions.ts +43 -191
- package/src/contracts/staking/transactions.ts +2 -7
- package/src/index.ts +4 -3
- package/tests/cdp/actions.ts +0 -11
- package/tests/cdp/cdp-helpers.ts +2 -2
- package/tests/cdp/cdp-queries.ts +8 -5
- package/tests/cdp/cdp.test.ts +409 -620
- package/tests/cdp/transactions-mutated.ts +30 -25
- package/tests/endpoints/initialize.ts +0 -2
- package/tests/gov/actions.ts +7 -32
- package/tests/gov/gov.test.ts +169 -401
- package/tests/indigo-test-helpers.ts +0 -1
- package/tests/initialize.test.ts +15 -20
- package/tests/interest-collection/interest-collection.test.ts +0 -4
- package/tests/interest-oracle.test.ts +1 -8
- package/tests/price-oracle/actions.ts +6 -8
- package/tests/price-oracle/price-oracle.test.ts +1 -13
- package/tests/price-oracle/transactions-mutated.ts +1 -4
- package/tests/pyth/pyth-feeds.test.ts +943 -0
- package/tests/pyth/pyth-indigo.test.ts +8 -12
- package/tests/pyth/pyth.test.ts +1 -2
- package/tests/rob/actions.ts +0 -2
- package/tests/rob/rob-leverage.test.ts +164 -220
- package/tests/rob/rob.test.ts +158 -263
- package/tests/rob/transactions-mutated.ts +7 -18
- package/tests/stability-pool/actions.ts +31 -22
- package/tests/stability-pool.test.ts +226 -319
- package/tests/stableswap/stableswap-actions.ts +0 -1
- package/tests/stableswap/stableswap.test.ts +226 -4
- package/tests/staking.test.ts +2 -13
- package/tests/treasury/treasury.test.ts +6 -30
package/package.json
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigo-labs/indigo-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean --tsconfig tsconfig.build.json",
|
|
10
|
-
"type-check": "tsc --noEmit",
|
|
11
|
-
"lint": "pnpm eslint .",
|
|
12
|
-
"lint:fix": "npx eslint --fix .",
|
|
13
|
-
"repack": "pnpm run build && pnpm pack",
|
|
14
|
-
"format": "npx prettier --write src/ tests/",
|
|
15
|
-
"format:check": "npx prettier --check src/ tests/",
|
|
16
|
-
"test": "vitest run",
|
|
17
|
-
"prepare": "husky",
|
|
18
|
-
"lint-staged": "lint-staged"
|
|
19
|
-
},
|
|
20
8
|
"lint-staged": {
|
|
21
9
|
"*.{js,ts,jsx,tsx}": [
|
|
22
10
|
"prettier --write",
|
|
@@ -39,12 +27,11 @@
|
|
|
39
27
|
],
|
|
40
28
|
"author": "3rd Eye Labs",
|
|
41
29
|
"license": "MIT",
|
|
42
|
-
"packageManager": "pnpm@10.33.4",
|
|
43
30
|
"dependencies": {
|
|
44
31
|
"@3rd-eye-labs/cardano-offchain-common": "1.4.7",
|
|
45
32
|
"@evolution-sdk/evolution": "^0.3.22",
|
|
46
33
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
47
|
-
"@lucid-evolution/lucid": "0.
|
|
34
|
+
"@lucid-evolution/lucid": "0.6.0",
|
|
48
35
|
"@noble/ed25519": "^3.0.0",
|
|
49
36
|
"@pythnetwork/pyth-lazer-sdk": "^6.0.0",
|
|
50
37
|
"decimal.js": "^10.6.0",
|
|
@@ -71,10 +58,15 @@
|
|
|
71
58
|
"typescript-eslint": "^8.39.0",
|
|
72
59
|
"vitest": "^4.0.14"
|
|
73
60
|
},
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --tsconfig tsconfig.build.json",
|
|
63
|
+
"type-check": "tsc --noEmit",
|
|
64
|
+
"lint": "pnpm eslint .",
|
|
65
|
+
"lint:fix": "npx eslint --fix .",
|
|
66
|
+
"repack": "pnpm run build && pnpm pack",
|
|
67
|
+
"format": "npx prettier --write src/ tests/",
|
|
68
|
+
"format:check": "npx prettier --check src/ tests/",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"lint-staged": "lint-staged"
|
|
79
71
|
}
|
|
80
|
-
}
|
|
72
|
+
}
|
package/scripts/bench.sh
CHANGED
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Assets
|
|
1
|
+
import { Assets } from '@lucid-evolution/lucid';
|
|
2
2
|
import { calculateAccruedInterest } from '../interest-oracle/helpers';
|
|
3
3
|
import { match, P } from 'ts-pattern';
|
|
4
4
|
import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
|
|
@@ -30,19 +30,20 @@ export function iassetValueOfCollateral(
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function cdpCollateralRatioPercentage(
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
|
|
35
|
+
* Otherwise, the unix timestamp should suffice, but might not be 100% precise as on-chain.
|
|
36
|
+
*/
|
|
37
|
+
now: bigint,
|
|
34
38
|
iassetPrice: Rational,
|
|
35
39
|
cdpUtxoAssets: Assets,
|
|
36
40
|
cdpContent: CDPContent,
|
|
37
41
|
interestOracleDatum: InterestOracleDatum,
|
|
38
|
-
network: Network,
|
|
39
42
|
): number {
|
|
40
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
41
|
-
|
|
42
43
|
return match(cdpContent.cdpFees)
|
|
43
44
|
.with({ ActiveCDPInterestTracking: P.select() }, (interest) => {
|
|
44
45
|
const interestAmt = calculateAccruedInterest(
|
|
45
|
-
|
|
46
|
+
now,
|
|
46
47
|
interest.unitaryInterestSnapshot,
|
|
47
48
|
cdpContent.mintedAmt,
|
|
48
49
|
interest.lastSettled,
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
LucidEvolution,
|
|
9
9
|
OutRef,
|
|
10
10
|
scriptHashToCredential,
|
|
11
|
-
slotToUnixTime,
|
|
12
11
|
toHex,
|
|
13
12
|
TxBuilder,
|
|
14
13
|
UTxO,
|
|
@@ -89,12 +88,11 @@ export async function openCdp(
|
|
|
89
88
|
*/
|
|
90
89
|
treasuryOref: OutRef | undefined,
|
|
91
90
|
lucid: LucidEvolution,
|
|
92
|
-
currentSlot: number,
|
|
93
91
|
pythMessage: string | undefined = undefined,
|
|
94
92
|
pythStateOref: OutRef | undefined = undefined,
|
|
95
93
|
): Promise<TxBuilder> {
|
|
96
94
|
const network = lucid.config().network!;
|
|
97
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
95
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
98
96
|
|
|
99
97
|
const [pkh, skh] = await addrDetails(lucid);
|
|
100
98
|
|
|
@@ -239,7 +237,6 @@ export async function openCdp(
|
|
|
239
237
|
pythMessage,
|
|
240
238
|
sysParams.pythConfig,
|
|
241
239
|
sysParams.cdpCreatorParams.biasTime,
|
|
242
|
-
currentSlot,
|
|
243
240
|
lucid,
|
|
244
241
|
tx,
|
|
245
242
|
);
|
|
@@ -320,12 +317,10 @@ export async function adjustCdp(
|
|
|
320
317
|
interestCollectorOref: OutRef,
|
|
321
318
|
sysParams: SystemParams,
|
|
322
319
|
lucid: LucidEvolution,
|
|
323
|
-
currentSlot: number,
|
|
324
320
|
pythMessage: string | undefined = undefined,
|
|
325
321
|
pythStateOref: OutRef | undefined = undefined,
|
|
326
322
|
): Promise<TxBuilder> {
|
|
327
|
-
const
|
|
328
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
323
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
329
324
|
|
|
330
325
|
const cdpRefScriptUtxo = matchSingle(
|
|
331
326
|
await lucid.utxosByOutRef([
|
|
@@ -408,7 +403,6 @@ export async function adjustCdp(
|
|
|
408
403
|
pythMessage,
|
|
409
404
|
sysParams.pythConfig,
|
|
410
405
|
sysParams.cdpParams.biasTime,
|
|
411
|
-
currentSlot,
|
|
412
406
|
lucid,
|
|
413
407
|
tx,
|
|
414
408
|
);
|
|
@@ -555,7 +549,6 @@ export async function depositCdp(
|
|
|
555
549
|
interestCollectorOref: OutRef,
|
|
556
550
|
params: SystemParams,
|
|
557
551
|
lucid: LucidEvolution,
|
|
558
|
-
currentSlot: number,
|
|
559
552
|
): Promise<TxBuilder> {
|
|
560
553
|
return adjustCdp(
|
|
561
554
|
amount,
|
|
@@ -569,7 +562,6 @@ export async function depositCdp(
|
|
|
569
562
|
interestCollectorOref,
|
|
570
563
|
params,
|
|
571
564
|
lucid,
|
|
572
|
-
currentSlot,
|
|
573
565
|
);
|
|
574
566
|
}
|
|
575
567
|
|
|
@@ -587,7 +579,6 @@ export async function withdrawCdp(
|
|
|
587
579
|
interestCollectorOref: OutRef,
|
|
588
580
|
params: SystemParams,
|
|
589
581
|
lucid: LucidEvolution,
|
|
590
|
-
currentSlot: number,
|
|
591
582
|
pythMessage: string | undefined = undefined,
|
|
592
583
|
pythStateOref: OutRef | undefined = undefined,
|
|
593
584
|
): Promise<TxBuilder> {
|
|
@@ -603,7 +594,6 @@ export async function withdrawCdp(
|
|
|
603
594
|
interestCollectorOref,
|
|
604
595
|
params,
|
|
605
596
|
lucid,
|
|
606
|
-
currentSlot,
|
|
607
597
|
pythMessage,
|
|
608
598
|
pythStateOref,
|
|
609
599
|
);
|
|
@@ -623,7 +613,6 @@ export async function mintCdp(
|
|
|
623
613
|
interestCollectorOref: OutRef,
|
|
624
614
|
params: SystemParams,
|
|
625
615
|
lucid: LucidEvolution,
|
|
626
|
-
currentSlot: number,
|
|
627
616
|
pythMessage: string | undefined = undefined,
|
|
628
617
|
pythStateOref: OutRef | undefined = undefined,
|
|
629
618
|
): Promise<TxBuilder> {
|
|
@@ -639,7 +628,6 @@ export async function mintCdp(
|
|
|
639
628
|
interestCollectorOref,
|
|
640
629
|
params,
|
|
641
630
|
lucid,
|
|
642
|
-
currentSlot,
|
|
643
631
|
pythMessage,
|
|
644
632
|
pythStateOref,
|
|
645
633
|
);
|
|
@@ -658,7 +646,6 @@ export async function burnCdp(
|
|
|
658
646
|
interestCollectorOref: OutRef,
|
|
659
647
|
params: SystemParams,
|
|
660
648
|
lucid: LucidEvolution,
|
|
661
|
-
currentSlot: number,
|
|
662
649
|
): Promise<TxBuilder> {
|
|
663
650
|
return adjustCdp(
|
|
664
651
|
0n,
|
|
@@ -672,7 +659,6 @@ export async function burnCdp(
|
|
|
672
659
|
interestCollectorOref,
|
|
673
660
|
params,
|
|
674
661
|
lucid,
|
|
675
|
-
currentSlot,
|
|
676
662
|
);
|
|
677
663
|
}
|
|
678
664
|
|
|
@@ -683,10 +669,8 @@ export async function closeCdp(
|
|
|
683
669
|
interestCollectorOref: OutRef,
|
|
684
670
|
sysParams: SystemParams,
|
|
685
671
|
lucid: LucidEvolution,
|
|
686
|
-
currentSlot: number,
|
|
687
672
|
): Promise<TxBuilder> {
|
|
688
|
-
const
|
|
689
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
673
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
690
674
|
|
|
691
675
|
const cdpRefScriptUtxo = matchSingle(
|
|
692
676
|
await lucid.utxosByOutRef([
|
|
@@ -735,7 +719,7 @@ export async function closeCdp(
|
|
|
735
719
|
getInlineDatumOrThrow(interestOracleUtxo),
|
|
736
720
|
);
|
|
737
721
|
|
|
738
|
-
const validateFrom = slotToUnixTime(
|
|
722
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
739
723
|
const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
|
|
740
724
|
|
|
741
725
|
const tx = lucid
|
|
@@ -830,12 +814,10 @@ export async function redeemCdp(
|
|
|
830
814
|
govOref: OutRef,
|
|
831
815
|
sysParams: SystemParams,
|
|
832
816
|
lucid: LucidEvolution,
|
|
833
|
-
currentSlot: number,
|
|
834
817
|
pythMessage: string | undefined = undefined,
|
|
835
818
|
_pythStateOref: OutRef | undefined = undefined,
|
|
836
819
|
): Promise<TxBuilder> {
|
|
837
|
-
const
|
|
838
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
820
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
839
821
|
|
|
840
822
|
const cdpRefScriptUtxo = matchSingle(
|
|
841
823
|
await lucid.utxosByOutRef([
|
|
@@ -996,17 +978,16 @@ export async function redeemCdp(
|
|
|
996
978
|
);
|
|
997
979
|
|
|
998
980
|
const txValidity = oracleExpirationAwareValidity(
|
|
999
|
-
|
|
981
|
+
lucid,
|
|
1000
982
|
Number(sysParams.cdpCreatorParams.biasTime),
|
|
1001
983
|
Number(priceOracleDatum.expirationTime),
|
|
1002
|
-
network,
|
|
1003
984
|
);
|
|
1004
985
|
|
|
1005
986
|
referenceInputs.push(priceOracleUtxo);
|
|
1006
987
|
|
|
1007
988
|
tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
|
|
1008
989
|
} else {
|
|
1009
|
-
const validateFrom = slotToUnixTime(
|
|
990
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
1010
991
|
const validateTo =
|
|
1011
992
|
validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
|
|
1012
993
|
|
|
@@ -1160,12 +1141,11 @@ export async function freezeCdp(
|
|
|
1160
1141
|
interestOracleOref: OutRef,
|
|
1161
1142
|
sysParams: SystemParams,
|
|
1162
1143
|
lucid: LucidEvolution,
|
|
1163
|
-
currentSlot: number,
|
|
1164
1144
|
pythMessage: string | undefined = undefined,
|
|
1165
1145
|
pythStateOref: OutRef | undefined = undefined,
|
|
1166
1146
|
): Promise<TxBuilder> {
|
|
1167
1147
|
const network = lucid.config().network!;
|
|
1168
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
1148
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
1169
1149
|
|
|
1170
1150
|
const cdpRefScriptUtxo = matchSingle(
|
|
1171
1151
|
await lucid.utxosByOutRef([
|
|
@@ -1262,7 +1242,6 @@ export async function freezeCdp(
|
|
|
1262
1242
|
pythMessage,
|
|
1263
1243
|
sysParams.pythConfig,
|
|
1264
1244
|
sysParams.cdpParams.biasTime,
|
|
1265
|
-
currentSlot,
|
|
1266
1245
|
lucid,
|
|
1267
1246
|
tx,
|
|
1268
1247
|
);
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
LucidEvolution,
|
|
8
8
|
OutRef,
|
|
9
9
|
paymentCredentialOf,
|
|
10
|
-
slotToUnixTime,
|
|
11
10
|
toHex,
|
|
12
11
|
TxBuilder,
|
|
13
12
|
UTxO,
|
|
@@ -109,7 +108,6 @@ export async function createProposal(
|
|
|
109
108
|
treasuryWithdrawal: TreasuryWithdrawal | null,
|
|
110
109
|
sysParams: SystemParams,
|
|
111
110
|
lucid: LucidEvolution,
|
|
112
|
-
currentSlot: number,
|
|
113
111
|
govOref: OutRef,
|
|
114
112
|
/**
|
|
115
113
|
* This has to be passed only in case of createAsset proposal
|
|
@@ -117,7 +115,7 @@ export async function createProposal(
|
|
|
117
115
|
allIAssetOrefs: OutRef[] | undefined,
|
|
118
116
|
): Promise<[TxBuilder, bigint]> {
|
|
119
117
|
const network = lucid.config().network!;
|
|
120
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
118
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
121
119
|
|
|
122
120
|
const ownAddr = await lucid.wallet().address();
|
|
123
121
|
const pkh = paymentCredentialOf(ownAddr);
|
|
@@ -274,11 +272,10 @@ export async function createShardsChunks(
|
|
|
274
272
|
chunkSize: bigint,
|
|
275
273
|
pollManagerOref: OutRef,
|
|
276
274
|
sysParams: SystemParams,
|
|
277
|
-
currentSlot: number,
|
|
278
275
|
lucid: LucidEvolution,
|
|
279
276
|
): Promise<TxBuilder> {
|
|
280
277
|
const network = lucid.config().network!;
|
|
281
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
278
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
282
279
|
|
|
283
280
|
const ownAddr = await lucid.wallet().address();
|
|
284
281
|
|
|
@@ -413,10 +410,10 @@ export async function vote(
|
|
|
413
410
|
stakingPositionOref: OutRef,
|
|
414
411
|
sysParams: SystemParams,
|
|
415
412
|
lucid: LucidEvolution,
|
|
416
|
-
currentSlot: number,
|
|
417
413
|
): Promise<TxBuilder> {
|
|
418
|
-
const
|
|
419
|
-
|
|
414
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
415
|
+
|
|
416
|
+
const ownAddr = await lucid.wallet().address();
|
|
420
417
|
|
|
421
418
|
const pollShardRefScriptUtxo = matchSingle(
|
|
422
419
|
await lucid.utxosByOutRef([
|
|
@@ -475,7 +472,12 @@ export async function vote(
|
|
|
475
472
|
.newTx()
|
|
476
473
|
.validFrom(validityFrom)
|
|
477
474
|
.validTo(
|
|
478
|
-
|
|
475
|
+
Math.min(
|
|
476
|
+
validityFrom +
|
|
477
|
+
Number(sysParams.pollManagerParams.pBiasTime) -
|
|
478
|
+
ONE_SECOND,
|
|
479
|
+
Number(pollShardDatum.votingEndTime) - ONE_SECOND,
|
|
480
|
+
),
|
|
479
481
|
)
|
|
480
482
|
.readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo])
|
|
481
483
|
.collectFrom([stakingPosUtxo], serialiseStakingRedeemer('Lock'))
|
|
@@ -507,7 +509,7 @@ export async function vote(
|
|
|
507
509
|
},
|
|
508
510
|
stakingPosUtxo.assets,
|
|
509
511
|
)
|
|
510
|
-
.
|
|
512
|
+
.addSigner(ownAddr);
|
|
511
513
|
}
|
|
512
514
|
|
|
513
515
|
export async function mergeShards(
|
|
@@ -515,10 +517,8 @@ export async function mergeShards(
|
|
|
515
517
|
shardsOutRefs: OutRef[],
|
|
516
518
|
sysParams: SystemParams,
|
|
517
519
|
lucid: LucidEvolution,
|
|
518
|
-
currentSlot: number,
|
|
519
520
|
): Promise<TxBuilder> {
|
|
520
|
-
const
|
|
521
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
521
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
522
522
|
|
|
523
523
|
const ownAddr = await lucid.wallet().address();
|
|
524
524
|
|
|
@@ -634,10 +634,9 @@ export async function endProposal(
|
|
|
634
634
|
govOref: OutRef,
|
|
635
635
|
sysParams: SystemParams,
|
|
636
636
|
lucid: LucidEvolution,
|
|
637
|
-
currentSlot: number,
|
|
638
637
|
): Promise<TxBuilder> {
|
|
639
638
|
const network = lucid.config().network!;
|
|
640
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
639
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
641
640
|
|
|
642
641
|
const ownAddr = await lucid.wallet().address();
|
|
643
642
|
|
|
@@ -795,10 +794,9 @@ export async function executeProposal(
|
|
|
795
794
|
stableswapPoolOrCdpCreatorOref: OutRef | null,
|
|
796
795
|
sysParams: SystemParams,
|
|
797
796
|
lucid: LucidEvolution,
|
|
798
|
-
currentSlot: number,
|
|
799
797
|
): Promise<TxBuilder> {
|
|
800
798
|
const network = lucid.config().network!;
|
|
801
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
799
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
802
800
|
|
|
803
801
|
const ownAddr = await lucid.wallet().address();
|
|
804
802
|
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
LucidEvolution,
|
|
6
6
|
OutRef,
|
|
7
7
|
scriptHashToCredential,
|
|
8
|
-
slotToUnixTime,
|
|
9
8
|
toHex,
|
|
10
9
|
TxBuilder,
|
|
11
10
|
UTxO,
|
|
@@ -48,16 +47,13 @@ export function attachOracle(
|
|
|
48
47
|
pythMessage: string | undefined,
|
|
49
48
|
pythConfig: PythConfig,
|
|
50
49
|
biasTime: bigint,
|
|
51
|
-
currentSlot: number,
|
|
52
50
|
lucid: LucidEvolution,
|
|
53
51
|
tx: TxBuilder,
|
|
54
52
|
): Promise<{ interval: Interval; referenceInputs: UTxO[] }> {
|
|
55
53
|
return match(priceInfo)
|
|
56
54
|
.returnType<Promise<{ interval: Interval; referenceInputs: UTxO[] }>>()
|
|
57
55
|
.with({ Delisted: P.any }, () => {
|
|
58
|
-
const currentTime = BigInt(
|
|
59
|
-
slotToUnixTime(lucid.config().network!, currentSlot),
|
|
60
|
-
);
|
|
56
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
61
57
|
|
|
62
58
|
// We want to make sure the transaction is valid within the bias time for interest tracking AND Pyth
|
|
63
59
|
// For validFrom, we take the higher of the two bias times
|
|
@@ -86,10 +82,9 @@ export function attachOracle(
|
|
|
86
82
|
|
|
87
83
|
return {
|
|
88
84
|
interval: oracleExpirationAwareValidity(
|
|
89
|
-
|
|
85
|
+
lucid,
|
|
90
86
|
Number(biasTime),
|
|
91
87
|
Number(priceOracleDatum.expirationTime),
|
|
92
|
-
lucid.config().network!,
|
|
93
88
|
),
|
|
94
89
|
referenceInputs: [priceOracleUtxo],
|
|
95
90
|
};
|
|
@@ -168,7 +168,6 @@ export async function initPythConfig(
|
|
|
168
168
|
export async function init(
|
|
169
169
|
lucid: LucidEvolution,
|
|
170
170
|
defaultInitialAssets: InitialAssetParam[],
|
|
171
|
-
currentSlot: number,
|
|
172
171
|
mkPythBasedAssets: (
|
|
173
172
|
pythStateNft: AssetClass,
|
|
174
173
|
) => InitialAssetParam[] = () => [],
|
|
@@ -527,7 +526,6 @@ export async function init(
|
|
|
527
526
|
stabilityPoolToken,
|
|
528
527
|
asset,
|
|
529
528
|
pythConfig,
|
|
530
|
-
currentSlot,
|
|
531
529
|
);
|
|
532
530
|
|
|
533
531
|
assetInfos.push(assetInfo);
|
|
@@ -346,7 +346,6 @@ export async function handleOracleForCollateralAsset(
|
|
|
346
346
|
iasset: InitialAssetParam,
|
|
347
347
|
collateralAsset: InitialCollateralAssetParam,
|
|
348
348
|
pythConfig: PythConfig,
|
|
349
|
-
currentSlot: number,
|
|
350
349
|
): Promise<{ info: IAssetPriceInfo; params: PriceOracleParams | undefined }> {
|
|
351
350
|
return match(collateralAsset.priceOracle)
|
|
352
351
|
.returnType<
|
|
@@ -366,7 +365,6 @@ export async function handleOracleForCollateralAsset(
|
|
|
366
365
|
val.tokenName,
|
|
367
366
|
val.startPrice,
|
|
368
367
|
priceOracleParams,
|
|
369
|
-
currentSlot,
|
|
370
368
|
);
|
|
371
369
|
await runAndAwaitTxBuilder(lucid, priceOracleStartTx);
|
|
372
370
|
|
|
@@ -403,7 +401,6 @@ export async function initializeAsset(
|
|
|
403
401
|
stabilityPoolToken: AssetClass,
|
|
404
402
|
asset: InitialAssetParam,
|
|
405
403
|
pythConfig: PythConfig,
|
|
406
|
-
currentSlot: number,
|
|
407
404
|
): Promise<AssetInfo> {
|
|
408
405
|
const iassetName = fromHex(fromText(asset.name));
|
|
409
406
|
|
|
@@ -431,7 +428,6 @@ export async function initializeAsset(
|
|
|
431
428
|
asset,
|
|
432
429
|
collateralAsset,
|
|
433
430
|
pythConfig,
|
|
434
|
-
currentSlot,
|
|
435
431
|
);
|
|
436
432
|
|
|
437
433
|
const collateralAssetContent: CollateralAssetContent = {
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
addAssets,
|
|
9
9
|
Assets,
|
|
10
10
|
fromHex,
|
|
11
|
-
slotToUnixTime,
|
|
12
11
|
sortUTxOs,
|
|
13
12
|
getInputIndices,
|
|
14
13
|
} from '@lucid-evolution/lucid';
|
|
@@ -58,10 +57,8 @@ export async function batchCollectInterest(
|
|
|
58
57
|
cdpOutRefs: OutRef[],
|
|
59
58
|
params: SystemParams,
|
|
60
59
|
lucid: LucidEvolution,
|
|
61
|
-
currentSlot: number,
|
|
62
60
|
): Promise<TxBuilder> {
|
|
63
|
-
const
|
|
64
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
61
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
65
62
|
|
|
66
63
|
const interestCollectionRefScriptUtxo = matchSingle(
|
|
67
64
|
await lucid.utxosByOutRef([
|
|
@@ -183,7 +180,7 @@ export async function batchCollectInterest(
|
|
|
183
180
|
false,
|
|
184
181
|
);
|
|
185
182
|
|
|
186
|
-
const validateFrom = slotToUnixTime(
|
|
183
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
187
184
|
const validateTo = validateFrom + Number(params.cdpParams.biasTime);
|
|
188
185
|
|
|
189
186
|
const tx = lucid
|
|
@@ -26,6 +26,10 @@ export function calculateUnitaryInterestSinceOracleLastUpdated(
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function calculateAccruedInterest(
|
|
29
|
+
/**
|
|
30
|
+
* Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
|
|
31
|
+
* Otherwise, the unix timestamp should suffice, but might not be 100% precise as on-chain.
|
|
32
|
+
*/
|
|
29
33
|
now: bigint,
|
|
30
34
|
unitaryInterestSnapshot: bigint,
|
|
31
35
|
mintedAmount: bigint,
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
fromText,
|
|
4
4
|
LucidEvolution,
|
|
5
5
|
OutRef,
|
|
6
|
-
slotToUnixTime,
|
|
7
6
|
toUnit,
|
|
8
7
|
TxBuilder,
|
|
9
8
|
UTxO,
|
|
@@ -95,7 +94,6 @@ export async function feedInterestOracle(
|
|
|
95
94
|
params: InterestOracleParams,
|
|
96
95
|
newInterestRate: bigint,
|
|
97
96
|
lucid: LucidEvolution,
|
|
98
|
-
currentSlot: number,
|
|
99
97
|
assetClass?: AssetClass,
|
|
100
98
|
utxo?: UTxO,
|
|
101
99
|
scriptRef?: UTxO,
|
|
@@ -106,8 +104,7 @@ export async function feedInterestOracle(
|
|
|
106
104
|
utxo = await findInterestOracle(lucid, assetClass);
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
const
|
|
110
|
-
const now = BigInt(slotToUnixTime(network, currentSlot));
|
|
107
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
111
108
|
|
|
112
109
|
const tx = lucid.newTx();
|
|
113
110
|
const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo!));
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Network,
|
|
3
|
-
slotToUnixTime,
|
|
4
|
-
unixTimeToSlot,
|
|
5
|
-
} from '@lucid-evolution/lucid';
|
|
1
|
+
import { LucidEvolution } from '@lucid-evolution/lucid';
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Calculates the validity range based on the oracle expiration,
|
|
9
5
|
* and caps the upper bound when necessary.
|
|
10
6
|
*/
|
|
11
7
|
export function oracleExpirationAwareValidity(
|
|
12
|
-
|
|
8
|
+
lucid: LucidEvolution,
|
|
13
9
|
biasTime: number,
|
|
14
10
|
oracleExpiration: number,
|
|
15
|
-
network: Network,
|
|
16
11
|
): {
|
|
17
12
|
validFrom: number;
|
|
18
13
|
validTo: number;
|
|
19
14
|
} {
|
|
20
|
-
const validateFrom = slotToUnixTime(
|
|
15
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
21
16
|
const defaultValidateTo = validateFrom + biasTime;
|
|
22
17
|
/// Take the oracle expiration time - 1 slot which is the last acceptable non-expired valid_to time
|
|
23
18
|
/// for the current oracle.
|
|
24
|
-
const cappedValidateTo = slotToUnixTime(
|
|
25
|
-
|
|
26
|
-
unixTimeToSlot(network, oracleExpiration) - 1,
|
|
19
|
+
const cappedValidateTo = lucid.slotToUnixTime(
|
|
20
|
+
lucid.unixTimeToSlot(oracleExpiration) - 1,
|
|
27
21
|
);
|
|
28
22
|
const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
|
|
29
23
|
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
fromText,
|
|
6
6
|
LucidEvolution,
|
|
7
7
|
OutRef,
|
|
8
|
-
slotToUnixTime,
|
|
9
8
|
TxBuilder,
|
|
10
9
|
validatorToAddress,
|
|
11
10
|
} from '@lucid-evolution/lucid';
|
|
@@ -28,12 +27,10 @@ export async function startPriceOracleTx(
|
|
|
28
27
|
assetName: string,
|
|
29
28
|
startPrice: Rational,
|
|
30
29
|
oracleParams: PriceOracleParams,
|
|
31
|
-
currentSlot: number,
|
|
32
30
|
refOutRef?: OutRef,
|
|
33
31
|
auxiliaryData?: Core.Data.Data,
|
|
34
32
|
): Promise<[TxBuilder, AssetClass]> {
|
|
35
|
-
const
|
|
36
|
-
const now = BigInt(slotToUnixTime(network, currentSlot));
|
|
33
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
37
34
|
|
|
38
35
|
if (!refOutRef) {
|
|
39
36
|
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
@@ -79,11 +76,9 @@ export async function feedPriceOracleTx(
|
|
|
79
76
|
oracleOref: OutRef,
|
|
80
77
|
newPrice: Rational,
|
|
81
78
|
oracleParams: PriceOracleParams,
|
|
82
|
-
currentSlot: number,
|
|
83
79
|
auxiliaryData?: Core.Data.Data,
|
|
84
80
|
): Promise<TxBuilder> {
|
|
85
|
-
const
|
|
86
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
81
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
87
82
|
|
|
88
83
|
const priceOracleUtxo = matchSingle(
|
|
89
84
|
await lucid.utxosByOutRef([oracleOref]),
|
|
@@ -149,7 +149,6 @@ export async function redeemRob(
|
|
|
149
149
|
collateralAssetOutRef: OutRef,
|
|
150
150
|
lucid: LucidEvolution,
|
|
151
151
|
sysParams: SystemParams,
|
|
152
|
-
currentSlot: number,
|
|
153
152
|
pythMessage: string | undefined = undefined,
|
|
154
153
|
pythStateOutRef: OutRef | undefined = undefined,
|
|
155
154
|
): Promise<TxBuilder> {
|
|
@@ -208,7 +207,6 @@ export async function redeemRob(
|
|
|
208
207
|
pythMessage,
|
|
209
208
|
sysParams.pythConfig,
|
|
210
209
|
sysParams.cdpParams.biasTime,
|
|
211
|
-
currentSlot,
|
|
212
210
|
lucid,
|
|
213
211
|
tx,
|
|
214
212
|
);
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
OutRef,
|
|
5
5
|
UTxO,
|
|
6
6
|
addAssets,
|
|
7
|
-
slotToUnixTime,
|
|
8
7
|
Data,
|
|
9
8
|
fromHex,
|
|
10
9
|
getInputIndices,
|
|
@@ -65,12 +64,11 @@ export async function leverageCdpWithRob(
|
|
|
65
64
|
sysParams: SystemParams,
|
|
66
65
|
lucid: LucidEvolution,
|
|
67
66
|
allRobs: [UTxO, RobDatum][],
|
|
68
|
-
currentSlot: number,
|
|
69
67
|
pythMessage: string | undefined = undefined,
|
|
70
68
|
pythStateOref: OutRef | undefined = undefined,
|
|
71
69
|
): Promise<TxBuilder> {
|
|
72
70
|
const network = lucid.config().network!;
|
|
73
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
71
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
74
72
|
|
|
75
73
|
const [pkh, skh] = await addrDetails(lucid);
|
|
76
74
|
|
|
@@ -306,7 +304,6 @@ export async function leverageCdpWithRob(
|
|
|
306
304
|
pythMessage,
|
|
307
305
|
sysParams.pythConfig,
|
|
308
306
|
sysParams.cdpCreatorParams.biasTime,
|
|
309
|
-
currentSlot,
|
|
310
307
|
lucid,
|
|
311
308
|
tx,
|
|
312
309
|
);
|