Skip to content

Commit a15190d

Browse files
hack override all transactions
1 parent 7dda2e3 commit a15190d

File tree

19 files changed

+161
-62
lines changed

19 files changed

+161
-62
lines changed

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ 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 { populateEip712Transaction } from "thirdweb/transaction";
16+
import {
17+
getTransactionDecorator,
18+
setThirdwebDomains,
19+
setTransactionDecorator,
20+
} from "thirdweb/utils";
21+
import { getZkPaymasterData } from "thirdweb/wallets/smart";
1522
import { getVercelEnv } from "../../lib/vercel-utils";
1623

1724
// returns a thirdweb client with optional JWT passed in
@@ -24,8 +31,43 @@ export function getThirdwebClient(jwt?: string) {
2431
pay: THIRDWEB_PAY_DOMAIN,
2532
storage: THIRDWEB_STORAGE_DOMAIN,
2633
social: THIRDWEB_SOCIAL_API_DOMAIN,
34+
bundler: THIRDWEB_BUNDLER_DOMAIN,
2735
});
2836
}
37+
38+
if (!getTransactionDecorator()) {
39+
setTransactionDecorator(async ({ account, transaction }) => {
40+
// special override for sophon testnet (zk chain)
41+
// sophon only allows transactions through their paymaster
42+
// so always use eip712 tx + paymaster
43+
if (transaction.chain.id === 531050104) {
44+
const serializedTx = await populateEip712Transaction({
45+
transaction,
46+
account,
47+
});
48+
const pmData = await getZkPaymasterData({
49+
options: {
50+
client: transaction.client,
51+
chain: transaction.chain,
52+
},
53+
transaction: serializedTx,
54+
});
55+
return {
56+
account,
57+
transaction: {
58+
...transaction,
59+
eip712: {
60+
...transaction.eip712,
61+
paymaster: pmData.paymaster,
62+
paymasterInput: pmData.paymasterInput,
63+
},
64+
},
65+
};
66+
}
67+
return { account, transaction };
68+
});
69+
}
70+
2971
return createThirdwebClient({
3072
secretKey: jwt ? jwt : DASHBOARD_THIRDWEB_SECRET_KEY,
3173
clientId: DASHBOARD_THIRDWEB_CLIENT_ID,

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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,27 @@ export async function zkDeployCreate2Factory(
3030
return ZKSYNC_SINGLETON_FACTORY;
3131
}
3232

33+
if (!PUBLISHED_PRIVATE_KEY) {
34+
throw new Error(
35+
`Unable to deploy create2 factory on chain ${options.chain.id} - please contact us via https://thirdweb.com/support to enable this chain`,
36+
);
37+
}
38+
3339
const create2Signer = privateKeyToAccount({
3440
client: options.client,
3541
privateKey: PUBLISHED_PRIVATE_KEY,
3642
});
37-
console.log("create2Signer", create2Signer);
43+
3844
const valueToSend = toWei("0.01");
3945
const balance = await getWalletBalance({
4046
address: create2Signer.address,
4147
chain: options.chain,
4248
client: options.client,
4349
});
44-
console.log("balance", balance);
4550

4651
if (balance.value < valueToSend) {
4752
await sendAndConfirmTransaction({
48-
account: create2Signer,
53+
account: options.account,
4954
transaction: prepareTransaction({
5055
chain: options.chain,
5156
client: options.client,

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import { keccakId } from "../../../utils/any-evm/keccak-id.js";
99
import { computeDeploymentAddress } from "../../../utils/any-evm/zksync/computeDeploymentAddress.js";
1010
import {
1111
KNOWN_CODES_STORAGE,
12-
PUBLISHED_PRIVATE_KEY,
1312
singletonFactoryAbi,
1413
} from "../../../utils/any-evm/zksync/constants.js";
1514
import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js";
1615
import { ensureBytecodePrefix } from "../../../utils/bytecode/prefix.js";
1716
import { type Hex, uint8ArrayToHex } from "../../../utils/encoding/hex.js";
1817
import type { ClientAndChainAndAccount } from "../../../utils/types.js";
19-
import { privateKeyToAccount } from "../../../wallets/private-key.js";
2018
import { getContract } from "../../contract.js";
2119
import { zkDeployContract } from "./zkDeployContract.js";
2220
import { zkDeployCreate2Factory } from "./zkDeployCreate2Factory.js";
@@ -71,15 +69,10 @@ export async function zkDeployContractDeterministic(
7169
});
7270
// if not known, publish the bytecodehash
7371
if (marker !== 1n) {
74-
console.log("deploying marker");
75-
const create2Signer = privateKeyToAccount({
76-
client: options.client,
77-
privateKey: PUBLISHED_PRIVATE_KEY,
78-
});
7972
await zkDeployContract({
8073
client: options.client,
8174
chain: options.chain,
82-
account: create2Signer,
75+
account: options.account,
8376
abi: options.abi,
8477
bytecode,
8578
params: options.params,

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/transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export {
5959
type StoredTransaction,
6060
getTransactionStore,
6161
} from "../transaction/transaction-store.js";
62+
export { populateEip712Transaction } from "../transaction/actions/zksync/send-eip712-transaction.js";
6263

6364
//types & utils
6465
export {

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/config.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,

0 commit comments

Comments
 (0)