@agether/openclaw-plugin 1.2.0 → 1.3.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/package.json +2 -2
- package/src/index.ts +26 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agether/openclaw-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "OpenClaw plugin for Agether — on-chain credit for AI agents",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"openclaw": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
]
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@agether/sdk": "^1.
|
|
12
|
+
"@agether/sdk": "^1.3.0",
|
|
13
13
|
"axios": "^1.6.0",
|
|
14
14
|
"ethers": "^6.9.0"
|
|
15
15
|
},
|
package/src/index.ts
CHANGED
|
@@ -566,6 +566,10 @@ export default function register(api: any) {
|
|
|
566
566
|
|
|
567
567
|
// Borrow via AgentAccount.execute → drawWithCollateral
|
|
568
568
|
const account = new ethers.Contract(accountAddr, AGENT_ACCOUNT_ABI, signer);
|
|
569
|
+
|
|
570
|
+
// Ensure credit provider approved (one-time, idempotent)
|
|
571
|
+
try { const cpTx = await account.approveCreditProvider(status.contracts.morphoCredit); await cpTx.wait(); } catch { /* already approved */ }
|
|
572
|
+
|
|
569
573
|
const morphoIface = new ethers.Interface(MORPHO_CREDIT_ABI);
|
|
570
574
|
const calldata = morphoIface.encodeFunctionData("drawWithCollateral", [collateralAddr, amountWei]);
|
|
571
575
|
|
|
@@ -632,14 +636,15 @@ export default function register(api: any) {
|
|
|
632
636
|
const morphoIface = new ethers.Interface(MORPHO_CREDIT_ABI);
|
|
633
637
|
const erc20Iface = new ethers.Interface(ERC20_ABI);
|
|
634
638
|
|
|
635
|
-
//
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
639
|
+
// Single tx via executeBatch: approve USDC + repayWithCollateral
|
|
640
|
+
const tx = await account.executeBatch(
|
|
641
|
+
[status.contracts.usdc, status.contracts.morphoCredit],
|
|
642
|
+
[0, 0],
|
|
643
|
+
[
|
|
644
|
+
erc20Iface.encodeFunctionData("approve", [status.contracts.morphoCredit, amountWei]),
|
|
645
|
+
morphoIface.encodeFunctionData("repayWithCollateral", [collateralAddr, amountWei]),
|
|
646
|
+
],
|
|
647
|
+
);
|
|
643
648
|
await tx.wait();
|
|
644
649
|
|
|
645
650
|
const totalDebt = await morpho.getTotalDebt(accountAddr);
|
|
@@ -660,7 +665,7 @@ export default function register(api: any) {
|
|
|
660
665
|
api.registerTool({
|
|
661
666
|
name: "morpho_withdraw",
|
|
662
667
|
description:
|
|
663
|
-
"Withdraw collateral from Morpho Blue back to EOA wallet. Use amount 'all' to withdraw maximum. Must maintain
|
|
668
|
+
"Withdraw collateral from Morpho Blue back to EOA wallet. Use amount 'all' to withdraw maximum. Must maintain 125% collateral ratio (80% max LTV) if debt remains.",
|
|
664
669
|
parameters: {
|
|
665
670
|
type: "object",
|
|
666
671
|
properties: {
|
|
@@ -693,15 +698,18 @@ export default function register(api: any) {
|
|
|
693
698
|
|
|
694
699
|
const account = new ethers.Contract(accountAddr, AGENT_ACCOUNT_ABI, signer);
|
|
695
700
|
const morphoIface = new ethers.Interface(MORPHO_CREDIT_ABI);
|
|
701
|
+
const erc20Iface = new ethers.Interface(ERC20_ABI);
|
|
696
702
|
|
|
697
|
-
//
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
703
|
+
// Single tx via executeBatch: withdrawCollateral + transfer to EOA
|
|
704
|
+
const tx = await account.executeBatch(
|
|
705
|
+
[status.contracts.morphoCredit, tokenInfo.address],
|
|
706
|
+
[0, 0],
|
|
707
|
+
[
|
|
708
|
+
morphoIface.encodeFunctionData("withdrawCollateral", [tokenInfo.address, withdrawAmount]),
|
|
709
|
+
erc20Iface.encodeFunctionData("transfer", [signer.address, withdrawAmount]),
|
|
710
|
+
],
|
|
711
|
+
);
|
|
712
|
+
await tx.wait();
|
|
705
713
|
|
|
706
714
|
const newPos = await morpho.getPosition(accountAddr, tokenInfo.address);
|
|
707
715
|
|
|
@@ -711,7 +719,7 @@ export default function register(api: any) {
|
|
|
711
719
|
remainingCollateral: `${ethers.formatUnits(newPos.collateralAmount, tokenInfo.decimals)} ${params.token}`,
|
|
712
720
|
remainingDebt: `$${ethers.formatUnits(newPos.borrowedAmount, 6)}`,
|
|
713
721
|
destination: signer.address,
|
|
714
|
-
tx:
|
|
722
|
+
tx: tx.hash,
|
|
715
723
|
}));
|
|
716
724
|
} catch (e) { return fail(e); }
|
|
717
725
|
},
|