@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.
- package/.nvmrc +1 -0
- package/.prettierrc +6 -0
- package/README.md +21 -0
- package/babel.config.cjs +13 -0
- package/dist/contracts/cdp-creator.d.ts +9 -0
- package/dist/contracts/cdp-creator.js +58 -0
- package/dist/contracts/cdp.d.ts +22 -0
- package/dist/contracts/cdp.js +542 -0
- package/dist/contracts/collector.d.ts +9 -0
- package/dist/contracts/collector.js +52 -0
- package/dist/contracts/gov.d.ts +5 -0
- package/dist/contracts/gov.js +50 -0
- package/dist/contracts/interest-oracle.d.ts +8 -0
- package/dist/contracts/interest-oracle.js +39 -0
- package/dist/contracts/price-oracle.d.ts +5 -0
- package/dist/contracts/price-oracle.js +18 -0
- package/dist/contracts/treasury.d.ts +9 -0
- package/dist/contracts/treasury.js +56 -0
- package/dist/helpers/asset-helpers.d.ts +11 -0
- package/dist/helpers/asset-helpers.js +23 -0
- package/dist/helpers/cdp-helpers.d.ts +5 -0
- package/dist/helpers/cdp-helpers.js +5 -0
- package/dist/helpers/helpers.d.ts +4 -0
- package/dist/helpers/helpers.js +14 -0
- package/dist/helpers/lucid-utils.d.ts +6 -0
- package/dist/helpers/lucid-utils.js +18 -0
- package/dist/helpers/time-helpers.d.ts +3 -0
- package/dist/helpers/time-helpers.js +3 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/scripts/cdp-creator-validator.d.ts +6 -0
- package/dist/scripts/cdp-creator-validator.js +6 -0
- package/dist/scripts/cdp-validator.d.ts +6 -0
- package/dist/scripts/cdp-validator.js +6 -0
- package/dist/scripts/collector-validator.d.ts +6 -0
- package/dist/scripts/collector-validator.js +5 -0
- package/dist/scripts/interest-oracle-validator.d.ts +6 -0
- package/dist/scripts/interest-oracle-validator.js +5 -0
- package/dist/scripts/treasury-validator.d.ts +6 -0
- package/dist/scripts/treasury-validator.js +5 -0
- package/dist/types/generic.d.ts +10 -0
- package/dist/types/generic.js +1 -0
- package/dist/types/indigo/cdp.d.ts +37 -0
- package/dist/types/indigo/cdp.js +1 -0
- package/dist/types/indigo/gov.d.ts +20 -0
- package/dist/types/indigo/gov.js +1 -0
- package/dist/types/indigo/interest-oracle.d.ts +5 -0
- package/dist/types/indigo/interest-oracle.js +1 -0
- package/dist/types/indigo/price-oracle.d.ts +4 -0
- package/dist/types/indigo/price-oracle.js +1 -0
- package/dist/types/system-params.d.ts +217 -0
- package/dist/types/system-params.js +1 -0
- package/jest.config.js +13 -0
- package/package.json +46 -0
- package/src/contracts/cdp-creator.ts +86 -0
- package/src/contracts/cdp.ts +892 -0
- package/src/contracts/collector.ts +91 -0
- package/src/contracts/gov.ts +58 -0
- package/src/contracts/interest-oracle.ts +49 -0
- package/src/contracts/price-oracle.ts +24 -0
- package/src/contracts/treasury.ts +95 -0
- package/src/helpers/asset-helpers.ts +28 -0
- package/src/helpers/cdp-helpers.ts +9 -0
- package/src/helpers/helpers.ts +17 -0
- package/src/helpers/lucid-utils.ts +24 -0
- package/src/helpers/time-helpers.ts +3 -0
- package/src/index.ts +23 -0
- package/src/scripts/cdp-creator-validator.ts +9 -0
- package/src/scripts/cdp-validator.ts +9 -0
- package/src/scripts/collector-validator.ts +8 -0
- package/src/scripts/interest-oracle-validator.ts +8 -0
- package/src/scripts/treasury-validator.ts +8 -0
- package/src/types/generic.ts +13 -0
- package/src/types/indigo/cdp.ts +33 -0
- package/src/types/indigo/gov.ts +21 -0
- package/src/types/indigo/interest-oracle.ts +5 -0
- package/src/types/indigo/price-oracle.ts +4 -0
- package/src/types/system-params.ts +228 -0
- package/tests/data/system-params.json +989 -0
- package/tests/datums.test.ts +51 -0
- package/tests/hash-checks.test.ts +17 -0
- package/tests/interest-calculations.test.ts +143 -0
- package/tsconfig.json +35 -0
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v18.19.1
|
package/.prettierrc
ADDED
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
|
+
```
|
package/babel.config.cjs
ADDED
|
@@ -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
|
+
}
|