@coinbase/agentkit 0.2.3-nightly.20250316.38 → 0.2.3-nightly.20250318.40
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/action-providers/erc20/constants.d.ts +2 -0
- package/dist/action-providers/erc20/constants.js +12 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +18 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +4 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
- package/dist/wallet-providers/cdpWalletProvider.js +24 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.abi = void 0;
|
|
3
|
+
exports.BaseSepoliaTokenToAssetId = exports.BaseTokenToAssetId = exports.abi = void 0;
|
|
4
|
+
const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
|
|
4
5
|
exports.abi = [
|
|
5
6
|
{
|
|
6
7
|
type: "event",
|
|
@@ -189,3 +190,13 @@ exports.abi = [
|
|
|
189
190
|
],
|
|
190
191
|
},
|
|
191
192
|
];
|
|
193
|
+
exports.BaseTokenToAssetId = new Map([
|
|
194
|
+
["0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", coinbase_sdk_1.Coinbase.assets.Cbbtc],
|
|
195
|
+
["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", coinbase_sdk_1.Coinbase.assets.Usdc],
|
|
196
|
+
["0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42", coinbase_sdk_1.Coinbase.assets.Eurc],
|
|
197
|
+
]);
|
|
198
|
+
exports.BaseSepoliaTokenToAssetId = new Map([
|
|
199
|
+
["0xcbB7C0006F23900c38EB856149F799620fcb8A4a", coinbase_sdk_1.Coinbase.assets.Cbbtc],
|
|
200
|
+
["0x036CbD53842c5426634e7929541eC2318f3dCF7e", coinbase_sdk_1.Coinbase.assets.Usdc],
|
|
201
|
+
["0x808456652fdb597867f38412077A9182bf77359F", coinbase_sdk_1.Coinbase.assets.Eurc],
|
|
202
|
+
]);
|
|
@@ -70,6 +70,24 @@ class ERC20ActionProvider extends actionProvider_1.ActionProvider {
|
|
|
70
70
|
*/
|
|
71
71
|
async transfer(walletProvider, args) {
|
|
72
72
|
try {
|
|
73
|
+
// Check if we can do gasless transfer
|
|
74
|
+
const isCdpWallet = walletProvider.getName() === "cdp_wallet_provider";
|
|
75
|
+
const network = walletProvider.getNetwork();
|
|
76
|
+
const tokenAddress = (0, viem_1.getAddress)(args.contractAddress);
|
|
77
|
+
const canDoGasless = isCdpWallet &&
|
|
78
|
+
((network.networkId === "base-mainnet" && constants_1.BaseTokenToAssetId.has(tokenAddress)) ||
|
|
79
|
+
(network.networkId === "base-sepolia" && constants_1.BaseSepoliaTokenToAssetId.has(tokenAddress)));
|
|
80
|
+
if (canDoGasless) {
|
|
81
|
+
// Cast to CdpWalletProvider to access erc20Transfer
|
|
82
|
+
const cdpWallet = walletProvider;
|
|
83
|
+
const assetId = network.networkId === "base-mainnet"
|
|
84
|
+
? constants_1.BaseTokenToAssetId.get(tokenAddress)
|
|
85
|
+
: constants_1.BaseSepoliaTokenToAssetId.get(tokenAddress);
|
|
86
|
+
const hash = await cdpWallet.gaslessERC20Transfer(assetId, args.destination, args.amount);
|
|
87
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
88
|
+
return `Transferred ${args.amount} of ${args.contractAddress} to ${args.destination} using gasless transfer.\nTransaction hash: ${hash}`;
|
|
89
|
+
}
|
|
90
|
+
// Fallback to regular transfer
|
|
73
91
|
const hash = await walletProvider.sendTransaction({
|
|
74
92
|
to: args.contractAddress,
|
|
75
93
|
data: (0, viem_1.encodeFunctionData)({
|
|
@@ -74,6 +74,10 @@ describe("Transfer Action", () => {
|
|
|
74
74
|
mockWallet = {
|
|
75
75
|
sendTransaction: jest.fn(),
|
|
76
76
|
waitForTransactionReceipt: jest.fn(),
|
|
77
|
+
getName: jest.fn().mockReturnValue("evm_wallet_provider"),
|
|
78
|
+
getNetwork: jest.fn().mockReturnValue({
|
|
79
|
+
networkId: "base-mainnet",
|
|
80
|
+
}),
|
|
77
81
|
};
|
|
78
82
|
mockWallet.sendTransaction.mockResolvedValue(TRANSACTION_HASH);
|
|
79
83
|
mockWallet.waitForTransactionReceipt.mockResolvedValue({});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
|
|
1
|
+
import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, Abi, ContractFunctionName, ContractFunctionArgs, Address, Hex } from "viem";
|
|
2
2
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
3
3
|
import { Network } from "../network";
|
|
4
|
-
import { CreateERC20Options, CreateTradeOptions, SmartContract, Trade, Wallet, WalletData } from "@coinbase/coinbase-sdk";
|
|
4
|
+
import { Coinbase, CreateERC20Options, CreateTradeOptions, SmartContract, Trade, Wallet, WalletData } from "@coinbase/coinbase-sdk";
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options for the CDP Providers.
|
|
7
7
|
*/
|
|
@@ -233,5 +233,14 @@ export declare class CdpWalletProvider extends EvmWalletProvider {
|
|
|
233
233
|
* @returns The wallet.
|
|
234
234
|
*/
|
|
235
235
|
getWallet(): Wallet;
|
|
236
|
+
/**
|
|
237
|
+
* ERC20 transfer method
|
|
238
|
+
*
|
|
239
|
+
* @param assetId - The asset ID to transfer. Either USDC, CBBTC or EURC
|
|
240
|
+
* @param destination - The destination address
|
|
241
|
+
* @param amount - The amount to transfer
|
|
242
|
+
* @returns The transaction hash
|
|
243
|
+
*/
|
|
244
|
+
gaslessERC20Transfer(assetId: typeof Coinbase.assets.Usdc | typeof Coinbase.assets.Cbbtc | typeof Coinbase.assets.Eurc, destination: Address, amount: bigint): Promise<Hex>;
|
|
236
245
|
}
|
|
237
246
|
export {};
|
|
@@ -392,6 +392,30 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
392
392
|
}
|
|
393
393
|
return __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f");
|
|
394
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* ERC20 transfer method
|
|
397
|
+
*
|
|
398
|
+
* @param assetId - The asset ID to transfer. Either USDC, CBBTC or EURC
|
|
399
|
+
* @param destination - The destination address
|
|
400
|
+
* @param amount - The amount to transfer
|
|
401
|
+
* @returns The transaction hash
|
|
402
|
+
*/
|
|
403
|
+
async gaslessERC20Transfer(assetId, destination, amount) {
|
|
404
|
+
if (!__classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f")) {
|
|
405
|
+
throw new Error("Wallet not initialized");
|
|
406
|
+
}
|
|
407
|
+
const transferResult = await __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f").createTransfer({
|
|
408
|
+
amount,
|
|
409
|
+
assetId,
|
|
410
|
+
destination,
|
|
411
|
+
gasless: true,
|
|
412
|
+
});
|
|
413
|
+
const result = await transferResult.wait();
|
|
414
|
+
if (!result.getTransactionHash()) {
|
|
415
|
+
throw new Error("Transaction hash not found");
|
|
416
|
+
}
|
|
417
|
+
return result.getTransactionHash();
|
|
418
|
+
}
|
|
395
419
|
}
|
|
396
420
|
exports.CdpWalletProvider = CdpWalletProvider;
|
|
397
421
|
_CdpWalletProvider_cdpWallet = new WeakMap(), _CdpWalletProvider_address = new WeakMap(), _CdpWalletProvider_network = new WeakMap(), _CdpWalletProvider_publicClient = new WeakMap(), _CdpWalletProvider_gasLimitMultiplier = new WeakMap(), _CdpWalletProvider_feePerGasMultiplier = new WeakMap();
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@coinbase/agentkit",
|
|
3
3
|
"description": "Coinbase AgentKit core primitives",
|
|
4
4
|
"repository": "https://github.com/coinbase/agentkit",
|
|
5
|
-
"version": "0.2.3-nightly.
|
|
5
|
+
"version": "0.2.3-nightly.20250318.40",
|
|
6
6
|
"author": "Coinbase Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.js",
|