@@ -1001,6 +1001,21 @@ export class MintMarketTemplate {
10011001 return await this . _addCollateral ( collateral , address , false ) as string ;
10021002 }
10031003
1004+ public async addCollateralFutureLeverage ( collateral : number | string , userAddress = '' ) : Promise < string > {
1005+ this . _checkLeverageForStats ( ) ;
1006+ userAddress = _getAddress . call ( this . llamalend , userAddress ) ;
1007+ const [ userCollateral , { collateral : currentCollateral } ] = await Promise . all ( [
1008+ _getUserCollateralCrvUsdFull ( this . llamalend . constants . NETWORK_NAME , this . controller , userAddress ) ,
1009+ this . userState ( userAddress ) ,
1010+ ] ) ;
1011+
1012+ const total_deposit_from_user = userCollateral . total_deposit_from_user_precise ?? userCollateral . total_deposit_precise ;
1013+ const collateralBN = BN ( collateral ) ;
1014+ const currentCollateralBN = BN ( currentCollateral ) ;
1015+
1016+ return currentCollateralBN . plus ( collateralBN ) . div ( BN ( total_deposit_from_user ) . plus ( collateralBN ) ) . toString ( ) ;
1017+ }
1018+
10041019 // ---------------- REMOVE COLLATERAL ----------------
10051020
10061021 public async maxRemovable ( ) : Promise < string > {
@@ -1069,6 +1084,21 @@ export class MintMarketTemplate {
10691084 return await this . _removeCollateral ( collateral , false ) as string ;
10701085 }
10711086
1087+ public async removeCollateralFutureLeverage ( collateral : number | string , userAddress = '' ) : Promise < string > {
1088+ this . _checkLeverageForStats ( ) ;
1089+ userAddress = _getAddress . call ( this . llamalend , userAddress ) ;
1090+ const [ userCollateral , { collateral : currentCollateral } ] = await Promise . all ( [
1091+ _getUserCollateralCrvUsdFull ( this . llamalend . constants . NETWORK_NAME , this . controller , userAddress ) ,
1092+ this . userState ( userAddress ) ,
1093+ ] ) ;
1094+
1095+ const total_deposit_from_user = userCollateral . total_deposit_from_user_precise ?? userCollateral . total_deposit_precise ;
1096+ const collateralBN = BN ( collateral ) ;
1097+ const currentCollateralBN = BN ( currentCollateral ) ;
1098+
1099+ return currentCollateralBN . minus ( collateralBN ) . div ( BN ( total_deposit_from_user ) . minus ( collateralBN ) ) . toString ( ) ;
1100+ }
1101+
10721102 // ---------------- REPAY ----------------
10731103
10741104 private async _repayBands ( debt : number | string , address : string ) : Promise < [ bigint , bigint ] > {
0 commit comments