Skip to content

Commit

Permalink
Preview Deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjames44 committed Nov 5, 2024
1 parent 8895d52 commit ca3b002
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/contexts/v1/BoringVaultContextV1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ interface BoringVaultV1ContextProps {
amount: string,
token: Token
) => Promise<DepositStatus>;
previewDeposit: (
amount: string,
token: Token
) => Promise<string>;
/* Delay Withdraws */
delayWithdraw: (
signer: JsonRpcSigner,
Expand Down Expand Up @@ -587,6 +591,65 @@ export const BoringVaultV1Provider: React.FC<{
]
);

const previewDeposit = useCallback(
async (
amountHumanReadable: string,
token: Token
) => {
if (
!vaultEthersContract ||
!isBoringV1ContextReady ||
!lensEthersContract ||
!decimals
) {
console.error("Contracts or user not ready", {
/* Dependencies here */
});
return Promise.reject("Contracts or user not ready");
}

try {
const bigNumAmt = new BigNumber(amountHumanReadable);
console.warn(amountHumanReadable);
console.warn("Amount to deposit: ", bigNumAmt.toNumber());
const amountDepositBaseDenom = bigNumAmt.multipliedBy(
new BigNumber(10).pow(token.decimals)
);
console.warn("Amount to deposit: ", amountDepositBaseDenom.toNumber());

// Preview the deposit
console.log(token.address);
console.log(amountDepositBaseDenom.toFixed(0));
console.log(vaultContract);
console.log(accountantContract);
const depositPreviewAmt = await lensEthersContract.previewDeposit(
token.address,
amountDepositBaseDenom.toFixed(0),
outputTokenContract ? outputTokenContract : vaultContract,
accountantContract
);
console.log("Deposit preview: ", depositPreviewAmt);

const humanReadablePreviewAmt = Number(depositPreviewAmt) / Math.pow(10, decimals);

console.log("Deposit preview: ", humanReadablePreviewAmt);
return String(humanReadablePreviewAmt);
} catch (error: any) {
console.error("Error previewing deposit: ", error);
return Promise.reject("Error previewing deposit");
}
},
[
vaultEthersContract,
tellerEthersContract,
decimals,
ethersProvider,
isBoringV1ContextReady,
lensEthersContract,
outputTokenContract,
]
);

/* Delay Withdraws */

const delayWithdraw = useCallback(
Expand Down Expand Up @@ -1810,6 +1873,7 @@ export const BoringVaultV1Provider: React.FC<{
fetchShareValue,
fetchUserUnlockTime,
deposit,
previewDeposit,
delayWithdraw,
delayWithdrawStatuses,
delayWithdrawCancel,
Expand Down

0 comments on commit ca3b002

Please sign in to comment.