Skip to content

Commit e333a61

Browse files
committed
fix: approve underlying
1 parent 9dcdd0f commit e333a61

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/dev/AccountOpener.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from "../sdk";
1313
import {
1414
ADDRESS_0X0,
15+
AddressMap,
1516
childLogger,
1617
formatBN,
1718
iDegenNftv2Abi,
@@ -69,9 +70,17 @@ export class AccountOpener {
6970
): Promise<CreditAccountData[]> {
7071
await this.#prepareBorrower(targets);
7172

73+
const toApprove = new AddressMap<Set<Address>>();
7274
for (const c of targets) {
7375
const cm = this.sdk.marketRegister.findCreditManager(c.creditManager);
74-
await this.#approve(c.collateral, cm);
76+
const toApproveOnCM = toApprove.get(c.creditManager) ?? new Set();
77+
toApproveOnCM.add(cm.underlying);
78+
}
79+
for (const [cmAddr, tokens] of toApprove.entries()) {
80+
const cm = this.sdk.marketRegister.findCreditManager(cmAddr);
81+
for (const token of tokens) {
82+
await this.#approve(token, cm);
83+
}
7584
}
7685

7786
for (let i = 0; i < targets.length; i++) {

0 commit comments

Comments
 (0)