@@ -4,9 +4,11 @@ import {
4
4
ensureAllowanceEstimateGas ,
5
5
formatUnits ,
6
6
hasAllowance ,
7
+ getAllowance ,
7
8
parseUnits ,
8
9
smartNumber ,
9
10
getBalances ,
11
+ MAX_ALLOWANCE ,
10
12
} from "./utils.js" ;
11
13
import { lending } from "./lending.js" ;
12
14
import { TAmount , TGas } from "./interfaces.js" ;
@@ -67,12 +69,16 @@ export const depositIsApproved = async(assets: TAmount): Promise<boolean> => {
67
69
return await hasAllowance ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . signerAddress , lending . constants . ALIASES . st_crvUSD ) ;
68
70
}
69
71
72
+ export const depositAllowance = async ( ) : Promise < string [ ] > => {
73
+ return await getAllowance ( [ lending . constants . ALIASES . crvUSD ] , lending . signerAddress , lending . constants . ALIASES . st_crvUSD ) ;
74
+ }
75
+
70
76
export const depositApproveEstimateGas = async ( assets : TAmount ) : Promise < TGas > => {
71
77
return await ensureAllowanceEstimateGas ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . constants . ALIASES . st_crvUSD ) ;
72
78
}
73
79
74
- export const depositApprove = async ( assets : TAmount ) : Promise < string [ ] > => {
75
- return await ensureAllowance ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . constants . ALIASES . st_crvUSD ) ;
80
+ export const depositApprove = async ( assets : TAmount , isMax = true ) : Promise < string [ ] > => {
81
+ return await ensureAllowance ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . constants . ALIASES . st_crvUSD , isMax ) ;
76
82
}
77
83
78
84
const _deposit = async ( assets : TAmount , estimateGas = false ) : Promise < string | TGas > => {
@@ -120,14 +126,24 @@ export const mintIsApproved = async (shares: TAmount): Promise<boolean> => {
120
126
return await hasAllowance ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . signerAddress , lending . constants . ALIASES . st_crvUSD ) ;
121
127
}
122
128
129
+ export const mintAllowance = async ( ) : Promise < string [ ] > => {
130
+ const assets = await getAllowance ( [ lending . constants . ALIASES . crvUSD ] , lending . signerAddress , lending . constants . ALIASES . st_crvUSD ) ;
131
+ try {
132
+ return [ await convertToShares ( assets [ 0 ] ) ]
133
+ } catch ( e ) {
134
+ if ( parseUnits ( assets [ 0 ] ) === MAX_ALLOWANCE ) return [ lending . formatUnits ( MAX_ALLOWANCE ) ] ;
135
+ throw e ;
136
+ }
137
+ }
138
+
123
139
export const mintApproveEstimateGas = async ( shares : TAmount ) : Promise < TGas > => {
124
140
const assets = await previewMint ( shares ) ;
125
141
return await ensureAllowanceEstimateGas ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . constants . ALIASES . st_crvUSD ) ;
126
142
}
127
143
128
- export const mintApprove = async ( shares : TAmount ) : Promise < string [ ] > => {
144
+ export const mintApprove = async ( shares : TAmount , isMax = true ) : Promise < string [ ] > => {
129
145
const assets = await previewMint ( shares ) ;
130
- return await ensureAllowance ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . constants . ALIASES . st_crvUSD ) ;
146
+ return await ensureAllowance ( [ lending . constants . ALIASES . crvUSD ] , [ assets ] , lending . constants . ALIASES . st_crvUSD , isMax ) ;
131
147
}
132
148
133
149
const _mint = async ( shares : TAmount , estimateGas = false ) : Promise < string | TGas > => {
0 commit comments