diff --git a/README.md b/README.md index c2780eb..5ca1eff 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ ## ⚠️ Warning Any content produced by Solana, or developer resources that Solana provides, are for educational and inspiration purposes only. Solana does not encourage, induce or sanction the deployment of any such applications in violation of applicable laws or regulations. + + +## TODO + +- [] Calculate deposit APY and borrow APY for home page +- [] Finish Reserve overview page (chart, and borrows information) +- [] Create Dashboard page +- [] Deposit view calculate APY and health factor +- [] Format total Borrows +- [] Add repay view +- [] Add liquidate view +- [] Borrow view calculate available to you and borrow APY +- [] Facuet add USDC that is using sol airdrop and USDC reserve to give user USDC +- [] Borrow - Convert target ccy to collateral on oposite side \ No newline at end of file diff --git a/src/contexts/wallet.tsx b/src/contexts/wallet.tsx index c9065e2..5dbb321 100644 --- a/src/contexts/wallet.tsx +++ b/src/contexts/wallet.tsx @@ -9,6 +9,7 @@ export const WALLET_PROVIDERS = [ { name: "sollet.io", url: "https://www.sollet.io" }, { name: "solongwallet.com", url: "http://solongwallet.com" }, { name: "solflare.com", url: "https://solflare.com/access-wallet" }, + { name: "mathwallet.org", url: "https://www.mathwallet.org" }, ]; const WalletContext = React.createContext(null); diff --git a/src/models/lending/borrow.ts b/src/models/lending/borrow.ts index 2909a96..7b36a57 100644 --- a/src/models/lending/borrow.ts +++ b/src/models/lending/borrow.ts @@ -59,7 +59,7 @@ export const borrowInstruction = ( const data = Buffer.alloc(dataLayout.span); dataLayout.encode( { - instruction: LendingInstruction.BorrowReserveLiquidity, + instruction: LendingInstruction.BorrowLiquidity, collateralAmount: new BN(collateralAmount), }, data diff --git a/src/models/lending/lending.ts b/src/models/lending/lending.ts index 030bdf2..49c31ad 100644 --- a/src/models/lending/lending.ts +++ b/src/models/lending/lending.ts @@ -3,6 +3,7 @@ export enum LendingInstruction { InitReserve = 1, DepositReserveLiquidity = 2, WithdrawReserveLiquidity = 3, - BorrowReserveLiquidity = 4, - RepayReserveLiquidity = 5, + BorrowLiquidity = 4, + RepayOblogationLiquidity = 5, + LiquidateObligation = 6, } diff --git a/src/models/lending/liquidate.ts b/src/models/lending/liquidate.ts new file mode 100644 index 0000000..c7b6ef2 --- /dev/null +++ b/src/models/lending/liquidate.ts @@ -0,0 +1,62 @@ +import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from "@solana/web3.js"; +import BN from "bn.js"; +import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../../constants/ids"; +import { LendingInstruction } from "./lending"; +import * as BufferLayout from "buffer-layout"; +import * as Layout from "./../../utils/layout"; + +/// Purchase collateral tokens at a discount rate if the chosen obligation is unhealthy. +/// +/// 0. `[writable]` Liquidity input SPL Token account, $authority can transfer $liquidity_amount +/// 1. `[writable]` Collateral output SPL Token account +/// 2. `[writable]` Repay reserve account. +/// 3. `[writable]` Repay reserve liquidity supply SPL Token account +/// 4. `[writable]` Withdraw reserve account. +/// 5. `[writable]` Withdraw reserve collateral supply SPL Token account +/// 6. `[writable]` Obligation - initialized +/// 7. `[]` Derived lending market authority ($authority). +/// 8. `[]` Dex market +/// 9. `[]` Dex market orders +/// 10 `[]` Temporary memory +/// 11 `[]` Clock sysvar +/// 12 `[]` Token program id +export const liquidateInstruction = ( + liquidityAmount: number | BN, + from: PublicKey, // Collateral input SPL Token account. $authority can transfer $liquidity_amount + to: PublicKey, // Liquidity output SPL Token account, + reserveAccount: PublicKey, + collateralMint: PublicKey, + reserveSupply: PublicKey, + authority: PublicKey +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + Layout.uint64("liquidityAmount"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: LendingInstruction.RepayOblogationLiquidity, + collateralAmount: new BN(liquidityAmount), + }, + data + ); + + const keys = [ + { pubkey: from, isSigner: false, isWritable: true }, + { pubkey: to, isSigner: false, isWritable: true }, + { pubkey: reserveAccount, isSigner: false, isWritable: true }, + { pubkey: collateralMint, isSigner: false, isWritable: true }, + { pubkey: reserveSupply, isSigner: false, isWritable: true }, + + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, + ]; + return new TransactionInstruction({ + keys, + programId: LENDING_PROGRAM_ID, + data, + }); +}; \ No newline at end of file diff --git a/src/models/lending/repay.ts b/src/models/lending/repay.ts new file mode 100644 index 0000000..a744a12 --- /dev/null +++ b/src/models/lending/repay.ts @@ -0,0 +1,62 @@ +import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from "@solana/web3.js"; +import BN from "bn.js"; +import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../../constants/ids"; +import { LendingInstruction } from "./lending"; +import * as BufferLayout from "buffer-layout"; +import * as Layout from "./../../utils/layout"; + +/// Repay loaned tokens to a reserve and receive collateral tokens. The obligation balance +/// will be recalculated for interest. +/// +/// 0. `[writable]` Liquidity input SPL Token account, $authority can transfer $liquidity_amount +/// 1. `[writable]` Collateral output SPL Token account +/// 2. `[writable]` Repay reserve account. +/// 3. `[writable]` Repay reserve liquidity supply SPL Token account +/// 4. `[]` Withdraw reserve account. +/// 5. `[writable]` Withdraw reserve collateral supply SPL Token account +/// 6. `[writable]` Obligation - initialized +/// 7. `[writable]` Obligation token mint, $authority can transfer calculated amount +/// 8. `[writable]` Obligation token input +/// 9. `[]` Derived lending market authority ($authority). +/// 10 `[]` Clock sysvar +/// 11 `[]` Token program id +export const repayInstruction = ( + liquidityAmount: number | BN, + from: PublicKey, // Collateral input SPL Token account. $authority can transfer $liquidity_amount + to: PublicKey, // Liquidity output SPL Token account, + reserveAccount: PublicKey, + collateralMint: PublicKey, + reserveSupply: PublicKey, + authority: PublicKey +): TransactionInstruction => { + const dataLayout = BufferLayout.struct([ + BufferLayout.u8("instruction"), + Layout.uint64("liquidityAmount"), + ]); + + const data = Buffer.alloc(dataLayout.span); + dataLayout.encode( + { + instruction: LendingInstruction.RepayOblogationLiquidity, + collateralAmount: new BN(liquidityAmount), + }, + data + ); + + const keys = [ + { pubkey: from, isSigner: false, isWritable: true }, + { pubkey: to, isSigner: false, isWritable: true }, + { pubkey: reserveAccount, isSigner: false, isWritable: true }, + { pubkey: collateralMint, isSigner: false, isWritable: true }, + { pubkey: reserveSupply, isSigner: false, isWritable: true }, + + { pubkey: authority, isSigner: false, isWritable: false }, + { pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, + { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, + ]; + return new TransactionInstruction({ + keys, + programId: LENDING_PROGRAM_ID, + data, + }); +}; \ No newline at end of file diff --git a/src/views/home/item.tsx b/src/views/home/item.tsx index 1f319e7..590d4dc 100644 --- a/src/views/home/item.tsx +++ b/src/views/home/item.tsx @@ -20,6 +20,7 @@ export const LendingReserveItem = (props: { props.reserve.totalLiquidity.toNumber(), liquidityMint ); + const totalBorrows = props.reserve.totalBorrows.toString(); console.log(liquidityMint);