@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,348 +0,0 @@
1
- import {
2
- addAssets,
3
- Data,
4
- fromHex,
5
- LucidEvolution,
6
- OutRef,
7
- sortUTxOs,
8
- toHex,
9
- TxBuilder,
10
- UTxO,
11
- } from '@lucid-evolution/lucid';
12
- import {
13
- parseStableswapOrderDatumOrThrow,
14
- serialiseStableswapOrderRedeemer,
15
- StableswapOrderDatum,
16
- } from '../../src/contracts/stableswap/types-new';
17
- import {
18
- fromSystemParamsScriptRef,
19
- SystemParams,
20
- treasuryFeeTx,
21
- } from '../../src';
22
- import {
23
- addressToBech32,
24
- assetClassToUnit,
25
- getInlineDatumOrThrow,
26
- lovelacesAmt,
27
- matchSingle,
28
- mkAssetsOf,
29
- mkLovelacesOf,
30
- } from '@3rd-eye-labs/cardano-offchain-common';
31
- import { isEmpty } from 'fp-ts/lib/Array';
32
- import { array as A, function as F } from 'fp-ts';
33
- import { calculateFeeFromRatio } from '../../src/utils/indigo-helpers';
34
- import {
35
- parseStableswapPoolDatumOrThrow,
36
- serialiseCdpRedeemer,
37
- serialiseStableswapPoolDatum,
38
- } from '../../src/contracts/cdp/types-new';
39
- import { createDestinationDatum } from '../../src/contracts/stableswap/helpers';
40
- import {
41
- rationalDiv,
42
- rationalFloor,
43
- rationalFromInt,
44
- rationalMul,
45
- } from '../../src/types/rational';
46
-
47
- type StableswapOrderInfo = {
48
- utxo: UTxO;
49
- datum: StableswapOrderDatum;
50
- suppliedIasset: bigint;
51
- suppliedCollateralAsset: bigint;
52
- };
53
- export type MutatedBatchProcessStableswapOrdersType = {
54
- type: 'exceed-max-execution-fee';
55
- maxExecutionFee: bigint;
56
- };
57
- export async function mutatedBatchProcessStableswapOrders(
58
- stableswapOrderOrefs: OutRef[],
59
- stableswapPoolOref: OutRef,
60
- treasuryOref: OutRef,
61
- sysParams: SystemParams,
62
- lucid: LucidEvolution,
63
- type: MutatedBatchProcessStableswapOrdersType,
64
- ): Promise<TxBuilder> {
65
- const stableswapScriptRefUtxo = matchSingle(
66
- await lucid.utxosByOutRef([
67
- fromSystemParamsScriptRef(
68
- sysParams.scriptReferences.stableswapValidatorRef,
69
- ),
70
- ]),
71
- (_) => new Error('Expected a single Stableswap Ref Script UTXO'),
72
- );
73
-
74
- const cdpScriptRefUtxo = matchSingle(
75
- await lucid.utxosByOutRef([
76
- fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef),
77
- ]),
78
- (_) => new Error('Expected a single CDP Ref Script UTXO'),
79
- );
80
-
81
- const iAssetTokenPolicyRefScriptUtxo = matchSingle(
82
- await lucid.utxosByOutRef([
83
- fromSystemParamsScriptRef(
84
- sysParams.scriptReferences.iAssetTokenPolicyRef,
85
- ),
86
- ]),
87
- (_) => new Error('Expected a single iasset token policy Ref Script UTXO'),
88
- );
89
-
90
- if (isEmpty(stableswapOrderOrefs)) {
91
- throw new Error('At least one order must be provided.');
92
- }
93
-
94
- const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
95
-
96
- const sortedStableswapOrderUtxos = sortUTxOs(
97
- stableswapOrderUtxos,
98
- 'Canonical',
99
- );
100
-
101
- if (sortedStableswapOrderUtxos.length !== stableswapOrderOrefs.length) {
102
- throw new Error('Expected certain number of orders');
103
- }
104
-
105
- const mainOrderUtxo = sortedStableswapOrderUtxos[0];
106
-
107
- const mainOrderDatum = parseStableswapOrderDatumOrThrow(
108
- getInlineDatumOrThrow(mainOrderUtxo),
109
- );
110
-
111
- const iassetAc = {
112
- currencySymbol: fromHex(
113
- sysParams.stableswapParams.iassetSymbol.unCurrencySymbol,
114
- ),
115
- tokenName: mainOrderDatum.iasset,
116
- };
117
-
118
- const collateralAc = mainOrderDatum.collateralAsset;
119
-
120
- const ordersInfo: StableswapOrderInfo[] = sortedStableswapOrderUtxos.map(
121
- (orderUtxo) => {
122
- const orderDatum = parseStableswapOrderDatumOrThrow(
123
- getInlineDatumOrThrow(orderUtxo),
124
- );
125
-
126
- if (
127
- toHex(orderDatum.iasset) != toHex(mainOrderDatum.iasset) ||
128
- toHex(orderDatum.collateralAsset.currencySymbol) !=
129
- toHex(mainOrderDatum.collateralAsset.currencySymbol) ||
130
- toHex(orderDatum.collateralAsset.tokenName) !=
131
- toHex(mainOrderDatum.collateralAsset.tokenName)
132
- ) {
133
- throw new Error('Wrong batch of orders');
134
- }
135
-
136
- const suppliedIasset = orderUtxo.assets[assetClassToUnit(iassetAc)] ?? 0n;
137
- const suppliedCollateralAsset =
138
- orderUtxo.assets[assetClassToUnit(collateralAc)] ?? 0n;
139
-
140
- if (
141
- (suppliedIasset != 0n && suppliedCollateralAsset != 0n) ||
142
- (suppliedIasset == 0n && suppliedCollateralAsset == 0n)
143
- ) {
144
- throw new Error(
145
- 'An order must supply either iAsset or collateral asset',
146
- );
147
- }
148
-
149
- return {
150
- utxo: orderUtxo,
151
- datum: orderDatum,
152
- suppliedIasset: suppliedIasset,
153
- suppliedCollateralAsset: suppliedCollateralAsset,
154
- };
155
- },
156
- );
157
-
158
- const totalSuppliedAssets = F.pipe(
159
- ordersInfo,
160
- A.reduce<StableswapOrderInfo, [bigint, bigint]>(
161
- [0n, 0n],
162
- (acc, orderInfo) => [
163
- acc[0] + orderInfo.suppliedIasset,
164
- acc[1] + orderInfo.suppliedCollateralAsset,
165
- ],
166
- ),
167
- );
168
-
169
- const totalSuppliedIasset = totalSuppliedAssets[0];
170
-
171
- const totalSuppliedCollateralAsset = totalSuppliedAssets[1];
172
-
173
- const stableswapPoolUtxo = matchSingle(
174
- await lucid.utxosByOutRef([stableswapPoolOref]),
175
- (_) => new Error('Expected a single cdp UTXO'),
176
- );
177
-
178
- const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
179
- getInlineDatumOrThrow(stableswapPoolUtxo),
180
- );
181
-
182
- const redemptionFee = calculateFeeFromRatio(
183
- stableswapPoolDatum.redemptionFeeRatio,
184
- totalSuppliedIasset,
185
- );
186
-
187
- const totalEffectiveSuppliedIasset = totalSuppliedIasset - redemptionFee;
188
-
189
- const collateralAmtChangePool =
190
- totalSuppliedCollateralAsset -
191
- rationalFloor(
192
- rationalMul(
193
- rationalFromInt(totalEffectiveSuppliedIasset),
194
- stableswapPoolDatum.collateralToIassetRatio,
195
- ),
196
- );
197
-
198
- const amountToMint =
199
- rationalFloor(
200
- rationalDiv(
201
- rationalFromInt(totalSuppliedCollateralAsset),
202
- stableswapPoolDatum.collateralToIassetRatio,
203
- ),
204
- ) - totalEffectiveSuppliedIasset;
205
-
206
- const mintingFee = calculateFeeFromRatio(
207
- stableswapPoolDatum.mintingFeeRatio,
208
- amountToMint,
209
- );
210
-
211
- const tx = lucid
212
- .newTx()
213
- .readFrom([
214
- stableswapScriptRefUtxo,
215
- cdpScriptRefUtxo,
216
- iAssetTokenPolicyRefScriptUtxo,
217
- ])
218
- .collectFrom([stableswapPoolUtxo], {
219
- kind: 'selected',
220
- makeRedeemer: (inputIndices) =>
221
- serialiseCdpRedeemer({
222
- Stableswap: {
223
- forwardingInputIndex: inputIndices[0],
224
- },
225
- }),
226
- inputs: [mainOrderUtxo],
227
- })
228
- .pay.ToContract(
229
- stableswapPoolUtxo.address,
230
- {
231
- kind: 'inline',
232
- value: serialiseStableswapPoolDatum(stableswapPoolDatum),
233
- },
234
- collateralAmtChangePool != 0n
235
- ? addAssets(
236
- stableswapPoolUtxo.assets,
237
- mkAssetsOf(collateralAc, collateralAmtChangePool),
238
- )
239
- : stableswapPoolUtxo.assets,
240
- );
241
-
242
- const fee = mintingFee + redemptionFee;
243
-
244
- if (fee > 0) {
245
- await treasuryFeeTx(
246
- iassetAc,
247
- fee,
248
- 0n,
249
- lucid,
250
- sysParams,
251
- tx,
252
- stableswapPoolOref,
253
- treasuryOref,
254
- );
255
- }
256
-
257
- if (amountToMint != 0n) {
258
- tx.mintAssets(mkAssetsOf(iassetAc, amountToMint), Data.void());
259
- }
260
-
261
- F.pipe(
262
- ordersInfo,
263
- A.reduce<StableswapOrderInfo, TxBuilder>(tx, (acc, orderInfo) => {
264
- const iassetSupplied =
265
- orderInfo.utxo.assets[assetClassToUnit(iassetAc)] ?? 0n;
266
-
267
- const collateralAssetSupplied =
268
- orderInfo.utxo.assets[assetClassToUnit(collateralAc)] ?? 0n;
269
-
270
- const isMinting = iassetSupplied > 0n ? false : true;
271
-
272
- const iAssetEquivalentSupplied = isMinting
273
- ? rationalFloor(
274
- rationalDiv(
275
- rationalFromInt(collateralAssetSupplied),
276
- stableswapPoolDatum.collateralToIassetRatio,
277
- ),
278
- )
279
- : iassetSupplied;
280
-
281
- const effectiveiAssetEquivalentSupplied = isMinting
282
- ? iAssetEquivalentSupplied -
283
- calculateFeeFromRatio(
284
- stableswapPoolDatum.mintingFeeRatio,
285
- iAssetEquivalentSupplied,
286
- )
287
- : iAssetEquivalentSupplied -
288
- calculateFeeFromRatio(
289
- stableswapPoolDatum.redemptionFeeRatio,
290
- iAssetEquivalentSupplied,
291
- );
292
-
293
- const amountToReceive = isMinting
294
- ? effectiveiAssetEquivalentSupplied
295
- : rationalFloor(
296
- rationalMul(
297
- rationalFromInt(effectiveiAssetEquivalentSupplied),
298
- stableswapPoolDatum.collateralToIassetRatio,
299
- ),
300
- );
301
-
302
- const maxExecutionFee =
303
- type.type === 'exceed-max-execution-fee'
304
- ? type.maxExecutionFee
305
- : orderInfo.datum.maxExecutionFee;
306
-
307
- return acc
308
- .collectFrom(
309
- [orderInfo.utxo],
310
- orderInfo.utxo == mainOrderUtxo
311
- ? serialiseStableswapOrderRedeemer('BatchProcessStableswapOrders')
312
- : {
313
- kind: 'selected',
314
- makeRedeemer: (inputIndices: bigint[]) => {
315
- return serialiseStableswapOrderRedeemer({
316
- BatchAuxiliary: {
317
- ownInputIndex: inputIndices[0],
318
- mainOrderInputIndex: inputIndices[1],
319
- },
320
- });
321
- },
322
- inputs: [orderInfo.utxo, mainOrderUtxo],
323
- },
324
- )
325
- .pay.ToAddressWithData(
326
- addressToBech32(orderInfo.datum.destination, lucid.config().network!),
327
- {
328
- kind: 'inline',
329
- value: createDestinationDatum(
330
- orderInfo.datum.destinationInlineDatum ?? null,
331
- orderInfo.utxo,
332
- ),
333
- },
334
- addAssets(
335
- // Currently, we always take the max execution fee from the order utxo.
336
- // This can be improved so that we take the actual execution fee.
337
- mkLovelacesOf(
338
- lovelacesAmt(orderInfo.utxo.assets) - maxExecutionFee,
339
- ),
340
- isMinting
341
- ? mkAssetsOf(iassetAc, amountToReceive)
342
- : mkAssetsOf(collateralAc, amountToReceive),
343
- ),
344
- );
345
- }),
346
- );
347
- return tx;
348
- }
@@ -1,172 +0,0 @@
1
- import { beforeEach, expect, test } from 'vitest';
2
- import { IndigoTestContext, runAndAwaitTx } from './test-helpers';
3
- import { addrDetails } from '../src/utils/lucid-utils';
4
- import { findStakingPosition } from './queries/staking-queries';
5
- import {
6
- adjustStakingPosition,
7
- closeStakingPosition,
8
- distributeAda,
9
- openStakingPosition,
10
- } from '../src/contracts/staking/transactions';
11
- import {
12
- collectorFeeTx,
13
- findStakingManager,
14
- fromSystemParamsAsset,
15
- } from '../src';
16
- import { createIndigoTestContext } from './indigo-test-helpers';
17
- import { benchmarkAndAwaitTx } from './utils/benchmark-utils';
18
- import {
19
- findAllCollectors,
20
- findRandomCollector,
21
- } from './queries/collector-queries';
22
- import { getValueChangeAtAddressAfterAction, sendValueTo } from './utils';
23
- import {
24
- lovelacesAmt,
25
- mkAssetsOf,
26
- } from '@3rd-eye-labs/cardano-offchain-common';
27
-
28
- beforeEach<IndigoTestContext>(async (context: IndigoTestContext) => {
29
- await createIndigoTestContext(context);
30
- });
31
-
32
- test<IndigoTestContext>('Staking - Create Position', async ({
33
- lucid,
34
- emulator,
35
- systemParams,
36
- }: IndigoTestContext) => {
37
- await benchmarkAndAwaitTx(
38
- 'Staking - Create Position',
39
- await openStakingPosition(1_000_000n, systemParams, lucid),
40
- lucid,
41
- emulator,
42
- );
43
- });
44
-
45
- test<IndigoTestContext>('Staking - Adjust Position', async ({
46
- lucid,
47
- emulator,
48
- systemParams,
49
- }: IndigoTestContext) => {
50
- await runAndAwaitTx(
51
- lucid,
52
- openStakingPosition(1_000_000n, systemParams, lucid),
53
- );
54
-
55
- const [pkh, __] = await addrDetails(lucid);
56
- const myStakingPosition = await findStakingPosition(
57
- lucid,
58
- systemParams.validatorHashes.stakingHash,
59
- fromSystemParamsAsset(systemParams.stakingParams.stakingToken),
60
- pkh.hash,
61
- );
62
-
63
- await benchmarkAndAwaitTx(
64
- 'Staking - Adjust Position',
65
- await adjustStakingPosition(
66
- myStakingPosition.utxo,
67
- 1_000_000n,
68
- systemParams,
69
- lucid,
70
- ),
71
- lucid,
72
- emulator,
73
- );
74
- });
75
-
76
- // TODO: fails with the Lucid Evolution error: `Error: Not enough ADA leftover to include non-ADA assets in a change address`
77
- test.todo<IndigoTestContext>(
78
- 'Staking - Close Position',
79
- async ({ lucid, emulator, systemParams, users }: IndigoTestContext) => {
80
- lucid.selectWallet.fromSeed(users.admin.seedPhrase);
81
-
82
- await sendValueTo(
83
- users.user2.address,
84
- mkAssetsOf(
85
- fromSystemParamsAsset(systemParams.govParams.indyAsset),
86
- 1_000_000n,
87
- ),
88
- lucid,
89
- );
90
-
91
- lucid.selectWallet.fromSeed(users.user2.seedPhrase);
92
-
93
- await runAndAwaitTx(
94
- lucid,
95
- openStakingPosition(1_000_000n, systemParams, lucid),
96
- );
97
-
98
- const [pkh, __] = await addrDetails(lucid);
99
- const myStakingPosition = await findStakingPosition(
100
- lucid,
101
- systemParams.validatorHashes.stakingHash,
102
- fromSystemParamsAsset(systemParams.stakingParams.stakingToken),
103
- pkh.hash,
104
- );
105
-
106
- await benchmarkAndAwaitTx(
107
- 'Staking - Close Position',
108
- await closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
109
- lucid,
110
- emulator,
111
- );
112
- },
113
- );
114
-
115
- test<IndigoTestContext>('Staking - Distribute ADA to Stakers', async ({
116
- lucid,
117
- users,
118
- emulator,
119
- systemParams,
120
- }: IndigoTestContext) => {
121
- await runAndAwaitTx(
122
- lucid,
123
- openStakingPosition(1_000_000n, systemParams, lucid),
124
- );
125
-
126
- const collectorOref = await findRandomCollector(
127
- lucid,
128
- systemParams.validatorHashes.collectorHash,
129
- );
130
- const tx = lucid.newTx();
131
- await collectorFeeTx(100_000_000n, lucid, systemParams, tx, collectorOref);
132
- await runAndAwaitTx(lucid, Promise.resolve(tx));
133
-
134
- const collectorUtxo = (
135
- await findAllCollectors(lucid, systemParams.validatorHashes.collectorHash)
136
- ).find((utxo) => utxo.assets['lovelace'] > 100_000_000n);
137
- if (!collectorUtxo) {
138
- throw new Error('Expected a collector UTXO');
139
- }
140
-
141
- await benchmarkAndAwaitTx(
142
- 'Staking - Distribute ADA to Stakers',
143
- await distributeAda(
144
- (await findStakingManager(systemParams, lucid)).utxo,
145
- [collectorUtxo],
146
- systemParams,
147
- lucid,
148
- ),
149
- lucid,
150
- emulator,
151
- );
152
-
153
- const [pkh, __] = await addrDetails(lucid);
154
- const myStakingPosition = await findStakingPosition(
155
- lucid,
156
- systemParams.validatorHashes.stakingHash,
157
- fromSystemParamsAsset(systemParams.stakingParams.stakingToken),
158
- pkh.hash,
159
- );
160
-
161
- const [____, userValChange] = await getValueChangeAtAddressAfterAction(
162
- lucid,
163
- users.admin.address,
164
- () =>
165
- runAndAwaitTx(
166
- lucid,
167
- closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
168
- ),
169
- );
170
-
171
- expect(lovelacesAmt(userValChange)).toBeGreaterThan(95_000_000n); // There is some loss due to tx fees.
172
- });
@@ -1,94 +0,0 @@
1
- import {
2
- Emulator,
3
- EmulatorAccount,
4
- LucidEvolution,
5
- TxBuilder,
6
- } from '@lucid-evolution/lucid';
7
- import { AssetInfo } from '../src/contracts/initialize/types';
8
- import { SystemParams } from '../src';
9
- import { array as A, function as F, option as O } from 'fp-ts';
10
-
11
- type EmulatorAccountMap = Record<string, EmulatorAccount> & {
12
- admin: EmulatorAccount;
13
- };
14
-
15
- export type LucidContext<T extends EmulatorAccountMap = EmulatorAccountMap> = {
16
- lucid: LucidEvolution;
17
- users: T;
18
- emulator: Emulator;
19
- };
20
-
21
- export type IndigoTestContext = LucidContext<{
22
- admin: EmulatorAccount;
23
- user: EmulatorAccount;
24
- user2: EmulatorAccount;
25
- withdrawalAccount: EmulatorAccount;
26
- }> & {
27
- systemParams: SystemParams;
28
- assetConfigs: readonly AssetInfo[];
29
- };
30
-
31
- export async function runAndAwaitTx(
32
- lucid: LucidEvolution,
33
- transaction: Promise<TxBuilder>,
34
- extraSigners: string[] = [],
35
- ): Promise<string> {
36
- const bTx = await (await transaction).complete();
37
-
38
- const signatures = [await bTx.partialSign.withWallet()];
39
- for (const signer of extraSigners) {
40
- lucid.selectWallet.fromSeed(signer);
41
- signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
42
- }
43
-
44
- const signedTx = bTx.assemble(signatures);
45
-
46
- const txHash = await signedTx.complete().then((tx) => tx.submit());
47
-
48
- await lucid.awaitTx(txHash);
49
- return txHash;
50
- }
51
-
52
- export async function runAndAwaitTxBuilder(
53
- lucid: LucidEvolution,
54
- transaction: TxBuilder,
55
- extraSigners: string[] = [],
56
- ): Promise<string> {
57
- const bTx = await transaction.complete();
58
-
59
- const signatures = [await bTx.partialSign.withWallet()];
60
- for (const signer of extraSigners) {
61
- lucid.selectWallet.fromSeed(signer);
62
- signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
63
- }
64
-
65
- const signedTx = bTx.assemble(signatures);
66
-
67
- const txHash = await signedTx.complete().then((tx) => tx.submit());
68
-
69
- await lucid.awaitTx(txHash);
70
- return txHash;
71
- }
72
-
73
- export async function repeat(
74
- times: number,
75
- action: (isLast: boolean, idx: number) => Promise<void>,
76
- ): Promise<void> {
77
- for (let i = 0; i < times; i++) {
78
- await action(i === times - 1, i);
79
- }
80
- }
81
-
82
- export function selectWalletByAddress(
83
- context: LucidContext,
84
- addr: string,
85
- ): void {
86
- const account = F.pipe(
87
- Object.values(context.users),
88
- A.findFirst((account) => account.address === addr),
89
- O.getOrElse<EmulatorAccount>(() => {
90
- throw new Error('No such account with the given address');
91
- }),
92
- );
93
- context.lucid.selectWallet.fromSeed(account.seedPhrase);
94
- }
@@ -1,67 +0,0 @@
1
- import { Assets, TxBuilder } from '@lucid-evolution/lucid';
2
- import { LucidContext } from '../test-helpers';
3
- import { createUtxoAtTreasury } from '../endpoints/treasury';
4
- import { SystemParams, treasuryMerge, treasurySplit } from '../../src';
5
- import { findAllTreasuryUtxos } from '../../src/contracts/treasury/queries';
6
- import { assert } from 'vitest';
7
-
8
- export async function treasuryMergeTx(
9
- context: LucidContext,
10
- sysParams: SystemParams,
11
- treasuryOutputs: Assets[],
12
- ): Promise<TxBuilder> {
13
- for (const output of treasuryOutputs) {
14
- await createUtxoAtTreasury(output, sysParams, context);
15
- }
16
-
17
- const treasuryUtxos = await findAllTreasuryUtxos(context.lucid, sysParams);
18
-
19
- // Simpler approach: for each expected output in treasuryOutputs, find one UTxO with exactly matching assets and take it
20
- // Find UTxOs for each expected output, but remove it from the candidate list as we match
21
- const availableUtxos = [...treasuryUtxos];
22
- const matchedTreasuryUtxos = treasuryOutputs
23
- .map((expectedAssets) => {
24
- const idx = availableUtxos.findIndex((utxo) => {
25
- const utxoAssets = utxo.assets;
26
- const keys1 = Object.keys(utxoAssets).sort();
27
- const keys2 = Object.keys(expectedAssets).sort();
28
- if (keys1.length !== keys2.length) return false;
29
- return keys1.every(
30
- (k, i) => k === keys2[i] && utxoAssets[k] === expectedAssets[k],
31
- );
32
- });
33
- if (idx !== -1) {
34
- return availableUtxos.splice(idx, 1)[0];
35
- } else {
36
- return undefined;
37
- }
38
- })
39
- .filter((utxo) => utxo !== undefined);
40
-
41
- assert(
42
- matchedTreasuryUtxos.length === treasuryOutputs.length,
43
- 'Expected all treasury outputs to be matched',
44
- );
45
-
46
- return await treasuryMerge(matchedTreasuryUtxos, context.lucid, sysParams);
47
- }
48
-
49
- export async function treasurySplitTx(
50
- context: LucidContext,
51
- sysParams: SystemParams,
52
- treasuryOutput: Assets,
53
- ): Promise<TxBuilder> {
54
- await createUtxoAtTreasury(treasuryOutput, sysParams, context);
55
-
56
- const treasuryUtxos = await findAllTreasuryUtxos(context.lucid, sysParams);
57
-
58
- const matchedTreasuryUtxo = treasuryUtxos.find((utxo) =>
59
- Object.keys(treasuryOutput).every(
60
- (key) => utxo.assets[key] === treasuryOutput[key],
61
- ),
62
- );
63
-
64
- assert(matchedTreasuryUtxo !== undefined, 'Expected a single treasury UTXO');
65
-
66
- return await treasurySplit(matchedTreasuryUtxo, context.lucid, sysParams);
67
- }