Skip to content

Commit

Permalink
fix: api should match spl; add + update instruction docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaaash committed Mar 1, 2021
1 parent 489d840 commit 75966ec
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
29 changes: 16 additions & 13 deletions src/models/lending/borrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ export enum BorrowAmountType {
/// 1. `[writable]` Destination liquidity token account, minted by borrow reserve liquidity mint
/// 2. `[]` Deposit reserve account.
/// 3. `[writable]` Deposit reserve collateral supply SPL Token account
/// 4. `[writable]` Borrow reserve account.
/// 5. `[writable]` Borrow reserve liquidity supply SPL Token account
/// 6. `[writable]` Obligation
/// 7. `[writable]` Obligation token mint
/// 8. `[writable]` Obligation token output
/// 8 `[]` Lending market account.
/// 10 `[]` Derived lending market authority.
/// 11 `[]` User transfer authority ($authority).
/// 12 `[]` Dex market
/// 13 `[]` Dex market order book side
/// 14 `[]` Temporary memory
/// 15 `[]` Clock sysvar
/// 16 '[]` Token program id
/// 4. `[writable]` Deposit reserve collateral fee receiver account.
/// Must be the fee account specified at InitReserve.
/// 5. `[writable]` Borrow reserve account.
/// 6. `[writable]` Borrow reserve liquidity supply SPL Token account
/// 7. `[writable]` Obligation
/// 8. `[writable]` Obligation token mint
/// 9. `[writable]` Obligation token output
/// 10 `[]` Lending market account.
/// 11 `[]` Derived lending market authority.
/// 12 `[]` User transfer authority ($authority).
/// 13 `[]` Dex market
/// 14 `[]` Dex market order book side
/// 15 `[]` Temporary memory
/// 16 `[]` Clock sysvar
/// 17 '[]` Token program id
/// 18 `[optional, writable]` Deposit reserve collateral host fee receiver account.
export const borrowInstruction = (
amount: number | BN,
amountType: BorrowAmountType,
Expand Down
4 changes: 2 additions & 2 deletions src/models/lending/liquidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } from "../../utils/ids";
/// 0. `[writable]` Source liquidity token account, minted by repay reserve liquidity mint
/// $authority can transfer $collateral_amount
/// 1. `[writable]` Destination collateral token account, minted by withdraw reserve collateral mint
/// 2. `[]` Repay reserve account.
/// 2. `[writable]` Repay reserve account.
/// 3. `[writable]` Repay reserve liquidity supply SPL Token account
/// 4. `[writable]` Withdraw reserve account.
/// 4. `[]` Withdraw reserve account.
/// 5. `[writable]` Withdraw reserve collateral supply SPL Token account
/// 6. `[writable]` Obligation - initialized
/// 7. `[]` Lending market account.
Expand Down
9 changes: 7 additions & 2 deletions src/models/lending/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ export const LendingMarketParser = (
return details;
};

// TODO:
// create instructions for init
// TODO: create instructions for init
/// Initializes a new lending market.
///
/// 0. `[writable]` Lending market account.
/// 1. `[]` Quote currency SPL Token mint. Must be initialized.
/// 2. `[]` Rent sysvar
/// 3. '[]` Token program id
13 changes: 13 additions & 0 deletions src/models/lending/obligation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ export const healthFactorToRiskColor = (health: number) => {
return "";
};

/// Initializes a new loan obligation.
///
/// 0. `[]` Deposit reserve account.
/// 1. `[]` Borrow reserve account.
/// 2. `[writable]` Obligation
/// 3. `[writable]` Obligation token mint
/// 4. `[writable]` Obligation token output
/// 5. `[]` Obligation token owner
/// 6. `[]` Lending market account.
/// 7. `[]` Derived lending market authority.
/// 8. `[]` Clock sysvar
/// 9. `[]` Rent sysvar
/// 10 '[]` Token program id
export const initObligationInstruction = (
depositReserve: PublicKey,
borrowReserve: PublicKey,
Expand Down
25 changes: 25 additions & 0 deletions src/models/lending/reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ export const LendingReserveParser = (
return details;
};

/// Initializes a new lending market reserve.
///
/// 0. `[writable]` Source liquidity token account. $authority can transfer $liquidity_amount
/// 1. `[writable]` Destination collateral token account - uninitialized
/// 2. `[writable]` Reserve account.
/// 3. `[]` Reserve liquidity SPL Token mint
/// 4. `[writable]` Reserve liquidity supply SPL Token account - uninitialized
/// 5. `[writable]` Reserve collateral SPL Token mint - uninitialized
/// 6. `[writable]` Reserve collateral token supply - uninitialized
/// 7. `[writable]` Reserve collateral fees receiver - uninitialized.
/// Owner will be set to the lending market account.
/// 8. `[]` Lending market account.
/// 9. `[signer]` Lending market owner.
/// 10 `[]` Derived lending market authority.
/// 11 `[]` User transfer authority ($authority).
/// 12 `[]` Clock sysvar
/// 13 `[]` Rent sysvar
/// 14 '[]` Token program id
/// 15 `[optional]` Serum DEX market account. Not required for quote currency reserves.
/// Must be initialized and match quote and base currency.
export const initReserveInstruction = (
liquidityAmount: number | BN,
maxUtilizationRate: number,
Expand Down Expand Up @@ -207,6 +227,11 @@ export const initReserveInstruction = (
});
};

/// Accrue interest on reserves
///
/// 0. `[]` Clock sysvar
/// 1. `[writable]` Reserve account.
/// .. `[writable]` Additional reserve accounts.
export const accrueInterestInstruction = (
...reserveAccount: PublicKey[]
): TransactionInstruction => {
Expand Down
12 changes: 12 additions & 0 deletions src/models/lending/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } from "../../utils/ids";
import * as Layout from "./../../utils/layout";
import { LendingInstruction } from "./lending";

/// Withdraw tokens from a reserve. The input is a collateral token representing ownership
/// of the reserve liquidity pool.
///
/// 0. `[writable]` Source collateral token account. $authority can transfer $collateral_amount
/// 1. `[writable]` Destination liquidity token account.
/// 2. `[writable]` Reserve account.
/// 3. `[writable]` Reserve collateral SPL Token mint.
/// 4. `[writable]` Reserve liquidity supply SPL Token account.
/// 5. `[]` Lending market account.
/// 6. `[]` Derived lending market authority.
/// 7. `[]` User transfer authority ($authority).
/// 8. '[]` Token program id
export const withdrawInstruction = (
collateralAmount: number | BN,
from: PublicKey, // Collateral input SPL Token account. $authority can transfer $liquidity_amount
Expand Down

0 comments on commit 75966ec

Please sign in to comment.