-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrations and working scenarios
- Loading branch information
1 parent
6635049
commit 4ba3b92
Showing
32 changed files
with
2,872 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
170 changes: 170 additions & 0 deletions
170
...oyments/arbitrum/usdc.e/migrations/1735299634_update_comet_to_support_more_collaterals.ts
This file contains 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,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); | ||
}, | ||
}); |
170 changes: 170 additions & 0 deletions
170
deployments/arbitrum/usdc/migrations/1735299626_update_comet_to_support_more_collaterals.ts
This file contains 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,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); | ||
}, | ||
}); |
Oops, something went wrong.