@indigo-labs/indigo-sdk 0.3.16 → 0.3.17

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.
Files changed (43) hide show
  1. package/dist/index.d.mts +40 -8
  2. package/dist/index.d.ts +40 -8
  3. package/dist/index.js +112 -57
  4. package/dist/index.mjs +110 -57
  5. package/package.json +1 -1
  6. package/src/contracts/iasset/helpers.ts +1 -1
  7. package/src/contracts/rob/helpers.ts +122 -43
  8. package/src/contracts/rob/transactions.ts +12 -3
  9. package/src/contracts/rob-leverage/helpers.ts +4 -1
  10. package/src/contracts/treasury/transactions.ts +8 -2
  11. package/src/validators/cdp-creator-validator.ts +1 -1
  12. package/src/validators/cdp-redeem-validator.ts +1 -1
  13. package/src/validators/cdp-validator.ts +1 -1
  14. package/src/validators/collector-validator.ts +1 -1
  15. package/src/validators/execute-validator.ts +1 -1
  16. package/src/validators/governance-validator.ts +1 -1
  17. package/src/validators/iasset-validator.ts +1 -1
  18. package/src/validators/interest-collection-validator.ts +1 -1
  19. package/src/validators/interest-oracle-validator.ts +1 -1
  20. package/src/validators/poll-manager-validator.ts +1 -1
  21. package/src/validators/poll-shard-validator.ts +1 -1
  22. package/src/validators/price-oracle-validator.ts +1 -1
  23. package/src/validators/pyth-feed-validator.ts +1 -1
  24. package/src/validators/rob-validator.ts +1 -1
  25. package/src/validators/stability-pool-validator.ts +1 -1
  26. package/src/validators/stableswap-validator.ts +1 -1
  27. package/src/validators/staking-validator.ts +1 -1
  28. package/src/validators/treasury-validator.ts +1 -1
  29. package/src/validators/version-record-policy.ts +1 -1
  30. package/tests/cdp/actions.ts +1 -1
  31. package/tests/cdp/cdp-queries.ts +1 -1
  32. package/tests/cdp/cdp.test.ts +1 -1
  33. package/tests/cdp/transactions-mutated.ts +1 -1
  34. package/tests/gov/gov.test.ts +78 -12
  35. package/tests/interest-collection/interest-collection.test.ts +5 -5
  36. package/tests/rob/rob-leverage.test.ts +12 -27
  37. package/tests/rob/rob.test.ts +56 -52
  38. package/tests/stability-pool.test.ts +6 -3
  39. package/tests/stableswap/stableswap.test.ts +1 -1
  40. package/tests/treasury/actions.ts +67 -0
  41. package/tests/{queries → treasury}/treasury-queries.ts +11 -2
  42. package/tests/treasury/treasury.test.ts +342 -0
  43. package/tests/treasury.test.ts +0 -242
@@ -1,242 +0,0 @@
1
- import { addAssets, Assets, TxBuilder } from '@lucid-evolution/lucid';
2
- import { assert, beforeEach, describe, test } from 'vitest';
3
- import { IndigoTestContext } from './test-helpers';
4
- import { treasuryCollect, treasuryMerge, treasurySplit } from '../src';
5
- import {
6
- createIndigoTestContext,
7
- EXAMPLE_TOKEN_1,
8
- EXAMPLE_TOKEN_2,
9
- EXAMPLE_TOKEN_3,
10
- } from './indigo-test-helpers';
11
- import { benchmarkAndAwaitTx } from './utils/benchmark-utils';
12
- import {
13
- findAllTreasuryUtxos,
14
- findRandomTreasuryUtxoWithOnlyAda,
15
- } from './queries/treasury-queries';
16
- import {
17
- adaAssetClass,
18
- mkLovelacesOf,
19
- } from '@3rd-eye-labs/cardano-offchain-common';
20
- import { mkAssetsOf } from '@3rd-eye-labs/cardano-offchain-common';
21
- import { createUtxoAtTreasury } from './endpoints/treasury';
22
- import { expectScriptFailure } from './utils/asserts';
23
-
24
- // NOTE: Withdrawing and PrepareWithdrawal from Treasury is tested in gov.test.ts
25
- describe('Treasury', () => {
26
- beforeEach<IndigoTestContext>(async (context: IndigoTestContext) => {
27
- await createIndigoTestContext(context);
28
- });
29
-
30
- async function treasuryMergeTx(
31
- context: IndigoTestContext,
32
- treasuryOutputs: Assets[],
33
- ): Promise<TxBuilder> {
34
- for (const output of treasuryOutputs) {
35
- await createUtxoAtTreasury(output, context.systemParams, context);
36
- }
37
-
38
- const treasuryUtxos = await findAllTreasuryUtxos(
39
- context.lucid,
40
- context.systemParams,
41
- );
42
-
43
- // Simpler approach: for each expected output in treasuryOutputs, find one UTxO with exactly matching assets and take it
44
- // Find UTxOs for each expected output, but remove it from the candidate list as we match
45
- const availableUtxos = [...treasuryUtxos];
46
- const matchedTreasuryUtxos = treasuryOutputs
47
- .map((expectedAssets) => {
48
- const idx = availableUtxos.findIndex((utxo) => {
49
- const utxoAssets = utxo.assets;
50
- const keys1 = Object.keys(utxoAssets).sort();
51
- const keys2 = Object.keys(expectedAssets).sort();
52
- if (keys1.length !== keys2.length) return false;
53
- return keys1.every(
54
- (k, i) => k === keys2[i] && utxoAssets[k] === expectedAssets[k],
55
- );
56
- });
57
- if (idx !== -1) {
58
- return availableUtxos.splice(idx, 1)[0];
59
- } else {
60
- return undefined;
61
- }
62
- })
63
- .filter((utxo) => utxo !== undefined);
64
-
65
- assert(
66
- matchedTreasuryUtxos.length === treasuryOutputs.length,
67
- 'Expected all treasury outputs to be matched',
68
- );
69
-
70
- return await treasuryMerge(
71
- matchedTreasuryUtxos,
72
- context.lucid,
73
- context.systemParams,
74
- );
75
- }
76
-
77
- async function treasurySplitTx(
78
- context: IndigoTestContext,
79
- treasuryOutput: Assets,
80
- ): Promise<TxBuilder> {
81
- await createUtxoAtTreasury(treasuryOutput, context.systemParams, context);
82
-
83
- const treasuryUtxos = await findAllTreasuryUtxos(
84
- context.lucid,
85
- context.systemParams,
86
- );
87
-
88
- const matchedTreasuryUtxo = treasuryUtxos.find((utxo) =>
89
- Object.keys(treasuryOutput).every(
90
- (key) => utxo.assets[key] === treasuryOutput[key],
91
- ),
92
- );
93
-
94
- assert(
95
- matchedTreasuryUtxo !== undefined,
96
- 'Expected a single treasury UTXO',
97
- );
98
-
99
- return await treasurySplit(
100
- matchedTreasuryUtxo,
101
- context.lucid,
102
- context.systemParams,
103
- );
104
- }
105
-
106
- test<IndigoTestContext>('Merge (3 lovelace UTxOs)', async (context: IndigoTestContext) => {
107
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
108
-
109
- await benchmarkAndAwaitTx(
110
- 'Treasury - Merge (3 lovelace UTxOs)',
111
- await treasuryMergeTx(context, [
112
- mkLovelacesOf(50_000_000n),
113
- mkLovelacesOf(50_000_000n),
114
- mkLovelacesOf(50_000_000n),
115
- ]),
116
- context.lucid,
117
- context.emulator,
118
- );
119
- });
120
-
121
- test<IndigoTestContext>('Merge (3 INDY UTxOs)', async (context: IndigoTestContext) => {
122
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
123
-
124
- await benchmarkAndAwaitTx(
125
- 'Treasury - Merge (3 INDY UTxOs)',
126
- await treasuryMergeTx(context, [
127
- addAssets(
128
- mkLovelacesOf(5_000_000n),
129
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
130
- ),
131
- addAssets(
132
- mkLovelacesOf(5_000_000n),
133
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
134
- ),
135
- addAssets(
136
- mkLovelacesOf(5_000_000n),
137
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
138
- ),
139
- ]),
140
- context.lucid,
141
- context.emulator,
142
- );
143
- });
144
-
145
- test<IndigoTestContext>('Merge (fail, 1 lovelace, 2 INDY UTxOs)', async (context: IndigoTestContext) => {
146
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
147
-
148
- await expectScriptFailure(
149
- 'All inputs have to contain the same merging assets',
150
- treasuryMergeTx(context, [
151
- mkLovelacesOf(5_000_000n),
152
- addAssets(
153
- mkLovelacesOf(5_000_000n),
154
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
155
- ),
156
- addAssets(
157
- mkLovelacesOf(5_000_000n),
158
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
159
- ),
160
- ]),
161
- );
162
- });
163
-
164
- test<IndigoTestContext>('Split (3 assets)', async (context: IndigoTestContext) => {
165
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
166
-
167
- await benchmarkAndAwaitTx(
168
- 'Treasury - Split (3 assets)',
169
- await treasurySplitTx(
170
- context,
171
- addAssets(
172
- mkLovelacesOf(5_000_000n),
173
- mkAssetsOf(EXAMPLE_TOKEN_1, 1n),
174
- mkAssetsOf(EXAMPLE_TOKEN_2, 1n),
175
- mkAssetsOf(EXAMPLE_TOKEN_3, 1n),
176
- ),
177
- ),
178
- context.lucid,
179
- context.emulator,
180
- );
181
- });
182
-
183
- test<IndigoTestContext>('Split (fail, lovelace only)', async (context: IndigoTestContext) => {
184
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
185
-
186
- await expectScriptFailure(
187
- 'All inputs must have more than 1 non-ADA asset or 1 non-ADA asset and more than 2x ADA buffer',
188
- treasurySplitTx(context, mkLovelacesOf(5_000_000n)),
189
- );
190
- });
191
-
192
- test<IndigoTestContext>('Collect non-positive amount or negative extra lovelaces fails', async (context: IndigoTestContext) => {
193
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
194
-
195
- const treasuryUTxO = await findRandomTreasuryUtxoWithOnlyAda(
196
- context.lucid,
197
- context.systemParams,
198
- );
199
-
200
- // This tests that the amount to collect cannot be negative.
201
- await expectScriptFailure(
202
- 'Collected amount is positive',
203
- treasuryCollect(
204
- adaAssetClass,
205
- -1_000_000n,
206
- 0n,
207
- context.lucid,
208
- context.systemParams,
209
- treasuryUTxO,
210
- treasuryUTxO,
211
- ),
212
- );
213
-
214
- // This tests that the amount to collect cannot be zero.
215
- await expectScriptFailure(
216
- 'Collected amount is positive',
217
- treasuryCollect(
218
- adaAssetClass,
219
- 0n,
220
- 0n,
221
- context.lucid,
222
- context.systemParams,
223
- treasuryUTxO,
224
- treasuryUTxO,
225
- ),
226
- );
227
-
228
- // This tests that the extra lovelaces cannot be negative.
229
- await expectScriptFailure(
230
- 'Collected amount is positive',
231
- treasuryCollect(
232
- adaAssetClass,
233
- 1n,
234
- -1_000_000n,
235
- context.lucid,
236
- context.systemParams,
237
- treasuryUTxO,
238
- treasuryUTxO,
239
- ),
240
- );
241
- });
242
- });