@indigo-labs/indigo-sdk 0.5.5 → 0.5.6

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 (204) hide show
  1. package/package.json +11 -1
  2. package/.claude/settings.local.json +0 -7
  3. package/.github/workflows/ci.yml +0 -66
  4. package/.husky/pre-commit +0 -1
  5. package/.nvmrc +0 -1
  6. package/.prettierignore +0 -1
  7. package/.prettierrc +0 -6
  8. package/eslint.config.mjs +0 -42
  9. package/scripts/bench.sh +0 -62
  10. package/scripts/run-repeat.sh +0 -22
  11. package/src/contracts/cdp/helpers.ts +0 -173
  12. package/src/contracts/cdp/scripts.ts +0 -70
  13. package/src/contracts/cdp/transactions.ts +0 -1584
  14. package/src/contracts/cdp/types-new.ts +0 -277
  15. package/src/contracts/cdp/types.ts +0 -43
  16. package/src/contracts/cdp-creator/queries.ts +0 -30
  17. package/src/contracts/cdp-creator/scripts.ts +0 -45
  18. package/src/contracts/cdp-creator/types-new.ts +0 -50
  19. package/src/contracts/cdp-creator/types.ts +0 -24
  20. package/src/contracts/collector/scripts.ts +0 -32
  21. package/src/contracts/collector/transactions.ts +0 -50
  22. package/src/contracts/collector/types-new.ts +0 -17
  23. package/src/contracts/execute/scripts.ts +0 -57
  24. package/src/contracts/execute/types-new.ts +0 -44
  25. package/src/contracts/execute/types.ts +0 -24
  26. package/src/contracts/gov/helpers.ts +0 -351
  27. package/src/contracts/gov/scripts.ts +0 -41
  28. package/src/contracts/gov/transactions.ts +0 -1607
  29. package/src/contracts/gov/types-new.ts +0 -268
  30. package/src/contracts/gov/types.ts +0 -22
  31. package/src/contracts/iasset/helpers.ts +0 -170
  32. package/src/contracts/iasset/queries.ts +0 -102
  33. package/src/contracts/iasset/scripts.ts +0 -38
  34. package/src/contracts/iasset/types.ts +0 -154
  35. package/src/contracts/initialize/actions.ts +0 -789
  36. package/src/contracts/initialize/helpers.ts +0 -616
  37. package/src/contracts/initialize/types.ts +0 -116
  38. package/src/contracts/interest-collection/helpers.ts +0 -19
  39. package/src/contracts/interest-collection/queries.ts +0 -66
  40. package/src/contracts/interest-collection/scripts.ts +0 -44
  41. package/src/contracts/interest-collection/transactions.ts +0 -433
  42. package/src/contracts/interest-collection/types-new.ts +0 -50
  43. package/src/contracts/interest-collection/types.ts +0 -26
  44. package/src/contracts/interest-oracle/helpers.ts +0 -61
  45. package/src/contracts/interest-oracle/scripts.ts +0 -18
  46. package/src/contracts/interest-oracle/transactions.ts +0 -151
  47. package/src/contracts/interest-oracle/types-new.ts +0 -32
  48. package/src/contracts/interest-oracle/types.ts +0 -16
  49. package/src/contracts/one-shot/scripts.ts +0 -12
  50. package/src/contracts/one-shot/transactions.ts +0 -66
  51. package/src/contracts/one-shot/types.ts +0 -22
  52. package/src/contracts/poll/helpers.ts +0 -37
  53. package/src/contracts/poll/scripts.ts +0 -71
  54. package/src/contracts/poll/types-poll-manager.ts +0 -20
  55. package/src/contracts/poll/types-poll-new.ts +0 -196
  56. package/src/contracts/poll/types-poll-shard.ts +0 -16
  57. package/src/contracts/price-oracle/helpers.ts +0 -30
  58. package/src/contracts/price-oracle/scripts.ts +0 -18
  59. package/src/contracts/price-oracle/transactions.ts +0 -115
  60. package/src/contracts/price-oracle/types-new.ts +0 -50
  61. package/src/contracts/price-oracle/types.ts +0 -16
  62. package/src/contracts/pyth-feed/helpers.ts +0 -82
  63. package/src/contracts/pyth-feed/scripts.ts +0 -15
  64. package/src/contracts/pyth-feed/types.ts +0 -181
  65. package/src/contracts/rob/helpers.ts +0 -666
  66. package/src/contracts/rob/scripts.ts +0 -35
  67. package/src/contracts/rob/transactions.ts +0 -423
  68. package/src/contracts/rob/types-new.ts +0 -128
  69. package/src/contracts/rob/types.ts +0 -16
  70. package/src/contracts/rob-leverage/helpers.ts +0 -422
  71. package/src/contracts/rob-leverage/transactions.ts +0 -368
  72. package/src/contracts/stability-pool/helpers.ts +0 -798
  73. package/src/contracts/stability-pool/queries.ts +0 -132
  74. package/src/contracts/stability-pool/scripts.ts +0 -51
  75. package/src/contracts/stability-pool/transactions.ts +0 -921
  76. package/src/contracts/stability-pool/types-new.ts +0 -385
  77. package/src/contracts/stability-pool/types.ts +0 -25
  78. package/src/contracts/stableswap/helpers.ts +0 -507
  79. package/src/contracts/stableswap/scripts.ts +0 -37
  80. package/src/contracts/stableswap/transactions.ts +0 -475
  81. package/src/contracts/stableswap/types-new.ts +0 -131
  82. package/src/contracts/stableswap/types.ts +0 -17
  83. package/src/contracts/staking/helpers.ts +0 -136
  84. package/src/contracts/staking/scripts.ts +0 -41
  85. package/src/contracts/staking/transactions.ts +0 -349
  86. package/src/contracts/staking/types-new.ts +0 -137
  87. package/src/contracts/staking/types.ts +0 -17
  88. package/src/contracts/treasury/helpers.ts +0 -21
  89. package/src/contracts/treasury/queries.ts +0 -100
  90. package/src/contracts/treasury/scripts.ts +0 -27
  91. package/src/contracts/treasury/transactions.ts +0 -334
  92. package/src/contracts/treasury/types-new.ts +0 -69
  93. package/src/contracts/treasury/types.ts +0 -14
  94. package/src/contracts/version-registry/scripts.ts +0 -29
  95. package/src/contracts/version-registry/types-new.ts +0 -18
  96. package/src/contracts/version-registry/types.ts +0 -17
  97. package/src/index.ts +0 -99
  98. package/src/scripts/always-fail-validator.ts +0 -7
  99. package/src/scripts/auth-token-policy.ts +0 -24
  100. package/src/scripts/iasset-policy.ts +0 -23
  101. package/src/types/evolution-schema-options.ts +0 -16
  102. package/src/types/generic.ts +0 -52
  103. package/src/types/multisig.ts +0 -48
  104. package/src/types/on-chain-decimal.ts +0 -57
  105. package/src/types/rational.ts +0 -76
  106. package/src/types/system-params.ts +0 -463
  107. package/src/utils/array-utils.ts +0 -108
  108. package/src/utils/bigint-utils.ts +0 -35
  109. package/src/utils/helper-txs.ts +0 -31
  110. package/src/utils/indigo-helpers.ts +0 -17
  111. package/src/utils/lucid-utils.ts +0 -125
  112. package/src/utils/oracle-helpers.ts +0 -62
  113. package/src/utils/pyth/decode.ts +0 -223
  114. package/src/utils/pyth/encode.ts +0 -262
  115. package/src/utils/pyth/index.ts +0 -14
  116. package/src/utils/pyth/types.ts +0 -87
  117. package/src/utils/time-helpers.ts +0 -4
  118. package/src/utils/utils.ts +0 -25
  119. package/src/validators/always-succeed-validator.ts +0 -6
  120. package/src/validators/cdp-creator-validator.ts +0 -7
  121. package/src/validators/cdp-redeem-validator.ts +0 -7
  122. package/src/validators/cdp-validator.ts +0 -7
  123. package/src/validators/collector-validator.ts +0 -7
  124. package/src/validators/execute-validator.ts +0 -7
  125. package/src/validators/governance-validator.ts +0 -7
  126. package/src/validators/iasset-validator.ts +0 -7
  127. package/src/validators/interest-collection-validator.ts +0 -7
  128. package/src/validators/interest-oracle-validator.ts +0 -7
  129. package/src/validators/one-shot-policy.ts +0 -7
  130. package/src/validators/poll-manager-validator.ts +0 -7
  131. package/src/validators/poll-shard-validator.ts +0 -7
  132. package/src/validators/price-oracle-validator.ts +0 -7
  133. package/src/validators/pyth-feed-validator.ts +0 -7
  134. package/src/validators/rob-validator.ts +0 -7
  135. package/src/validators/stability-pool-validator.ts +0 -7
  136. package/src/validators/stableswap-validator.ts +0 -7
  137. package/src/validators/staking-validator.ts +0 -7
  138. package/src/validators/treasury-validator.ts +0 -7
  139. package/src/validators/version-record-policy.ts +0 -7
  140. package/src/validators/version-registry-validator.ts +0 -7
  141. package/tests/always-succeed/script.ts +0 -7
  142. package/tests/array-utils.test.ts +0 -92
  143. package/tests/bigint-utils.test.ts +0 -41
  144. package/tests/cdp/actions.ts +0 -680
  145. package/tests/cdp/cdp-helpers.ts +0 -55
  146. package/tests/cdp/cdp-queries.ts +0 -423
  147. package/tests/cdp/cdp.test.ts +0 -6730
  148. package/tests/cdp/transactions-mutated.ts +0 -1733
  149. package/tests/data/system-params.json +0 -1155
  150. package/tests/datums.test.ts +0 -302
  151. package/tests/endpoints/initialize.ts +0 -78
  152. package/tests/endpoints/interest-collector.ts +0 -37
  153. package/tests/endpoints/treasury.ts +0 -70
  154. package/tests/gov/actions.ts +0 -381
  155. package/tests/gov/gov.test.ts +0 -5147
  156. package/tests/gov/governance-queries.ts +0 -37
  157. package/tests/hash-checks.test.ts +0 -112
  158. package/tests/indigo-test-helpers.ts +0 -99
  159. package/tests/initialize.test.ts +0 -79
  160. package/tests/interest-calculations.test.ts +0 -120
  161. package/tests/interest-collection/interest-collection.test.ts +0 -843
  162. package/tests/interest-collection/transactions-mutated.ts +0 -260
  163. package/tests/interest-oracle.test.ts +0 -93
  164. package/tests/mock/assets-mock.ts +0 -243
  165. package/tests/mock/protocol-params-mock.ts +0 -21
  166. package/tests/price-oracle/actions.ts +0 -161
  167. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  168. package/tests/price-oracle/price-oracle.test.ts +0 -228
  169. package/tests/price-oracle/transactions-mutated.ts +0 -59
  170. package/tests/pyth/endpoints.ts +0 -96
  171. package/tests/pyth/helpers.ts +0 -37
  172. package/tests/pyth/pyth-encoding.test.ts +0 -376
  173. package/tests/pyth/pyth-feeds.test.ts +0 -943
  174. package/tests/pyth/pyth-indigo.test.ts +0 -505
  175. package/tests/pyth/pyth.test.ts +0 -299
  176. package/tests/queries/collector-queries.ts +0 -27
  177. package/tests/queries/execute-queries.ts +0 -47
  178. package/tests/queries/iasset-queries.ts +0 -149
  179. package/tests/queries/interest-oracle-queries.ts +0 -12
  180. package/tests/queries/poll-queries.ts +0 -97
  181. package/tests/queries/staking-queries.ts +0 -54
  182. package/tests/rob/actions.ts +0 -56
  183. package/tests/rob/rob-leverage.test.ts +0 -2555
  184. package/tests/rob/rob-queries.ts +0 -95
  185. package/tests/rob/rob.test.ts +0 -3677
  186. package/tests/rob/transactions-mutated.ts +0 -844
  187. package/tests/script-size.test.ts +0 -240
  188. package/tests/setup.ts +0 -135
  189. package/tests/stability-pool/actions.ts +0 -229
  190. package/tests/stability-pool.test.ts +0 -6491
  191. package/tests/stableswap/stableswap-actions.ts +0 -83
  192. package/tests/stableswap/stableswap-queries.ts +0 -98
  193. package/tests/stableswap/stableswap.test.ts +0 -4471
  194. package/tests/stableswap/transactions-mutated.ts +0 -348
  195. package/tests/staking.test.ts +0 -172
  196. package/tests/test-helpers.ts +0 -94
  197. package/tests/treasury/actions.ts +0 -67
  198. package/tests/treasury/treasury.test.ts +0 -320
  199. package/tests/utils/asserts.ts +0 -87
  200. package/tests/utils/benchmark-utils.ts +0 -130
  201. package/tests/utils/index.ts +0 -168
  202. package/tsconfig.build.json +0 -4
  203. package/tsconfig.json +0 -27
  204. package/vitest.config.ts +0 -11
@@ -1,320 +0,0 @@
1
- import {
2
- addAssets,
3
- Emulator,
4
- EmulatorAccount,
5
- fromHex,
6
- fromText,
7
- generateEmulatorAccount,
8
- Lucid,
9
- } from '@lucid-evolution/lucid';
10
- import { beforeEach, describe, test } from 'vitest';
11
- import { LucidContext } from '../test-helpers';
12
- import { treasuryCollect } from '../../src';
13
- import {
14
- EXAMPLE_TOKEN_1,
15
- EXAMPLE_TOKEN_2,
16
- EXAMPLE_TOKEN_3,
17
- MAINNET_PROTOCOL_PARAMETERS,
18
- } from '../indigo-test-helpers';
19
- import { benchmarkAndAwaitTx } from '../utils/benchmark-utils';
20
- import { findRandomTreasuryUtxoWithOnlyAda } from '../../src/contracts/treasury/queries';
21
- import {
22
- adaAssetClass,
23
- AssetClass,
24
- mkLovelacesOf,
25
- } from '@3rd-eye-labs/cardano-offchain-common';
26
- import { mkAssetsOf } from '@3rd-eye-labs/cardano-offchain-common';
27
- import { expectScriptFailure } from '../utils/asserts';
28
- import { treasuryMergeTx, treasurySplitTx } from './actions';
29
- import { init } from '../endpoints/initialize';
30
- import { iusdInitialAssetCfg } from '../mock/assets-mock';
31
-
32
- type MyContext = LucidContext<{
33
- admin: EmulatorAccount;
34
- user: EmulatorAccount;
35
- withdrawalAccount: EmulatorAccount;
36
- }>;
37
-
38
- const testAssetA: AssetClass = {
39
- currencySymbol: fromHex(
40
- // random generated
41
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8daa',
42
- ),
43
- tokenName: fromHex(fromText('A')),
44
- };
45
- const testAssetB: AssetClass = {
46
- currencySymbol: fromHex(
47
- // random generated
48
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dab',
49
- ),
50
- tokenName: fromHex(fromText('B')),
51
- };
52
-
53
- const testAssetC: AssetClass = {
54
- currencySymbol: fromHex(
55
- // random generated
56
- 'aa072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dac',
57
- ),
58
- tokenName: fromHex(fromText('C')),
59
- };
60
-
61
- const testAssetD: AssetClass = {
62
- currencySymbol: fromHex(
63
- // random generated
64
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dad',
65
- ),
66
- tokenName: fromHex(fromText('D')),
67
- };
68
-
69
- const testAssetE: AssetClass = {
70
- currencySymbol: fromHex(
71
- // random generated
72
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dae',
73
- ),
74
- tokenName: fromHex(fromText('E')),
75
- };
76
-
77
- const testAssetF: AssetClass = {
78
- currencySymbol: fromHex(
79
- // random generated
80
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8daf',
81
- ),
82
- tokenName: fromHex(fromText('F')),
83
- };
84
-
85
- const testAssetG: AssetClass = {
86
- currencySymbol: fromHex(
87
- // random generated
88
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dba',
89
- ),
90
- tokenName: fromHex(fromText('G')),
91
- };
92
-
93
- const testAssetH: AssetClass = {
94
- currencySymbol: fromHex(
95
- // random generated
96
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dbb',
97
- ),
98
- tokenName: fromHex(fromText('H')),
99
- };
100
-
101
- const testAssetI: AssetClass = {
102
- currencySymbol: fromHex(
103
- // random generated
104
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dbc',
105
- ),
106
- tokenName: fromHex(fromText('I')),
107
- };
108
-
109
- const testAssetJ: AssetClass = {
110
- currencySymbol: fromHex(
111
- // random generated
112
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dbd',
113
- ),
114
- tokenName: fromHex(fromText('J')),
115
- };
116
-
117
- const testAssetK: AssetClass = {
118
- currencySymbol: fromHex(
119
- // random generated
120
- 'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dbe',
121
- ),
122
- tokenName: fromHex(fromText('K')),
123
- };
124
-
125
- // NOTE: Withdrawing and PrepareWithdrawal from Treasury is tested in gov.test.ts
126
- describe('Treasury', () => {
127
- beforeEach<MyContext>(async (context: MyContext) => {
128
- context.users = {
129
- admin: generateEmulatorAccount({
130
- lovelace: BigInt(100_000_000_000_000),
131
- }),
132
- user: generateEmulatorAccount(
133
- addAssets(
134
- mkLovelacesOf(100_000_000_000_000n),
135
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000_000_000n),
136
- mkAssetsOf(EXAMPLE_TOKEN_2, 1_000_000_000_000_000n),
137
- mkAssetsOf(EXAMPLE_TOKEN_3, 1_000_000_000_000_000n),
138
- mkAssetsOf(testAssetA, 1_000_000_000_000_000n),
139
- mkAssetsOf(testAssetB, 1_000_000_000_000_000n),
140
- mkAssetsOf(testAssetC, 1_000_000_000_000_000n),
141
- mkAssetsOf(testAssetD, 1_000_000_000_000_000n),
142
- mkAssetsOf(testAssetE, 1_000_000_000_000_000n),
143
- mkAssetsOf(testAssetF, 1_000_000_000_000_000n),
144
- mkAssetsOf(testAssetG, 1_000_000_000_000_000n),
145
- mkAssetsOf(testAssetH, 1_000_000_000_000_000n),
146
- mkAssetsOf(testAssetI, 1_000_000_000_000_000n),
147
- mkAssetsOf(testAssetJ, 1_000_000_000_000_000n),
148
- mkAssetsOf(testAssetK, 1_000_000_000_000_000n),
149
- ),
150
- ),
151
- withdrawalAccount: generateEmulatorAccount({}),
152
- };
153
-
154
- context.emulator = new Emulator(
155
- [context.users.admin, context.users.user],
156
- MAINNET_PROTOCOL_PARAMETERS,
157
- );
158
- context.lucid = await Lucid(context.emulator, 'Custom');
159
-
160
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
161
- });
162
-
163
- test<MyContext>('Merge (3 lovelace UTxOs)', async (context: MyContext) => {
164
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
165
-
166
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
167
-
168
- await benchmarkAndAwaitTx(
169
- 'Treasury - Merge (3 lovelace UTxOs)',
170
- await treasuryMergeTx(context, sysParams, [
171
- mkLovelacesOf(50_000_000n),
172
- mkLovelacesOf(50_000_000n),
173
- mkLovelacesOf(50_000_000n),
174
- ]),
175
- context.lucid,
176
- context.emulator,
177
- );
178
- });
179
-
180
- test<MyContext>('Merge (3 INDY UTxOs)', async (context: MyContext) => {
181
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
182
-
183
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
184
-
185
- await benchmarkAndAwaitTx(
186
- 'Treasury - Merge (3 INDY UTxOs)',
187
- await treasuryMergeTx(context, sysParams, [
188
- addAssets(
189
- mkLovelacesOf(5_000_000n),
190
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
191
- ),
192
- addAssets(
193
- mkLovelacesOf(5_000_000n),
194
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
195
- ),
196
- addAssets(
197
- mkLovelacesOf(5_000_000n),
198
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
199
- ),
200
- ]),
201
- context.lucid,
202
- context.emulator,
203
- );
204
- });
205
-
206
- test<MyContext>('Merge (fail, 1 lovelace, 2 INDY UTxOs)', async (context: MyContext) => {
207
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
208
-
209
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
210
-
211
- await expectScriptFailure(
212
- 'All inputs have to contain the same merging assets',
213
- treasuryMergeTx(context, sysParams, [
214
- mkLovelacesOf(5_000_000n),
215
- addAssets(
216
- mkLovelacesOf(5_000_000n),
217
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
218
- ),
219
- addAssets(
220
- mkLovelacesOf(5_000_000n),
221
- mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000n),
222
- ),
223
- ]),
224
- );
225
- });
226
-
227
- test<MyContext>('Split (12 assets)', async (context: MyContext) => {
228
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
229
-
230
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
231
-
232
- await benchmarkAndAwaitTx(
233
- 'Treasury - Split (12 assets)',
234
- await treasurySplitTx(
235
- context,
236
- sysParams,
237
- addAssets(
238
- mkLovelacesOf(5_000_000n),
239
- mkAssetsOf(testAssetA, 1n),
240
- mkAssetsOf(testAssetB, 1n),
241
- mkAssetsOf(testAssetC, 1n),
242
- mkAssetsOf(testAssetD, 1n),
243
- mkAssetsOf(testAssetE, 1n),
244
- mkAssetsOf(testAssetF, 1n),
245
- mkAssetsOf(testAssetG, 1n),
246
- mkAssetsOf(testAssetH, 1n),
247
- mkAssetsOf(testAssetI, 1n),
248
- mkAssetsOf(testAssetJ, 1n),
249
- mkAssetsOf(testAssetK, 1n),
250
- ),
251
- ),
252
- context.lucid,
253
- context.emulator,
254
- );
255
- });
256
-
257
- test<MyContext>('Split (fail, lovelace only)', async (context: MyContext) => {
258
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
259
-
260
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
261
-
262
- await expectScriptFailure(
263
- 'All inputs must have more than 1 non-ADA asset or 1 non-ADA asset and more than 2x ADA buffer',
264
- treasurySplitTx(context, sysParams, mkLovelacesOf(5_000_000n)),
265
- );
266
- });
267
-
268
- test<MyContext>('Collect non-positive amount or negative extra lovelaces fails', async (context: MyContext) => {
269
- const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
270
-
271
- context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
272
-
273
- const treasuryUTxO = await findRandomTreasuryUtxoWithOnlyAda(
274
- context.lucid,
275
- sysParams,
276
- );
277
-
278
- // This tests that the amount to collect cannot be negative.
279
- await expectScriptFailure(
280
- 'Collected amount is positive',
281
- treasuryCollect(
282
- adaAssetClass,
283
- -1_000_000n,
284
- 0n,
285
- context.lucid,
286
- sysParams,
287
- treasuryUTxO,
288
- treasuryUTxO,
289
- ),
290
- );
291
-
292
- // This tests that the amount to collect cannot be zero.
293
- await expectScriptFailure(
294
- 'Collected amount is positive',
295
- treasuryCollect(
296
- adaAssetClass,
297
- 0n,
298
- 0n,
299
- context.lucid,
300
- sysParams,
301
- treasuryUTxO,
302
- treasuryUTxO,
303
- ),
304
- );
305
-
306
- // This tests that the extra lovelaces cannot be negative.
307
- await expectScriptFailure(
308
- 'Collected amount is positive',
309
- treasuryCollect(
310
- adaAssetClass,
311
- 1n,
312
- -1_000_000n,
313
- context.lucid,
314
- sysParams,
315
- treasuryUTxO,
316
- treasuryUTxO,
317
- ),
318
- );
319
- });
320
- });
@@ -1,87 +0,0 @@
1
- import {
2
- isAssetsZero,
3
- lovelacesAmt,
4
- negateAssets,
5
- noAdaValue,
6
- } from '@3rd-eye-labs/cardano-offchain-common';
7
- import { addAssets, Assets, TxBuilder } from '@lucid-evolution/lucid';
8
- import { JSONStringify } from 'json-with-bigint';
9
- import { match, P } from 'ts-pattern';
10
- import { assert, expect } from 'vitest';
11
-
12
- export async function expectScriptFailure(
13
- /**
14
- * This doesn't have to be full message, can be just a part of it.
15
- */
16
- contains: string,
17
- tx: Promise<TxBuilder>,
18
- ): Promise<void> {
19
- if (contains.length === 0) {
20
- throw new Error('Expected error message has to be non empty.');
21
- }
22
-
23
- const result = await (await tx).completeSafe();
24
-
25
- const errMsg = match(result)
26
- .with({ _tag: 'Left', left: P.select() }, (smth) => smth.message)
27
- .otherwise(() => null);
28
-
29
- if (!errMsg) {
30
- throw new Error(`Expected TX to fail, but it succeeded.`);
31
- }
32
-
33
- if (!errMsg.includes(contains)) {
34
- throw new Error(
35
- `Expected TX to fail with error containing: "${contains}". But got: "${errMsg}"`,
36
- );
37
- }
38
- }
39
-
40
- export function assertValueInRange<T extends number | bigint>(
41
- val: T,
42
- bounds: { min: T; max: T },
43
- ): void {
44
- assert(bounds.max > bounds.min, 'Bounds are incorrectly configured.');
45
-
46
- expect(
47
- bounds.min <= val && val <= bounds.max,
48
- `${val} not in range [${bounds.min}, ${bounds.max}]`,
49
- ).toBeTruthy();
50
- }
51
-
52
- export function expectValue(
53
- actual: Assets,
54
- msg: string,
55
- ): {
56
- toEqual: (expected: Assets) => void;
57
- /**
58
- * The non ADA part of value has to equal and the lovelace has to be less than or equal than
59
- * the expected `maxLovelace`.
60
- */
61
- toEqualNonAdaAndMaxAda: (constraints: {
62
- expectedNonAda: Assets;
63
- maxLovelace: bigint;
64
- }) => void;
65
- } {
66
- return {
67
- toEqual(expected) {
68
- expect(
69
- isAssetsZero(addAssets(actual, negateAssets(expected))),
70
- `${msg}: Expected ${JSONStringify(actual)} to equal ${JSONStringify(expected)}`,
71
- ).toBeTruthy();
72
- },
73
- toEqualNonAdaAndMaxAda({ expectedNonAda, maxLovelace }) {
74
- expect(
75
- isAssetsZero(
76
- addAssets(noAdaValue(actual), negateAssets(expectedNonAda)),
77
- ),
78
- `${msg}: Expected no ADA part of ${JSONStringify(actual)} to equal ${JSONStringify(expectedNonAda)}`,
79
- ).toBeTruthy();
80
-
81
- expect(
82
- lovelacesAmt(actual),
83
- `${msg}: Lovelace part is more than expected`,
84
- ).toBeLessThanOrEqual(maxLovelace);
85
- },
86
- };
87
- }
@@ -1,130 +0,0 @@
1
- import {
2
- EvalRedeemer,
3
- LucidEvolution,
4
- Provider,
5
- TxBuilder,
6
- TxSignBuilder,
7
- } from '@lucid-evolution/lucid';
8
- import { array as A } from 'fp-ts';
9
- import { BENCHMARK_RESULTS } from '../setup';
10
- import { MAINNET_PROTOCOL_PARAMETERS } from '../indigo-test-helpers';
11
-
12
- type ExUnits = { mem: number; steps: number; txSize: number };
13
-
14
- export async function calculateTxExUnits(
15
- provider: Provider,
16
- tx: TxSignBuilder,
17
- ): Promise<ExUnits> {
18
- const cbor = tx.toCBOR();
19
- const redeemersEval = await provider.evaluateTx(tx.toCBOR());
20
-
21
- const res = A.reduce<EvalRedeemer, ExUnits>(
22
- { mem: 0, steps: 0, txSize: 0 },
23
- (acc, e) => {
24
- return {
25
- mem: acc.mem + e.ex_units.mem,
26
- steps: acc.steps + e.ex_units.steps,
27
- txSize: 0,
28
- };
29
- },
30
- )(redeemersEval);
31
-
32
- return { ...res, txSize: cbor.length / 2 };
33
- }
34
-
35
- export type BenchmarkResult = ExUnits & {
36
- memPercentage: number;
37
- stepsPercentage: number;
38
- sizePercentage: number;
39
- };
40
-
41
- // This function is used to benchmark a transaction and await it's successful execution.
42
- export async function benchmarkAndAwaitTx(
43
- name: string,
44
- tx: TxBuilder,
45
- lucid: LucidEvolution,
46
- provider: Provider,
47
- extraSigners: string[] = [],
48
- ): Promise<void> {
49
- // Complete the transaction
50
- const bTx = await tx.complete();
51
- const signatures = [await bTx.partialSign.withWallet()];
52
- for (const signer of extraSigners) {
53
- lucid.selectWallet.fromSeed(signer);
54
- signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
55
- }
56
-
57
- const signedTx = bTx.assemble(signatures);
58
-
59
- // Calculate execution units
60
- const exUnits = await calculateTxExUnits(provider, signedTx);
61
-
62
- // Get protocol parameters for percentages
63
- const protocolParams = await provider.getProtocolParameters();
64
-
65
- if (protocolParams.maxTxExMem !== MAINNET_PROTOCOL_PARAMETERS.maxTxExMem) {
66
- throw new Error('Protocol parameters do not match Mainnet');
67
- }
68
-
69
- // Calculate percentages
70
- const result = {
71
- ...exUnits,
72
- memPercentage: (exUnits.mem / Number(protocolParams.maxTxExMem)) * 100,
73
- stepsPercentage:
74
- (exUnits.steps / Number(protocolParams.maxTxExSteps)) * 100,
75
- sizePercentage: (exUnits.txSize / Number(protocolParams.maxTxSize)) * 100,
76
- };
77
-
78
- BENCHMARK_RESULTS[name] = result;
79
-
80
- await lucid.awaitTx(await (await signedTx.complete()).submit());
81
- }
82
-
83
- // This function is used to benchmark a transaction and await it's successful execution,
84
- // as well as to query the transaction fee.
85
- export async function benchmarkAndAwaitTxWithTxFee(
86
- name: string,
87
- tx: TxBuilder,
88
- lucid: LucidEvolution,
89
- provider: Provider,
90
- extraSigners: string[] = [],
91
- ): Promise<bigint> {
92
- // Complete the transaction
93
- const bTx = await tx.complete();
94
- const signatures = [await bTx.partialSign.withWallet()];
95
- for (const signer of extraSigners) {
96
- lucid.selectWallet.fromSeed(signer);
97
- signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
98
- }
99
-
100
- const signedTx = bTx.assemble(signatures);
101
-
102
- // Calculate execution units
103
- const exUnits = await calculateTxExUnits(provider, signedTx);
104
-
105
- // Get protocol parameters for percentages
106
- const protocolParams = await provider.getProtocolParameters();
107
-
108
- if (protocolParams.maxTxExMem !== MAINNET_PROTOCOL_PARAMETERS.maxTxExMem) {
109
- throw new Error('Protocol parameters do not match Mainnet');
110
- }
111
-
112
- // Calculate percentages
113
- const result = {
114
- ...exUnits,
115
- memPercentage: (exUnits.mem / Number(protocolParams.maxTxExMem)) * 100,
116
- stepsPercentage:
117
- (exUnits.steps / Number(protocolParams.maxTxExSteps)) * 100,
118
- sizePercentage: (exUnits.txSize / Number(protocolParams.maxTxSize)) * 100,
119
- };
120
-
121
- BENCHMARK_RESULTS[name] = result;
122
-
123
- const completedTx = await signedTx.complete();
124
-
125
- const txFee = completedTx.toTransaction().body().fee();
126
-
127
- await lucid.awaitTx(await completedTx.submit());
128
-
129
- return txFee;
130
- }
@@ -1,168 +0,0 @@
1
- import {
2
- negateAssets,
3
- noAdaValue,
4
- } from '@3rd-eye-labs/cardano-offchain-common';
5
- import {
6
- addAssets,
7
- Assets,
8
- credentialToAddress,
9
- getAddressDetails,
10
- LucidEvolution,
11
- paymentCredentialOf,
12
- UTxO,
13
- } from '@lucid-evolution/lucid';
14
- import { array as A, function as F } from 'fp-ts';
15
- import { zipWith } from 'fp-ts/lib/Array';
16
- import { runAndAwaitTxBuilder } from '../test-helpers';
17
-
18
- /**
19
- * In case passing in address with stake credential, the non stake credential address
20
- * is used as well for collecting inputs but cannot increase its value.
21
- */
22
- export async function getValueChangeAtAddressAfterAction<T>(
23
- lucid: LucidEvolution,
24
- address: string,
25
- action: () => Promise<T>,
26
- ): Promise<[T, Assets]> {
27
- const hasStakeCred = getAddressDetails(address).stakeCredential != null;
28
-
29
- const valBefore = A.reduce<UTxO, Assets>({}, (acc, utxo) =>
30
- addAssets(acc, utxo.assets),
31
- )(await lucid.utxosAt(address));
32
-
33
- const [res, nonStakeCredValChange] = hasStakeCred
34
- ? await getValueChangeAtAddressAfterAction(
35
- lucid,
36
- credentialToAddress(
37
- lucid.config().network!,
38
- paymentCredentialOf(address),
39
- ),
40
- action,
41
- )
42
- : [await action(), {}];
43
-
44
- if (
45
- hasStakeCred &&
46
- !Object.entries(nonStakeCredValChange).every(([_, amt]) => amt <= 0n)
47
- ) {
48
- throw new Error("Can't add value to the address without stake credential");
49
- }
50
-
51
- const valAfter = A.reduce<UTxO, Assets>({}, (acc, utxo) =>
52
- addAssets(acc, utxo.assets),
53
- )(await lucid.utxosAt(address));
54
-
55
- return [
56
- res,
57
- addAssets(valAfter, negateAssets(valBefore), nonStakeCredValChange),
58
- ];
59
- }
60
-
61
- export async function getValueChangeAtAddressesAfterAction<T>(
62
- lucid: LucidEvolution,
63
- addresses: string[],
64
- action: () => Promise<T>,
65
- ): Promise<[T, Assets[]]> {
66
- const valsBefore = [];
67
-
68
- for (const address of addresses) {
69
- const utxos = await lucid.utxosAt(address);
70
- valsBefore.push(
71
- F.pipe(
72
- utxos,
73
- A.reduce<UTxO, Assets>({}, (acc, utxo) => addAssets(acc, utxo.assets)),
74
- ),
75
- );
76
- }
77
-
78
- const res = await action();
79
-
80
- const valsAfter = [];
81
-
82
- for (const address of addresses) {
83
- const utxos = await lucid.utxosAt(address);
84
- valsAfter.push(
85
- F.pipe(
86
- utxos,
87
- A.reduce<UTxO, Assets>({}, (acc, utxo) => addAssets(acc, utxo.assets)),
88
- ),
89
- );
90
- }
91
-
92
- return [
93
- res,
94
- zipWith(valsBefore, valsAfter, (valBefore, valAfter) =>
95
- addAssets(valAfter, negateAssets(valBefore)),
96
- ),
97
- ];
98
- }
99
-
100
- export async function getNewUtxosAtAddressAfterAction<T>(
101
- lucid: LucidEvolution,
102
- address: string,
103
- action: () => Promise<T>,
104
- ): Promise<[T, UTxO[]]> {
105
- const utxosBefore = await lucid.utxosAt(address);
106
-
107
- const res = await action();
108
-
109
- const utxosAfter = await lucid.utxosAt(address);
110
-
111
- return [
112
- res,
113
- utxosAfter.filter(
114
- (utxo) =>
115
- utxosBefore.filter(
116
- (oldUtxo) =>
117
- utxo.txHash === oldUtxo.txHash &&
118
- utxo.outputIndex === oldUtxo.outputIndex,
119
- ).length === 0,
120
- ),
121
- ];
122
- }
123
-
124
- export async function totalValueAtAddress(
125
- lucid: LucidEvolution,
126
- addr: string,
127
- ): Promise<Assets> {
128
- const utxos = await lucid.utxosAt(addr);
129
-
130
- return F.pipe(
131
- utxos,
132
- A.reduce<UTxO, Assets>({}, (acc, utxo) => addAssets(acc, utxo.assets)),
133
- );
134
- }
135
-
136
- export async function sendValueTo(
137
- destinationAddr: string,
138
- value: Assets,
139
- lucid: LucidEvolution,
140
- ): Promise<void> {
141
- await runAndAwaitTxBuilder(
142
- lucid,
143
- lucid.newTx().pay.ToAddress(destinationAddr, value),
144
- );
145
- }
146
-
147
- /**
148
- * For all the non-ADA assets in current wallet, create a separate UTXo with each of them.
149
- */
150
- export async function fragmentWallet(lucid: LucidEvolution): Promise<void> {
151
- const currentAddr = await lucid.wallet().address();
152
-
153
- const totalVal = await totalValueAtAddress(lucid, currentAddr);
154
-
155
- const otherAssets = Object.keys(noAdaValue(totalVal));
156
-
157
- if (otherAssets.length === 0) return;
158
-
159
- const tx = lucid.newTx();
160
-
161
- for (const asset of otherAssets) {
162
- tx.pay.ToAddress(currentAddr, {
163
- [asset]: totalVal[asset],
164
- });
165
- }
166
-
167
- await runAndAwaitTxBuilder(lucid, tx);
168
- }
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["spec/**/*.spec.ts", "vitest.config.ts"]
4
- }