@indigo-labs/indigo-sdk 0.5.4 → 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 (208) hide show
  1. package/dist/index.d.mts +11 -1
  2. package/dist/index.d.ts +11 -1
  3. package/dist/index.js +17 -0
  4. package/dist/index.mjs +15 -0
  5. package/package.json +11 -1
  6. package/.claude/settings.local.json +0 -7
  7. package/.github/workflows/ci.yml +0 -66
  8. package/.husky/pre-commit +0 -1
  9. package/.nvmrc +0 -1
  10. package/.prettierignore +0 -1
  11. package/.prettierrc +0 -6
  12. package/eslint.config.mjs +0 -42
  13. package/scripts/bench.sh +0 -62
  14. package/scripts/run-repeat.sh +0 -22
  15. package/src/contracts/cdp/helpers.ts +0 -173
  16. package/src/contracts/cdp/scripts.ts +0 -70
  17. package/src/contracts/cdp/transactions.ts +0 -1584
  18. package/src/contracts/cdp/types-new.ts +0 -277
  19. package/src/contracts/cdp/types.ts +0 -43
  20. package/src/contracts/cdp-creator/queries.ts +0 -30
  21. package/src/contracts/cdp-creator/scripts.ts +0 -45
  22. package/src/contracts/cdp-creator/types-new.ts +0 -50
  23. package/src/contracts/cdp-creator/types.ts +0 -24
  24. package/src/contracts/collector/scripts.ts +0 -32
  25. package/src/contracts/collector/transactions.ts +0 -50
  26. package/src/contracts/collector/types-new.ts +0 -17
  27. package/src/contracts/execute/scripts.ts +0 -57
  28. package/src/contracts/execute/types-new.ts +0 -44
  29. package/src/contracts/execute/types.ts +0 -24
  30. package/src/contracts/gov/helpers.ts +0 -351
  31. package/src/contracts/gov/scripts.ts +0 -41
  32. package/src/contracts/gov/transactions.ts +0 -1607
  33. package/src/contracts/gov/types-new.ts +0 -268
  34. package/src/contracts/gov/types.ts +0 -22
  35. package/src/contracts/iasset/helpers.ts +0 -170
  36. package/src/contracts/iasset/queries.ts +0 -102
  37. package/src/contracts/iasset/scripts.ts +0 -38
  38. package/src/contracts/iasset/types.ts +0 -154
  39. package/src/contracts/initialize/actions.ts +0 -789
  40. package/src/contracts/initialize/helpers.ts +0 -616
  41. package/src/contracts/initialize/types.ts +0 -116
  42. package/src/contracts/interest-collection/helpers.ts +0 -19
  43. package/src/contracts/interest-collection/queries.ts +0 -66
  44. package/src/contracts/interest-collection/scripts.ts +0 -44
  45. package/src/contracts/interest-collection/transactions.ts +0 -433
  46. package/src/contracts/interest-collection/types-new.ts +0 -50
  47. package/src/contracts/interest-collection/types.ts +0 -26
  48. package/src/contracts/interest-oracle/helpers.ts +0 -61
  49. package/src/contracts/interest-oracle/scripts.ts +0 -18
  50. package/src/contracts/interest-oracle/transactions.ts +0 -151
  51. package/src/contracts/interest-oracle/types-new.ts +0 -32
  52. package/src/contracts/interest-oracle/types.ts +0 -16
  53. package/src/contracts/one-shot/scripts.ts +0 -12
  54. package/src/contracts/one-shot/transactions.ts +0 -66
  55. package/src/contracts/one-shot/types.ts +0 -22
  56. package/src/contracts/poll/helpers.ts +0 -37
  57. package/src/contracts/poll/scripts.ts +0 -71
  58. package/src/contracts/poll/types-poll-manager.ts +0 -20
  59. package/src/contracts/poll/types-poll-new.ts +0 -196
  60. package/src/contracts/poll/types-poll-shard.ts +0 -16
  61. package/src/contracts/price-oracle/helpers.ts +0 -30
  62. package/src/contracts/price-oracle/scripts.ts +0 -18
  63. package/src/contracts/price-oracle/transactions.ts +0 -115
  64. package/src/contracts/price-oracle/types-new.ts +0 -50
  65. package/src/contracts/price-oracle/types.ts +0 -16
  66. package/src/contracts/pyth-feed/helpers.ts +0 -82
  67. package/src/contracts/pyth-feed/scripts.ts +0 -15
  68. package/src/contracts/pyth-feed/types.ts +0 -181
  69. package/src/contracts/rob/helpers.ts +0 -666
  70. package/src/contracts/rob/scripts.ts +0 -35
  71. package/src/contracts/rob/transactions.ts +0 -423
  72. package/src/contracts/rob/types-new.ts +0 -128
  73. package/src/contracts/rob/types.ts +0 -16
  74. package/src/contracts/rob-leverage/helpers.ts +0 -422
  75. package/src/contracts/rob-leverage/transactions.ts +0 -368
  76. package/src/contracts/stability-pool/helpers.ts +0 -798
  77. package/src/contracts/stability-pool/queries.ts +0 -132
  78. package/src/contracts/stability-pool/scripts.ts +0 -51
  79. package/src/contracts/stability-pool/transactions.ts +0 -921
  80. package/src/contracts/stability-pool/types-new.ts +0 -385
  81. package/src/contracts/stability-pool/types.ts +0 -25
  82. package/src/contracts/stableswap/helpers.ts +0 -507
  83. package/src/contracts/stableswap/scripts.ts +0 -37
  84. package/src/contracts/stableswap/transactions.ts +0 -475
  85. package/src/contracts/stableswap/types-new.ts +0 -131
  86. package/src/contracts/stableswap/types.ts +0 -17
  87. package/src/contracts/staking/helpers.ts +0 -136
  88. package/src/contracts/staking/scripts.ts +0 -41
  89. package/src/contracts/staking/transactions.ts +0 -349
  90. package/src/contracts/staking/types-new.ts +0 -137
  91. package/src/contracts/staking/types.ts +0 -17
  92. package/src/contracts/treasury/helpers.ts +0 -21
  93. package/src/contracts/treasury/queries.ts +0 -100
  94. package/src/contracts/treasury/scripts.ts +0 -27
  95. package/src/contracts/treasury/transactions.ts +0 -334
  96. package/src/contracts/treasury/types-new.ts +0 -69
  97. package/src/contracts/treasury/types.ts +0 -14
  98. package/src/contracts/version-registry/scripts.ts +0 -29
  99. package/src/contracts/version-registry/types-new.ts +0 -18
  100. package/src/contracts/version-registry/types.ts +0 -17
  101. package/src/index.ts +0 -93
  102. package/src/scripts/always-fail-validator.ts +0 -7
  103. package/src/scripts/auth-token-policy.ts +0 -24
  104. package/src/scripts/iasset-policy.ts +0 -23
  105. package/src/types/evolution-schema-options.ts +0 -16
  106. package/src/types/generic.ts +0 -52
  107. package/src/types/multisig.ts +0 -48
  108. package/src/types/on-chain-decimal.ts +0 -57
  109. package/src/types/rational.ts +0 -61
  110. package/src/types/system-params.ts +0 -463
  111. package/src/utils/array-utils.ts +0 -108
  112. package/src/utils/bigint-utils.ts +0 -35
  113. package/src/utils/helper-txs.ts +0 -31
  114. package/src/utils/indigo-helpers.ts +0 -17
  115. package/src/utils/lucid-utils.ts +0 -125
  116. package/src/utils/oracle-helpers.ts +0 -62
  117. package/src/utils/pyth/decode.ts +0 -223
  118. package/src/utils/pyth/encode.ts +0 -262
  119. package/src/utils/pyth/index.ts +0 -14
  120. package/src/utils/pyth/types.ts +0 -87
  121. package/src/utils/time-helpers.ts +0 -4
  122. package/src/utils/utils.ts +0 -25
  123. package/src/validators/always-succeed-validator.ts +0 -6
  124. package/src/validators/cdp-creator-validator.ts +0 -7
  125. package/src/validators/cdp-redeem-validator.ts +0 -7
  126. package/src/validators/cdp-validator.ts +0 -7
  127. package/src/validators/collector-validator.ts +0 -7
  128. package/src/validators/execute-validator.ts +0 -7
  129. package/src/validators/governance-validator.ts +0 -7
  130. package/src/validators/iasset-validator.ts +0 -7
  131. package/src/validators/interest-collection-validator.ts +0 -7
  132. package/src/validators/interest-oracle-validator.ts +0 -7
  133. package/src/validators/one-shot-policy.ts +0 -7
  134. package/src/validators/poll-manager-validator.ts +0 -7
  135. package/src/validators/poll-shard-validator.ts +0 -7
  136. package/src/validators/price-oracle-validator.ts +0 -7
  137. package/src/validators/pyth-feed-validator.ts +0 -7
  138. package/src/validators/rob-validator.ts +0 -7
  139. package/src/validators/stability-pool-validator.ts +0 -7
  140. package/src/validators/stableswap-validator.ts +0 -7
  141. package/src/validators/staking-validator.ts +0 -7
  142. package/src/validators/treasury-validator.ts +0 -7
  143. package/src/validators/version-record-policy.ts +0 -7
  144. package/src/validators/version-registry-validator.ts +0 -7
  145. package/tests/always-succeed/script.ts +0 -7
  146. package/tests/array-utils.test.ts +0 -92
  147. package/tests/bigint-utils.test.ts +0 -41
  148. package/tests/cdp/actions.ts +0 -680
  149. package/tests/cdp/cdp-helpers.ts +0 -55
  150. package/tests/cdp/cdp-queries.ts +0 -423
  151. package/tests/cdp/cdp.test.ts +0 -6730
  152. package/tests/cdp/transactions-mutated.ts +0 -1733
  153. package/tests/data/system-params.json +0 -1155
  154. package/tests/datums.test.ts +0 -302
  155. package/tests/endpoints/initialize.ts +0 -78
  156. package/tests/endpoints/interest-collector.ts +0 -37
  157. package/tests/endpoints/treasury.ts +0 -70
  158. package/tests/gov/actions.ts +0 -381
  159. package/tests/gov/gov.test.ts +0 -5147
  160. package/tests/gov/governance-queries.ts +0 -37
  161. package/tests/hash-checks.test.ts +0 -112
  162. package/tests/indigo-test-helpers.ts +0 -99
  163. package/tests/initialize.test.ts +0 -79
  164. package/tests/interest-calculations.test.ts +0 -120
  165. package/tests/interest-collection/interest-collection.test.ts +0 -843
  166. package/tests/interest-collection/transactions-mutated.ts +0 -260
  167. package/tests/interest-oracle.test.ts +0 -93
  168. package/tests/mock/assets-mock.ts +0 -243
  169. package/tests/mock/protocol-params-mock.ts +0 -21
  170. package/tests/price-oracle/actions.ts +0 -161
  171. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  172. package/tests/price-oracle/price-oracle.test.ts +0 -228
  173. package/tests/price-oracle/transactions-mutated.ts +0 -59
  174. package/tests/pyth/endpoints.ts +0 -96
  175. package/tests/pyth/helpers.ts +0 -37
  176. package/tests/pyth/pyth-encoding.test.ts +0 -376
  177. package/tests/pyth/pyth-feeds.test.ts +0 -943
  178. package/tests/pyth/pyth-indigo.test.ts +0 -505
  179. package/tests/pyth/pyth.test.ts +0 -299
  180. package/tests/queries/collector-queries.ts +0 -27
  181. package/tests/queries/execute-queries.ts +0 -47
  182. package/tests/queries/iasset-queries.ts +0 -149
  183. package/tests/queries/interest-oracle-queries.ts +0 -12
  184. package/tests/queries/poll-queries.ts +0 -97
  185. package/tests/queries/staking-queries.ts +0 -54
  186. package/tests/rob/actions.ts +0 -56
  187. package/tests/rob/rob-leverage.test.ts +0 -2555
  188. package/tests/rob/rob-queries.ts +0 -95
  189. package/tests/rob/rob.test.ts +0 -3677
  190. package/tests/rob/transactions-mutated.ts +0 -844
  191. package/tests/script-size.test.ts +0 -240
  192. package/tests/setup.ts +0 -135
  193. package/tests/stability-pool/actions.ts +0 -229
  194. package/tests/stability-pool.test.ts +0 -6491
  195. package/tests/stableswap/stableswap-actions.ts +0 -83
  196. package/tests/stableswap/stableswap-queries.ts +0 -98
  197. package/tests/stableswap/stableswap.test.ts +0 -4471
  198. package/tests/stableswap/transactions-mutated.ts +0 -348
  199. package/tests/staking.test.ts +0 -172
  200. package/tests/test-helpers.ts +0 -94
  201. package/tests/treasury/actions.ts +0 -67
  202. package/tests/treasury/treasury.test.ts +0 -320
  203. package/tests/utils/asserts.ts +0 -87
  204. package/tests/utils/benchmark-utils.ts +0 -130
  205. package/tests/utils/index.ts +0 -168
  206. package/tsconfig.build.json +0 -4
  207. package/tsconfig.json +0 -27
  208. package/vitest.config.ts +0 -11
@@ -1,423 +0,0 @@
1
- import {
2
- LucidEvolution,
3
- TxBuilder,
4
- Credential,
5
- OutRef,
6
- addAssets,
7
- fromHex,
8
- toHex,
9
- fromText,
10
- Assets,
11
- getInputIndices,
12
- } from '@lucid-evolution/lucid';
13
- import {
14
- addrDetails,
15
- createScriptAddress,
16
- getInlineDatumOrThrow,
17
- } from '../../utils/lucid-utils';
18
- import {
19
- readonlyArray as RA,
20
- array as A,
21
- function as F,
22
- option as O,
23
- } from 'fp-ts';
24
- import { unzip, zip } from 'fp-ts/lib/Array';
25
- import {
26
- adaAssetClass,
27
- AssetClass,
28
- assetClassValueOf,
29
- isSameAssetClass,
30
- mkAssetsOf,
31
- mkLovelacesOf,
32
- negateAssets,
33
- } from '@3rd-eye-labs/cardano-offchain-common';
34
- import { matchSingle } from '../../utils/utils';
35
- import {
36
- RobDatum,
37
- RobOrderType,
38
- parseRobDatumOrThrow,
39
- serialiseRobDatum,
40
- serialiseRobRedeemer,
41
- } from './types-new';
42
- import {
43
- parseCollateralAssetDatumOrThrow,
44
- parseIAssetDatumOrThrow,
45
- } from '../iasset/types';
46
- import {
47
- fromSystemParamsScriptRef,
48
- SystemParams,
49
- } from '../../types/system-params';
50
- import {
51
- buildRedemptionsTx,
52
- isFullyRedeemed,
53
- MIN_ROB_COLLATERAL_AMT,
54
- robAmtToSpend,
55
- } from './helpers';
56
- import { match, P } from 'ts-pattern';
57
- import { Rational } from '../../types/rational';
58
- import { attachOracle } from '../iasset/helpers';
59
- import { retrieveAdjustedPrice } from '../../utils/oracle-helpers';
60
-
61
- export async function openRob(
62
- assetTokenNameAscii: string,
63
- depositAmt: bigint,
64
- orderType: RobOrderType,
65
- lucid: LucidEvolution,
66
- sysParams: SystemParams,
67
- robStakeCredential?: Credential,
68
- ): Promise<TxBuilder> {
69
- const network = lucid.config().network!;
70
- const [ownPkh, _] = await addrDetails(lucid);
71
-
72
- const newDatum: RobDatum = {
73
- owner: fromHex(ownPkh.hash),
74
- iasset: fromHex(fromText(assetTokenNameAscii)),
75
- orderType: orderType,
76
- robRefInput: {
77
- txHash: fromHex(
78
- '0000000000000000000000000000000000000000000000000000000000000000',
79
- ),
80
- outputIndex: 0n,
81
- },
82
- };
83
-
84
- const depositVal = match(orderType)
85
- .with({ BuyIAssetOrder: P.select() }, (buyContent) =>
86
- mkAssetsOf(buyContent.collateralAsset, depositAmt),
87
- )
88
- .with({ SellIAssetOrder: P.any }, (_) =>
89
- mkAssetsOf(
90
- {
91
- currencySymbol: fromHex(
92
- sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol,
93
- ),
94
- tokenName: newDatum.iasset,
95
- },
96
- depositAmt,
97
- ),
98
- )
99
- .exhaustive();
100
-
101
- return lucid.newTx().pay.ToContract(
102
- createScriptAddress(
103
- network,
104
- sysParams.validatorHashes.robHash,
105
- robStakeCredential,
106
- ),
107
- {
108
- kind: 'inline',
109
- value: serialiseRobDatum(newDatum),
110
- },
111
- addAssets(depositVal, mkLovelacesOf(MIN_ROB_COLLATERAL_AMT)),
112
- );
113
- }
114
-
115
- export async function cancelRob(
116
- robOutRef: OutRef,
117
- sysParams: SystemParams,
118
- lucid: LucidEvolution,
119
- ): Promise<TxBuilder> {
120
- const robScriptRefUtxo = matchSingle(
121
- await lucid.utxosByOutRef([
122
- fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef),
123
- ]),
124
- (_) => new Error('Expected a single ROB Ref Script UTXO'),
125
- );
126
-
127
- const robUtxo = matchSingle(
128
- await lucid.utxosByOutRef([robOutRef]),
129
- (_) => new Error('Expected a single ROB UTXO.'),
130
- );
131
-
132
- const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
133
-
134
- return lucid
135
- .newTx()
136
- .readFrom([robScriptRefUtxo])
137
- .collectFrom([robUtxo], serialiseRobRedeemer('Cancel'))
138
- .addSignerKey(toHex(robDatum.owner));
139
- }
140
-
141
- export async function redeemRob(
142
- /**
143
- * The tuple represents the ROB UTXO and the amount to payout for a redemption. In case of buy order,
144
- * it's denominated in iAssets, in case of sell order, it's denominated in collateral asset.
145
- */
146
- redemptionRobsData: [OutRef, bigint][],
147
- priceOracleOutRef: OutRef | undefined,
148
- iassetOutRef: OutRef,
149
- collateralAssetOutRef: OutRef,
150
- lucid: LucidEvolution,
151
- sysParams: SystemParams,
152
- pythMessage: string | undefined = undefined,
153
- pythStateOutRef: OutRef | undefined = undefined,
154
- ): Promise<TxBuilder> {
155
- const robScriptRefUtxo = matchSingle(
156
- await lucid.utxosByOutRef([
157
- fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef),
158
- ]),
159
- (_) => new Error('Expected a single ROB Ref Script UTXO'),
160
- );
161
-
162
- const iassetUtxo = matchSingle(
163
- await lucid.utxosByOutRef([iassetOutRef]),
164
- (_) => new Error('Expected a single IAsset UTXO'),
165
- );
166
-
167
- const iassetDatum = parseIAssetDatumOrThrow(
168
- getInlineDatumOrThrow(iassetUtxo),
169
- );
170
-
171
- const collateralAssetUtxo = matchSingle(
172
- await lucid.utxosByOutRef([collateralAssetOutRef]),
173
- (_) => new Error('Expected a single collateral asset UTXO'),
174
- );
175
-
176
- const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
177
- getInlineDatumOrThrow(collateralAssetUtxo),
178
- );
179
-
180
- const [robsToRedeemOutRefs, robRedemptionIAssetAmt] =
181
- unzip(redemptionRobsData);
182
-
183
- const [adjustedPrice, _] = await retrieveAdjustedPrice(
184
- iassetDatum.assetName,
185
- collateralAssetDatum.collateralAsset,
186
- collateralAssetDatum.priceInfo,
187
- collateralAssetDatum.extraDecimals,
188
- priceOracleOutRef,
189
- pythMessage,
190
- sysParams.pythConfig,
191
- lucid,
192
- );
193
-
194
- const redemptionRobs = await lucid
195
- .utxosByOutRef(robsToRedeemOutRefs)
196
- .then((val) => zip(val, robRedemptionIAssetAmt));
197
-
198
- const allRefInputs = [robScriptRefUtxo, iassetUtxo, collateralAssetUtxo];
199
-
200
- const tx = lucid.newTx();
201
- const { interval, referenceInputs } = await attachOracle(
202
- iassetDatum.assetName,
203
- collateralAssetDatum.collateralAsset,
204
- collateralAssetDatum.priceInfo,
205
- priceOracleOutRef,
206
- pythStateOutRef,
207
- pythMessage,
208
- sysParams.pythConfig,
209
- sysParams.cdpParams.biasTime,
210
- lucid,
211
- tx,
212
- );
213
-
214
- // Set the validity interval for the transaction
215
- tx.validFrom(interval.validFrom).validTo(interval.validTo);
216
-
217
- // Read from the reference inputs
218
- allRefInputs.push(...referenceInputs);
219
-
220
- const refInputIdxs = getInputIndices(allRefInputs, allRefInputs);
221
-
222
- buildRedemptionsTx(
223
- redemptionRobs,
224
- iassetDatum.assetName,
225
- collateralAssetDatum.collateralAsset,
226
- adjustedPrice,
227
- iassetDatum.redemptionReimbursementRatio,
228
- sysParams,
229
- tx,
230
- 0n,
231
- refInputIdxs[2],
232
- refInputIdxs[1],
233
- priceOracleOutRef !== undefined
234
- ? { OracleRefInputIdx: refInputIdxs[3] }
235
- : 'OracleVoid',
236
- );
237
-
238
- tx.readFrom(allRefInputs);
239
-
240
- return tx;
241
- }
242
-
243
- /**
244
- * Create Tx adjusting the ROB and claiming the received iAssets
245
- */
246
- export async function adjustRob(
247
- lucid: LucidEvolution,
248
- robOutRef: OutRef,
249
- /**
250
- * A positive amount increases the deposit in the ROB,
251
- * and a negative amount takes deposit from the ROB.
252
- */
253
- adjustmentAmt: bigint,
254
- newLimitPrice:
255
- | { BuyOrder: Rational }
256
- | { SellOrder: { newLimitPrices: [AssetClass, Rational][] } }
257
- | undefined,
258
- sysParams: SystemParams,
259
- ): Promise<TxBuilder> {
260
- const robScriptRefUtxo = matchSingle(
261
- await lucid.utxosByOutRef([
262
- fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef),
263
- ]),
264
- (_) => new Error('Expected a single ROB Ref Script UTXO'),
265
- );
266
-
267
- const robUtxo = matchSingle(
268
- await lucid.utxosByOutRef([robOutRef]),
269
- (_) => new Error('Expected a single ROB UTXO.'),
270
- );
271
-
272
- const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
273
-
274
- // The claim case
275
- if (
276
- adjustmentAmt === 0n &&
277
- isFullyRedeemed(robUtxo.assets, robDatum.orderType, {
278
- currencySymbol: fromHex(
279
- sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol,
280
- ),
281
- tokenName: robDatum.iasset,
282
- })
283
- ) {
284
- throw new Error(
285
- "When there's no more lovelaces to spend, use close instead of claim.",
286
- );
287
- }
288
-
289
- // Negative adjust case
290
- if (
291
- adjustmentAmt < 0 &&
292
- robAmtToSpend(robUtxo.assets, robDatum.orderType, {
293
- currencySymbol: fromHex(
294
- sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol,
295
- ),
296
- tokenName: robDatum.iasset,
297
- }) <= -adjustmentAmt
298
- ) {
299
- throw new Error(
300
- "Can't adjust negatively by more than available. Also, for adjusting by exactly the amount deposited, a close action should be used instead.",
301
- );
302
- }
303
-
304
- const iassetAc: AssetClass = {
305
- currencySymbol: fromHex(
306
- sysParams.robParams.iassetPolicyId.unCurrencySymbol,
307
- ),
308
- tokenName: robDatum.iasset,
309
- };
310
-
311
- const [depositAsset, rewardVal] = match(robDatum.orderType)
312
- .returnType<[AssetClass, Assets]>()
313
- .with({ BuyIAssetOrder: P.select() }, (buyContent) => {
314
- const reward = assetClassValueOf(robUtxo.assets, iassetAc);
315
-
316
- return [buyContent.collateralAsset, mkAssetsOf(iassetAc, reward)];
317
- })
318
- .with({ SellIAssetOrder: P.select() }, (content) => {
319
- const reward = F.pipe(
320
- content.allowedCollateralAssets,
321
- RA.reduce<readonly [AssetClass, Rational], Assets>(
322
- {},
323
- (acc, [asset, _]) => {
324
- const amt =
325
- assetClassValueOf(robUtxo.assets, asset) -
326
- // in case of ADA, the min has to stay.
327
- (isSameAssetClass(asset, adaAssetClass)
328
- ? MIN_ROB_COLLATERAL_AMT
329
- : 0n);
330
-
331
- return addAssets(acc, mkAssetsOf(asset, amt));
332
- },
333
- ),
334
- );
335
-
336
- return [iassetAc, reward];
337
- })
338
- .exhaustive();
339
-
340
- return lucid
341
- .newTx()
342
- .readFrom([robScriptRefUtxo])
343
- .collectFrom([robUtxo], serialiseRobRedeemer('Cancel'))
344
- .pay.ToContract(
345
- robUtxo.address,
346
- {
347
- kind: 'inline',
348
- value: serialiseRobDatum({
349
- ...robDatum,
350
- orderType:
351
- newLimitPrice == null
352
- ? robDatum.orderType
353
- : match(robDatum.orderType)
354
- .returnType<RobOrderType>()
355
- .with({ BuyIAssetOrder: P.select() }, (content) => {
356
- const newPrice = match(newLimitPrice)
357
- .with({ BuyOrder: P.select() }, (price) => price)
358
- .otherwise(() => {
359
- throw new Error(
360
- 'Must use buy order price change on buy order.',
361
- );
362
- });
363
-
364
- return {
365
- BuyIAssetOrder: { ...content, maxPrice: newPrice },
366
- };
367
- })
368
- .with({ SellIAssetOrder: P.select() }, (content) => {
369
- const newPrices = match(newLimitPrice)
370
- .with(
371
- { SellOrder: { newLimitPrices: P.select() } },
372
- (prices) => prices,
373
- )
374
- .otherwise(() => {
375
- throw new Error(
376
- 'Must use sell order price change on sell order.',
377
- );
378
- });
379
-
380
- return {
381
- SellIAssetOrder: {
382
- allowedCollateralAssets:
383
- content.allowedCollateralAssets.map((entry) =>
384
- F.pipe(
385
- newPrices,
386
- A.findFirst((newPrice) =>
387
- isSameAssetClass(newPrice[0], entry[0]),
388
- ),
389
- O.match(
390
- () => entry,
391
- (newPrice) =>
392
- [
393
- entry[0],
394
- newPrice[1],
395
- ] satisfies typeof entry,
396
- ),
397
- ),
398
- ),
399
- },
400
- };
401
- })
402
- .exhaustive(),
403
- }),
404
- },
405
- addAssets(
406
- robUtxo.assets,
407
- mkAssetsOf(depositAsset, adjustmentAmt),
408
- negateAssets(rewardVal),
409
- ),
410
- )
411
- .addSignerKey(toHex(robDatum.owner));
412
- }
413
-
414
- /**
415
- * Create Tx claiming the received iAssets.
416
- */
417
- export async function claimRob(
418
- lucid: LucidEvolution,
419
- robOutRef: OutRef,
420
- sysParams: SystemParams,
421
- ): Promise<TxBuilder> {
422
- return adjustRob(lucid, robOutRef, 0n, undefined, sysParams);
423
- }
@@ -1,128 +0,0 @@
1
- import { TSchema, Data } from '@evolution-sdk/evolution';
2
- import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
3
- import {
4
- AssetClassSchema,
5
- OutputReferenceSchema,
6
- } from '@3rd-eye-labs/cardano-offchain-common';
7
- import { option as O, function as F } from 'fp-ts';
8
- import { UTxO } from '@lucid-evolution/lucid';
9
- import { RationalSchema } from '../../types/rational';
10
- import { OracleIdxSchema } from '../price-oracle/types-new';
11
-
12
- const RobOrderTypeSchema = TSchema.Union(
13
- TSchema.Struct(
14
- {
15
- BuyIAssetOrder: TSchema.Struct(
16
- {
17
- collateralAsset: AssetClassSchema,
18
- maxPrice: RationalSchema,
19
- },
20
- { flatFields: true },
21
- ),
22
- },
23
- { flatInUnion: true },
24
- ),
25
- TSchema.Struct(
26
- {
27
- SellIAssetOrder: TSchema.Struct(
28
- {
29
- allowedCollateralAssets: TSchema.Array(
30
- TSchema.Tuple([AssetClassSchema, RationalSchema]),
31
- ),
32
- },
33
- { flatFields: true },
34
- ),
35
- },
36
- { flatInUnion: true },
37
- ),
38
- );
39
-
40
- export type RobOrderType = typeof RobOrderTypeSchema.Type;
41
-
42
- const RobDatumSchema = TSchema.Struct({
43
- owner: TSchema.ByteArray,
44
- iasset: TSchema.ByteArray,
45
- orderType: RobOrderTypeSchema,
46
- robRefInput: OutputReferenceSchema,
47
- });
48
-
49
- export type RobDatum = typeof RobDatumSchema.Type;
50
-
51
- const RobRedeemerSchema = TSchema.Union(
52
- TSchema.Struct(
53
- {
54
- Redeem: TSchema.Struct(
55
- {
56
- ownInputIdx: TSchema.Integer,
57
- collateralAssetRefInputIdx: TSchema.Integer,
58
- iassetRefInputIdx: TSchema.Integer,
59
- continuingOutputIdx: TSchema.Integer,
60
- sellOrderAllowedAssetsIdx: TSchema.Integer,
61
- priceOracleIdx: OracleIdxSchema,
62
- },
63
- { flatFields: true },
64
- ),
65
- },
66
- { flatInUnion: true },
67
- ),
68
- TSchema.Literal('Cancel', { flatInUnion: true }),
69
- TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
70
- );
71
-
72
- export type RobRedeemer = typeof RobRedeemerSchema.Type;
73
-
74
- export function parseRobDatum(datum: string): O.Option<RobDatum> {
75
- try {
76
- return O.some(
77
- Data.withSchema(RobDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
78
- datum,
79
- ),
80
- );
81
- } catch (_) {
82
- return O.none;
83
- }
84
- }
85
-
86
- export function parseRobDatumOrThrow(datum: string): RobDatum {
87
- return F.pipe(
88
- parseRobDatum(datum),
89
- O.match(() => {
90
- throw new Error('Expected an ROB datum.');
91
- }, F.identity),
92
- );
93
- }
94
-
95
- export function serialiseRobDatum(d: RobDatum): string {
96
- return Data.withSchema(RobDatumSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex(d);
97
- }
98
-
99
- export function serialiseRobRedeemer(r: RobRedeemer): string {
100
- return Data.withSchema(RobRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex(
101
- r,
102
- );
103
- }
104
-
105
- export function parseRobRedeemer(
106
- redeemerCborHex: string,
107
- ): O.Option<RobRedeemer> {
108
- try {
109
- return O.some(
110
- Data.withSchema(RobRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
111
- redeemerCborHex,
112
- ),
113
- );
114
- } catch (_) {
115
- return O.none;
116
- }
117
- }
118
-
119
- export function parseRobRedeemerOrThrow(redeemerCborHex: string): RobRedeemer {
120
- return F.pipe(
121
- parseRobRedeemer(redeemerCborHex),
122
- O.match(() => {
123
- throw new Error('Expected an ROB redeemer.');
124
- }, F.identity),
125
- );
126
- }
127
-
128
- export type RobOutput = { datum: RobDatum; utxo: UTxO };
@@ -1,16 +0,0 @@
1
- import { Data } from '@lucid-evolution/lucid';
2
- import { AssetClassSchema } from '../../types/generic';
3
-
4
- export const RobParamsSchema = Data.Object({
5
- versionRecordToken: AssetClassSchema,
6
- iassetAuthToken: AssetClassSchema,
7
- collateralAssetAuthToken: AssetClassSchema,
8
- iassetPolicyId: Data.Bytes(),
9
- iassetValHash: Data.Bytes(),
10
- });
11
- export type RobParams = Data.Static<typeof RobParamsSchema>;
12
- const RobParams = RobParamsSchema as unknown as RobParams;
13
-
14
- export function castRobParams(params: RobParams): Data {
15
- return Data.castTo(params, RobParams);
16
- }