diff --git a/.gitignore b/.gitignore
index bc1d547..bca192f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
node_modules
-.next
\ No newline at end of file
+.next
+.env
+.env.local
\ No newline at end of file
diff --git a/components/notification/index.js b/components/notification/index.js
index ef1c3d5..2460a35 100644
--- a/components/notification/index.js
+++ b/components/notification/index.js
@@ -1,13 +1,13 @@
-import styles from '../../styles/dapp.module.scss';
-import { useState, useEffect } from 'react';
-import { BsBell } from 'react-icons/bs';
-import { useSignMessage, useAccount } from 'wagmi';
-import { api } from '../../utils/addresses';
-import tooltip from '../../components/tooltip';
+import styles from "../../styles/dapp.module.scss";
+import { useState, useEffect } from "react";
+import { BsBell } from "react-icons/bs";
+import { useSignMessage, useAccount } from "wagmi";
+import { api } from "../../utils/addresses";
+import tooltip from "../../components/tooltip";
export default function Notification({ collateral }) {
const [showTelegramModal, setShowTelegramModal] = useState(false);
- const [registrationCode, setRegistrationCode] = useState('');
+ const [registrationCode, setRegistrationCode] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [alreadyRegistered, setAlreadyRegistered] = useState(false);
@@ -15,6 +15,22 @@ export default function Notification({ collateral }) {
const { address } = useAccount();
const handleTelegramSignup = () => {
+ // Validate that we have the necessary information
+ if (!collateral) {
+ tooltip.error({
+ content: "Collateral information is not available. Please try again.",
+ duration: 5000,
+ });
+ return;
+ }
+
+ if (!address) {
+ tooltip.error({
+ content: "Please connect your wallet first.",
+ duration: 5000,
+ });
+ return;
+ }
setShowTelegramModal(true);
};
@@ -30,25 +46,29 @@ export default function Notification({ collateral }) {
const getSubscription = async () => {
try {
- if (!address) return;
+ if (!address || !collateral) return;
setIsLoading(true);
+
const response = await fetch(`${api.bot}/subscription/${address}`, {
- method: 'GET',
+ method: "GET",
headers: {
- 'Content-Type': 'application/json',
+ "Content-Type": "application/json",
},
});
if (!response.ok) {
- throw new Error('Failed to register for notifications');
+ throw new Error("Failed to get subscription");
}
- const { data } = await response.json();
- console.log({ data, collateral });
- setAlreadyRegistered(
- data.find((item) => item.collateralName === collateral)
+ const responseData = await response.json();
+
+ const { data } = responseData;
+ const subscription = data.find(
+ (item) => item.collateralName === collateral
);
+ setAlreadyRegistered(!!subscription);
} catch (error) {
+ console.error("Error fetching subscription:", error);
setAlreadyRegistered(false);
} finally {
setIsLoading(false);
@@ -57,6 +77,23 @@ export default function Notification({ collateral }) {
const handleNotificationSetup = async () => {
try {
+ // Validate required fields
+ if (!address) {
+ tooltip.error({
+ content: "Please connect your wallet first.",
+ duration: 5000,
+ });
+ return;
+ }
+
+ if (!collateral) {
+ tooltip.error({
+ content: "Collateral information is not available. Please try again.",
+ duration: 5000,
+ });
+ return;
+ }
+
setIsLoading(true);
// Message to sign
@@ -67,9 +104,9 @@ export default function Notification({ collateral }) {
// Call API to register for notifications
const response = await fetch(`${api.bot}/registration/generate-code`, {
- method: 'POST',
+ method: "POST",
headers: {
- 'Content-Type': 'application/json',
+ "Content-Type": "application/json",
},
body: JSON.stringify({
walletAddress: address,
@@ -78,17 +115,24 @@ export default function Notification({ collateral }) {
}),
});
- if (!response.ok) {
- throw new Error('Failed to register for notifications');
+ if (response.status !== 200 && response.status !== 201) {
+ const errorText = await response.text();
+ console.error("Error response:", errorText);
+ throw new Error("Failed to register for notifications");
}
- const { registrationCode } = await response.json();
+ const data = await response.json();
+ console.log("Response data:", data);
+
+ const { registrationCode } = data;
setRegistrationCode(registrationCode);
+
// setShowModal(true);
} catch (error) {
- console.error('Error setting up notifications:', error);
+ console.error("Error setting up notifications:", error);
tooltip.error({
- content: 'Failed to setup notifications. Please try again.',
+ content:
+ error.message || "Failed to setup notifications. Please try again.",
duration: 5000,
});
} finally {
@@ -98,17 +142,19 @@ export default function Notification({ collateral }) {
return (
<>
-
-
-
-
Enable Telegram Notifications
+ {collateral && (
+
+
+
+
Enable Telegram Notifications
+
-
+ )}
{/* Modal */}
{showTelegramModal && (
@@ -131,7 +177,7 @@ export default function Notification({ collateral }) {
<>
Open our Telegram bot @BitProtocolBot
- Send the following code to the bot:{' '}
+ Send the following code to the bot:{" "}
{registrationCode}
The bot will confirm your registration
@@ -152,7 +198,7 @@ export default function Notification({ collateral }) {
{registrationCode ? (
handleNotificationSetup(false)}
>
- {isLoading ? 'Signing...' : 'Sign'}
+ {isLoading ? "Signing..." : "Sign"}
)}
diff --git a/hook/blockchain.js b/hook/blockchain.js
index 2f256d4..0525cad 100644
--- a/hook/blockchain.js
+++ b/hook/blockchain.js
@@ -4,44 +4,44 @@ import {
useEffect,
useMemo,
useCallback,
-} from 'react';
-import { ethers } from 'ethers';
+} from "react";
+import { ethers } from "ethers";
import {
useAccount,
usePublicClient,
useBalance,
useWalletClient,
useConnectorClient,
-} from 'wagmi';
-import { addresses, rpc } from '../utils/addresses';
-import { collateralNames } from '../utils/collateralNames';
-import TroveManagerGettersABI from '../abi/TroveManagerGetters';
-import TroveManagerABI from '../abi/TroveManager';
-import BorrowerOperationsABI from '../abi/BorrowerOperations';
-import FactoryABI from '../abi/Factory';
-import PriceFeedABI from '../abi/PriceFeed';
-import SortedTrovesABI from '../abi/SortedTroves';
-import DebtTokenABI from '../abi/DebtToken';
-import StabilityPoolABI from '../abi/StabilityPool';
-import BoostCalculatorABI from '../abi/BoostCalculator';
-import VaultABI from '../abi/Vault';
-import BitGovABI from '../abi/token';
-import TokenLockerABI from '../abi/tokenLocker';
-import IncentiveVotingABI from '../abi/IncentiveVoting';
-import BitLpTokenABI from '../abi/BitLpTokenPool';
-import MultiCollateralHintHelpersABI from '../abi/MultiCollateralHintHelpers';
-import BitLpOracleABI from '../abi/BitLpOracle';
-import TWAPOracleABI from '../abi/TWAPOracle';
-import { fromBigNumber, convertInterestRate } from '../utils/helpers';
-import { useSignatureCheck } from './useSignatureCheck';
-import BigNumber from 'bignumber.js';
-import * as sapphire from '@oasisprotocol/sapphire-paratime';
+} from "wagmi";
+import { addresses, rpc } from "../utils/addresses";
+import { collateralNames } from "../utils/collateralNames";
+import TroveManagerGettersABI from "../abi/TroveManagerGetters";
+import TroveManagerABI from "../abi/TroveManager";
+import BorrowerOperationsABI from "../abi/BorrowerOperations";
+import FactoryABI from "../abi/Factory";
+import PriceFeedABI from "../abi/PriceFeed";
+import SortedTrovesABI from "../abi/SortedTroves";
+import DebtTokenABI from "../abi/DebtToken";
+import StabilityPoolABI from "../abi/StabilityPool";
+import BoostCalculatorABI from "../abi/BoostCalculator";
+import VaultABI from "../abi/Vault";
+import BitGovABI from "../abi/token";
+import TokenLockerABI from "../abi/tokenLocker";
+import IncentiveVotingABI from "../abi/IncentiveVoting";
+import BitLpTokenABI from "../abi/BitLpTokenPool";
+import MultiCollateralHintHelpersABI from "../abi/MultiCollateralHintHelpers";
+import BitLpOracleABI from "../abi/BitLpOracle";
+import TWAPOracleABI from "../abi/TWAPOracle";
+import { fromBigNumber } from "../utils/helpers";
+import { useSignatureCheck } from "./useSignatureCheck";
+import BigNumber from "bignumber.js";
+import * as sapphire from "@oasisprotocol/sapphire-paratime";
export const BlockchainContext = createContext({
// STATES
deposits: 0.0,
debt: 0.0,
- troveStatus: '',
+ troveStatus: "",
balance: 0,
collaterals: {},
systemTVL: 0,
@@ -129,7 +129,7 @@ export const BlockchainContextProvider = ({ children }) => {
// STATES
const [deposits, setDeposits] = useState(0.0);
const [debt, setDebt] = useState(0.0);
- const [troveStatus, setTroveStatus] = useState('');
+ const [troveStatus, setTroveStatus] = useState("");
const [balance, setBalance] = useState(0);
const [collaterals, setCollaterals] = useState({});
const [userTroves, setUserTroves] = useState({});
@@ -151,8 +151,8 @@ export const BlockchainContextProvider = ({ children }) => {
const [totalSystemDebt, setTotalSystemDebt] = useState(0);
const [currentState, setCurrentState] = useState(false);
const [currentWaitInfo, setCurrentWaitInfo] = useState({
- type: '',
- info: '',
+ type: "",
+ info: "",
});
const [systemWeek, setWeek] = useState(0);
// GET DATA LOCK TO AVOID TOO MANY CALLS
@@ -317,7 +317,7 @@ export const BlockchainContextProvider = ({ children }) => {
const tx = await vault.batchClaimRewards(
account.address,
- '0x0000000000000000000000000000000000000000',
+ "0x0000000000000000000000000000000000000000",
[
addresses.troveManager[account.chainId],
addresses.stabilityPool[account.chainId],
@@ -429,34 +429,18 @@ export const BlockchainContextProvider = ({ children }) => {
const approve = async (collateralAddr, collAmount) => {
try {
const args = [addresses.borrowerOps[account.chainId], collAmount];
+ const tx = await walletClient.writeContract({
+ account: account.address,
+ abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
+ functionName: "approve",
+ address: collateralAddr,
+ args,
+ gas: await publicClient.estimateGas(args),
+ });
- // Check if walletClient is available
- if (walletClient) {
- const tx = await walletClient.writeContract({
- account: account.address,
- abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
- functionName: 'approve',
- address: collateralAddr,
- args,
- gas: '3000000', // await publicClient.estimateGas(args),
- });
- return tx;
- } else {
- // Fallback to ethers.js if walletClient is not available
- const tokenContract = new ethers.Contract(
- collateralAddr,
- BitGovABI, // JUST TO USE THE ERC20 INTERFACE
- sapphire.wrap(signer)
- );
-
- const tx = await tokenContract.approve(
- addresses.borrowerOps[account.chainId],
- collAmount
- );
- return tx.hash;
- }
+ return tx;
} catch (error) {
- console.log('approve error: ', error);
+ console.log("approve error: ", error);
throw error;
}
};
@@ -670,7 +654,7 @@ export const BlockchainContextProvider = ({ children }) => {
// QUERY FUNCTIONS
const getData = useCallback(async () => {
- if (typeof window === 'undefined') return;
+ if (typeof window === "undefined") return;
const signatures = await getSignatures();
@@ -693,7 +677,7 @@ export const BlockchainContextProvider = ({ children }) => {
}
} catch (error) {
console.log(
- 'Failed to get balance through alternative method',
+ "Failed to get balance through alternative method",
error
);
}
@@ -735,7 +719,7 @@ export const BlockchainContextProvider = ({ children }) => {
truncatedDebtAmount: new BigNumber(hints[2]._hex).toFixed(),
};
} catch (error) {
- console.log('error', error);
+ console.log("error", error);
throw error;
}
};
@@ -744,37 +728,37 @@ export const BlockchainContextProvider = ({ children }) => {
const balanceLp = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitUsdLp[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [account.address],
});
const allowanceLp = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitUsdLp[account.chainId],
- functionName: 'allowance',
+ functionName: "allowance",
args: [account.address, addresses.bitUsdDeposit[account.chainId]],
});
const deposiitBalance = await publicClient.readContract({
abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitUsdDeposit[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [account.address],
});
const depositLpBalance = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitUsdLp[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [addresses.bitUsdDeposit[account.chainId]],
});
const rewardRate = await publicClient.readContract({
abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitUsdDeposit[account.chainId],
- functionName: 'rewardRate',
+ functionName: "rewardRate",
args: [],
});
const totalSupply = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitUsdDeposit[account.chainId],
- functionName: 'totalSupply',
+ functionName: "totalSupply",
args: [],
});
@@ -792,31 +776,31 @@ export const BlockchainContextProvider = ({ children }) => {
const balanceLp = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitGovLp[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [account.address],
});
const allowanceLp = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitGovLp[account.chainId],
- functionName: 'allowance',
+ functionName: "allowance",
args: [account.address, addresses.bitGovDeposit[account.chainId]],
});
const depositBalance = await publicClient.readContract({
abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitGovDeposit[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [account.address],
});
const depositLpBalance = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitGovLp[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [addresses.bitGovDeposit[account.chainId]],
});
const rewardRate = await publicClient.readContract({
abi: BitLpTokenABI, // JUST TO USE THE ERC20 INTERFACE
address: addresses.bitGovDeposit[account.chainId],
- functionName: 'rewardRate',
+ functionName: "rewardRate",
args: [],
});
@@ -833,7 +817,7 @@ export const BlockchainContextProvider = ({ children }) => {
const weight = await publicClient.readContract({
abi: IncentiveVotingABI,
address: addresses.incentiveVoting[account.chainId],
- functionName: 'getReceiverWeightAt',
+ functionName: "getReceiverWeightAt",
args: [receiver, week],
});
@@ -844,7 +828,7 @@ export const BlockchainContextProvider = ({ children }) => {
const currentWeeklyEmissions = await publicClient.readContract({
abi: VaultABI,
address: addresses.vault[account.chainId],
- functionName: 'weeklyEmissions',
+ functionName: "weeklyEmissions",
args: [week],
});
return Number(currentWeeklyEmissions);
@@ -854,7 +838,7 @@ export const BlockchainContextProvider = ({ children }) => {
const weight = await publicClient.readContract({
abi: IncentiveVotingABI,
address: addresses.incentiveVoting[account.chainId],
- functionName: 'getTotalWeightAt',
+ functionName: "getTotalWeightAt",
args: [week],
});
return Number(weight);
@@ -864,7 +848,7 @@ export const BlockchainContextProvider = ({ children }) => {
const votes = await publicClient.readContract({
abi: IncentiveVotingABI,
address: addresses.incentiveVoting[account.chainId],
- functionName: 'getAccountCurrentVotes',
+ functionName: "getAccountCurrentVotes",
args: [account.address],
});
return votes;
@@ -874,19 +858,19 @@ export const BlockchainContextProvider = ({ children }) => {
const tcr = await publicClient.readContract({
abi: BorrowerOperationsABI,
address: addresses.borrowerOps[account.chainId],
- functionName: 'getTCR',
+ functionName: "getTCR",
args: [],
});
const systemBalances = await publicClient.readContract({
abi: BorrowerOperationsABI,
address: addresses.borrowerOps[account.chainId],
- functionName: 'getGlobalSystemBalances',
+ functionName: "getGlobalSystemBalances",
args: [],
});
const getWeek = await publicClient.readContract({
abi: VaultABI,
address: addresses.vault[account.chainId],
- functionName: 'getWeek',
+ functionName: "getWeek",
args: [],
});
@@ -903,11 +887,11 @@ export const BlockchainContextProvider = ({ children }) => {
const vault = await publicClient.readContract({
abi: VaultABI,
address: addresses.vault[account.chainId],
- functionName: 'claimableRewardAfterBoost',
+ functionName: "claimableRewardAfterBoost",
args: [
account.address,
account.address,
- '0x0000000000000000000000000000000000000000',
+ "0x0000000000000000000000000000000000000000",
trove,
],
});
@@ -918,22 +902,22 @@ export const BlockchainContextProvider = ({ children }) => {
const bitGovPool = await publicClient.readContract({
abi: VaultABI,
address: addresses.vault[account.chainId],
- functionName: 'claimableRewardAfterBoost',
+ functionName: "claimableRewardAfterBoost",
args: [
account.address,
account.address,
- '0x0000000000000000000000000000000000000000',
+ "0x0000000000000000000000000000000000000000",
addresses.bitGovDeposit[account.chainId],
],
});
const bitUsdPool = await publicClient.readContract({
abi: VaultABI,
address: addresses.vault[account.chainId],
- functionName: 'claimableRewardAfterBoost',
+ functionName: "claimableRewardAfterBoost",
args: [
account.address,
account.address,
- '0x0000000000000000000000000000000000000000',
+ "0x0000000000000000000000000000000000000000",
addresses.bitUsdDeposit[account.chainId],
],
});
@@ -949,19 +933,19 @@ export const BlockchainContextProvider = ({ children }) => {
const deposits = await publicClient.readContract({
abi: StabilityPoolABI,
address: addresses.stabilityPool[account.chainId],
- functionName: 'getTotalDebtTokenDeposits',
+ functionName: "getTotalDebtTokenDeposits",
args: [],
});
const rewardRate = await publicClient.readContract({
abi: StabilityPoolABI,
address: addresses.stabilityPool[account.chainId],
- functionName: 'rewardRate',
+ functionName: "rewardRate",
args: [],
});
const accountDeposits = await publicClient.readContract({
abi: StabilityPoolABI,
address: addresses.stabilityPool[account.chainId],
- functionName: 'accountDeposits',
+ functionName: "accountDeposits",
args: [account.address],
});
// COMMENTED OUT UNLESS WE HAVE REWARDS
@@ -980,7 +964,7 @@ export const BlockchainContextProvider = ({ children }) => {
const collateralGainsByDepositor = await publicClient.readContract({
abi: StabilityPoolABI,
address: addresses.stabilityPool[account.chainId],
- functionName: 'getDepositorCollateralGain',
+ functionName: "getDepositorCollateralGain",
args: [account.address],
});
@@ -1000,7 +984,7 @@ export const BlockchainContextProvider = ({ children }) => {
const balance = await publicClient.readContract({
abi: DebtTokenABI,
address: addresses.debtToken[account.chainId],
- functionName: 'checkBalanceOf',
+ functionName: "checkBalanceOf",
args: [dataDebt],
});
setBitUSDBalance(fromBigNumber(balance));
@@ -1010,7 +994,7 @@ export const BlockchainContextProvider = ({ children }) => {
const balance = await publicClient.readContract({
abi: BitGovABI,
address: addresses.bitGov[account.chainId],
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [account.address],
});
setBitGovBalance(fromBigNumber(balance));
@@ -1020,7 +1004,7 @@ export const BlockchainContextProvider = ({ children }) => {
const balance = await publicClient.readContract({
abi: BitGovABI, // JUST TO USE THE ERC20 INTERFACE
address,
- functionName: 'balanceOf',
+ functionName: "balanceOf",
args: [account.address],
});
@@ -1034,7 +1018,7 @@ export const BlockchainContextProvider = ({ children }) => {
const weight = await publicClient.readContract({
abi: TokenLockerABI,
address: addresses.tokenLocker[account.chainId],
- functionName: 'getAccountWeight',
+ functionName: "getAccountWeight",
args: [account.address],
});
setAccountWeight(Number(weight));
@@ -1044,7 +1028,7 @@ export const BlockchainContextProvider = ({ children }) => {
const balance = await publicClient.readContract({
abi: TokenLockerABI,
address: addresses.tokenLocker[account.chainId],
- functionName: 'getAccountBalances',
+ functionName: "getAccountBalances",
args: [account.address],
});
setAccountLockAmount(Number(balance[0]));
@@ -1055,7 +1039,7 @@ export const BlockchainContextProvider = ({ children }) => {
const locks = await publicClient.readContract({
abi: TokenLockerABI,
address: addresses.tokenLocker[account.chainId],
- functionName: 'getAccountActiveLocks',
+ functionName: "getAccountActiveLocks",
args: [account.address, 26],
});
@@ -1072,7 +1056,7 @@ export const BlockchainContextProvider = ({ children }) => {
const weight = await publicClient.readContract({
abi: TokenLockerABI,
address: addresses.tokenLocker[account.chainId],
- functionName: 'getTotalWeight',
+ functionName: "getTotalWeight",
args: [],
});
setTotalWeight(Number(weight));
@@ -1082,7 +1066,7 @@ export const BlockchainContextProvider = ({ children }) => {
const amounts = await publicClient.readContract({
abi: TokenLockerABI,
address: addresses.tokenLocker[account.chainId],
- functionName: 'getWithdrawWithPenaltyAmounts',
+ functionName: "getWithdrawWithPenaltyAmounts",
args: [account.address, value],
});
@@ -1096,7 +1080,7 @@ export const BlockchainContextProvider = ({ children }) => {
const circulation = await publicClient.readContract({
abi: DebtTokenABI,
address: addresses.debtToken[account.chainId],
- functionName: 'totalSupply',
+ functionName: "totalSupply",
args: [],
});
setBitUSDCirculation(fromBigNumber(circulation));
@@ -1106,7 +1090,7 @@ export const BlockchainContextProvider = ({ children }) => {
const prev = await publicClient.readContract({
abi: SortedTrovesABI,
address: sortedTroves,
- functionName: 'getPrev',
+ functionName: "getPrev",
args: [id],
});
return prev;
@@ -1116,7 +1100,7 @@ export const BlockchainContextProvider = ({ children }) => {
const next = await publicClient.readContract({
abi: SortedTrovesABI,
address: sortedTroves,
- functionName: 'getNext',
+ functionName: "getNext",
args: [id],
});
return next;
@@ -1128,7 +1112,7 @@ export const BlockchainContextProvider = ({ children }) => {
const trove = await publicClient.readContract({
abi: TroveManagerABI,
address: troveManagerAddr,
- functionName: 'getTrove',
+ functionName: "getTrove",
args: [account.address],
});
@@ -1145,7 +1129,7 @@ export const BlockchainContextProvider = ({ children }) => {
const trove = await publicClient.readContract({
abi: TroveManagerGettersABI,
address: addresses.troveManagerGetter[account.chainId],
- functionName: 'getTrove',
+ functionName: "getTrove",
args: [dataTrove, troveManagerAddr],
});
@@ -1173,7 +1157,7 @@ export const BlockchainContextProvider = ({ children }) => {
const count = await publicClient.readContract({
abi: FactoryABI,
address: addresses.factory[account.chainId],
- functionName: 'troveManagerCount',
+ functionName: "troveManagerCount",
args: [],
});
@@ -1181,87 +1165,81 @@ export const BlockchainContextProvider = ({ children }) => {
const address = await publicClient.readContract({
abi: FactoryABI,
address: addresses.factory[account.chainId],
- functionName: 'troveManagers',
+ functionName: "troveManagers",
args: [index],
});
const systemBalances = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'getEntireSystemBalances',
+ functionName: "getEntireSystemBalances",
args: [],
});
const redemptionRate = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'getRedemptionRate',
+ functionName: "getRedemptionRate",
args: [],
});
const borrowingRate = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'getBorrowingRate',
+ functionName: "getBorrowingRate",
args: [],
});
const mcr = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'MCR',
+ functionName: "MCR",
args: [],
});
const collateral = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'collateralToken',
+ functionName: "collateralToken",
args: [],
});
const maxSystemDebt = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'maxSystemDebt',
+ functionName: "maxSystemDebt",
args: [],
});
const rewardRate = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'rewardRate',
+ functionName: "rewardRate",
args: [],
});
const deploymentTime = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'systemDeploymentTime',
+ functionName: "systemDeploymentTime",
args: [],
});
const BOOTSTRAP_PERIOD = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'BOOTSTRAP_PERIOD',
+ functionName: "BOOTSTRAP_PERIOD",
args: [],
});
const redemptionFeeFloor = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'redemptionFeeFloor',
+ functionName: "redemptionFeeFloor",
args: [],
});
const baseRate = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'baseRate',
- args: [],
- });
- const interestRate = await publicClient.readContract({
- abi: TroveManagerABI,
- address: address,
- functionName: 'interestRate',
+ functionName: "baseRate",
args: [],
});
const sortedTroves = await publicClient.readContract({
abi: TroveManagerABI,
address: address,
- functionName: 'sortedTroves',
+ functionName: "sortedTroves",
args: [],
});
@@ -1283,7 +1261,7 @@ export const BlockchainContextProvider = ({ children }) => {
...collateralNames[collateral],
address: collateral,
payable:
- collateral === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
+ collateral === "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
},
sortedTroves,
interestRate: convertInterestRate(interestRate),
@@ -1310,7 +1288,7 @@ export const BlockchainContextProvider = ({ children }) => {
const price = await publicClient.readContract({
abi: PriceFeedABI,
address: addresses.priceFeed[account.chainId],
- functionName: 'loadPrice',
+ functionName: "loadPrice",
args: [collateral],
});
return fromBigNumber(price);
@@ -1320,7 +1298,7 @@ export const BlockchainContextProvider = ({ children }) => {
const boost = await publicClient.readContract({
abi: BoostCalculatorABI,
address: addresses.boostCalculator[account.chainId],
- functionName: 'getBoostedAmount',
+ functionName: "getBoostedAmount",
args: [account.address, 10000, 0, 100000],
});
@@ -1333,14 +1311,14 @@ export const BlockchainContextProvider = ({ children }) => {
const getLpTokenPrice = async (lpName) => {
const lpAddress =
- lpName === 'bitGov'
+ lpName === "bitGov"
? addresses.bitGovLpOracle[account.chainId]
: addresses.bitUsdLpOracle[account.chainId];
const price = await publicClient.readContract({
abi: BitLpOracleABI,
address: lpAddress,
- functionName: 'getLPPrice',
+ functionName: "getLPPrice",
args: [],
});
@@ -1351,7 +1329,7 @@ export const BlockchainContextProvider = ({ children }) => {
const price = await publicClient.readContract({
abi: TWAPOracleABI,
address: addresses.bitGovTWAP[account.chainId],
- functionName: 'consult',
+ functionName: "consult",
args: [addresses.bitGov[account.chainId], new BigNumber(1e18).toFixed()],
});
@@ -1365,7 +1343,7 @@ export const BlockchainContextProvider = ({ children }) => {
const borrowingFee = await publicClient.readContract({
abi: TroveManagerABI,
address: troveAddr,
- functionName: 'getBorrowingFee',
+ functionName: "getBorrowingFee",
args: [debt],
});
@@ -1373,7 +1351,7 @@ export const BlockchainContextProvider = ({ children }) => {
const maxFee = (fromBigNumber(borrowingFee) / fromBigNumber(debt)) * 1.2;
return ethers.utils
- .parseEther(maxFee.toString().replace(/,/g, ''))
+ .parseEther(maxFee.toString().replace(/,/g, ""))
.toString();
};
@@ -1381,7 +1359,7 @@ export const BlockchainContextProvider = ({ children }) => {
const surplus = await publicClient.readContract({
abi: TroveManagerABI,
address: troveManager,
- functionName: 'surplusBalances',
+ functionName: "surplusBalances",
args: [account.address],
});
diff --git a/next.config.js b/next.config.js
index bd3c7d9..599c099 100644
--- a/next.config.js
+++ b/next.config.js
@@ -2,15 +2,23 @@
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
- async redirects() {
- return [
- {
- source: "/",
- destination: "/Vault",
- permanent: false,
- },
- ];
+ async rewrites() {
+ const isPreview = process.env.VERCEL_ENV === "preview";
+ const isDevelopment = process.env.NODE_ENV === "development";
+
+ if (isDevelopment || isPreview) {
+ return [
+ {
+ source: "/api/bot/:path*",
+ destination: `${
+ process.env.BACKEND_API_URL || "https://api.bitusd.finance/v1"
+ }/:path*`,
+ },
+ ];
+ }
+ return [];
},
};
module.exports = nextConfig;
+module.exports = nextConfig;
diff --git a/utils/addresses.js b/utils/addresses.js
index cf95e97..a96afac 100644
--- a/utils/addresses.js
+++ b/utils/addresses.js
@@ -1,118 +1,121 @@
export const addresses = {
troveManager: {
- [23294]: '0xC91EDf48269D0373c17718F6D281D34908a5700d',
- [23295]: '', // ...
- [19236265]: '',
+ [23294]: "0xC91EDf48269D0373c17718F6D281D34908a5700d",
+ [23295]: "", // ...
+ [19236265]: "",
},
troveManagerGetter: {
- [23294]: '0x674487D9b51E9d14778f260e0B259fF9d61bB361',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x674487D9b51E9d14778f260e0B259fF9d61bB361",
+ [23295]: "",
+ [19236265]: "",
},
factory: {
- [23294]: '0xD58b7e6aC330a4bB7DA02AC626aaC527B0c8c6Cc',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0xD58b7e6aC330a4bB7DA02AC626aaC527B0c8c6Cc",
+ [23295]: "",
+ [19236265]: "",
},
priceFeed: {
- [23294]: '0xd35c6AAA15F04C29E09635FB08f26C288ccE87Dd',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0xd35c6AAA15F04C29E09635FB08f26C288ccE87Dd",
+ [23295]: "",
+ [19236265]: "",
},
borrowerOps: {
- [23294]: '0x9be6f065aFC34ca99e82af0f0BfB9a01E3f919eE',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x9be6f065aFC34ca99e82af0f0BfB9a01E3f919eE",
+ [23295]: "",
+ [19236265]: "",
},
debtToken: {
- [23294]: '0xA14167756d9F86Aed12b472C29B257BBdD9974C2',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0xA14167756d9F86Aed12b472C29B257BBdD9974C2",
+ [23295]: "",
+ [19236265]: "",
},
stabilityPool: {
- [23294]: '0x5aa111d889E9C6e3cca8A86430665b5CE7DfcdFf',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x5aa111d889E9C6e3cca8A86430665b5CE7DfcdFf",
+ [23295]: "",
+ [19236265]: "",
},
vault: {
- [23294]: '0x6D4b43f6378d0b74EE8BF2F88630103518E0af30',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x6D4b43f6378d0b74EE8BF2F88630103518E0af30",
+ [23295]: "",
+ [19236265]: "",
},
boostCalculator: {
- [23294]: '',
- [23295]: '0xc340f4fDb60F18BB5F7e736E848Eb38849d62b4F',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0xc340f4fDb60F18BB5F7e736E848Eb38849d62b4F",
+ [19236265]: "",
},
bitGov: {
- [23294]: '0x94E4b9C5B544EdD825F62fBE094E90C7Cc363B91',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x94E4b9C5B544EdD825F62fBE094E90C7Cc363B91",
+ [23295]: "",
+ [19236265]: "",
},
tokenLocker: {
- [23294]: '0x32F50d6662fbe972713ac39DBA98C0C526017f2C',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x32F50d6662fbe972713ac39DBA98C0C526017f2C",
+ [23295]: "",
+ [19236265]: "",
},
incentiveVoting: {
- [23294]: '0x8aC0f9Ad26a36C76d78899b42E6aBd0d805A46A6',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0x8aC0f9Ad26a36C76d78899b42E6aBd0d805A46A6",
+ [23295]: "",
+ [19236265]: "",
},
bitGovLp: {
- [23294]: '',
- [23295]: '0x15F2b1Dc4c427A8a022ba1Bb457fcbb1172E1855',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0x15F2b1Dc4c427A8a022ba1Bb457fcbb1172E1855",
+ [19236265]: "",
},
bitGovDeposit: {
- [23294]: '',
- [23295]: '0x2719Adf8D2D03fBE0Cc7506AAc33b213538c5112',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0x2719Adf8D2D03fBE0Cc7506AAc33b213538c5112",
+ [19236265]: "",
},
bitUsdLp: {
- [23294]: '',
- [23295]: '0xC682Eb99486ACDD5a896bda6bD3198FE26f78Bb6',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0xC682Eb99486ACDD5a896bda6bD3198FE26f78Bb6",
+ [19236265]: "",
},
bitUsdDeposit: {
- [23294]: '',
- [23295]: '0x4dcd40e74504aAd595A308a33bd73DB39B55815b',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0x4dcd40e74504aAd595A308a33bd73DB39B55815b",
+ [19236265]: "",
},
multiCollateralHintHelpers: {
- [23294]: '0xA0576AD90c960faf8a52B8D5647BF88A30fbc8e1',
- [23295]: '',
- [19236265]: '',
+ [23294]: "0xA0576AD90c960faf8a52B8D5647BF88A30fbc8e1",
+ [23295]: "",
+ [19236265]: "",
},
bitUsdTWAP: {
- [23294]: '',
- [23295]: '0x793EA3ef890570f6935697CDc61f769a04Ed63C2',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0x793EA3ef890570f6935697CDc61f769a04Ed63C2",
+ [19236265]: "",
},
bitUsdLpOracle: {
- [23294]: '',
- [23295]: '0x6e0DfB9a7159e557273287dD4E46485fCA966C5c',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0x6e0DfB9a7159e557273287dD4E46485fCA966C5c",
+ [19236265]: "",
},
bitGovTWAP: {
- [23294]: '',
- [23295]: '0xD4a5b94EDEa30f9A07BB5270B6bf766aA760615F',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0xD4a5b94EDEa30f9A07BB5270B6bf766aA760615F",
+ [19236265]: "",
},
bitGovLpOracle: {
- [23294]: '',
- [23295]: '0xB1066f2B3E8fc94051295D9A63330C2bd31C00a5',
- [19236265]: '',
+ [23294]: "",
+ [23295]: "0xB1066f2B3E8fc94051295D9A63330C2bd31C00a5",
+ [19236265]: "",
},
};
export const rpc = {
- [23294]: 'https://sapphire.oasis.io',
- [23295]: 'https://testnet.sapphire.oasis.dev/',
- [19236265]: '',
+ [23294]: "https://sapphire.oasis.io",
+ [23295]: "https://testnet.sapphire.oasis.dev/",
+ [19236265]: "",
};
export const api = {
- bot: 'https://api.bitusd.finance/api',
- // bot: 'http://localhost:3000/api',
+ // bot: 'https://api.bitusd.finance/api',
+ bot:
+ process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
+ ? process.env.NEXT_PUBLIC_API_URL_V1 || "https://api.bitusd.finance/v1"
+ : process.env.NEXT_PUBLIC_API_LOCAL_URL_V1 || "/api/bot",
};