From 1c02b339e821aebea5ceade1c0bd87e999f45928 Mon Sep 17 00:00:00 2001 From: maxcoto Date: Wed, 29 Nov 2023 17:31:48 -0300 Subject: [PATCH] avalanche deployment data --- contracts/Libraries/Balancer/Math.sol | 2 +- contracts/Libraries/Balancer/StableMath.sol | 32 +++++------ hardhat.config.js | 11 +++- .../omnichain_governance_executor.js | 10 ++-- scripts/deploy/sweep/balancer.js | 20 +++---- scripts/deploy/sweep/sweep.js | 19 +++---- scripts/deploy/sweep/treasury.js | 10 ++-- tasks/setExecutorTrustedRemote.js | 17 +++++- tasks/setSenderTrustedRemote.js | 16 +++++- utils/layerzero/chainIds.json | 3 +- utils/layerzero/layerzeroEndpoints.json | 2 +- utils/networks/avalanche.js | 50 ++++++++++++++++ utils/networks/example.js | 57 +++++++------------ utils/networks/optimism.js | 1 - 14 files changed, 153 insertions(+), 97 deletions(-) create mode 100644 utils/networks/avalanche.js diff --git a/contracts/Libraries/Balancer/Math.sol b/contracts/Libraries/Balancer/Math.sol index c1d5922f..b456ece1 100644 --- a/contracts/Libraries/Balancer/Math.sol +++ b/contracts/Libraries/Balancer/Math.sol @@ -5,7 +5,7 @@ pragma solidity 0.8.19; * @dev Wrappers over Solidity's arithmetic operations with added overflow checks. * Adapted from OpenZeppelin's SafeMath library. */ -library Math { +library BMath { // solhint-disable no-inline-assembly /** diff --git a/contracts/Libraries/Balancer/StableMath.sol b/contracts/Libraries/Balancer/StableMath.sol index 9fd9eabc..416f52f3 100644 --- a/contracts/Libraries/Balancer/StableMath.sol +++ b/contracts/Libraries/Balancer/StableMath.sol @@ -36,21 +36,21 @@ library StableMath { for (uint256 j = 0; j < numTokens; j++) { // (D_P * invariant) / (balances[j] * numTokens) - D_P = Math.divDown(Math.mul(D_P, invariant), Math.mul(balances[j], numTokens)); + D_P = BMath.divDown(BMath.mul(D_P, invariant), BMath.mul(balances[j], numTokens)); } prevInvariant = invariant; - invariant = Math.divDown( - Math.mul( + invariant = BMath.divDown( + BMath.mul( // (ampTimesTotal * sum) / AMP_PRECISION + D_P * numTokens - (Math.divDown(Math.mul(ampTimesTotal, sum), _AMP_PRECISION).add(Math.mul(D_P, numTokens))), + (BMath.divDown(BMath.mul(ampTimesTotal, sum), _AMP_PRECISION).add(BMath.mul(D_P, numTokens))), invariant ), // ((ampTimesTotal - _AMP_PRECISION) * invariant) / _AMP_PRECISION + (numTokens + 1) * D_P ( - Math.divDown(Math.mul((ampTimesTotal - _AMP_PRECISION), invariant), _AMP_PRECISION).add( - Math.mul((numTokens + 1), D_P) + BMath.divDown(BMath.mul((ampTimesTotal - _AMP_PRECISION), invariant), _AMP_PRECISION).add( + BMath.mul((numTokens + 1), D_P) ) ) ); @@ -319,32 +319,32 @@ library StableMath { uint256 sum = balances[0]; uint256 P_D = balances[0] * balances.length; for (uint256 j = 1; j < balances.length; j++) { - P_D = Math.divDown(Math.mul(Math.mul(P_D, balances[j]), balances.length), invariant); + P_D = BMath.divDown(BMath.mul(BMath.mul(P_D, balances[j]), balances.length), invariant); sum = sum.add(balances[j]); } - // No need to use safe math, based on the loop above `sum` is greater than or equal to `balances[tokenIndex]` + // No need to use safe Bmath, based on the loop above `sum` is greater than or equal to `balances[tokenIndex]` sum = sum - balances[tokenIndex]; - uint256 inv2 = Math.mul(invariant, invariant); + uint256 inv2 = BMath.mul(invariant, invariant); // We remove the balance from c by multiplying it - uint256 c = Math.mul( - Math.mul(Math.divUp(inv2, Math.mul(ampTimesTotal, P_D)), _AMP_PRECISION), + uint256 c = BMath.mul( + BMath.mul(BMath.divUp(inv2, BMath.mul(ampTimesTotal, P_D)), _AMP_PRECISION), balances[tokenIndex] ); - uint256 b = sum.add(Math.mul(Math.divDown(invariant, ampTimesTotal), _AMP_PRECISION)); + uint256 b = sum.add(BMath.mul(BMath.divDown(invariant, ampTimesTotal), _AMP_PRECISION)); // We iterate to find the balance uint256 prevTokenBalance = 0; // We multiply the first iteration outside the loop with the invariant to set the value of the // initial approximation. - uint256 tokenBalance = Math.divUp(inv2.add(c), invariant.add(b)); + uint256 tokenBalance = BMath.divUp(inv2.add(c), invariant.add(b)); for (uint256 i = 0; i < 255; i++) { prevTokenBalance = tokenBalance; - tokenBalance = Math.divUp( - Math.mul(tokenBalance, tokenBalance).add(c), - Math.mul(tokenBalance, 2).add(b).sub(invariant) + tokenBalance = BMath.divUp( + BMath.mul(tokenBalance, tokenBalance).add(c), + BMath.mul(tokenBalance, 2).add(b).sub(invariant) ); if (tokenBalance > prevTokenBalance) { diff --git a/hardhat.config.js b/hardhat.config.js index fe75594a..2c484668 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -59,6 +59,7 @@ module.exports = { base: scanApiKey, optimisticEthereum: scanApiKey, mainnet: scanApiKey, + avalanche: scanApiKey, }, customChains: [ { @@ -68,7 +69,15 @@ module.exports = { apiURL: "https://api.basescan.org/api", browserURL: "https://basescan.org" } - } + }, + { + network: "avalanche", + chainId: 43114, + urls: { + apiURL: "https://api.routescan.io/v2/network/mainnet/evm/43114/etherscan", + browserURL: "https://avalanche.routescan.io" + } + }, ] }, diff --git a/scripts/deploy/governance/omnichain_governance_executor.js b/scripts/deploy/governance/omnichain_governance_executor.js index 200fb567..9cbdec8f 100644 --- a/scripts/deploy/governance/omnichain_governance_executor.js +++ b/scripts/deploy/governance/omnichain_governance_executor.js @@ -1,11 +1,9 @@ const { ethers } = require("hardhat"); -const { network } = require("../../../utils/address"); +const { network, layerZero } = require("../../../utils/constants"); const { ask } = require("../../../utils/helper_functions"); -const LZ_ENDPOINTS = require("../../../utils/layerzero/layerzeroEndpoints.json") async function main() { [deployer] = await ethers.getSigners(); - const lzEndpointAddress = LZ_ENDPOINTS[hre.network.name]; console.log("==========================================="); console.log("OMNICHAIN GOVERNANCE EXECUTOR - DEPLOY"); @@ -13,7 +11,7 @@ async function main() { console.log("Network:", network.name); console.log("Deployer:", deployer.address); console.log("==========================================="); - console.log("lzEndpointAddress:", lzEndpointAddress); + console.log("lzEndpointAddress:", layerZero.endpoint); console.log("==========================================="); const answer = (await ask("continue? y/n: ")); if(answer !== 'y'){ process.exit(); } @@ -21,12 +19,12 @@ async function main() { const OmnichainProposalExecutor = await ethers.getContractFactory("OmnichainGovernanceExecutor"); - const proposalExecutor = await OmnichainProposalExecutor.deploy(lzEndpointAddress); + const proposalExecutor = await OmnichainProposalExecutor.deploy(layerZero.endpoint); await proposalExecutor.deployed(); console.log("==========================================="); console.log("OmnichainGovernanceExecutor deployed to: ", proposalExecutor.address); - console.log(`\nnpx hardhat verify --network ${network.name} ${proposalExecutor.address} ${lzEndpointAddress}`); + console.log(`\nnpx hardhat verify --network ${network.name} ${proposalExecutor.address} ${layerZero.endpoint}`); } main(); diff --git a/scripts/deploy/sweep/balancer.js b/scripts/deploy/sweep/balancer.js index f4ee8b04..486c1d29 100644 --- a/scripts/deploy/sweep/balancer.js +++ b/scripts/deploy/sweep/balancer.js @@ -1,12 +1,10 @@ const { ethers } = require("hardhat"); -const { addresses, network } = require("../../../utils/address"); -const { sleep } = require("../../../utils/helper_functions"); -const LZ_ENDPOINTS = require("../../../utils/layerzero/layerzeroEndpoints.json") +const { tokens, network, layerZero } = require("../../../utils/constants"); +const { ask } = require("../../../utils/helper_functions"); async function main() { [deployer] = await ethers.getSigners(); - const lzEndpointAddress = LZ_ENDPOINTS[hre.network.name]; - const sweep = addresses.sweep; + const sweep = tokens.sweep; console.log("==========================================="); console.log("BALANCER DEPLOY"); @@ -14,20 +12,20 @@ async function main() { console.log("Network:", network.name); console.log("Deployer:", deployer.address); console.log("==========================================="); - console.log("lzEndpointAddress:", lzEndpointAddress); + console.log("lzEndpointAddress:", layerZero.endpoint); console.log("SweepAddress:", sweep); console.log("==========================================="); - console.log("Deploying in 5 seconds..."); - await sleep(5); - console.log("Deploying..."); + const answer = (await ask("continue? y/n: ")); + if(answer !== 'y'){ process.exit(); } + console.log("Deploying..."); const Balancer = await ethers.getContractFactory("Balancer"); - const balancer = await Balancer.deploy(sweep, lzEndpointAddress); + const balancer = await Balancer.deploy(sweep, layerZero.endpoint); console.log("==========================================="); console.log("Balancer deployed to:", balancer.address); - console.log(`\nnpx hardhat verify --network ${network.name} ${balancer.address} ${sweep} ${lzEndpointAddress}`) + console.log(`\nnpx hardhat verify --network ${network.name} ${balancer.address} ${sweep} ${layerZero.endpoint}`) } main(); diff --git a/scripts/deploy/sweep/sweep.js b/scripts/deploy/sweep/sweep.js index ae9f0a0a..06bc3f5d 100644 --- a/scripts/deploy/sweep/sweep.js +++ b/scripts/deploy/sweep/sweep.js @@ -1,11 +1,9 @@ const { ethers, upgrades } = require('hardhat'); -const { addresses, network } = require("../../../utils/address"); -const { sleep } = require("../../../utils/helper_functions"); -const LZ_ENDPOINTS = require("../../../utils/layerzero/layerzeroEndpoints.json") +const { network, layerZero, wallets } = require("../../../utils/constants"); +const { ask } = require("../../../utils/helper_functions"); async function main() { [deployer] = await ethers.getSigners(); - const lzEndpointAddress = LZ_ENDPOINTS[hre.network.name]; const stepValue = 70000; // 0.00274% daily rate ~ 4% yearly rate console.log("==========================================="); @@ -14,19 +12,18 @@ async function main() { console.log("Network:", network.name); console.log("Deployer:", deployer.address); console.log("==========================================="); - console.log("lzEndpointAddress:", lzEndpointAddress); - console.log("Multisig:", addresses.multisig); + console.log("lzEndpointAddress:", layerZero.endpoint); + console.log("Multisig:", wallets.multisig); console.log("StepValue:", stepValue); console.log("==========================================="); - console.log("Deploying in 5 seconds..."); - await sleep(5); + const answer = (await ask("continue? y/n: ")); + if(answer !== 'y'){ process.exit(); } console.log("Deploying..."); - const sweepInstance = await ethers.getContractFactory("SweepCoin"); const sweep = await upgrades.deployProxy(sweepInstance, [ - lzEndpointAddress, - addresses.multisig, + layerZero.endpoint, + wallets.multisig, stepValue ], { initializer: 'initialize' }); diff --git a/scripts/deploy/sweep/treasury.js b/scripts/deploy/sweep/treasury.js index 3ca91a66..c9ca3109 100644 --- a/scripts/deploy/sweep/treasury.js +++ b/scripts/deploy/sweep/treasury.js @@ -1,10 +1,10 @@ const { ethers } = require("hardhat"); -const { addresses, network } = require("../../../utils/address"); -const { sleep } = require("../../../utils/helper_functions"); +const { tokens, network } = require("../../../utils/constants"); +const { ask } = require("../../../utils/helper_functions"); async function main() { [deployer] = await ethers.getSigners(); - const sweep = addresses.sweep; + const sweep = tokens.sweep; console.log("==========================================="); console.log("TREASURY DEPLOY"); @@ -14,8 +14,8 @@ async function main() { console.log("==========================================="); console.log("SweepAddress:", sweep); console.log("==========================================="); - console.log("Deploying in 5 seconds..."); - await sleep(5); + const answer = (await ask("continue? y/n: ")); + if(answer !== 'y'){ process.exit(); } console.log("Deploying..."); diff --git a/tasks/setExecutorTrustedRemote.js b/tasks/setExecutorTrustedRemote.js index 22bea394..567ca894 100644 --- a/tasks/setExecutorTrustedRemote.js +++ b/tasks/setExecutorTrustedRemote.js @@ -8,6 +8,19 @@ module.exports = async function (taskArgs, hre) { const targetChainId = targetNetwork.layerZero.id; - console.log(sourceNetwork.network.name, "=> OmnichainGovernanceExecutor @", sourceAddress); - console.log("setTrustedRemoteAddress", targetChainId, targetAddress); + const OGE = await ethers.getContractAt("OmnichainGovernanceExecutor", sourceAddress); + + let currentRemoteAddress = ""; + try { + currentRemoteAddress = await OGE.getTrustedRemoteAddress(targetChainId); + } catch (e) {} + + if(currentRemoteAddress.toUpperCase() !== targetAddress.toUpperCase()) { + console.log(sourceNetwork.network.name, "=> OmnichainGovernanceExecutor @", sourceAddress); + console.log("setTrustedRemoteAddress", targetChainId, targetAddress); + } else { + console.log("*source already set*"); + } + + } diff --git a/tasks/setSenderTrustedRemote.js b/tasks/setSenderTrustedRemote.js index 4f114ca6..1eff7221 100644 --- a/tasks/setSenderTrustedRemote.js +++ b/tasks/setSenderTrustedRemote.js @@ -5,10 +5,20 @@ module.exports = async function (taskArgs, hre) { const targetNetwork = require('../utils/networks/' + taskArgs.targetNetwork); const targetAddress = targetNetwork.deployments.proposal_executor; - const sourceBalancer = await ethers.getContractAt("Balancer", sourceAddress); const targetChainId = targetNetwork.layerZero.id; - console.log(sourceNetwork.network.name, "=> OmnichainProposalSender @", sourceAddress); - console.log("setTrustedRemoteAddress", targetChainId, targetAddress); + const OPS = await ethers.getContractAt("OmnichainProposalSender", sourceAddress); + + let currentRemoteAddress = ""; + try { + currentRemoteAddress = await OPS.getTrustedRemoteAddress(targetChainId); + } catch (e) {} + + if(currentRemoteAddress.toUpperCase() !== targetAddress.toUpperCase()) { + console.log(sourceNetwork.network.name, "=> OmnichainProposalSender @", sourceAddress); + console.log("setTrustedRemoteAddress", targetChainId, targetAddress); + } else { + console.log("*source already set*"); + } } diff --git a/utils/layerzero/chainIds.json b/utils/layerzero/chainIds.json index 9db7549b..5bfad478 100644 --- a/utils/layerzero/chainIds.json +++ b/utils/layerzero/chainIds.json @@ -3,10 +3,11 @@ "arbitrum": 110, "optimism": 111, "base": 184, + "avalanche": 106, "bsc": 102, "polygon": 109, - "avalanche": 106, + "linea": 183, "celo": 125, "canto": 159, diff --git a/utils/layerzero/layerzeroEndpoints.json b/utils/layerzero/layerzeroEndpoints.json index bfaeb2b0..a9771921 100644 --- a/utils/layerzero/layerzeroEndpoints.json +++ b/utils/layerzero/layerzeroEndpoints.json @@ -3,10 +3,10 @@ "arbitrum": "0x3c2269811836af69497E5F486A85D7316753cf62", "optimism": "0x3c2269811836af69497E5F486A85D7316753cf62", "base": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7", + "avalanche": "0x3c2269811836af69497E5F486A85D7316753cf62", "bsc": "0x3c2269811836af69497E5F486A85D7316753cf62", "polygon": "0x3c2269811836af69497E5F486A85D7316753cf62", - "avalanche": "0x3c2269811836af69497E5F486A85D7316753cf62", "linea": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7", "celo": "0x3A73033C0b1407574C76BdBAc67f126f6b4a9AA9", "canto": "0x9740FF91F1985D8d2B71494aE1A2f723bb3Ed9E4", diff --git a/utils/networks/avalanche.js b/utils/networks/avalanche.js new file mode 100644 index 00000000..32eeda60 --- /dev/null +++ b/utils/networks/avalanche.js @@ -0,0 +1,50 @@ +module.exports = { + + network: { + id: 43114, + name: 'avalanche', + }, + + layerZero: { + id: 106, + endpoint: '0x3c2269811836af69497E5F486A85D7316753cf62', + }, + + alchemyLink: 'https://api.avax.network/ext/bc/C/rpc', + scanApiKey: 'avalanche', + + wallets: { + multisig: '0x04997790D83C9f8021c63f6f613458507B73056c', + owner: '0x7Adc86401f246B87177CEbBEC189dE075b75Af3A', + }, + + tokens: { + sweep: '0xB88a5Ac00917a02d82c7cd6CEBd73E2852d43574', + sweepr: '0x89B1e7068bF8E3232dD8f16c35cAc45bDA584f4E', + usdc: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', + }, + + protocols: { }, + + chainlink: { + usdc_usd: '0xf096872672f44d6eba71458d74fe67f9a77a23b9', + sequencer: '0x0000000000000000000000000000000000000000', + }, + + balancer: { + factory: '0xE42FFA682A26EF8F25891db4882932711D42e467', + }, + + deployments: { + balancer: '0xa884970F06Dda7BedD86829E14BeCa2c8fEd5220', + treasury: '0x7c9131d7E2bEdb29dA39503DD8Cf809739f047B3', + balancer_pool: '0x121b0DfC48444C4d10caddeD9885D90E7453E878', + balancer_amm: '0x9693AEea2B32452e0834C860E01C33295d2164a5', + proposal_executor: '0xE7b247DBbb1bFdC8E223e78F9585ACF93Df297f5', + + assets: { + market_maker: '0x26D68988843197B22AB03c92519b357eCd9c5b5f', + } + }, + +}; diff --git a/utils/networks/example.js b/utils/networks/example.js index 4be538f7..ab02caf6 100644 --- a/utils/networks/example.js +++ b/utils/networks/example.js @@ -10,59 +10,40 @@ module.exports = { endpoint: '', }, - alchemyLink: '' + process.env.ALCHEMY_KEY, - scanApiKey: process.env.XXXXXXSCAN_API_KEY, - - misc: { - observationCardinality: 480, - }, + alchemyLink: '', + scanApiKey: '', wallets: { - multisig: '', - owner: '0x7Adc86401f246B87177CEbBEC189dE075b75Af3A', + multisig: '', + owner: '', }, - + tokens: { - sweep: '0xB88a5Ac00917a02d82c7cd6CEBd73E2852d43574', - sweepr: '0x89B1e7068bF8E3232dD8f16c35cAc45bDA584f4E', - usdc: '', - usdc_e: '', + sweep: '0xB88a5Ac00917a02d82c7cd6CEBd73E2852d43574', + sweepr: '0x89B1e7068bF8E3232dD8f16c35cAc45bDA584f4E', + usdc: '', }, - assets: { - usdPlus_exchanger: '', - maple: { - usdcPool: '', - poolManager: '', - withdrawalManager: '', - } - }, + protocols: { }, chainlink: { - usdc_usd: '', - sequencer: '', + usdc_usd: '', + sequencer: '', }, - uniswap: { - factory: '', - universal_router: '', - positions_manager: '', - quoterV2: '', + balancer: { + factory: '', }, deployments: { - balancer: '', - treasury: '', - liquidity_helper: '', - pool: '', - amm: '', - proposal_executor: '', + balancer: '', + treasury: '', + balancer_pool: '', + balancer_amm: '', + proposal_executor: '', assets: { - uniswap: '', - market_maker: '', - usd_plus: '', - maple: '', + market_maker: '', } }, diff --git a/utils/networks/optimism.js b/utils/networks/optimism.js index 31b39806..e7b0971c 100755 --- a/utils/networks/optimism.js +++ b/utils/networks/optimism.js @@ -42,7 +42,6 @@ module.exports = { positions_manager: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88', quoter: '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6', observationCardinality: 480, - pool: '' }, balancer: {