Skip to content

Commit

Permalink
fix: roninscan constructor args fetch and deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
artemwoofsoftware committed Jan 28, 2025
1 parent b2ddf00 commit c04e412
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 73 deletions.
53 changes: 45 additions & 8 deletions deployments/ronin-saigon/usdc/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Deployed,
DeploymentManager,
} from '../../../plugins/deployment_manager';
import { DeploySpec, deployComet } from '../../../src/deploy';
import { DeploySpec, deployComet, exp } from '../../../src/deploy';

const HOUR = 60 * 60;
const DAY = 24 * HOUR;
Expand Down Expand Up @@ -31,11 +31,11 @@ async function deployContracts(
);

// pre-deployed OptimismMintableERC20
const COMP = await deploymentManager.existing(
'COMP',
'0x52b7D8851d6CcBC6342ba0855Be65f7B82A3F17f',
'ronin-saigon'
);
// const COMP = await deploymentManager.existing(
// 'COMP',
// '0x52b7D8851d6CcBC6342ba0855Be65f7B82A3F17f',
// 'ronin-saigon'
// );

const l2CCIPRouter = await deploymentManager.existing(
'l2CCIPRouter',
Expand Down Expand Up @@ -82,8 +82,43 @@ async function deployContracts(
}
);

const USDCPriceFeed = await deploymentManager.deploy(
'USDC:simplePriceFeed',
'test/SimplePriceFeed.sol',
[
exp(0.98882408, 18), // Latest answer on mainnet at block 16170924
8
]
);

// Deploy cbETH / ETH SimplePriceFeed
const WRONPriceFeed = await deploymentManager.deploy(
'WRON:simplePriceFeed',
'test/SimplePriceFeed.sol',
[
exp(0.97, 18),
8
]
);


const assetConfig = {
asset: WRON.address,
priceFeed: WRONPriceFeed.address,
decimals: (18).toString(),
borrowCollateralFactor: (0.9e18).toString(),
liquidateCollateralFactor: (0.91e18).toString(),
liquidationFactor: (0.95e18).toString(),
supplyCap: (1000000e8).toString(),
};


// Deploy all Comet-related contracts
const deployed = await deployComet(deploymentManager, deploySpec, {
baseTokenPriceFeed: USDCPriceFeed.address,
assetConfigs: [assetConfig],
});
// Deploy Comet
const deployed = await deployComet(deploymentManager, deploySpec);
const { comet } = deployed;

// Deploy Bulker
Expand All @@ -96,13 +131,15 @@ async function deployContracts(
WRON.address, // wrapped native token
]
);
// Deploy stETH / ETH SimplePriceFeed


return {
...deployed,
bridgeReceiver,
l2CCIPRouter,
l2CCIPOffRamp,
bulker,
COMP,
// COMP,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ENSSubdomainLabel = "v3-additional-grants";
const ENSSubdomain = `${ENSSubdomainLabel}.${ENSName}`;
const ENSTextRecordKey = "v3-official-markets";
const roninSaigonCOMPAddress = "0x7e7d4467112689329f7E06571eD0E8CbAd4910eE";
const destinationChainSelector = "13116810400804392105";

export default migration("1707394874_configurate_and_ens", {
prepare: async (deploymentManager: DeploymentManager) => {
Expand All @@ -42,7 +43,7 @@ export default migration("1707394874_configurate_and_ens", {
COMP: mainnetCOMP,
USDC: mainnetUSDC,
} = await govDeploymentManager.getContracts();


// ENS Setup
// See also: https://docs.ens.domains/contract-api-reference/name-processing
Expand Down Expand Up @@ -86,17 +87,19 @@ export default migration("1707394874_configurate_and_ens", {
const l2ProposalData = utils.defaultAbiCoder.encode(
["address[]", "uint256[]", "string[]", "bytes[]"],
[
[configurator.address, cometAdmin.address, rewards.address],
[0, 0, 0],
// [configurator.address, cometAdmin.address, rewards.address],
[configurator.address, cometAdmin.address],
//[0, 0, 0],
[0, 0],
[
"setConfiguration(address,(address,address,address,address,address,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint104,uint104,uint104,(address,address,uint8,uint64,uint64,uint64,uint128)[]))",
"deployAndUpgradeTo(address,address)",
"setRewardConfig(address,address)",
// "setRewardConfig(address,address)",
],
[
setConfigurationCalldata,
deployAndUpgradeToCalldata,
setRewardConfigCalldata,
// setRewardConfigCalldata,
],
]
);
Expand All @@ -119,7 +122,7 @@ export default migration("1707394874_configurate_and_ens", {
contract: l1CCIPRouter,
signature: "ccipSend(uint64,(bytes,bytes,address,bytes,uint256,address[]))",
args: [
13116810400804392105,
destinationChainSelector,
{
messageId: "0x",
payload: l2ProposalData,
Expand Down
10 changes: 9 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ const config: HardhatUserConfig = {
// apiURL: 'https://api.mantlescan.xyz/api',
// browserURL: 'https://mantlescan.xyz/'
}
},
{
network: 'ronin-saigon',
chainId: 2021,
urls: {
apiURL: 'https://explorer-kintsugi.roninchain.com/v2/2021',
browserURL: 'https://explorer-kintsugi.roninchain.com/v2/2021'
}
}
]
},
Expand Down Expand Up @@ -634,7 +642,7 @@ const config: HardhatUserConfig = {
name: 'ronin-saigon',
network: 'ronin-saigon',
deployment: 'usdc',
auxiliaryBase: 'sepolia'
auxiliaryBase: 'sepolia-usdc'
}
],
},
Expand Down
8 changes: 8 additions & 0 deletions plugins/deployment_manager/Import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export async function fetchAndCacheContract(
importRetryDelay = DEFAULT_RETRY_DELAY,
force = false
): Promise<BuildFile> {
console.log(`Fetching and caching ${network}@${address}`);
console.log(`cache: ${cache}`);
console.log(`network: ${network}`);
console.log(`address: ${address}`);
console.log(`importRetries: ${importRetries}`);
console.log(`importRetryDelay: ${importRetryDelay}`);
console.log(`force: ${force}`);

const buildFile = await fetchContract(cache, network, address, importRetries, importRetryDelay, force);
await storeBuildFile(cache, network, address, buildFile);
return buildFile;
Expand Down
2 changes: 1 addition & 1 deletion plugins/deployment_manager/Spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async function crawl(
contracts,
trace
);

// Add the aliasTemplate in place to the relative context
(context[subKey] = context[subKey] || []).push(contracts.get(subAlias));
}
Expand Down
38 changes: 18 additions & 20 deletions plugins/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function getRoninApiData(network: string, address: string) {
let abi = (await get(`${apiUrl}/contract/${address}/abi`, {})).result.output.abi;
let src = (await get(`${apiUrl}/contract/${address}/src`, {})).result[0].content;
let metadata = (await get(`${apiUrl}/contract/${address}/metadata`, {})).result;
let deploymentBytecode = (await get(`${apiUrl}/contract/${address}`, {})).result.at_tx;
let compiler = metadata.compiler.version;
let optimized = metadata.settings.optimizer.enabled;
let optimizationRuns = metadata.settings.optimizer.runs;
Expand All @@ -71,7 +72,7 @@ async function getRoninApiData(network: string, address: string) {
compiler,
optimized: optimized,
optimizationRuns: optimizationRuns,
constructorArgs: '',
constructorArgs: deploymentBytecode,
}
}

Expand Down Expand Up @@ -176,6 +177,17 @@ async function pullFirstTransactionForContract(network: string, address: string)
return contractCreationCode.slice(2);
}

async function getRoninContractDeploymentData(tx: string) {
const res = await post(`https://saigon-testnet.roninchain.com/rpc`, {
jsonrpc: '2.0',
method: 'eth_getTransactionByHash',
params: [tx],
id: 1
});

return res.result.input;
}

async function getContractCreationCode(network: string, address: string) {
if (network === 'ronin-saigon') {
const res = await post(`https://saigon-testnet.roninchain.com/rpc`, {
Expand Down Expand Up @@ -243,24 +255,16 @@ export async function loadRoninContract(network: string, address: string) {
const networkName = network;
const roninData = await getRoninApiData(networkName, address);
const { language, settings, sources } = parseSources(roninData);
let input = await getContractCreationCode(networkName, address);
const constructorAbi = roninData.abi.find((entry) => entry.type === "constructor");
if (!constructorAbi) {
return {
creationBytecode: input,
constructorArgs: [],
};
}

const {
let contractCreationCode = await getContractCreationCode(networkName, address);

let {
abi,
contract,
compiler,
constructorArgs
} = roninData;
const inputTypes = constructorAbi.inputs.map((input) => input.type);
const contractCreationCode = extractCreationBytecode(input, inputTypes);

let bytecodeWithTxArgs = await getRoninContractDeploymentData(constructorArgs);
constructorArgs = bytecodeWithTxArgs.slice(contractCreationCode.length);
const encodedABI = JSON.stringify(abi);
const contractPath = Object.keys(sources)[0];
const contractFQN = `${contractPath}:${contract}`;
Expand Down Expand Up @@ -296,12 +300,6 @@ export async function loadRoninContract(network: string, address: string) {
return contractBuild;
}

function extractCreationBytecode(fullInput: string, inputTypes: string[]): string {
const encodedArgsLength = ethers.utils.defaultAbiCoder.encode(inputTypes, []).length;
const contractCreationCode = fullInput.slice(0, fullInput.length - encodedArgsLength);

return contractCreationCode;
}


export async function loadEtherscanContract(network: string, address: string) {
Expand Down
37 changes: 0 additions & 37 deletions scenario/utils/relayRoninSaigonMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,6 @@ import { BigNumber, ethers } from 'ethers';
import { Log } from '@ethersproject/abstract-provider';
import { OpenBridgedProposal } from '../context/Gov';

// interface IEVM2EVMOnRamp extends ethers.Contract {
// filters: {
// CCIPSendRequested(): ethers.EventFilter;
// };
// interface: ethers.utils.Interface;
// }

// interface IRouter extends ethers.Contract {
// filters: {
// MessageExecuted(): ethers.EventFilter;
// };
// interface: ethers.utils.Interface;
// routeMessage(
// message: {
// messageId: string;
// sourceChainSelector: number;
// sender: string;
// data: string;
// destTokenAmounts: {
// token: string;
// amount: BigNumber;
// }[];
// },
// gasForCallExactCheck: number,
// gasLimit: number,
// receiver: string
// ): Promise<ethers.ContractTransaction>;
// }

// interface IBridgeReceiver extends ethers.Contract {
// interface: ethers.utils.Interface;
// executeProposal: (id: BigNumber, overrides?: any) => Promise<ethers.ContractTransaction>;
// }


// const offRampAddress = '0x77008Fbd8Ae8f395beF9c6a55905896f3Ead75e9';

export default async function relayRoninSaigonMessage(
governanceDeploymentManager: DeploymentManager,
bridgeDeploymentManager: DeploymentManager,
Expand Down

0 comments on commit c04e412

Please sign in to comment.