Skip to content

Commit 04fee1e

Browse files
committed
feat: add gas sponsorship, few ui tweaks
1 parent 7fa3a2e commit 04fee1e

12 files changed

Lines changed: 586 additions & 157 deletions

File tree

resources/version.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
EXPERIMENTAL BUILD
2-
FOR INTERNAL USE ONLY
1+
Masters Tournament
2+
Executed Secured by EigenCloud

src/client/Contract.ts

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {
22
createPublicClient,
3-
createWalletClient,
4-
custom,
53
encodeFunctionData,
64
formatEther,
75
formatUnits,
@@ -39,17 +37,24 @@ const publicClient = createPublicClient({
3937
chain: base,
4038
transport: RPC_URL ? http(RPC_URL) : http(),
4139
});
42-
let walletClientCache: any | null = null;
43-
44-
async function getWalletClient() {
45-
if (walletClientCache) return walletClientCache;
46-
const provider = await window.privyWallet?.getEmbeddedProvider?.();
47-
if (!provider) throw new Error("Embedded wallet provider unavailable");
48-
walletClientCache = createWalletClient({
49-
chain: base,
50-
transport: custom(provider),
51-
});
52-
return walletClientCache;
40+
41+
type SponsoredTransactionInput = {
42+
to?: `0x${string}`;
43+
data?: `0x${string}`;
44+
value?: bigint;
45+
gas?: bigint;
46+
};
47+
48+
function getSponsoredSender(): (
49+
tx: SponsoredTransactionInput,
50+
) => Promise<`0x${string}`> {
51+
const sender = window.privyWallet?.sendSponsoredTransaction;
52+
if (!sender) {
53+
throw new Error(
54+
"Privy gas sponsorship unavailable. Ensure Privy provider initialized.",
55+
);
56+
}
57+
return sender;
5358
}
5459

5560
async function wagmiRead(params: {
@@ -72,29 +77,38 @@ async function wagmiWrite(params: {
7277
const walletManager = WalletManager.getInstance();
7378
const account = walletManager.address as `0x${string}` | undefined;
7479
if (!account) throw new Error("No connected wallet");
75-
const client = await getWalletClient();
7680

77-
const { address, abi, functionName, args, value } = params;
81+
const { address, abi, functionName, args, value, gas } = params;
7882
const data = encodeFunctionData({
7983
abi,
8084
functionName,
8185
args: args ?? [],
8286
});
8387

84-
const request: any = {
85-
account,
86-
chain: base,
88+
const sendSponsored = getSponsoredSender();
89+
90+
const txRequest: {
91+
to: `0x${string}`;
92+
data?: `0x${string}`;
93+
value?: bigint;
94+
gas?: bigint;
95+
} = {
8796
to: address,
88-
data,
8997
};
9098

99+
if (data && data !== "0x") {
100+
txRequest.data = data as `0x${string}`;
101+
}
102+
91103
if (typeof value !== "undefined") {
92-
request.value = value;
104+
txRequest.value = value;
93105
}
94106

95-
return await client.sendTransaction(request, {
96-
sponsor: true,
97-
});
107+
if (typeof gas !== "undefined") {
108+
txRequest.gas = gas;
109+
}
110+
111+
return (await sendSponsored(txRequest)) as Hash;
98112
}
99113

100114
function wagmiWatch(params: {
@@ -265,19 +279,13 @@ async function sendNativeTransaction(to: `0x${string}`, value: bigint) {
265279
const walletManager = WalletManager.getInstance();
266280
const account = walletManager.address as `0x${string}` | undefined;
267281
if (!account) throw new Error("No connected wallet");
268-
const client = await getWalletClient();
269282

270-
const request: any = {
271-
account,
272-
chain: base,
283+
const sendSponsored = getSponsoredSender();
284+
285+
return (await sendSponsored({
273286
to,
274287
value,
275-
data: "0x",
276-
};
277-
278-
return await client.sendTransaction(request, {
279-
sponsor: true,
280-
});
288+
})) as Hash;
281289
}
282290

283291
export async function withdrawAsset(params: {
@@ -446,12 +454,16 @@ async function ensureErc20Allowance(params: {
446454
current: currentAllowance.toString(),
447455
});
448456

449-
await wagmiWrite({
457+
const hash = await wagmiWrite({
450458
address: token,
451459
abi: ERC20_ABI,
452460
functionName: "approve",
453461
args: [CONTRACT_ADDRESS, amount],
454462
});
463+
464+
await publicClient.waitForTransactionReceipt({
465+
hash,
466+
});
455467
}
456468

457469
export interface SetAllowlistEnabledParams {

src/client/InitPrivy.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,11 @@ export function initializePrivy() {
3232
"wallet-button-container",
3333
);
3434
if (!walletButtonContainer) {
35-
// Find the connect-wallet button and replace it with our container
36-
const connectWalletButton = document.getElementById("connect-wallet");
37-
if (connectWalletButton) {
35+
const anchor = document.getElementById("wallet-button-anchor");
36+
if (anchor) {
3837
walletButtonContainer = document.createElement("div");
3938
walletButtonContainer.id = "wallet-button-container";
40-
walletButtonContainer.style.cssText = `
41-
width: 100%;
42-
margin-bottom: 1rem;
43-
`;
44-
connectWalletButton.parentNode?.insertBefore(
45-
walletButtonContainer,
46-
connectWalletButton,
47-
);
48-
connectWalletButton.remove();
39+
anchor.appendChild(walletButtonContainer);
4940
} else {
5041
// Fallback: add to body
5142
walletButtonContainer = document.createElement("div");

src/client/Main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ class Client {
522522
"language-modal",
523523
"news-modal",
524524
"flag-input-modal",
525-
"account-button",
526525
"token-login",
527526
].forEach((tag) => {
528527
const modal = document.querySelector(tag) as HTMLElement & {

0 commit comments

Comments
 (0)