Skip to content
Open
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
122 changes: 122 additions & 0 deletions scripts/deploy/checkReceiverDeployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Checks that BungeeReceiver and CalldataExecutor are deployed on the current network.
* Addresses are computed deterministically from the deployer address and CREATE3 salts —
* no hardcoded address constants needed.
*
* Usage:
* npx hardhat run scripts/deploy/checkReceiverDeployment.ts --network <network>
*
* Required env vars:
* DEPLOYER_ADDRESS — address used to deploy the contracts (determines CREATE3 addresses)
*
* Optional env vars:
* OWNER_ADDRESS — if set, assert BungeeReceiver owner() matches this address
*/

import hre from 'hardhat';
import { ethers } from 'hardhat';
import { Contract } from 'ethers';
import {
CREATE_X_FACTORY,
Create3ABI,
BUNGEE_RECEIVER_CREATE3_SALT,
CALLDATA_EXECUTOR_CREATE3_SALT,
getBungeeReceiverDeploymentStatus,
getCalldataExecutorDeploymentStatus,
} from './create3';

async function main() {
const networkName = hre.network.name;
const { chainId } = await ethers.provider.getNetwork();

const deployerAddress = process.env.DEPLOYER_ADDRESS?.trim();
if (!deployerAddress) {
console.error('DEPLOYER_ADDRESS env var is required');
process.exit(1);
}

const create3Factory = new Contract(
CREATE_X_FACTORY,
Create3ABI,
ethers.provider,
);

const receiverAddress = (await create3Factory.computeCreate3Address(
BUNGEE_RECEIVER_CREATE3_SALT,
deployerAddress,
)) as string;

const executorAddress = (await create3Factory.computeCreate3Address(
CALLDATA_EXECUTOR_CREATE3_SALT,
deployerAddress,
)) as string;

let hasError = false;

// ── Check CalldataExecutor ───────────────────────────────────────────────────

const executorStatus = await getCalldataExecutorDeploymentStatus({
provider: ethers.provider,
address: executorAddress,
});

if (!executorStatus.deployed) {
console.error(
`CalldataExecutor NOT deployed on ${networkName} (chainId=${chainId}) at ${executorAddress}`,
);
hasError = true;
} else {
if (
executorStatus.bungeeReceiver?.toLowerCase() !==
receiverAddress.toLowerCase()
) {
console.error(
`CalldataExecutor BUNGEE_RECEIVER mismatch on ${networkName} (chainId=${chainId}): ` +
`executor=${executorAddress}, expected receiver=${receiverAddress}, got ${executorStatus.bungeeReceiver}`,
);
hasError = true;
} else {
console.log(
`CalldataExecutor deployed on ${networkName} (chainId=${chainId}) at ${executorAddress}, BUNGEE_RECEIVER=${executorStatus.bungeeReceiver}`,
);
}
}

// ── Check BungeeReceiver ─────────────────────────────────────────────────────

const receiverStatus = await getBungeeReceiverDeploymentStatus({
provider: ethers.provider,
address: receiverAddress,
});

if (!receiverStatus.deployed) {
console.error(
`BungeeReceiver NOT deployed on ${networkName} (chainId=${chainId}) at ${receiverAddress}`,
);
hasError = true;
} else {
const expectedOwner = process.env.OWNER_ADDRESS?.trim();
if (
expectedOwner &&
receiverStatus.owner?.toLowerCase() !== expectedOwner.toLowerCase()
) {
console.error(
`BungeeReceiver owner mismatch on ${networkName} (chainId=${chainId}): expected ${expectedOwner}, got ${receiverStatus.owner}`,
);
hasError = true;
} else {
console.log(
`BungeeReceiver deployed on ${networkName} (chainId=${chainId}) at ${receiverAddress}, owner=${receiverStatus.owner}`,
);
}
}

if (hasError) {
process.exit(1);
}
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
70 changes: 70 additions & 0 deletions scripts/deploy/create3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ export const CREATE_X_FACTORY = '0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed';
/** CREATE3 salt label used by `deployOpenRouter.ts`. */
export const OPEN_ROUTER_CREATE3_SALT_TEXT = 'OpenRouter' + '000';

/** CREATE3 salt label used by `deployReceiverAndExecutor.ts`. */
export const BUNGEE_RECEIVER_CREATE3_SALT_TEXT = 'BungeeReceiver' + '000';

/** CREATE3 salt label used by `deployReceiverAndExecutor.ts`. */
export const CALLDATA_EXECUTOR_CREATE3_SALT_TEXT = 'CalldataExecutor' + '000';

/** Keccak256 salt for deterministic OpenRouter CREATE3 deployments. */
export const OPEN_ROUTER_CREATE3_SALT = keccak256(
toUtf8Bytes(OPEN_ROUTER_CREATE3_SALT_TEXT),
);

/** Keccak256 salt for deterministic BungeeReceiver CREATE3 deployments. */
export const BUNGEE_RECEIVER_CREATE3_SALT = keccak256(
toUtf8Bytes(BUNGEE_RECEIVER_CREATE3_SALT_TEXT),
);

/** Keccak256 salt for deterministic CalldataExecutor CREATE3 deployments. */
export const CALLDATA_EXECUTOR_CREATE3_SALT = keccak256(
toUtf8Bytes(CALLDATA_EXECUTOR_CREATE3_SALT_TEXT),
/** CREATE3 salt label used by `deployAcrossERC20AmountManipulator.ts`. */
export const ACROSS_MANIPULATOR_CREATE3_SALT_TEXT =
'AcrossERC20AmountManipulator' + '1';
Expand Down Expand Up @@ -167,3 +181,59 @@ export function decodeCreate3DeploymentFromTxReceipt(params: {

return '0x' + eventData.slice(26);
}

/**
* Checks whether BungeeReceiver bytecode is present at the given address.
* When deployed, reads `owner()` to confirm the contract responds.
*/
export async function getBungeeReceiverDeploymentStatus(params: {
provider: Provider;
address: string;
}): Promise<{ address: string; deployed: boolean; owner?: string }> {
const { provider, address } = params;
const bytecode = await provider.getCode(address);

if (!hasContractBytecode(bytecode)) {
return { address, deployed: false };
}

try {
const contract = new Contract(
address,
['function owner() view returns (address)'],
provider,
);
const owner = (await contract.owner()) as string;
return { address, deployed: true, owner };
} catch {
return { address, deployed: false };
}
}
Comment on lines +189 to +211
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Strengthen getBungeeReceiverDeploymentStatus contract identity check.

Current logic marks deployment as valid if owner() responds. That can false-positive on unrelated Ownable contracts. This should also probe BungeeReceiver-specific view(s), e.g. CALLDATA_EXECUTOR() and/or SOLVER_SIGNER().

Suggested direction
 export async function getBungeeReceiverDeploymentStatus(params: {
   provider: Provider;
   address: string;
-}): Promise<{ address: string; deployed: boolean; owner?: string }> {
+}): Promise<{ address: string; deployed: boolean; owner?: string; calldataExecutor?: string }> {
@@
   try {
     const contract = new Contract(
       address,
-      ['function owner() view returns (address)'],
+      [
+        'function owner() view returns (address)',
+        'function CALLDATA_EXECUTOR() view returns (address)',
+      ],
       provider,
     );
     const owner = (await contract.owner()) as string;
-    return { address, deployed: true, owner };
+    const calldataExecutor = (await contract.CALLDATA_EXECUTOR()) as string;
+    return { address, deployed: true, owner, calldataExecutor };
   } catch {
     return { address, deployed: false };
   }
 }

As per coding guidelines, “Check for resource leaks, race conditions, and unhandled edge cases. Flag over-engineering and premature abstractions.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function getBungeeReceiverDeploymentStatus(params: {
provider: Provider;
address: string;
}): Promise<{ address: string; deployed: boolean; owner?: string }> {
const { provider, address } = params;
const bytecode = await provider.getCode(address);
if (!hasContractBytecode(bytecode)) {
return { address, deployed: false };
}
try {
const contract = new Contract(
address,
['function owner() view returns (address)'],
provider,
);
const owner = (await contract.owner()) as string;
return { address, deployed: true, owner };
} catch {
return { address, deployed: false };
}
}
export async function getBungeeReceiverDeploymentStatus(params: {
provider: Provider;
address: string;
}): Promise<{ address: string; deployed: boolean; owner?: string; calldataExecutor?: string }> {
const { provider, address } = params;
const bytecode = await provider.getCode(address);
if (!hasContractBytecode(bytecode)) {
return { address, deployed: false };
}
try {
const contract = new Contract(
address,
[
'function owner() view returns (address)',
'function CALLDATA_EXECUTOR() view returns (address)',
],
provider,
);
const owner = (await contract.owner()) as string;
const calldataExecutor = (await contract.CALLDATA_EXECUTOR()) as string;
return { address, deployed: true, owner, calldataExecutor };
} catch {
return { address, deployed: false };
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/deploy/create3.ts` around lines 124 - 146, Update
getBungeeReceiverDeploymentStatus to verify the contract is actually a
BungeeReceiver by calling one or more BungeeReceiver-specific view methods
(e.g., CALLDATA_EXECUTOR() and/or SOLVER_SIGNER()) in addition to owner(); after
confirming bytecode exists, instantiate the Contract as you do now, call owner()
and then call CALLDATA_EXECUTOR() and/or SOLVER_SIGNER(), treat the deployment
as valid only if those Bungee-specific calls succeed and return plausible values
(addresses/non-zero), and propagate or handle errors so that exceptions from
unrelated Ownable contracts do not yield a false positive; keep the existing
return shape { address, deployed: boolean, owner?: string } and only set
deployed=true when the Bungee-specific probes succeed.


/**
* Checks whether CalldataExecutor bytecode is present at the given address.
* When deployed, reads `BUNGEE_RECEIVER()` to confirm the contract responds.
*/
export async function getCalldataExecutorDeploymentStatus(params: {
provider: Provider;
address: string;
}): Promise<{ address: string; deployed: boolean; bungeeReceiver?: string }> {
const { provider, address } = params;
const bytecode = await provider.getCode(address);

if (!hasContractBytecode(bytecode)) {
return { address, deployed: false };
}

try {
const contract = new Contract(
address,
['function BUNGEE_RECEIVER() view returns (address)'],
provider,
);
const bungeeReceiver = (await contract.BUNGEE_RECEIVER()) as string;
return { address, deployed: true, bungeeReceiver };
} catch {
return { address, deployed: false };
}
}
184 changes: 184 additions & 0 deletions scripts/deploy/deployReceiverAndExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/**
* Deploys CalldataExecutor and BungeeReceiver via CreateX CREATE3.
*
* Both contracts reference each other in their constructors (CalldataExecutor is wired with the
* receiver's address; BungeeReceiver is wired with the executor's address). We resolve this by
* pre-computing both CREATE3 addresses from the factory before deploying either contract, then
* deploying in order: CalldataExecutor first (using pre-computed receiver address), then BungeeReceiver.
*
* Usage:
* npx hardhat run scripts/deploy/deployReceiverAndExecutor.ts --network <network>
*
* Required env vars:
* DEPLOYER_PRIVATE_KEY — deployer wallet private key
*
* Optional env vars:
* OWNER_ADDRESS — owner of BungeeReceiver (defaults to deployer)
* SOLVER_SIGNER_ADDRESS — initial SOLVER_SIGNER on BungeeReceiver (defaults to deployer)
*/

import hre from 'hardhat';
import { ethers } from 'hardhat';
import {
CREATE_X_FACTORY,
Create3ABI,
BUNGEE_RECEIVER_CREATE3_SALT,
CALLDATA_EXECUTOR_CREATE3_SALT,
decodeCreate3DeploymentFromTxReceipt,
getBungeeReceiverDeploymentStatus,
getCalldataExecutorDeploymentStatus,
} from './create3';

async function main() {
const [deployer] = await ethers.getSigners();
const networkName = hre.network.name;
const owner = process.env.OWNER_ADDRESS?.trim() || deployer.address;
const solverSigner =
process.env.SOLVER_SIGNER_ADDRESS?.trim() || deployer.address;

console.log('Deployer: ', deployer.address);
console.log('Owner: ', owner);
console.log('SolverSigner: ', solverSigner);
console.log('Network: ', networkName);
console.log('');

const create3Factory = new ethers.Contract(
CREATE_X_FACTORY,
Create3ABI,
deployer,
);

// Pre-compute both CREATE3 addresses before deploying anything.
// CREATE3 address is deterministic: f(salt, deployer) — no bytecode dependency.
const receiverAddress = (await create3Factory.computeCreate3Address(
BUNGEE_RECEIVER_CREATE3_SALT,
deployer.address,
)) as string;

const executorAddress = (await create3Factory.computeCreate3Address(
CALLDATA_EXECUTOR_CREATE3_SALT,
deployer.address,
)) as string;

console.log('Pre-computed BungeeReceiver address: ', receiverAddress);
console.log('Pre-computed CalldataExecutor address: ', executorAddress);
console.log('');

// ── Deploy CalldataExecutor (wired with pre-computed receiver address) ──────

const executorStatus = await getCalldataExecutorDeploymentStatus({
provider: ethers.provider,
address: executorAddress,
});

if (executorStatus.deployed) {
if (
executorStatus.bungeeReceiver?.toLowerCase() !==
receiverAddress.toLowerCase()
) {
throw new Error(
`CalldataExecutor wiring mismatch at ${executorAddress}: ` +
`BUNGEE_RECEIVER=${executorStatus.bungeeReceiver}, expected ${receiverAddress}`,
);
}
console.log(
`CalldataExecutor already deployed at ${executorAddress}, BUNGEE_RECEIVER=${executorStatus.bungeeReceiver}`,
);
} else {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const executorFactory = await ethers.getContractFactory('CalldataExecutor');
const executorDeployTx =
await executorFactory.getDeployTransaction(receiverAddress);

console.log('Deploying CalldataExecutor via CREATE3...');
const executorDeployment = await create3Factory.deployCreate3(
CALLDATA_EXECUTOR_CREATE3_SALT,
executorDeployTx.data,
);
console.log('CREATE3 deployment tx:', executorDeployment.hash);

const executorReceipt = await executorDeployment.wait();
const deployedExecutorAddress = decodeCreate3DeploymentFromTxReceipt({
receipt: executorReceipt,
});
if (!deployedExecutorAddress) {
throw new Error('CalldataExecutor address not found in CREATE3 receipt');
}
console.log('CalldataExecutor deployed to:', deployedExecutorAddress);
}

// ── Deploy BungeeReceiver (wired with actual executor address) ───────────────

const receiverStatus = await getBungeeReceiverDeploymentStatus({
provider: ethers.provider,
address: receiverAddress,
});

if (receiverStatus.deployed) {
console.log(
`BungeeReceiver already deployed at ${receiverAddress}, owner=${receiverStatus.owner}`,
);
} else {
const receiverFactory = await ethers.getContractFactory('BungeeReceiver');
const receiverDeployTx = await receiverFactory.getDeployTransaction(
owner,
solverSigner,
executorAddress,
);

console.log('Deploying BungeeReceiver via CREATE3...');
const receiverDeployment = await create3Factory.deployCreate3(
BUNGEE_RECEIVER_CREATE3_SALT,
receiverDeployTx.data,
);
console.log('CREATE3 deployment tx:', receiverDeployment.hash);

const receiverReceipt = await receiverDeployment.wait();
const deployedReceiverAddress = decodeCreate3DeploymentFromTxReceipt({
receipt: receiverReceipt,
});
if (!deployedReceiverAddress) {
throw new Error('BungeeReceiver address not found in CREATE3 receipt');
}
console.log('BungeeReceiver deployed to:', deployedReceiverAddress);
}

console.log('\n=== Deployment Summary ===');
console.log(`CalldataExecutor: ${executorAddress}`);
console.log(`BungeeReceiver: ${receiverAddress}`);

const chainId = (await ethers.provider.getNetwork()).chainId;
if (chainId !== 31337n) {
await new Promise((resolve) => setTimeout(resolve, 5000));

try {
await hre.run('verify:verify', {
address: executorAddress,
constructorArguments: [receiverAddress],
});
console.log('CalldataExecutor verified on block explorer');
} catch (err) {
console.warn(
'CalldataExecutor verification failed (deployment succeeded):',
err instanceof Error ? err.message : err,
);
}

try {
await hre.run('verify:verify', {
address: receiverAddress,
constructorArguments: [owner, solverSigner, executorAddress],
});
console.log('BungeeReceiver verified on block explorer');
} catch (err) {
console.warn(
'BungeeReceiver verification failed (deployment succeeded):',
err instanceof Error ? err.message : err,
);
}
}
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
Loading