@agether/openclaw-plugin 1.2.0 → 1.3.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.ts +25 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agether/openclaw-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
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.1.0",
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
- // Approve USDC for MorphoCredit
636
- const approveData = erc20Iface.encodeFunctionData("approve", [status.contracts.morphoCredit, amountWei]);
637
- const approveTx = await account.execute(status.contracts.usdc, 0, approveData);
638
- await approveTx.wait();
639
-
640
- // Repay
641
- const repayData = morphoIface.encodeFunctionData("repayWithCollateral", [collateralAddr, amountWei]);
642
- const tx = await account.execute(status.contracts.morphoCredit, 0, repayData);
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);
@@ -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
- // Step 1: Withdraw from Morpho AgentAccount
698
- const withdrawData = morphoIface.encodeFunctionData("withdrawCollateral", [tokenInfo.address, withdrawAmount]);
699
- const tx1 = await account.execute(status.contracts.morphoCredit, 0, withdrawData);
700
- await tx1.wait();
701
-
702
- // Step 2: Move from AgentAccount → EOA
703
- const tx2 = await account.withdraw(tokenInfo.address, withdrawAmount, signer.address);
704
- await tx2.wait();
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: tx1.hash,
722
+ tx: tx.hash,
715
723
  }));
716
724
  } catch (e) { return fail(e); }
717
725
  },