Skip to content

Commit 91aa8d9

Browse files
authored
Update Packages & Remove near-safe dependency (#55)
We were only using near-safe for its native asset wrapped addresses. Added them here.
1 parent 04bd411 commit 91aa8d9

File tree

8 files changed

+357
-184
lines changed

8 files changed

+357
-184
lines changed

bun.lock

Lines changed: 312 additions & 139 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
"@duneanalytics/client-sdk": "^0.2.5",
2020
"@types/bun": "latest",
2121
"@types/jest": "^30.0.0",
22-
"@typescript-eslint/eslint-plugin": "^8.36.0",
23-
"@typescript-eslint/parser": "^8.36.0",
22+
"@typescript-eslint/eslint-plugin": "^8.40.0",
23+
"@typescript-eslint/parser": "^8.40.0",
2424
"csv-parser": "^3.2.0",
25-
"dotenv": "^17.2.0",
26-
"eslint": "^9.30.1",
27-
"jest": "^30.0.4",
28-
"next": "^15.3.5",
25+
"dotenv": "^17.2.1",
26+
"eslint": "^9.33.0",
27+
"jest": "^30.0.5",
28+
"next": "^15.5.0",
2929
"prettier": "^3.6.2",
30-
"ts-jest": "^29.4.0",
31-
"typescript": "^5.8.3"
30+
"ts-jest": "^29.4.1",
31+
"typescript": "^5.9.2"
3232
}
3333
}

packages/agent-sdk/package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@
3232
"build:cjs": "tsc -p tsconfig.cjs.json"
3333
},
3434
"dependencies": {
35-
"@bitte-ai/types": "^0.7.0",
36-
"near-safe": "^0.10.0",
37-
"viem": "^2.31.7",
38-
"zerion-sdk": "^0.1.4"
39-
},
40-
"peerDependencies": {
41-
"react": "^18.3.1",
42-
"react-dom": "^18.3.1"
35+
"@bitte-ai/types": "^0.8.1",
36+
"viem": "^2.34.0",
37+
"zerion-sdk": "^0.1.6"
4338
}
4439
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Address } from "viem";
2+
3+
export const CHAIN_INFO: Record<number, Address> = {
4+
1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // Ethereum Mainnet
5+
10: "0x4200000000000000000000000000000000000006", // Optimism
6+
56: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", // Binance Smart Chain
7+
97: "0x094616f0bdfb0b526bd735bf66eca0ad254ca81f", // Binance Testnet
8+
100: "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d", // Gnosis Chain
9+
137: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270", // Polygon
10+
8453: "0x4200000000000000000000000000000000000006", // Base
11+
10200: "0xb2D0d7aD1D4b2915390Dc7053b9421F735A723E7", // Gnosis Chiado Testnet
12+
42161: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", // Arbitrum
13+
43114: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", // Avalanche
14+
84532: "0x4200000000000000000000000000000000000006", // Base Sepolia
15+
80002: "0xa5733b3a8e62a8faf43b0376d5faf46e89b3033e", // Polygon Amoy
16+
421614: "0x980b62da83eff3d4576c647993b0c1d7faf17c73", // Arbitrum Sepolia
17+
11155111: "0xfff9976782d46cc05630d1f6ebab18b2324d6b14", // Sepolia
18+
11155420: "0x4200000000000000000000000000000000000006", // OP Testnet
19+
};

packages/agent-sdk/src/evm/weth.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
parseEther,
88
toHex,
99
} from "viem";
10-
import { Network } from "near-safe";
10+
import { CHAIN_INFO } from "./constants";
11+
import { getChainById } from "./chain";
1112

12-
type NativeAsset = {
13+
type WrappedAsset = {
1314
address: Address;
1415
symbol: string;
1516
scanUrl: string;
@@ -19,7 +20,7 @@ type NativeAsset = {
1920
export function validateWethInput(params: URLSearchParams): {
2021
chainId: number;
2122
amount: bigint;
22-
nativeAsset: NativeAsset;
23+
nativeAsset: WrappedAsset;
2324
} {
2425
const chainIdStr = params.get("chainId");
2526
const amountStr = params.get("amount");
@@ -78,18 +79,16 @@ export const wrapMetaTransaction = (
7879
};
7980
};
8081

81-
export function getNativeAsset(chainId: number): NativeAsset {
82-
const network = Network.fromChainId(chainId);
83-
const wethAddress = network.nativeCurrency.wrappedAddress;
82+
export function getNativeAsset(chainId: number): WrappedAsset {
83+
const wethAddress = CHAIN_INFO[chainId];
8484
if (!wethAddress) {
85-
throw new Error(
86-
`Couldn't find wrapped address for Network ${network.name} (chainId=${chainId})`,
87-
);
85+
throw new Error(`Couldn't find wrapped address for chainId=${chainId}`);
8886
}
87+
const chain = getChainById(chainId);
8988
return {
9089
address: getAddress(wethAddress),
91-
symbol: network.nativeCurrency.symbol,
92-
scanUrl: `${network.scanUrl}/address/${wethAddress}`,
93-
decimals: network.nativeCurrency.decimals,
90+
symbol: chain.nativeCurrency.symbol,
91+
scanUrl: `${chain.blockExplorers?.default.url}/address/${wethAddress}`,
92+
decimals: chain.nativeCurrency.decimals,
9493
};
9594
}

packages/agent-sdk/src/misc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MetaTransaction } from "near-safe";
1+
import { MetaTransaction } from "@bitte-ai/types";
22

33
export const NULL_TRANSACTION: MetaTransaction = {
44
to: "0x0000000000000000000000000000000000000000",

packages/agent-sdk/src/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { SignRequestData } from "near-safe";
1+
import { SignRequest } from "@bitte-ai/types";
22
import { errorString } from "./error";
33

44
export interface TxData {
5-
transaction?: SignRequestData;
5+
transaction?: SignRequest;
66
meta?: unknown;
77
}
88

packages/agent-sdk/tests/evm/weth.spec.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Network } from "near-safe";
21
import { parseEther } from "viem";
32
import {
43
validateWethInput,
@@ -114,20 +113,8 @@ describe("evm/weth", () => {
114113

115114
it("throws error for chain without wrapped address", () => {
116115
// Mock a network without wrapped address
117-
jest.spyOn(Network, "fromChainId").mockImplementationOnce(
118-
() =>
119-
({
120-
name: "TestNet",
121-
nativeCurrency: {
122-
wrappedAddress: null,
123-
symbol: "TEST",
124-
decimals: 18,
125-
},
126-
}) as unknown as Network,
127-
);
128-
129116
expect(() => getNativeAsset(999)).toThrow(
130-
"Couldn't find wrapped address for Network TestNet (chainId=999)",
117+
"Couldn't find wrapped address for chainId=999",
131118
);
132119
});
133120
});

0 commit comments

Comments
 (0)