Skip to content

Commit 56528dc

Browse files
hack override all transactions
1 parent 7dda2e3 commit 56528dc

File tree

18 files changed

+151
-55
lines changed

18 files changed

+151
-55
lines changed

apps/dashboard/src/@/constants/thirdweb.server.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ import {
44
IPFS_GATEWAY_URL,
55
} from "@/constants/env";
66
import {
7+
THIRDWEB_BUNDLER_DOMAIN,
78
THIRDWEB_INAPP_WALLET_DOMAIN,
89
THIRDWEB_PAY_DOMAIN,
910
THIRDWEB_RPC_DOMAIN,
1011
THIRDWEB_SOCIAL_API_DOMAIN,
1112
THIRDWEB_STORAGE_DOMAIN,
1213
} from "constants/urls";
1314
import { createThirdwebClient } from "thirdweb";
14-
import { setThirdwebDomains } from "thirdweb/utils";
15+
import {
16+
getTransactionDecorator,
17+
setThirdwebDomains,
18+
setTransactionDecorator,
19+
} from "thirdweb/utils";
20+
import { getZkPaymasterData } from "thirdweb/wallets/smart";
1521
import { getVercelEnv } from "../../lib/vercel-utils";
1622

1723
// returns a thirdweb client with optional JWT passed in
@@ -24,8 +30,39 @@ export function getThirdwebClient(jwt?: string) {
2430
pay: THIRDWEB_PAY_DOMAIN,
2531
storage: THIRDWEB_STORAGE_DOMAIN,
2632
social: THIRDWEB_SOCIAL_API_DOMAIN,
33+
bundler: THIRDWEB_BUNDLER_DOMAIN,
2734
});
2835
}
36+
37+
if (!getTransactionDecorator()) {
38+
setTransactionDecorator(async ({ account, transaction }) => {
39+
// special override for sophon testnet (zk chain)
40+
// sophon only allows transactions through their paymaster
41+
// so always use eip712 txs with paymaster
42+
if (transaction.chain.id === 531050104) {
43+
const pmData = await getZkPaymasterData({
44+
options: {
45+
client: transaction.client,
46+
chain: transaction.chain,
47+
},
48+
transaction,
49+
});
50+
return {
51+
account,
52+
transaction: {
53+
...transaction,
54+
eip712: {
55+
...transaction.eip712,
56+
paymaster: pmData.paymaster,
57+
paymasterInput: pmData.paymasterInput,
58+
},
59+
},
60+
};
61+
}
62+
return { account, transaction };
63+
});
64+
}
65+
2966
return createThirdwebClient({
3067
secretKey: jwt ? jwt : DASHBOARD_THIRDWEB_SECRET_KEY,
3168
clientId: DASHBOARD_THIRDWEB_CLIENT_ID,

apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Image from "next/image";
1313
import Link from "next/link";
1414
import { usePathname } from "next/navigation";
1515
import { useCallback, useMemo, useState } from "react";
16-
import type { Chain } from "thirdweb";
16+
import { type Chain } from "thirdweb";
1717
import {
1818
AutoConnect,
1919
ConnectButton,

apps/dashboard/src/components/buttons/MismatchButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { useV5DashboardChain } from "../../lib/v5-adapter";
5959
const GAS_FREE_CHAINS = [
6060
75513, // Geek verse testnet
6161
75512, // Geek verse mainnet
62+
531050104, // sophon testnet
6263
];
6364

6465
function useNetworkMismatchAdapter(desiredChainId: number) {

apps/dashboard/src/constants/urls.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ export const THIRDWEB_STORAGE_DOMAIN =
2424

2525
export const THIRDWEB_SOCIAL_API_DOMAIN =
2626
process.env.NEXT_PUBLIC_SOCIAL_URL || "social.thirdweb-dev.com";
27+
28+
export const THIRDWEB_BUNDLER_DOMAIN =
29+
process.env.NEXT_PUBLIC_BUNDLER_URL || "bundler.thirdweb-dev.com";

packages/thirdweb/src/contract/deployment/zksync/zkDeployContract.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export async function zkDeployContract(
3737
),
3838
});
3939

40-
console.log("deploying", options.deploymentType);
41-
4240
const receipt = await sendAndConfirmTransaction({
4341
account: options.account,
4442
transaction: prepareTransaction({
@@ -49,23 +47,17 @@ export async function zkDeployContract(
4947
eip712: {
5048
factoryDeps: [options.bytecode],
5149
// TODO (zksync): allow passing in a paymaster
52-
paymaster: "0x950e3Bb8C6bab20b56a70550EC037E22032A413e",
53-
paymasterInput:
54-
"0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
5550
},
5651
}),
5752
});
5853

59-
console.log("receipt", receipt);
60-
6154
const events = parseEventLogs({
6255
logs: receipt.logs,
6356
events: [contractDeployedEvent()],
6457
});
6558

6659
const contractAddress = events[0]?.args.contractAddress;
6760

68-
console.log("deployed contractAddress", contractAddress);
6961
if (!contractAddress) {
7062
throw new Error("Contract creation failed");
7163
}

packages/thirdweb/src/contract/deployment/zksync/zkDeployCreate2Factory.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ export async function zkDeployCreate2Factory(
3434
client: options.client,
3535
privateKey: PUBLISHED_PRIVATE_KEY,
3636
});
37-
console.log("create2Signer", create2Signer);
37+
3838
const valueToSend = toWei("0.01");
3939
const balance = await getWalletBalance({
4040
address: create2Signer.address,
4141
chain: options.chain,
4242
client: options.client,
4343
});
44-
console.log("balance", balance);
4544

4645
if (balance.value < valueToSend) {
4746
await sendAndConfirmTransaction({
48-
account: create2Signer,
47+
account: options.account,
4948
transaction: prepareTransaction({
5049
chain: options.chain,
5150
client: options.client,

packages/thirdweb/src/contract/deployment/zksync/zkDeployProxy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export async function zkDeployProxy(
3838
`Implementation contract at ${implementationAddress} is not deployed`,
3939
);
4040
}
41-
console.log("deploying tw proxy");
4241
// deploy tw proxy of the implementation
4342
const proxyAddress = await zkDeployContractDeterministic({
4443
client: options.client,

packages/thirdweb/src/exports/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export { encodePacked } from "viem";
147147
// Useful helpers
148148
export { setThirdwebDomains } from "../utils/domains.js";
149149
export { resolvePromisedValue } from "../utils/promise/resolve-promised-value.js";
150+
export {
151+
setTransactionDecorator,
152+
getTransactionDecorator,
153+
clearTransactionDecorator,
154+
} from "../utils/accounts.js";
150155

151156
// ------------------------------------------------
152157
// json

packages/thirdweb/src/exports/wallets/smart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {
2121
} from "../../wallets/smart/lib/calls.js";
2222

2323
export { getPaymasterAndData } from "../../wallets/smart/lib/paymaster.js";
24+
export { getZkPaymasterData } from "../../wallets/smart/lib/bundler.js";
2425

2526
export type {
2627
SmartWalletConnectionOptions,

packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,43 @@ export async function getRequiredTransactions(
5151
| DeployTransactionResult[]
5252
| null
5353
)[] = await Promise.all([
54-
getDeployedCreate2Factory({
55-
chain,
56-
client,
57-
}).then((c) =>
58-
c || isZkSync
59-
? null
60-
: ({ type: "infra", contractId: "Create2Factory" } as const),
61-
),
62-
getDeployedInfraContract({
63-
chain,
64-
client,
65-
contractId: "Forwarder",
66-
}).then((c) =>
67-
c || isZkSync
68-
? null
69-
: ({ type: "infra", contractId: "Forwarder" } as const),
70-
),
71-
getDeployedInfraContract({
72-
chain,
73-
client,
74-
contractId: "TWCloneFactory",
75-
constructorParams: {
76-
_trustedForwarder: await computePublishedContractAddress({
54+
isZkSync
55+
? null
56+
: getDeployedCreate2Factory({
57+
chain,
58+
client,
59+
}).then((c) =>
60+
c
61+
? null
62+
: ({ type: "infra", contractId: "Create2Factory" } as const),
63+
),
64+
isZkSync
65+
? null
66+
: getDeployedInfraContract({
7767
chain,
7868
client,
7969
contractId: "Forwarder",
80-
}),
81-
},
82-
}).then((c) =>
83-
c || isZkSync
84-
? null
85-
: ({ type: "infra", contractId: "TWCloneFactory" } as const),
86-
),
70+
}).then((c) =>
71+
c ? null : ({ type: "infra", contractId: "Forwarder" } as const),
72+
),
73+
isZkSync
74+
? null
75+
: getDeployedInfraContract({
76+
chain,
77+
client,
78+
contractId: "TWCloneFactory",
79+
constructorParams: {
80+
_trustedForwarder: await computePublishedContractAddress({
81+
chain,
82+
client,
83+
contractId: "Forwarder",
84+
}),
85+
},
86+
}).then((c) =>
87+
c
88+
? null
89+
: ({ type: "infra", contractId: "TWCloneFactory" } as const),
90+
),
8791
// TODO (deploy): add WETH contract check for implementations that need it (check implementation constructor params)
8892
getTransactionsForImplementation({
8993
chain,

0 commit comments

Comments
 (0)