Skip to content

Commit

Permalink
chore: upgrades task deploy-bridge-forwarder
Browse files Browse the repository at this point in the history
  • Loading branch information
doncesarts committed Jun 17, 2022
1 parent 6f5c928 commit 9b6e9b4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 43 deletions.
5 changes: 3 additions & 2 deletions tasks/deployEmissionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ task("deploy-bridge-forwarder", "Deploys a BridgeForwarder contract on mainnet f
undefined,
types.string,
)
.addOptionalParam("useProxy", "Deploy with proxy", true, types.boolean)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signer = await getSigner(hre, taskArgs.speed)

const l2Chain = chain === Chain.mainnet ? Chain.polygon : Chain.mumbai
const bridgeRecipientAddress = resolveAddress(taskArgs.token, l2Chain, "bridgeRecipient")
await deployBridgeForwarder(signer, hre, bridgeRecipientAddress)
await deployBridgeForwarder(signer, hre, bridgeRecipientAddress, taskArgs.useProxy)
})

task("deploy-basic-forwarder", "Deploys a basic rewards forwarder from the emissions controller.")
Expand Down Expand Up @@ -131,7 +132,7 @@ task("deploy-bal-reward-forwarder", "Deploys a basic rewards forwarder from the
await deployBalRewardsForwarder(signer, emissionsControllerAddress, taskArgs.recipient, hre, taskArgs.owner)
})

task("deploy-bridge-recipient", "Deploys L2 Bridge Recipients for Polygon mUSD Vault and FRAX Farm")
task("deploy-bridge-recipient", "Deploys L2 Bridge Recipients for Polygon")
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const signer = await getSigner(hre, taskArgs.speed)
Expand Down
52 changes: 12 additions & 40 deletions tasks/utils/emissions-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export const deployBridgeForwarder = async (
signer: Signer,
hre: HardhatRuntimeEnvironment,
bridgeRecipientAddress: string,
useProxy: boolean,
_emissionsControllerAddress?: string,
): Promise<BridgeForwarder> => {
const chain = getChain(hre)
Expand All @@ -283,15 +284,18 @@ export const deployBridgeForwarder = async (
const emissionsControllerAddress = _emissionsControllerAddress || resolveAddress("EmissionsController", chain)

const bridgeForwarderImpl = await deployBridgeForwarderImpl(signer, hre, "Vault Bridge Forwarder", bridgeRecipientAddress)

let bridgeForwarder = bridgeForwarderImpl
// Deploy proxy and initialize
const initializeData = bridgeForwarderImpl.interface.encodeFunctionData("initialize", [emissionsControllerAddress])
const proxy = await deployContract(new AssetProxy__factory(signer), "AssetProxy", [
bridgeForwarderImpl.address,
proxyAdminAddress,
initializeData,
])
const bridgeForwarder = new BridgeForwarder__factory(signer).attach(proxy.address)
if (useProxy) {
const initializeData = bridgeForwarderImpl.interface.encodeFunctionData("initialize", [emissionsControllerAddress])

const proxy = await deployContract(new AssetProxy__factory(signer), "AssetProxy", [
bridgeForwarderImpl.address,
proxyAdminAddress,
initializeData,
])
bridgeForwarder = new BridgeForwarder__factory(signer).attach(proxy.address)
}

console.log(`\nSet bridgeForwarder to ${bridgeForwarder.address}`)
console.log(`Governor calls EmissionsController.addDial ${emissionsControllerAddress} with params:`)
Expand All @@ -300,38 +304,6 @@ export const deployBridgeForwarder = async (
return bridgeForwarder
}

export const upgradeBridgeForwarder = async (
signer: Signer,
hre: HardhatRuntimeEnvironment,
bridgeRecipientAddress: string,
proxyAddress: string,
): Promise<BridgeForwarder> => {
const chain = getChain(hre)

const proxyAdminAddress = resolveAddress("DelayedProxyAdmin", chain)

const assetProxy = new AssetProxy__factory(signer).attach(proxyAddress)
const assetProxyAdmin = await assetProxy.callStatic.admin()
const signerAddress = await signer.getAddress()

console.log("AssetProxy address to validate", assetProxyAdmin, signerAddress, proxyAdminAddress)

if (assetProxyAdmin !== signerAddress || assetProxyAdmin !== proxyAdminAddress || proxyAdminAddress !== signerAddress) {
console.log("AssetProxy admin is not the same as the signer", assetProxyAdmin, signerAddress, proxyAdminAddress)
}

const bridgeForwarderImpl = await deployBridgeForwarderImpl(signer, hre, "Vault Bridge Forwarder", bridgeRecipientAddress)

// Upgrade deployed proxy to new implementation
await assetProxy.upgradeTo(bridgeForwarderImpl.address)

const bridgeForwarder = new BridgeForwarder__factory(signer).attach(proxyAddress)

console.log(`\nSet bridgeForwarder to ${bridgeForwarder.address}`)
console.log(`recipient ${bridgeForwarder.address}, cap 0, notify true`)
return bridgeForwarder
}

export const deployRevenueBuyBack = async (
signer: Signer,
hre: HardhatRuntimeEnvironment,
Expand Down
20 changes: 19 additions & 1 deletion test-fork/emissions/emissions-mainnet-deployment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,25 @@ describe("Fork test Emissions Controller on mainnet", async () => {
it("Deploy bridgeForwarder for Polygon mUSD Vault", async () => {
emissionsController = await deployEmissionsController(ops, hre)
const bridgeRecipient = Wallet.createRandom()
const bridgeForwarder = await deployBridgeForwarder(ops, hre, bridgeRecipient.address, emissionsController.address)
const bridgeForwarder = await deployBridgeForwarder(ops, hre, bridgeRecipient.address, true, emissionsController.address)

expect(await bridgeForwarder.BRIDGE_RECIPIENT(), "Bridge Recipient").to.eq(bridgeRecipient.address)
expect(await bridgeForwarder.rewardsDistributor(), "Emissions Controller").to.eq(emissionsController.address)
expect(await bridgeForwarder.BRIDGE_TOKEN_LOCKER(), "Bridge token locker").to.eq("0x40ec5B33f54e0E8A33A975908C5BA1c14e5BbbDf")
expect(await bridgeForwarder.ROOT_CHAIN_MANAGER(), "RootChainMananger").to.eq("0xA0c68C638235ee32657e8f720a23ceC1bFc77C77")
expect(await bridgeForwarder.REWARDS_TOKEN(), "MTA").to.eq(MTA.address)
expect(await mta.allowance(bridgeForwarder.address, "0x40ec5B33f54e0E8A33A975908C5BA1c14e5BbbDf")).to.eq(MAX_UINT256)

const tx = await emissionsController.connect(governor).addDial(bridgeForwarder.address, 0, true)

await expect(tx).to.emit(emissionsController, "AddedDial").withArgs(11, bridgeForwarder.address)

expect(await emissionsController.getDialRecipient(11), "dial 10 Bridge Forwarder").to.eq(bridgeForwarder.address)
})
it("Upgrade a bridgeForwarder proxy", async () => {
// emissionsController = await deployEmissionsController(ops, hre)
const bridgeRecipient = Wallet.createRandom()
const bridgeForwarder = await deployBridgeForwarder(ops, hre, bridgeRecipient.address, true, emissionsController.address)

expect(await bridgeForwarder.BRIDGE_RECIPIENT(), "Bridge Recipient").to.eq(bridgeRecipient.address)
expect(await bridgeForwarder.rewardsDistributor(), "Emissions Controller").to.eq(emissionsController.address)
Expand Down

0 comments on commit 9b6e9b4

Please sign in to comment.