Skip to content

IndigoProtocol/sdk

Repository files navigation

Indigo SDK

indigo-sdk is a TypeScript SDK designed to interact with Indigo endpoints for managing CDPs (Collateralized Debt Positions), Staking Positions, and Stability Pool Accounts by integrating the lucid-evolution library.

Installation

npm install @indigo-labs/indigo-sdk

Development

Prerequisites

  • Node.js 20 or newer (version in .nvmrc is the one used for development; pnpm run test:coverage relies on the V8 coverage provider and requires Node 20+)
  • pnpm package manager

Setup

  1. Clone this repository
  2. Install dependencies: pnpm install
  3. Build the project: pnpm run build

Available Scripts

  • pnpm run build - Build the project using tsup
  • pnpm run lint - Run ESLint to check code quality
  • pnpm run format - Format code using Prettier
  • pnpm run format:check - Check if code is properly formatted
  • pnpm run test - Run tests using Vitest
  • pnpm run test:coverage - Run tests with a V8 coverage report (coverage/; open coverage/index.html for the HTML report)

Code Quality

This project uses:

  • ESLint for code linting and quality checks
  • Prettier for code formatting
  • TypeScript for type safety

Running Tests

There are currently a few unit tests available for datums, hash checks, and interest calculations. Additionally, acceptance tests have been published for CDPs, Staking Positions, and Stability Pool accounts. These tests initialize the Indigo Protocol and positively test that the transaction building is working in an emulated Cardano Blockchain.

Instructions:

  1. Clone this repository
  2. Run pnpm install
  3. Run pnpm run test

For a coverage report (summary in the terminal, HTML under coverage/), run pnpm run test:coverage.

Transaction endpoints

The SDK exposes transaction builders (mostly async functions that return a Lucid TxBuilder, or attach to an existing builder). They are grouped below by on-chain contract module under src/contracts/.

CDP (cdp)

Function Summary
openCdp Open a new CDP: deposit collateral, mint iAsset, and wire creator, oracle, and treasury inputs.
depositCdp Add collateral to an existing CDP (settles interest via the interest collector as needed).
withdrawCdp Remove collateral, respecting collateral ratio using the price oracle when required.
mintCdp Mint additional iAsset debt against the CDP’s collateral.
burnCdp Burn iAsset to pay down debt.
closeCdp Close the CDP: settle interest, burn remaining debt, and return collateral.
redeemCdp Redeem iAsset for collateral through the CDP redemption flow (oracle-priced, with fees to treasury/collector as applicable).
freezeCdp Freeze a CDP that is below the redemption collateral ratio so it can be liquidated.
liquidateCdp Liquidate a frozen CDP via the stability pool: absorb debt, move collateral, and route fees.
mergeCdps Merge several CDPs for the same iAsset into a single combined position.

Collector (collector)

Function Summary
collectorFeeTx Attach a collector fee payment to an in-flight transaction; returns the collector ref script UTXO for further chaining.

Governance (gov)

Function Summary
createProposal Create a governance proposal, lock the poll deposit, and return the new poll id.
createShardsChunks Mint poll shard NFTs in chunks so voting can be split across shard UTxOs.
vote Vote yes/no on a poll shard using a staking position (updates vote tallies and staking locks).
mergeShards Burn shard NFTs and merge vote totals back into the poll manager.
endProposal End the poll: update governance state, burn the poll NFT, and either enqueue execution or refund the deposit.
executeProposal Execute a passed proposal (protocol changes, treasury actions, iAsset/collateral updates, etc.).

Stability pool (stability-pool)

Function Summary
createSpAccount Open a stability pool account and deposit iAsset for a given asset name.
adjustSpAccount Queue a deposit or withdrawal on an existing account (subject to pool rules).
closeSpAccount Queue closing the account and receiving outputs at your address.
processSpRequest Process a pending account request against the pool and iAsset state (including snapshots).
createE2s2sSnapshots Record new epoch–scale–sum snapshots on the pool for accounting and rewards.

Staking (staking)

Function Summary
openStakingPosition Stake INDY, update the staking manager, and mint a staking position NFT.
adjustStakingPosition Increase or decrease stake, update snapshots, and accrue ADA rewards.
closeStakingPosition Unstake, burn the position NFT, and return INDY plus accrued ADA rewards.
distributeAda Pull ADA from collector UTxOs into the staking manager’s reward snapshot.

Interest oracle (interest-oracle)

Function Summary
startInterestOracle Bootstrap an interest oracle UTxO (one-shot mint of the oracle NFT + initial datum).
feedInterestOracle Update the oracle’s interest rate and last-updated time (feeds unitary interest accrual for CDPs).

Interest collection (interest-collection)

Function Summary
batchCollectInterest Batch-settle accrued interest on many CDPs and credit the interest collector in one transaction.
collectInterestTx Append interest collection to an existing TxBuilder (pays iAsset interest into the collector).
distributeInterest Distribute funds held by interest collector UTxOs according to the interest admin multisig.
updatePermissions Update interest admin permissions, authorized via governance.

Treasury (treasury)

Function Summary
treasuryFeeTx Collect protocol fees into the treasury for a referenced action UTxO (augments an existing TxBuilder).
treasuryMerge Merge multiple treasury UTxOs into one.
treasurySplit Split one treasury UTxO into separate outputs per asset.
treasuryPrepareWithdrawal Prepare treasury UTxOs for a withdrawal flow tied to an upgrade reference.

ROB — redemption order book (rob)

Function Summary
openRob Create a buy-iAsset or sell-iAsset order with locked deposit on the ROB script.
cancelRob Cancel an open order and recover the deposit.
redeemRob Execute redemptions against ROB orders at the current oracle price.
adjustRob Add or remove deposit on an order, or re-lock after partial fills.
claimRob Claim proceeds from a filled or partially filled order (implemented as adjustRob with zero adjustment).

sdk

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors