diff --git a/src/contexts/v1/BoringVaultContextV1.tsx b/src/contexts/v1/BoringVaultContextV1.tsx index 12e57d2..9e539b7 100644 --- a/src/contexts/v1/BoringVaultContextV1.tsx +++ b/src/contexts/v1/BoringVaultContextV1.tsx @@ -62,6 +62,10 @@ interface BoringVaultV1ContextProps { amount: string, token: Token ) => Promise; + previewDeposit: ( + amount: string, + token: Token + ) => Promise; /* Delay Withdraws */ delayWithdraw: ( signer: JsonRpcSigner, @@ -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( @@ -1810,6 +1873,7 @@ export const BoringVaultV1Provider: React.FC<{ fetchShareValue, fetchUserUnlockTime, deposit, + previewDeposit, delayWithdraw, delayWithdrawStatuses, delayWithdrawCancel,