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

Uniswap V3 Support #119

Merged
merged 2 commits into from
Jan 15, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@safe-global/safe-gateway-typescript-sdk": "^3.22.6",
"near-api-js": "^5.0.1",
"near-ca": "^0.8.1",
"near-ca": "^0.8.2",
"semver": "^7.6.3",
"viem": "^2.22.8"
},
Expand Down
2 changes: 1 addition & 1 deletion src/near-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class NearSafe {
const lowerMpc = this.mpcAddress.toLowerCase();
// We allow zeroAddress (and and treat is as from = safe)
if (![lowerSafe, lowerMpc, lowerZero].includes(lowerFrom)) {
throw new Error(`Unexpected from address ${from}`);
throw new Error(`Unexpected from address ${from} - expected {}`);
}
return [this.address.toLowerCase(), lowerZero].includes(lowerFrom);
}
Expand Down
13 changes: 4 additions & 9 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import {
toBytes,
keccak256,
serializeSignature,
createPublicClient,
http,
} from "viem";

import { DEFAULT_SETUP_RPC } from "./constants";
import { PaymasterData, MetaTransaction, UserOperation } from "./types";

export const PLACEHOLDER_SIG = encodePacked(["uint48", "uint48"], [0, 0]);
Expand Down Expand Up @@ -67,12 +64,10 @@ export async function isContract(
return (await getClient(chainId).getCode({ address })) !== undefined;
}

export function getClient(chainId: number): PublicClient {
// TODO(bh2smith): Update defailt client URL in viem for sepolia.
if (chainId === 11155111) {
return createPublicClient({ transport: http(DEFAULT_SETUP_RPC) });
}
return Network.fromChainId(chainId).client;
export function getClient(chainId: number, rpcUrl?: string): PublicClient {
// Caution: rpcUrl might not be aligned with chainId!
const options = rpcUrl ? { rpcUrl } : {};
return Network.fromChainId(chainId, options).client;
}

export function metaTransactionsFromRequest(
Expand Down
19 changes: 18 additions & 1 deletion tests/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from "dotenv";
import { isHex } from "viem";
import { isHex, zeroAddress } from "viem";

import { DEFAULT_SAFE_SALT_NONCE, NearSafe } from "../src";
import { decodeTxData } from "../src/decode";
Expand Down Expand Up @@ -94,6 +94,23 @@ describe("Near Safe Requests", () => {
});
});

it("adapter: encodeEvmTx Uniswap V3", async () => {
const chainId = 43114;
const request = await adapter.requestRouter({
method: "eth_signTypedData_v4",
params: [
zeroAddress,
// eslint-disable-next-line quotes
'{"types":{"PermitSingle":[{"name":"details","type":"PermitDetails"},{"name":"spender","type":"address"},{"name":"sigDeadline","type":"uint256"}],"PermitDetails":[{"name":"token","type":"address"},{"name":"amount","type":"uint160"},{"name":"expiration","type":"uint48"},{"name":"nonce","type":"uint48"}],"EIP712Domain":[{"name":"name","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}]},"domain":{"name":"Permit2","chainId": 43114,"verifyingContract":"0x000000000022d473030f116ddee9f6b43ac78ba3"},"primaryType":"PermitSingle","message":{"details":{"token":"0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e","amount":"1461501637330902918203684832716283019655932542975","expiration":"1739457501","nonce":"0"},"spender":"0x4dae2f939acf50408e13d58534ff8c2776d45265","sigDeadline":"1736867301"}}',
],
chainId,
});
console.log(request);
expect(() =>
decodeTxData({ evmMessage: request.evmMessage, chainId })
).not.toThrow();
});

it("adapter: requestRouter", async () => {
const { evmMessage } = await adapter.requestRouter({
method: "eth_sendTransaction",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4257,10 +4257,10 @@ near-api-js@^5.0.1:
near-abi "0.1.1"
node-fetch "2.6.7"

near-ca@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/near-ca/-/near-ca-0.8.1.tgz#1157b27ffd8a782655017506c8896335b86da900"
integrity sha512-RHgnZU5duXnr2BwLnG/4uhaTWAt+UjbdHMvpA3b6Kfbl7VAcPH3REjro3MvaGAFPN9HH2RJcWKzQMg1z19NYFA==
near-ca@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/near-ca/-/near-ca-0.8.2.tgz#c4797b7e02a0f6b4859245e209eb261cc0a360c0"
integrity sha512-tmQ7DBqRDJN4M6DSLGAXEQ77aF39lTpcpNz8O1FQuvDDAaTR8F+6/VPxjxNkE51KO+IvgwGnTR13xDHCJoLHxw==
dependencies:
"@walletconnect/web3wallet" "^1.13.0"
elliptic "^6.5.6"
Expand Down
Loading