Skip to content

Commit 85c0f15

Browse files
authored
Merge pull request #382 from Gearbox-protocol/repay
fix: repay
2 parents 6dbf748 + 7cf39dd commit 85c0f15

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

src/sdk/accounts/AbstractCreditAccountsService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
201201
} while (offset !== 0n);
202202
}
203203
this.#logger?.debug(
204-
`loaded ${allCAs.length} credit accounts (${allCAs.length - revertingOffset} reverting)`,
204+
`loaded ${allCAs.length} credit accounts (${
205+
allCAs.length - revertingOffset
206+
} reverting)`,
205207
);
206208

207209
// sort by health factor ascending
@@ -409,6 +411,8 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
409411
creditAccount: ca,
410412
});
411413

414+
console.log("CLOSE", this.sdk.parseMultiCall(routerCloseResult.calls));
415+
412416
const calls: Array<MultiCall> = [
413417
...(operation === "close" ? [] : priceUpdates),
414418
...routerCloseResult.calls,

src/sdk/accounts/CreditAccountsServiceV310.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ export class CreditAccountServiceV310
102102
creditAccount: ca,
103103
permits,
104104
to,
105+
tokensToClaim,
105106
}: RepayCreditAccountProps): Promise<CreditAccountOperationResult> {
106107
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
107108

108109
const addCollateral = collateralAssets.filter(a => a.balance > 0);
109110

110111
const router = this.sdk.routerFor(ca);
112+
// HERE
113+
111114
const claimPath = await router.findClaimAllRewards({
112115
calls: [],
116+
tokensToClaim,
113117
creditAccount: ca,
114118
});
119+
console.log("claimPath", this.sdk.parseMultiCall(claimPath.calls));
115120

116121
const priceUpdates = await this.getPriceUpdatesForFacade({
117122
creditManager: ca.creditManager,
@@ -146,15 +151,20 @@ export class CreditAccountServiceV310
146151
creditAccount: ca,
147152
permits,
148153
to,
154+
tokensToClaim,
149155
}: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult> {
150156
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
151157

152158
const router = this.sdk.routerFor(ca);
159+
// HERE
153160
const claimPath = await router.findClaimAllRewards({
154161
calls: [],
162+
tokensToClaim,
155163
creditAccount: ca,
156164
});
157165

166+
console.log("claimPath", this.sdk.parseMultiCall(claimPath.calls));
167+
158168
const priceUpdates = await this.getPriceUpdatesForFacade({
159169
creditManager: ca.creditManager,
160170
creditAccount: ca,
@@ -188,12 +198,14 @@ export class CreditAccountServiceV310
188198

189199
minQuota,
190200
averageQuota,
201+
tokensToClaim,
191202
}: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult> {
192203
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
193204

194205
const router = this.sdk.routerFor(ca);
195206
const claimPath = await router.findClaimAllRewards({
196207
calls: legacyCalls,
208+
tokensToClaim,
197209
creditAccount: ca,
198210
});
199211
if (claimPath.calls.length === 0) throw new Error("No path to execute");

src/sdk/accounts/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export interface RepayAndLiquidateCreditAccountProps {
135135
* permits of tokens to withdraw (in any permittable token is present)
136136
*/
137137
permits: Record<string, PermitResult>;
138+
tokensToClaim: Asset[];
138139
}
139140

140141
export interface PrepareUpdateQuotasProps {
@@ -257,6 +258,7 @@ export interface ClaimFarmRewardsProps extends PrepareUpdateQuotasProps {
257258
* minimal credit account data on which operation is performed
258259
*/
259260
creditAccount: RouterCASlice;
261+
tokensToClaim: Asset[];
260262
}
261263

262264
export interface EnableTokensProps {

src/sdk/router/RouterV310Contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class RouterV310Contract
168168
public async findClaimAllRewards(
169169
props: FindClaimAllRewardsProps,
170170
): Promise<RouterRewardsResult> {
171-
const tData: Array<TokenData> = props.creditAccount.tokens.map(a => ({
171+
const tData: Array<TokenData> = props.tokensToClaim.map(a => ({
172172
balance: 0n,
173173
claimRewards: true,
174174
leftoverBalance: 0n,

src/sdk/router/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ export interface FindClaimAllRewardsProps {
209209
* Minimal credit account data on which operation is performed
210210
*/
211211
creditAccount: RouterCASlice;
212+
/**
213+
* List of token rewards of which we want to claim and swap to underlying token during closing ca process
214+
*/
215+
tokensToClaim: Array<Asset>;
212216
/**
213217
* Legacy property - array of MultiCall from getRewards
214218
*/

0 commit comments

Comments
 (0)