Skip to content
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: 2 additions & 0 deletions src/eoa/eoa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class EOA {
requiredFee: validatedPayload.requiredFee,
chainId: this.chainId,
signer: this.signer,
provider: this.provider,
});
}

Expand Down Expand Up @@ -158,6 +159,7 @@ export class EOA {
deposits: validatedPayload.deposits,
batchDepositContractAddress: chainConfig.BATCH_DEPOSIT_CONTRACT.address,
signer: this.signer,
provider: this.provider,
});
}
}
19 changes: 14 additions & 5 deletions src/eoa/eoaHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ETHER_TO_GWEI } from '../constants.js';
import { type SignerType } from '../types.js';
import { type SignerType, type ProviderType } from '../types.js';
import { Contract, type JsonRpcSigner } from 'ethers';
import { BatchDepositContract } from '../abi/BatchDeposit.js';
import { SignerRequiredError } from '../errors.js';
Expand All @@ -12,13 +12,16 @@ import {
// tx.wait() hangs forever (the hash never appears on-chain). Contract-wallet
// signers submit unchecked and resolve via the Safe's ExecutionSuccess log.
// This is the first dereference on both write flows, so it guards the signer.
const isSafeLikeSigner = async (signer: SignerType): Promise<boolean> => {
const isSafeLikeSigner = async (
signer: SignerType,
provider?: ProviderType | null,
): Promise<boolean> => {
if (!signer) {
throw new SignerRequiredError('submitEOATransaction');
}
return (
'sendUncheckedTransaction' in signer &&
(await isContractWalletSigner(signer))
(await isContractWalletSigner(signer, provider))
);
};

Expand All @@ -33,6 +36,7 @@ export async function submitEOAWithdrawalRequest({
requiredFee,
chainId,
signer,
provider,
}: {
pubkey: string;
allocation: number;
Expand All @@ -41,6 +45,7 @@ export async function submitEOAWithdrawalRequest({
requiredFee: string;
chainId: number;
signer: SignerType;
provider?: ProviderType | null;
}): Promise<{ txHash: string | null }> {
if (!withdrawalAddress) {
throw new Error('No withdrawal address provided');
Expand All @@ -52,12 +57,13 @@ export async function submitEOAWithdrawalRequest({
const amountInGwei = BigInt(Math.floor(Number(allocation) * ETHER_TO_GWEI));
const data = `0x${pubkey.slice(2)}${amountInGwei.toString(16).padStart(16, '0')}`;

if (await isSafeLikeSigner(signer)) {
if (await isSafeLikeSigner(signer, provider)) {
const txHash = await submitViaContractWalletAndWait({
signer: signer as JsonRpcSigner,
to: withdrawalContractAddress,
data,
value: BigInt(requiredFee),
provider,
});
return { txHash };
}
Expand All @@ -81,6 +87,7 @@ export async function submitEOABatchDeposit({
deposits,
batchDepositContractAddress,
signer,
provider,
}: {
deposits: Array<{
pubkey: string;
Expand All @@ -91,6 +98,7 @@ export async function submitEOABatchDeposit({
}>;
batchDepositContractAddress: string;
signer: SignerType;
provider?: ProviderType | null;
}): Promise<{ txHashes: string[] }> {
if (!deposits || deposits.length === 0) {
throw new Error('No deposits provided');
Expand All @@ -103,7 +111,7 @@ export async function submitEOABatchDeposit({
signer,
);

const useContractWallet = await isSafeLikeSigner(signer);
const useContractWallet = await isSafeLikeSigner(signer, provider);

const BATCH_SIZE = 500;
const txHashes: string[] = [];
Expand Down Expand Up @@ -137,6 +145,7 @@ export async function submitEOABatchDeposit({
[depositData],
),
value: totalValue,
provider,
});
txHashes.push(txHash);
continue;
Expand Down
20 changes: 13 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,19 @@ export class Client extends Base {

const checkSplitMainAddress = await isContractAvailable(
chainConfig.SPLITMAIN_CONTRACT.address,
this.signer.provider as ProviderType,
this.provider as ProviderType,
chainConfig.SPLITMAIN_CONTRACT.bytecode,
);

const checkMulticall3Address = await isContractAvailable(
chainConfig.MULTICALL3_CONTRACT.address,
this.signer.provider as ProviderType,
this.provider as ProviderType,
chainConfig.MULTICALL3_CONTRACT.bytecode,
);

const checkOWRFactoryAddress = await isContractAvailable(
chainConfig.OWR_FACTORY_CONTRACT.address,
this.signer.provider as ProviderType,
this.provider as ProviderType,
chainConfig.OWR_FACTORY_CONTRACT.bytecode,
);

Expand Down Expand Up @@ -388,11 +388,12 @@ export class Client extends Base {
chainId: this.chainId,
distributorFee: validatedPayload.distributorFee,
controllerAddress: validatedPayload.controllerAddress,
provider: this.provider,
});

const isSplitterDeployed = await isContractAvailable(
predictedSplitterAddress,
this.signer.provider as ProviderType,
this.provider as ProviderType,
);

const { withdrawal_address, fee_recipient_address } =
Expand Down Expand Up @@ -478,7 +479,7 @@ export class Client extends Base {

const checkSplitMainAddress = await isContractAvailable(
chainConfig.SPLITMAIN_CONTRACT.address,
this.signer.provider as ProviderType,
this.provider as ProviderType,
chainConfig.SPLITMAIN_CONTRACT.bytecode,
);

Expand Down Expand Up @@ -507,11 +508,12 @@ export class Client extends Base {
chainId: this.chainId,
distributorFee: validatedPayload.distributorFee,
controllerAddress: validatedPayload.controllerAddress,
provider: this.provider,
});

const isSplitterDeployed = await isContractAvailable(
predictedSplitterAddress,
this.signer.provider as ProviderType,
this.provider as ProviderType,
);

if (!isSplitterDeployed) {
Expand Down Expand Up @@ -561,7 +563,11 @@ export class Client extends Base {
}

const signer = this.signer;
return await getOWRTranches({ owrAddress, signer });
return await getOWRTranches({
owrAddress,
signer,
provider: this.provider,
});
}

/**
Expand Down
Loading
Loading