Skip to content

Commit

Permalink
feat: migrations and working scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaShWoof committed Dec 27, 2024
1 parent 6635049 commit 4ba3b92
Show file tree
Hide file tree
Showing 32 changed files with 2,872 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-slither.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
run: solc-select install 0.8.15;solc-select use 0.8.15

- name: Function clash analysis
run: yarn slither:fn-clashes &> tmp_res; cat tmp_res | { grep 'Function id collision found' || false; } && exit 1 || exit 0
run: yarn slither:fn-clashes &> tmp_res; cat tmp_res | grep 'Function id collision found' && exit 1 || exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { expect } from 'chai';
import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../../plugins/deployment_manager/Migration';
import { calldata, proposal } from '../../../../src/deploy';
import { ethers } from 'ethers';
import { Contract } from 'ethers';
import { utils } from 'ethers';
import { applyL1ToL2Alias, estimateL2Transaction } from '../../../../scenario/utils/arbitrumUtils';

let newCometExtAddress: string;

export default migration('1735299634_update_comet_to_support_more_collaterals', {
async prepare(deploymentManager: DeploymentManager) {
const _assetListFactory = await deploymentManager.deploy(
'assetListFactory',
'AssetListFactory.sol',
[]
);

const cometFactoryExtendedAssetList = await deploymentManager.deploy(
'cometFactoryExtendedAssetList',
'CometFactoryExtendedAssetList.sol',
[]
);
const {
comet
} = await deploymentManager.getContracts();

const extensionDelegate = new Contract(
await comet.extensionDelegate(),
[
'function name() external view returns (string)',
'function symbol() external view returns (string)',
],
deploymentManager.hre.ethers.provider
);
const name = await extensionDelegate.name();
const symbol = await extensionDelegate.symbol();

const _newCometExt = await deploymentManager.deploy(
'CometExtAssetList',
'CometExtAssetList.sol',
[
{
name32: ethers.utils.formatBytes32String(name),
symbol32: ethers.utils.formatBytes32String(symbol)
},
_assetListFactory.address
]
);
return {
cometFactoryExtendedAssetList: cometFactoryExtendedAssetList.address,
newCometExt: _newCometExt.address
};
},

async enact(deploymentManager: DeploymentManager, govDeploymentManager, {
cometFactoryExtendedAssetList,
newCometExt,
}) {

const trace = deploymentManager.tracer();
const {
comet,
cometAdmin,
configurator,
bridgeReceiver,
timelock: l2Timelock,
} = await deploymentManager.getContracts();

const {
arbitrumInbox,
timelock,
governor
} = await govDeploymentManager.getContracts();

newCometExtAddress = newCometExt;

const setFactoryCalldata = await calldata(
configurator.populateTransaction.setFactory(comet.address, cometFactoryExtendedAssetList)
);

const setExtensionDelegateCalldata = await calldata(
configurator.populateTransaction.setExtensionDelegate(comet.address, newCometExt)
);

const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode(
['address', 'address'],
[configurator.address, comet.address]
);

const l2ProposalData = utils.defaultAbiCoder.encode(
['address[]', 'uint256[]', 'string[]', 'bytes[]'],
[
[configurator.address, configurator.address, cometAdmin.address],
[0, 0, 0],
[
'setFactory(address,address)',
'setExtensionDelegate(address,address)',
'deployAndUpgradeTo(address,address)',
],
[setFactoryCalldata, setExtensionDelegateCalldata, deployAndUpgradeToCalldata],
]
);

const createRetryableTicketGasParams = await estimateL2Transaction(
{
from: applyL1ToL2Alias(timelock.address),
to: bridgeReceiver.address,
data: l2ProposalData
},
deploymentManager
);
const refundAddress = l2Timelock.address;

const mainnetActions = [
// 1. Set Comet configuration and deployAndUpgradeTo WETH Comet on Arbitrum.
{
contract: arbitrumInbox,
signature: 'createRetryableTicket(address,uint256,uint256,address,address,uint256,uint256,bytes)',
args: [
bridgeReceiver.address, // address to,
0, // uint256 l2CallValue,
createRetryableTicketGasParams.maxSubmissionCost, // uint256 maxSubmissionCost,
refundAddress, // address excessFeeRefundAddress,
refundAddress, // address callValueRefundAddress,
createRetryableTicketGasParams.gasLimit, // uint256 gasLimit,
createRetryableTicketGasParams.maxFeePerGas, // uint256 maxFeePerGas,
l2ProposalData, // bytes calldata data
],
value: createRetryableTicketGasParams.deposit
},
];

const description = 'DESCRIPTION';
const txn = await deploymentManager.retry(async () =>
trace(
await governor.propose(...(await proposal(mainnetActions, description)))
)
);

const event = txn.events.find(
(event) => event.event === 'ProposalCreated'
);
const [proposalId] = event.args;
trace(`Created proposal ${proposalId}.`);
},

async enacted(): Promise<boolean> {
return false;
},

async verify(deploymentManager: DeploymentManager) {
const { comet } = await deploymentManager.getContracts();

const cometNew = new Contract(
comet.address,
[
'function assetList() external view returns (address)',
],
deploymentManager.hre.ethers.provider
);

const assetListAddress = await cometNew.assetList();

expect(assetListAddress).to.not.be.equal(ethers.constants.AddressZero);

expect(await comet.extensionDelegate()).to.be.equal(newCometExtAddress);
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { expect } from 'chai';
import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../../plugins/deployment_manager/Migration';
import { calldata, proposal } from '../../../../src/deploy';
import { ethers } from 'ethers';
import { Contract } from 'ethers';
import { utils } from 'ethers';
import { applyL1ToL2Alias, estimateL2Transaction } from '../../../../scenario/utils/arbitrumUtils';

let newCometExtAddress: string;

export default migration('1735299626_update_comet_to_support_more_collaterals', {
async prepare(deploymentManager: DeploymentManager) {
const _assetListFactory = await deploymentManager.deploy(
'assetListFactory',
'AssetListFactory.sol',
[]
);

const cometFactoryExtendedAssetList = await deploymentManager.deploy(
'cometFactoryExtendedAssetList',
'CometFactoryExtendedAssetList.sol',
[]
);
const {
comet
} = await deploymentManager.getContracts();

const extensionDelegate = new Contract(
await comet.extensionDelegate(),
[
'function name() external view returns (string)',
'function symbol() external view returns (string)',
],
deploymentManager.hre.ethers.provider
);
const name = await extensionDelegate.name();
const symbol = await extensionDelegate.symbol();

const _newCometExt = await deploymentManager.deploy(
'CometExtAssetList',
'CometExtAssetList.sol',
[
{
name32: ethers.utils.formatBytes32String(name),
symbol32: ethers.utils.formatBytes32String(symbol)
},
_assetListFactory.address
]
);
return {
cometFactoryExtendedAssetList: cometFactoryExtendedAssetList.address,
newCometExt: _newCometExt.address
};
},

async enact(deploymentManager: DeploymentManager, govDeploymentManager, {
cometFactoryExtendedAssetList,
newCometExt,
}) {

const trace = deploymentManager.tracer();
const {
comet,
cometAdmin,
configurator,
bridgeReceiver,
timelock: l2Timelock,
} = await deploymentManager.getContracts();

const {
arbitrumInbox,
timelock,
governor
} = await govDeploymentManager.getContracts();

newCometExtAddress = newCometExt;

const setFactoryCalldata = await calldata(
configurator.populateTransaction.setFactory(comet.address, cometFactoryExtendedAssetList)
);

const setExtensionDelegateCalldata = await calldata(
configurator.populateTransaction.setExtensionDelegate(comet.address, newCometExt)
);

const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode(
['address', 'address'],
[configurator.address, comet.address]
);

const l2ProposalData = utils.defaultAbiCoder.encode(
['address[]', 'uint256[]', 'string[]', 'bytes[]'],
[
[configurator.address, configurator.address, cometAdmin.address],
[0, 0, 0],
[
'setFactory(address,address)',
'setExtensionDelegate(address,address)',
'deployAndUpgradeTo(address,address)',
],
[setFactoryCalldata, setExtensionDelegateCalldata, deployAndUpgradeToCalldata],
]
);

const createRetryableTicketGasParams = await estimateL2Transaction(
{
from: applyL1ToL2Alias(timelock.address),
to: bridgeReceiver.address,
data: l2ProposalData
},
deploymentManager
);
const refundAddress = l2Timelock.address;

const mainnetActions = [
// 1. Set Comet configuration and deployAndUpgradeTo WETH Comet on Arbitrum.
{
contract: arbitrumInbox,
signature: 'createRetryableTicket(address,uint256,uint256,address,address,uint256,uint256,bytes)',
args: [
bridgeReceiver.address, // address to,
0, // uint256 l2CallValue,
createRetryableTicketGasParams.maxSubmissionCost, // uint256 maxSubmissionCost,
refundAddress, // address excessFeeRefundAddress,
refundAddress, // address callValueRefundAddress,
createRetryableTicketGasParams.gasLimit, // uint256 gasLimit,
createRetryableTicketGasParams.maxFeePerGas, // uint256 maxFeePerGas,
l2ProposalData, // bytes calldata data
],
value: createRetryableTicketGasParams.deposit
},
];

const description = 'DESCRIPTION';
const txn = await deploymentManager.retry(async () =>
trace(
await governor.propose(...(await proposal(mainnetActions, description)))
)
);

const event = txn.events.find(
(event) => event.event === 'ProposalCreated'
);
const [proposalId] = event.args;
trace(`Created proposal ${proposalId}.`);
},

async enacted(): Promise<boolean> {
return false;
},

async verify(deploymentManager: DeploymentManager) {
const { comet } = await deploymentManager.getContracts();

const cometNew = new Contract(
comet.address,
[
'function assetList() external view returns (address)',
],
deploymentManager.hre.ethers.provider
);

const assetListAddress = await cometNew.assetList();

expect(assetListAddress).to.not.be.equal(ethers.constants.AddressZero);

expect(await comet.extensionDelegate()).to.be.equal(newCometExtAddress);
},
});
Loading

0 comments on commit 4ba3b92

Please sign in to comment.