Skip to content

Commit

Permalink
avalanche deployment data
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcoto committed Nov 30, 2023
1 parent aa32aa8 commit 1c02b33
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 97 deletions.
2 changes: 1 addition & 1 deletion contracts/Libraries/Balancer/Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
32 changes: 16 additions & 16 deletions contracts/Libraries/Balancer/StableMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
);
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = {
base: scanApiKey,
optimisticEthereum: scanApiKey,
mainnet: scanApiKey,
avalanche: scanApiKey,
},
customChains: [
{
Expand All @@ -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"
}
},
]
},

Expand Down
10 changes: 4 additions & 6 deletions scripts/deploy/governance/omnichain_governance_executor.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
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");
console.log("===========================================");
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(); }
console.log("Deploying...");


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();
Expand Down
20 changes: 9 additions & 11 deletions scripts/deploy/sweep/balancer.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
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");
console.log("===========================================");
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();
19 changes: 8 additions & 11 deletions scripts/deploy/sweep/sweep.js
Original file line number Diff line number Diff line change
@@ -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("===========================================");
Expand All @@ -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' });

Expand Down
10 changes: 5 additions & 5 deletions scripts/deploy/sweep/treasury.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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...");


Expand Down
17 changes: 15 additions & 2 deletions tasks/setExecutorTrustedRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*");
}


}
16 changes: 13 additions & 3 deletions tasks/setSenderTrustedRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*");
}
}

3 changes: 2 additions & 1 deletion utils/layerzero/chainIds.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"arbitrum": 110,
"optimism": 111,
"base": 184,
"avalanche": 106,

"bsc": 102,
"polygon": 109,
"avalanche": 106,

"linea": 183,
"celo": 125,
"canto": 159,
Expand Down
2 changes: 1 addition & 1 deletion utils/layerzero/layerzeroEndpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"arbitrum": "0x3c2269811836af69497E5F486A85D7316753cf62",
"optimism": "0x3c2269811836af69497E5F486A85D7316753cf62",
"base": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7",
"avalanche": "0x3c2269811836af69497E5F486A85D7316753cf62",

"bsc": "0x3c2269811836af69497E5F486A85D7316753cf62",
"polygon": "0x3c2269811836af69497E5F486A85D7316753cf62",
"avalanche": "0x3c2269811836af69497E5F486A85D7316753cf62",
"linea": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7",
"celo": "0x3A73033C0b1407574C76BdBAc67f126f6b4a9AA9",
"canto": "0x9740FF91F1985D8d2B71494aE1A2f723bb3Ed9E4",
Expand Down
50 changes: 50 additions & 0 deletions utils/networks/avalanche.js
Original file line number Diff line number Diff line change
@@ -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',
}
},

};
Loading

0 comments on commit 1c02b33

Please sign in to comment.