mirror of https://github.com/certusone/oyster.git
Merge pull request #35 from jstarry/bug-fixes
fix: typos, repay with wrapped sol, withdraw overpay
This commit is contained in:
commit
adf11ebda9
|
@ -28,7 +28,7 @@ export const liquidate = async (
|
||||||
withdrawReserve: ParsedAccount<LendingReserve>
|
withdrawReserve: ParsedAccount<LendingReserve>
|
||||||
) => {
|
) => {
|
||||||
notify({
|
notify({
|
||||||
message: 'Repaing funds...',
|
message: 'Repaying funds...',
|
||||||
description: 'Please review transactions to approve.',
|
description: 'Please review transactions to approve.',
|
||||||
type: 'warn',
|
type: 'warn',
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,15 +8,15 @@ import { sendTransaction } from "../contexts/connection";
|
||||||
import { notify } from "../utils/notifications";
|
import { notify } from "../utils/notifications";
|
||||||
import { LendingReserve } from "./../models/lending/reserve";
|
import { LendingReserve } from "./../models/lending/reserve";
|
||||||
import { repayInstruction } from "./../models/lending/repay";
|
import { repayInstruction } from "./../models/lending/repay";
|
||||||
import { AccountLayout } from "@solana/spl-token";
|
import { AccountLayout, Token, NATIVE_MINT } from "@solana/spl-token";
|
||||||
import { LENDING_PROGRAM_ID } from "../utils/ids";
|
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../utils/ids";
|
||||||
import { findOrCreateAccountByMint } from "./account";
|
import { createTokenAccount, findOrCreateAccountByMint } from "./account";
|
||||||
import { approve, LendingObligation, TokenAccount } from "../models";
|
import { approve, LendingObligation, TokenAccount } from "../models";
|
||||||
import { ParsedAccount } from "../contexts/accounts";
|
import { ParsedAccount } from "../contexts/accounts";
|
||||||
|
|
||||||
export const repay = async (
|
export const repay = async (
|
||||||
from: TokenAccount, // CollateralAccount
|
from: TokenAccount,
|
||||||
amountLamports: number, // in collateral token (lamports)
|
repayAmount: number,
|
||||||
|
|
||||||
// which loan to repay
|
// which loan to repay
|
||||||
obligation: ParsedAccount<LendingObligation>,
|
obligation: ParsedAccount<LendingObligation>,
|
||||||
|
@ -31,7 +31,7 @@ export const repay = async (
|
||||||
wallet: any
|
wallet: any
|
||||||
) => {
|
) => {
|
||||||
notify({
|
notify({
|
||||||
message: 'Repaing funds...',
|
message: 'Repaying funds...',
|
||||||
description: 'Please review transactions to approve.',
|
description: 'Please review transactions to approve.',
|
||||||
type: 'warn',
|
type: 'warn',
|
||||||
});
|
});
|
||||||
|
@ -48,7 +48,11 @@ export const repay = async (
|
||||||
LENDING_PROGRAM_ID
|
LENDING_PROGRAM_ID
|
||||||
);
|
);
|
||||||
|
|
||||||
const fromAccount = from.pubkey;
|
let fromAccount = from.pubkey;
|
||||||
|
if (wallet.publicKey.equals(fromAccount) && repayReserve.info.liquidityMint.equals(NATIVE_MINT)) {
|
||||||
|
fromAccount = createTokenAccount(instructions, wallet.publicKey, accountRentExempt + repayAmount, NATIVE_MINT, wallet.publicKey, signers);
|
||||||
|
cleanupInstructions.push(Token.createCloseAccountInstruction(TOKEN_PROGRAM_ID, fromAccount, wallet.publicKey, wallet.publicKey, []));
|
||||||
|
}
|
||||||
|
|
||||||
// create approval for transfer transactions
|
// create approval for transfer transactions
|
||||||
approve(
|
approve(
|
||||||
|
@ -57,7 +61,7 @@ export const repay = async (
|
||||||
fromAccount,
|
fromAccount,
|
||||||
authority,
|
authority,
|
||||||
wallet.publicKey,
|
wallet.publicKey,
|
||||||
amountLamports
|
repayAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
// get destination account
|
// get destination account
|
||||||
|
@ -85,7 +89,7 @@ export const repay = async (
|
||||||
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
repayInstruction(
|
repayInstruction(
|
||||||
amountLamports,
|
repayAmount,
|
||||||
fromAccount,
|
fromAccount,
|
||||||
toAccount,
|
toAccount,
|
||||||
repayReserve.pubkey,
|
repayReserve.pubkey,
|
||||||
|
|
|
@ -106,7 +106,7 @@ export const ReserveStatus = (props: {
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={6}>
|
<Col span={6}>
|
||||||
<Statistic
|
<Statistic
|
||||||
title={LABELS.LIQUIDATION_THREASHOLD}
|
title={LABELS.LIQUIDATION_THRESHOLD}
|
||||||
className="small-statisitc"
|
className="small-statisitc"
|
||||||
value={liquidationThreshold}
|
value={liquidationThreshold}
|
||||||
precision={2}
|
precision={2}
|
||||||
|
|
|
@ -22,7 +22,8 @@ export const ReserveUtilizationChart = (props: { reserve: LendingReserve }) => {
|
||||||
[props.reserve, liquidityMint]
|
[props.reserve, liquidityMint]
|
||||||
);
|
);
|
||||||
|
|
||||||
const percent = (availableLiquidity * 100) / (availableLiquidity + totalBorrows);
|
const totalSupply = availableLiquidity + totalBorrows;
|
||||||
|
const percent = 100 * totalBorrows / totalSupply;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WaterWave
|
<WaterWave
|
||||||
|
|
|
@ -59,14 +59,15 @@ export const WithdrawInput = (props: {
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await withdraw(
|
const withdrawAmount = Math.min(type === InputType.Percent
|
||||||
fromAccounts[0],
|
|
||||||
type === InputType.Percent
|
|
||||||
? (pct * collateralBalanceLamports) / 100
|
? (pct * collateralBalanceLamports) / 100
|
||||||
: Math.ceil(
|
: Math.ceil(
|
||||||
collateralBalanceLamports *
|
collateralBalanceLamports *
|
||||||
(parseFloat(value) / collateralBalanceInLiquidity)
|
(parseFloat(value) / collateralBalanceInLiquidity)
|
||||||
),
|
), collateralBalanceLamports);
|
||||||
|
await withdraw(
|
||||||
|
fromAccounts[0],
|
||||||
|
withdrawAmount,
|
||||||
reserve,
|
reserve,
|
||||||
address,
|
address,
|
||||||
connection,
|
connection,
|
||||||
|
|
|
@ -53,7 +53,7 @@ export const LABELS = {
|
||||||
TABLE_TITLE_MARKET_SIZE: "Market Size",
|
TABLE_TITLE_MARKET_SIZE: "Market Size",
|
||||||
TABLE_TITLE_ACTION: "Action",
|
TABLE_TITLE_ACTION: "Action",
|
||||||
MAX_LTV: "Maximum LTV",
|
MAX_LTV: "Maximum LTV",
|
||||||
LIQUIDATION_THREASHOLD: "Liquidation threashold",
|
LIQUIDATION_THRESHOLD: "Liquidation threshold",
|
||||||
LIQUIDATION_PENALTY: "Liquidation penalty",
|
LIQUIDATION_PENALTY: "Liquidation penalty",
|
||||||
TABLE_TITLE_MAX_BORROW: "Available for you",
|
TABLE_TITLE_MAX_BORROW: "Available for you",
|
||||||
DASHBOARD_TITLE_LOANS: "Loans",
|
DASHBOARD_TITLE_LOANS: "Loans",
|
||||||
|
|
Loading…
Reference in New Issue