Skip to content

Commit

Permalink
Unpins the usage of the Optimism ops tool and starts managing L2 gas (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 authored Jun 14, 2021
1 parent aeee6b2 commit 504d916
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 88 deletions.
6 changes: 4 additions & 2 deletions hardhat/tasks/task-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ task('ops', 'Run Optimism chain')
.addOptionalParam(
'optimismCommit',
'Commit to checkout',
'86708bb5758cd2b647b3ca2be698beb5aa3af81f'
undefined // Define here to pin to that specific commit
)
.setAction(async (taskArguments, hre, runSuper) => {
const opsPath = taskArguments.optimismPath.replace('~', homedir);
Expand Down Expand Up @@ -142,7 +142,9 @@ function _build({ opsPath, opsCommit }) {
execa.sync('sh', ['-c', `cd ${opsPath} && git fetch `]);
execa.sync('sh', ['-c', `cd ${opsPath} && git checkout master `]);
execa.sync('sh', ['-c', `cd ${opsPath} && git pull origin master `]);
execa.sync('sh', ['-c', `cd ${opsPath} && git checkout ${opsCommit}`]);
if (opsCommit) {
execa.sync('sh', ['-c', `cd ${opsPath} && git checkout ${opsCommit}`]);
}
console.log(gray(' get dependencies'));
execa.sync('sh', ['-c', `cd ${opsPath} && yarn `]);
console.log(gray(' build'));
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const constants = {
ZERO_ADDRESS: '0x' + '0'.repeat(40),
ZERO_BYTES32: '0x' + '0'.repeat(64),

OVM_MAX_GAS_LIMIT: '8999999',
OVM_GAS_PRICE_GWEI: '0.0',

inflationStartTimestampInSecs: 1551830400, // 2019-03-06T00:00:00Z
};
Expand Down
30 changes: 20 additions & 10 deletions publish/src/Deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class Deployer {
*/
this.provider = { web3: {}, ethers: {} };
this.provider.web3 = new Web3(new Web3.providers.HttpProvider(providerUrl));
this.provider.ethers.ro = ethers.getDefaultProvider(providerUrl);
this.provider.ethers.transactional = null;
this.provider.ethers.provider = new ethers.providers.JsonRpcProvider(providerUrl);

if (useFork || (!privateKey && network === 'local')) {
this.provider.web3.eth.defaultAccount = getUsers({ network, user: 'owner' }).address; // protocolDAO
Expand All @@ -68,7 +67,7 @@ class Deployer {
this.provider.web3.eth.accounts.wallet.add(privateKey);
this.provider.web3.eth.defaultAccount = this.provider.web3.eth.accounts.wallet[0].address;

this.provider.ethers.wallet = new ethers.Wallet(privateKey);
this.provider.ethers.wallet = new ethers.Wallet(privateKey, this.provider.ethers.provider);
this.provider.ethers.defaultAccount = this.provider.ethers.wallet.address;
}
this.account = this.provider.ethers.defaultAccount;
Expand Down Expand Up @@ -140,9 +139,15 @@ class Deployer {
}

async sendParameters(type = 'method-call') {
const gas = this.useOvm
? undefined
: type === 'method-call'
? this.methodCallGasLimit
: this.contractDeploymentGasLimit;

const params = {
from: this.account,
gas: type === 'method-call' ? this.methodCallGasLimit : this.contractDeploymentGasLimit,
gas,
gasPrice: ethers.utils.parseUnits(this.gasPrice.toString(), 'gwei'),
};

Expand Down Expand Up @@ -278,12 +283,17 @@ class Deployer {
}

const newContract = new this.provider.web3.eth.Contract(compiled.abi);
deployedContract = await newContract
.deploy({
data: '0x' + bytecode,
arguments: args,
})
.send(await this.sendParameters('contract-deployment'))

const deploymentTx = await newContract.deploy({
data: '0x' + bytecode,
arguments: args,
});

const params = await this.sendParameters('contract-deployment');
params.gas = await deploymentTx.estimateGas();

deployedContract = await deploymentTx
.send(params)
.on('receipt', receipt => (gasUsed = receipt.gasUsed));

if (this.nonceManager) {
Expand Down
97 changes: 49 additions & 48 deletions publish/src/commands/connect-bridge.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const fs = require('fs');
const path = require('path');
const Web3 = require('web3');
const ethers = require('ethers');
const { gray, red, yellow } = require('chalk');
const { wrap, toBytes32 } = require('../../..');
const {
wrap,
toBytes32,
constants: { OVM_GAS_PRICE_GWEI },
} = require('../../..');
const { confirmAction } = require('../util');
const {
ensureNetwork,
Expand All @@ -26,18 +30,17 @@ const connectBridge = async ({
l2Messenger,
dryRun,
l1GasPrice,
l2GasPrice,
gasLimit,
l1GasLimit,
}) => {
// ---------------------------------
// Setup L1 instance
// ---------------------------------

console.log(gray('* Setting up L1 instance...'));
const {
wallet: walletL1,
AddressResolver: AddressResolverL1,
SynthetixBridge: SynthetixBridgeToOptimism,
account: accountL1,
} = await setupInstance({
network: l1Network,
providerUrl: l1ProviderUrl,
Expand All @@ -54,9 +57,9 @@ const connectBridge = async ({

console.log(gray('* Setting up L2 instance...'));
const {
wallet: walletL2,
AddressResolver: AddressResolverL2,
SynthetixBridge: SynthetixBridgeToBase,
account: accountL2,
} = await setupInstance({
network: l2Network,
providerUrl: l2ProviderUrl,
Expand All @@ -73,11 +76,11 @@ const connectBridge = async ({

console.log(gray('* Connecting bridge on L1...'));
await connectLayer({
account: accountL1,
wallet: walletL1,
gasPrice: l1GasPrice,
gasLimit,
gasLimit: l1GasLimit,
names: ['ext:Messenger', 'ovm:SynthetixBridgeToBase'],
addresses: [l1Messenger, SynthetixBridgeToBase.options.address],
addresses: [l1Messenger, SynthetixBridgeToBase.address],
AddressResolver: AddressResolverL1,
SynthetixBridge: SynthetixBridgeToOptimism,
dryRun,
Expand All @@ -89,19 +92,19 @@ const connectBridge = async ({

console.log(gray('* Connecting bridge on L2...'));
await connectLayer({
account: accountL2,
gasPrice: l2GasPrice,
gasLimit,
wallet: walletL2,
gasPrice: OVM_GAS_PRICE_GWEI,
gasLimit: undefined,
names: ['ext:Messenger', 'base:SynthetixBridgeToOptimism'],
addresses: [l2Messenger, SynthetixBridgeToOptimism.options.address],
addresses: [l2Messenger, SynthetixBridgeToOptimism.address],
AddressResolver: AddressResolverL2,
SynthetixBridge: SynthetixBridgeToBase,
dryRun,
});
};

const connectLayer = async ({
account,
wallet,
gasPrice,
gasLimit,
names,
Expand All @@ -121,7 +124,7 @@ const connectLayer = async ({
const address = addresses[i];
console.log(gray(` * Checking if ${name} is already set to ${address}`));

const readAddress = await AddressResolver.methods.getAddress(toBytes32(name)).call();
const readAddress = await AddressResolver.getAddress(toBytes32(name));

if (readAddress.toLowerCase() !== address.toLowerCase()) {
console.log(yellow(` > ${name} is not set, including it...`));
Expand All @@ -137,12 +140,11 @@ const connectLayer = async ({
// ---------------------------------

const params = {
from: account,
gasPrice: Web3.utils.toWei(gasPrice.toString(), 'gwei'),
gasPrice: ethers.utils.parseUnits(gasPrice.toString(), 'gwei'),
gas: gasLimit,
};

let tx;
let tx, receipt;

if (needToImportAddresses) {
const ids = names.map(toBytes32);
Expand All @@ -155,25 +157,24 @@ const connectLayer = async ({
yellow.inverse(` * CALLING AddressResolver.importAddresses([${ids}], [${addresses}])`)
);

const owner = await AddressResolver.methods.owner().call();
if (account.toLowerCase() !== owner.toLowerCase()) {
const owner = await AddressResolver.owner();
if (wallet.address.toLowerCase() !== owner.toLowerCase()) {
await confirmAction(
yellow(
` ⚠️ AddressResolver is owned by ${owner} and the current signer is $${account}. Please execute the above transaction and press "y" when done.`
` ⚠️ AddressResolver is owned by ${owner} and the current signer is $${wallet.address}. Please execute the above transaction and press "y" when done.`
)
);
} else {
tx = await AddressResolver.methods
.importAddresses(names.map(toBytes32), addresses)
.send(params);
console.log(gray(` > tx hash: ${tx.transactionHash}`));
tx = await AddressResolver.importAddresses(names.map(toBytes32), addresses, params);
receipt = await tx.wait();
console.log(gray(` > tx hash: ${receipt.transactionHash}`));
}
} else {
console.log(yellow(' * Skipping, since this is a DRY RUN'));
}
} else {
console.log(
gray(' * Bridge is already does not need to import any addresses in this layer. Skipping...')
gray(' * Bridge does not need to import any addresses in this layer. Skipping...')
);
}

Expand All @@ -183,7 +184,7 @@ const connectLayer = async ({

let needToSyncCacheOnBridge = needToImportAddresses;
if (!needToSyncCacheOnBridge) {
const isResolverCached = await SynthetixBridge.methods.isResolverCached().call();
const isResolverCached = await SynthetixBridge.isResolverCached();
if (!isResolverCached) {
needToSyncCacheOnBridge = true;
}
Expand All @@ -194,7 +195,8 @@ const connectLayer = async ({

if (!dryRun) {
console.log(yellow.inverse(' * CALLING SynthetixBridge.rebuildCache()...'));
tx = await SynthetixBridge.methods.rebuildCache().send(params);
tx = await SynthetixBridge.rebuildCache(params);
receipt = await tx.wait();
console.log(gray(` > tx hash: ${tx.transactionHash}`));
} else {
console.log(yellow(' * Skipping, since this is a DRY RUN'));
Expand All @@ -218,40 +220,40 @@ const setupInstance = async ({
console.log(gray(' > useFork:', useFork));
console.log(gray(' > useOvm:', useOvm));

const { web3, getSource, getTarget, providerUrl, account } = bootstrapConnection({
const { wallet, provider, getSource, getTarget } = bootstrapConnection({
network,
providerUrl: specifiedProviderUrl,
deploymentPath,
privateKey,
useFork,
useOvm,
});
console.log(gray(' > provider:', providerUrl));
console.log(gray(' > account:', account));
console.log(gray(' > provider:', provider.url));
console.log(gray(' > account:', wallet.address));

const AddressResolver = getContract({
contract: 'AddressResolver',
getTarget,
getSource,
deploymentPath,
web3,
wallet,
});
console.log(gray(' > AddressResolver:', AddressResolver.options.address));
console.log(gray(' > AddressResolver:', AddressResolver.address));

const bridgeName = useOvm ? 'SynthetixBridgeToBase' : 'SynthetixBridgeToOptimism';
const SynthetixBridge = getContract({
contract: bridgeName,
getTarget,
getSource,
deploymentPath,
web3,
wallet,
});
console.log(gray(` > ${bridgeName}:`, SynthetixBridge.options.address));
console.log(gray(` > ${bridgeName}:`, SynthetixBridge.address));

return {
wallet,
AddressResolver,
SynthetixBridge,
account,
};
};

Expand All @@ -278,31 +280,31 @@ const bootstrapConnection = ({
}

const providerUrl = specifiedProviderUrl || defaultProviderUrl;
const web3 = new Web3(new Web3.providers.HttpProvider(providerUrl));
const provider = new ethers.providers.JsonRpcProvider(providerUrl);

const { getUsers, getTarget, getSource } = wrap({ network, useOvm, fs, path });

let account;
let wallet;
if (useFork) {
account = getUsers({ network, user: 'owner' }).address; // protocolDAO
const account = getUsers({ network, user: 'owner' }).address;
wallet = provider.getSigner(account);
} else {
web3.eth.accounts.wallet.add(privateKey);
account = web3.eth.accounts.wallet[0].address;
wallet = new ethers.Wallet(privateKey, provider);
}

return {
deploymentPath,
providerUrl,
privateKey,
web3,
account,
provider,
wallet,
getTarget,
getSource,
getUsers,
};
};

const getContract = ({ contract, deploymentPath, getTarget, getSource, web3 }) => {
const getContract = ({ contract, deploymentPath, getTarget, getSource, wallet }) => {
const target = getTarget({ deploymentPath, contract });
if (!target) {
throw new Error(`Unable to find deployed target for ${contract} in ${deploymentPath}`);
Expand All @@ -313,7 +315,7 @@ const getContract = ({ contract, deploymentPath, getTarget, getSource, web3 }) =
throw new Error(`Unable to find source for ${contract}`);
}

return new web3.eth.Contract(source.abi, target.address);
return new ethers.Contract(target.address, source.abi, wallet);
};

module.exports = {
Expand All @@ -334,9 +336,8 @@ module.exports = {
.option('--l2-use-fork', 'Wether to use a fork for the L2 connection', false)
.option('--l1-messenger <value>', 'L1 cross domain messenger to use')
.option('--l2-messenger <value>', 'L2 cross domain messenger to use')
.option('-g, --l1-gas-price <value>', 'Gas price to set when performing transfers in L1', 1)
.option('-g, --l2-gas-price <value>', 'Gas price to set when performing transfers in L2', 1)
.option('-l, --gas-limit <value>', 'Max gas to use when signing transactions', 8000000)
.option('--l1-gas-price <value>', 'Gas price to set when performing transfers in L1', 1)
.option('--l1-gas-limit <value>', 'Max gas to use when signing transactions to l1', 8000000)
.option('--dry-run', 'Do not execute any transactions')
.action(async (...args) => {
try {
Expand Down
Loading

0 comments on commit 504d916

Please sign in to comment.