diff --git a/README.md b/README.md index fea83b3..a7dcdca 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,9 @@ Any content produced by Solana, or developer resources that Solana provides, are - [] Facuet add USDC that is using sol airdrop and USDC reserve to give user USDC - [] Borrow - Convert target ccy to collateral on oposite side - [] Borrow - liquidity token wrapped SOL should be unwrapped ... -- [] Fix slider on repay page -- [] Add slider to borrow page (100% max collateral) -- [] Add market size on front page +- [x] Fix slider on repay page +- [x] Add slider to borrow page (100% max collateral) +- [x] Add market size on front page - [] Add github link - [] Repay from reserve (add selection for obligation/loan) - [] Add support for token names in URL in addition to reserve address - -# TOP for tomorrow - -- subscribe to all dex markets that are used by lending reserves -- finish reserve overivew diff --git a/src/App.less b/src/App.less index c56d258..1a1fdff 100644 --- a/src/App.less +++ b/src/App.less @@ -260,6 +260,10 @@ body { } } +.ant-slider { + margin: 20px 15px 40px 15px; +} + .token-input { display: flex; align-items: center; diff --git a/src/actions/deposit.tsx b/src/actions/deposit.tsx index 76e4290..672984d 100644 --- a/src/actions/deposit.tsx +++ b/src/actions/deposit.tsx @@ -28,9 +28,6 @@ export const deposit = async ( connection: Connection, wallet: any ) => { - // TODO: customize ? - const MAX_UTILIZATION_RATE = 80; - notify({ message: "Depositing funds...", description: "Please review transactions to approve.", @@ -110,6 +107,7 @@ export const deposit = async ( ); } else { // TODO: finish reserve init + const MAX_UTILIZATION_RATE = 80; instructions.push( initReserveInstruction( amountLamports, diff --git a/src/actions/repay.tsx b/src/actions/repay.tsx index ff4d4b8..e318eb7 100644 --- a/src/actions/repay.tsx +++ b/src/actions/repay.tsx @@ -109,22 +109,18 @@ export const repay = async ( authority ) ); + + let tx = await sendTransaction( + connection, + wallet, + instructions.concat(cleanupInstructions), + signers, + true + ); - try { - let tx = await sendTransaction( - connection, - wallet, - instructions.concat(cleanupInstructions), - signers, - true - ); - - notify({ - message: "Funds repaid.", - type: "success", - description: `Transaction - ${tx}`, - }); - } catch { - // TODO: - } + notify({ + message: "Funds repaid.", + type: "success", + description: `Transaction - ${tx}`, + }); }; diff --git a/src/components/BorrowInput/index.tsx b/src/components/BorrowInput/index.tsx index abbd3da..e6e2a10 100644 --- a/src/components/BorrowInput/index.tsx +++ b/src/components/BorrowInput/index.tsx @@ -10,7 +10,7 @@ import { LendingReserveParser, } from "../../models"; import { TokenIcon } from "../TokenIcon"; -import { Button, Card, Spin } from "antd"; +import { Button, Card } from "antd"; import { cache, ParsedAccount } from "../../contexts/accounts"; import { NumericInput } from "../Input/numeric"; import { useConnection } from "../../contexts/connection"; @@ -19,12 +19,9 @@ import { borrow } from "../../actions"; import { CollateralSelector } from "./../CollateralSelector"; import "./style.less"; import { LABELS } from "../../constants"; -import { LoadingOutlined } from "@ant-design/icons"; import { ActionConfirmation } from "./../ActionConfirmation"; import { BackButton } from "./../BackButton"; -const antIcon = ; - export const BorrowInput = (props: { className?: string; reserve: ParsedAccount; @@ -154,12 +151,10 @@ export const BorrowInput = (props: { diff --git a/src/components/DepositInput/index.tsx b/src/components/DepositInput/index.tsx index 334f76d..533d0e8 100644 --- a/src/components/DepositInput/index.tsx +++ b/src/components/DepositInput/index.tsx @@ -7,19 +7,16 @@ import { } from "../../hooks"; import { LendingReserve } from "../../models/lending"; import { TokenIcon } from "../TokenIcon"; -import { Button, Card, Slider, Spin } from "antd"; +import { Button, Card, Slider } from "antd"; import { NumericInput } from "../Input/numeric"; import { useConnection } from "../../contexts/connection"; import { useWallet } from "../../contexts/wallet"; import { deposit } from "../../actions/deposit"; import { PublicKey } from "@solana/web3.js"; import "./style.less"; -import { LoadingOutlined } from "@ant-design/icons"; import { ActionConfirmation } from "./../ActionConfirmation"; import { LABELS, marks } from "../../constants"; -const antIcon = ; - export const DepositInput = (props: { className?: string; reserve: LendingReserve; @@ -134,12 +131,10 @@ export const DepositInput = (props: { )} diff --git a/src/components/RepayInput/index.tsx b/src/components/RepayInput/index.tsx index a013af9..f9815c1 100644 --- a/src/components/RepayInput/index.tsx +++ b/src/components/RepayInput/index.tsx @@ -6,7 +6,7 @@ import { LendingReserveParser, } from "../../models"; import { TokenIcon } from "../TokenIcon"; -import { Button, Card, Slider, Spin } from "antd"; +import { Button, Card, Slider } from "antd"; import { cache, ParsedAccount, useMint } from "../../contexts/accounts"; import { NumericInput } from "../Input/numeric"; import { useConnection } from "../../contexts/connection"; @@ -15,15 +15,14 @@ import { repay } from "../../actions"; import { CollateralSelector } from "./../CollateralSelector"; import "./style.less"; import { LABELS, marks } from "../../constants"; -import { LoadingOutlined } from "@ant-design/icons"; import { ActionConfirmation } from "./../ActionConfirmation"; - -const antIcon = ; +import { fromLamports, wadToLamports } from "../../utils/utils"; +import { notify } from "../../utils/notifications"; export const RepayInput = (props: { className?: string; reserve: ParsedAccount; - obligation?: ParsedAccount; + obligation: ParsedAccount; }) => { const connection = useConnection(); const { wallet } = useWallet(); @@ -33,6 +32,14 @@ export const RepayInput = (props: { const repayReserve = props.reserve; const obligation = props.obligation; + const liquidityMint = useMint(repayReserve.info.liquidityMint); + + const borrowAmountLamports = wadToLamports(obligation.info.borrowAmountWad).toNumber(); + const borrowAmount = fromLamports( + borrowAmountLamports, + liquidityMint + ); + const [collateralReserveMint, setCollateralReserveMint] = useState(); const collateralReserve = useMemo(() => { @@ -49,20 +56,17 @@ export const RepayInput = (props: { repayReserve.info.liquidityMint ); - const repayLiquidityMint = useMint(repayReserve.info.liquidityMint); - // const collateralBalance = useUserBalance(reserve?.collateralMint); - const obligationAccount = useAccountByMint(obligation?.info.tokenMint); const convert = useCallback( (val: string | number) => { if (typeof val === "string") { - return (parseFloat(val) / balance) * 100; + return (parseFloat(val) / borrowAmount) * 100; } else { - return ((val * balance) / 100).toFixed(2); + return ((val * borrowAmount) / 100).toFixed(2); } }, - [balance] + [borrowAmount] ); const { value, setValue, mark, setMark, type } = useSliderInput(convert); @@ -81,11 +85,13 @@ export const RepayInput = (props: { (async () => { try { + const toRepayLamports = type === InputType.Slider + ? (mark * borrowAmountLamports) / 100 + : Math.ceil(borrowAmountLamports * (parseFloat(value) / borrowAmount)); + await repay( fromAccounts[0], - type === InputType.Slider - ? (mark * balanceLamports) / 100 - : Math.ceil(balanceLamports * (parseFloat(value) / balance)), + toRepayLamports, obligation, obligationAccount, repayReserve, @@ -96,8 +102,13 @@ export const RepayInput = (props: { setValue(""); setShowConfirmation(true); - } catch { - // TODO: + } catch (error) { + notify({ + message: "Unable to repay loan.", + type: "error", + description: error.message, + }); + } finally { setPendingTx(false); } @@ -105,7 +116,8 @@ export const RepayInput = (props: { }, [ mark, value, - balance, + borrowAmount, + borrowAmountLamports, balanceLamports, type, connection, @@ -171,12 +183,10 @@ export const RepayInput = (props: { )} diff --git a/src/components/WithdrawInput/index.tsx b/src/components/WithdrawInput/index.tsx index 77b93f4..f00c4a3 100644 --- a/src/components/WithdrawInput/index.tsx +++ b/src/components/WithdrawInput/index.tsx @@ -8,7 +8,7 @@ import { } from "../../hooks"; import { LendingReserve } from "../../models/lending"; import { TokenIcon } from "../TokenIcon"; -import { Button, Card, Slider, Spin } from "antd"; +import { Button, Card, Slider } from "antd"; import { NumericInput } from "../Input/numeric"; import { useConnection } from "../../contexts/connection"; import { useWallet } from "../../contexts/wallet"; @@ -16,11 +16,8 @@ import { withdraw } from "../../actions"; import { PublicKey } from "@solana/web3.js"; import "./style.less"; import { LABELS, marks } from "../../constants"; -import { LoadingOutlined } from "@ant-design/icons"; import { ActionConfirmation } from "./../ActionConfirmation"; -const antIcon = ; - export const WithdrawInput = (props: { className?: string; reserve: LendingReserve; @@ -140,12 +137,10 @@ export const WithdrawInput = (props: { )} diff --git a/src/views/repayReserve/index.tsx b/src/views/repayReserve/index.tsx index ffba62b..9d71346 100644 --- a/src/views/repayReserve/index.tsx +++ b/src/views/repayReserve/index.tsx @@ -22,9 +22,7 @@ export const RepayReserveView = () => { ); const reserve = lendingReserve?.info; - console.log([reserveId, obligationId]); - - if (!reserve || !lendingReserve) { + if (!reserve || !lendingReserve || !lendingObligation) { return null; }