Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: map chainId to networkId #196

Merged
merged 1 commit into from
Jan 31, 2025
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
chore: map chainId to networkId
  • Loading branch information
0xRAG committed Jan 31, 2025
commit 5972db4f202facb6cb7b56016e936641f6f9deed
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { WalletProvider } from "../wallet_providers/wallet_provider";
import { Network } from "../wallet_providers/wallet_provider";
import { Network } from "../network";
import { StoredActionMetadata, ACTION_DECORATOR_KEY } from "./action_decorator";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { encodeFunctionData, Hex, namehash, parseEther } from "viem";
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network } from "../../wallet_providers/wallet_provider";
import { Network } from "../../network";
import { CreateAction } from "../action_decorator";
import {
L2_RESOLVER_ADDRESS_MAINNET,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network, EvmWalletProvider } from "../../wallet_providers";
import { EvmWalletProvider } from "../../wallet_providers";
import { CreateAction } from "../action_decorator";
import { Coinbase, ExternalAddress } from "@coinbase/coinbase-sdk";
import { AddressReputationSchema, RequestFaucetFundsSchema } from "./schemas";
import { Network } from "../../network";

/**
* Configuration options for the CdpActionProvider.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network } from "../../wallet_providers/wallet_provider";
import { Network } from "../../network";
import { CreateAction } from "../action_decorator";
import { GetBalanceSchema, TransferSchema } from "./schemas";
import { abi } from "./constants";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network, EvmWalletProvider } from "../../wallet_providers";
import { EvmWalletProvider } from "../../wallet_providers";
import { CreateAction } from "../action_decorator";
import { GetBalanceSchema, MintSchema, TransferSchema } from "./schemas";
import { ERC721_ABI } from "./constants";
import { encodeFunctionData, Hex } from "viem";
import { Network } from "../../network";

/**
* Erc721ActionProvider is an action provider for Erc721 contract interactions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network } from "../../wallet_providers";
import { Network } from "../../network";
import { CreateAction } from "../action_decorator";
import { FarcasterAccountDetailsSchema, FarcasterPostCastSchema } from "./schemas";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Decimal } from "decimal.js";
import { encodeFunctionData, parseEther } from "viem";

import { ActionProvider } from "../action_provider";
import { Network, EvmWalletProvider } from "../../wallet_providers";
import { EvmWalletProvider } from "../../wallet_providers";
import { CreateAction } from "../action_decorator";
import { approve } from "../../utils";
import { METAMORPHO_ABI } from "./constants";
import { DepositSchema, WithdrawSchema } from "./schemas";
import { Network } from "../../network";

export const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { CreateAction } from "../action_decorator";
import { TwitterApi, TwitterApiTokens } from "twitter-api-v2";
import { Network } from "../../wallet_providers/wallet_provider";
import { Network } from "../../network";
import {
TwitterAccountDetailsSchema,
TwitterAccountMentionsSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network, WalletProvider } from "../../wallet_providers/wallet_provider";
import { WalletProvider } from "../../wallet_providers/wallet_provider";
import { CreateAction } from "../action_decorator";
import { Network } from "../../network";

/**
* Schema for the get_wallet_details action.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network } from "../../wallet_providers/wallet_provider";
import { Network } from "../../network";
import { CreateAction } from "../action_decorator";
import { WrapEthSchema } from "./schemas";
import { WETH_ABI, WETH_ADDRESS } from "./constants";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { Network, EvmWalletProvider } from "../../wallet_providers";
import { EvmWalletProvider } from "../../wallet_providers";
import { CreateAction } from "../action_decorator";
import { Network } from "../../network";
import {
SUPPORTED_NETWORKS,
WOW_ABI,
Expand Down
1 change: 1 addition & 0 deletions cdp-agentkit-core/typescript/src/network/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./types";
15 changes: 15 additions & 0 deletions cdp-agentkit-core/typescript/src/network/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Maps EVM chain IDs to Coinbase network IDs
*/
export const CHAIN_ID_TO_NETWORK_ID: Record<number, string> = {
1: "ethereum-mainnet",
11155111: "ethereum-sepolia",
137: "polygon-mainnet",
80001: "polygon-mumbai",
8453: "base-mainnet",
84532: "base-sepolia",
42161: "arbitrum-mainnet",
421614: "arbitrum-sepolia",
10: "optimism-mainnet",
11155420: "optimism-sepolia",
};
19 changes: 19 additions & 0 deletions cdp-agentkit-core/typescript/src/network/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Network is the network that the wallet provider is connected to.
*/
export interface Network {
/**
* The protocol family of the network.
*/
protocolFamily: string;

/**
* The network ID of the network.
*/
networkId?: string;

/**
* The chain ID of the network.
*/
chainId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
import { EvmWalletProvider } from "./evm_wallet_provider";
import { Network } from "./wallet_provider";
import { Network } from "../network";

/**
* A wallet provider that uses the Coinbase SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
ReadContractReturnType,
} from "viem";
import { EvmWalletProvider } from "./evm_wallet_provider";
import { Network } from "./wallet_provider";
import { Network } from "../network";
import { CHAIN_ID_TO_NETWORK_ID } from "../network/network";

/**
* A wallet provider that uses the Viem library.
Expand Down Expand Up @@ -119,6 +120,7 @@ export class ViemWalletProvider extends EvmWalletProvider {
return {
protocolFamily: "evm" as const,
chainId: this.#walletClient.chain!.id! as any as string,
networkId: CHAIN_ID_TO_NETWORK_ID[this.#walletClient.chain!.id!],
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
/**
* Network is the network that the wallet provider is connected to.
*/
export interface Network {
/**
* The protocol family of the network.
*/
protocolFamily: string;

/**
* The network ID of the network.
*/
networkId?: string;

/**
* The chain ID of the network.
*/
chainId?: string;
}
import { Network } from "../network";

/**
* WalletProvider is the abstract base class for all wallet providers.
Expand Down