@indigo-labs/indigo-sdk 0.1.0

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 (83) hide show
  1. package/.nvmrc +1 -0
  2. package/.prettierrc +6 -0
  3. package/README.md +21 -0
  4. package/babel.config.cjs +13 -0
  5. package/dist/contracts/cdp-creator.d.ts +9 -0
  6. package/dist/contracts/cdp-creator.js +58 -0
  7. package/dist/contracts/cdp.d.ts +22 -0
  8. package/dist/contracts/cdp.js +542 -0
  9. package/dist/contracts/collector.d.ts +9 -0
  10. package/dist/contracts/collector.js +52 -0
  11. package/dist/contracts/gov.d.ts +5 -0
  12. package/dist/contracts/gov.js +50 -0
  13. package/dist/contracts/interest-oracle.d.ts +8 -0
  14. package/dist/contracts/interest-oracle.js +39 -0
  15. package/dist/contracts/price-oracle.d.ts +5 -0
  16. package/dist/contracts/price-oracle.js +18 -0
  17. package/dist/contracts/treasury.d.ts +9 -0
  18. package/dist/contracts/treasury.js +56 -0
  19. package/dist/helpers/asset-helpers.d.ts +11 -0
  20. package/dist/helpers/asset-helpers.js +23 -0
  21. package/dist/helpers/cdp-helpers.d.ts +5 -0
  22. package/dist/helpers/cdp-helpers.js +5 -0
  23. package/dist/helpers/helpers.d.ts +4 -0
  24. package/dist/helpers/helpers.js +14 -0
  25. package/dist/helpers/lucid-utils.d.ts +6 -0
  26. package/dist/helpers/lucid-utils.js +18 -0
  27. package/dist/helpers/time-helpers.d.ts +3 -0
  28. package/dist/helpers/time-helpers.js +3 -0
  29. package/dist/index.d.ts +23 -0
  30. package/dist/index.js +23 -0
  31. package/dist/scripts/cdp-creator-validator.d.ts +6 -0
  32. package/dist/scripts/cdp-creator-validator.js +6 -0
  33. package/dist/scripts/cdp-validator.d.ts +6 -0
  34. package/dist/scripts/cdp-validator.js +6 -0
  35. package/dist/scripts/collector-validator.d.ts +6 -0
  36. package/dist/scripts/collector-validator.js +5 -0
  37. package/dist/scripts/interest-oracle-validator.d.ts +6 -0
  38. package/dist/scripts/interest-oracle-validator.js +5 -0
  39. package/dist/scripts/treasury-validator.d.ts +6 -0
  40. package/dist/scripts/treasury-validator.js +5 -0
  41. package/dist/types/generic.d.ts +10 -0
  42. package/dist/types/generic.js +1 -0
  43. package/dist/types/indigo/cdp.d.ts +37 -0
  44. package/dist/types/indigo/cdp.js +1 -0
  45. package/dist/types/indigo/gov.d.ts +20 -0
  46. package/dist/types/indigo/gov.js +1 -0
  47. package/dist/types/indigo/interest-oracle.d.ts +5 -0
  48. package/dist/types/indigo/interest-oracle.js +1 -0
  49. package/dist/types/indigo/price-oracle.d.ts +4 -0
  50. package/dist/types/indigo/price-oracle.js +1 -0
  51. package/dist/types/system-params.d.ts +217 -0
  52. package/dist/types/system-params.js +1 -0
  53. package/jest.config.js +13 -0
  54. package/package.json +46 -0
  55. package/src/contracts/cdp-creator.ts +86 -0
  56. package/src/contracts/cdp.ts +892 -0
  57. package/src/contracts/collector.ts +91 -0
  58. package/src/contracts/gov.ts +58 -0
  59. package/src/contracts/interest-oracle.ts +49 -0
  60. package/src/contracts/price-oracle.ts +24 -0
  61. package/src/contracts/treasury.ts +95 -0
  62. package/src/helpers/asset-helpers.ts +28 -0
  63. package/src/helpers/cdp-helpers.ts +9 -0
  64. package/src/helpers/helpers.ts +17 -0
  65. package/src/helpers/lucid-utils.ts +24 -0
  66. package/src/helpers/time-helpers.ts +3 -0
  67. package/src/index.ts +23 -0
  68. package/src/scripts/cdp-creator-validator.ts +9 -0
  69. package/src/scripts/cdp-validator.ts +9 -0
  70. package/src/scripts/collector-validator.ts +8 -0
  71. package/src/scripts/interest-oracle-validator.ts +8 -0
  72. package/src/scripts/treasury-validator.ts +8 -0
  73. package/src/types/generic.ts +13 -0
  74. package/src/types/indigo/cdp.ts +33 -0
  75. package/src/types/indigo/gov.ts +21 -0
  76. package/src/types/indigo/interest-oracle.ts +5 -0
  77. package/src/types/indigo/price-oracle.ts +4 -0
  78. package/src/types/system-params.ts +228 -0
  79. package/tests/data/system-params.json +989 -0
  80. package/tests/datums.test.ts +51 -0
  81. package/tests/hash-checks.test.ts +17 -0
  82. package/tests/interest-calculations.test.ts +143 -0
  83. package/tsconfig.json +35 -0
@@ -0,0 +1,4 @@
1
+ export type PriceOracleDatum = {
2
+ price: bigint;
3
+ expiration: bigint;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,217 @@
1
+ import { AssetClass, CurrencySymbol } from "./generic";
2
+ export interface SystemParams {
3
+ versionRecordParams: VersionRecordParams;
4
+ validatorHashes: ValidatorHashes;
5
+ treasuryParams: TreasuryParams;
6
+ startTime: StartTime;
7
+ stakingParams: StakingParams;
8
+ stabilityPoolParams: StabilityPoolParams;
9
+ scriptReferences: ScriptReferences;
10
+ pollShardParams: PollShardParams;
11
+ pollManagerParams: PollManagerParams;
12
+ indyToken: AssetClass;
13
+ govParams: GovParams;
14
+ executeParams: ExecuteParams;
15
+ distributionParams: DistributionParams;
16
+ collectorParams: CollectorParams;
17
+ cdpParams: CdpParams;
18
+ cdpCreatorParams: CdpCreatorParams;
19
+ }
20
+ export type ValidatorHashes = {
21
+ versionRegistryHash: string;
22
+ treasuryHash: string;
23
+ stakingHash: string;
24
+ stabilityPoolHash: string;
25
+ pollShardHash: string;
26
+ pollManagerHash: string;
27
+ govHash: string;
28
+ executeHash: string;
29
+ collectorHash: string;
30
+ cdpHash: string;
31
+ cdpCreatorHash: string;
32
+ };
33
+ export interface AddressCredential {
34
+ tag: string;
35
+ contents: PubKeyHash;
36
+ }
37
+ export interface ScriptCredential {
38
+ tag: string;
39
+ contents: {
40
+ tag: string;
41
+ contents: string;
42
+ };
43
+ }
44
+ export interface PubKeyHash {
45
+ getPubKeyHash: string;
46
+ }
47
+ export interface VersionRecordParams {
48
+ upgradeToken: AssetClass;
49
+ }
50
+ export interface TreasuryParams {
51
+ upgradeToken: AssetClass;
52
+ versionRecordToken: AssetClass;
53
+ treasuryUtxosStakeCredential?: ScriptCredential;
54
+ }
55
+ export interface StartTime {
56
+ slot: number;
57
+ blockHeader: string;
58
+ }
59
+ export interface StakingParams {
60
+ versionRecordToken: AssetClass;
61
+ stakingToken: AssetClass;
62
+ stakingManagerNFT: AssetClass;
63
+ pollToken: AssetClass;
64
+ indyToken: AssetClass;
65
+ collectorValHash: string;
66
+ }
67
+ export interface StabilityPoolParams {
68
+ versionRecordToken: AssetClass;
69
+ stabilityPoolToken: AssetClass;
70
+ snapshotEpochToScaleToSumToken: AssetClass;
71
+ requestCollateralLovelaces: number;
72
+ iAssetAuthToken: AssetClass;
73
+ govNFT: AssetClass;
74
+ collectorValHash: string;
75
+ cdpToken: AssetClass;
76
+ assetSymbol: CurrencySymbol;
77
+ accountToken: AssetClass;
78
+ accountCreateFeeLovelaces: number;
79
+ accountAdjustmentFeeLovelaces: number;
80
+ }
81
+ export interface ScriptReferences {
82
+ vestingValidatorRef: ScriptReference;
83
+ versionRegistryValidatorRef: ScriptReference;
84
+ versionRecordTokenPolicyRef: ScriptReference;
85
+ treasuryValidatorRef: ScriptReference;
86
+ stakingValidatorRef: ScriptReference;
87
+ stabilityPoolValidatorRef: ScriptReference;
88
+ pollShardValidatorRef: ScriptReference;
89
+ pollManagerValidatorRef: ScriptReference;
90
+ liquidityValidatorRef: ScriptReference;
91
+ iAssetTokenPolicyRef: ScriptReference;
92
+ governanceValidatorRef: ScriptReference;
93
+ executeValidatorRef: ScriptReference;
94
+ collectorValidatorRef: ScriptReference;
95
+ cdpValidatorRef: ScriptReference;
96
+ cdpCreatorValidatorRef: ScriptReference;
97
+ authTokenPolicies: AuthTokenPolicies;
98
+ }
99
+ export interface Output {
100
+ scriptRef: ScriptRef;
101
+ output: ScriptOutput;
102
+ }
103
+ export interface ScriptRef {
104
+ tag: string;
105
+ contents?: string[] | null;
106
+ }
107
+ export interface ScriptOutput {
108
+ referenceScript: string;
109
+ datum: AddressCredentialOrDatum;
110
+ amount: Amount;
111
+ address: Address;
112
+ }
113
+ export interface AddressCredentialOrDatum {
114
+ tag: string;
115
+ contents: string;
116
+ }
117
+ export interface Amount {
118
+ getValue?: ((CurrencySymbol | ((number)[] | null)[] | null)[] | null)[] | null;
119
+ }
120
+ export interface Address {
121
+ addressStakingCredential?: null;
122
+ addressCredential: AddressCredentialOrDatum;
123
+ }
124
+ export interface Input {
125
+ transactionId: string;
126
+ index: number;
127
+ }
128
+ export interface ScriptReference {
129
+ output: Output;
130
+ input: Input;
131
+ }
132
+ export interface AuthTokenPolicies {
133
+ upgradeTokenRef: ScriptReference;
134
+ stakingTokenRef: ScriptReference;
135
+ stabilityPoolTokenRef: ScriptReference;
136
+ snapshotEpochToScaleToSumTokenRef: ScriptReference;
137
+ pollManagerTokenRef: ScriptReference;
138
+ iAssetTokenRef: ScriptReference;
139
+ cdpAuthTokenRef: ScriptReference;
140
+ accountTokenRef: ScriptReference;
141
+ }
142
+ export interface PollShardParams {
143
+ stakingValHash: string;
144
+ stakingToken: AssetClass;
145
+ pollToken: AssetClass;
146
+ indyAsset: AssetClass;
147
+ }
148
+ export interface PollManagerParams {
149
+ upgradeToken: AssetClass;
150
+ treasuryValHash: string;
151
+ shardsValHash: string;
152
+ pollToken: AssetClass;
153
+ pBiasTime: number;
154
+ initialIndyDistribution: number;
155
+ indyAsset: AssetClass;
156
+ govNFT: AssetClass;
157
+ govExecuteValHash: string;
158
+ }
159
+ export interface GovParams {
160
+ versionRecordToken: AssetClass;
161
+ upgradeToken: AssetClass;
162
+ pollToken: AssetClass;
163
+ pollManagerValHash: string;
164
+ indyAsset: AssetClass;
165
+ iAssetAuthToken: AssetClass;
166
+ govNFT: AssetClass;
167
+ gBiasTime: number;
168
+ daoIdentityToken: AssetClass;
169
+ }
170
+ export interface ExecuteParams {
171
+ versionRegistryValHash: string;
172
+ versionRecordToken: AssetClass;
173
+ upgradeToken: AssetClass;
174
+ treasuryValHash: string;
175
+ stabilityPoolToken: AssetClass;
176
+ sPoolValHash: string;
177
+ maxInterestPeriods: number;
178
+ iAssetToken: AssetClass;
179
+ govNFT: AssetClass;
180
+ cdpValHash: string;
181
+ }
182
+ export interface DistributionParams {
183
+ treasuryIndyAmount: number;
184
+ totalINDYSupply: number;
185
+ initialIndyDistribution: number;
186
+ }
187
+ export interface CollectorParams {
188
+ versionRecordToken: AssetClass;
189
+ stakingToken: AssetClass;
190
+ stakingManagerNFT: AssetClass;
191
+ }
192
+ export interface CdpParams {
193
+ versionRecordToken: AssetClass;
194
+ upgradeToken: AssetClass;
195
+ treasuryValHash: string;
196
+ stabilityPoolAuthToken: AssetClass;
197
+ spValHash: string;
198
+ partialRedemptionExtraFeeLovelace: number;
199
+ minCollateralInLovelace: number;
200
+ iAssetAuthToken: AssetClass;
201
+ govNFT: AssetClass;
202
+ collectorValHash: string;
203
+ cdpAuthToken: AssetClass;
204
+ cdpAssetSymbol: CurrencySymbol;
205
+ biasTime: number;
206
+ }
207
+ export interface CdpCreatorParams {
208
+ versionRecordToken: AssetClass;
209
+ minCollateralInLovelace: number;
210
+ iAssetAuthTk: AssetClass;
211
+ collectorValHash: string;
212
+ cdpScriptHash: string;
213
+ cdpCreatorNft: AssetClass;
214
+ cdpAuthTk: AssetClass;
215
+ cdpAssetCs: CurrencySymbol;
216
+ biasTime: number;
217
+ }
@@ -0,0 +1 @@
1
+ export {};
package/jest.config.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": "current"
8
+ }
9
+ }
10
+ ],
11
+ "@babel/preset-typescript",
12
+ ]
13
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@indigo-labs/indigo-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "build-tsup": "tsup src/index.ts --format esm,cjs --dts --clean",
11
+ "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
12
+ "lint": "eslint .",
13
+ "lint:fix": "eslint . --fix",
14
+ "prettier": "prettier --ignore-path .gitignore --write \"./src/**/*.+(js|ts|json)\"",
15
+ "prettier:fix": "prettier --write src",
16
+ "example": "tsup ./examples/sample-cdp.ts --format esm,cjs --dts --clean && node ./dist/sample-cdp.js"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/IndigoProtocol/indigo-sdk.git"
21
+ },
22
+ "keywords": [
23
+ "indigo",
24
+ "sdk",
25
+ "typescript",
26
+ "lucid-evolution",
27
+ "cdp"
28
+ ],
29
+ "author": "3rd Eye Labs",
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "@lucid-evolution/lucid": "^0.4.22",
33
+ "babel-jest": "^29.5.0"
34
+ },
35
+ "devDependencies": {
36
+ "@babel/core": "^7.21.4",
37
+ "@babel/preset-env": "^7.21.4",
38
+ "@babel/preset-typescript": "^7.21.4",
39
+ "@types/jest": "^29.5.0",
40
+ "jest": "^29.5.0",
41
+ "ts-jest": "^29.1.0",
42
+ "ts-node": "^10.9.1",
43
+ "tsup": "^8.3.6",
44
+ "typescript": "^5.0.3"
45
+ }
46
+ }
@@ -0,0 +1,86 @@
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
+ }