@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
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v18.19.1
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "tabWidth": 2,
5
+ "semi": true
6
+ }
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Indigo SDK
2
+
3
+ ** Not ready for production yet **
4
+
5
+ `indigo-sdk` is a TypeScript SDK designed to interact with Indigo endpoints for managing CDPs (Collateralized Debt Positions) by integrating the [lucid-evolution](https://github.com/Anastasia-Labs/lucid-evolution) library.
6
+
7
+ ## Endpoints
8
+
9
+ - **Open CDP**
10
+ - **Close CDP**
11
+ - **Deposit Collateral to CDP**
12
+ - **Withdraw Collateral from CDP**
13
+ - **Mint against CDP**
14
+ - **Burn against CDP**
15
+ - **Pay CDP Interest**
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @indigo-labs/indigo-sdk
21
+ ```
@@ -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
+ };
@@ -0,0 +1,9 @@
1
+ import { Address, Credential, Data, LucidEvolution, SpendingValidator, UTxO } from '@lucid-evolution/lucid';
2
+ import { CdpCreatorParams, ScriptReferences } from '../types/system-params';
3
+ export declare class CDPCreatorContract {
4
+ static address(params: CdpCreatorParams, lucid: LucidEvolution): Address;
5
+ static validator(params: CdpCreatorParams): SpendingValidator;
6
+ static validatorHash(params: CdpCreatorParams): string;
7
+ static redeemer(hash: Credential, mintedAmount: bigint, collateralAmount: bigint, currentTime: bigint): Data;
8
+ static scriptRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
9
+ }
@@ -0,0 +1,58 @@
1
+ import { applyParamsToScript, Constr, fromText, validatorToAddress, validatorToScriptHash, } from '@lucid-evolution/lucid';
2
+ import { _cdpCreatorValidator } from '../scripts/cdp-creator-validator';
3
+ import { scriptRef } from '../helpers/lucid-utils';
4
+ export class CDPCreatorContract {
5
+ static address(params, lucid) {
6
+ const network = lucid.config().network;
7
+ if (!network) {
8
+ throw new Error('Network configuration is undefined');
9
+ }
10
+ return validatorToAddress(network, CDPCreatorContract.validator(params));
11
+ }
12
+ static validator(params) {
13
+ return {
14
+ type: 'PlutusV2',
15
+ script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
16
+ new Constr(0, [
17
+ new Constr(0, [
18
+ params.cdpCreatorNft[0].unCurrencySymbol,
19
+ fromText(params.cdpCreatorNft[1].unTokenName),
20
+ ]),
21
+ params.cdpAssetCs.unCurrencySymbol,
22
+ new Constr(0, [
23
+ params.cdpAuthTk[0].unCurrencySymbol,
24
+ fromText(params.cdpAuthTk[1].unTokenName),
25
+ ]),
26
+ new Constr(0, [
27
+ params.iAssetAuthTk[0].unCurrencySymbol,
28
+ fromText(params.iAssetAuthTk[1].unTokenName),
29
+ ]),
30
+ new Constr(0, [
31
+ params.versionRecordToken[0].unCurrencySymbol,
32
+ fromText(params.versionRecordToken[1].unTokenName),
33
+ ]),
34
+ params.cdpScriptHash,
35
+ params.collectorValHash,
36
+ BigInt(params.minCollateralInLovelace),
37
+ BigInt(params.biasTime),
38
+ ]),
39
+ ]),
40
+ };
41
+ }
42
+ static validatorHash(params) {
43
+ return validatorToScriptHash(CDPCreatorContract.validator(params));
44
+ }
45
+ static redeemer(hash, mintedAmount, collateralAmount, currentTime) {
46
+ if (hash.type !== 'Key')
47
+ throw new Error('Cannot support script hash.');
48
+ return new Constr(0, [
49
+ hash.hash,
50
+ BigInt(mintedAmount),
51
+ BigInt(collateralAmount),
52
+ currentTime
53
+ ]);
54
+ }
55
+ static scriptRef(params, lucid) {
56
+ return scriptRef(params.cdpCreatorValidatorRef, lucid);
57
+ }
58
+ }
@@ -0,0 +1,22 @@
1
+ import { Constr, Credential, Data, LucidEvolution, OutRef, SpendingValidator, TxBuilder, UTxO } from '@lucid-evolution/lucid';
2
+ import { CdpParams, ScriptReferences, SystemParams } from '../types/system-params';
3
+ import { CDPDatum, CDPFees } from '../types/indigo/cdp';
4
+ export declare class CDPContract {
5
+ static openPosition(asset: string, collateralAmount: bigint, mintedAmount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, cdpCreatorRef?: OutRef, collectorRef?: OutRef): Promise<TxBuilder>;
6
+ static deposit(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
7
+ static withdraw(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
8
+ static mint(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
9
+ static burn(cdpRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
10
+ 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>;
11
+ static close(cdpRef: OutRef, params: SystemParams, lucid: LucidEvolution, assetRef?: OutRef, priceOracleRef?: OutRef, interestOracleRef?: OutRef, collectorRef?: OutRef, govRef?: OutRef, treasuryRef?: OutRef): Promise<TxBuilder>;
12
+ static decodeCdpDatum(datum: string): CDPDatum;
13
+ static encodeCdpDatum(datum: CDPDatum): string;
14
+ static datum(hash: Credential, asset: string, mintedAmount: bigint, fees: CDPFees): Constr<Data>;
15
+ static validator(params: CdpParams): SpendingValidator;
16
+ static validatorHash(params: CdpParams): string;
17
+ static address(cdpParams: CdpParams, lucid: LucidEvolution, skh?: Credential): string;
18
+ static scriptRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
19
+ static cdpAuthTokenRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
20
+ static assetTokenRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
21
+ static assetAuthTokenRef(params: ScriptReferences, lucid: LucidEvolution): Promise<UTxO>;
22
+ }