@indigo-labs/indigo-sdk 0.1.2 → 0.1.3

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 (93) hide show
  1. package/.github/workflows/ci.yml +62 -0
  2. package/.github/workflows/test.yml +44 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.prettierrc +1 -1
  5. package/README.md +52 -7
  6. package/dist/index.d.mts +1064 -182
  7. package/dist/index.d.ts +1064 -182
  8. package/dist/index.js +2565 -561
  9. package/dist/index.mjs +2546 -593
  10. package/eslint.config.mjs +35 -0
  11. package/package.json +61 -43
  12. package/src/contracts/cdp.ts +208 -359
  13. package/src/contracts/collector.ts +13 -6
  14. package/src/contracts/gov.ts +1 -58
  15. package/src/contracts/interest-oracle.ts +139 -39
  16. package/src/contracts/lrp.ts +223 -0
  17. package/src/contracts/one-shot.ts +67 -0
  18. package/src/contracts/stability-pool.ts +684 -0
  19. package/src/contracts/staking.ts +348 -0
  20. package/src/contracts/treasury.ts +30 -13
  21. package/src/helpers/asset-helpers.ts +51 -22
  22. package/src/helpers/helper-txs.ts +30 -0
  23. package/src/helpers/helpers.ts +29 -8
  24. package/src/helpers/indigo-helpers.ts +19 -0
  25. package/src/helpers/interest-oracle.ts +57 -0
  26. package/src/helpers/lucid-utils.ts +62 -16
  27. package/src/helpers/price-oracle-helpers.ts +36 -0
  28. package/src/helpers/stability-pool-helpers.ts +207 -0
  29. package/src/helpers/staking-helpers.ts +94 -0
  30. package/src/helpers/time-helpers.ts +4 -3
  31. package/src/helpers/value-helpers.ts +16 -0
  32. package/src/index.ts +15 -4
  33. package/src/scripts/always-fail-validator.ts +7 -0
  34. package/src/scripts/auth-token-policy.ts +23 -0
  35. package/src/scripts/cdp-creator-validator.ts +46 -2
  36. package/src/scripts/collector-validator.ts +2 -2
  37. package/src/scripts/execute-validator.ts +52 -0
  38. package/src/scripts/gov-validator.ts +44 -0
  39. package/src/scripts/iasset-policy.ts +22 -0
  40. package/src/scripts/interest-oracle-validator.ts +18 -3
  41. package/src/scripts/lrp-validator.ts +23 -0
  42. package/src/scripts/one-shot-policy.ts +62 -0
  43. package/src/scripts/poll-manager-validator.ts +52 -0
  44. package/src/scripts/poll-shard-validator.ts +47 -0
  45. package/src/scripts/price-oracle-validator.ts +26 -0
  46. package/src/scripts/stability-pool-validator.ts +60 -0
  47. package/src/scripts/staking-validator.ts +8 -0
  48. package/src/scripts/version-record-policy.ts +26 -0
  49. package/src/scripts/version-registry.ts +15 -0
  50. package/src/types/generic.ts +99 -6
  51. package/src/types/indigo/cdp-creator.ts +46 -0
  52. package/src/types/indigo/cdp.ts +86 -31
  53. package/src/types/indigo/execute.ts +21 -0
  54. package/src/types/indigo/gov.ts +50 -20
  55. package/src/types/indigo/interest-oracle.ts +55 -5
  56. package/src/types/indigo/lrp.ts +54 -0
  57. package/src/types/indigo/poll-manager.ts +21 -0
  58. package/src/types/indigo/poll-shard.ts +16 -0
  59. package/src/types/indigo/price-oracle.ts +38 -4
  60. package/src/types/indigo/stability-pool.ts +233 -0
  61. package/src/types/indigo/staking.ts +99 -0
  62. package/src/types/indigo/version-record.ts +17 -0
  63. package/src/types/on-chain-decimal.ts +23 -0
  64. package/src/types/one-shot.ts +22 -0
  65. package/src/types/system-params.ts +95 -77
  66. package/tests/data/system-params.json +972 -972
  67. package/tests/datums.test.ts +279 -44
  68. package/tests/endpoints/initialize.ts +1013 -0
  69. package/tests/hash-checks.test.ts +71 -15
  70. package/tests/indigo-test-helpers.ts +115 -0
  71. package/tests/initialize.test.ts +27 -0
  72. package/tests/interest-calculations.test.ts +110 -133
  73. package/tests/interest-oracle.test.ts +90 -0
  74. package/tests/lrp.test.ts +149 -0
  75. package/tests/queries/governance-queries.ts +31 -0
  76. package/tests/queries/iasset-queries.ts +39 -0
  77. package/tests/queries/interest-oracle-queries.ts +13 -0
  78. package/tests/queries/lrp-queries.ts +39 -0
  79. package/tests/queries/price-oracle-queries.ts +27 -0
  80. package/tests/queries/stability-pool-queries.ts +75 -0
  81. package/tests/queries/staking-queries.ts +43 -0
  82. package/tests/stability-pool.test.ts +364 -0
  83. package/tests/staking.test.ts +105 -0
  84. package/tests/test-helpers.ts +38 -0
  85. package/tsconfig.build.json +4 -0
  86. package/tsconfig.json +8 -27
  87. package/vitest.config.ts +9 -0
  88. package/babel.config.cjs +0 -13
  89. package/examples/sample-cdp.ts +0 -43
  90. package/jest.config.js +0 -13
  91. package/src/contracts/cdp-creator.ts +0 -86
  92. package/src/contracts/price-oracle.ts +0 -24
  93. package/src/helpers/cdp-helpers.ts +0 -9
@@ -1,86 +0,0 @@
1
- import {
2
- Address,
3
- applyParamsToScript,
4
- Constr,
5
- Credential,
6
- Data,
7
- fromText,
8
- LucidEvolution,
9
- SpendingValidator,
10
- UTxO,
11
- validatorToAddress,
12
- validatorToScriptHash,
13
- } from '@lucid-evolution/lucid';
14
- import { _cdpCreatorValidator } from '../scripts/cdp-creator-validator';
15
- import { CdpCreatorParams, ScriptReferences } from '../types/system-params';
16
- import { scriptRef } from '../helpers/lucid-utils';
17
-
18
- export class CDPCreatorContract {
19
- static address(params: CdpCreatorParams, lucid: LucidEvolution): Address {
20
- const network = lucid.config().network;
21
- if (!network) {
22
- throw new Error('Network configuration is undefined');
23
- }
24
- return validatorToAddress(network, CDPCreatorContract.validator(params));
25
- }
26
-
27
- static validator(params: CdpCreatorParams): SpendingValidator {
28
- return {
29
- type: 'PlutusV2',
30
- script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
31
- new Constr(0, [
32
- new Constr(0, [
33
- params.cdpCreatorNft[0].unCurrencySymbol,
34
- fromText(params.cdpCreatorNft[1].unTokenName),
35
- ]),
36
- params.cdpAssetCs.unCurrencySymbol,
37
- new Constr(0, [
38
- params.cdpAuthTk[0].unCurrencySymbol,
39
- fromText(params.cdpAuthTk[1].unTokenName),
40
- ]),
41
- new Constr(0, [
42
- params.iAssetAuthTk[0].unCurrencySymbol,
43
- fromText(params.iAssetAuthTk[1].unTokenName),
44
- ]),
45
- new Constr(0, [
46
- params.versionRecordToken[0].unCurrencySymbol,
47
- fromText(params.versionRecordToken[1].unTokenName),
48
- ]),
49
- params.cdpScriptHash,
50
- params.collectorValHash,
51
- BigInt(params.minCollateralInLovelace),
52
- BigInt(params.biasTime),
53
- ]),
54
- ]),
55
- };
56
- }
57
-
58
- static validatorHash(
59
- params: CdpCreatorParams
60
- ): string {
61
- return validatorToScriptHash(CDPCreatorContract.validator(params));
62
- }
63
-
64
- static redeemer(
65
- hash: Credential,
66
- mintedAmount: bigint,
67
- collateralAmount: bigint,
68
- currentTime: bigint,
69
- ): Data {
70
- if (hash.type !== 'Key') throw new Error('Cannot support script hash.');
71
-
72
- return new Constr<Data>(0, [
73
- hash.hash,
74
- BigInt(mintedAmount),
75
- BigInt(collateralAmount),
76
- currentTime
77
- ]);
78
- }
79
-
80
- static scriptRef(
81
- params: ScriptReferences,
82
- lucid: LucidEvolution,
83
- ): Promise<UTxO> {
84
- return scriptRef(params.cdpCreatorValidatorRef, lucid);
85
- }
86
- }
@@ -1,24 +0,0 @@
1
- import { Constr, Data } from "@lucid-evolution/lucid";
2
- import { PriceOracleDatum } from "../types/indigo/price-oracle";
3
-
4
- export class PriceOracleContract {
5
- static decodePriceOracleDatum(datum: string): PriceOracleDatum {
6
- const oracleDatum = Data.from(datum) as any;
7
- if (oracleDatum.index != 0 || oracleDatum.fields.length !== 2 || oracleDatum.fields[0].index !== 0)
8
- throw 'Invalid Price Oracle Datum provided.'
9
-
10
- return {
11
- price: oracleDatum.fields[0].fields[0],
12
- expiration: oracleDatum.fields[1],
13
- }
14
- }
15
-
16
- static encodePriceOracleDatum(datum: PriceOracleDatum): string {
17
- return Data.to(
18
- new Constr(0, [
19
- new Constr(0, [datum.price]),
20
- datum.expiration,
21
- ])
22
- )
23
- }
24
- }
@@ -1,9 +0,0 @@
1
- import { LucidEvolution, UTxO } from "@lucid-evolution/lucid";
2
- import { SystemParams } from "../types/system-params";
3
-
4
- export class CDPHelpers {
5
- static async cdps(params: SystemParams, lucid: LucidEvolution): Promise<UTxO[]> {
6
- throw new Error('Not implemented');
7
- }
8
-
9
- }