Skip to content

Commit b3dc3d0

Browse files
committed
fix: approval for usdt
1 parent afbc11c commit b3dc3d0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/dev/AccountOpener.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,22 @@ export class AccountOpener {
230230

231231
async #approve(token: Address, cm: CreditFactory): Promise<void> {
232232
const borrower = await this.#getBorrower();
233+
const symbol = this.#service.sdk.tokensMeta.symbol(token);
233234
try {
235+
if (symbol === "USDT") {
236+
const hash = await this.#anvil.writeContract({
237+
account: borrower,
238+
address: token,
239+
abi: ierc20Abi,
240+
functionName: "approve",
241+
args: [cm.creditManager.address, 0n],
242+
chain: this.#anvil.chain,
243+
});
244+
await this.#anvil.waitForTransactionReceipt({
245+
hash,
246+
});
247+
}
248+
234249
const hash = await this.#anvil.writeContract({
235250
account: borrower,
236251
address: token,
@@ -245,16 +260,16 @@ export class AccountOpener {
245260

246261
if (receipt.status === "reverted") {
247262
this.#logger?.error(
248-
`failed to allowed credit manager ${cm.creditManager.name} to spend ${token}, tx reverted: ${hash}`,
263+
`failed to allowed credit manager ${cm.creditManager.name} to spend ${symbol} (${token}), tx reverted: ${hash}`,
249264
);
250265
} else {
251266
this.#logger?.debug(
252-
`allowed credit manager ${cm.creditManager.name} to spend ${token}, tx: ${hash}`,
267+
`allowed credit manager ${cm.creditManager.name} to spend ${symbol} (${token}), tx: ${hash}`,
253268
);
254269
}
255270
} catch (e) {
256271
this.#logger?.error(
257-
`failed to allowed credit manager ${cm.creditManager.name} to spend ${token}: ${e}`,
272+
`failed to allowed credit manager ${cm.creditManager.name} to spend ${symbol} (${token}): ${e}`,
258273
);
259274
}
260275
}

0 commit comments

Comments
 (0)