Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/coinbase-agentkit/changelog.d/573.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug in Morpho action provider to allow depositing ERC20 tokens of variable decimal precision
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from coinbase_agentkit.action_providers.action_decorator import create_action
from coinbase_agentkit.action_providers.action_provider import ActionProvider
from coinbase_agentkit.action_providers.erc20.constants import ERC20_ABI
from coinbase_agentkit.action_providers.morpho.constants import METAMORPHO_ABI
from coinbase_agentkit.action_providers.morpho.schemas import (
MorphoDepositSchema,
Expand Down Expand Up @@ -60,7 +61,14 @@ def deposit(self, wallet_provider: EvmWalletProvider, args: dict[str, Any]) -> s
return "Error: Assets amount must be greater than 0"

try:
atomic_assets = Web3.to_wei(assets, "ether")
decimals = wallet_provider.read_contract(
contract_address=args["token_address"],
abi=ERC20_ABI,
function_name="decimals",
args=[],
)

atomic_assets = int(assets * (10**decimals))

try:
approve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
MOCK_TOKEN_ADDRESS = "0x0987654321098765432109876543210987654321"
MOCK_RECEIVER = "0x5555555555555555555555555555555555555555"
MOCK_TX_HASH = "0xabcdef1234567890"
MOCK_DECIMALS = 18


# Deposit Tests
def test_morpho_deposit_success():
"""Test successful morpho deposit with valid parameters."""
mock_wallet = MagicMock()
mock_wallet.send_transaction.return_value = MOCK_TX_HASH
mock_wallet.read_contract.return_value = MOCK_DECIMALS

with patch(
"coinbase_agentkit.action_providers.morpho.morpho_action_provider.approve"
Expand Down
5 changes: 5 additions & 0 deletions typescript/.changeset/chubby-squids-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase/agentkit": patch
---

Fixed bug in Morpho action provider to allow depositing ERC20 tokens of variable decimal precision
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const MOCK_RECEIVER_ID = "0x9876543210987654321098765432109876543210";
const MOCK_TOKEN_ADDRESS = "0x4200000000000000000000000000000000000006";
const MOCK_TX_HASH = "0xabcdef1234567890";
const MOCK_RECEIPT = { status: 1, blockNumber: 1234567 };
const MOCK_DECIMALS = 18;

jest.mock("../../utils");
const mockApprove = approve as jest.MockedFunction<typeof approve>;
Expand All @@ -25,6 +26,7 @@ describe("Morpho Action Provider", () => {
getNetwork: jest.fn().mockReturnValue({ protocolFamily: "evm", networkId: "1" }),
sendTransaction: jest.fn().mockResolvedValue(MOCK_TX_HASH as `0x${string}`),
waitForTransactionReceipt: jest.fn().mockResolvedValue(MOCK_RECEIPT),
readContract: jest.fn().mockResolvedValue(MOCK_DECIMALS),
} as unknown as jest.Mocked<EvmWalletProvider>;

mockApprove.mockResolvedValue("Approval successful");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { Decimal } from "decimal.js";
import { encodeFunctionData, parseEther } from "viem";

import { encodeFunctionData, Hex, parseUnits } from "viem";
import { abi } from "../erc20/constants";
import { ActionProvider } from "../actionProvider";
import { EvmWalletProvider } from "../../wallet-providers";
import { CreateAction } from "../actionDecorator";
Expand Down Expand Up @@ -59,7 +59,14 @@ Important notes:
}

try {
const atomicAssets = parseEther(args.assets);
const decimals = await wallet.readContract({
address: args.tokenAddress as Hex,
abi,
functionName: "decimals",
args: [],
});

const atomicAssets = parseUnits(args.assets, decimals);

const approvalResult = await approve(
wallet,
Expand Down