@indigo-labs/indigo-sdk 0.1.21 → 0.1.22
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 +3 -8
- package/.github/workflows/test.yml +44 -0
- package/dist/index.d.mts +670 -1291
- package/dist/index.d.ts +670 -1291
- package/dist/index.js +2235 -4669
- package/dist/index.mjs +2216 -4618
- package/eslint.config.mjs +1 -7
- package/package.json +4 -9
- package/src/contracts/cdp.ts +746 -0
- package/src/contracts/collector.ts +98 -0
- package/src/contracts/gov.ts +1 -0
- package/src/contracts/interest-oracle.ts +149 -0
- package/src/contracts/{lrp/transactions.ts → lrp.ts} +14 -14
- package/src/contracts/{one-shot/transactions.ts → one-shot.ts} +3 -3
- package/src/contracts/stability-pool.ts +690 -0
- package/src/contracts/staking.ts +348 -0
- package/src/contracts/treasury.ts +112 -0
- package/src/helpers/asset-helpers.ts +57 -0
- package/src/{utils → helpers}/helper-txs.ts +0 -1
- package/src/{utils/utils.ts → helpers/helpers.ts} +10 -0
- package/src/{contracts/interest-oracle/helpers.ts → helpers/interest-oracle.ts} +9 -37
- package/src/{contracts/stability-pool/helpers.ts → helpers/stability-pool-helpers.ts} +6 -110
- package/src/helpers/staking-helpers.ts +94 -0
- package/src/helpers/time-helpers.ts +4 -0
- package/src/{utils → helpers}/value-helpers.ts +0 -10
- package/src/index.ts +33 -38
- package/src/{validators → scripts}/cdp-creator-validator.ts +50 -4
- package/src/{validators → scripts}/cdp-validator.ts +5 -3
- package/src/{validators → scripts}/collector-validator.ts +3 -2
- package/src/scripts/execute-validator.ts +52 -0
- package/src/{validators/governance-validator.ts → scripts/gov-validator.ts} +40 -3
- package/src/{validators → scripts}/interest-oracle-validator.ts +20 -4
- package/src/scripts/lrp-validator.ts +40 -0
- package/src/{contracts/one-shot/scripts.ts → scripts/one-shot-policy.ts} +1 -1
- package/src/scripts/poll-manager-validator.ts +52 -0
- package/src/{validators → scripts}/poll-shard-validator.ts +43 -3
- package/src/{contracts/price-oracle/scripts.ts → scripts/price-oracle-validator.ts} +4 -1
- package/src/{validators → scripts}/stability-pool-validator.ts +57 -4
- package/src/{validators → scripts}/staking-validator.ts +3 -2
- package/src/{validators → scripts}/treasury-validator.ts +3 -2
- package/src/{validators → scripts}/version-record-policy.ts +23 -4
- package/src/{validators/execute-validator.ts → scripts/version-registry.ts} +11 -3
- package/src/types/generic.ts +60 -78
- package/src/{contracts/cdp-creator/types.ts → types/indigo/cdp-creator.ts} +4 -6
- package/src/types/indigo/cdp.ts +88 -0
- package/src/types/indigo/execute.ts +21 -0
- package/src/types/indigo/gov.ts +51 -0
- package/src/{contracts/interest-oracle/types.ts → types/indigo/interest-oracle.ts} +1 -1
- package/src/{contracts/lrp/types.ts → types/indigo/lrp.ts} +2 -2
- package/src/types/indigo/poll-manager.ts +21 -0
- package/src/types/indigo/poll-shard.ts +16 -0
- package/src/{contracts/price-oracle/types.ts → types/indigo/price-oracle.ts} +4 -16
- package/src/types/indigo/stability-pool.ts +233 -0
- package/src/types/indigo/staking.ts +99 -0
- package/src/{contracts/version-registry/types.ts → types/indigo/version-record.ts} +1 -1
- package/src/types/on-chain-decimal.ts +0 -22
- package/src/types/system-params.ts +11 -22
- package/tests/datums.test.ts +108 -125
- package/tests/endpoints/initialize.ts +338 -240
- package/tests/hash-checks.test.ts +21 -26
- package/tests/indigo-test-helpers.ts +55 -1
- package/tests/initialize.test.ts +5 -10
- package/tests/interest-calculations.test.ts +18 -18
- package/tests/interest-oracle.test.ts +18 -20
- package/tests/lrp.test.ts +65 -191
- package/tests/queries/governance-queries.ts +16 -19
- package/tests/queries/iasset-queries.ts +23 -46
- package/tests/queries/interest-oracle-queries.ts +6 -3
- package/tests/queries/lrp-queries.ts +2 -2
- package/tests/queries/price-oracle-queries.ts +22 -5
- package/tests/queries/stability-pool-queries.ts +8 -10
- package/tests/queries/staking-queries.ts +19 -28
- package/tests/stability-pool.test.ts +71 -186
- package/tests/staking.test.ts +23 -30
- package/tests/test-helpers.ts +2 -11
- package/tsconfig.json +1 -3
- package/vitest.config.ts +1 -1
- package/src/contracts/cdp/helpers.ts +0 -167
- package/src/contracts/cdp/scripts.ts +0 -33
- package/src/contracts/cdp/transactions.ts +0 -1310
- package/src/contracts/cdp/types.ts +0 -161
- package/src/contracts/cdp-creator/scripts.ts +0 -39
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -44
- package/src/contracts/execute/scripts.ts +0 -48
- package/src/contracts/execute/types.ts +0 -57
- package/src/contracts/gov/helpers.ts +0 -157
- package/src/contracts/gov/scripts.ts +0 -34
- package/src/contracts/gov/transactions.ts +0 -1224
- package/src/contracts/gov/types-new.ts +0 -115
- package/src/contracts/gov/types.ts +0 -89
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -149
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/poll/helpers.ts +0 -55
- package/src/contracts/poll/scripts.ts +0 -72
- package/src/contracts/poll/types-poll-manager.ts +0 -38
- package/src/contracts/poll/types-poll-shard.ts +0 -38
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/price-oracle/transactions.ts +0 -112
- package/src/contracts/stability-pool/scripts.ts +0 -46
- package/src/contracts/stability-pool/transactions.ts +0 -660
- package/src/contracts/stability-pool/types-new.ts +0 -208
- package/src/contracts/stability-pool/types.ts +0 -42
- package/src/contracts/staking/helpers.ts +0 -116
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -268
- package/src/contracts/staking/types-new.ts +0 -81
- package/src/contracts/staking/types.ts +0 -41
- package/src/contracts/treasury/scripts.ts +0 -37
- package/src/contracts/treasury/transactions.ts +0 -44
- package/src/contracts/treasury/types.ts +0 -55
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -19
- package/src/contracts/vesting/helpers.ts +0 -267
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/utils/bigint-utils.ts +0 -7
- package/src/utils/time-helpers.ts +0 -4
- package/src/validators/lrp-validator.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1565
- package/tests/gov.test.ts +0 -1874
- package/tests/mock/assets-mock.ts +0 -59
- package/tests/queries/cdp-queries.ts +0 -144
- package/tests/queries/collector-queries.ts +0 -26
- package/tests/queries/execute-queries.ts +0 -46
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/treasury-queries.ts +0 -19
- package/tests/utils/asserts.ts +0 -13
- package/tests/utils/index.ts +0 -50
- /package/src/{utils → helpers}/indigo-helpers.ts +0 -0
- /package/src/{utils → helpers}/lucid-utils.ts +0 -0
- /package/src/{contracts/price-oracle/helpers.ts → helpers/price-oracle-helpers.ts} +0 -0
- /package/src/{contracts/one-shot/types.ts → types/one-shot.ts} +0 -0
|
@@ -1,39 +1,20 @@
|
|
|
1
1
|
import { beforeEach, test, afterEach } from 'vitest';
|
|
2
2
|
import { LucidContext, runAndAwaitTx } from './test-helpers';
|
|
3
|
-
import {
|
|
3
|
+
import { fromText, Lucid } from '@lucid-evolution/lucid';
|
|
4
4
|
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
5
|
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
6
|
import { init } from './endpoints/initialize';
|
|
7
|
-
import {
|
|
8
|
-
addrDetails,
|
|
9
|
-
adjustSpAccount,
|
|
10
|
-
closeSpAccount,
|
|
11
|
-
createSpAccount,
|
|
12
|
-
fromSystemParamsAsset,
|
|
13
|
-
openCdp,
|
|
14
|
-
processSpRequest,
|
|
15
|
-
} from '../src';
|
|
7
|
+
import { addrDetails, CDPContract, StabilityPoolContract } from '../src';
|
|
16
8
|
import {
|
|
17
9
|
findStabilityPool,
|
|
18
10
|
findStabilityPoolAccount,
|
|
19
11
|
} from './queries/stability-pool-queries';
|
|
20
12
|
import { findIAsset } from './queries/iasset-queries';
|
|
21
13
|
import { findGov } from './queries/governance-queries';
|
|
22
|
-
import { findRandomCdpCreator } from './queries/cdp-queries';
|
|
23
|
-
import { findPriceOracle } from './queries/price-oracle-queries';
|
|
24
|
-
import { match, P } from 'ts-pattern';
|
|
25
|
-
import { findInterestOracle } from './queries/interest-oracle-queries';
|
|
26
|
-
import { findRandomCollector } from './queries/collector-queries';
|
|
27
|
-
import { iusdInitialAssetCfg } from './mock/assets-mock';
|
|
28
14
|
|
|
29
15
|
let originalDateNow: () => number;
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
admin: EmulatorAccount;
|
|
33
|
-
user: EmulatorAccount;
|
|
34
|
-
}>;
|
|
35
|
-
|
|
36
|
-
beforeEach<MyContext>(async (context: MyContext) => {
|
|
17
|
+
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
37
18
|
context.users = {
|
|
38
19
|
admin: generateEmulatorAccount({
|
|
39
20
|
lovelace: BigInt(100_000_000_000_000),
|
|
@@ -55,48 +36,23 @@ afterEach(() => {
|
|
|
55
36
|
Date.now = originalDateNow;
|
|
56
37
|
});
|
|
57
38
|
|
|
58
|
-
test<
|
|
39
|
+
test<LucidContext>('Stability Pool - Create Account', async ({
|
|
59
40
|
lucid,
|
|
60
41
|
users,
|
|
61
42
|
emulator,
|
|
62
|
-
}:
|
|
43
|
+
}: LucidContext) => {
|
|
63
44
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
64
|
-
const
|
|
45
|
+
const systemParams = await init(lucid);
|
|
65
46
|
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
66
47
|
const [pkh, _] = await addrDetails(lucid);
|
|
67
48
|
|
|
68
|
-
const iasset = await findIAsset(
|
|
69
|
-
lucid,
|
|
70
|
-
systemParams.validatorHashes.cdpHash,
|
|
71
|
-
fromSystemParamsAsset(systemParams.cdpParams.iAssetAuthToken),
|
|
72
|
-
iusdInfo.iassetTokenNameAscii,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
49
|
await runAndAwaitTx(
|
|
76
50
|
lucid,
|
|
77
|
-
|
|
51
|
+
CDPContract.openPosition(
|
|
52
|
+
'iUSD',
|
|
78
53
|
1_000_000_000n,
|
|
79
54
|
20n,
|
|
80
55
|
systemParams,
|
|
81
|
-
await findRandomCdpCreator(
|
|
82
|
-
lucid,
|
|
83
|
-
systemParams.validatorHashes.cdpCreatorHash,
|
|
84
|
-
fromSystemParamsAsset(systemParams.cdpCreatorParams.cdpCreatorNft),
|
|
85
|
-
),
|
|
86
|
-
iasset.utxo,
|
|
87
|
-
await findPriceOracle(
|
|
88
|
-
lucid,
|
|
89
|
-
match(iasset.datum.price)
|
|
90
|
-
.with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
|
|
91
|
-
.otherwise(() => {
|
|
92
|
-
throw new Error('Expected active oracle');
|
|
93
|
-
}),
|
|
94
|
-
),
|
|
95
|
-
await findInterestOracle(lucid, iasset.datum.interestOracleNft),
|
|
96
|
-
await findRandomCollector(
|
|
97
|
-
lucid,
|
|
98
|
-
systemParams.validatorHashes.collectorHash,
|
|
99
|
-
),
|
|
100
56
|
lucid,
|
|
101
57
|
emulator.slot,
|
|
102
58
|
),
|
|
@@ -104,7 +60,7 @@ test<MyContext>('Stability Pool - Create Account', async ({
|
|
|
104
60
|
|
|
105
61
|
await runAndAwaitTx(
|
|
106
62
|
lucid,
|
|
107
|
-
|
|
63
|
+
StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
|
|
108
64
|
);
|
|
109
65
|
|
|
110
66
|
const stabilityPoolUtxo = await findStabilityPool(
|
|
@@ -117,14 +73,14 @@ test<MyContext>('Stability Pool - Create Account', async ({
|
|
|
117
73
|
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
118
74
|
),
|
|
119
75
|
},
|
|
120
|
-
|
|
76
|
+
'iUSD',
|
|
121
77
|
);
|
|
122
78
|
|
|
123
79
|
const accountUtxo = await findStabilityPoolAccount(
|
|
124
80
|
lucid,
|
|
125
81
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
126
82
|
pkh.hash,
|
|
127
|
-
|
|
83
|
+
'iUSD',
|
|
128
84
|
);
|
|
129
85
|
|
|
130
86
|
const assetUtxo = await findIAsset(
|
|
@@ -137,7 +93,7 @@ test<MyContext>('Stability Pool - Create Account', async ({
|
|
|
137
93
|
systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
|
|
138
94
|
),
|
|
139
95
|
},
|
|
140
|
-
|
|
96
|
+
'iUSD',
|
|
141
97
|
);
|
|
142
98
|
|
|
143
99
|
const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
|
|
@@ -149,65 +105,36 @@ test<MyContext>('Stability Pool - Create Account', async ({
|
|
|
149
105
|
|
|
150
106
|
await runAndAwaitTx(
|
|
151
107
|
lucid,
|
|
152
|
-
|
|
153
|
-
|
|
108
|
+
StabilityPoolContract.processRequest(
|
|
109
|
+
'iUSD',
|
|
154
110
|
stabilityPoolUtxo,
|
|
155
111
|
accountUtxo,
|
|
156
|
-
govUtxo
|
|
157
|
-
assetUtxo
|
|
112
|
+
govUtxo,
|
|
113
|
+
assetUtxo,
|
|
158
114
|
undefined,
|
|
159
115
|
systemParams,
|
|
160
116
|
lucid,
|
|
161
|
-
await findRandomCollector(
|
|
162
|
-
lucid,
|
|
163
|
-
systemParams.validatorHashes.collectorHash,
|
|
164
|
-
),
|
|
165
117
|
),
|
|
166
118
|
);
|
|
167
119
|
});
|
|
168
120
|
|
|
169
|
-
test<
|
|
121
|
+
test<LucidContext>('Stability Pool - Adjust Account', async ({
|
|
170
122
|
lucid,
|
|
171
123
|
users,
|
|
172
124
|
emulator,
|
|
173
|
-
}:
|
|
125
|
+
}: LucidContext) => {
|
|
174
126
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
175
|
-
const
|
|
127
|
+
const systemParams = await init(lucid);
|
|
176
128
|
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
177
129
|
const [pkh, _] = await addrDetails(lucid);
|
|
178
130
|
|
|
179
|
-
const iasset = await findIAsset(
|
|
180
|
-
lucid,
|
|
181
|
-
systemParams.validatorHashes.cdpHash,
|
|
182
|
-
fromSystemParamsAsset(systemParams.cdpParams.iAssetAuthToken),
|
|
183
|
-
iusdInfo.iassetTokenNameAscii,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
131
|
await runAndAwaitTx(
|
|
187
132
|
lucid,
|
|
188
|
-
|
|
133
|
+
CDPContract.openPosition(
|
|
134
|
+
'iUSD',
|
|
189
135
|
1_000_000_000n,
|
|
190
136
|
20n,
|
|
191
137
|
systemParams,
|
|
192
|
-
await findRandomCdpCreator(
|
|
193
|
-
lucid,
|
|
194
|
-
systemParams.validatorHashes.cdpCreatorHash,
|
|
195
|
-
fromSystemParamsAsset(systemParams.cdpCreatorParams.cdpCreatorNft),
|
|
196
|
-
),
|
|
197
|
-
iasset.utxo,
|
|
198
|
-
await findPriceOracle(
|
|
199
|
-
lucid,
|
|
200
|
-
match(iasset.datum.price)
|
|
201
|
-
.with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
|
|
202
|
-
.otherwise(() => {
|
|
203
|
-
throw new Error('Expected active oracle');
|
|
204
|
-
}),
|
|
205
|
-
),
|
|
206
|
-
await findInterestOracle(lucid, iasset.datum.interestOracleNft),
|
|
207
|
-
await findRandomCollector(
|
|
208
|
-
lucid,
|
|
209
|
-
systemParams.validatorHashes.collectorHash,
|
|
210
|
-
),
|
|
211
138
|
lucid,
|
|
212
139
|
emulator.slot,
|
|
213
140
|
),
|
|
@@ -215,7 +142,7 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
215
142
|
|
|
216
143
|
await runAndAwaitTx(
|
|
217
144
|
lucid,
|
|
218
|
-
|
|
145
|
+
StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
|
|
219
146
|
);
|
|
220
147
|
|
|
221
148
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
@@ -230,14 +157,14 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
230
157
|
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
231
158
|
),
|
|
232
159
|
},
|
|
233
|
-
|
|
160
|
+
'iUSD',
|
|
234
161
|
);
|
|
235
162
|
|
|
236
163
|
let accountUtxo = await findStabilityPoolAccount(
|
|
237
164
|
lucid,
|
|
238
165
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
239
166
|
pkh.hash,
|
|
240
|
-
|
|
167
|
+
'iUSD',
|
|
241
168
|
);
|
|
242
169
|
|
|
243
170
|
const assetUtxo = await findIAsset(
|
|
@@ -250,7 +177,7 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
250
177
|
systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
|
|
251
178
|
),
|
|
252
179
|
},
|
|
253
|
-
|
|
180
|
+
'iUSD',
|
|
254
181
|
);
|
|
255
182
|
|
|
256
183
|
const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
|
|
@@ -260,19 +187,15 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
260
187
|
|
|
261
188
|
await runAndAwaitTx(
|
|
262
189
|
lucid,
|
|
263
|
-
|
|
264
|
-
|
|
190
|
+
StabilityPoolContract.processRequest(
|
|
191
|
+
'iUSD',
|
|
265
192
|
stabilityPoolUtxo,
|
|
266
193
|
accountUtxo,
|
|
267
|
-
govUtxo
|
|
268
|
-
assetUtxo
|
|
194
|
+
govUtxo,
|
|
195
|
+
assetUtxo,
|
|
269
196
|
undefined,
|
|
270
197
|
systemParams,
|
|
271
198
|
lucid,
|
|
272
|
-
await findRandomCollector(
|
|
273
|
-
lucid,
|
|
274
|
-
systemParams.validatorHashes.collectorHash,
|
|
275
|
-
),
|
|
276
199
|
),
|
|
277
200
|
);
|
|
278
201
|
|
|
@@ -288,20 +211,20 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
288
211
|
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
289
212
|
),
|
|
290
213
|
},
|
|
291
|
-
|
|
214
|
+
'iUSD',
|
|
292
215
|
);
|
|
293
216
|
|
|
294
217
|
accountUtxo = await findStabilityPoolAccount(
|
|
295
218
|
lucid,
|
|
296
219
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
297
220
|
pkh.hash,
|
|
298
|
-
|
|
221
|
+
'iUSD',
|
|
299
222
|
);
|
|
300
223
|
|
|
301
224
|
await runAndAwaitTx(
|
|
302
225
|
lucid,
|
|
303
|
-
|
|
304
|
-
|
|
226
|
+
StabilityPoolContract.adjustAccount(
|
|
227
|
+
'iUSD',
|
|
305
228
|
10n,
|
|
306
229
|
accountUtxo,
|
|
307
230
|
systemParams,
|
|
@@ -314,24 +237,20 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
314
237
|
lucid,
|
|
315
238
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
316
239
|
pkh.hash,
|
|
317
|
-
|
|
240
|
+
'iUSD',
|
|
318
241
|
);
|
|
319
242
|
|
|
320
243
|
await runAndAwaitTx(
|
|
321
244
|
lucid,
|
|
322
|
-
|
|
323
|
-
|
|
245
|
+
StabilityPoolContract.processRequest(
|
|
246
|
+
'iUSD',
|
|
324
247
|
stabilityPoolUtxo,
|
|
325
248
|
accountUtxo,
|
|
326
|
-
govUtxo
|
|
327
|
-
assetUtxo
|
|
249
|
+
govUtxo,
|
|
250
|
+
assetUtxo,
|
|
328
251
|
undefined,
|
|
329
252
|
systemParams,
|
|
330
253
|
lucid,
|
|
331
|
-
await findRandomCollector(
|
|
332
|
-
lucid,
|
|
333
|
-
systemParams.validatorHashes.collectorHash,
|
|
334
|
-
),
|
|
335
254
|
),
|
|
336
255
|
);
|
|
337
256
|
|
|
@@ -348,20 +267,20 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
348
267
|
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
349
268
|
),
|
|
350
269
|
},
|
|
351
|
-
|
|
270
|
+
'iUSD',
|
|
352
271
|
);
|
|
353
272
|
|
|
354
273
|
accountUtxo = await findStabilityPoolAccount(
|
|
355
274
|
lucid,
|
|
356
275
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
357
276
|
pkh.hash,
|
|
358
|
-
|
|
277
|
+
'iUSD',
|
|
359
278
|
);
|
|
360
279
|
|
|
361
280
|
await runAndAwaitTx(
|
|
362
281
|
lucid,
|
|
363
|
-
|
|
364
|
-
|
|
282
|
+
StabilityPoolContract.adjustAccount(
|
|
283
|
+
'iUSD',
|
|
365
284
|
-10n,
|
|
366
285
|
accountUtxo,
|
|
367
286
|
systemParams,
|
|
@@ -374,70 +293,41 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
|
|
|
374
293
|
lucid,
|
|
375
294
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
376
295
|
pkh.hash,
|
|
377
|
-
|
|
296
|
+
'iUSD',
|
|
378
297
|
);
|
|
379
298
|
|
|
380
299
|
await runAndAwaitTx(
|
|
381
300
|
lucid,
|
|
382
|
-
|
|
383
|
-
|
|
301
|
+
StabilityPoolContract.processRequest(
|
|
302
|
+
'iUSD',
|
|
384
303
|
stabilityPoolUtxo,
|
|
385
304
|
accountUtxo,
|
|
386
|
-
govUtxo
|
|
387
|
-
assetUtxo
|
|
305
|
+
govUtxo,
|
|
306
|
+
assetUtxo,
|
|
388
307
|
undefined,
|
|
389
308
|
systemParams,
|
|
390
309
|
lucid,
|
|
391
|
-
await findRandomCollector(
|
|
392
|
-
lucid,
|
|
393
|
-
systemParams.validatorHashes.collectorHash,
|
|
394
|
-
),
|
|
395
310
|
),
|
|
396
311
|
);
|
|
397
312
|
});
|
|
398
313
|
|
|
399
|
-
test<
|
|
314
|
+
test<LucidContext>('Stability Pool - Close Account', async ({
|
|
400
315
|
lucid,
|
|
401
316
|
users,
|
|
402
317
|
emulator,
|
|
403
|
-
}:
|
|
318
|
+
}: LucidContext) => {
|
|
404
319
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
405
|
-
const
|
|
320
|
+
const systemParams = await init(lucid, emulator.now());
|
|
406
321
|
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
407
322
|
const [pkh, _] = await addrDetails(lucid);
|
|
408
323
|
|
|
409
|
-
const iasset = await findIAsset(
|
|
410
|
-
lucid,
|
|
411
|
-
systemParams.validatorHashes.cdpHash,
|
|
412
|
-
fromSystemParamsAsset(systemParams.cdpParams.iAssetAuthToken),
|
|
413
|
-
iusdInfo.iassetTokenNameAscii,
|
|
414
|
-
);
|
|
415
|
-
|
|
416
324
|
await runAndAwaitTx(
|
|
417
325
|
lucid,
|
|
418
|
-
|
|
326
|
+
CDPContract.openPosition(
|
|
327
|
+
'iUSD',
|
|
419
328
|
1_000_000_000n,
|
|
420
329
|
20n,
|
|
421
330
|
systemParams,
|
|
422
|
-
await findRandomCdpCreator(
|
|
423
|
-
lucid,
|
|
424
|
-
systemParams.validatorHashes.cdpCreatorHash,
|
|
425
|
-
fromSystemParamsAsset(systemParams.cdpCreatorParams.cdpCreatorNft),
|
|
426
|
-
),
|
|
427
|
-
iasset.utxo,
|
|
428
|
-
await findPriceOracle(
|
|
429
|
-
lucid,
|
|
430
|
-
match(iasset.datum.price)
|
|
431
|
-
.with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
|
|
432
|
-
.otherwise(() => {
|
|
433
|
-
throw new Error('Expected active oracle');
|
|
434
|
-
}),
|
|
435
|
-
),
|
|
436
|
-
await findInterestOracle(lucid, iasset.datum.interestOracleNft),
|
|
437
|
-
await findRandomCollector(
|
|
438
|
-
lucid,
|
|
439
|
-
systemParams.validatorHashes.collectorHash,
|
|
440
|
-
),
|
|
441
331
|
lucid,
|
|
442
332
|
emulator.slot,
|
|
443
333
|
),
|
|
@@ -445,7 +335,7 @@ test<MyContext>('Stability Pool - Close Account', async ({
|
|
|
445
335
|
|
|
446
336
|
await runAndAwaitTx(
|
|
447
337
|
lucid,
|
|
448
|
-
|
|
338
|
+
StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
|
|
449
339
|
);
|
|
450
340
|
|
|
451
341
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
@@ -460,14 +350,14 @@ test<MyContext>('Stability Pool - Close Account', async ({
|
|
|
460
350
|
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
461
351
|
),
|
|
462
352
|
},
|
|
463
|
-
|
|
353
|
+
'iUSD',
|
|
464
354
|
);
|
|
465
355
|
|
|
466
356
|
let accountUtxo = await findStabilityPoolAccount(
|
|
467
357
|
lucid,
|
|
468
358
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
469
359
|
pkh.hash,
|
|
470
|
-
|
|
360
|
+
'iUSD',
|
|
471
361
|
);
|
|
472
362
|
|
|
473
363
|
const assetUtxo = await findIAsset(
|
|
@@ -480,7 +370,7 @@ test<MyContext>('Stability Pool - Close Account', async ({
|
|
|
480
370
|
systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
|
|
481
371
|
),
|
|
482
372
|
},
|
|
483
|
-
|
|
373
|
+
'iUSD',
|
|
484
374
|
);
|
|
485
375
|
|
|
486
376
|
const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
|
|
@@ -490,19 +380,15 @@ test<MyContext>('Stability Pool - Close Account', async ({
|
|
|
490
380
|
|
|
491
381
|
await runAndAwaitTx(
|
|
492
382
|
lucid,
|
|
493
|
-
|
|
494
|
-
|
|
383
|
+
StabilityPoolContract.processRequest(
|
|
384
|
+
'iUSD',
|
|
495
385
|
stabilityPoolUtxo,
|
|
496
386
|
accountUtxo,
|
|
497
|
-
govUtxo
|
|
498
|
-
assetUtxo
|
|
387
|
+
govUtxo,
|
|
388
|
+
assetUtxo,
|
|
499
389
|
undefined,
|
|
500
390
|
systemParams,
|
|
501
391
|
lucid,
|
|
502
|
-
await findRandomCollector(
|
|
503
|
-
lucid,
|
|
504
|
-
systemParams.validatorHashes.collectorHash,
|
|
505
|
-
),
|
|
506
392
|
),
|
|
507
393
|
);
|
|
508
394
|
|
|
@@ -518,41 +404,40 @@ test<MyContext>('Stability Pool - Close Account', async ({
|
|
|
518
404
|
systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
|
|
519
405
|
),
|
|
520
406
|
},
|
|
521
|
-
|
|
407
|
+
'iUSD',
|
|
522
408
|
);
|
|
523
409
|
|
|
524
410
|
accountUtxo = await findStabilityPoolAccount(
|
|
525
411
|
lucid,
|
|
526
412
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
527
413
|
pkh.hash,
|
|
528
|
-
|
|
414
|
+
'iUSD',
|
|
529
415
|
);
|
|
530
416
|
|
|
531
|
-
await runAndAwaitTx(
|
|
417
|
+
await runAndAwaitTx(
|
|
418
|
+
lucid,
|
|
419
|
+
StabilityPoolContract.closeAccount(accountUtxo, systemParams, lucid),
|
|
420
|
+
);
|
|
532
421
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
533
422
|
|
|
534
423
|
accountUtxo = await findStabilityPoolAccount(
|
|
535
424
|
lucid,
|
|
536
425
|
systemParams.validatorHashes.stabilityPoolHash,
|
|
537
426
|
pkh.hash,
|
|
538
|
-
|
|
427
|
+
'iUSD',
|
|
539
428
|
);
|
|
540
429
|
|
|
541
430
|
await runAndAwaitTx(
|
|
542
431
|
lucid,
|
|
543
|
-
|
|
544
|
-
|
|
432
|
+
StabilityPoolContract.processRequest(
|
|
433
|
+
'iUSD',
|
|
545
434
|
stabilityPoolUtxo,
|
|
546
435
|
accountUtxo,
|
|
547
|
-
govUtxo
|
|
548
|
-
assetUtxo
|
|
436
|
+
govUtxo,
|
|
437
|
+
assetUtxo,
|
|
549
438
|
undefined,
|
|
550
439
|
systemParams,
|
|
551
440
|
lucid,
|
|
552
|
-
await findRandomCollector(
|
|
553
|
-
lucid,
|
|
554
|
-
systemParams.validatorHashes.collectorHash,
|
|
555
|
-
),
|
|
556
441
|
),
|
|
557
442
|
);
|
|
558
443
|
});
|
package/tests/staking.test.ts
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { beforeEach, test } from 'vitest';
|
|
2
2
|
import { LucidContext, runAndAwaitTx } from './test-helpers';
|
|
3
|
-
import {
|
|
3
|
+
import { fromText, Lucid } from '@lucid-evolution/lucid';
|
|
4
4
|
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
5
|
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
|
+
import { StakingContract } from '../src/contracts/staking';
|
|
6
7
|
import { init } from './endpoints/initialize';
|
|
7
|
-
import { addrDetails } from '../src/
|
|
8
|
+
import { addrDetails } from '../src/helpers/lucid-utils';
|
|
8
9
|
import { findStakingPosition } from './queries/staking-queries';
|
|
9
|
-
import { iusdInitialAssetCfg } from './mock/assets-mock';
|
|
10
|
-
import {
|
|
11
|
-
adjustStakingPosition,
|
|
12
|
-
closeStakingPosition,
|
|
13
|
-
openStakingPosition,
|
|
14
|
-
} from '../src/contracts/staking/transactions';
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
admin: EmulatorAccount;
|
|
18
|
-
}>;
|
|
19
|
-
|
|
20
|
-
beforeEach<MyContext>(async (context: MyContext) => {
|
|
11
|
+
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
21
12
|
context.users = {
|
|
22
13
|
admin: generateEmulatorAccount({
|
|
23
14
|
lovelace: BigInt(100_000_000_000_000),
|
|
@@ -29,34 +20,35 @@ beforeEach<MyContext>(async (context: MyContext) => {
|
|
|
29
20
|
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
30
21
|
});
|
|
31
22
|
|
|
32
|
-
test<
|
|
23
|
+
test<LucidContext>('Staking - Create Position', async ({
|
|
33
24
|
lucid,
|
|
34
25
|
users,
|
|
35
|
-
}:
|
|
26
|
+
}: LucidContext) => {
|
|
36
27
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
37
|
-
const
|
|
28
|
+
const systemParams = await init(lucid);
|
|
38
29
|
|
|
39
30
|
await runAndAwaitTx(
|
|
40
31
|
lucid,
|
|
41
|
-
|
|
32
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
42
33
|
);
|
|
43
34
|
});
|
|
44
35
|
|
|
45
|
-
test<
|
|
36
|
+
test<LucidContext>('Staking - Adjust Position', async ({
|
|
46
37
|
lucid,
|
|
47
38
|
users,
|
|
48
|
-
}:
|
|
39
|
+
}: LucidContext) => {
|
|
49
40
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
50
|
-
const
|
|
41
|
+
const systemParams = await init(lucid);
|
|
51
42
|
|
|
52
43
|
await runAndAwaitTx(
|
|
53
44
|
lucid,
|
|
54
|
-
|
|
45
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
55
46
|
);
|
|
56
47
|
|
|
57
|
-
const [pkh,
|
|
48
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
58
49
|
const myStakingPosition = await findStakingPosition(
|
|
59
50
|
lucid,
|
|
51
|
+
lucid.config().network,
|
|
60
52
|
systemParams.validatorHashes.stakingHash,
|
|
61
53
|
{
|
|
62
54
|
currencySymbol:
|
|
@@ -70,8 +62,8 @@ test<MyContext>('Staking - Adjust Position', async ({
|
|
|
70
62
|
|
|
71
63
|
await runAndAwaitTx(
|
|
72
64
|
lucid,
|
|
73
|
-
|
|
74
|
-
myStakingPosition
|
|
65
|
+
StakingContract.adjustPosition(
|
|
66
|
+
myStakingPosition,
|
|
75
67
|
1_000_000n,
|
|
76
68
|
systemParams,
|
|
77
69
|
lucid,
|
|
@@ -79,21 +71,22 @@ test<MyContext>('Staking - Adjust Position', async ({
|
|
|
79
71
|
);
|
|
80
72
|
});
|
|
81
73
|
|
|
82
|
-
test<
|
|
74
|
+
test<LucidContext>('Staking - Close Position', async ({
|
|
83
75
|
lucid,
|
|
84
76
|
users,
|
|
85
|
-
}:
|
|
77
|
+
}: LucidContext) => {
|
|
86
78
|
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
87
|
-
const
|
|
79
|
+
const systemParams = await init(lucid);
|
|
88
80
|
|
|
89
81
|
await runAndAwaitTx(
|
|
90
82
|
lucid,
|
|
91
|
-
|
|
83
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
92
84
|
);
|
|
93
85
|
|
|
94
|
-
const [pkh,
|
|
86
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
95
87
|
const myStakingPosition = await findStakingPosition(
|
|
96
88
|
lucid,
|
|
89
|
+
lucid.config().network,
|
|
97
90
|
systemParams.validatorHashes.stakingHash,
|
|
98
91
|
{
|
|
99
92
|
currencySymbol:
|
|
@@ -107,6 +100,6 @@ test<MyContext>('Staking - Close Position', async ({
|
|
|
107
100
|
|
|
108
101
|
await runAndAwaitTx(
|
|
109
102
|
lucid,
|
|
110
|
-
|
|
103
|
+
StakingContract.closePosition(myStakingPosition, systemParams, lucid),
|
|
111
104
|
);
|
|
112
105
|
});
|
package/tests/test-helpers.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
TxBuilder,
|
|
6
6
|
} from '@lucid-evolution/lucid';
|
|
7
7
|
|
|
8
|
-
export type LucidContext
|
|
8
|
+
export type LucidContext = {
|
|
9
9
|
lucid: LucidEvolution;
|
|
10
|
-
users:
|
|
10
|
+
users: { [key: string]: EmulatorAccount };
|
|
11
11
|
emulator: Emulator;
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -36,12 +36,3 @@ export async function runAndAwaitTxBuilder(
|
|
|
36
36
|
await lucid.awaitTx(txHash);
|
|
37
37
|
return txHash;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
export async function repeat(
|
|
41
|
-
times: number,
|
|
42
|
-
action: () => Promise<void>,
|
|
43
|
-
): Promise<void> {
|
|
44
|
-
for (let i = 0; i < times; i++) {
|
|
45
|
-
await action();
|
|
46
|
-
}
|
|
47
|
-
}
|
package/tsconfig.json
CHANGED
package/vitest.config.ts
CHANGED