@indigo-labs/indigo-sdk 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/dist/index.d.mts +11 -1
  2. package/dist/index.d.ts +11 -1
  3. package/dist/index.js +17 -0
  4. package/dist/index.mjs +15 -0
  5. package/package.json +11 -1
  6. package/.claude/settings.local.json +0 -7
  7. package/.github/workflows/ci.yml +0 -66
  8. package/.husky/pre-commit +0 -1
  9. package/.nvmrc +0 -1
  10. package/.prettierignore +0 -1
  11. package/.prettierrc +0 -6
  12. package/eslint.config.mjs +0 -42
  13. package/scripts/bench.sh +0 -62
  14. package/scripts/run-repeat.sh +0 -22
  15. package/src/contracts/cdp/helpers.ts +0 -173
  16. package/src/contracts/cdp/scripts.ts +0 -70
  17. package/src/contracts/cdp/transactions.ts +0 -1584
  18. package/src/contracts/cdp/types-new.ts +0 -277
  19. package/src/contracts/cdp/types.ts +0 -43
  20. package/src/contracts/cdp-creator/queries.ts +0 -30
  21. package/src/contracts/cdp-creator/scripts.ts +0 -45
  22. package/src/contracts/cdp-creator/types-new.ts +0 -50
  23. package/src/contracts/cdp-creator/types.ts +0 -24
  24. package/src/contracts/collector/scripts.ts +0 -32
  25. package/src/contracts/collector/transactions.ts +0 -50
  26. package/src/contracts/collector/types-new.ts +0 -17
  27. package/src/contracts/execute/scripts.ts +0 -57
  28. package/src/contracts/execute/types-new.ts +0 -44
  29. package/src/contracts/execute/types.ts +0 -24
  30. package/src/contracts/gov/helpers.ts +0 -351
  31. package/src/contracts/gov/scripts.ts +0 -41
  32. package/src/contracts/gov/transactions.ts +0 -1607
  33. package/src/contracts/gov/types-new.ts +0 -268
  34. package/src/contracts/gov/types.ts +0 -22
  35. package/src/contracts/iasset/helpers.ts +0 -170
  36. package/src/contracts/iasset/queries.ts +0 -102
  37. package/src/contracts/iasset/scripts.ts +0 -38
  38. package/src/contracts/iasset/types.ts +0 -154
  39. package/src/contracts/initialize/actions.ts +0 -789
  40. package/src/contracts/initialize/helpers.ts +0 -616
  41. package/src/contracts/initialize/types.ts +0 -116
  42. package/src/contracts/interest-collection/helpers.ts +0 -19
  43. package/src/contracts/interest-collection/queries.ts +0 -66
  44. package/src/contracts/interest-collection/scripts.ts +0 -44
  45. package/src/contracts/interest-collection/transactions.ts +0 -433
  46. package/src/contracts/interest-collection/types-new.ts +0 -50
  47. package/src/contracts/interest-collection/types.ts +0 -26
  48. package/src/contracts/interest-oracle/helpers.ts +0 -61
  49. package/src/contracts/interest-oracle/scripts.ts +0 -18
  50. package/src/contracts/interest-oracle/transactions.ts +0 -151
  51. package/src/contracts/interest-oracle/types-new.ts +0 -32
  52. package/src/contracts/interest-oracle/types.ts +0 -16
  53. package/src/contracts/one-shot/scripts.ts +0 -12
  54. package/src/contracts/one-shot/transactions.ts +0 -66
  55. package/src/contracts/one-shot/types.ts +0 -22
  56. package/src/contracts/poll/helpers.ts +0 -37
  57. package/src/contracts/poll/scripts.ts +0 -71
  58. package/src/contracts/poll/types-poll-manager.ts +0 -20
  59. package/src/contracts/poll/types-poll-new.ts +0 -196
  60. package/src/contracts/poll/types-poll-shard.ts +0 -16
  61. package/src/contracts/price-oracle/helpers.ts +0 -30
  62. package/src/contracts/price-oracle/scripts.ts +0 -18
  63. package/src/contracts/price-oracle/transactions.ts +0 -115
  64. package/src/contracts/price-oracle/types-new.ts +0 -50
  65. package/src/contracts/price-oracle/types.ts +0 -16
  66. package/src/contracts/pyth-feed/helpers.ts +0 -82
  67. package/src/contracts/pyth-feed/scripts.ts +0 -15
  68. package/src/contracts/pyth-feed/types.ts +0 -181
  69. package/src/contracts/rob/helpers.ts +0 -666
  70. package/src/contracts/rob/scripts.ts +0 -35
  71. package/src/contracts/rob/transactions.ts +0 -423
  72. package/src/contracts/rob/types-new.ts +0 -128
  73. package/src/contracts/rob/types.ts +0 -16
  74. package/src/contracts/rob-leverage/helpers.ts +0 -422
  75. package/src/contracts/rob-leverage/transactions.ts +0 -368
  76. package/src/contracts/stability-pool/helpers.ts +0 -798
  77. package/src/contracts/stability-pool/queries.ts +0 -132
  78. package/src/contracts/stability-pool/scripts.ts +0 -51
  79. package/src/contracts/stability-pool/transactions.ts +0 -921
  80. package/src/contracts/stability-pool/types-new.ts +0 -385
  81. package/src/contracts/stability-pool/types.ts +0 -25
  82. package/src/contracts/stableswap/helpers.ts +0 -507
  83. package/src/contracts/stableswap/scripts.ts +0 -37
  84. package/src/contracts/stableswap/transactions.ts +0 -475
  85. package/src/contracts/stableswap/types-new.ts +0 -131
  86. package/src/contracts/stableswap/types.ts +0 -17
  87. package/src/contracts/staking/helpers.ts +0 -136
  88. package/src/contracts/staking/scripts.ts +0 -41
  89. package/src/contracts/staking/transactions.ts +0 -349
  90. package/src/contracts/staking/types-new.ts +0 -137
  91. package/src/contracts/staking/types.ts +0 -17
  92. package/src/contracts/treasury/helpers.ts +0 -21
  93. package/src/contracts/treasury/queries.ts +0 -100
  94. package/src/contracts/treasury/scripts.ts +0 -27
  95. package/src/contracts/treasury/transactions.ts +0 -334
  96. package/src/contracts/treasury/types-new.ts +0 -69
  97. package/src/contracts/treasury/types.ts +0 -14
  98. package/src/contracts/version-registry/scripts.ts +0 -29
  99. package/src/contracts/version-registry/types-new.ts +0 -18
  100. package/src/contracts/version-registry/types.ts +0 -17
  101. package/src/index.ts +0 -93
  102. package/src/scripts/always-fail-validator.ts +0 -7
  103. package/src/scripts/auth-token-policy.ts +0 -24
  104. package/src/scripts/iasset-policy.ts +0 -23
  105. package/src/types/evolution-schema-options.ts +0 -16
  106. package/src/types/generic.ts +0 -52
  107. package/src/types/multisig.ts +0 -48
  108. package/src/types/on-chain-decimal.ts +0 -57
  109. package/src/types/rational.ts +0 -61
  110. package/src/types/system-params.ts +0 -463
  111. package/src/utils/array-utils.ts +0 -108
  112. package/src/utils/bigint-utils.ts +0 -35
  113. package/src/utils/helper-txs.ts +0 -31
  114. package/src/utils/indigo-helpers.ts +0 -17
  115. package/src/utils/lucid-utils.ts +0 -125
  116. package/src/utils/oracle-helpers.ts +0 -62
  117. package/src/utils/pyth/decode.ts +0 -223
  118. package/src/utils/pyth/encode.ts +0 -262
  119. package/src/utils/pyth/index.ts +0 -14
  120. package/src/utils/pyth/types.ts +0 -87
  121. package/src/utils/time-helpers.ts +0 -4
  122. package/src/utils/utils.ts +0 -25
  123. package/src/validators/always-succeed-validator.ts +0 -6
  124. package/src/validators/cdp-creator-validator.ts +0 -7
  125. package/src/validators/cdp-redeem-validator.ts +0 -7
  126. package/src/validators/cdp-validator.ts +0 -7
  127. package/src/validators/collector-validator.ts +0 -7
  128. package/src/validators/execute-validator.ts +0 -7
  129. package/src/validators/governance-validator.ts +0 -7
  130. package/src/validators/iasset-validator.ts +0 -7
  131. package/src/validators/interest-collection-validator.ts +0 -7
  132. package/src/validators/interest-oracle-validator.ts +0 -7
  133. package/src/validators/one-shot-policy.ts +0 -7
  134. package/src/validators/poll-manager-validator.ts +0 -7
  135. package/src/validators/poll-shard-validator.ts +0 -7
  136. package/src/validators/price-oracle-validator.ts +0 -7
  137. package/src/validators/pyth-feed-validator.ts +0 -7
  138. package/src/validators/rob-validator.ts +0 -7
  139. package/src/validators/stability-pool-validator.ts +0 -7
  140. package/src/validators/stableswap-validator.ts +0 -7
  141. package/src/validators/staking-validator.ts +0 -7
  142. package/src/validators/treasury-validator.ts +0 -7
  143. package/src/validators/version-record-policy.ts +0 -7
  144. package/src/validators/version-registry-validator.ts +0 -7
  145. package/tests/always-succeed/script.ts +0 -7
  146. package/tests/array-utils.test.ts +0 -92
  147. package/tests/bigint-utils.test.ts +0 -41
  148. package/tests/cdp/actions.ts +0 -680
  149. package/tests/cdp/cdp-helpers.ts +0 -55
  150. package/tests/cdp/cdp-queries.ts +0 -423
  151. package/tests/cdp/cdp.test.ts +0 -6730
  152. package/tests/cdp/transactions-mutated.ts +0 -1733
  153. package/tests/data/system-params.json +0 -1155
  154. package/tests/datums.test.ts +0 -302
  155. package/tests/endpoints/initialize.ts +0 -78
  156. package/tests/endpoints/interest-collector.ts +0 -37
  157. package/tests/endpoints/treasury.ts +0 -70
  158. package/tests/gov/actions.ts +0 -381
  159. package/tests/gov/gov.test.ts +0 -5147
  160. package/tests/gov/governance-queries.ts +0 -37
  161. package/tests/hash-checks.test.ts +0 -112
  162. package/tests/indigo-test-helpers.ts +0 -99
  163. package/tests/initialize.test.ts +0 -79
  164. package/tests/interest-calculations.test.ts +0 -120
  165. package/tests/interest-collection/interest-collection.test.ts +0 -843
  166. package/tests/interest-collection/transactions-mutated.ts +0 -260
  167. package/tests/interest-oracle.test.ts +0 -93
  168. package/tests/mock/assets-mock.ts +0 -243
  169. package/tests/mock/protocol-params-mock.ts +0 -21
  170. package/tests/price-oracle/actions.ts +0 -161
  171. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  172. package/tests/price-oracle/price-oracle.test.ts +0 -228
  173. package/tests/price-oracle/transactions-mutated.ts +0 -59
  174. package/tests/pyth/endpoints.ts +0 -96
  175. package/tests/pyth/helpers.ts +0 -37
  176. package/tests/pyth/pyth-encoding.test.ts +0 -376
  177. package/tests/pyth/pyth-feeds.test.ts +0 -943
  178. package/tests/pyth/pyth-indigo.test.ts +0 -505
  179. package/tests/pyth/pyth.test.ts +0 -299
  180. package/tests/queries/collector-queries.ts +0 -27
  181. package/tests/queries/execute-queries.ts +0 -47
  182. package/tests/queries/iasset-queries.ts +0 -149
  183. package/tests/queries/interest-oracle-queries.ts +0 -12
  184. package/tests/queries/poll-queries.ts +0 -97
  185. package/tests/queries/staking-queries.ts +0 -54
  186. package/tests/rob/actions.ts +0 -56
  187. package/tests/rob/rob-leverage.test.ts +0 -2555
  188. package/tests/rob/rob-queries.ts +0 -95
  189. package/tests/rob/rob.test.ts +0 -3677
  190. package/tests/rob/transactions-mutated.ts +0 -844
  191. package/tests/script-size.test.ts +0 -240
  192. package/tests/setup.ts +0 -135
  193. package/tests/stability-pool/actions.ts +0 -229
  194. package/tests/stability-pool.test.ts +0 -6491
  195. package/tests/stableswap/stableswap-actions.ts +0 -83
  196. package/tests/stableswap/stableswap-queries.ts +0 -98
  197. package/tests/stableswap/stableswap.test.ts +0 -4471
  198. package/tests/stableswap/transactions-mutated.ts +0 -348
  199. package/tests/staking.test.ts +0 -172
  200. package/tests/test-helpers.ts +0 -94
  201. package/tests/treasury/actions.ts +0 -67
  202. package/tests/treasury/treasury.test.ts +0 -320
  203. package/tests/utils/asserts.ts +0 -87
  204. package/tests/utils/benchmark-utils.ts +0 -130
  205. package/tests/utils/index.ts +0 -168
  206. package/tsconfig.build.json +0 -4
  207. package/tsconfig.json +0 -27
  208. package/vitest.config.ts +0 -11
@@ -1,616 +0,0 @@
1
- import {
2
- addAssets,
3
- credentialToAddress,
4
- Data,
5
- fromHex,
6
- fromText,
7
- LucidEvolution,
8
- mintingPolicyToId,
9
- PolicyId,
10
- SpendingValidator,
11
- validatorToScriptHash,
12
- } from '@lucid-evolution/lucid';
13
- import {
14
- AssetClass,
15
- assetClassToUnit,
16
- assetClassValueOf,
17
- lovelacesAmt,
18
- mkAssetsOf,
19
- mkLovelacesOf,
20
- } from '@3rd-eye-labs/cardano-offchain-common';
21
- import {
22
- addrDetails,
23
- createScriptAddress,
24
- submitTx,
25
- } from '../../utils/lucid-utils';
26
- import { runOneShotMintTx } from '../one-shot/transactions';
27
- import {
28
- fromSysParamsCredential,
29
- getPythFeedConfig,
30
- Input,
31
- } from '../../types/system-params';
32
- import type {
33
- AssetInfo,
34
- CollateralAssetInfo,
35
- InitialAssetParam,
36
- InitialCollateralAssetParam,
37
- InitializeOptions,
38
- } from './types';
39
- import type {
40
- CdpParamsSP,
41
- CollectorParamsSP,
42
- PythConfig,
43
- } from '../../types/system-params';
44
- import type {
45
- CDPCreatorParamsSP,
46
- TreasuryParamsSP,
47
- } from '../../types/system-params';
48
- import type {
49
- IAssetParamsSP,
50
- StabilityPoolParamsSP,
51
- StakingParamsSP,
52
- } from '../../types/system-params';
53
- import type { GovParamsSP } from '../../types/system-params';
54
- import type { InterestCollectionDatum } from '../interest-collection/types-new';
55
- import type { PriceOracleParams } from '../price-oracle/types';
56
- import type { InterestOracleParams } from '../interest-oracle/types';
57
- import { mkAuthTokenPolicy } from '../../scripts/auth-token-policy';
58
- import { mkIAssetValidatorFromSP } from '../iasset/scripts';
59
- import { mkCollectorValidatorFromSP } from '../collector/scripts';
60
- import { mkCDPCreatorValidatorFromSP } from '../cdp-creator/scripts';
61
- import { mkTreasuryValidatorFromSP } from '../treasury/scripts';
62
- import { mkStakingValidatorFromSP } from '../staking/scripts';
63
- import { mkGovValidatorFromSP } from '../gov/scripts';
64
- import { mkStabilityPoolValidatorFromSP } from '../stability-pool/scripts';
65
- import { serialiseInterestCollectionDatum } from '../interest-collection/types-new';
66
- import { startPriceOracleTx } from '../price-oracle/transactions';
67
- import { startInterestOracle } from '../interest-oracle/transactions';
68
- import { serialiseStakingDatum } from '../staking/types-new';
69
- import { initSpState } from '../stability-pool/helpers';
70
- import {
71
- serialiseStabilityPoolDatum,
72
- StabilityPoolContent,
73
- } from '../stability-pool/types-new';
74
- import {
75
- CollateralAssetContent,
76
- IAssetContent,
77
- IAssetPriceInfo,
78
- serialiseIAssetDatum,
79
- } from '../iasset/types';
80
- import { GovDatum, ProtocolParams, serialiseGovDatum } from '../gov/types-new';
81
- import { match } from 'ts-pattern';
82
- import { runAndAwaitTxBuilder } from '../../../tests/test-helpers';
83
- import {
84
- serialiseStableswapPoolDatum,
85
- StableswapPoolContent,
86
- } from '../cdp/types-new';
87
- import { mkCdpValidatorFromSP } from '../cdp/scripts';
88
-
89
- const alwaysFailValidatorHash =
90
- 'ea84d625650d066e1645e3e81d9c70a73f9ed837bd96dc49850ae744';
91
-
92
- /** Default init options used by tests; users must pass explicit options to init(). */
93
- export const DEFAULT_INIT_OPTIONS: InitializeOptions = {
94
- numCdpCreators: 2n,
95
- numCollectors: 2n,
96
- numInterestCollectors: 2n,
97
- numTreasuryUtxos: 5n,
98
- treasuryIndyAmount: 1_000_000n,
99
- totalIndySupply: 35000000000000n,
100
-
101
- accountCreateFeeLovelaces: 5_000_000n,
102
- accountProcessingCooldownMs: 300_000n,
103
- accountProcessingBiasTime: 120_000n,
104
-
105
- interestSettlementCooldown: 432_000_000n,
106
-
107
- partialRedemptionExtraFeeLovelace: 10_000_000,
108
- biasTime: 1200_000n,
109
- gBiasTime: 120_000n,
110
-
111
- interestCollectorUtxoLovelaces: 5_000_000n,
112
- };
113
-
114
- export const INIT_TOKEN_NAMES = {
115
- indy: 'INDY',
116
- dao: 'DAO',
117
- multisigUtxo: 'INTEREST_COLLECTION_ADMIN',
118
- govNft: 'GOV_NFT',
119
- pollManager: 'POLL_MANAGER',
120
- upgrade: 'UPGRADE',
121
- iasset: 'IASSET',
122
- collateralAsset: 'COLLATERAL_ASSET',
123
- stabilityPool: 'STABILITY_POOL',
124
- versionRecord: 'VERSION_RECORD',
125
- cdpCreator: 'CDP_CREATOR',
126
- cdp: 'CDP',
127
- stakingManager: 'STAKING_MANAGER',
128
- staking: 'STAKING_POSITION',
129
- snapshotEpochToScaleToSum: 'SNAPSHOT_EPOCH_TO_SCALE_TO_SUM',
130
- account: 'SP_ACCOUNT',
131
- } as const;
132
-
133
- export async function mintOneTimeToken(
134
- lucid: LucidEvolution,
135
- tokenName: string,
136
- amount: bigint,
137
- ): Promise<PolicyId> {
138
- const utxos = await lucid.wallet().getUtxos();
139
- return await runOneShotMintTx(lucid, {
140
- referenceOutRef: {
141
- txHash: utxos[0].txHash,
142
- outputIdx: BigInt(utxos[0].outputIndex),
143
- },
144
- mintAmounts: [{ tokenName: tokenName, amount: amount }],
145
- });
146
- }
147
-
148
- /** Mint a one-shot token and return its AssetClass. */
149
- export async function mintOneTimeAsset(
150
- lucid: LucidEvolution,
151
- tokenName: string,
152
- amount: bigint,
153
- ): Promise<AssetClass> {
154
- const policyId = await mintOneTimeToken(lucid, fromText(tokenName), amount);
155
- return {
156
- currencySymbol: fromHex(policyId),
157
- tokenName: fromHex(fromText(tokenName)),
158
- };
159
- }
160
-
161
- /** Build an auth-token AssetClass derived from a parent token. */
162
- export function deriveAuthToken(
163
- parent: AssetClass,
164
- tokenName: string,
165
- ): AssetClass {
166
- const policy = mkAuthTokenPolicy(parent, fromText(tokenName));
167
- return {
168
- currencySymbol: fromHex(mintingPolicyToId(policy)),
169
- tokenName: fromHex(fromText(tokenName)),
170
- };
171
- }
172
-
173
- export async function initScriptRef(
174
- lucid: LucidEvolution,
175
- validator: SpendingValidator,
176
- ): Promise<Input> {
177
- const tx = lucid.newTx().pay.ToContract(
178
- credentialToAddress(lucid.config().network!, {
179
- hash: alwaysFailValidatorHash,
180
- type: 'Script',
181
- }),
182
- undefined,
183
- undefined,
184
- validator,
185
- );
186
- const txHash = await tx
187
- .complete()
188
- .then((t) => t.sign.withWallet().complete())
189
- .then((t) => t.submit());
190
- await lucid.awaitTx(txHash);
191
- return { transactionId: txHash, index: 0 };
192
- }
193
-
194
- export async function initCollector(
195
- lucid: LucidEvolution,
196
- collectorParams: CollectorParamsSP,
197
- numCollectors: bigint,
198
- ): Promise<void> {
199
- const tx = lucid.newTx();
200
-
201
- for (let i = 0; i < Number(numCollectors); i++) {
202
- tx.pay.ToContract(
203
- createScriptAddress(
204
- lucid.config().network!,
205
- validatorToScriptHash(mkCollectorValidatorFromSP(collectorParams)),
206
- ),
207
- {
208
- kind: 'inline',
209
- value: Data.void(),
210
- },
211
- );
212
- }
213
-
214
- await submitTx(lucid, tx);
215
- }
216
-
217
- export async function initInterestCollector(
218
- lucid: LucidEvolution,
219
- interestCollectionValHash: string,
220
- multisigUtxoNft: AssetClass,
221
- numInterestCollectors: bigint,
222
- interestCollectorUtxoLovelaces: bigint,
223
- ): Promise<void> {
224
- const [pkh, _] = await addrDetails(lucid);
225
- const interestCollectionAdminDatum: InterestCollectionDatum = {
226
- admin_permissions: {
227
- Signature: {
228
- keyHash: fromHex(pkh.hash),
229
- },
230
- },
231
- };
232
-
233
- await submitTx(
234
- lucid,
235
- lucid.newTx().pay.ToContract(
236
- createScriptAddress(lucid.config().network!, interestCollectionValHash),
237
- {
238
- kind: 'inline',
239
- value: serialiseInterestCollectionDatum(interestCollectionAdminDatum),
240
- },
241
- mkAssetsOf(multisigUtxoNft, 1n),
242
- ),
243
- );
244
-
245
- const interestCollectionUtxoDeploymentTx = lucid.newTx();
246
-
247
- for (let i = 0; i < Number(numInterestCollectors); i++) {
248
- interestCollectionUtxoDeploymentTx.pay.ToContract(
249
- createScriptAddress(lucid.config().network!, interestCollectionValHash),
250
- undefined,
251
- mkLovelacesOf(interestCollectorUtxoLovelaces),
252
- );
253
- }
254
-
255
- await submitTx(lucid, interestCollectionUtxoDeploymentTx);
256
- }
257
-
258
- export async function initCDPCreator(
259
- lucid: LucidEvolution,
260
- cdpCreatorParams: CDPCreatorParamsSP,
261
- numCdpCreators: bigint,
262
- ): Promise<void> {
263
- const tx = lucid.newTx();
264
-
265
- for (let i = 0; i < Number(numCdpCreators); i++) {
266
- tx.pay.ToContract(
267
- credentialToAddress(lucid.config().network!, {
268
- hash: validatorToScriptHash(
269
- mkCDPCreatorValidatorFromSP(cdpCreatorParams),
270
- ),
271
- type: 'Script',
272
- }),
273
- { kind: 'inline', value: Data.void() },
274
- {
275
- [cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol +
276
- fromText(cdpCreatorParams.cdpCreatorNft[1].unTokenName)]: 1n,
277
- },
278
- );
279
- }
280
-
281
- await submitTx(lucid, tx);
282
- }
283
-
284
- export async function initTreasury(
285
- lucid: LucidEvolution,
286
- treasuryParams: TreasuryParamsSP,
287
- daoAsset: AssetClass,
288
- indyAsset: AssetClass,
289
- treasuryIndyAmount: bigint,
290
- numTreasuryCollectors: bigint,
291
- ): Promise<void> {
292
- const treasuryAddr = createScriptAddress(
293
- lucid.config().network!,
294
- validatorToScriptHash(mkTreasuryValidatorFromSP(treasuryParams)),
295
- treasuryParams.treasuryUtxosStakeCredential != null
296
- ? fromSysParamsCredential(treasuryParams.treasuryUtxosStakeCredential)
297
- : undefined,
298
- );
299
- const tx = lucid
300
- .newTx()
301
- .pay.ToContract(
302
- treasuryAddr,
303
- { kind: 'inline', value: Data.void() },
304
- addAssets(
305
- mkAssetsOf(daoAsset, 1n),
306
- mkAssetsOf(indyAsset, treasuryIndyAmount),
307
- ),
308
- );
309
-
310
- for (let i = 0; i < Number(numTreasuryCollectors); i++) {
311
- tx.pay.ToContract(treasuryAddr, {
312
- kind: 'inline',
313
- value: Data.void(),
314
- });
315
- }
316
-
317
- await submitTx(lucid, tx);
318
- }
319
-
320
- export async function initStakingManager(
321
- lucid: LucidEvolution,
322
- stakingParams: StakingParamsSP,
323
- ): Promise<void> {
324
- const tx = lucid.newTx().pay.ToContract(
325
- createScriptAddress(
326
- lucid.config().network!,
327
- validatorToScriptHash(mkStakingValidatorFromSP(stakingParams)),
328
- ),
329
- {
330
- kind: 'inline',
331
- value: serialiseStakingDatum({
332
- totalStake: 0n,
333
- managerSnapshot: { snapshotAda: 0n },
334
- }),
335
- },
336
- {
337
- [stakingParams.stakingManagerNFT[0].unCurrencySymbol +
338
- fromText(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n,
339
- },
340
- );
341
- await submitTx(lucid, tx);
342
- }
343
-
344
- export async function handleOracleForCollateralAsset(
345
- lucid: LucidEvolution,
346
- iasset: InitialAssetParam,
347
- collateralAsset: InitialCollateralAssetParam,
348
- pythConfig: PythConfig,
349
- ): Promise<{ info: IAssetPriceInfo; params: PriceOracleParams | undefined }> {
350
- return match(collateralAsset.priceOracle)
351
- .returnType<
352
- Promise<{ info: IAssetPriceInfo; params: PriceOracleParams | undefined }>
353
- >()
354
- .with({ tag: '_indigo_oracle_nft' }, async (val) => {
355
- const [pkh, _] = await addrDetails(lucid);
356
-
357
- const priceOracleParams: PriceOracleParams = {
358
- owner: pkh.hash,
359
- biasTime: val.params.biasTime,
360
- expirationPeriod: val.params.expirationPeriod,
361
- };
362
-
363
- const [priceOracleStartTx, priceOracleNft] = await startPriceOracleTx(
364
- lucid,
365
- val.tokenName,
366
- val.startPrice,
367
- priceOracleParams,
368
- );
369
- await runAndAwaitTxBuilder(lucid, priceOracleStartTx);
370
-
371
- return { info: { OracleNft: priceOracleNft }, params: priceOracleParams };
372
- })
373
- .with({ tag: '_pyth_oracle_nft' }, () => {
374
- return Promise.resolve({
375
- info: {
376
- DeferredValidation: {
377
- feedValHash: fromHex(
378
- getPythFeedConfig(
379
- pythConfig,
380
- fromHex(fromText(iasset.name)),
381
- collateralAsset.collateralAsset,
382
- ).pythFeedValHash,
383
- ),
384
- },
385
- } satisfies IAssetPriceInfo,
386
- params: undefined,
387
- });
388
- })
389
- .exhaustive();
390
- }
391
-
392
- export async function initializeAsset(
393
- lucid: LucidEvolution,
394
- iassetParams: IAssetParamsSP,
395
- iassetToken: AssetClass,
396
- collateralAssetAuthToken: AssetClass,
397
- cdpAuthToken: AssetClass,
398
- cdpParams: CdpParamsSP,
399
- stableswapValidatorHash: string,
400
- stabilityPoolParams: StabilityPoolParamsSP,
401
- stabilityPoolToken: AssetClass,
402
- asset: InitialAssetParam,
403
- pythConfig: PythConfig,
404
- ): Promise<AssetInfo> {
405
- const iassetName = fromHex(fromText(asset.name));
406
-
407
- const collateralAssetInfos: CollateralAssetInfo[] = [];
408
-
409
- for (const collateralAsset of asset.collateralAssets) {
410
- const [pkh, _] = await addrDetails(lucid);
411
-
412
- const interestOracleParams: InterestOracleParams = {
413
- owner: pkh.hash,
414
- biasTime: collateralAsset.interestOracle.params.biasTime,
415
- };
416
- const [startInterestOracleTx, interestOracleNft] =
417
- await startInterestOracle(
418
- 0n,
419
- collateralAsset.interestOracle.initialInterestRate,
420
- 0n,
421
- interestOracleParams,
422
- lucid,
423
- collateralAsset.interestOracle.tokenName,
424
- );
425
- await submitTx(lucid, startInterestOracleTx);
426
- const priceInfo = await handleOracleForCollateralAsset(
427
- lucid,
428
- asset,
429
- collateralAsset,
430
- pythConfig,
431
- );
432
-
433
- const collateralAssetContent: CollateralAssetContent = {
434
- iasset: iassetName,
435
- collateralAsset: collateralAsset.collateralAsset,
436
- extraDecimals: collateralAsset.extraDecimals,
437
- priceInfo: priceInfo.info,
438
- interestOracleNft: interestOracleNft,
439
- redemptionRatio: collateralAsset.redemptionRatio,
440
- maintenanceRatio: collateralAsset.maintenanceRatio,
441
- liquidationRatio: collateralAsset.liquidationRatio,
442
- minCollateralAmt: collateralAsset.minCollateralAmt,
443
- firstCollateralAsset: collateralAsset.firstCollateralAsset,
444
- nextCollateralAsset:
445
- collateralAsset.nextCollateralAsset != null
446
- ? collateralAsset.nextCollateralAsset
447
- : null,
448
- };
449
-
450
- const collateralAssetTx = lucid.newTx().pay.ToContract(
451
- createScriptAddress(
452
- lucid.config().network!,
453
- validatorToScriptHash(mkIAssetValidatorFromSP(iassetParams)),
454
- ),
455
- {
456
- kind: 'inline',
457
- value: serialiseIAssetDatum({
458
- CollateralAssetContent: collateralAssetContent,
459
- }),
460
- },
461
- mkAssetsOf(collateralAssetAuthToken, 1n),
462
- );
463
- await submitTx(lucid, collateralAssetTx);
464
-
465
- collateralAssetInfos.push({
466
- collateralAsset: collateralAsset.collateralAsset,
467
- interestOracleNft: interestOracleNft,
468
- interestOracleParams: interestOracleParams,
469
- oracleParams: priceInfo.params,
470
- });
471
- }
472
-
473
- for (const stableswapPool of asset.stablepools) {
474
- const stableswapPoolDatum: StableswapPoolContent = {
475
- collateralAsset: stableswapPool.collateralAsset,
476
- collateralToIassetRatio: stableswapPool.collateralToIassetRatio,
477
- mintingFeeRatio: stableswapPool.mintingFeeRatio,
478
- redemptionFeeRatio: stableswapPool.redemptionFeeRatio,
479
- mintingEnabled: stableswapPool.mintingEnabled,
480
- redemptionEnabled: stableswapPool.redemptionEnabled,
481
- feeManager: stableswapPool.feeManager
482
- ? fromHex(stableswapPool.feeManager)
483
- : null,
484
- minMintOrderAmount: stableswapPool.minMintOrderAmount,
485
- minRedemptionOrderAmount: stableswapPool.minRedemptionOrderAmount,
486
- iasset: iassetName,
487
- stableswapValHash: fromHex(stableswapValidatorHash),
488
- };
489
-
490
- await submitTx(
491
- lucid,
492
- lucid.newTx().pay.ToContract(
493
- createScriptAddress(
494
- lucid.config().network!,
495
- validatorToScriptHash(mkCdpValidatorFromSP(cdpParams)),
496
- ),
497
- {
498
- kind: 'inline',
499
- value: serialiseStableswapPoolDatum(stableswapPoolDatum),
500
- },
501
- mkAssetsOf(cdpAuthToken, 1n),
502
- ),
503
- );
504
- }
505
-
506
- const iassetDatum: IAssetContent = {
507
- assetName: iassetName,
508
- collateralAssetsCount: BigInt(asset.collateralAssets.length),
509
- debtMintingFeeRatio: asset.debtMintingFeeRatio,
510
- liquidationProcessingFeeRatio: asset.liquidationProcessingFeeRatio,
511
- stabilityPoolWithdrawalFeeRatio: asset.stabilityPoolWithdrawalFeeRatio,
512
- redemptionReimbursementRatio: asset.redemptionReimbursementRatio,
513
- redemptionProcessingFeeRatio: asset.redemptionProcessingFeeRatio,
514
- firstIAsset: asset.firstAsset,
515
- nextIAsset: asset.nextAsset ? fromHex(fromText(asset.nextAsset)) : null,
516
- };
517
-
518
- const assetTx = lucid.newTx().pay.ToContract(
519
- createScriptAddress(
520
- lucid.config().network!,
521
- validatorToScriptHash(mkIAssetValidatorFromSP(iassetParams)),
522
- ),
523
- {
524
- kind: 'inline',
525
- value: serialiseIAssetDatum({ IAssetContent: iassetDatum }),
526
- },
527
- mkAssetsOf(iassetToken, 1n),
528
- );
529
- await submitTx(lucid, assetTx);
530
-
531
- const stabilityPoolDatum: StabilityPoolContent = {
532
- iasset: fromHex(fromText(asset.name)),
533
- state: initSpState,
534
- assetStates: [],
535
- };
536
-
537
- const spTx = lucid.newTx().pay.ToContract(
538
- credentialToAddress(lucid.config().network!, {
539
- hash: validatorToScriptHash(
540
- mkStabilityPoolValidatorFromSP(stabilityPoolParams),
541
- ),
542
- type: 'Script',
543
- }),
544
- {
545
- kind: 'inline',
546
- value: serialiseStabilityPoolDatum({ StabilityPool: stabilityPoolDatum }),
547
- },
548
- mkAssetsOf(stabilityPoolToken, 1n),
549
- );
550
- await submitTx(lucid, spTx);
551
-
552
- return {
553
- iassetTokenNameAscii: asset.name,
554
- collateralAssets: collateralAssetInfos,
555
- };
556
- }
557
-
558
- export async function initGovernance(
559
- lucid: LucidEvolution,
560
- governanceParams: GovParamsSP,
561
- govToken: AssetClass,
562
- initialAssets: InitialAssetParam[],
563
- protocolParams: ProtocolParams,
564
- ): Promise<void> {
565
- const datum: GovDatum = {
566
- currentProposal: 0n,
567
- currentVersion: 0n,
568
- protocolParams: protocolParams,
569
- activeProposals: 0n,
570
- iassetsCount: BigInt(initialAssets.length),
571
- };
572
- const tx = lucid.newTx().pay.ToContract(
573
- credentialToAddress(lucid.config().network!, {
574
- hash: validatorToScriptHash(mkGovValidatorFromSP(governanceParams)),
575
- type: 'Script',
576
- }),
577
- { kind: 'inline', value: serialiseGovDatum(datum) },
578
- mkAssetsOf(govToken, 1n),
579
- );
580
-
581
- await submitTx(lucid, tx);
582
- }
583
-
584
- export async function mintAuthTokenDirect(
585
- lucid: LucidEvolution,
586
- asset: AssetClass,
587
- tokenName: string,
588
- amount: bigint,
589
- ): Promise<void> {
590
- const script = mkAuthTokenPolicy(asset, fromText(tokenName));
591
- const policyId = mintingPolicyToId(script);
592
- const address = await lucid.wallet().address();
593
-
594
- // Only select utxos that contain exactly 1 asset of the given asset class and sort by lovelaces amount in descending order
595
- const utxos = (await lucid.utxosAtWithUnit(address, assetClassToUnit(asset)))
596
- .filter((utxo) => assetClassValueOf(utxo.assets, asset) === 1n)
597
- .sort((a, b) => Number(lovelacesAmt(b.assets) - lovelacesAmt(a.assets)));
598
- if (utxos.length === 0) {
599
- throw new Error('No utxos found');
600
- }
601
-
602
- const utxo = utxos[0];
603
-
604
- const tx = lucid
605
- .newTx()
606
- .attach.MintingPolicy(script)
607
- .collectFrom([utxo])
608
- .mintAssets(
609
- {
610
- [policyId + fromText(tokenName)]: amount,
611
- },
612
- Data.void(),
613
- );
614
-
615
- await submitTx(lucid, tx);
616
- }