@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,4 +1,10 @@
1
- import { AssetClass, CurrencySymbol } from "./generic";
1
+ import { fromText, toText } from '@lucid-evolution/lucid';
2
+ import { AssetClass, CurrencySymbol, TokenName } from './generic';
3
+
4
+ /**
5
+ * AssetClassSP used in System Params
6
+ */
7
+ export type AssetClassSP = [CurrencySymbol, TokenName];
2
8
 
3
9
  export interface SystemParams {
4
10
  versionRecordParams: VersionRecordParams;
@@ -6,17 +12,17 @@ export interface SystemParams {
6
12
  treasuryParams: TreasuryParams;
7
13
  startTime: StartTime;
8
14
  stakingParams: StakingParams;
9
- stabilityPoolParams: StabilityPoolParams;
15
+ stabilityPoolParams: StabilityPoolParamsSP;
10
16
  scriptReferences: ScriptReferences;
11
- pollShardParams: PollShardParams;
12
- pollManagerParams: PollManagerParams;
13
- indyToken: AssetClass;
14
- govParams: GovParams;
15
- executeParams: ExecuteParams;
17
+ pollShardParams: PollShardParamsSP;
18
+ pollManagerParams: PollManagerParamsSP;
19
+ indyToken: AssetClassSP;
20
+ govParams: GovParamsSP;
21
+ executeParams: ExecuteParamsSP;
16
22
  distributionParams: DistributionParams;
17
23
  collectorParams: CollectorParams;
18
24
  cdpParams: CdpParams;
19
- cdpCreatorParams: CdpCreatorParams;
25
+ cdpCreatorParams: CDPCreatorParamsSP;
20
26
  }
21
27
  export type ValidatorHashes = {
22
28
  versionRegistryHash: string;
@@ -39,19 +45,19 @@ export interface AddressCredential {
39
45
  export interface ScriptCredential {
40
46
  tag: string;
41
47
  contents: {
42
- tag:string;
43
- contents:string;
48
+ tag: string;
49
+ contents: string;
44
50
  };
45
51
  }
46
52
  export interface PubKeyHash {
47
53
  getPubKeyHash: string;
48
54
  }
49
55
  export interface VersionRecordParams {
50
- upgradeToken: AssetClass;
56
+ upgradeToken: AssetClassSP;
51
57
  }
52
58
  export interface TreasuryParams {
53
- upgradeToken: AssetClass;
54
- versionRecordToken: AssetClass;
59
+ upgradeToken: AssetClassSP;
60
+ versionRecordToken: AssetClassSP;
55
61
  treasuryUtxosStakeCredential?: ScriptCredential;
56
62
  }
57
63
  export interface StartTime {
@@ -59,24 +65,24 @@ export interface StartTime {
59
65
  blockHeader: string;
60
66
  }
61
67
  export interface StakingParams {
62
- versionRecordToken: AssetClass;
63
- stakingToken: AssetClass;
64
- stakingManagerNFT: AssetClass;
65
- pollToken: AssetClass;
66
- indyToken: AssetClass;
68
+ versionRecordToken: AssetClassSP;
69
+ stakingToken: AssetClassSP;
70
+ stakingManagerNFT: AssetClassSP;
71
+ pollToken: AssetClassSP;
72
+ indyToken: AssetClassSP;
67
73
  collectorValHash: string;
68
74
  }
69
- export interface StabilityPoolParams {
70
- versionRecordToken: AssetClass;
71
- stabilityPoolToken: AssetClass;
72
- snapshotEpochToScaleToSumToken: AssetClass;
75
+ export interface StabilityPoolParamsSP {
76
+ versionRecordToken: AssetClassSP;
77
+ stabilityPoolToken: AssetClassSP;
78
+ snapshotEpochToScaleToSumToken: AssetClassSP;
73
79
  requestCollateralLovelaces: number;
74
- iAssetAuthToken: AssetClass;
75
- govNFT: AssetClass;
80
+ iAssetAuthToken: AssetClassSP;
81
+ govNFT: AssetClassSP;
76
82
  collectorValHash: string;
77
- cdpToken: AssetClass;
83
+ cdpToken: AssetClassSP;
78
84
  assetSymbol: CurrencySymbol;
79
- accountToken: AssetClass;
85
+ accountToken: AssetClassSP;
80
86
  accountCreateFeeLovelaces: number;
81
87
  accountAdjustmentFeeLovelaces: number;
82
88
  }
@@ -111,18 +117,16 @@ export interface ScriptOutput {
111
117
  referenceScript: string;
112
118
  datum: AddressCredentialOrDatum;
113
119
  amount: Amount;
114
- address: Address;
120
+ address: AddressSP;
115
121
  }
116
122
  export interface AddressCredentialOrDatum {
117
123
  tag: string;
118
124
  contents: string;
119
125
  }
120
126
  export interface Amount {
121
- getValue?:
122
- | ((CurrencySymbol | ((number)[] | null)[] | null)[] | null)[]
123
- | null;
127
+ getValue?: ((CurrencySymbol | (number[] | null)[] | null)[] | null)[] | null;
124
128
  }
125
- export interface Address {
129
+ export interface AddressSP {
126
130
  addressStakingCredential?: null;
127
131
  addressCredential: AddressCredentialOrDatum;
128
132
  }
@@ -132,7 +136,7 @@ export interface Input {
132
136
  }
133
137
 
134
138
  export interface ScriptReference {
135
- output: Output;
139
+ output?: Output;
136
140
  input: Input;
137
141
  }
138
142
 
@@ -147,47 +151,47 @@ export interface AuthTokenPolicies {
147
151
  accountTokenRef: ScriptReference;
148
152
  }
149
153
 
150
- export interface PollShardParams {
154
+ export interface PollShardParamsSP {
151
155
  stakingValHash: string;
152
- stakingToken: AssetClass;
153
- pollToken: AssetClass;
154
- indyAsset: AssetClass;
156
+ stakingToken: AssetClassSP;
157
+ pollToken: AssetClassSP;
158
+ indyAsset: AssetClassSP;
155
159
  }
156
160
 
157
- export interface PollManagerParams {
158
- upgradeToken: AssetClass;
161
+ export interface PollManagerParamsSP {
162
+ upgradeToken: AssetClassSP;
159
163
  treasuryValHash: string;
160
164
  shardsValHash: string;
161
- pollToken: AssetClass;
162
- pBiasTime: number;
163
- initialIndyDistribution: number;
164
- indyAsset: AssetClass;
165
- govNFT: AssetClass;
165
+ pollToken: AssetClassSP;
166
+ pBiasTime: bigint;
167
+ initialIndyDistribution: bigint;
168
+ indyAsset: AssetClassSP;
169
+ govNFT: AssetClassSP;
166
170
  govExecuteValHash: string;
167
171
  }
168
172
 
169
- export interface GovParams {
170
- versionRecordToken: AssetClass;
171
- upgradeToken: AssetClass;
172
- pollToken: AssetClass;
173
+ export interface GovParamsSP {
174
+ versionRecordToken: AssetClassSP;
175
+ upgradeToken: AssetClassSP;
176
+ pollToken: AssetClassSP;
173
177
  pollManagerValHash: string;
174
- indyAsset: AssetClass;
175
- iAssetAuthToken: AssetClass;
176
- govNFT: AssetClass;
177
- gBiasTime: number;
178
- daoIdentityToken: AssetClass;
179
- }
180
- export interface ExecuteParams {
178
+ indyAsset: AssetClassSP;
179
+ iAssetAuthToken: AssetClassSP;
180
+ govNFT: AssetClassSP;
181
+ gBiasTime: bigint;
182
+ daoIdentityToken: AssetClassSP;
183
+ }
184
+ export interface ExecuteParamsSP {
185
+ govNFT: AssetClassSP;
186
+ upgradeToken: AssetClassSP;
187
+ iAssetToken: AssetClassSP;
188
+ stabilityPoolToken: AssetClassSP;
189
+ versionRecordToken: AssetClassSP;
190
+ cdpValHash: string;
191
+ sPoolValHash: string;
181
192
  versionRegistryValHash: string;
182
- versionRecordToken: AssetClass;
183
- upgradeToken: AssetClass;
184
193
  treasuryValHash: string;
185
- stabilityPoolToken: AssetClass;
186
- sPoolValHash: string;
187
- maxInterestPeriods: number;
188
- iAssetToken: AssetClass;
189
- govNFT: AssetClass;
190
- cdpValHash: string;
194
+ indyAsset: AssetClassSP;
191
195
  }
192
196
  export interface DistributionParams {
193
197
  treasuryIndyAmount: number;
@@ -195,34 +199,48 @@ export interface DistributionParams {
195
199
  initialIndyDistribution: number;
196
200
  }
197
201
  export interface CollectorParams {
198
- versionRecordToken: AssetClass;
199
- stakingToken: AssetClass;
200
- stakingManagerNFT: AssetClass;
202
+ versionRecordToken: AssetClassSP;
203
+ stakingToken: AssetClassSP;
204
+ stakingManagerNFT: AssetClassSP;
201
205
  }
202
206
  export interface CdpParams {
203
- versionRecordToken: AssetClass;
204
- upgradeToken: AssetClass;
207
+ versionRecordToken: AssetClassSP;
208
+ upgradeToken: AssetClassSP;
205
209
  treasuryValHash: string;
206
- stabilityPoolAuthToken: AssetClass;
210
+ stabilityPoolAuthToken: AssetClassSP;
207
211
  spValHash: string;
208
212
  partialRedemptionExtraFeeLovelace: number;
209
213
  minCollateralInLovelace: number;
210
- iAssetAuthToken: AssetClass;
211
- govNFT: AssetClass;
214
+ iAssetAuthToken: AssetClassSP;
215
+ govNFT: AssetClassSP;
212
216
  collectorValHash: string;
213
- cdpAuthToken: AssetClass;
217
+ cdpAuthToken: AssetClassSP;
214
218
  cdpAssetSymbol: CurrencySymbol;
215
219
  biasTime: number;
216
220
  }
217
221
 
218
- export interface CdpCreatorParams {
219
- versionRecordToken: AssetClass;
222
+ export interface CDPCreatorParamsSP {
223
+ versionRecordToken: AssetClassSP;
220
224
  minCollateralInLovelace: number;
221
- iAssetAuthTk: AssetClass;
225
+ iAssetAuthTk: AssetClassSP;
222
226
  collectorValHash: string;
223
227
  cdpScriptHash: string;
224
- cdpCreatorNft: AssetClass;
225
- cdpAuthTk: AssetClass;
228
+ cdpCreatorNft: AssetClassSP;
229
+ cdpAuthTk: AssetClassSP;
226
230
  cdpAssetCs: CurrencySymbol;
227
- biasTime: number;
231
+ biasTime: bigint;
232
+ }
233
+
234
+ export function toSystemParamsAsset(asset: AssetClass): AssetClassSP {
235
+ return [
236
+ { unCurrencySymbol: asset.currencySymbol },
237
+ { unTokenName: toText(asset.tokenName) },
238
+ ];
239
+ }
240
+
241
+ export function fromSystemParamsAsset(asset: AssetClassSP): AssetClass {
242
+ return {
243
+ currencySymbol: asset[0].unCurrencySymbol,
244
+ tokenName: fromText(asset[1].unTokenName),
245
+ };
228
246
  }