@@ -24,6 +24,7 @@ const { replaceContractAt } = require("../utils/hardhat");
2424const { resolveContract } = require ( "../utils/resolvers" ) ;
2525const { impersonateAccount, getSigner } = require ( "../utils/signers" ) ;
2626const { getDefenderSigner } = require ( "../utils/signersNoHardhat" ) ;
27+ const { sleep } = require ( "../utils/time" ) ;
2728const { getTxOpts } = require ( "../utils/tx" ) ;
2829const createxAbi = require ( "../abi/createx.json" ) ;
2930
@@ -899,6 +900,24 @@ const deployOETHSupernovaAMOStrategyImplementation = async () => {
899900 return cOETHSupernovaAMOStrategy ;
900901} ;
901902
903+ // Poll eth_getCode until bytecode appears at `addr`. Base's read replicas can
904+ // lag the sequencer by several seconds, so a fresh deploy receipt does not
905+ // guarantee that the next call's RPC node sees the contract yet.
906+ const waitForBytecode = async (
907+ addr ,
908+ { timeoutMs = 60000 , pollMs = 2000 } = { }
909+ ) => {
910+ const start = Date . now ( ) ;
911+ while ( Date . now ( ) - start < timeoutMs ) {
912+ const code = await ethers . provider . getCode ( addr ) ;
913+ if ( code && code !== "0x" ) return ;
914+ await sleep ( pollMs ) ;
915+ }
916+ throw new Error (
917+ `waitForBytecode: no code at ${ addr } after ${ timeoutMs } ms; RPC may still be lagging`
918+ ) ;
919+ } ;
920+
902921const deployOETHbHydrexAMOStrategyImplementation = async ( gaugeAddress ) => {
903922 const { deployerAddr } = await getNamedAccounts ( ) ;
904923 const sDeployer = await ethers . provider . getSigner ( deployerAddr ) ;
@@ -927,6 +946,12 @@ const deployOETHbHydrexAMOStrategyImplementation = async (gaugeAddress) => {
927946 cOETHbHydrexAMOStrategyProxy . address
928947 ) ;
929948
949+ // Wait for the Base RPC read replicas to surface the freshly deployed
950+ // implementation bytecode before the proxy initialize() runs. Without this,
951+ // estimateGas on the proxy can hit a stale node and revert with
952+ // "Cannot set a proxy implementation to a non-contract address".
953+ await waitForBytecode ( dHydrexAMOStrategy . address ) ;
954+
930955 // Initialize OETHb Hydrex AMO Strategy via the proxy.
931956 // Reward token is oHYDX (call option on HYDX). The Hydrex gauge emits oHYDX
932957 // from getReward(); off-chain plumbing exercises/sells it.
0 commit comments