@indigo-labs/indigo-sdk 0.1.0 → 0.1.2

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 (53) hide show
  1. package/dist/index.d.mts +418 -0
  2. package/dist/index.d.ts +418 -23
  3. package/dist/index.js +1067 -23
  4. package/dist/index.mjs +1036 -0
  5. package/examples/sample-cdp.ts +43 -0
  6. package/package.json +2 -3
  7. package/src/contracts/cdp.ts +2 -2
  8. package/dist/contracts/cdp-creator.d.ts +0 -9
  9. package/dist/contracts/cdp-creator.js +0 -58
  10. package/dist/contracts/cdp.d.ts +0 -22
  11. package/dist/contracts/cdp.js +0 -542
  12. package/dist/contracts/collector.d.ts +0 -9
  13. package/dist/contracts/collector.js +0 -52
  14. package/dist/contracts/gov.d.ts +0 -5
  15. package/dist/contracts/gov.js +0 -50
  16. package/dist/contracts/interest-oracle.d.ts +0 -8
  17. package/dist/contracts/interest-oracle.js +0 -39
  18. package/dist/contracts/price-oracle.d.ts +0 -5
  19. package/dist/contracts/price-oracle.js +0 -18
  20. package/dist/contracts/treasury.d.ts +0 -9
  21. package/dist/contracts/treasury.js +0 -56
  22. package/dist/helpers/asset-helpers.d.ts +0 -11
  23. package/dist/helpers/asset-helpers.js +0 -23
  24. package/dist/helpers/cdp-helpers.d.ts +0 -5
  25. package/dist/helpers/cdp-helpers.js +0 -5
  26. package/dist/helpers/helpers.d.ts +0 -4
  27. package/dist/helpers/helpers.js +0 -14
  28. package/dist/helpers/lucid-utils.d.ts +0 -6
  29. package/dist/helpers/lucid-utils.js +0 -18
  30. package/dist/helpers/time-helpers.d.ts +0 -3
  31. package/dist/helpers/time-helpers.js +0 -3
  32. package/dist/scripts/cdp-creator-validator.d.ts +0 -6
  33. package/dist/scripts/cdp-creator-validator.js +0 -6
  34. package/dist/scripts/cdp-validator.d.ts +0 -6
  35. package/dist/scripts/cdp-validator.js +0 -6
  36. package/dist/scripts/collector-validator.d.ts +0 -6
  37. package/dist/scripts/collector-validator.js +0 -5
  38. package/dist/scripts/interest-oracle-validator.d.ts +0 -6
  39. package/dist/scripts/interest-oracle-validator.js +0 -5
  40. package/dist/scripts/treasury-validator.d.ts +0 -6
  41. package/dist/scripts/treasury-validator.js +0 -5
  42. package/dist/types/generic.d.ts +0 -10
  43. package/dist/types/generic.js +0 -1
  44. package/dist/types/indigo/cdp.d.ts +0 -37
  45. package/dist/types/indigo/cdp.js +0 -1
  46. package/dist/types/indigo/gov.d.ts +0 -20
  47. package/dist/types/indigo/gov.js +0 -1
  48. package/dist/types/indigo/interest-oracle.d.ts +0 -5
  49. package/dist/types/indigo/interest-oracle.js +0 -1
  50. package/dist/types/indigo/price-oracle.d.ts +0 -4
  51. package/dist/types/indigo/price-oracle.js +0 -1
  52. package/dist/types/system-params.d.ts +0 -217
  53. package/dist/types/system-params.js +0 -1
@@ -0,0 +1,418 @@
1
+ import { LucidEvolution, Address as Address$1, SpendingValidator, Credential, Data, UTxO, OutRef, TxBuilder, Constr, Assets, ScriptType } from '@lucid-evolution/lucid';
2
+
3
+ interface OnChainDecimal {
4
+ getOnChainInt: bigint;
5
+ }
6
+ interface CurrencySymbol {
7
+ unCurrencySymbol: string;
8
+ }
9
+ interface TokenName {
10
+ unTokenName: string;
11
+ }
12
+ type AssetClass = [CurrencySymbol, TokenName];
13
+
14
+ interface SystemParams {
15
+ versionRecordParams: VersionRecordParams;
16
+ validatorHashes: ValidatorHashes;
17
+ treasuryParams: TreasuryParams;
18
+ startTime: StartTime;
19
+ stakingParams: StakingParams;
20
+ stabilityPoolParams: StabilityPoolParams;
21
+ scriptReferences: ScriptReferences;
22
+ pollShardParams: PollShardParams;
23
+ pollManagerParams: PollManagerParams;
24
+ indyToken: AssetClass;
25
+ govParams: GovParams;
26
+ executeParams: ExecuteParams;
27
+ distributionParams: DistributionParams;
28
+ collectorParams: CollectorParams;
29
+ cdpParams: CdpParams;
30
+ cdpCreatorParams: CdpCreatorParams;
31
+ }
32
+ type ValidatorHashes = {
33
+ versionRegistryHash: string;
34
+ treasuryHash: string;
35
+ stakingHash: string;
36
+ stabilityPoolHash: string;
37
+ pollShardHash: string;
38
+ pollManagerHash: string;
39
+ govHash: string;
40
+ executeHash: string;
41
+ collectorHash: string;
42
+ cdpHash: string;
43
+ cdpCreatorHash: string;
44
+ };
45
+ interface AddressCredential {
46
+ tag: string;
47
+ contents: PubKeyHash;
48
+ }
49
+ interface ScriptCredential {
50
+ tag: string;
51
+ contents: {
52
+ tag: string;
53
+ contents: string;
54
+ };
55
+ }
56
+ interface PubKeyHash {
57
+ getPubKeyHash: string;
58
+ }
59
+ interface VersionRecordParams {
60
+ upgradeToken: AssetClass;
61
+ }
62
+ interface TreasuryParams {
63
+ upgradeToken: AssetClass;
64
+ versionRecordToken: AssetClass;
65
+ treasuryUtxosStakeCredential?: ScriptCredential;
66
+ }
67
+ interface StartTime {
68
+ slot: number;
69
+ blockHeader: string;
70
+ }
71
+ interface StakingParams {
72
+ versionRecordToken: AssetClass;
73
+ stakingToken: AssetClass;
74
+ stakingManagerNFT: AssetClass;
75
+ pollToken: AssetClass;
76
+ indyToken: AssetClass;
77
+ collectorValHash: string;
78
+ }
79
+ interface StabilityPoolParams {
80
+ versionRecordToken: AssetClass;
81
+ stabilityPoolToken: AssetClass;
82
+ snapshotEpochToScaleToSumToken: AssetClass;
83
+ requestCollateralLovelaces: number;
84
+ iAssetAuthToken: AssetClass;
85
+ govNFT: AssetClass;
86
+ collectorValHash: string;
87
+ cdpToken: AssetClass;
88
+ assetSymbol: CurrencySymbol;
89
+ accountToken: AssetClass;
90
+ accountCreateFeeLovelaces: number;
91
+ accountAdjustmentFeeLovelaces: number;
92
+ }
93
+ interface ScriptReferences {
94
+ vestingValidatorRef: ScriptReference;
95
+ versionRegistryValidatorRef: ScriptReference;
96
+ versionRecordTokenPolicyRef: ScriptReference;
97
+ treasuryValidatorRef: ScriptReference;
98
+ stakingValidatorRef: ScriptReference;
99
+ stabilityPoolValidatorRef: ScriptReference;
100
+ pollShardValidatorRef: ScriptReference;
101
+ pollManagerValidatorRef: ScriptReference;
102
+ liquidityValidatorRef: ScriptReference;
103
+ iAssetTokenPolicyRef: ScriptReference;
104
+ governanceValidatorRef: ScriptReference;
105
+ executeValidatorRef: ScriptReference;
106
+ collectorValidatorRef: ScriptReference;
107
+ cdpValidatorRef: ScriptReference;
108
+ cdpCreatorValidatorRef: ScriptReference;
109
+ authTokenPolicies: AuthTokenPolicies;
110
+ }
111
+ interface Output {
112
+ scriptRef: ScriptRef;
113
+ output: ScriptOutput;
114
+ }
115
+ interface ScriptRef {
116
+ tag: string;
117
+ contents?: string[] | null;
118
+ }
119
+ interface ScriptOutput {
120
+ referenceScript: string;
121
+ datum: AddressCredentialOrDatum;
122
+ amount: Amount;
123
+ address: Address;
124
+ }
125
+ interface AddressCredentialOrDatum {
126
+ tag: string;
127
+ contents: string;
128
+ }
129
+ interface Amount {
130
+ getValue?: ((CurrencySymbol | ((number)[] | null)[] | null)[] | null)[] | null;
131
+ }
132
+ interface Address {
133
+ addressStakingCredential?: null;
134
+ addressCredential: AddressCredentialOrDatum;
135
+ }
136
+ interface Input {
137
+ transactionId: string;
138
+ index: number;
139
+ }
140
+ interface ScriptReference {
141
+ output: Output;
142
+ input: Input;
143
+ }
144
+ interface AuthTokenPolicies {
145
+ upgradeTokenRef: ScriptReference;
146
+ stakingTokenRef: ScriptReference;
147
+ stabilityPoolTokenRef: ScriptReference;
148
+ snapshotEpochToScaleToSumTokenRef: ScriptReference;
149
+ pollManagerTokenRef: ScriptReference;
150
+ iAssetTokenRef: ScriptReference;
151
+ cdpAuthTokenRef: ScriptReference;
152
+ accountTokenRef: ScriptReference;
153
+ }
154
+ interface PollShardParams {
155
+ stakingValHash: string;
156
+ stakingToken: AssetClass;
157
+ pollToken: AssetClass;
158
+ indyAsset: AssetClass;
159
+ }
160
+ interface PollManagerParams {
161
+ upgradeToken: AssetClass;
162
+ treasuryValHash: string;
163
+ shardsValHash: string;
164
+ pollToken: AssetClass;
165
+ pBiasTime: number;
166
+ initialIndyDistribution: number;
167
+ indyAsset: AssetClass;
168
+ govNFT: AssetClass;
169
+ govExecuteValHash: string;
170
+ }
171
+ interface GovParams {
172
+ versionRecordToken: AssetClass;
173
+ upgradeToken: AssetClass;
174
+ pollToken: AssetClass;
175
+ pollManagerValHash: string;
176
+ indyAsset: AssetClass;
177
+ iAssetAuthToken: AssetClass;
178
+ govNFT: AssetClass;
179
+ gBiasTime: number;
180
+ daoIdentityToken: AssetClass;
181
+ }
182
+ interface ExecuteParams {
183
+ versionRegistryValHash: string;
184
+ versionRecordToken: AssetClass;
185
+ upgradeToken: AssetClass;
186
+ treasuryValHash: string;
187
+ stabilityPoolToken: AssetClass;
188
+ sPoolValHash: string;
189
+ maxInterestPeriods: number;
190
+ iAssetToken: AssetClass;
191
+ govNFT: AssetClass;
192
+ cdpValHash: string;
193
+ }
194
+ interface DistributionParams {
195
+ treasuryIndyAmount: number;
196
+ totalINDYSupply: number;
197
+ initialIndyDistribution: number;
198
+ }
199
+ interface CollectorParams {
200
+ versionRecordToken: AssetClass;
201
+ stakingToken: AssetClass;
202
+ stakingManagerNFT: AssetClass;
203
+ }
204
+ interface CdpParams {
205
+ versionRecordToken: AssetClass;
206
+ upgradeToken: AssetClass;
207
+ treasuryValHash: string;
208
+ stabilityPoolAuthToken: AssetClass;
209
+ spValHash: string;
210
+ partialRedemptionExtraFeeLovelace: number;
211
+ minCollateralInLovelace: number;
212
+ iAssetAuthToken: AssetClass;
213
+ govNFT: AssetClass;
214
+ collectorValHash: string;
215
+ cdpAuthToken: AssetClass;
216
+ cdpAssetSymbol: CurrencySymbol;
217
+ biasTime: number;
218
+ }
219
+ interface CdpCreatorParams {
220
+ versionRecordToken: AssetClass;
221
+ minCollateralInLovelace: number;
222
+ iAssetAuthTk: AssetClass;
223
+ collectorValHash: string;
224
+ cdpScriptHash: string;
225
+ cdpCreatorNft: AssetClass;
226
+ cdpAuthTk: AssetClass;
227
+ cdpAssetCs: CurrencySymbol;
228
+ biasTime: number;
229
+ }
230
+
231
+ declare class CDPCreatorContract {
232
+ static address(params: CdpCreatorParams, lucid: LucidEvolution): Address$1;
233
+ static validator(params: CdpCreatorParams): SpendingValidator;
234
+ static validatorHash(params: CdpCreatorParams): string;
235
+ static redeemer(hash: Credential, mintedAmount: bigint, collateralAmount: bigint, currentTime: bigint): Data;
236
+ static scriptRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
237
+ }
238
+
239
+ type ActiveCDPInterestTracking = {
240
+ type: 'ActiveCDPInterestTracking';
241
+ last_settled: bigint;
242
+ unitary_interest_snapshot: bigint;
243
+ };
244
+ type FrozenCDPAccumulatedFees = {
245
+ type: 'FrozenCDPAccumulatedFees';
246
+ lovelaces_treasury: bigint;
247
+ lovelaces_indy_stakers: bigint;
248
+ };
249
+ type CDPFees = ActiveCDPInterestTracking | FrozenCDPAccumulatedFees;
250
+ type CDP = {
251
+ type: 'CDP';
252
+ owner: string | undefined;
253
+ asset: string;
254
+ mintedAmount: bigint;
255
+ fees: CDPFees;
256
+ };
257
+ type IAsset = {
258
+ type: 'IAsset';
259
+ name: string;
260
+ price: OnChainDecimal | AssetClass;
261
+ interestOracle: AssetClass;
262
+ redemptionRatioPercentage: OnChainDecimal;
263
+ maintenanceRatioPercentage: OnChainDecimal;
264
+ liquidationRatioPercentage: OnChainDecimal;
265
+ debtMintingFeePercentage: OnChainDecimal;
266
+ liquidationProcessingFeePercentage: OnChainDecimal;
267
+ stabilityPoolWithdrawalFeePercentage: OnChainDecimal;
268
+ redemptionReimbursementPercentage: OnChainDecimal;
269
+ redemptionProcessingFeePercentage: OnChainDecimal;
270
+ interestCollectorPortionPercentage: OnChainDecimal;
271
+ firstAsset: boolean;
272
+ nextAsset?: string;
273
+ };
274
+ type CDPDatum = CDP | IAsset;
275
+
276
+ declare class CDPContract {
277
+ static openPosition(asset: string, collateralAmount: bigint, mintedAmount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, cdpCreatorRef?: OutRef, collectorRef?: OutRef): Promise<TxBuilder>;
278
+ static deposit(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
279
+ static withdraw(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
280
+ static mint(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
281
+ static burn(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
282
+ static adjust(cdpRef: OutRef, collateralAmount: bigint, mintAmount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
283
+ static close(cdpRef: OutRef, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
284
+ static decodeCdpDatum(datum: string): CDPDatum;
285
+ static encodeCdpDatum(datum: CDPDatum): string;
286
+ static datum(hash: Credential, asset: string, mintedAmount: bigint, fees: CDPFees): Constr<Data>;
287
+ static validator(params: CdpParams): SpendingValidator;
288
+ static validatorHash(params: CdpParams): string;
289
+ static address(cdpParams: CdpParams, lucid: LucidEvolution, skh?: Credential): string;
290
+ static scriptRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
291
+ static cdpAuthTokenRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
292
+ static assetTokenRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
293
+ static assetAuthTokenRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
294
+ }
295
+
296
+ declare class CollectorContract {
297
+ static feeTx(fee: bigint, lucid: LucidEvolution, params: SystemParams, tx: TxBuilder, collectorRef?: OutRef): Promise<void>;
298
+ static validator(params: CollectorParams): SpendingValidator;
299
+ static validatorHash(params: CollectorParams): string;
300
+ static address(params: CollectorParams, lucid: LucidEvolution): Address$1;
301
+ static scriptRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
302
+ }
303
+
304
+ type ProtocolParams = {
305
+ proposalDeposit: bigint;
306
+ votingPeriod: bigint;
307
+ effectiveDelay: bigint;
308
+ expirationPeriod: bigint;
309
+ collateralFeePercentage: bigint;
310
+ proposingPeriod: bigint;
311
+ totalShards: bigint;
312
+ minimumQuorum: bigint;
313
+ maxTreasuryLovelaceSpend: bigint;
314
+ maxTreasuryIndySpend: bigint;
315
+ };
316
+ type GovDatum = {
317
+ currentProposal: bigint;
318
+ protocolParams: ProtocolParams;
319
+ currentVersion: bigint;
320
+ iassetsCount: bigint;
321
+ activeProposals: bigint;
322
+ treasuryIndyWithdrawnAmt: bigint;
323
+ };
324
+
325
+ declare class GovContract {
326
+ static decodeGovDatum(datum: string): GovDatum;
327
+ static encodeGovDatum(datum: GovDatum): string;
328
+ }
329
+
330
+ type InterestOracleDatum = {
331
+ unitaryInterest: bigint;
332
+ interestRate: bigint;
333
+ lastUpdated: bigint;
334
+ };
335
+
336
+ declare class InterestOracleContract {
337
+ static decodeInterestOracleDatum(datum: string): InterestOracleDatum;
338
+ static encodeInterestOracleDatum(datum: InterestOracleDatum): string;
339
+ static calculateUnitaryInterestSinceOracleLastUpdated(now: bigint, oracleDatum: InterestOracleDatum): bigint;
340
+ static calculateUnitaryInterest(timePeriod: bigint, interestRate: bigint): bigint;
341
+ static calculateAccruedInterest(now: bigint, unitaryInterestSnapshot: bigint, mintedAmount: bigint, interestLastSettled: bigint, interestOracleDatum: InterestOracleDatum): bigint;
342
+ }
343
+
344
+ type PriceOracleDatum = {
345
+ price: bigint;
346
+ expiration: bigint;
347
+ };
348
+
349
+ declare class PriceOracleContract {
350
+ static decodePriceOracleDatum(datum: string): PriceOracleDatum;
351
+ static encodePriceOracleDatum(datum: PriceOracleDatum): string;
352
+ }
353
+
354
+ declare class TreasuryContract {
355
+ static feeTx(fee: bigint, lucid: LucidEvolution, params: SystemParams, tx: TxBuilder, treasuryRef?: OutRef): Promise<void>;
356
+ static validator(params: TreasuryParams): SpendingValidator;
357
+ static validatorHash(params: TreasuryParams): string;
358
+ static address(params: TreasuryParams, lucid: LucidEvolution): Address$1;
359
+ static scriptRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
360
+ }
361
+
362
+ type IAssetOutput = {
363
+ utxo: UTxO;
364
+ datum: IAsset;
365
+ };
366
+ declare class IAssetHelpers {
367
+ static findIAssetByRef(outRef: OutRef, params: SystemParams, lucid: LucidEvolution): Promise<IAssetOutput>;
368
+ static findIAssetByName(assetName: string, params: SystemParams, lucid: LucidEvolution): Promise<IAssetOutput>;
369
+ }
370
+
371
+ declare class CDPHelpers {
372
+ static cdps(params: SystemParams, lucid: LucidEvolution): Promise<UTxO[]>;
373
+ }
374
+
375
+ declare function calculateFeeFromPercentage(percent: bigint, amount: bigint): bigint;
376
+ declare function loadSystemParamsFromFile(file: string): SystemParams;
377
+ declare function loadSystemParamsFromUrl(url: string): Promise<SystemParams>;
378
+
379
+ declare function addrDetails(lucid: LucidEvolution): Promise<[Credential, Credential | undefined]>;
380
+ declare function scriptRef(ref: ScriptReference, lucid: LucidEvolution): Promise<UTxO>;
381
+ declare function balance(utxos: UTxO[]): Assets;
382
+ declare const getRandomElement: (arr: any[]) => any;
383
+
384
+ declare const oneHour: bigint;
385
+ declare const oneDay: bigint;
386
+ declare const oneYear: bigint;
387
+
388
+ declare const _cdpCreatorValidator: {
389
+ type: ScriptType;
390
+ description: string;
391
+ cborHex: string;
392
+ };
393
+
394
+ declare const _cdpValidator: {
395
+ type: ScriptType;
396
+ description: string;
397
+ cborHex: string;
398
+ };
399
+
400
+ declare const _collectorValidator: {
401
+ type: ScriptType;
402
+ description: string;
403
+ cborHex: string;
404
+ };
405
+
406
+ declare const _interestOracleValidator: {
407
+ type: ScriptType;
408
+ description: string;
409
+ cborHex: string;
410
+ };
411
+
412
+ declare const _treasuryValidator: {
413
+ type: ScriptType;
414
+ description: string;
415
+ cborHex: string;
416
+ };
417
+
418
+ export { type ActiveCDPInterestTracking, type Address, type AddressCredential, type AddressCredentialOrDatum, type Amount, type AssetClass, type AuthTokenPolicies, type CDP, CDPContract, CDPCreatorContract, type CDPDatum, type CDPFees, CDPHelpers, type CdpCreatorParams, type CdpParams, CollectorContract, type CollectorParams, type CurrencySymbol, type DistributionParams, type ExecuteParams, type FrozenCDPAccumulatedFees, GovContract, type GovDatum, type GovParams, type IAsset, IAssetHelpers, type IAssetOutput, type Input, InterestOracleContract, type InterestOracleDatum, type OnChainDecimal, type Output, type PollManagerParams, type PollShardParams, PriceOracleContract, type PriceOracleDatum, type ProtocolParams, type PubKeyHash, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type StabilityPoolParams, type StakingParams, type StartTime, type SystemParams, type TokenName, TreasuryContract, type TreasuryParams, type ValidatorHashes, type VersionRecordParams, _cdpCreatorValidator, _cdpValidator, _collectorValidator, _interestOracleValidator, _treasuryValidator, addrDetails, balance, calculateFeeFromPercentage, getRandomElement, loadSystemParamsFromFile, loadSystemParamsFromUrl, oneDay, oneHour, oneYear, scriptRef };