@indigo-labs/indigo-sdk 0.2.42 → 0.3.1

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 (202) hide show
  1. package/.github/workflows/ci.yml +4 -2
  2. package/README.md +88 -15
  3. package/dist/index.d.mts +3012 -2194
  4. package/dist/index.d.ts +3012 -2194
  5. package/dist/index.js +9849 -6198
  6. package/dist/index.mjs +8733 -4933
  7. package/package.json +14 -3
  8. package/src/contracts/cdp/helpers.ts +68 -72
  9. package/src/contracts/cdp/scripts.ts +50 -13
  10. package/src/contracts/cdp/transactions.ts +841 -546
  11. package/src/contracts/cdp/types-new.ts +256 -0
  12. package/src/contracts/cdp/types.ts +26 -144
  13. package/src/contracts/cdp-creator/scripts.ts +15 -9
  14. package/src/contracts/cdp-creator/types-new.ts +50 -0
  15. package/src/contracts/cdp-creator/types.ts +5 -31
  16. package/src/contracts/collector/scripts.ts +1 -1
  17. package/src/contracts/collector/transactions.ts +23 -13
  18. package/src/contracts/collector/types-new.ts +17 -0
  19. package/src/contracts/execute/scripts.ts +19 -10
  20. package/src/contracts/execute/types-new.ts +44 -0
  21. package/src/contracts/execute/types.ts +5 -38
  22. package/src/contracts/gov/helpers.ts +187 -51
  23. package/src/contracts/gov/scripts.ts +17 -10
  24. package/src/contracts/gov/transactions.ts +599 -271
  25. package/src/contracts/gov/types-new.ts +253 -100
  26. package/src/contracts/gov/types.ts +4 -71
  27. package/src/contracts/iasset/helpers.ts +172 -0
  28. package/src/contracts/iasset/scripts.ts +38 -0
  29. package/src/contracts/iasset/types.ts +154 -0
  30. package/src/contracts/initialize/actions.ts +768 -0
  31. package/src/contracts/initialize/helpers.ts +611 -36
  32. package/src/contracts/initialize/types.ts +102 -28
  33. package/src/contracts/interest-collection/helpers.ts +19 -0
  34. package/src/contracts/interest-collection/scripts.ts +44 -0
  35. package/src/contracts/interest-collection/transactions.ts +436 -0
  36. package/src/contracts/interest-collection/types-new.ts +50 -0
  37. package/src/contracts/interest-collection/types.ts +26 -0
  38. package/src/contracts/interest-oracle/helpers.ts +2 -30
  39. package/src/contracts/interest-oracle/scripts.ts +1 -1
  40. package/src/contracts/interest-oracle/transactions.ts +21 -16
  41. package/src/contracts/interest-oracle/types-new.ts +32 -0
  42. package/src/contracts/interest-oracle/types.ts +1 -40
  43. package/src/contracts/one-shot/transactions.ts +1 -2
  44. package/src/contracts/poll/helpers.ts +5 -23
  45. package/src/contracts/poll/scripts.ts +12 -13
  46. package/src/contracts/poll/types-poll-manager.ts +1 -19
  47. package/src/contracts/poll/types-poll-new.ts +170 -0
  48. package/src/contracts/poll/types-poll-shard.ts +2 -24
  49. package/src/contracts/price-oracle/helpers.ts +1 -4
  50. package/src/contracts/price-oracle/scripts.ts +3 -8
  51. package/src/contracts/price-oracle/transactions.ts +32 -25
  52. package/src/contracts/price-oracle/types-new.ts +50 -0
  53. package/src/contracts/price-oracle/types.ts +2 -36
  54. package/src/contracts/pyth-feed/helpers.ts +58 -0
  55. package/src/contracts/pyth-feed/scripts.ts +15 -0
  56. package/src/contracts/pyth-feed/types.ts +181 -0
  57. package/src/contracts/rob/helpers.ts +405 -0
  58. package/src/contracts/rob/scripts.ts +35 -0
  59. package/src/contracts/rob/transactions.ts +410 -0
  60. package/src/contracts/rob/types-new.ts +128 -0
  61. package/src/contracts/rob/types.ts +16 -0
  62. package/src/contracts/rob-leverage/helpers.ts +424 -0
  63. package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
  64. package/src/contracts/stability-pool/helpers.ts +714 -230
  65. package/src/contracts/stability-pool/scripts.ts +20 -15
  66. package/src/contracts/stability-pool/transactions.ts +628 -496
  67. package/src/contracts/stability-pool/types-new.ts +247 -100
  68. package/src/contracts/stability-pool/types.ts +5 -22
  69. package/src/contracts/stableswap/helpers.ts +22 -0
  70. package/src/contracts/stableswap/scripts.ts +37 -0
  71. package/src/contracts/stableswap/transactions.ts +647 -0
  72. package/src/contracts/stableswap/types-new.ts +131 -0
  73. package/src/contracts/stableswap/types.ts +17 -0
  74. package/src/contracts/staking/helpers.ts +49 -34
  75. package/src/contracts/staking/scripts.ts +1 -1
  76. package/src/contracts/staking/transactions.ts +85 -130
  77. package/src/contracts/staking/types-new.ts +60 -28
  78. package/src/contracts/staking/types.ts +1 -28
  79. package/src/contracts/treasury/helpers.ts +21 -0
  80. package/src/contracts/treasury/scripts.ts +16 -26
  81. package/src/contracts/treasury/transactions.ts +256 -27
  82. package/src/contracts/treasury/types-new.ts +69 -0
  83. package/src/contracts/treasury/types.ts +2 -43
  84. package/src/contracts/version-registry/scripts.ts +2 -2
  85. package/src/contracts/version-registry/types-new.ts +6 -7
  86. package/src/index.ts +37 -20
  87. package/src/scripts/auth-token-policy.ts +3 -2
  88. package/src/scripts/iasset-policy.ts +3 -2
  89. package/src/types/evolution-schema-options.ts +3 -3
  90. package/src/types/generic.ts +17 -89
  91. package/src/types/multisig.ts +48 -0
  92. package/src/types/on-chain-decimal.ts +14 -7
  93. package/src/types/rational.ts +61 -0
  94. package/src/types/system-params.ts +237 -41
  95. package/src/utils/array-utils.ts +70 -1
  96. package/src/utils/bigint-utils.ts +12 -0
  97. package/src/utils/indigo-helpers.ts +8 -10
  98. package/src/utils/lucid-utils.ts +47 -40
  99. package/src/utils/oracle-helpers.ts +62 -0
  100. package/src/utils/pyth/decode.ts +223 -0
  101. package/src/utils/pyth/encode.ts +262 -0
  102. package/src/utils/pyth/index.ts +14 -0
  103. package/src/utils/pyth/types.ts +87 -0
  104. package/src/validators/always-succeed-validator.ts +6 -0
  105. package/src/validators/cdp-creator-validator.ts +2 -2
  106. package/src/validators/cdp-redeem-validator.ts +7 -0
  107. package/src/validators/cdp-validator.ts +2 -2
  108. package/src/validators/collector-validator.ts +2 -2
  109. package/src/validators/execute-validator.ts +2 -2
  110. package/src/validators/governance-validator.ts +2 -2
  111. package/src/validators/iasset-validator.ts +7 -0
  112. package/src/validators/interest-collection-validator.ts +7 -0
  113. package/src/validators/interest-oracle-validator.ts +2 -2
  114. package/src/validators/poll-manager-validator.ts +2 -2
  115. package/src/validators/poll-shard-validator.ts +2 -2
  116. package/src/validators/price-oracle-validator.ts +7 -0
  117. package/src/validators/pyth-feed-validator.ts +7 -0
  118. package/src/validators/rob-validator.ts +7 -0
  119. package/src/validators/stability-pool-validator.ts +2 -2
  120. package/src/validators/stableswap-validator.ts +7 -0
  121. package/src/validators/staking-validator.ts +2 -2
  122. package/src/validators/treasury-validator.ts +2 -2
  123. package/src/validators/version-record-policy.ts +2 -2
  124. package/src/validators/version-registry-validator.ts +2 -2
  125. package/tests/always-succeed/script.ts +7 -0
  126. package/tests/bigint-utils.test.ts +41 -0
  127. package/tests/cdp/actions.ts +610 -0
  128. package/tests/cdp/cdp-helpers.ts +55 -0
  129. package/tests/cdp/cdp-queries.ts +440 -0
  130. package/tests/cdp/cdp.test.ts +6087 -0
  131. package/tests/cdp/transactions-mutated.ts +1729 -0
  132. package/tests/data/system-params.json +177 -34
  133. package/tests/datums.test.ts +209 -210
  134. package/tests/endpoints/initialize.ts +68 -0
  135. package/tests/endpoints/interest-collector.ts +37 -0
  136. package/tests/endpoints/treasury.ts +70 -0
  137. package/tests/gov/actions.ts +406 -0
  138. package/tests/gov/gov.test.ts +4450 -0
  139. package/tests/{queries → gov}/governance-queries.ts +6 -3
  140. package/tests/hash-checks.test.ts +38 -11
  141. package/tests/indigo-test-helpers.ts +100 -0
  142. package/tests/initialize.test.ts +61 -9
  143. package/tests/interest-collection/interest-collection.test.ts +892 -0
  144. package/tests/interest-collection/interest-collector-queries.ts +49 -0
  145. package/tests/interest-collection/transactions-mutated.ts +260 -0
  146. package/tests/interest-oracle.test.ts +43 -35
  147. package/tests/mock/assets-mock.ts +234 -23
  148. package/tests/mock/protocol-params-mock.ts +21 -0
  149. package/tests/price-oracle/actions.ts +163 -0
  150. package/tests/price-oracle/price-oracle-queries.ts +12 -0
  151. package/tests/price-oracle/price-oracle.test.ts +240 -0
  152. package/tests/price-oracle/transactions-mutated.ts +62 -0
  153. package/tests/pyth/endpoints.ts +96 -0
  154. package/tests/pyth/helpers.ts +37 -0
  155. package/tests/pyth/pyth-encoding.test.ts +376 -0
  156. package/tests/pyth/pyth-indigo.test.ts +509 -0
  157. package/tests/pyth/pyth.test.ts +300 -0
  158. package/tests/queries/execute-queries.ts +6 -5
  159. package/tests/queries/iasset-queries.ts +175 -5
  160. package/tests/queries/interest-oracle-queries.ts +4 -2
  161. package/tests/queries/poll-queries.ts +8 -9
  162. package/tests/queries/stability-pool-queries.ts +95 -48
  163. package/tests/queries/staking-queries.ts +4 -2
  164. package/tests/queries/treasury-queries.ts +80 -5
  165. package/tests/rob/actions.ts +58 -0
  166. package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
  167. package/tests/rob/rob-queries.ts +95 -0
  168. package/tests/rob/rob.test.ts +3762 -0
  169. package/tests/rob/transactions-mutated.ts +853 -0
  170. package/tests/script-size.test.ts +240 -0
  171. package/tests/setup.ts +135 -0
  172. package/tests/stability-pool/actions.ts +220 -0
  173. package/tests/stability-pool.test.ts +6121 -667
  174. package/tests/stableswap/stableswap-actions.ts +84 -0
  175. package/tests/stableswap/stableswap-queries.ts +89 -0
  176. package/tests/stableswap/stableswap.test.ts +3891 -0
  177. package/tests/stableswap/transactions-mutated.ts +348 -0
  178. package/tests/staking.test.ts +82 -99
  179. package/tests/test-helpers.ts +58 -11
  180. package/tests/treasury.test.ts +242 -0
  181. package/tests/utils/asserts.ts +74 -0
  182. package/tests/utils/benchmark-utils.ts +81 -0
  183. package/tests/utils/index.ts +122 -4
  184. package/tsconfig.json +9 -1
  185. package/vitest.config.ts +3 -1
  186. package/src/contracts/collector/types.ts +0 -16
  187. package/src/contracts/initialize/transactions.ts +0 -891
  188. package/src/contracts/leverage/helpers.ts +0 -424
  189. package/src/contracts/lrp/helpers.ts +0 -294
  190. package/src/contracts/lrp/scripts.ts +0 -27
  191. package/src/contracts/lrp/transactions.ts +0 -250
  192. package/src/contracts/lrp/types.ts +0 -131
  193. package/src/contracts/poll/types-poll.ts +0 -88
  194. package/src/contracts/vesting/helpers.ts +0 -218
  195. package/src/utils/value-helpers.ts +0 -37
  196. package/src/validators/lrp-validator.ts +0 -7
  197. package/tests/cdp.test.ts +0 -1528
  198. package/tests/gov.test.ts +0 -2011
  199. package/tests/lrp.test.ts +0 -673
  200. package/tests/queries/cdp-queries.ts +0 -220
  201. package/tests/queries/lrp-queries.ts +0 -76
  202. package/tests/queries/price-oracle-queries.ts +0 -10
@@ -0,0 +1,256 @@
1
+ import { TSchema, Data } from '@evolution-sdk/evolution';
2
+ import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
3
+ import { option as O, function as F } from 'fp-ts';
4
+ import {
5
+ AssetClassSchema,
6
+ OutputReferenceSchema,
7
+ } from '@3rd-eye-labs/cardano-offchain-common';
8
+ import { match, P } from 'ts-pattern';
9
+ import { RationalSchema } from '../../types/rational';
10
+ import { OracleIdxSchema } from '../price-oracle/types-new';
11
+
12
+ // const CdpParamsSchema = Core.TSchema.Struct({
13
+ // cdp_auth_token: EvoCommon.AssetClassSchema,
14
+ // cdp_asset_symbol: Core.TSchema.ByteArray,
15
+ // iasset_auth_token: EvoCommon.AssetClassSchema,
16
+ // stability_pool_auth_token: EvoCommon.AssetClassSchema,
17
+ // version_record_token: EvoCommon.AssetClassSchema,
18
+ // upgrade_token: EvoCommon.AssetClassSchema,
19
+ // collector_val_hash: Core.TSchema.ByteArray,
20
+ // sp_val_hash: Core.TSchema.ByteArray,
21
+ // gov_nft: EvoCommon.AssetClassSchema,
22
+ // min_collateral_in_lovelace: Core.TSchema.Integer,
23
+ // partial_redemption_extra_fee_lovelace: Core.TSchema.Integer,
24
+ // bias_time: Core.TSchema.Integer,
25
+ // treasury_val_hash: Core.TSchema.ByteArray,
26
+ // });
27
+
28
+ // export type CdpParams = typeof CdpParamsSchema.Type;
29
+
30
+ const CdpRedeemerSchema = TSchema.Union(
31
+ TSchema.Struct(
32
+ {
33
+ AdjustCdp: TSchema.Struct(
34
+ {
35
+ currentTime: TSchema.Integer,
36
+ debtAdjustment: TSchema.Integer,
37
+ collateralAdjustment: TSchema.Integer,
38
+ priceOracleIdx: OracleIdxSchema,
39
+ },
40
+ { flatFields: true },
41
+ ),
42
+ },
43
+ { flatInUnion: true },
44
+ ),
45
+ TSchema.Struct(
46
+ {
47
+ CloseCdp: TSchema.Struct(
48
+ {
49
+ currentTime: TSchema.Integer,
50
+ },
51
+ { flatFields: true },
52
+ ),
53
+ },
54
+ { flatInUnion: true },
55
+ ),
56
+ TSchema.Literal('RedeemCdp', { flatInUnion: true }),
57
+ TSchema.Struct(
58
+ {
59
+ FreezeCdp: TSchema.Struct(
60
+ {
61
+ currentTime: TSchema.Integer,
62
+ priceOracleIdx: OracleIdxSchema,
63
+ },
64
+ { flatFields: true },
65
+ ),
66
+ },
67
+ { flatInUnion: true },
68
+ ),
69
+ TSchema.Literal('MergeCdps', { flatInUnion: true }),
70
+ TSchema.Struct(
71
+ {
72
+ MergeAuxiliary: TSchema.Struct(
73
+ {
74
+ mainMergeUtxo: OutputReferenceSchema,
75
+ },
76
+ { flatFields: true },
77
+ ),
78
+ },
79
+ { flatInUnion: true },
80
+ ),
81
+ TSchema.Literal('Liquidate', { flatInUnion: true }),
82
+ TSchema.Struct(
83
+ {
84
+ SettleInterest: TSchema.Struct(
85
+ {
86
+ interestCollectorInputIndex: TSchema.Integer,
87
+ },
88
+ { flatFields: true },
89
+ ),
90
+ },
91
+ { flatInUnion: true },
92
+ ),
93
+ TSchema.Struct(
94
+ {
95
+ Stableswap: TSchema.Struct(
96
+ {
97
+ forwardingInputIndex: TSchema.Integer,
98
+ },
99
+ { flatFields: true },
100
+ ),
101
+ },
102
+ { flatInUnion: true },
103
+ ),
104
+ TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
105
+ );
106
+
107
+ export type CdpRedeemer = typeof CdpRedeemerSchema.Type;
108
+
109
+ const RedeemCdpWithdrawalRedeemerSchema = TSchema.Struct({
110
+ cdpOutReference: OutputReferenceSchema,
111
+ currentTime: TSchema.Integer,
112
+ priceOracleIdx: OracleIdxSchema,
113
+ });
114
+
115
+ export type RedeemCdpWithdrawalRedeemer =
116
+ typeof RedeemCdpWithdrawalRedeemerSchema.Type;
117
+
118
+ const CDPFeesSchema = TSchema.Union(
119
+ TSchema.Struct(
120
+ {
121
+ ActiveCDPInterestTracking: TSchema.Struct(
122
+ {
123
+ lastSettled: TSchema.Integer,
124
+ unitaryInterestSnapshot: TSchema.Integer,
125
+ },
126
+ { flatFields: true },
127
+ ),
128
+ },
129
+ { flatInUnion: true },
130
+ ),
131
+ TSchema.Struct(
132
+ {
133
+ FrozenCDPAccumulatedFees: TSchema.Struct(
134
+ {
135
+ iassetInterest: TSchema.Integer,
136
+ collateralTreasury: TSchema.Integer,
137
+ },
138
+ { flatFields: true },
139
+ ),
140
+ },
141
+ { flatInUnion: true },
142
+ ),
143
+ );
144
+
145
+ const CDPContentSchema = TSchema.Struct({
146
+ cdpOwner: TSchema.NullOr(TSchema.ByteArray),
147
+ iasset: TSchema.ByteArray,
148
+ collateralAsset: AssetClassSchema,
149
+ mintedAmt: TSchema.Integer,
150
+ cdpFees: CDPFeesSchema,
151
+ });
152
+
153
+ export type CDPContent = typeof CDPContentSchema.Type;
154
+
155
+ const StableswapPoolContentSchema = TSchema.Struct({
156
+ /** Use the HEX encoding */
157
+ iasset: TSchema.ByteArray,
158
+ collateralAsset: AssetClassSchema,
159
+ collateralToIassetRatio: RationalSchema,
160
+ mintingFeeRatio: RationalSchema,
161
+ redemptionFeeRatio: RationalSchema,
162
+ mintingEnabled: TSchema.Boolean,
163
+ redemptionEnabled: TSchema.Boolean,
164
+ feeManager: TSchema.NullOr(TSchema.ByteArray),
165
+ minMintOrderAmount: TSchema.Integer,
166
+ minRedemptionOrderAmount: TSchema.Integer,
167
+ stableswapValHash: TSchema.ByteArray,
168
+ });
169
+
170
+ export type StableswapPoolContent = typeof StableswapPoolContentSchema.Type;
171
+
172
+ const CDPDatumSchema = TSchema.Union(
173
+ TSchema.Struct({ CDP: CDPContentSchema }, { flatInUnion: true }),
174
+ TSchema.Struct(
175
+ { StableswapPool: StableswapPoolContentSchema },
176
+ { flatInUnion: true },
177
+ ),
178
+ );
179
+ export type CDPDatum = typeof CDPDatumSchema.Type;
180
+
181
+ export function serialiseCdpRedeemer(r: CdpRedeemer): string {
182
+ return Data.withSchema(CdpRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex(
183
+ r,
184
+ );
185
+ }
186
+
187
+ export function serialiseRedeemCdpWithdrawalRedeemer(
188
+ r: RedeemCdpWithdrawalRedeemer,
189
+ ): string {
190
+ return Data.withSchema(
191
+ RedeemCdpWithdrawalRedeemerSchema,
192
+ DEFAULT_SCHEMA_OPTIONS,
193
+ ).toCBORHex(r);
194
+ }
195
+
196
+ export function serialiseCdpDatum(d: CDPContent): string {
197
+ return Data.withSchema(CDPDatumSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex({
198
+ CDP: d,
199
+ });
200
+ }
201
+
202
+ export function serialiseStableswapPoolDatum(d: StableswapPoolContent): string {
203
+ return Data.withSchema(CDPDatumSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex({
204
+ StableswapPool: d,
205
+ });
206
+ }
207
+
208
+ export function parseCdpDatum(datum: string): O.Option<CDPContent> {
209
+ try {
210
+ return match(
211
+ Data.withSchema(CDPDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
212
+ datum,
213
+ ),
214
+ )
215
+ .with({ CDP: P.select() }, (res) => O.some(res))
216
+ .otherwise(() => O.none);
217
+ } catch (_) {
218
+ return O.none;
219
+ }
220
+ }
221
+
222
+ export function parseCdpDatumOrThrow(datum: string): CDPContent {
223
+ return F.pipe(
224
+ parseCdpDatum(datum),
225
+ O.match(() => {
226
+ throw new Error('Expected a CDP datum.');
227
+ }, F.identity),
228
+ );
229
+ }
230
+
231
+ export function parseStableswapPoolDatum(
232
+ datum: string,
233
+ ): O.Option<StableswapPoolContent> {
234
+ try {
235
+ return match(
236
+ Data.withSchema(CDPDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
237
+ datum,
238
+ ),
239
+ )
240
+ .with({ StableswapPool: P.select() }, (res) => O.some(res))
241
+ .otherwise(() => O.none);
242
+ } catch (_) {
243
+ return O.none;
244
+ }
245
+ }
246
+
247
+ export function parseStableswapPoolDatumOrThrow(
248
+ datum: string,
249
+ ): StableswapPoolContent {
250
+ return F.pipe(
251
+ parseStableswapPoolDatum(datum),
252
+ O.match(() => {
253
+ throw new Error('Expected a stableswap pool datum.');
254
+ }, F.identity),
255
+ );
256
+ }
@@ -1,161 +1,43 @@
1
- import { Data, Datum, Redeemer, UTxO } from '@lucid-evolution/lucid';
2
- import { AssetClassSchema, OutputReferenceSchema } from '../../types/generic';
3
- import { OnChainDecimalSchema } from '../../types/on-chain-decimal';
4
- import { OracleAssetNftSchema } from '../price-oracle/types';
5
- import { match, P } from 'ts-pattern';
6
- import { option as O, function as F } from 'fp-ts';
1
+ import { Data } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema } from '../../types/generic';
7
3
 
8
4
  const CdpParamsSchema = Data.Object({
9
5
  cdp_auth_token: AssetClassSchema,
10
6
  cdp_asset_symbol: Data.Bytes(),
11
7
  iasset_auth_token: AssetClassSchema,
8
+ collateral_asset_auth_token: AssetClassSchema,
12
9
  stability_pool_auth_token: AssetClassSchema,
13
- version_record_token: AssetClassSchema,
14
10
  upgrade_token: AssetClassSchema,
15
- collector_val_hash: Data.Bytes(),
11
+ version_record_token: AssetClassSchema,
12
+ interest_collector_val_hash: Data.Bytes(),
16
13
  sp_val_hash: Data.Bytes(),
17
- gov_nft: AssetClassSchema,
18
- min_collateral_in_lovelace: Data.Integer(),
19
- partial_redemption_extra_fee_lovelace: Data.Integer(),
20
- bias_time: Data.Integer(),
14
+ iasset_val_hash: Data.Bytes(),
21
15
  treasury_val_hash: Data.Bytes(),
16
+ cdp_redeem_val_hash: Data.Bytes(),
17
+ bias_time: Data.Integer(),
22
18
  });
23
19
  export type CdpParams = Data.Static<typeof CdpParamsSchema>;
24
20
  const CdpParams = CdpParamsSchema as unknown as CdpParams;
25
21
 
26
- export const CDPFeesSchema = Data.Enum([
27
- Data.Object({
28
- ActiveCDPInterestTracking: Data.Object({
29
- lastSettled: Data.Integer(),
30
- unitaryInterestSnapshot: Data.Integer(),
31
- }),
32
- }),
33
- Data.Object({
34
- FrozenCDPAccumulatedFees: Data.Object({
35
- lovelacesTreasury: Data.Integer(),
36
- lovelacesIndyStakers: Data.Integer(),
37
- }),
38
- }),
39
- ]);
40
-
41
- export const CDPContentSchema = Data.Object({
42
- cdpOwner: Data.Nullable(Data.Bytes()),
43
- iasset: Data.Bytes(),
44
- mintedAmt: Data.Integer(),
45
- cdpFees: CDPFeesSchema,
46
- });
47
-
48
- export const IAssetPriceInfoSchema = Data.Enum([
49
- Data.Object({
50
- Delisted: Data.Object({ content: OnChainDecimalSchema }),
51
- }),
52
- Data.Object({
53
- Oracle: Data.Object({ content: OracleAssetNftSchema }),
54
- }),
55
- ]);
56
-
57
- export const IAssetContentSchema = Data.Object({
58
- /** Use the HEX encoding */
59
- assetName: Data.Bytes(),
60
- price: IAssetPriceInfoSchema,
61
- interestOracleNft: AssetClassSchema,
62
- redemptionRatio: OnChainDecimalSchema,
63
- maintenanceRatio: OnChainDecimalSchema,
64
- liquidationRatio: OnChainDecimalSchema,
65
- debtMintingFeePercentage: OnChainDecimalSchema,
66
- liquidationProcessingFeePercentage: OnChainDecimalSchema,
67
- stabilityPoolWithdrawalFeePercentage: OnChainDecimalSchema,
68
- redemptionReimbursementPercentage: OnChainDecimalSchema,
69
- redemptionProcessingFeePercentage: OnChainDecimalSchema,
70
- interestCollectorPortionPercentage: OnChainDecimalSchema,
71
- firstIAsset: Data.Boolean(),
72
- nextIAsset: Data.Nullable(Data.Bytes()),
73
- });
74
-
75
- export const CDPDatumSchema = Data.Enum([
76
- Data.Object({ CDP: Data.Object({ content: CDPContentSchema }) }),
77
- Data.Object({ IAsset: Data.Object({ content: IAssetContentSchema }) }),
78
- ]);
79
-
80
- export type CDPFees = Data.Static<typeof CDPFeesSchema>;
81
- export type CDPDatum = Data.Static<typeof CDPDatumSchema>;
82
- const CDPDatum = CDPDatumSchema as unknown as CDPDatum;
83
-
84
- export type CDPContent = Data.Static<typeof CDPContentSchema>;
85
- const CDPContent = CDPContentSchema as unknown as CDPContent;
86
- export type IAssetContent = Data.Static<typeof IAssetContentSchema>;
87
- const IAssetContent = IAssetContentSchema as unknown as IAssetContent;
88
-
89
- const CDPRedeemerSchema = Data.Enum([
90
- Data.Object({
91
- AdjustCdp: Data.Object({
92
- currentTime: Data.Integer(),
93
- mintedAmtChange: Data.Integer(),
94
- collateralAmtChange: Data.Integer(),
95
- }),
96
- }),
97
- Data.Object({ CloseCdp: Data.Object({ currentTime: Data.Integer() }) }),
98
- Data.Object({ RedeemCdp: Data.Object({ currentTime: Data.Integer() }) }),
99
- Data.Object({ FreezeCdp: Data.Object({ currentTime: Data.Integer() }) }),
100
- Data.Literal('MergeCdps'),
101
- Data.Object({
102
- MergeAuxiliary: Data.Object({ mainMergeUtxo: OutputReferenceSchema }),
103
- }),
104
- Data.Literal('Liquidate'),
105
- Data.Literal('UpdateOrInsertAsset'),
106
- Data.Literal('UpgradeVersion'),
107
- ]);
108
- export type CDPRedeemer = Data.Static<typeof CDPRedeemerSchema>;
109
- const CDPRedeemer = CDPRedeemerSchema as unknown as CDPRedeemer;
110
-
111
- export function serialiseCdpRedeemer(r: CDPRedeemer): Redeemer {
112
- return Data.to<CDPRedeemer>(r, CDPRedeemer, { canonical: false });
113
- }
114
-
115
- export function parseCdpDatum(datum: Datum): O.Option<CDPContent> {
116
- return match(Data.from<CDPDatum>(datum, CDPDatum))
117
- .with({ CDP: { content: P.select() } }, (res) => O.some(res))
118
- .otherwise(() => O.none);
119
- }
120
-
121
- export function parseCdpDatumOrThrow(datum: Datum): CDPContent {
122
- return F.pipe(
123
- parseCdpDatum(datum),
124
- O.match(() => {
125
- throw new Error('Expected a CDP datum.');
126
- }, F.identity),
127
- );
128
- }
129
-
130
- export function serialiseCdpDatum(cdpDatum: CDPContent): Datum {
131
- return Data.to<CDPDatum>({ CDP: { content: cdpDatum } }, CDPDatum);
132
- }
133
-
134
- export function parseIAssetDatum(datum: Datum): O.Option<IAssetContent> {
135
- try {
136
- return match(Data.from<CDPDatum>(datum, CDPDatum))
137
- .with({ IAsset: { content: P.select() } }, (res) => O.some(res))
138
- .otherwise(() => O.none);
139
- } catch (_) {
140
- return O.none;
141
- }
142
- }
143
-
144
- export function parseIAssetDatumOrThrow(datum: Datum): IAssetContent {
145
- return F.pipe(
146
- parseIAssetDatum(datum),
147
- O.match(() => {
148
- throw new Error('Expected an IAsset datum.');
149
- }, F.identity),
150
- );
151
- }
152
-
153
- export function serialiseIAssetDatum(iassetDatum: IAssetContent): Datum {
154
- return Data.to<CDPDatum>({ IAsset: { content: iassetDatum } }, CDPDatum);
155
- }
156
-
157
22
  export function castCdpParams(params: CdpParams): Data {
158
23
  return Data.castTo(params, CdpParams);
159
24
  }
160
25
 
161
- export type IAssetOutput = { datum: IAssetContent; utxo: UTxO };
26
+ const CdpRedeemParamsSchema = Data.Object({
27
+ cdp_auth_token: AssetClassSchema,
28
+ cdp_asset_symbol: Data.Bytes(),
29
+ iasset_auth_token: AssetClassSchema,
30
+ collateral_asset_auth_token: AssetClassSchema,
31
+ interest_collector_val_hash: Data.Bytes(),
32
+ iasset_val_hash: Data.Bytes(),
33
+ treasury_val_hash: Data.Bytes(),
34
+ gov_nft: AssetClassSchema,
35
+ partial_redemption_extra_fee_lovelace: Data.Integer(),
36
+ bias_time: Data.Integer(),
37
+ });
38
+ export type CdpRedeemParams = Data.Static<typeof CdpRedeemParamsSchema>;
39
+ const CdpRedeemParams = CdpRedeemParamsSchema as unknown as CdpRedeemParams;
40
+
41
+ export function castCdpRedeemParams(params: CdpRedeemParams): Data {
42
+ return Data.castTo(params, CdpRedeemParams);
43
+ }
@@ -2,7 +2,7 @@ import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
2
2
  import { castCDPCreatorParams, CDPCreatorParams } from './types';
3
3
  import {
4
4
  CDPCreatorParamsSP,
5
- fromSystemParamsAsset,
5
+ fromSystemParamsAssetLucid,
6
6
  } from '../../types/system-params';
7
7
  import { _cdpCreatorValidator } from '../../validators/cdp-creator-validator';
8
8
 
@@ -10,7 +10,7 @@ export const mkCDPCreatorValidator = (
10
10
  params: CDPCreatorParams,
11
11
  ): SpendingValidator => {
12
12
  return {
13
- type: 'PlutusV2',
13
+ type: 'PlutusV3',
14
14
  script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
15
15
  castCDPCreatorParams(params),
16
16
  ]),
@@ -21,17 +21,23 @@ export const mkCDPCreatorValidatorFromSP = (
21
21
  params: CDPCreatorParamsSP,
22
22
  ): SpendingValidator => {
23
23
  return {
24
- type: 'PlutusV2',
24
+ type: 'PlutusV3',
25
25
  script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
26
26
  castCDPCreatorParams({
27
- cdpCreatorNft: fromSystemParamsAsset(params.cdpCreatorNft),
27
+ cdpCreatorNft: fromSystemParamsAssetLucid(params.cdpCreatorNft),
28
28
  cdpAssetCs: params.cdpAssetCs.unCurrencySymbol,
29
- cdpAuthTk: fromSystemParamsAsset(params.cdpAuthTk),
30
- iAssetAuthTk: fromSystemParamsAsset(params.iAssetAuthTk),
31
- versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
29
+ cdpAuthTk: fromSystemParamsAssetLucid(params.cdpAuthTk),
30
+ iAssetAuthTk: fromSystemParamsAssetLucid(params.iAssetAuthTk),
31
+ collateralAssetAuthTk: fromSystemParamsAssetLucid(
32
+ params.collateralAssetAuthTk,
33
+ ),
34
+ upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
35
+ versionRecordToken: fromSystemParamsAssetLucid(
36
+ params.versionRecordToken,
37
+ ),
38
+ iassetValHash: params.iassetValHash,
32
39
  cdpScriptHash: params.cdpScriptHash,
33
- collectorValHash: params.collectorValHash,
34
- minCollateralInLovelace: BigInt(params.minCollateralInLovelace),
40
+ treasuryValHash: params.treasuryValHash,
35
41
  biasTime: BigInt(params.biasTime),
36
42
  }),
37
43
  ]),
@@ -0,0 +1,50 @@
1
+ import { TSchema, Data } from '@evolution-sdk/evolution';
2
+ import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
3
+ import { OutputReferenceSchema } from '@3rd-eye-labs/cardano-offchain-common';
4
+ import { OracleIdxSchema } from '../price-oracle/types-new';
5
+
6
+ const CDPCreatorDatumSchema = TSchema.Struct({
7
+ creatorInputOref: OutputReferenceSchema,
8
+ });
9
+
10
+ const CreateCDPContentSchema = TSchema.Struct({
11
+ cdpOwner: TSchema.ByteArray,
12
+ minted: TSchema.Integer,
13
+ collateralAmt: TSchema.Integer,
14
+ currentTime: TSchema.Integer,
15
+ creatorInputIdx: TSchema.Integer,
16
+ creatorOutputIdx: TSchema.Integer,
17
+ cdpOutputIdx: TSchema.Integer,
18
+ iassetRefInputIdx: TSchema.Integer,
19
+ collateralAssetRefInputIdx: TSchema.Integer,
20
+ interestOracleRefInputIdx: TSchema.Integer,
21
+ priceOracleIdx: OracleIdxSchema,
22
+ });
23
+
24
+ const CDPCreatorRedeemerSchema = TSchema.Union(
25
+ TSchema.Struct(
26
+ {
27
+ CreateCDP: CreateCDPContentSchema,
28
+ },
29
+ { flatInUnion: true },
30
+ ),
31
+ TSchema.Literal('CreateStableswapPool', { flatInUnion: true }),
32
+ TSchema.Literal('UpgradeCreatorVersion', { flatInUnion: true }),
33
+ );
34
+ export type CDPCreatorRedeemer = typeof CDPCreatorRedeemerSchema.Type;
35
+
36
+ export function serialiseCDPCreatorDatum(
37
+ r: typeof CDPCreatorDatumSchema.Type,
38
+ ): string {
39
+ return Data.withSchema(
40
+ CDPCreatorDatumSchema,
41
+ DEFAULT_SCHEMA_OPTIONS,
42
+ ).toCBORHex(r);
43
+ }
44
+
45
+ export function serialiseCDPCreatorRedeemer(r: CDPCreatorRedeemer): string {
46
+ return Data.withSchema(
47
+ CDPCreatorRedeemerSchema,
48
+ DEFAULT_SCHEMA_OPTIONS,
49
+ ).toCBORHex(r);
50
+ }
@@ -1,4 +1,4 @@
1
- import { Data, Datum, Redeemer } from '@lucid-evolution/lucid';
1
+ import { Data } from '@lucid-evolution/lucid';
2
2
  import { AssetClassSchema } from '../../types/generic';
3
3
 
4
4
  const CDPCreatorParamsSchema = Data.Object({
@@ -6,10 +6,12 @@ const CDPCreatorParamsSchema = Data.Object({
6
6
  cdpAssetCs: Data.Bytes(),
7
7
  cdpAuthTk: AssetClassSchema,
8
8
  iAssetAuthTk: AssetClassSchema,
9
+ collateralAssetAuthTk: AssetClassSchema,
10
+ upgradeToken: AssetClassSchema,
9
11
  versionRecordToken: AssetClassSchema,
10
12
  cdpScriptHash: Data.Bytes(),
11
- collectorValHash: Data.Bytes(),
12
- minCollateralInLovelace: Data.Integer(),
13
+ treasuryValHash: Data.Bytes(),
14
+ iassetValHash: Data.Bytes(),
13
15
  biasTime: Data.Integer(),
14
16
  });
15
17
 
@@ -20,31 +22,3 @@ export const CDPCreatorParams =
20
22
  export function castCDPCreatorParams(params: CDPCreatorParams): Data {
21
23
  return Data.castTo(params, CDPCreatorParams);
22
24
  }
23
-
24
- const CDPCreatorRedeemerSchema = Data.Enum([
25
- Data.Object({
26
- CreateCDP: Data.Object({
27
- cdpOwner: Data.Bytes(),
28
- minted: Data.Integer(),
29
- collateral: Data.Integer(),
30
- currentTime: Data.Integer(),
31
- }),
32
- }),
33
- Data.Object({ UpgradeCreatorVersion: Data.Object({}) }),
34
- ]);
35
-
36
- export type CDPCreatorRedeemer = Data.Static<typeof CDPCreatorRedeemerSchema>;
37
- export const CDPCreatorRedeemer =
38
- CDPCreatorRedeemerSchema as unknown as CDPCreatorRedeemer;
39
-
40
- export function serialiseCDPCreatorRedeemer(
41
- params: CDPCreatorRedeemer,
42
- ): Redeemer {
43
- return Data.to<CDPCreatorRedeemer>(params, CDPCreatorRedeemer, {
44
- canonical: false,
45
- });
46
- }
47
-
48
- export function serialiseCDPCreatorDatum(): Datum {
49
- return Data.void();
50
- }
@@ -11,7 +11,7 @@ export const mkCollectorValidatorFromSP = (
11
11
  params: CollectorParamsSP,
12
12
  ): SpendingValidator => {
13
13
  return {
14
- type: 'PlutusV2',
14
+ type: 'PlutusV3',
15
15
  script: applyParamsToScript(_collectorValidator.cborHex, [
16
16
  new Constr(0, [
17
17
  new Constr(0, [
@@ -1,23 +1,34 @@
1
- import { Data, LucidEvolution, TxBuilder, UTxO } from '@lucid-evolution/lucid';
1
+ import {
2
+ addAssets,
3
+ Data,
4
+ LucidEvolution,
5
+ OutRef,
6
+ TxBuilder,
7
+ UTxO,
8
+ } from '@lucid-evolution/lucid';
2
9
  import {
3
10
  fromSystemParamsScriptRef,
4
11
  SystemParams,
5
12
  } from '../../types/system-params';
6
13
  import { matchSingle } from '../../utils/utils';
7
- import { resolveUtxo, UtxoOrOutRef } from '../../utils/lucid-utils';
8
- import { serialiseCollectorRedeemer } from './types';
14
+ import { serialiseCollectorRedeemer } from './types-new';
15
+ import { mkLovelacesOf } from '@3rd-eye-labs/cardano-offchain-common';
9
16
 
17
+ /**
18
+ * Returns the collector ref script UTXO that was added to ref inputs.
19
+ *
20
+ * No need to return the TxBuilder since it's stateful object.
21
+ */
10
22
  export async function collectorFeeTx(
11
23
  fee: bigint,
12
24
  lucid: LucidEvolution,
13
25
  params: SystemParams,
14
26
  tx: TxBuilder,
15
- collector: UtxoOrOutRef,
16
- ): Promise<void> {
17
- const collectorUtxo: UTxO = await resolveUtxo(
18
- collector,
19
- lucid,
20
- 'Expected a single collector UTXO',
27
+ collectorOref: OutRef,
28
+ ): Promise<UTxO> {
29
+ const collectorUtxo: UTxO = matchSingle(
30
+ await lucid.utxosByOutRef([collectorOref]),
31
+ (_) => new Error('Expected a single collector UTXO'),
21
32
  );
22
33
 
23
34
  const collectorRefScriptUtxo = matchSingle(
@@ -31,10 +42,9 @@ export async function collectorFeeTx(
31
42
  .pay.ToContract(
32
43
  collectorUtxo.address,
33
44
  { kind: 'inline', value: Data.void() },
34
- {
35
- ...collectorUtxo.assets,
36
- lovelace: collectorUtxo.assets.lovelace + fee,
37
- },
45
+ addAssets(collectorUtxo.assets, mkLovelacesOf(fee)),
38
46
  )
39
47
  .readFrom([collectorRefScriptUtxo]);
48
+
49
+ return collectorRefScriptUtxo;
40
50
  }
@@ -0,0 +1,17 @@
1
+ import { TSchema, Data } from '@evolution-sdk/evolution';
2
+ import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
3
+
4
+ export const CollectorRedeemerSchema = TSchema.Union(
5
+ TSchema.Literal('Collect', { flatInUnion: true }),
6
+ TSchema.Literal('DistributeToStakers', { flatInUnion: true }),
7
+ TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
8
+ );
9
+
10
+ export type CollectorRedeemer = typeof CollectorRedeemerSchema.Type;
11
+
12
+ export function serialiseCollectorRedeemer(r: CollectorRedeemer): string {
13
+ return Data.withSchema(
14
+ CollectorRedeemerSchema,
15
+ DEFAULT_SCHEMA_OPTIONS,
16
+ ).toCBORHex(r);
17
+ }