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
10 changes: 10 additions & 0 deletions packages/agent-sdk/src/evm/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { encodeFunctionData, type Address } from "viem";
import { getClient, type MetaTransaction } from "near-safe";
import type { TokenInfo } from "./types";

const NATIVE_ASSET = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const MAX_APPROVAL = BigInt(
"115792089237316195423570985008687907853269984665640564039457584007913129639935",
);
Expand Down Expand Up @@ -60,6 +61,15 @@ export async function getTokenInfo(
chainId: number,
address: Address,
): Promise<TokenInfo> {
if (address.toLowerCase() === NATIVE_ASSET.toLowerCase()) {
return {
address: NATIVE_ASSET,
decimals: 18,
// Not all Native Assets are ETH, but enough are.
symbol: "ETH",
};
}

const [decimals, symbol] = await Promise.all([
getTokenDecimals(chainId, address),
getTokenSymbol(chainId, address),
Expand Down
13 changes: 13 additions & 0 deletions packages/agent-sdk/tests/evm/token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ describe("getTokenDetails", () => {
expect(tokenDetails).toBeDefined();
});

it("should return the token details for native asset", async () => {
const tokenDetails = await getTokenDetails(
8453,
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
);

expect(tokenDetails).toStrictEqual({
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
decimals: 18,
symbol: "ETH",
});
});

it("should return the token details for a given symbol", async () => {
const tokenDetails = await getTokenDetails(43114, "UNI");
expect(tokenDetails).toBeUndefined();
Expand Down