-
Notifications
You must be signed in to change notification settings - Fork 0
feat: added calldata executor and bridge receiver #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tHeMaskedMan981
wants to merge
6
commits into
main
Choose a base branch
from
feat/dst-payload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ccca148
feat: added calldata executor and bridge receiver
tHeMaskedMan981 968594f
feat: bungee receiver cleanup
tHeMaskedMan981 52f737a
Merge branch 'main' into feat/dst-payload
tHeMaskedMan981 e754e97
fix: comments
tHeMaskedMan981 b7ec9c3
Merge branch 'feat/dst-payload' of github.com:SocketDotTech/poc-openr…
tHeMaskedMan981 b11369e
fix: added quoteId check to avoid double spends
tHeMaskedMan981 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
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); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strengthen
getBungeeReceiverDeploymentStatuscontract 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/orSOLVER_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
🤖 Prompt for AI Agents