1- import { formatEther } from 'viem' ;
1+ import { formatEther , Hex , TransactionReceipt } from 'viem' ;
22
33import {
44 getStethContract ,
@@ -7,26 +7,31 @@ import {
77} from 'contracts' ;
88import { getAccount } from 'providers' ;
99import {
10- callReadMethod ,
1110 callReadMethodSilent ,
1211 callWriteMethodWithReceipt ,
1312 confirmOperation ,
1413 logInfo ,
14+ PopulatedTx ,
1515} from 'utils' ;
1616
1717export const checkAllowance = async (
1818 contract : DashboardContract ,
1919 amount : bigint ,
2020 token : 'steth' | 'wsteth' | 'shares' ,
21- ) => {
21+ populateTx ?: boolean ,
22+ ) : Promise < {
23+ receipt ?: TransactionReceipt ;
24+ tx ?: Hex ;
25+ data ?: PopulatedTx ;
26+ } | void > => {
2227 const accountAddress = ( await getAccount ( ) ) . address ;
2328 const isShares = token === 'shares' ;
2429 let currentAmount = amount ;
2530
2631 if ( token === 'steth' || isShares ) {
2732 const stethContract = await getStethContract ( ) ;
2833
29- const allowance = await callReadMethod ( stethContract , 'allowance' , [
34+ const allowance = await callReadMethodSilent ( stethContract , 'allowance' , [
3035 accountAddress ,
3136 contract . address ,
3237 ] ) ;
@@ -46,19 +51,21 @@ export const checkAllowance = async (
4651 ) ;
4752 if ( ! confirm ) throw new Error ( 'Allowance not set' ) ;
4853
49- await callWriteMethodWithReceipt ( {
54+ return await callWriteMethodWithReceipt ( {
5055 contract : stethContract ,
5156 methodName : 'approve' ,
5257 payload : [ contract . address , currentAmount ] ,
58+ populateTx,
5359 } ) ;
5460 }
5561 } else {
5662 const wstethContract = await getWstethContract ( ) ;
5763
58- const wstethAllowance = await callReadMethod ( wstethContract , 'allowance' , [
59- accountAddress ,
60- accountAddress ,
61- ] ) ;
64+ const wstethAllowance = await callReadMethodSilent (
65+ wstethContract ,
66+ 'allowance' ,
67+ [ accountAddress , contract . address ] ,
68+ ) ;
6269 if ( wstethAllowance < amount ) {
6370 logInfo ( 'Insufficient allowance' ) ;
6471
@@ -67,10 +74,11 @@ export const checkAllowance = async (
6774 ) ;
6875 if ( ! confirm ) throw new Error ( 'Allowance not set' ) ;
6976
70- await callWriteMethodWithReceipt ( {
77+ return await callWriteMethodWithReceipt ( {
7178 contract : wstethContract ,
7279 methodName : 'approve' ,
7380 payload : [ contract . address , amount ] ,
81+ populateTx,
7482 } ) ;
7583 }
7684 }
0 commit comments