@indigo-labs/indigo-sdk 0.1.0 → 0.1.2

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 (53) hide show
  1. package/dist/index.d.mts +418 -0
  2. package/dist/index.d.ts +418 -23
  3. package/dist/index.js +1067 -23
  4. package/dist/index.mjs +1036 -0
  5. package/examples/sample-cdp.ts +43 -0
  6. package/package.json +2 -3
  7. package/src/contracts/cdp.ts +2 -2
  8. package/dist/contracts/cdp-creator.d.ts +0 -9
  9. package/dist/contracts/cdp-creator.js +0 -58
  10. package/dist/contracts/cdp.d.ts +0 -22
  11. package/dist/contracts/cdp.js +0 -542
  12. package/dist/contracts/collector.d.ts +0 -9
  13. package/dist/contracts/collector.js +0 -52
  14. package/dist/contracts/gov.d.ts +0 -5
  15. package/dist/contracts/gov.js +0 -50
  16. package/dist/contracts/interest-oracle.d.ts +0 -8
  17. package/dist/contracts/interest-oracle.js +0 -39
  18. package/dist/contracts/price-oracle.d.ts +0 -5
  19. package/dist/contracts/price-oracle.js +0 -18
  20. package/dist/contracts/treasury.d.ts +0 -9
  21. package/dist/contracts/treasury.js +0 -56
  22. package/dist/helpers/asset-helpers.d.ts +0 -11
  23. package/dist/helpers/asset-helpers.js +0 -23
  24. package/dist/helpers/cdp-helpers.d.ts +0 -5
  25. package/dist/helpers/cdp-helpers.js +0 -5
  26. package/dist/helpers/helpers.d.ts +0 -4
  27. package/dist/helpers/helpers.js +0 -14
  28. package/dist/helpers/lucid-utils.d.ts +0 -6
  29. package/dist/helpers/lucid-utils.js +0 -18
  30. package/dist/helpers/time-helpers.d.ts +0 -3
  31. package/dist/helpers/time-helpers.js +0 -3
  32. package/dist/scripts/cdp-creator-validator.d.ts +0 -6
  33. package/dist/scripts/cdp-creator-validator.js +0 -6
  34. package/dist/scripts/cdp-validator.d.ts +0 -6
  35. package/dist/scripts/cdp-validator.js +0 -6
  36. package/dist/scripts/collector-validator.d.ts +0 -6
  37. package/dist/scripts/collector-validator.js +0 -5
  38. package/dist/scripts/interest-oracle-validator.d.ts +0 -6
  39. package/dist/scripts/interest-oracle-validator.js +0 -5
  40. package/dist/scripts/treasury-validator.d.ts +0 -6
  41. package/dist/scripts/treasury-validator.js +0 -5
  42. package/dist/types/generic.d.ts +0 -10
  43. package/dist/types/generic.js +0 -1
  44. package/dist/types/indigo/cdp.d.ts +0 -37
  45. package/dist/types/indigo/cdp.js +0 -1
  46. package/dist/types/indigo/gov.d.ts +0 -20
  47. package/dist/types/indigo/gov.js +0 -1
  48. package/dist/types/indigo/interest-oracle.d.ts +0 -5
  49. package/dist/types/indigo/interest-oracle.js +0 -1
  50. package/dist/types/indigo/price-oracle.d.ts +0 -4
  51. package/dist/types/indigo/price-oracle.js +0 -1
  52. package/dist/types/system-params.d.ts +0 -217
  53. package/dist/types/system-params.js +0 -1
@@ -0,0 +1,43 @@
1
+ import { Blockfrost, Lucid, OutRef } from "@lucid-evolution/lucid";
2
+ import { balance, CDPContract, loadSystemParamsFromUrl } from "../src";
3
+
4
+ async function main() {
5
+ const lucid = await Lucid(
6
+ new Blockfrost(
7
+ 'https://cardano-mainnet.blockfrost.io/api/v0',
8
+ 'mainnetpb1Y1PczllObhmQKFMO6wm3la39p70k5'
9
+ ),
10
+ 'Mainnet'
11
+ );
12
+
13
+ lucid.selectWallet.fromSeed('helmet coconut robot path message library verb lobster rigid taxi recall ribbon vacuum uniform horse thumb praise sibling wise frown cattle settle century sad');
14
+
15
+ const systemParams = await loadSystemParamsFromUrl('https://config.indigoprotocol.io/mainnet/mainnet-system-params-v21.json')
16
+ const address = await lucid.wallet().address();
17
+ const utxos = await lucid.wallet().getUtxos();
18
+ const walletBalance = balance(utxos);
19
+
20
+ console.log('Wallet Address', address);
21
+ console.log('Wallet Balance', walletBalance);
22
+
23
+ // const cdpOutRef: OutRef = {txHash: '70b09ded453b6122688d3cd51e2c75a007f2d801d1104eae734d8f5314b2b393', outputIndex: 0};
24
+
25
+ const cdpTx = await CDPContract.openPosition('iUSD', 10_000_000n, 7_820_000n, systemParams, lucid);
26
+ const cdpBTx = await cdpTx.complete();
27
+ const cdpBsTx = await cdpBTx.sign.withWallet().complete();
28
+
29
+ console.log(cdpBsTx.toCBOR());
30
+ // const cdpTx = await CDPContract.openPosition(
31
+ // 'iUSD',
32
+ // 10_000_000n,
33
+ // 1_000_000n,
34
+ // systemParams,
35
+ // lucid
36
+ // );
37
+ // const cdpBTx = await cdpTx.complete()
38
+ // const cdpBsTx = await cdpBTx.sign.withWallet().complete()
39
+
40
+ // console.log(cdpBsTx.toCBOR());
41
+ }
42
+
43
+ main();
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
- "build": "tsc",
10
- "build-tsup": "tsup src/index.ts --format esm,cjs --dts --clean",
9
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
11
10
  "test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
12
11
  "lint": "eslint .",
13
12
  "lint:fix": "eslint . --fix",
@@ -136,7 +136,7 @@ export class CDPContract {
136
136
 
137
137
  const debtMintingFee = calculateFeeFromPercentage(
138
138
  BigInt(assetOut.datum.debtMintingFeePercentage.getOnChainInt),
139
- mintedAmount * oracleDatum.price,
139
+ (mintedAmount * oracleDatum.price) / 1_000_000n,
140
140
  );
141
141
 
142
142
  // Oracle timestamp - 20s (length of a slot)
@@ -432,7 +432,7 @@ export class CDPContract {
432
432
  if (mintAmount > 0) {
433
433
  fee += calculateFeeFromPercentage(
434
434
  iAsset.datum.debtMintingFeePercentage.getOnChainInt,
435
- mintAmount * od.price,
435
+ (mintAmount * od.price) / 1_000_000n,
436
436
  );
437
437
  }
438
438
 
@@ -1,9 +0,0 @@
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
- }
@@ -1,58 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }