Skip to content

Commit 74071bf

Browse files
feat: update counterfactual contracts (#3179)
* feat: update counterfactual contracts * Get contracts addresses from indexer --------- Co-authored-by: Alexandru Matei <alexandrumatei3693@gmail.com>
1 parent a0ccfdc commit 74071bf

File tree

4 files changed

+10
-38
lines changed

4 files changed

+10
-38
lines changed

src/common/ContractAddresses.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import SCROLL_GAS_PRICE_ORACLE_ABI from "./abi/ScrollGasPriceOracle.json";
4040
import IOFT_ABI_FULL from "./abi/IOFT.json";
4141
import HYPERLIQUID_DEPOSIT_HANDLER_ABI from "./abi/HyperliquidDepositHandler.json";
4242
import SPOKE_POOL_PERIPHERY_ABI from "./abi/SpokePoolPeriphery.json";
43-
import COUNTERFACTUAL_DEPOSIT_FACTORY_ABI from "./abi/CounterfactualDepositFactory.json";
4443
import PERMIT2_ABI from "./abi/Permit2.json";
4544
export { IOFT_ABI_FULL };
4645
import HUB_POOL_STORE_ABI from "./abi/HubPoolStore.json";
@@ -249,13 +248,6 @@ export const CONTRACT_ADDRESSES: {
249248
spokePoolPeriphery: {
250249
abi: SPOKE_POOL_PERIPHERY_ABI,
251250
},
252-
counterfactualDepositFactory: {
253-
address: "0x20e67fBE0150B498048709306cc7729d382F1fB1",
254-
abi: COUNTERFACTUAL_DEPOSIT_FACTORY_ABI,
255-
},
256-
counterfactualDeposit: {
257-
address: "0xfb090c119c838CeD214F962F931d5fa38b111E46",
258-
},
259251
permit2: {
260252
address: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
261253
abi: PERMIT2_ABI,
@@ -495,13 +487,6 @@ export const CONTRACT_ADDRESSES: {
495487
spokePoolPeriphery: {
496488
abi: SPOKE_POOL_PERIPHERY_ABI,
497489
},
498-
counterfactualDepositFactory: {
499-
address: "0x20e67fBE0150B498048709306cc7729d382F1fB1",
500-
abi: COUNTERFACTUAL_DEPOSIT_FACTORY_ABI,
501-
},
502-
counterfactualDeposit: {
503-
address: "0xfb090c119c838CeD214F962F931d5fa38b111E46",
504-
},
505490
sponsoredCCTPDstPeriphery: {
506491
address: "0xd9dc78b969e9efb1e54b625c33a21aaf2509e6a1",
507492
abi: SPONSORED_CCTP_DST_PERIPHERY_ABI,
@@ -601,13 +586,6 @@ export const CONTRACT_ADDRESSES: {
601586
spokePoolPeriphery: {
602587
abi: SPOKE_POOL_PERIPHERY_ABI,
603588
},
604-
counterfactualDepositFactory: {
605-
address: "0x20e67fBE0150B498048709306cc7729d382F1fB1",
606-
abi: COUNTERFACTUAL_DEPOSIT_FACTORY_ABI,
607-
},
608-
counterfactualDeposit: {
609-
address: "0xfb090c119c838CeD214F962F931d5fa38b111E46",
610-
},
611589
permit2: {
612590
address: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
613591
abi: PERMIT2_ABI,

src/deposit-address/DepositAddressHandler.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
toBN,
2020
getDepositKey,
2121
assert,
22-
getCounterfactualDepositImplementationAddress,
2322
getNetworkName,
2423
blockExplorerLink,
2524
} from "../utils";
@@ -38,8 +37,6 @@ export class DepositAddressHandler {
3837

3938
private providersByChain: { [chainId: number]: Provider } = {};
4039

41-
private counterfactualDepositFactories: { [chainId: number]: Contract } = {};
42-
4340
/** Per chainId: set of deposit keys already executed (like gasless depositNonces). */
4441
private observedExecutedDeposits: { [chainId: number]: Set<string> } = {};
4542

@@ -99,7 +96,6 @@ export class DepositAddressHandler {
9996
await forEachAsync(this.config.relayerOriginChains, async (chainId) => {
10097
const provider = await getProvider(chainId);
10198
this.providersByChain[chainId] = provider;
102-
this.counterfactualDepositFactories[chainId] = getCounterfactualDepositFactory(chainId).connect(provider);
10399
this.observedExecutedDeposits[chainId] = new Set<string>();
104100
});
105101

@@ -244,7 +240,9 @@ export class DepositAddressHandler {
244240
return;
245241
}
246242

247-
const baseFactoryContract = this.counterfactualDepositFactories[originChainId];
243+
const baseFactoryContract = getCounterfactualDepositFactory(
244+
depositMessage.counterfactualFactoryContractAddress
245+
).connect(this.providersByChain[originChainId]);
248246

249247
const useDispatcher = this.depositAddressSigners.length > 0;
250248
const factoryContract = useDispatcher
@@ -272,7 +270,7 @@ export class DepositAddressHandler {
272270
const _deployTx = buildDeployTx(
273271
factoryContract,
274272
originChainId,
275-
getCounterfactualDepositImplementationAddress(originChainId),
273+
depositMessage.counterfactualDepositContractAddress,
276274
depositMessage.paramsHash,
277275
depositMessage.salt
278276
);

src/interfaces/DepositAddress.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface DepositAddressMessage {
2121
routeParams: RouteParams;
2222
erc20Transfer: Erc20Transfer;
2323
salt: string;
24+
counterfactualDepositContractAddress: string;
25+
counterfactualFactoryContractAddress: string;
2426
}
2527

2628
// TODO: Add schema for SwapAPI response.

src/utils/ContractUtils.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function getTypechainAbi(contractName: string): readonly JsonFragment[] {
2525
assert("abi" in factory, `Typechain export ${factoryName} has no abi`);
2626
return factory.abi as readonly JsonFragment[];
2727
}
28+
import COUNTERFACTUAL_DEPOSIT_FACTORY_ABI from "../common/abi/CounterfactualDepositFactory.json";
2829

2930
// Return an ethers contract instance for a deployed contract, imported from the Across-protocol contracts repo.
3031
export function getDeployedContract(contractName: string, networkId: number, signer?: Signer): Contract {
@@ -38,16 +39,9 @@ export function getDeployedContract(contractName: string, networkId: number, sig
3839
}
3940
}
4041

41-
export function getCounterfactualDepositImplementationAddress(chainId: number): string {
42-
return CONTRACT_ADDRESSES[chainId].counterfactualDeposit.address;
43-
}
44-
45-
// For a chain ID and optional CounterfactualDepositFactory address, return a Contract instance with the corresponding ABI.
46-
export function getCounterfactualDepositFactory(chainId: number, address?: string): Contract {
47-
return new Contract(
48-
address ?? CONTRACT_ADDRESSES[chainId].counterfactualDepositFactory.address,
49-
CONTRACT_ADDRESSES[chainId].counterfactualDepositFactory.abi
50-
);
42+
// For a CounterfactualDepositFactory address, return a Contract instance with the corresponding ABI.
43+
export function getCounterfactualDepositFactory(address: string): Contract {
44+
return new Contract(address, COUNTERFACTUAL_DEPOSIT_FACTORY_ABI);
5145
}
5246

5347
// For a chain ID and optional SpokePool address, return a Contract instance with the corresponding ABI.

0 commit comments

Comments
 (0)