@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
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
getInputIndices,
|
|
6
6
|
LucidEvolution,
|
|
7
7
|
OutRef,
|
|
8
|
-
slotToUnixTime,
|
|
9
8
|
toHex,
|
|
10
9
|
TxBuilder,
|
|
11
10
|
} from '@lucid-evolution/lucid';
|
|
@@ -55,12 +54,9 @@ export async function testRedeemRob(
|
|
|
55
54
|
iassetOutRef: OutRef,
|
|
56
55
|
collateralAssetOutRef: OutRef,
|
|
57
56
|
lucid: LucidEvolution,
|
|
58
|
-
currentSlot: number,
|
|
59
57
|
sysParams: SystemParams,
|
|
60
58
|
pythMessage?: string,
|
|
61
59
|
): Promise<TxBuilder> {
|
|
62
|
-
const network = lucid.config().network!;
|
|
63
|
-
|
|
64
60
|
const robScriptRefUtxo = matchSingle(
|
|
65
61
|
await lucid.utxosByOutRef([
|
|
66
62
|
fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef),
|
|
@@ -131,7 +127,7 @@ export async function testRedeemRob(
|
|
|
131
127
|
|
|
132
128
|
const transaction = lucid
|
|
133
129
|
.newTx()
|
|
134
|
-
.validTo(slotToUnixTime(
|
|
130
|
+
.validTo(lucid.slotToUnixTime(lucid.currentSlot()))
|
|
135
131
|
.readFrom(allRefInputs)
|
|
136
132
|
.compose(tx);
|
|
137
133
|
|
|
@@ -154,10 +150,9 @@ export async function redeemWithCdpCreate(
|
|
|
154
150
|
interestOracleOref: OutRef,
|
|
155
151
|
treasuryOref: OutRef,
|
|
156
152
|
lucid: LucidEvolution,
|
|
157
|
-
currentSlot: number,
|
|
158
153
|
): Promise<TxBuilder> {
|
|
159
154
|
const network = lucid.config().network!;
|
|
160
|
-
const currentTime = BigInt(slotToUnixTime(
|
|
155
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
161
156
|
|
|
162
157
|
const [pkh, skh] = await addrDetails(lucid);
|
|
163
158
|
|
|
@@ -301,10 +296,9 @@ export async function redeemWithCdpCreate(
|
|
|
301
296
|
);
|
|
302
297
|
|
|
303
298
|
const txValidity = oracleExpirationAwareValidity(
|
|
304
|
-
|
|
299
|
+
lucid,
|
|
305
300
|
Number(sysParams.cdpCreatorParams.biasTime),
|
|
306
301
|
Number(priceOracleDatum.expirationTime),
|
|
307
|
-
network,
|
|
308
302
|
);
|
|
309
303
|
|
|
310
304
|
tx.validFrom(txValidity.validFrom)
|
|
@@ -400,10 +394,8 @@ export async function redeemWithCdpClose(
|
|
|
400
394
|
interestCollectorOref: OutRef,
|
|
401
395
|
sysParams: SystemParams,
|
|
402
396
|
lucid: LucidEvolution,
|
|
403
|
-
currentSlot: number,
|
|
404
397
|
): Promise<TxBuilder> {
|
|
405
|
-
const
|
|
406
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
398
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
407
399
|
|
|
408
400
|
const robScriptRefUtxo = matchSingle(
|
|
409
401
|
await lucid.utxosByOutRef([
|
|
@@ -539,7 +531,7 @@ export async function redeemWithCdpClose(
|
|
|
539
531
|
{ OracleRefInputIdx: refInputIdxs[2] },
|
|
540
532
|
);
|
|
541
533
|
|
|
542
|
-
const validateFrom = slotToUnixTime(
|
|
534
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
543
535
|
const validateTo = Math.min(
|
|
544
536
|
Number(BigInt(validateFrom) + sysParams.cdpParams.biasTime / 2n),
|
|
545
537
|
Number(priceOracleDatum.expirationTime - 1n * 1000n),
|
|
@@ -610,12 +602,10 @@ export async function redeemWithCdpAdjust(
|
|
|
610
602
|
interestOracleOref: OutRef,
|
|
611
603
|
treasuryOref: OutRef,
|
|
612
604
|
interestCollectorOref: OutRef,
|
|
613
|
-
currentSlot: number,
|
|
614
605
|
lucid: LucidEvolution,
|
|
615
606
|
sysParams: SystemParams,
|
|
616
607
|
): Promise<TxBuilder> {
|
|
617
|
-
const
|
|
618
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
608
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
619
609
|
|
|
620
610
|
const robScriptRefUtxo = matchSingle(
|
|
621
611
|
await lucid.utxosByOutRef([
|
|
@@ -764,10 +754,9 @@ export async function redeemWithCdpAdjust(
|
|
|
764
754
|
);
|
|
765
755
|
|
|
766
756
|
const txValidity = oracleExpirationAwareValidity(
|
|
767
|
-
|
|
757
|
+
lucid,
|
|
768
758
|
Number(sysParams.cdpCreatorParams.biasTime),
|
|
769
759
|
Number(priceOracleDatum.expirationTime),
|
|
770
|
-
network,
|
|
771
760
|
);
|
|
772
761
|
|
|
773
762
|
tx.validFrom(txValidity.validFrom)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
2
2
|
import {
|
|
3
|
+
fromHex,
|
|
4
|
+
fromText,
|
|
3
5
|
LucidEvolution,
|
|
4
6
|
TxBuilder,
|
|
5
|
-
unixTimeToSlot,
|
|
6
7
|
} from '@lucid-evolution/lucid';
|
|
7
8
|
import {
|
|
8
9
|
addrDetails,
|
|
@@ -15,16 +16,15 @@ import {
|
|
|
15
16
|
openCdp,
|
|
16
17
|
processSpRequest,
|
|
17
18
|
SystemParams,
|
|
19
|
+
findStabilityPool,
|
|
20
|
+
findStabilityPoolAccount,
|
|
21
|
+
findE2s2sSnapshots,
|
|
18
22
|
} from '../../src';
|
|
19
23
|
import {
|
|
20
24
|
findAllNecessaryOrefs,
|
|
21
25
|
findPriceOracleFromCollateralAsset,
|
|
22
26
|
} from '../cdp/cdp-queries';
|
|
23
|
-
|
|
24
|
-
findE2s2sSnapshots,
|
|
25
|
-
findStabilityPool,
|
|
26
|
-
findStabilityPoolAccount,
|
|
27
|
-
} from '../queries/stability-pool-queries';
|
|
27
|
+
|
|
28
28
|
import { LucidContext, runAndAwaitTx } from '../test-helpers';
|
|
29
29
|
import { expect } from 'vitest';
|
|
30
30
|
import { findIAsset } from '../queries/iasset-queries';
|
|
@@ -90,7 +90,6 @@ export async function runOpenCdpAndCreateSPAccount(
|
|
|
90
90
|
orefs.interestOracleUtxo,
|
|
91
91
|
orefs.treasuryUtxo,
|
|
92
92
|
context.lucid,
|
|
93
|
-
context.emulator.slot,
|
|
94
93
|
),
|
|
95
94
|
);
|
|
96
95
|
|
|
@@ -113,20 +112,19 @@ async function waitForAccountCooldown(
|
|
|
113
112
|
context.lucid,
|
|
114
113
|
sysParams,
|
|
115
114
|
pkh,
|
|
116
|
-
asset,
|
|
115
|
+
fromHex(fromText(asset)),
|
|
117
116
|
);
|
|
118
117
|
|
|
119
118
|
if (accountUtxo.datum.lastRequestProcessingTime !== 0n) {
|
|
120
|
-
const targetSlot = unixTimeToSlot(
|
|
121
|
-
context.lucid.config().network!,
|
|
119
|
+
const targetSlot = context.lucid.unixTimeToSlot(
|
|
122
120
|
Number(accountUtxo.datum.lastRequestProcessingTime) +
|
|
123
121
|
sysParams.stabilityPoolParams.accountProcessingCooldownMs,
|
|
124
122
|
);
|
|
125
123
|
|
|
126
|
-
if (targetSlot > context.
|
|
127
|
-
expect(targetSlot).toBeGreaterThan(context.
|
|
124
|
+
if (targetSlot > context.lucid.currentSlot()) {
|
|
125
|
+
expect(targetSlot).toBeGreaterThan(context.lucid.currentSlot());
|
|
128
126
|
|
|
129
|
-
context.emulator.awaitSlot(targetSlot - context.
|
|
127
|
+
context.emulator.awaitSlot(targetSlot - context.lucid.currentSlot() + 2);
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
130
|
}
|
|
@@ -138,7 +136,11 @@ export async function runProcessSpRequest(
|
|
|
138
136
|
// Request owner
|
|
139
137
|
pkh: string,
|
|
140
138
|
): Promise<TxBuilder> {
|
|
141
|
-
const sp = await findStabilityPool(
|
|
139
|
+
const sp = await findStabilityPool(
|
|
140
|
+
context.lucid,
|
|
141
|
+
sysParams,
|
|
142
|
+
fromHex(fromText(asset)),
|
|
143
|
+
);
|
|
142
144
|
|
|
143
145
|
const ia = await findIAsset(
|
|
144
146
|
context.lucid,
|
|
@@ -151,7 +153,7 @@ export async function runProcessSpRequest(
|
|
|
151
153
|
context.lucid,
|
|
152
154
|
sysParams,
|
|
153
155
|
pkh,
|
|
154
|
-
asset,
|
|
156
|
+
fromHex(fromText(asset)),
|
|
155
157
|
);
|
|
156
158
|
|
|
157
159
|
await waitForAccountCooldown(context, sysParams, asset, pkh);
|
|
@@ -160,12 +162,15 @@ export async function runProcessSpRequest(
|
|
|
160
162
|
sp.utxo,
|
|
161
163
|
accountUtxo.utxo,
|
|
162
164
|
ia.utxo,
|
|
163
|
-
(
|
|
164
|
-
(
|
|
165
|
-
|
|
165
|
+
(
|
|
166
|
+
await findE2s2sSnapshots(
|
|
167
|
+
context.lucid,
|
|
168
|
+
sysParams,
|
|
169
|
+
fromHex(fromText(asset)),
|
|
170
|
+
)
|
|
171
|
+
).map((res) => res.utxo),
|
|
166
172
|
sysParams,
|
|
167
173
|
context.lucid,
|
|
168
|
-
context.emulator.slot,
|
|
169
174
|
);
|
|
170
175
|
}
|
|
171
176
|
|
|
@@ -181,7 +186,7 @@ export async function runCreateAdjustRequest(
|
|
|
181
186
|
lucid,
|
|
182
187
|
sysParams,
|
|
183
188
|
pkh.hash,
|
|
184
|
-
asset,
|
|
189
|
+
fromHex(fromText(asset)),
|
|
185
190
|
);
|
|
186
191
|
|
|
187
192
|
return requestSpAccountAdjustment(
|
|
@@ -203,7 +208,7 @@ export async function runCreateCloseRequest(
|
|
|
203
208
|
lucid,
|
|
204
209
|
sysParams,
|
|
205
210
|
pkh.hash,
|
|
206
|
-
asset,
|
|
211
|
+
fromHex(fromText(asset)),
|
|
207
212
|
);
|
|
208
213
|
|
|
209
214
|
return requestSpAccountClosure(accountUtxo.utxo, sysParams, lucid);
|
|
@@ -214,7 +219,11 @@ export async function runCreateE2s2sSnapshots(
|
|
|
214
219
|
sysParams: SystemParams,
|
|
215
220
|
asset: string,
|
|
216
221
|
): Promise<TxBuilder> {
|
|
217
|
-
const spUtxo = await findStabilityPool(
|
|
222
|
+
const spUtxo = await findStabilityPool(
|
|
223
|
+
context.lucid,
|
|
224
|
+
sysParams,
|
|
225
|
+
fromHex(fromText(asset)),
|
|
226
|
+
);
|
|
218
227
|
|
|
219
228
|
return createE2s2sSnapshots(spUtxo.utxo, sysParams, context.lucid);
|
|
220
229
|
}
|