@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,463 +0,0 @@
1
- import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
2
- import {
3
- Credential,
4
- fromHex,
5
- fromText,
6
- OutRef,
7
- toHex,
8
- toText,
9
- } from '@lucid-evolution/lucid';
10
- import { AssetClassD, StakeCredential } from './generic';
11
- import {
12
- DerivedPythPrice,
13
- PythFeedParams,
14
- toDataDerivedPythPrice,
15
- } from '../contracts/pyth-feed/types';
16
- import { match } from 'ts-pattern';
17
- import { P } from 'ts-pattern';
18
-
19
- export interface CurrencySymbolSP {
20
- unCurrencySymbol: string;
21
- }
22
-
23
- export interface TokenNameSP {
24
- unTokenName: string;
25
- }
26
-
27
- /**
28
- * AssetClassSP used in System Params
29
- */
30
- export type AssetClassSP = [CurrencySymbolSP, TokenNameSP];
31
-
32
- export type PythPriceConfigurationSP = {
33
- priceFeedId: number;
34
- };
35
-
36
- export type DerivedPythPriceSP =
37
- | {
38
- tag: 'value';
39
- val: PythPriceConfigurationSP;
40
- }
41
- | {
42
- tag: 'inverse';
43
- val: DerivedPythPriceSP;
44
- }
45
- | {
46
- tag: 'divide';
47
- val: [DerivedPythPriceSP, DerivedPythPriceSP];
48
- };
49
-
50
- export type PythFeedParamsSP = {
51
- config: DerivedPythPriceSP;
52
- pythStatePolicyId: CurrencySymbolSP;
53
- };
54
-
55
- export function fromSysParamsDerivedPythPrice(
56
- cfg: DerivedPythPriceSP,
57
- ): DerivedPythPrice {
58
- return match(cfg)
59
- .returnType<DerivedPythPrice>()
60
- .with({ tag: 'value', val: P.select() }, (val) => {
61
- return {
62
- Value: {
63
- configuration: {
64
- priceFeedId: BigInt(val.priceFeedId),
65
- },
66
- },
67
- };
68
- })
69
- .with({ tag: 'inverse', val: P.select() }, (val) => {
70
- return {
71
- Inverse: {
72
- value: toDataDerivedPythPrice(fromSysParamsDerivedPythPrice(val)),
73
- },
74
- };
75
- })
76
- .with({ tag: 'divide', val: P.select() }, (val) => {
77
- return {
78
- Divide: {
79
- x: toDataDerivedPythPrice(fromSysParamsDerivedPythPrice(val[0])),
80
- y: toDataDerivedPythPrice(fromSysParamsDerivedPythPrice(val[1])),
81
- },
82
- };
83
- })
84
- .exhaustive();
85
- }
86
-
87
- export function fromSysParamsPythFeedParams(
88
- params: PythFeedParamsSP,
89
- ): PythFeedParams {
90
- return {
91
- config: fromSysParamsDerivedPythPrice(params.config),
92
- pythStatePolicyId: fromHex(params.pythStatePolicyId.unCurrencySymbol),
93
- };
94
- }
95
-
96
- export type PythFeedConfig = {
97
- params: PythFeedParamsSP;
98
- pythFeedValHash: string;
99
- pythFeedValScriptRef: ScriptReference;
100
- };
101
-
102
- export type PythConfig = {
103
- pythStateAssetClass: AssetClassSP;
104
- /**
105
- * Key is in the format: "iAsset.ascii/Collateral.currency.hex.Collateral.tokenName.hex".
106
- * Use the `getPythFeedConfig` helper to querying.
107
- */
108
- pythFeeds: {
109
- [key: string]: PythFeedConfig;
110
- };
111
- };
112
-
113
- export function getPythFeedConfig(
114
- cfg: PythConfig,
115
- iasset: Uint8Array<ArrayBufferLike>,
116
- collateralAsset: AssetClass,
117
- ): PythFeedConfig {
118
- const res =
119
- cfg.pythFeeds[
120
- `${toText(toHex(iasset))}/${toHex(collateralAsset.currencySymbol)}.${toHex(collateralAsset.tokenName)}`
121
- ];
122
-
123
- if (res == null)
124
- throw new Error('No Pyth config known for such assets combination');
125
-
126
- return res;
127
- }
128
-
129
- export interface SystemParams {
130
- versionRecordParams: VersionRecordParams;
131
- validatorHashes: ValidatorHashes;
132
- treasuryParams: TreasuryParamsSP;
133
- startTime: StartTime;
134
- stakingParams: StakingParamsSP;
135
- stabilityPoolParams: StabilityPoolParamsSP;
136
- stableswapParams: StableswapParamsSP;
137
- scriptReferences: ScriptReferences;
138
- pollShardParams: PollShardParamsSP;
139
- pollManagerParams: PollManagerParamsSP;
140
- robParams: RobParamsSP;
141
- interestCollectionParams: InterestCollectionParamsSP;
142
- indyToken: AssetClassSP;
143
- govParams: GovParamsSP;
144
- executeParams: ExecuteParamsSP;
145
- collectorParams: CollectorParamsSP;
146
- cdpParams: CdpParamsSP;
147
- cdpCreatorParams: CDPCreatorParamsSP;
148
- cdpRedeemParams: CdpRedeemParamsSP;
149
- iassetParams: IAssetParamsSP;
150
- pythConfig: PythConfig;
151
- }
152
- export type ValidatorHashes = {
153
- versionRegistryHash: string;
154
- treasuryHash: string;
155
- stableswapHash: string;
156
- stakingHash: string;
157
- stabilityPoolHash: string;
158
- pollShardHash: string;
159
- pollManagerHash: string;
160
- robHash: string;
161
- interestCollectionHash: string;
162
- govHash: string;
163
- executeHash: string;
164
- collectorHash: string;
165
- cdpHash: string;
166
- cdpCreatorHash: string;
167
- iassetHash: string;
168
- };
169
- export interface AddressCredential {
170
- tag: string;
171
- contents: PubKeyHash;
172
- }
173
-
174
- export interface ScriptCredential {
175
- tag: string;
176
- contents: {
177
- tag: string;
178
- contents: string;
179
- };
180
- }
181
- export interface PubKeyHash {
182
- getPubKeyHash: string;
183
- }
184
- export interface VersionRecordParams {
185
- upgradeToken: AssetClassSP;
186
- }
187
- export interface TreasuryParamsSP {
188
- upgradeToken: AssetClassSP;
189
- versionRecordToken: AssetClassSP;
190
- treasuryUtxosStakeCredential: ScriptCredential | undefined;
191
- }
192
- export interface StartTime {
193
- slot: number;
194
- blockHeader: string;
195
- }
196
- export interface StakingParamsSP {
197
- versionRecordToken: AssetClassSP;
198
- stakingToken: AssetClassSP;
199
- stakingManagerNFT: AssetClassSP;
200
- pollToken: AssetClassSP;
201
- indyToken: AssetClassSP;
202
- collectorValHash: string;
203
- }
204
- export interface StabilityPoolParamsSP {
205
- versionRecordToken: AssetClassSP;
206
- stabilityPoolToken: AssetClassSP;
207
- snapshotEpochToScaleToSumToken: AssetClassSP;
208
- iAssetAuthToken: AssetClassSP;
209
- iassetValHash: string;
210
- cdpToken: AssetClassSP;
211
- assetSymbol: CurrencySymbolSP;
212
- accountToken: AssetClassSP;
213
- accountCreateFeeLovelaces: number;
214
- accountProcessingCooldownMs: number;
215
- accountProcessingBiasMs: number;
216
- stakeCredential: ScriptCredential | undefined;
217
- }
218
-
219
- export interface StableswapParamsSP {
220
- iassetSymbol: CurrencySymbolSP;
221
- cdpToken: AssetClassSP;
222
- versionRecordToken: AssetClassSP;
223
- cdpValHash: string;
224
- treasuryValHash: string;
225
- }
226
-
227
- export interface ScriptReferences {
228
- versionRegistryValidatorRef: ScriptReference;
229
- treasuryValidatorRef: ScriptReference;
230
- stakingValidatorRef: ScriptReference;
231
- stabilityPoolValidatorRef: ScriptReference;
232
- stableswapValidatorRef: ScriptReference;
233
- pollShardValidatorRef: ScriptReference;
234
- pollManagerValidatorRef: ScriptReference;
235
- robValidatorRef: ScriptReference;
236
- interestCollectionValidatorRef: ScriptReference;
237
- iAssetTokenPolicyRef: ScriptReference;
238
- governanceValidatorRef: ScriptReference;
239
- executeValidatorRef: ScriptReference;
240
- collectorValidatorRef: ScriptReference;
241
- cdpValidatorRef: ScriptReference;
242
- cdpCreatorValidatorRef: ScriptReference;
243
- cdpRedeemValidatorRef: ScriptReference;
244
- iassetValidatorRef: ScriptReference;
245
- authTokenPolicies: AuthTokenPolicies;
246
- }
247
- export interface Output {
248
- scriptRef: ScriptRef;
249
- output: ScriptOutput;
250
- }
251
- export interface ScriptRef {
252
- tag: string;
253
- contents?: string[] | null;
254
- }
255
- export interface ScriptOutput {
256
- referenceScript: string;
257
- datum: AddressCredentialOrDatum;
258
- amount: Amount;
259
- address: AddressSP;
260
- }
261
- export interface AddressCredentialOrDatum {
262
- tag: string;
263
- contents: string;
264
- }
265
- export interface Amount {
266
- getValue?:
267
- | ((CurrencySymbolSP | (number[] | null)[] | null)[] | null)[]
268
- | null;
269
- }
270
- export interface AddressSP {
271
- addressStakingCredential?: null;
272
- addressCredential: AddressCredentialOrDatum;
273
- }
274
- export interface Input {
275
- transactionId: string;
276
- index: number;
277
- }
278
-
279
- export interface ScriptReference {
280
- output?: Output;
281
- input: Input;
282
- }
283
-
284
- export interface AuthTokenPolicies {
285
- upgradeTokenRef: ScriptReference;
286
- stakingTokenRef: ScriptReference;
287
- stabilityPoolTokenRef: ScriptReference;
288
- stabilityPoolAuthTokenRef: ScriptReference;
289
- snapshotEpochToScaleToSumTokenRef: ScriptReference;
290
- pollManagerTokenRef: ScriptReference;
291
- iAssetAuthTokenRef: ScriptReference;
292
- iAssetTokenRef: ScriptReference;
293
- collateralAssetTokenRef: ScriptReference;
294
- cdpAuthTokenRef: ScriptReference;
295
- accountTokenRef: ScriptReference;
296
- versionRecordTokenPolicyRef: ScriptReference;
297
- }
298
-
299
- export interface RobParamsSP {
300
- versionRecordToken: AssetClassSP;
301
- iassetAuthToken: AssetClassSP;
302
- collateralAssetAuthToken: AssetClassSP;
303
- iassetValHash: string;
304
- iassetPolicyId: CurrencySymbolSP;
305
- }
306
-
307
- export interface InterestCollectionParamsSP {
308
- versionRecordNft: AssetClassSP;
309
- multisigUtxoNft: AssetClassSP;
310
- cdpAuthTk: AssetClassSP;
311
- collateralAssetAuthTk: AssetClassSP;
312
- govAuthTk: AssetClassSP;
313
- cdpAssetSymbol: CurrencySymbolSP;
314
- cdpBiasTime: bigint;
315
- interestSettlementCooldown: bigint;
316
- }
317
-
318
- export interface PollShardParamsSP {
319
- stakingValHash: string;
320
- stakingToken: AssetClassSP;
321
- pollToken: AssetClassSP;
322
- indyAsset: AssetClassSP;
323
- }
324
-
325
- export interface PollManagerParamsSP {
326
- upgradeToken: AssetClassSP;
327
- treasuryValHash: string;
328
- shardsValHash: string;
329
- pollToken: AssetClassSP;
330
- pBiasTime: bigint;
331
- indyAsset: AssetClassSP;
332
- govNFT: AssetClassSP;
333
- govExecuteValHash: string;
334
- }
335
-
336
- export interface GovParamsSP {
337
- versionRecordToken: AssetClassSP;
338
- upgradeToken: AssetClassSP;
339
- pollToken: AssetClassSP;
340
- pollManagerValHash: string;
341
- iassetValHash: string;
342
- indyAsset: AssetClassSP;
343
- iAssetAuthToken: AssetClassSP;
344
- govNFT: AssetClassSP;
345
- gBiasTime: bigint;
346
- daoIdentityToken: AssetClassSP;
347
- iassetSymbol: CurrencySymbolSP;
348
- }
349
-
350
- export interface ExecuteParamsSP {
351
- govNFT: AssetClassSP;
352
- upgradeToken: AssetClassSP;
353
- iAssetToken: AssetClassSP;
354
- collateralAssetToken: AssetClassSP;
355
- stabilityPoolToken: AssetClassSP;
356
- cdpCreatorToken: AssetClassSP;
357
- cdpToken: AssetClassSP;
358
- versionRecordToken: AssetClassSP;
359
- iassetValHash: string;
360
- cdpValHash: string;
361
- sPoolValHash: string;
362
- versionRegistryValHash: string;
363
- treasuryValHash: string;
364
- }
365
- export interface CollectorParamsSP {
366
- versionRecordToken: AssetClassSP;
367
- stakingToken: AssetClassSP;
368
- stakingManagerNFT: AssetClassSP;
369
- }
370
- export interface CdpRedeemParamsSP {
371
- treasuryValHash: string;
372
- iassetValHash: string;
373
- partialRedemptionExtraFeeLovelace: number;
374
- iAssetAuthToken: AssetClassSP;
375
- collateralAssetAuthToken: AssetClassSP;
376
- govNFT: AssetClassSP;
377
- interestCollectorValHash: string;
378
- cdpAuthToken: AssetClassSP;
379
- cdpAssetSymbol: CurrencySymbolSP;
380
- biasTime: bigint;
381
- }
382
- export interface CdpParamsSP {
383
- upgradeToken: AssetClassSP;
384
- versionRecordToken: AssetClassSP;
385
- treasuryValHash: string;
386
- stabilityPoolAuthToken: AssetClassSP;
387
- spValHash: string;
388
- iassetValHash: string;
389
- iAssetAuthToken: AssetClassSP;
390
- collateralAssetAuthToken: AssetClassSP;
391
- interestCollectorValHash: string;
392
- cdpRedeemValHash: string;
393
- cdpAuthToken: AssetClassSP;
394
- cdpAssetSymbol: CurrencySymbolSP;
395
- biasTime: bigint;
396
- }
397
-
398
- export interface IAssetParamsSP {
399
- upgradeToken: AssetClassSP;
400
- versionRecordToken: AssetClassSP;
401
- }
402
-
403
- export interface CDPCreatorParamsSP {
404
- versionRecordToken: AssetClassSP;
405
- upgradeToken: AssetClassSP;
406
- iAssetAuthTk: AssetClassSP;
407
- collateralAssetAuthTk: AssetClassSP;
408
- treasuryValHash: string;
409
- cdpScriptHash: string;
410
- iassetValHash: string;
411
- cdpCreatorNft: AssetClassSP;
412
- cdpAuthTk: AssetClassSP;
413
- cdpAssetCs: CurrencySymbolSP;
414
- biasTime: bigint;
415
- }
416
-
417
- export function toSystemParamsAsset(asset: AssetClass): AssetClassSP {
418
- return [
419
- { unCurrencySymbol: toHex(asset.currencySymbol) },
420
- { unTokenName: toText(toHex(asset.tokenName)) },
421
- ];
422
- }
423
-
424
- export function fromSystemParamsAsset(asset: AssetClassSP): AssetClass {
425
- return {
426
- currencySymbol: fromHex(asset[0].unCurrencySymbol),
427
- tokenName: fromHex(fromText(asset[1].unTokenName)),
428
- };
429
- }
430
-
431
- export function fromSystemParamsAssetLucid(asset: AssetClassSP): AssetClassD {
432
- return {
433
- currencySymbol: asset[0].unCurrencySymbol,
434
- tokenName: fromText(asset[1].unTokenName),
435
- };
436
- }
437
-
438
- export function fromSystemParamsScriptRef(ref: ScriptReference): OutRef {
439
- return { outputIndex: ref.input.index, txHash: ref.input.transactionId };
440
- }
441
-
442
- export function fromSysParamsCredential(cred: ScriptCredential): Credential {
443
- if (cred.contents.tag === 'PublicKeyCredential') {
444
- return { type: 'Key', hash: cred.contents.contents };
445
- }
446
- return { type: 'Script', hash: cred.contents.contents };
447
- }
448
-
449
- export function fromSysParamsStakeCredential(
450
- cred: ScriptCredential,
451
- ): StakeCredential {
452
- return {
453
- Inline: [
454
- cred.contents.tag === 'PublicKeyCredential'
455
- ? {
456
- PublicKeyCredential: [cred.contents.contents],
457
- }
458
- : {
459
- ScriptCredential: [cred.contents.contents],
460
- },
461
- ],
462
- };
463
- }
@@ -1,108 +0,0 @@
1
- import {
2
- array as A,
3
- ord as Ord,
4
- readonlyArray as RA,
5
- option as O,
6
- function as F,
7
- } from 'fp-ts';
8
- import { Predicate } from 'fp-ts/lib/Predicate';
9
-
10
- export function shuffle<T>(arr: T[]): T[] {
11
- const source = [...arr];
12
- for (let i = source.length - 1; i > 0; i--) {
13
- const j = Math.floor(Math.random() * (i + 1));
14
- [source[i], source[j]] = [source[j], source[i]];
15
- }
16
-
17
- return source;
18
- }
19
-
20
- /**
21
- * The parameter `arr` should be sorted for correct results.
22
- */
23
- export function insertSorted<T>(arr: T[], item: T, ord: Ord.Ord<T>): T[] {
24
- if (arr.length === 0) {
25
- return [item];
26
- }
27
-
28
- const arrOrd = ord.compare(arr[0], arr[arr.length - 1]);
29
- // Array containing the same items
30
- if (arrOrd === 0) {
31
- if (ord.compare(arr[0], item) === -1) {
32
- return [...arr, item];
33
- } else {
34
- return [item, ...arr];
35
- }
36
- }
37
-
38
- // TODO: could be improved with binary search
39
- for (let i = 0; i < arr.length; i++) {
40
- if (ord.compare(arr[i], item) !== arrOrd) {
41
- return [...A.takeLeft(i)(arr), item, ...A.takeRight(arr.length - i)(arr)];
42
- }
43
- }
44
-
45
- return [...arr, item];
46
- }
47
-
48
- /**
49
- * Replace when existent, otherwise add at the end.
50
- */
51
- export const repsertReadonlyArr =
52
- <K, V>(predicate: Predicate<K>, val: V, mkKey: () => K) =>
53
- (arr: ReadonlyArray<readonly [K, V]>): ReadonlyArray<readonly [K, V]> => {
54
- const idx = F.pipe(
55
- arr,
56
- RA.findIndex(([key, _]) => predicate(key)),
57
- );
58
-
59
- const res = F.pipe(
60
- idx,
61
- O.chain((i) =>
62
- F.pipe(
63
- arr,
64
- RA.modifyAt(i, ([key, _]) => [key, val]),
65
- ),
66
- ),
67
- );
68
-
69
- return F.pipe(
70
- res,
71
- O.getOrElse<ReadonlyArray<readonly [K, V]>>(() => [
72
- ...arr,
73
- [mkKey(), val],
74
- ]),
75
- );
76
- };
77
-
78
- export const repsertWithReadonlyArr =
79
- <K, V>(
80
- predicate: Predicate<K>,
81
- replaceVal: (oldVal: V) => V,
82
- newVal: () => V,
83
- mkKey: () => K,
84
- ) =>
85
- (arr: ReadonlyArray<readonly [K, V]>): ReadonlyArray<readonly [K, V]> => {
86
- const idx = F.pipe(
87
- arr,
88
- RA.findIndex(([key, _]) => predicate(key)),
89
- );
90
-
91
- const res = F.pipe(
92
- idx,
93
- O.chain((i) =>
94
- F.pipe(
95
- arr,
96
- RA.modifyAt(i, ([key, oldVal]) => [key, replaceVal(oldVal)]),
97
- ),
98
- ),
99
- );
100
-
101
- return F.pipe(
102
- res,
103
- O.getOrElse<ReadonlyArray<readonly [K, V]>>(() => [
104
- ...arr,
105
- [mkKey(), newVal()],
106
- ]),
107
- );
108
- };
@@ -1,35 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- import { array as A, ord as Ord } from 'fp-ts';
3
-
4
- /**
5
- * Plutus division behaves differently when working with negative numbers vs positive ones.
6
- */
7
- export function divideOnChainCompatible(a: bigint, b: bigint): bigint {
8
- const res = a / b;
9
- return res + (res < 0n ? -1n : 0n);
10
- }
11
-
12
- export function bigintMax(a: bigint, b: bigint): bigint {
13
- return a > b ? a : b;
14
- }
15
-
16
- export function bigintMin(a: bigint, b: bigint): bigint {
17
- return a < b ? a : b;
18
- }
19
-
20
- export function sum(arr: bigint[]): bigint {
21
- return A.reduce<bigint, bigint>(0n, (acc, val) => acc + val)(arr);
22
- }
23
-
24
- export function fromDecimal(val: Decimal): bigint {
25
- return BigInt(val.toString());
26
- }
27
-
28
- export function zeroNegatives(a: bigint): bigint {
29
- return bigintMax(0n, a);
30
- }
31
-
32
- export const BigIntOrd: Ord.Ord<bigint> = {
33
- equals: (x, y) => x === y,
34
- compare: (first, second) => (first < second ? -1 : first > second ? 1 : 0),
35
- };
@@ -1,31 +0,0 @@
1
- import {
2
- LucidEvolution,
3
- Network,
4
- OutRef,
5
- SpendingValidator,
6
- validatorToAddress,
7
- } from '@lucid-evolution/lucid';
8
- import { alwaysFailValidator } from '../scripts/always-fail-validator';
9
-
10
- /**
11
- * TODO: remove this, it should be part of the testsuite only
12
- * Uses an always fail validator for the destination address.
13
- */
14
- export async function runCreateScriptRefTx(
15
- lucid: LucidEvolution,
16
- scriptRefValidator: SpendingValidator,
17
- network: Network,
18
- ): Promise<OutRef> {
19
- const scriptAddr = validatorToAddress(network, alwaysFailValidator);
20
-
21
- const txHash = await lucid
22
- .newTx()
23
- .pay.ToAddressWithData(scriptAddr, undefined, {}, scriptRefValidator)
24
- .complete()
25
- .then((tx) => tx.sign.withWallet().complete())
26
- .then((tx) => tx.submit());
27
-
28
- await lucid.awaitTx(txHash);
29
-
30
- return { txHash: txHash, outputIndex: 0 };
31
- }
@@ -1,17 +0,0 @@
1
- import {
2
- Rational,
3
- rationalFloor,
4
- rationalFromInt,
5
- rationalMul,
6
- } from '../types/rational';
7
-
8
- export function calculateFeeFromRatio(
9
- feeRatio: Rational,
10
- amount: bigint,
11
- ): bigint {
12
- if (amount < 0) {
13
- return 0n;
14
- }
15
-
16
- return rationalFloor(rationalMul(rationalFromInt(amount), feeRatio));
17
- }