Skip to content

Commit 6fcb1ee

Browse files
hack override all transactions
1 parent 7dda2e3 commit 6fcb1ee

File tree

9 files changed

+96
-35
lines changed

9 files changed

+96
-35
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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,
@@ -24,6 +25,7 @@ export function getThirdwebClient(jwt?: string) {
2425
pay: THIRDWEB_PAY_DOMAIN,
2526
storage: THIRDWEB_STORAGE_DOMAIN,
2627
social: THIRDWEB_SOCIAL_API_DOMAIN,
28+
bundler: THIRDWEB_BUNDLER_DOMAIN,
2729
});
2830
}
2931
return createThirdwebClient({

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/components/contract-components/contract-deploy-form/custom-contract.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from "thirdweb/deploys";
3838
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
3939
import { upload } from "thirdweb/storage";
40+
import { type Account, smartWallet } from "thirdweb/wallets";
4041
import { FormHelperText, FormLabel, Heading, Text } from "tw-components";
4142
import { useCustomFactoryAbi, useFunctionParamsFromABI } from "../hooks";
4243
import { addContractToMultiChainRegistry } from "../utils";
@@ -438,8 +439,21 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
438439
: params.saltForCreate2
439440
: undefined;
440441

442+
let accountOverride: Account | undefined;
443+
if (walletChain.id === 531050104) {
444+
// sophon testnet - can only use with their paymaster
445+
const sw = smartWallet({
446+
chain: walletChain,
447+
sponsorGas: true,
448+
});
449+
accountOverride = await sw.connect({
450+
client: thirdwebClient,
451+
personalAccount: activeAccount,
452+
});
453+
}
454+
441455
return await deployContractfromDeployMetadata({
442-
account: activeAccount,
456+
account: accountOverride ?? activeAccount,
443457
chain: walletChain,
444458
client: thirdwebClient,
445459
deployMetadata: metadata,

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/extensions/erc1155/customDrop1155.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { fetchDeployMetadata } from "../../utils/any-evm/deploy-metadata.js";
22

33
import { beforeAll, describe, expect, it } from "vitest";
4-
import { VITALIK_WALLET } from "../../../test/src/addresses.js";
54
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
65
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
76
import {
@@ -128,7 +127,6 @@ describe.runIf(process.env.TW_SECRET_KEY)(
128127
{
129128
overrideList: [
130129
{ address: TEST_ACCOUNT_C.address, maxClaimable: "100" },
131-
{ address: VITALIK_WALLET, maxClaimable: "100" },
132130
],
133131
maxClaimablePerWallet: 0n,
134132
},

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,

packages/thirdweb/src/transaction/actions/send-transaction.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ export async function sendTransaction(
174174
});
175175
}
176176

177+
if (transaction.chain.id === 531050104 && !options.transaction.eip712) {
178+
// sophon testnet - can only use with their paymaster
179+
const { smartWallet } = await import("../../wallets/smart/smart-wallet.js");
180+
const sw = smartWallet({
181+
chain: transaction.chain,
182+
sponsorGas: true,
183+
});
184+
const smartAccount = await sw.connect({
185+
client: transaction.client,
186+
personalAccount: account,
187+
});
188+
const result = await smartAccount.sendTransaction(serializableTransaction);
189+
// Store the transaction
190+
addTransactionToStore({
191+
address: account.address,
192+
transactionHash: result.transactionHash,
193+
chainId: transaction.chain.id,
194+
});
195+
return { ...result, chain: transaction.chain, client: transaction.client };
196+
}
197+
177198
const result = await account.sendTransaction(serializableTransaction);
178199
// Store the transaction
179200
addTransactionToStore({

packages/thirdweb/src/utils/fetch.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export function getClientFetch(client: ThirdwebClient, ecosystem?: Ecosystem) {
4747

4848
// if we have an auth token set, use that (thirdweb.com/dashboard sets this for the user)
4949
// pay urls should never send the auth token, because we always want the "developer" to be the one making the request, not the "end user"
50-
if (authToken && !isPayUrl(url) && !isInAppWalletUrl(url)) {
50+
if (
51+
authToken &&
52+
!isPayUrl(url) &&
53+
!isInAppWalletUrl(url) &&
54+
!isBundlerUrl(url)
55+
) {
5156
headers.set("authorization", `Bearer ${authToken}`);
5257
} else if (secretKey) {
5358
headers.set("x-secret-key", secretKey);
@@ -153,6 +158,19 @@ function isInAppWalletUrl(url: string): boolean {
153158
}
154159
}
155160

161+
function isBundlerUrl(url: string): boolean {
162+
try {
163+
const { hostname } = new URL(url);
164+
// in app wallet service hostname always starts with "in-app-wallet." or "embedded-wallet."
165+
return (
166+
hostname.endsWith("bundler.thirdweb.com") ||
167+
hostname.endsWith("bundler.thirdweb-dev.com")
168+
);
169+
} catch {
170+
return false;
171+
}
172+
}
173+
156174
const SDK_NAME = "unified-sdk";
157175

158176
let previousPlatform: [string, string][] | undefined;

0 commit comments

Comments
 (0)