1- import type { Address , ContractFunctionArgs , WalletClient } from "viem" ;
1+ import type { Address , ContractFunctionArgs } from "viem" ;
22import { decodeFunctionData , encodeFunctionData } from "viem" ;
33
44import {
@@ -41,14 +41,12 @@ export interface CreditAccountFilter {
4141
4242export class CreditAccountsService extends SDKConstruct {
4343 #compressor: Address ;
44- #wallet: WalletClient ;
4544
46- constructor ( sdk : GearboxSDK , wallet : WalletClient ) {
45+ constructor ( sdk : GearboxSDK ) {
4746 super ( sdk ) ;
4847 this . #compressor = sdk . addressProvider . getLatestVersion (
4948 AP_CREDIT_ACCOUNT_COMPRESSOR ,
5049 ) ;
51- this . #wallet = wallet ;
5250 }
5351
5452 /**
@@ -81,7 +79,8 @@ export class CreditAccountsService extends SDKConstruct {
8179 // if (this.provider.testnet && priceUpdateTxs.length > 0) {
8280 // await this.provider.warpSafe(timestamp);
8381 // }
84- const resp = await simulateMulticall ( this . #wallet, {
82+ const resp = await simulateMulticall ( this . provider . publicClient , {
83+ account : this . provider . account ,
8584 contracts : [
8685 ...priceUpdateTxs . map ( rawTxToMulticallPriceUpdate ) ,
8786 {
@@ -166,7 +165,7 @@ export class CreditAccountsService extends SDKConstruct {
166165 */
167166 public async fullyLiquidate (
168167 account : CreditAccountData ,
169- to : Address ,
168+ to ? : Address ,
170169 slippage = 50n ,
171170 ) : Promise < RawTx > {
172171 const cm = this . sdk . marketRegister . findCreditManager ( account . creditManager ) ;
@@ -183,11 +182,15 @@ export class CreditAccountsService extends SDKConstruct {
183182 cm . creditFacade . address ,
184183 priceUpdates ,
185184 ) ;
185+ const recipient = to ?? this . sdk . provider . account ;
186+ if ( ! recipient ) {
187+ throw new Error ( "liquidate account: assets recipient not specied" ) ;
188+ }
186189 return cm . creditFacade . createRawTx ( {
187190 functionName : "liquidateCreditAccount" ,
188191 args : [
189192 account . creditAccount ,
190- to ,
193+ recipient ,
191194 [ ...priceUpdateCalls , ...preview . calls ] ,
192195 ] ,
193196 } ) ;
@@ -206,15 +209,19 @@ export class CreditAccountsService extends SDKConstruct {
206209 operation : "close" | "zeroDebt" ,
207210 ca : CreditAccountData ,
208211 assetsToKeep : Address [ ] ,
209- to : Address ,
212+ to ? : Address ,
210213 slippage = 50n ,
211214 ) : Promise < RawTx > {
212215 const cm = this . sdk . marketRegister . findCreditManager ( ca . creditManager ) ;
216+ const recipient = to ?? this . sdk . provider . account ;
217+ if ( ! recipient ) {
218+ throw new Error ( "close account: assets recipient not specied" ) ;
219+ }
213220 const calls = await this . #prepareCloseCreditAccount(
214221 ca ,
215222 cm ,
216223 assetsToKeep ,
217- to ,
224+ recipient ,
218225 slippage ,
219226 ) ;
220227 return cm . creditFacade . createRawTx ( {
@@ -236,7 +243,8 @@ export class CreditAccountsService extends SDKConstruct {
236243 args : GetCreditAccountsArgs ;
237244 } ) : Promise < [ accounts : CreditAccountData [ ] , newOffset : bigint ] > {
238245 if ( priceUpdateTxs ?. length ) {
239- const resp = await simulateMulticall ( this . #wallet, {
246+ const resp = await simulateMulticall ( this . provider . publicClient , {
247+ account : this . provider . account ,
240248 contracts : [
241249 ...priceUpdateTxs . map ( rawTxToMulticallPriceUpdate ) ,
242250 {
0 commit comments