@agether/sdk 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -18
- package/dist/index.mjs +13 -18
- package/package.json +1 -1
- package/dist/cli.js +0 -2252
package/dist/index.js
CHANGED
|
@@ -1228,26 +1228,21 @@ var MorphoClient = class {
|
|
|
1228
1228
|
repayAssets = import_ethers2.ethers.parseUnits(usdcAmount, 6);
|
|
1229
1229
|
repayShares = 0n;
|
|
1230
1230
|
approveAmount = repayAssets;
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1231
|
+
}
|
|
1232
|
+
const usdcContract = new import_ethers2.Contract(usdcAddr, ERC20_ABI, this._signer);
|
|
1233
|
+
const acctBalance = await usdcContract.balanceOf(acctAddr);
|
|
1234
|
+
if (acctBalance < approveAmount) {
|
|
1235
|
+
const shortfall = approveAmount - acctBalance;
|
|
1236
|
+
const eoaBalance = await usdcContract.balanceOf(await this.getSignerAddress());
|
|
1237
|
+
if (eoaBalance < shortfall) {
|
|
1238
|
+
throw new AgetherError(
|
|
1239
|
+
`Insufficient USDC for repay. Need ${import_ethers2.ethers.formatUnits(approveAmount, 6)} USDC, AgentAccount has ${import_ethers2.ethers.formatUnits(acctBalance, 6)}, EOA has ${import_ethers2.ethers.formatUnits(eoaBalance, 6)}.`,
|
|
1240
|
+
"INSUFFICIENT_BALANCE"
|
|
1235
1241
|
);
|
|
1236
|
-
if (mkt) {
|
|
1237
|
-
const pos = await this.morphoBlue.position(mkt.uniqueKey, acctAddr);
|
|
1238
|
-
const onChainMkt = await this.morphoBlue.market(mkt.uniqueKey);
|
|
1239
|
-
const totalBorrowAssets = BigInt(onChainMkt.totalBorrowAssets);
|
|
1240
|
-
const totalBorrowShares = BigInt(onChainMkt.totalBorrowShares);
|
|
1241
|
-
const currentDebt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
|
|
1242
|
-
if (repayAssets >= currentDebt && BigInt(pos.borrowShares) > 0n) {
|
|
1243
|
-
repayShares = BigInt(pos.borrowShares);
|
|
1244
|
-
repayAssets = 0n;
|
|
1245
|
-
approveAmount = currentDebt + 10n;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
} catch (e) {
|
|
1249
|
-
console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
|
|
1250
1242
|
}
|
|
1243
|
+
const transferTx = await usdcContract.transfer(acctAddr, shortfall);
|
|
1244
|
+
await transferTx.wait();
|
|
1245
|
+
this._refreshSigner();
|
|
1251
1246
|
}
|
|
1252
1247
|
const targets = [usdcAddr, morphoAddr];
|
|
1253
1248
|
const values = [0n, 0n];
|
package/dist/index.mjs
CHANGED
|
@@ -1163,26 +1163,21 @@ var MorphoClient = class {
|
|
|
1163
1163
|
repayAssets = ethers2.parseUnits(usdcAmount, 6);
|
|
1164
1164
|
repayShares = 0n;
|
|
1165
1165
|
approveAmount = repayAssets;
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1166
|
+
}
|
|
1167
|
+
const usdcContract = new Contract2(usdcAddr, ERC20_ABI, this._signer);
|
|
1168
|
+
const acctBalance = await usdcContract.balanceOf(acctAddr);
|
|
1169
|
+
if (acctBalance < approveAmount) {
|
|
1170
|
+
const shortfall = approveAmount - acctBalance;
|
|
1171
|
+
const eoaBalance = await usdcContract.balanceOf(await this.getSignerAddress());
|
|
1172
|
+
if (eoaBalance < shortfall) {
|
|
1173
|
+
throw new AgetherError(
|
|
1174
|
+
`Insufficient USDC for repay. Need ${ethers2.formatUnits(approveAmount, 6)} USDC, AgentAccount has ${ethers2.formatUnits(acctBalance, 6)}, EOA has ${ethers2.formatUnits(eoaBalance, 6)}.`,
|
|
1175
|
+
"INSUFFICIENT_BALANCE"
|
|
1170
1176
|
);
|
|
1171
|
-
if (mkt) {
|
|
1172
|
-
const pos = await this.morphoBlue.position(mkt.uniqueKey, acctAddr);
|
|
1173
|
-
const onChainMkt = await this.morphoBlue.market(mkt.uniqueKey);
|
|
1174
|
-
const totalBorrowAssets = BigInt(onChainMkt.totalBorrowAssets);
|
|
1175
|
-
const totalBorrowShares = BigInt(onChainMkt.totalBorrowShares);
|
|
1176
|
-
const currentDebt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
|
|
1177
|
-
if (repayAssets >= currentDebt && BigInt(pos.borrowShares) > 0n) {
|
|
1178
|
-
repayShares = BigInt(pos.borrowShares);
|
|
1179
|
-
repayAssets = 0n;
|
|
1180
|
-
approveAmount = currentDebt + 10n;
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
} catch (e) {
|
|
1184
|
-
console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
|
|
1185
1177
|
}
|
|
1178
|
+
const transferTx = await usdcContract.transfer(acctAddr, shortfall);
|
|
1179
|
+
await transferTx.wait();
|
|
1180
|
+
this._refreshSigner();
|
|
1186
1181
|
}
|
|
1187
1182
|
const targets = [usdcAddr, morphoAddr];
|
|
1188
1183
|
const values = [0n, 0n];
|