@indigo-labs/indigo-sdk 0.1.1 → 0.1.3
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/.github/workflows/ci.yml +62 -0
- package/.github/workflows/test.yml +44 -0
- package/.husky/pre-commit +1 -0
- package/.prettierrc +1 -1
- package/README.md +52 -7
- package/dist/index.d.mts +1064 -182
- package/dist/index.d.ts +1064 -182
- package/dist/index.js +2565 -561
- package/dist/index.mjs +2546 -593
- package/eslint.config.mjs +35 -0
- package/package.json +61 -43
- package/src/contracts/cdp.ts +208 -359
- package/src/contracts/collector.ts +13 -6
- package/src/contracts/gov.ts +1 -58
- package/src/contracts/interest-oracle.ts +139 -39
- package/src/contracts/lrp.ts +223 -0
- package/src/contracts/one-shot.ts +67 -0
- package/src/contracts/stability-pool.ts +684 -0
- package/src/contracts/staking.ts +348 -0
- package/src/contracts/treasury.ts +30 -13
- package/src/helpers/asset-helpers.ts +51 -22
- package/src/helpers/helper-txs.ts +30 -0
- package/src/helpers/helpers.ts +29 -8
- package/src/helpers/indigo-helpers.ts +19 -0
- package/src/helpers/interest-oracle.ts +57 -0
- package/src/helpers/lucid-utils.ts +62 -16
- package/src/helpers/price-oracle-helpers.ts +36 -0
- package/src/helpers/stability-pool-helpers.ts +207 -0
- package/src/helpers/staking-helpers.ts +94 -0
- package/src/helpers/time-helpers.ts +4 -3
- package/src/helpers/value-helpers.ts +16 -0
- package/src/index.ts +15 -4
- package/src/scripts/always-fail-validator.ts +7 -0
- package/src/scripts/auth-token-policy.ts +23 -0
- package/src/scripts/cdp-creator-validator.ts +46 -2
- package/src/scripts/collector-validator.ts +2 -2
- package/src/scripts/execute-validator.ts +52 -0
- package/src/scripts/gov-validator.ts +44 -0
- package/src/scripts/iasset-policy.ts +22 -0
- package/src/scripts/interest-oracle-validator.ts +18 -3
- package/src/scripts/lrp-validator.ts +23 -0
- package/src/scripts/one-shot-policy.ts +62 -0
- package/src/scripts/poll-manager-validator.ts +52 -0
- package/src/scripts/poll-shard-validator.ts +47 -0
- package/src/scripts/price-oracle-validator.ts +26 -0
- package/src/scripts/stability-pool-validator.ts +60 -0
- package/src/scripts/staking-validator.ts +8 -0
- package/src/scripts/version-record-policy.ts +26 -0
- package/src/scripts/version-registry.ts +15 -0
- package/src/types/generic.ts +99 -6
- package/src/types/indigo/cdp-creator.ts +46 -0
- package/src/types/indigo/cdp.ts +86 -31
- package/src/types/indigo/execute.ts +21 -0
- package/src/types/indigo/gov.ts +50 -20
- package/src/types/indigo/interest-oracle.ts +55 -5
- package/src/types/indigo/lrp.ts +54 -0
- package/src/types/indigo/poll-manager.ts +21 -0
- package/src/types/indigo/poll-shard.ts +16 -0
- package/src/types/indigo/price-oracle.ts +38 -4
- package/src/types/indigo/stability-pool.ts +233 -0
- package/src/types/indigo/staking.ts +99 -0
- package/src/types/indigo/version-record.ts +17 -0
- package/src/types/on-chain-decimal.ts +23 -0
- package/src/types/one-shot.ts +22 -0
- package/src/types/system-params.ts +95 -77
- package/tests/data/system-params.json +972 -972
- package/tests/datums.test.ts +279 -44
- package/tests/endpoints/initialize.ts +1013 -0
- package/tests/hash-checks.test.ts +71 -15
- package/tests/indigo-test-helpers.ts +115 -0
- package/tests/initialize.test.ts +27 -0
- package/tests/interest-calculations.test.ts +110 -133
- package/tests/interest-oracle.test.ts +90 -0
- package/tests/lrp.test.ts +149 -0
- package/tests/queries/governance-queries.ts +31 -0
- package/tests/queries/iasset-queries.ts +39 -0
- package/tests/queries/interest-oracle-queries.ts +13 -0
- package/tests/queries/lrp-queries.ts +39 -0
- package/tests/queries/price-oracle-queries.ts +27 -0
- package/tests/queries/stability-pool-queries.ts +75 -0
- package/tests/queries/staking-queries.ts +43 -0
- package/tests/stability-pool.test.ts +364 -0
- package/tests/staking.test.ts +105 -0
- package/tests/test-helpers.ts +38 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +8 -27
- package/vitest.config.ts +9 -0
- package/babel.config.cjs +0 -13
- package/jest.config.js +0 -13
- package/src/contracts/cdp-creator.ts +0 -86
- package/src/contracts/price-oracle.ts +0 -24
- package/src/helpers/cdp-helpers.ts +0 -9
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { beforeEach, test, afterEach } from 'vitest';
|
|
2
|
+
import { LucidContext, runAndAwaitTx } from './test-helpers';
|
|
3
|
+
import { fromText, Lucid } from '@lucid-evolution/lucid';
|
|
4
|
+
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
|
+
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
|
+
import { init } from './endpoints/initialize';
|
|
7
|
+
import { addrDetails, CDPContract, StabilityPoolContract } from '../src';
|
|
8
|
+
import {
|
|
9
|
+
findStabilityPool,
|
|
10
|
+
findStabilityPoolAccount,
|
|
11
|
+
} from './queries/stability-pool-queries';
|
|
12
|
+
import { findIAsset } from './queries/iasset-queries';
|
|
13
|
+
import { findGov } from './queries/governance-queries';
|
|
14
|
+
|
|
15
|
+
let originalDateNow: () => number;
|
|
16
|
+
|
|
17
|
+
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
18
|
+
context.users = {
|
|
19
|
+
admin: generateEmulatorAccount({
|
|
20
|
+
lovelace: BigInt(100_000_000_000_000),
|
|
21
|
+
}),
|
|
22
|
+
user: generateEmulatorAccount({
|
|
23
|
+
lovelace: BigInt(100_000_000_000_000),
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
context.emulator = new Emulator([context.users.admin, context.users.user]);
|
|
28
|
+
|
|
29
|
+
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
30
|
+
|
|
31
|
+
originalDateNow = Date.now;
|
|
32
|
+
Date.now = () => context.emulator.now();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
Date.now = originalDateNow;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test<LucidContext>('Stability Pool - Create Account', async ({
|
|
40
|
+
lucid,
|
|
41
|
+
users,
|
|
42
|
+
}: LucidContext) => {
|
|
43
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
44
|
+
const systemParams = await init(lucid);
|
|
45
|
+
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
46
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
47
|
+
|
|
48
|
+
await runAndAwaitTx(
|
|
49
|
+
lucid,
|
|
50
|
+
CDPContract.openPosition('iUSD', 1_000_000_000n, 20n, systemParams, lucid),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
await runAndAwaitTx(
|
|
54
|
+
lucid,
|
|
55
|
+
StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const stabilityPoolUtxo = await findStabilityPool(
|
|
59
|
+
lucid,
|
|
60
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
61
|
+
{
|
|
62
|
+
currencySymbol:
|
|
63
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
|
|
64
|
+
tokenName: fromText(
|
|
65
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
66
|
+
),
|
|
67
|
+
},
|
|
68
|
+
'iUSD',
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const accountUtxo = await findStabilityPoolAccount(
|
|
72
|
+
lucid,
|
|
73
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
74
|
+
pkh.hash,
|
|
75
|
+
'iUSD',
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const assetUtxo = await findIAsset(
|
|
79
|
+
lucid,
|
|
80
|
+
systemParams.validatorHashes.cdpHash,
|
|
81
|
+
{
|
|
82
|
+
currencySymbol:
|
|
83
|
+
systemParams.cdpParams.iAssetAuthToken[0].unCurrencySymbol,
|
|
84
|
+
tokenName: fromText(
|
|
85
|
+
systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
|
|
86
|
+
),
|
|
87
|
+
},
|
|
88
|
+
'iUSD',
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
|
|
92
|
+
currencySymbol: systemParams.govParams.govNFT[0].unCurrencySymbol,
|
|
93
|
+
tokenName: fromText(systemParams.govParams.govNFT[1].unTokenName),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
97
|
+
|
|
98
|
+
await runAndAwaitTx(
|
|
99
|
+
lucid,
|
|
100
|
+
StabilityPoolContract.processRequest(
|
|
101
|
+
'iUSD',
|
|
102
|
+
stabilityPoolUtxo,
|
|
103
|
+
accountUtxo,
|
|
104
|
+
govUtxo,
|
|
105
|
+
assetUtxo,
|
|
106
|
+
undefined,
|
|
107
|
+
systemParams,
|
|
108
|
+
lucid,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test<LucidContext>('Stability Pool - Adjust Account', async ({
|
|
114
|
+
lucid,
|
|
115
|
+
users,
|
|
116
|
+
}: LucidContext) => {
|
|
117
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
118
|
+
const systemParams = await init(lucid);
|
|
119
|
+
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
120
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
121
|
+
|
|
122
|
+
await runAndAwaitTx(
|
|
123
|
+
lucid,
|
|
124
|
+
CDPContract.openPosition('iUSD', 1_000_000_000n, 20n, systemParams, lucid),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
await runAndAwaitTx(
|
|
128
|
+
lucid,
|
|
129
|
+
StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
133
|
+
|
|
134
|
+
let stabilityPoolUtxo = await findStabilityPool(
|
|
135
|
+
lucid,
|
|
136
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
137
|
+
{
|
|
138
|
+
currencySymbol:
|
|
139
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
|
|
140
|
+
tokenName: fromText(
|
|
141
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
142
|
+
),
|
|
143
|
+
},
|
|
144
|
+
'iUSD',
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
let accountUtxo = await findStabilityPoolAccount(
|
|
148
|
+
lucid,
|
|
149
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
150
|
+
pkh.hash,
|
|
151
|
+
'iUSD',
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const assetUtxo = await findIAsset(
|
|
155
|
+
lucid,
|
|
156
|
+
systemParams.validatorHashes.cdpHash,
|
|
157
|
+
{
|
|
158
|
+
currencySymbol:
|
|
159
|
+
systemParams.cdpParams.iAssetAuthToken[0].unCurrencySymbol,
|
|
160
|
+
tokenName: fromText(
|
|
161
|
+
systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
|
|
162
|
+
),
|
|
163
|
+
},
|
|
164
|
+
'iUSD',
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
|
|
168
|
+
currencySymbol: systemParams.govParams.govNFT[0].unCurrencySymbol,
|
|
169
|
+
tokenName: fromText(systemParams.govParams.govNFT[1].unTokenName),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await runAndAwaitTx(
|
|
173
|
+
lucid,
|
|
174
|
+
StabilityPoolContract.processRequest(
|
|
175
|
+
'iUSD',
|
|
176
|
+
stabilityPoolUtxo,
|
|
177
|
+
accountUtxo,
|
|
178
|
+
govUtxo,
|
|
179
|
+
assetUtxo,
|
|
180
|
+
undefined,
|
|
181
|
+
systemParams,
|
|
182
|
+
lucid,
|
|
183
|
+
),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
187
|
+
|
|
188
|
+
stabilityPoolUtxo = await findStabilityPool(
|
|
189
|
+
lucid,
|
|
190
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
191
|
+
{
|
|
192
|
+
currencySymbol:
|
|
193
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
|
|
194
|
+
tokenName: fromText(
|
|
195
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
196
|
+
),
|
|
197
|
+
},
|
|
198
|
+
'iUSD',
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
accountUtxo = await findStabilityPoolAccount(
|
|
202
|
+
lucid,
|
|
203
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
204
|
+
pkh.hash,
|
|
205
|
+
'iUSD',
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
await runAndAwaitTx(
|
|
209
|
+
lucid,
|
|
210
|
+
StabilityPoolContract.adjustAccount(
|
|
211
|
+
'iUSD',
|
|
212
|
+
10n,
|
|
213
|
+
accountUtxo,
|
|
214
|
+
systemParams,
|
|
215
|
+
lucid,
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
219
|
+
|
|
220
|
+
accountUtxo = await findStabilityPoolAccount(
|
|
221
|
+
lucid,
|
|
222
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
223
|
+
pkh.hash,
|
|
224
|
+
'iUSD',
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
await runAndAwaitTx(
|
|
228
|
+
lucid,
|
|
229
|
+
StabilityPoolContract.processRequest(
|
|
230
|
+
'iUSD',
|
|
231
|
+
stabilityPoolUtxo,
|
|
232
|
+
accountUtxo,
|
|
233
|
+
govUtxo,
|
|
234
|
+
assetUtxo,
|
|
235
|
+
undefined,
|
|
236
|
+
systemParams,
|
|
237
|
+
lucid,
|
|
238
|
+
),
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test<LucidContext>('Stability Pool - Close Account', async ({
|
|
243
|
+
lucid,
|
|
244
|
+
users,
|
|
245
|
+
emulator,
|
|
246
|
+
}: LucidContext) => {
|
|
247
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
248
|
+
const systemParams = await init(lucid, emulator.now());
|
|
249
|
+
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
250
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
251
|
+
|
|
252
|
+
await runAndAwaitTx(
|
|
253
|
+
lucid,
|
|
254
|
+
CDPContract.openPosition('iUSD', 1_000_000_000n, 20n, systemParams, lucid),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
await runAndAwaitTx(
|
|
258
|
+
lucid,
|
|
259
|
+
StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
263
|
+
|
|
264
|
+
let stabilityPoolUtxo = await findStabilityPool(
|
|
265
|
+
lucid,
|
|
266
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
267
|
+
{
|
|
268
|
+
currencySymbol:
|
|
269
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
|
|
270
|
+
tokenName: fromText(
|
|
271
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
272
|
+
),
|
|
273
|
+
},
|
|
274
|
+
'iUSD',
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
let accountUtxo = await findStabilityPoolAccount(
|
|
278
|
+
lucid,
|
|
279
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
280
|
+
pkh.hash,
|
|
281
|
+
'iUSD',
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const assetUtxo = await findIAsset(
|
|
285
|
+
lucid,
|
|
286
|
+
systemParams.validatorHashes.cdpHash,
|
|
287
|
+
{
|
|
288
|
+
currencySymbol:
|
|
289
|
+
systemParams.cdpParams.iAssetAuthToken[0].unCurrencySymbol,
|
|
290
|
+
tokenName: fromText(
|
|
291
|
+
systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
|
|
292
|
+
),
|
|
293
|
+
},
|
|
294
|
+
'iUSD',
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
|
|
298
|
+
currencySymbol: systemParams.govParams.govNFT[0].unCurrencySymbol,
|
|
299
|
+
tokenName: fromText(systemParams.govParams.govNFT[1].unTokenName),
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
await runAndAwaitTx(
|
|
303
|
+
lucid,
|
|
304
|
+
StabilityPoolContract.processRequest(
|
|
305
|
+
'iUSD',
|
|
306
|
+
stabilityPoolUtxo,
|
|
307
|
+
accountUtxo,
|
|
308
|
+
govUtxo,
|
|
309
|
+
assetUtxo,
|
|
310
|
+
undefined,
|
|
311
|
+
systemParams,
|
|
312
|
+
lucid,
|
|
313
|
+
),
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
317
|
+
|
|
318
|
+
stabilityPoolUtxo = await findStabilityPool(
|
|
319
|
+
lucid,
|
|
320
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
321
|
+
{
|
|
322
|
+
currencySymbol:
|
|
323
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
|
|
324
|
+
tokenName: fromText(
|
|
325
|
+
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
326
|
+
),
|
|
327
|
+
},
|
|
328
|
+
'iUSD',
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
accountUtxo = await findStabilityPoolAccount(
|
|
332
|
+
lucid,
|
|
333
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
334
|
+
pkh.hash,
|
|
335
|
+
'iUSD',
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
await runAndAwaitTx(
|
|
339
|
+
lucid,
|
|
340
|
+
StabilityPoolContract.closeAccount(accountUtxo, systemParams, lucid),
|
|
341
|
+
);
|
|
342
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
343
|
+
|
|
344
|
+
accountUtxo = await findStabilityPoolAccount(
|
|
345
|
+
lucid,
|
|
346
|
+
systemParams.validatorHashes.stabilityPoolHash,
|
|
347
|
+
pkh.hash,
|
|
348
|
+
'iUSD',
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
await runAndAwaitTx(
|
|
352
|
+
lucid,
|
|
353
|
+
StabilityPoolContract.processRequest(
|
|
354
|
+
'iUSD',
|
|
355
|
+
stabilityPoolUtxo,
|
|
356
|
+
accountUtxo,
|
|
357
|
+
govUtxo,
|
|
358
|
+
assetUtxo,
|
|
359
|
+
undefined,
|
|
360
|
+
systemParams,
|
|
361
|
+
lucid,
|
|
362
|
+
),
|
|
363
|
+
);
|
|
364
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { beforeEach, test } from 'vitest';
|
|
2
|
+
import { LucidContext, runAndAwaitTx } from './test-helpers';
|
|
3
|
+
import { fromText, Lucid } from '@lucid-evolution/lucid';
|
|
4
|
+
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
|
+
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
|
+
import { StakingContract } from '../src/contracts/staking';
|
|
7
|
+
import { init } from './endpoints/initialize';
|
|
8
|
+
import { addrDetails } from '../src/helpers/lucid-utils';
|
|
9
|
+
import { findStakingPosition } from './queries/staking-queries';
|
|
10
|
+
|
|
11
|
+
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
12
|
+
context.users = {
|
|
13
|
+
admin: generateEmulatorAccount({
|
|
14
|
+
lovelace: BigInt(100_000_000_000_000),
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
context.emulator = new Emulator([context.users.admin]);
|
|
19
|
+
|
|
20
|
+
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test<LucidContext>('Staking - Create Position', async ({
|
|
24
|
+
lucid,
|
|
25
|
+
users,
|
|
26
|
+
}: LucidContext) => {
|
|
27
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
28
|
+
const systemParams = await init(lucid);
|
|
29
|
+
|
|
30
|
+
await runAndAwaitTx(
|
|
31
|
+
lucid,
|
|
32
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test<LucidContext>('Staking - Adjust Position', async ({
|
|
37
|
+
lucid,
|
|
38
|
+
users,
|
|
39
|
+
}: LucidContext) => {
|
|
40
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
41
|
+
const systemParams = await init(lucid);
|
|
42
|
+
|
|
43
|
+
await runAndAwaitTx(
|
|
44
|
+
lucid,
|
|
45
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
49
|
+
const myStakingPosition = await findStakingPosition(
|
|
50
|
+
lucid,
|
|
51
|
+
lucid.config().network,
|
|
52
|
+
systemParams.validatorHashes.stakingHash,
|
|
53
|
+
{
|
|
54
|
+
currencySymbol:
|
|
55
|
+
systemParams.stakingParams.stakingToken[0].unCurrencySymbol,
|
|
56
|
+
tokenName: fromText(
|
|
57
|
+
systemParams.stakingParams.stakingToken[1].unTokenName,
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
pkh.hash,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
await runAndAwaitTx(
|
|
64
|
+
lucid,
|
|
65
|
+
StakingContract.adjustPosition(
|
|
66
|
+
myStakingPosition,
|
|
67
|
+
1_000_000n,
|
|
68
|
+
systemParams,
|
|
69
|
+
lucid,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test<LucidContext>('Staking - Close Position', async ({
|
|
75
|
+
lucid,
|
|
76
|
+
users,
|
|
77
|
+
}: LucidContext) => {
|
|
78
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
79
|
+
const systemParams = await init(lucid);
|
|
80
|
+
|
|
81
|
+
await runAndAwaitTx(
|
|
82
|
+
lucid,
|
|
83
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
87
|
+
const myStakingPosition = await findStakingPosition(
|
|
88
|
+
lucid,
|
|
89
|
+
lucid.config().network,
|
|
90
|
+
systemParams.validatorHashes.stakingHash,
|
|
91
|
+
{
|
|
92
|
+
currencySymbol:
|
|
93
|
+
systemParams.stakingParams.stakingToken[0].unCurrencySymbol,
|
|
94
|
+
tokenName: fromText(
|
|
95
|
+
systemParams.stakingParams.stakingToken[1].unTokenName,
|
|
96
|
+
),
|
|
97
|
+
},
|
|
98
|
+
pkh.hash,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await runAndAwaitTx(
|
|
102
|
+
lucid,
|
|
103
|
+
StakingContract.closePosition(myStakingPosition, systemParams, lucid),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Emulator,
|
|
3
|
+
EmulatorAccount,
|
|
4
|
+
LucidEvolution,
|
|
5
|
+
TxBuilder,
|
|
6
|
+
} from '@lucid-evolution/lucid';
|
|
7
|
+
|
|
8
|
+
export type LucidContext = {
|
|
9
|
+
lucid: LucidEvolution;
|
|
10
|
+
users: { [key: string]: EmulatorAccount };
|
|
11
|
+
emulator: Emulator;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export async function runAndAwaitTx(
|
|
15
|
+
lucid: LucidEvolution,
|
|
16
|
+
transaction: Promise<TxBuilder>,
|
|
17
|
+
): Promise<string> {
|
|
18
|
+
const txHash = await transaction
|
|
19
|
+
.then((tx) => tx.complete())
|
|
20
|
+
.then((tx) => tx.sign.withWallet().complete())
|
|
21
|
+
.then((tx) => tx.submit());
|
|
22
|
+
|
|
23
|
+
await lucid.awaitTx(txHash);
|
|
24
|
+
return txHash;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function runAndAwaitTxBuilder(
|
|
28
|
+
lucid: LucidEvolution,
|
|
29
|
+
transaction: TxBuilder,
|
|
30
|
+
): Promise<string> {
|
|
31
|
+
const txHash = await transaction
|
|
32
|
+
.complete()
|
|
33
|
+
.then((tx) => tx.sign.withWallet().complete())
|
|
34
|
+
.then((tx) => tx.submit());
|
|
35
|
+
|
|
36
|
+
await lucid.awaitTx(txHash);
|
|
37
|
+
return txHash;
|
|
38
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,35 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"outDir": "./dist",
|
|
4
|
-
"
|
|
5
|
-
"module": "
|
|
6
|
-
"target": "
|
|
7
|
-
"
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"strict": true,
|
|
12
|
-
"strictNullChecks": true,
|
|
13
|
-
"strictFunctionTypes": true,
|
|
14
|
-
"strictBindCallApply": true,
|
|
15
|
-
"strictPropertyInitialization": false,
|
|
16
|
-
"noImplicitThis": true,
|
|
17
|
-
"alwaysStrict": false,
|
|
18
|
-
"noUnusedLocals": false,
|
|
19
|
-
"noUnusedParameters": false,
|
|
20
|
-
"noImplicitReturns": true,
|
|
21
|
-
"noFallthroughCasesInSwitch": true,
|
|
22
|
-
"esModuleInterop": true,
|
|
23
|
-
"skipLibCheck": true,
|
|
24
|
-
"forceConsistentCasingInFileNames": true,
|
|
25
|
-
"resolveJsonModule": true,
|
|
26
|
-
"allowSyntheticDefaultImports": true
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"module": "nodenext",
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"moduleResolution": "nodenext"
|
|
27
8
|
},
|
|
28
9
|
"ts-node": {
|
|
29
10
|
"compilerOptions": {
|
|
30
|
-
"module": "ES2022"
|
|
11
|
+
"module": "ES2022"
|
|
31
12
|
}
|
|
32
13
|
},
|
|
33
|
-
"include": ["src/**/*.ts"],
|
|
34
|
-
"exclude": ["
|
|
35
|
-
}
|
|
14
|
+
"include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"],
|
|
15
|
+
"exclude": ["dist", "node_modules"]
|
|
16
|
+
}
|
package/vitest.config.ts
ADDED
package/babel.config.cjs
DELETED
package/jest.config.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Address,
|
|
3
|
-
applyParamsToScript,
|
|
4
|
-
Constr,
|
|
5
|
-
Credential,
|
|
6
|
-
Data,
|
|
7
|
-
fromText,
|
|
8
|
-
LucidEvolution,
|
|
9
|
-
SpendingValidator,
|
|
10
|
-
UTxO,
|
|
11
|
-
validatorToAddress,
|
|
12
|
-
validatorToScriptHash,
|
|
13
|
-
} from '@lucid-evolution/lucid';
|
|
14
|
-
import { _cdpCreatorValidator } from '../scripts/cdp-creator-validator';
|
|
15
|
-
import { CdpCreatorParams, ScriptReferences } from '../types/system-params';
|
|
16
|
-
import { scriptRef } from '../helpers/lucid-utils';
|
|
17
|
-
|
|
18
|
-
export class CDPCreatorContract {
|
|
19
|
-
static address(params: CdpCreatorParams, lucid: LucidEvolution): Address {
|
|
20
|
-
const network = lucid.config().network;
|
|
21
|
-
if (!network) {
|
|
22
|
-
throw new Error('Network configuration is undefined');
|
|
23
|
-
}
|
|
24
|
-
return validatorToAddress(network, CDPCreatorContract.validator(params));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static validator(params: CdpCreatorParams): SpendingValidator {
|
|
28
|
-
return {
|
|
29
|
-
type: 'PlutusV2',
|
|
30
|
-
script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
|
|
31
|
-
new Constr(0, [
|
|
32
|
-
new Constr(0, [
|
|
33
|
-
params.cdpCreatorNft[0].unCurrencySymbol,
|
|
34
|
-
fromText(params.cdpCreatorNft[1].unTokenName),
|
|
35
|
-
]),
|
|
36
|
-
params.cdpAssetCs.unCurrencySymbol,
|
|
37
|
-
new Constr(0, [
|
|
38
|
-
params.cdpAuthTk[0].unCurrencySymbol,
|
|
39
|
-
fromText(params.cdpAuthTk[1].unTokenName),
|
|
40
|
-
]),
|
|
41
|
-
new Constr(0, [
|
|
42
|
-
params.iAssetAuthTk[0].unCurrencySymbol,
|
|
43
|
-
fromText(params.iAssetAuthTk[1].unTokenName),
|
|
44
|
-
]),
|
|
45
|
-
new Constr(0, [
|
|
46
|
-
params.versionRecordToken[0].unCurrencySymbol,
|
|
47
|
-
fromText(params.versionRecordToken[1].unTokenName),
|
|
48
|
-
]),
|
|
49
|
-
params.cdpScriptHash,
|
|
50
|
-
params.collectorValHash,
|
|
51
|
-
BigInt(params.minCollateralInLovelace),
|
|
52
|
-
BigInt(params.biasTime),
|
|
53
|
-
]),
|
|
54
|
-
]),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static validatorHash(
|
|
59
|
-
params: CdpCreatorParams
|
|
60
|
-
): string {
|
|
61
|
-
return validatorToScriptHash(CDPCreatorContract.validator(params));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static redeemer(
|
|
65
|
-
hash: Credential,
|
|
66
|
-
mintedAmount: bigint,
|
|
67
|
-
collateralAmount: bigint,
|
|
68
|
-
currentTime: bigint,
|
|
69
|
-
): Data {
|
|
70
|
-
if (hash.type !== 'Key') throw new Error('Cannot support script hash.');
|
|
71
|
-
|
|
72
|
-
return new Constr<Data>(0, [
|
|
73
|
-
hash.hash,
|
|
74
|
-
BigInt(mintedAmount),
|
|
75
|
-
BigInt(collateralAmount),
|
|
76
|
-
currentTime
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
static scriptRef(
|
|
81
|
-
params: ScriptReferences,
|
|
82
|
-
lucid: LucidEvolution,
|
|
83
|
-
): Promise<UTxO> {
|
|
84
|
-
return scriptRef(params.cdpCreatorValidatorRef, lucid);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Constr, Data } from "@lucid-evolution/lucid";
|
|
2
|
-
import { PriceOracleDatum } from "../types/indigo/price-oracle";
|
|
3
|
-
|
|
4
|
-
export class PriceOracleContract {
|
|
5
|
-
static decodePriceOracleDatum(datum: string): PriceOracleDatum {
|
|
6
|
-
const oracleDatum = Data.from(datum) as any;
|
|
7
|
-
if (oracleDatum.index != 0 || oracleDatum.fields.length !== 2 || oracleDatum.fields[0].index !== 0)
|
|
8
|
-
throw 'Invalid Price Oracle Datum provided.'
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
price: oracleDatum.fields[0].fields[0],
|
|
12
|
-
expiration: oracleDatum.fields[1],
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static encodePriceOracleDatum(datum: PriceOracleDatum): string {
|
|
17
|
-
return Data.to(
|
|
18
|
-
new Constr(0, [
|
|
19
|
-
new Constr(0, [datum.price]),
|
|
20
|
-
datum.expiration,
|
|
21
|
-
])
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
}
|