feat: add extra instructions

This commit is contained in:
bartosz-lipinski 2020-11-21 14:53:41 -06:00
parent 8e761239ea
commit 7324c3c67a
7 changed files with 144 additions and 3 deletions

View File

@ -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

View File

@ -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<any>(null);

View File

@ -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

View File

@ -3,6 +3,7 @@ export enum LendingInstruction {
InitReserve = 1,
DepositReserveLiquidity = 2,
WithdrawReserveLiquidity = 3,
BorrowReserveLiquidity = 4,
RepayReserveLiquidity = 5,
BorrowLiquidity = 4,
RepayOblogationLiquidity = 5,
LiquidateObligation = 6,
}

View File

@ -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,
});
};

View File

@ -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,
});
};

View File

@ -20,6 +20,7 @@ export const LendingReserveItem = (props: {
props.reserve.totalLiquidity.toNumber(),
liquidityMint
);
const totalBorrows = props.reserve.totalBorrows.toString();
console.log(liquidityMint);