@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,51 @@
1
+ import { InterestOracleContract } from '../src/contracts/interest-oracle';
2
+ import { CDPContract, CDPDatum, PriceOracleContract } from '../src/index';
3
+
4
+ describe('Datum checks', () => {
5
+ it('Price Oracle', () => {
6
+ expect(PriceOracleContract.decodePriceOracleDatum('d8799fd8799f1a0013c347ff1b00000194d68e13d8ff')).toEqual({ price: 1295175n, expiration: 1738766423000n });
7
+ expect(PriceOracleContract.encodePriceOracleDatum({ price: 1295175n, expiration: 1738766423000n })).toEqual('d8799fd8799f1a0013c347ff1b00000194d68e13d8ff');
8
+ });
9
+
10
+ it('Interest Oracle', () => {
11
+ expect(InterestOracleContract.decodeInterestOracleDatum('d8799f1b0180e51d1ae19514d8799f1a00030d40ff1b00000194ce33c598ff')).toEqual({ unitaryInterest: 108338304224695572n, interestRate: 200000n, lastUpdated: 1738626287000n });
12
+ expect(InterestOracleContract.encodeInterestOracleDatum({ unitaryInterest: 108338304224695572n, interestRate: 200000n, lastUpdated: 1738626287000n })).toEqual('d8799f1b0180e51d1ae19514d8799f1a00030d40ff1b00000194ce33c598ff');
13
+ });
14
+
15
+ it('CDP', () => {
16
+ // Active CDP
17
+ const activeCDPDatum = 'd8799fd8799fd8799f581c98e30e1c6dbb727dc98bdcb48b99b313c97fabfb537ff4b29a94ed1cff44695553441b00000004d9b0a47ed8799f1b00000194d5ebec201b03022de04fddf5f9ffffff';
18
+ const activeCDPObject: CDPDatum = { type: 'CDP', owner: '98e30e1c6dbb727dc98bdcb48b99b313c97fabfb537ff4b29a94ed1c', asset: 'iUSD', mintedAmount: 20832101502n, fees: { type: 'ActiveCDPInterestTracking', last_settled: 1738755796000n, unitary_interest_snapshot: 216786173503075833n } };
19
+ expect(CDPContract.decodeCdpDatum(activeCDPDatum)).toEqual(activeCDPObject);
20
+ expect(CDPContract.encodeCdpDatum(activeCDPObject)).toEqual(activeCDPDatum);
21
+
22
+ // Frozen CDP
23
+ const frozenCDPDatum = 'd8799fd8799fd87a8044695553441a0050924ed87a9f1a0002765a1a0003ca56ffffff';
24
+ const frozenCDPObject: CDPDatum = { type: 'CDP', owner: undefined, asset: 'iUSD', mintedAmount: 5280334n, fees: { type: 'FrozenCDPAccumulatedFees', lovelaces_treasury: 161370n, lovelaces_indy_stakers: 248406n } };
25
+ expect(CDPContract.decodeCdpDatum(frozenCDPDatum)).toEqual(frozenCDPObject);
26
+ expect(CDPContract.encodeCdpDatum(frozenCDPObject)).toEqual(frozenCDPDatum);
27
+ });
28
+
29
+ it('iAsset', () => {
30
+ const assetDatum = 'd87a9fd8799f4469455448d87a9fd8799fd8799f581c6c9497ffd7e8baf86c3c0d6fcd43c524daa49ad5fceba26d715468e952694554483230323231323139313931333032ffffffd8799f581c7b75e317505dddce858ae7bf200656a967c7544e55efa5d18ef302494d694554485f494e544552455354ffd8799f1a08f0d180ffd8799f1a06dac2c0ffd8799f1a068e7780ffd8799f1a000186a0ffd8799f1a001e8480ffd8799f19c350ffd8799f1a000f4240ffd8799f1a000f4240ffd8799f1a01c9c380ffd87980d8799f4469534f4cffffff';;
31
+ const assetObject: CDPDatum = {
32
+ type: 'IAsset',
33
+ name: 'iETH',
34
+ price: [{ unCurrencySymbol: '6c9497ffd7e8baf86c3c0d6fcd43c524daa49ad5fceba26d715468e9'}, {unTokenName: 'iETH20221219191302'}],
35
+ interestOracle: [{ unCurrencySymbol: '7b75e317505dddce858ae7bf200656a967c7544e55efa5d18ef30249'}, {unTokenName: 'iETH_INTEREST'}],
36
+ redemptionRatioPercentage: {getOnChainInt: 150000000n},
37
+ maintenanceRatioPercentage: {getOnChainInt: 115000000n},
38
+ liquidationRatioPercentage: {getOnChainInt: 110000000n},
39
+ debtMintingFeePercentage: {getOnChainInt: 100000n},
40
+ liquidationProcessingFeePercentage: {getOnChainInt: 2000000n},
41
+ stabilityPoolWithdrawalFeePercentage: {getOnChainInt: 50000n},
42
+ redemptionReimbursementPercentage: {getOnChainInt: 1000000n},
43
+ redemptionProcessingFeePercentage: {getOnChainInt: 1000000n},
44
+ interestCollectorPortionPercentage: {getOnChainInt: 30000000n},
45
+ firstAsset: false,
46
+ nextAsset: 'iSOL',
47
+ };
48
+ expect(CDPContract.decodeCdpDatum(assetDatum)).toEqual(assetObject);
49
+ expect(CDPContract.encodeCdpDatum(assetObject)).toEqual(assetDatum);
50
+ });
51
+ });
@@ -0,0 +1,17 @@
1
+ import { loadSystemParamsFromFile, loadSystemParamsFromUrl } from '../src/helpers';
2
+ import { CDPCreatorContract } from '../src/contracts/cdp-creator';
3
+ import { CDPContract, SystemParams } from '../src';
4
+ import { CollectorContract } from '../src/contracts/collector';
5
+
6
+ const systemParams = loadSystemParamsFromFile('./tests/data/system-params.json');
7
+ describe('Validator Hash checks', () => {
8
+ it('CDP Creator validator hash', () => {
9
+ expect(CDPCreatorContract.validatorHash(systemParams.cdpCreatorParams)).toBe(systemParams.validatorHashes.cdpCreatorHash);
10
+ });
11
+ it('CDP validator hash', () => {
12
+ expect(CDPContract.validatorHash(systemParams.cdpParams)).toBe(systemParams.validatorHashes.cdpHash);
13
+ });
14
+ it('Collector validator hash', () => {
15
+ expect(CollectorContract.validatorHash(systemParams.collectorParams)).toBe(systemParams.validatorHashes.collectorHash);
16
+ });
17
+ })
@@ -0,0 +1,143 @@
1
+ import { InterestOracleContract } from "../src/contracts/interest-oracle";
2
+ import { oneDay } from "../src/helpers/time-helpers";
3
+
4
+ describe('Interest Calculations', () => {
5
+ describe('Calculate Unitary Interest', () => {
6
+ it('Should calculate the unitary interest correctly, 0', () => {
7
+ expect(
8
+ InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
9
+ oneDay * 6n,
10
+ {
11
+ unitaryInterest: 684_931_506_849_315n,
12
+ interestRate: 100_000n,
13
+ lastUpdated: oneDay * 5n
14
+ }
15
+ )
16
+ ).toBe(273_972_602_739_726n);
17
+ });
18
+
19
+ it('Should calculate the unitary interest correctly, 1', () => {
20
+ expect(
21
+ InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
22
+ oneDay * 6n,
23
+ {
24
+ unitaryInterest: 0n,
25
+ interestRate: 50_000n,
26
+ lastUpdated: 0n
27
+ }
28
+ )
29
+ ).toBe(821_917_808_219_178n);
30
+ });
31
+
32
+ it('Should calculate the unitary interest correctly, 2', () => {
33
+ expect(
34
+ InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
35
+ 1n,
36
+ {
37
+ unitaryInterest: 0n,
38
+ interestRate: 1n,
39
+ lastUpdated: 0n
40
+ }
41
+ )
42
+ ).toBe(31n);
43
+ });
44
+ })
45
+
46
+ describe('Calculate Accumulated Interest', () => {
47
+ it('Should calculate the accumulated interest correctly, 0', () => {
48
+ expect(
49
+ InterestOracleContract.calculateAccruedInterest(
50
+ oneDay,
51
+ 0n,
52
+ 1_000_000n,
53
+ 0n,
54
+ {
55
+ unitaryInterest: 0n,
56
+ interestRate: 50_000n,
57
+ lastUpdated: 0n
58
+ }
59
+ )
60
+ ).toBe(136n)
61
+ });
62
+
63
+ it('Should calculate the accumulated interest correctly, 1', () => {
64
+ expect(
65
+ InterestOracleContract.calculateAccruedInterest(
66
+ oneDay * 6n,
67
+ 0n,
68
+ 1_000_000n,
69
+ 0n,
70
+ {
71
+ unitaryInterest: 684_931_506_849_315n,
72
+ interestRate: 100_000n,
73
+ lastUpdated: oneDay * 5n
74
+ }
75
+ )
76
+ ).toBe(684n + 273n)
77
+ });
78
+
79
+ it('Should calculate the accumulated interest correctly, 2', () => {
80
+ expect(
81
+ InterestOracleContract.calculateAccruedInterest(
82
+ oneDay * 17n,
83
+ 0n,
84
+ 1_000_000n,
85
+ 0n,
86
+ {
87
+ unitaryInterest: 1_506_849_315_068_493n,
88
+ interestRate: 100_000n,
89
+ lastUpdated: oneDay * 15n
90
+ }
91
+ )
92
+ ).toBe(1506n + 547n)
93
+ });
94
+
95
+ it('Should calculate the accumulated interest correctly, 3', () => {
96
+ expect(
97
+ InterestOracleContract.calculateAccruedInterest(
98
+ oneDay * 17n,
99
+ 410_958_904_109_589n,
100
+ 1_000_000n,
101
+ oneDay * 3n,
102
+ {
103
+ unitaryInterest: 1_506_849_315_068_493n,
104
+ interestRate: 100_000n,
105
+ lastUpdated: oneDay * 15n
106
+ }
107
+ )
108
+ ).toBe(1095n + 547n)
109
+ });
110
+
111
+ it('Should calculate the accumulated interest correctly, 4', () => {
112
+ expect(
113
+ InterestOracleContract.calculateAccruedInterest(
114
+ oneDay * 17n,
115
+ 767_123_287_671_232n,
116
+ 1_000_000n,
117
+ oneDay * 6n,
118
+ {
119
+ unitaryInterest: 1_506_849_315_068_493n,
120
+ interestRate: 100_000n,
121
+ lastUpdated: oneDay * 15n
122
+ }
123
+ )
124
+ ).toBe(739n + 547n)
125
+ });
126
+
127
+ it('Should calculate the accumulated interest correctly, 5', () => {
128
+ expect(
129
+ InterestOracleContract.calculateAccruedInterest(
130
+ oneDay * 10n,
131
+ 821_917_808_219_178n,
132
+ 1_000_000n,
133
+ oneDay * 6n,
134
+ {
135
+ unitaryInterest: 0n,
136
+ interestRate: 50_000n,
137
+ lastUpdated: 0n
138
+ }
139
+ )
140
+ ).toBe(547n)
141
+ });
142
+ });
143
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist",
4
+ "noImplicitAny": true,
5
+ "module": "es2022",
6
+ "target": "es2022",
7
+ "lib": ["es2022", "DOM"],
8
+ "allowJs": true,
9
+ "moduleResolution": "node",
10
+ "declaration": true,
11
+ "strict": true,
12
+ "strictNullChecks": true,
13
+ "strictFunctionTypes": true,
14
+ "strictBindCallApply": true,
15
+ "strictPropertyInitialization": false,
16
+ "noImplicitThis": true,
17
+ "alwaysStrict": false,
18
+ "noUnusedLocals": false,
19
+ "noUnusedParameters": false,
20
+ "noImplicitReturns": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "esModuleInterop": true,
23
+ "skipLibCheck": true,
24
+ "forceConsistentCasingInFileNames": true,
25
+ "resolveJsonModule": true,
26
+ "allowSyntheticDefaultImports": true
27
+ },
28
+ "ts-node": {
29
+ "compilerOptions": {
30
+ "module": "ES2022",
31
+ }
32
+ },
33
+ "include": ["src/**/*.ts"],
34
+ "exclude": ["node_modules", "tests", "dist"],
35
+ }