@lpfinance/solana v2.1.4
Note: -
Installation
yarn add @lpfinance/solana
LP Finance Library
This is the LP Finance javascript library to interact with https://test.lp.finance.
Latest API documentation
configurations
Create a config-overrides.js file in root folder
const webpack = require("webpack");
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
crypto: false,
stream: false,
assert: false,
http: false,
https: false,
os: false,
url: false,
fs: false,
path: false,
buffer: false,
process: false,
util: false
});
config.resolve.fallback = fallback;
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
]);
return config;
};
after install and add script in package.json file
yarn add -D react-app-rewired
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
create a .env file and start project
GENERATE_SOURCEMAP=false
Basic usage
- First Create a wallet using private key to perform Transaction and get details.Private key should be in bytes.
import { useWallet } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
}
- Use
useCBSProtocolOverview
hook to get cbs system details.
import { useWallet, useCBSProtocolOverview } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const { netDeposit, netBorrow, cbsTVL, systemLTV } =
useCBSProtocolOverview(wallet);
}
- Use
useAuctionProtocolOverview
hook to get cbs system details.
import { useWallet, useAuctionProtocolOverview } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const { netDeposit ,auctionAPY, netLiquidatorFunds, lastEpochProfit } =
useAuctionProtocolOverview(wallet);
}
- get LiquidateList using
getLiquidateList
hook to get cbs system details.
import React, { useState, useEffect } from "react";
import { getLiquidateList } from "@lpfinance/solana";
const App = () => {
const [LiquidateList, setLiquidateList] = useState({
count: null,
List: [],
});
useEffect(() => {
const callLiquidate = async () => {
const { count, List } = await getLiquidateList();
setLiquidateList({ ...LiquidateList, count, List });
};
callLiquidate();
}, []);
}
- get CBS user account details using
useCBSUserAccount
hook.
import { useWallet, useCBSUserAccount } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const AccountDetails = useCBSUserAccount(wallet);
}
- get Auction user account details using
useAuctionUserAccount
hook.
import { useWallet, useAuctionUserAccount } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const AccountDetails = useAuctionUserAccount(wallet);
}
- Use CBS Transaction Functions -
a) Deposit - Use depositCBS function and TokenName should be "SOL", "lpUSD", "lpSOL", "lpBTC", "lpETH", "USDC", "BTC", "mSOL", "ETH", "UST", "SRM", "scnSOL", "stSOL", "USDT".
import { useWallet, depositCBS } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const SendTransaction = async() => {
const { message } = await depositCBS(wallet, amount, TokenName);
}
return (
<>
<button onClick={SendTransaction}>depositCBS</button>
</>
)
}
b) Borrow - Use borrowCBS function and TokenName should be "lpUSD", "lpSOL", "lpBTC", "lpETH".
import { useWallet, borrowCBS } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const SendTransaction = async() => {
const { message } = await borrowCBS(wallet, amount, TokenName);
}
return (
<>
<button onClick={SendTransaction}>borrowCBS</button>
</>
)
}
c) Withdraw - Use withdrawCBS function and TokenName should be "SOL", "lpUSD", "lpSOL", "lpBTC", "lpETH", "USDC", "BTC", "mSOL", "ETH", "UST", "SRM", "scnSOL", "stSOL", "USDT".
import { useWallet, withdrawCBS } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const SendTransaction = async() => {
const { message } = await withdrawCBS(wallet, amount, TokenName);
}
return (
<>
<button onClick={SendTransaction}>withdrawCBS</button>
</>
)
}
d) Repayment - Use repayCBS function and TokenName should be "SOL", "lpUSD", "lpSOL", "lpBTC", "lpETH", "USDC", "BTC", "ETH".
import { useWallet, repayCBS } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const SendTransaction = async() => {
const { message } = await repayCBS(wallet, amount, TokenName);
}
return (
<>
<button onClick={SendTransaction}>repayCBS</button>
</>
)
}
- Use Auction Transaction Functions -
a) Deposit - Use depositAuction function and "lpUSD" is default token to perform deposit.
import { useWallet, depositAuction } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const SendTransaction = async() => {
const { message } = await depositAuction(wallet, amount);
}
return (
<>
<button onClick={SendTransaction}>depositAuction</button>
</>
)
}
a) Withdraw - Use withdrawAuction function and "lpUSD" is default token to perform withdraw.
import { useWallet, withdrawAuction } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const SendTransaction = async() => {
const { message } = await withdrawAuction(wallet, amount);
}
return (
<>
<button onClick={SendTransaction}>withdrawAuction</button>
</>
)
}
- Liquidate - Use liquidateAccount function
import { useWallet, liquidateAccount } from "@lpfinance/solana";
const App = () => {
const { wallet } = useWallet(process.env.PRIVATE_KEY);
const liquidateAccountFun = async() => {
const { message } = await liquidateAccount( wallet, userKey, Debt, Collateral,
LTV, LiquidatorFunds, LastEpochProfit);
return (
<>
<button onClick={liquidateAccountFun}>liquidateAccount</button>
</>
)
}
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago