@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,268 +0,0 @@
1
- import { TSchema, Data } from '@evolution-sdk/evolution';
2
- import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
3
- import {
4
- AddressSchema,
5
- AssetClassSchema,
6
- } from '@3rd-eye-labs/cardano-offchain-common';
7
- import { option as O, function as F } from 'fp-ts';
8
- import { IAssetPriceInfoSchema } from '../iasset/types';
9
- import { MultisigSchema } from '../../types/multisig';
10
- import { RationalSchema } from '../../types/rational';
11
-
12
- export const ProtocolParamsSchema = TSchema.Struct({
13
- proposalDeposit: TSchema.Integer,
14
- votingPeriod: TSchema.Integer,
15
- effectiveDelay: TSchema.Integer,
16
- expirationPeriod: TSchema.Integer,
17
- proposingPeriod: TSchema.Integer,
18
- totalShards: TSchema.Integer,
19
- minimumQuorum: TSchema.Integer,
20
- maxTreasuryLovelaceSpend: TSchema.Integer,
21
- maxTreasuryIndySpend: TSchema.Integer,
22
- cdpRedemptionRequiredSignature: TSchema.NullOr(TSchema.ByteArray),
23
- electorate: TSchema.Integer,
24
- foundationMultisig: MultisigSchema,
25
- });
26
-
27
- export type ProtocolParams = typeof ProtocolParamsSchema.Type;
28
-
29
- const UpgradePathSchema = TSchema.Struct({
30
- upgradeSymbol: TSchema.ByteArray,
31
- });
32
-
33
- const UpgradePathsSchema = TSchema.Struct({
34
- upgradeId: TSchema.Integer,
35
- /// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
36
- upgradePaths: TSchema.Array(
37
- TSchema.Tuple([TSchema.ByteArray, UpgradePathSchema]),
38
- ),
39
- });
40
- export type UpgradePaths = typeof UpgradePathsSchema.Type;
41
-
42
- const ProposeIAssetContentSchema = TSchema.Struct({
43
- asset: TSchema.ByteArray,
44
- debtMintingFeeRatio: RationalSchema,
45
- liquidationProcessingFeeRatio: RationalSchema,
46
- stabilityPoolWithdrawalFeeRatio: RationalSchema,
47
- redemptionReimbursementRatio: RationalSchema,
48
- redemptionProcessingFeeRatio: RationalSchema,
49
- });
50
- export type ProposeAssetContent = typeof ProposeIAssetContentSchema.Type;
51
-
52
- const ModifyIAssetContentSchema = TSchema.Struct({
53
- asset: TSchema.ByteArray,
54
- newDebtMintingFeeRatio: RationalSchema,
55
- newLiquidationProcessingFeeRatio: RationalSchema,
56
- newStabilityPoolWithdrawalFeeRatio: RationalSchema,
57
- newRedemptionReimbursementRatio: RationalSchema,
58
- newRedemptionProcessingFeeRatio: RationalSchema,
59
- });
60
-
61
- const AddCollateralAssetContentSchema = TSchema.Struct({
62
- correspondingIAsset: TSchema.ByteArray,
63
- collateralAsset: AssetClassSchema,
64
- assetExtraDecimals: TSchema.Integer,
65
- assetPriceInfo: IAssetPriceInfoSchema,
66
- interestOracleNft: AssetClassSchema,
67
- redemptionRatio: RationalSchema,
68
- maintenanceRatio: RationalSchema,
69
- liquidationRatio: RationalSchema,
70
- minCollateralAmt: TSchema.Integer,
71
- });
72
-
73
- export type AddCollateralAsssetContent =
74
- typeof AddCollateralAssetContentSchema.Type;
75
-
76
- const UpdateCollateralAssetContentSchema = TSchema.Struct({
77
- correspondingIAsset: TSchema.ByteArray,
78
- collateralAsset: AssetClassSchema,
79
- newAssetExtraDecimals: TSchema.Integer,
80
- newAssetPriceInfo: IAssetPriceInfoSchema,
81
- newInterestOracleNft: AssetClassSchema,
82
- newRedemptionRatio: RationalSchema,
83
- newMaintenanceRatio: RationalSchema,
84
- newLiquidationRatio: RationalSchema,
85
- newMinCollateralAmt: TSchema.Integer,
86
- });
87
-
88
- const ProposeStableswapPoolContentSchema = TSchema.Struct({
89
- iasset: TSchema.ByteArray,
90
- collateralAsset: AssetClassSchema,
91
- collateralToIassetRatio: RationalSchema,
92
- mintingFeeRatio: RationalSchema,
93
- redemptionFeeRatio: RationalSchema,
94
- feeManager: TSchema.NullOr(TSchema.ByteArray),
95
- minMintingAmount: TSchema.Integer,
96
- minRedemptionAmount: TSchema.Integer,
97
- stableswapValHash: TSchema.ByteArray,
98
- });
99
-
100
- export type ProposeStableswapPoolContent =
101
- typeof ProposeStableswapPoolContentSchema.Type;
102
-
103
- const ModifyStableswapPoolContentSchema = TSchema.Struct({
104
- iasset: TSchema.ByteArray,
105
- collateralAsset: AssetClassSchema,
106
- newCollateralToIassetRatio: RationalSchema,
107
- newMintingFeeRatio: RationalSchema,
108
- newRedemptionFeeRatio: RationalSchema,
109
- newMintingEnabled: TSchema.Boolean,
110
- newRedemptionEnabled: TSchema.Boolean,
111
- newFeeManager: TSchema.NullOr(TSchema.ByteArray),
112
- newMinMintingAmount: TSchema.Integer,
113
- newMinRedemptionAmount: TSchema.Integer,
114
- newStableswapValHash: TSchema.ByteArray,
115
- });
116
-
117
- export type ModifyStableswapPoolContent =
118
- typeof ModifyStableswapPoolContentSchema.Type;
119
-
120
- export const ProposalContentSchema = TSchema.Union(
121
- TSchema.Struct(
122
- {
123
- ProposeIAsset: ProposeIAssetContentSchema,
124
- },
125
- { flatInUnion: true },
126
- ),
127
- TSchema.Struct(
128
- {
129
- ModifyIAsset: ModifyIAssetContentSchema,
130
- },
131
- { flatInUnion: true },
132
- ),
133
- TSchema.Struct(
134
- {
135
- AddCollateralAsset: AddCollateralAssetContentSchema,
136
- },
137
- { flatInUnion: true },
138
- ),
139
- TSchema.Struct(
140
- {
141
- UpdateCollateralAsset: UpdateCollateralAssetContentSchema,
142
- },
143
- { flatInUnion: true },
144
- ),
145
- TSchema.Struct(
146
- {
147
- ProposeStableswapPool: ProposeStableswapPoolContentSchema,
148
- },
149
- { flatInUnion: true },
150
- ),
151
- TSchema.Struct(
152
- {
153
- ModifyStableswapPool: ModifyStableswapPoolContentSchema,
154
- },
155
- { flatInUnion: true },
156
- ),
157
- TSchema.Struct(
158
- {
159
- ModifyProtocolParams: TSchema.Struct(
160
- {
161
- newParams: ProtocolParamsSchema,
162
- },
163
- { flatFields: true },
164
- ),
165
- },
166
- { flatInUnion: true },
167
- ),
168
- TSchema.Struct(
169
- {
170
- UpgradeProtocol: TSchema.Struct(
171
- {
172
- content: UpgradePathsSchema,
173
- },
174
- { flatFields: true },
175
- ),
176
- },
177
- { flatInUnion: true },
178
- ),
179
- TSchema.Struct(
180
- {
181
- TextProposal: TSchema.ByteArray,
182
- },
183
- { flatInUnion: true },
184
- ),
185
- );
186
- export type ProposalContent = typeof ProposalContentSchema.Type;
187
-
188
- const TreasuryWithdrawalItemSchema = TSchema.Struct({
189
- currencySymbol: TSchema.ByteArray,
190
- tokenName: TSchema.ByteArray,
191
- amount: TSchema.Integer,
192
- });
193
- export type TreasuryWithdrawalItem = typeof TreasuryWithdrawalItemSchema.Type;
194
-
195
- export const TreasuryWithdrawalSchema = TSchema.Struct({
196
- destination: AddressSchema,
197
- value: TSchema.Array(TreasuryWithdrawalItemSchema),
198
- });
199
- export type TreasuryWithdrawal = typeof TreasuryWithdrawalSchema.Type;
200
-
201
- const GovRedeemerSchema = TSchema.Union(
202
- TSchema.Struct(
203
- {
204
- CreatePoll: TSchema.Struct(
205
- {
206
- currentTime: TSchema.Integer,
207
- proposalOwner: TSchema.ByteArray,
208
- content: ProposalContentSchema,
209
- treasuryWithdrawal: TSchema.NullOr(TreasuryWithdrawalSchema),
210
- },
211
- { flatFields: true },
212
- ),
213
- },
214
- { flatInUnion: true },
215
- ),
216
- TSchema.Struct(
217
- {
218
- WitnessEndPoll: TSchema.Struct(
219
- {
220
- currentTime: TSchema.Integer,
221
- },
222
- { flatFields: true },
223
- ),
224
- },
225
- { flatInUnion: true },
226
- ),
227
- TSchema.Literal('UpgradeGov', { flatInUnion: true }),
228
- TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
229
- );
230
- export type GovRedeemer = typeof GovRedeemerSchema.Type;
231
-
232
- const GovDatumSchema = TSchema.Struct({
233
- currentProposal: TSchema.Integer,
234
- protocolParams: ProtocolParamsSchema,
235
- currentVersion: TSchema.Integer,
236
- iassetsCount: TSchema.Integer,
237
- activeProposals: TSchema.Integer,
238
- });
239
- export type GovDatum = typeof GovDatumSchema.Type;
240
-
241
- export function serialiseGovRedeemer(r: GovRedeemer): string {
242
- return Data.withSchema(GovRedeemerSchema).toCBORHex(r);
243
- }
244
-
245
- export function serialiseGovDatum(d: GovDatum): string {
246
- return Data.withSchema(GovDatumSchema).toCBORHex(d);
247
- }
248
-
249
- export function parseGovDatum(datum: string): O.Option<GovDatum> {
250
- try {
251
- return O.some(
252
- Data.withSchema(GovDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
253
- datum,
254
- ),
255
- );
256
- } catch (_) {
257
- return O.none;
258
- }
259
- }
260
-
261
- export function parseGovDatumOrThrow(datum: string): GovDatum {
262
- return F.pipe(
263
- parseGovDatum(datum),
264
- O.match(() => {
265
- throw new Error('Expected a Gov datum.');
266
- }, F.identity),
267
- );
268
- }
@@ -1,22 +0,0 @@
1
- import { Data } from '@lucid-evolution/lucid';
2
- import { AssetClassSchema } from '../../types/generic';
3
-
4
- const GovParamsSchema = Data.Object({
5
- govNFT: AssetClassSchema,
6
- pollToken: AssetClassSchema,
7
- upgradeToken: AssetClassSchema,
8
- indyAsset: AssetClassSchema,
9
- versionRecordToken: AssetClassSchema,
10
- iassetSymbol: Data.Bytes(),
11
- pollManagerValHash: Data.Bytes(),
12
- iassetValHash: Data.Bytes(),
13
- gBiasTime: Data.Integer(),
14
- daoIdentityToken: AssetClassSchema,
15
- iAssetAuthToken: AssetClassSchema,
16
- });
17
- export type GovParams = Data.Static<typeof GovParamsSchema>;
18
- export const GovParams = GovParamsSchema as unknown as GovParams;
19
-
20
- export function castGovParams(params: GovParams): Data {
21
- return Data.castTo(params, GovParams);
22
- }
@@ -1,170 +0,0 @@
1
- import {
2
- credentialToRewardAddress,
3
- Data,
4
- fromHex,
5
- LucidEvolution,
6
- OutRef,
7
- scriptHashToCredential,
8
- toHex,
9
- TxBuilder,
10
- UTxO,
11
- } from '@lucid-evolution/lucid';
12
- import { IAssetPriceInfo } from './types';
13
- import { matchSingle } from '../../utils/utils';
14
- import { parsePriceOracleDatum } from '../price-oracle/types-new';
15
- import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
16
- import { oracleExpirationAwareValidity } from '../price-oracle/helpers';
17
- import {
18
- fromSysParamsDerivedPythPrice,
19
- fromSystemParamsScriptRef,
20
- getPythFeedConfig,
21
- PythConfig,
22
- } from '../../types/system-params';
23
- import {
24
- parsePythStateDatum,
25
- serialisePythFeedRedeemer,
26
- serialisePythUpdatesRedeemer,
27
- } from '../pyth-feed/types';
28
- import { match, P } from 'ts-pattern';
29
- import { derivePythPrice } from '../pyth-feed/helpers';
30
- import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
31
- import * as Core from '@evolution-sdk/evolution';
32
- import { decodePriceUpdate, decodePythMessage } from '../../utils/pyth';
33
-
34
- export const MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
35
-
36
- type Interval = {
37
- validFrom: number;
38
- validTo: number;
39
- };
40
-
41
- export function attachOracle(
42
- iasset: Uint8Array<ArrayBufferLike>,
43
- collateralAsset: AssetClass,
44
- priceInfo: IAssetPriceInfo,
45
- priceOracleOref: OutRef | undefined,
46
- pythStateOref: OutRef | undefined,
47
- pythMessage: string | undefined,
48
- pythConfig: PythConfig,
49
- biasTime: bigint,
50
- lucid: LucidEvolution,
51
- tx: TxBuilder,
52
- ): Promise<{ interval: Interval; referenceInputs: UTxO[] }> {
53
- return match(priceInfo)
54
- .returnType<Promise<{ interval: Interval; referenceInputs: UTxO[] }>>()
55
- .with({ Delisted: P.any }, () => {
56
- const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
57
-
58
- // We want to make sure the transaction is valid within the bias time for interest tracking AND Pyth
59
- // For validFrom, we take the higher of the two bias times
60
- const validFrom = Number(currentTime - BigInt(biasTime / 2n));
61
- // For validTo, we take the lower of the two bias times
62
- const validTo = Number(currentTime + BigInt(biasTime / 2n));
63
-
64
- return Promise.resolve({
65
- interval: {
66
- validFrom,
67
- validTo,
68
- },
69
- referenceInputs: [],
70
- });
71
- })
72
- .with({ OracleNft: P.any }, async () => {
73
- if (!priceOracleOref) throw new Error('Missing price oracle');
74
-
75
- const priceOracleUtxo = matchSingle<UTxO>(
76
- await lucid.utxosByOutRef([priceOracleOref]),
77
- (_) => new Error('Expected a single price oracle UTXO'),
78
- );
79
- const priceOracleDatum = parsePriceOracleDatum(
80
- getInlineDatumOrThrow(priceOracleUtxo),
81
- );
82
-
83
- return {
84
- interval: oracleExpirationAwareValidity(
85
- lucid,
86
- Number(biasTime),
87
- Number(priceOracleDatum.expirationTime),
88
- ),
89
- referenceInputs: [priceOracleUtxo],
90
- };
91
- })
92
- .with(
93
- { DeferredValidation: { feedValHash: P.select() } },
94
- async (feedValHash) => {
95
- if (priceOracleOref) throw new Error('Cannot pass price oracle oref');
96
- if (!pythMessage) throw new Error('Missing Pyth message');
97
- if (!pythStateOref) throw new Error('Missing pyth state out ref');
98
-
99
- const pythStateUtxo = matchSingle(
100
- await lucid.utxosByOutRef([pythStateOref]),
101
- (_) => new Error('Expected a single pyth state UTXO'),
102
- );
103
-
104
- const pythStateDatum = parsePythStateDatum(
105
- getInlineDatumOrThrow(pythStateUtxo),
106
- );
107
-
108
- const pythFeedCfg = getPythFeedConfig(
109
- pythConfig,
110
- iasset,
111
- collateralAsset,
112
- );
113
-
114
- // Lookup PFV Validator
115
- const pfvScriptRefUtxo = matchSingle(
116
- await lucid.utxosByOutRef([
117
- fromSystemParamsScriptRef(pythFeedCfg.pythFeedValScriptRef),
118
- ]),
119
- (_) =>
120
- new Error('Expected a single pyth feed validator Ref Script UTXO'),
121
- );
122
-
123
- const derivedPythPrice = fromSysParamsDerivedPythPrice(
124
- pythFeedCfg.params.config,
125
- );
126
-
127
- const price = derivePythPrice(derivedPythPrice, pythMessage);
128
-
129
- const decodedMessage = decodePythMessage(fromHex(pythMessage));
130
- const pricePayload = decodePriceUpdate(decodedMessage.payload);
131
- const pythTimestamp = Number(pricePayload.timestampUs) / 1_000;
132
-
133
- tx.withdraw(
134
- credentialToRewardAddress(
135
- lucid.config().network!,
136
- scriptHashToCredential(toHex(pythStateDatum.withdraw_script)),
137
- ),
138
- 0n,
139
- serialisePythUpdatesRedeemer([fromHex(pythMessage)]),
140
- );
141
-
142
- tx.withdraw(
143
- credentialToRewardAddress(
144
- lucid.config().network!,
145
- scriptHashToCredential(toHex(feedValHash)),
146
- ),
147
- 0n,
148
- serialisePythFeedRedeemer({
149
- price: price,
150
- auxiliaryData: Core.Data.fromCBORHex(Data.void()),
151
- }),
152
- );
153
-
154
- // 5 minutes - 20 seconds
155
- const pythMaxDelay = 280 * 1000;
156
-
157
- const validFrom = Number(pythTimestamp);
158
- const validTo = Number(pythTimestamp + pythMaxDelay);
159
-
160
- return {
161
- interval: {
162
- validFrom: validFrom,
163
- validTo: validTo,
164
- },
165
- referenceInputs: [pythStateUtxo, pfvScriptRefUtxo],
166
- };
167
- },
168
- )
169
- .exhaustive();
170
- }
@@ -1,102 +0,0 @@
1
- import { LucidEvolution, toHex } from '@lucid-evolution/lucid';
2
- import { fromSystemParamsAsset, SystemParams } from '../../types/system-params';
3
- import {
4
- AssetClass,
5
- assetClassToUnit,
6
- isSameAssetClass,
7
- matchSingle,
8
- } from '@3rd-eye-labs/cardano-offchain-common';
9
- import {
10
- CollateralAssetOutput,
11
- IAssetOutput,
12
- parseCollateralAssetDatum,
13
- parseIAssetDatum,
14
- } from './types';
15
- import { createScriptAddress } from '../../utils/lucid-utils';
16
- import { option as O, array as A, function as F } from 'fp-ts';
17
-
18
- export async function findIAsset(
19
- lucid: LucidEvolution,
20
- sysParams: SystemParams,
21
- /**
22
- * For conversion from hex use the `fromHex` function from lucid-evolution.
23
- */
24
- iassetName: Uint8Array<ArrayBufferLike>,
25
- ): Promise<IAssetOutput> {
26
- const iassetUtxos = await lucid.utxosAtWithUnit(
27
- createScriptAddress(
28
- lucid.config().network!,
29
- sysParams.validatorHashes.iassetHash,
30
- ),
31
- assetClassToUnit(
32
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
33
- ),
34
- );
35
-
36
- return matchSingle(
37
- F.pipe(
38
- iassetUtxos.map((utxo) =>
39
- F.pipe(
40
- O.fromNullable(utxo.datum),
41
- O.flatMap(parseIAssetDatum),
42
- O.flatMap((datum) => {
43
- if (toHex(datum.assetName) === toHex(iassetName)) {
44
- return O.some({ utxo, datum: datum });
45
- } else {
46
- return O.none;
47
- }
48
- }),
49
- ),
50
- ),
51
- A.compact,
52
- ),
53
- (res) =>
54
- new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
55
- );
56
- }
57
-
58
- export async function findCollateralAsset(
59
- lucid: LucidEvolution,
60
- sysParams: SystemParams,
61
- /**
62
- * For conversion from hex use the `fromHex` function from lucid-evolution.
63
- */
64
- iassetName: Uint8Array<ArrayBufferLike>,
65
- collateralAsset: AssetClass,
66
- ): Promise<CollateralAssetOutput> {
67
- const collateralAssetUtxos = await lucid.utxosAtWithUnit(
68
- createScriptAddress(
69
- lucid.config().network!,
70
- sysParams.validatorHashes.iassetHash,
71
- ),
72
- assetClassToUnit(
73
- fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
74
- ),
75
- );
76
-
77
- return matchSingle(
78
- F.pipe(
79
- collateralAssetUtxos.map((utxo) =>
80
- F.pipe(
81
- O.fromNullable(utxo.datum),
82
- O.flatMap(parseCollateralAssetDatum),
83
- O.flatMap((datum) => {
84
- if (
85
- isSameAssetClass(datum.collateralAsset, collateralAsset) &&
86
- toHex(iassetName) === toHex(datum.iasset)
87
- ) {
88
- return O.some({ utxo, datum: datum });
89
- } else {
90
- return O.none;
91
- }
92
- }),
93
- ),
94
- ),
95
- A.compact,
96
- ),
97
- (res) =>
98
- new Error(
99
- 'Expected a single Collateral Asset UTXO.: ' + JSON.stringify(res),
100
- ),
101
- );
102
- }
@@ -1,38 +0,0 @@
1
- import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
2
- import {
3
- fromSystemParamsAssetLucid,
4
- IAssetParamsSP,
5
- } from '../../types/system-params';
6
- import { _cdpValidator } from '../../validators/cdp-validator';
7
- import { _iassetValidator } from '../../validators/iasset-validator';
8
-
9
- import { Data } from '@lucid-evolution/lucid';
10
- import { AssetClassSchema } from '../../types/generic';
11
-
12
- const IAssetScriptParamsSchema = Data.Object({
13
- upgradeToken: AssetClassSchema,
14
- versionRecordToken: AssetClassSchema,
15
- });
16
-
17
- export type IAssetScriptParams = Data.Static<typeof IAssetScriptParamsSchema>;
18
- export const IAssetScriptParams =
19
- IAssetScriptParamsSchema as unknown as IAssetScriptParams;
20
-
21
- export const mkIAssetValidatorFromSP = (
22
- params: IAssetParamsSP,
23
- ): SpendingValidator => {
24
- return {
25
- type: 'PlutusV3',
26
- script: applyParamsToScript(_iassetValidator.cborHex, [
27
- Data.castTo(
28
- {
29
- upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
30
- versionRecordToken: fromSystemParamsAssetLucid(
31
- params.versionRecordToken,
32
- ),
33
- },
34
- IAssetScriptParams,
35
- ),
36
- ]),
37
- };
38
- };