Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate deploy confirms; delegates report; consistent swapERC20Contract #1334

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"check:owners": "node ./scripts/owners-report.js",
"check:receivers": "node ./scripts/receivers-report.js",
"check:wrappers": "node ./scripts/wrappers-report.js",
"check:delegates": "node ./scripts/delegates-report.js",
"clean": "lerna run clean",
"compile": "lerna run compile",
"linter": "yarn eslint . --ext .js,.ts --fix",
Expand Down
59 changes: 59 additions & 0 deletions scripts/delegates-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require('dotenv').config({ path: './.env' })
const { ethers } = require('ethers')
const { mainnets, chainNames, apiUrls } = require('@airswap/utils')
const swapERC20Deploys = require('@airswap/swap-erc20/deploys.js')

async function main() {
console.log()
for (const chainId of mainnets) {
const apiUrl = apiUrls[chainId]
const provider = new ethers.providers.JsonRpcProvider(apiUrl)
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)

const deploys = require('../source/delegate/deploys.js')
const {
Delegate__factory,
} = require('@airswap/delegate/typechain/factories/contracts')
if (deploys[chainId]) {
const contract = Delegate__factory.connect(deploys[chainId], deployer)
const currentSwapERC20 = await contract.swapERC20Contract()

const intendedSwapERC20 = swapERC20Deploys[chainId]

if (intendedSwapERC20) {
console.log(
chainNames[chainId].toUpperCase(),
`(${chainId})`,
'· Intended SwapERC20: ',
intendedSwapERC20
)

let label = 'Delegate has correct SwapERC20'
if (currentSwapERC20 !== intendedSwapERC20) {
label = `Delegate has incorrect SwapERC20: ${currentSwapERC20}`
}
console.log(currentSwapERC20 === intendedSwapERC20 ? '✔' : '✘', label)
} else {
console.log(
chainNames[chainId].toUpperCase(),
`(${chainId})`,
'✘ SwapERC20 not deployed'
)
}
} else {
console.log(
chainNames[chainId].toUpperCase(),
`(${chainId})`,
'✘ Delegate not deployed'
)
}
console.log()
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
28 changes: 18 additions & 10 deletions scripts/deployer-info.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
const Confirm = require('prompt-confirm')
const {
chainNames,
chainCurrencies,
EVM_NATIVE_TOKEN_DECIMALS,
} = require('@airswap/utils')

module.exports = {
displayDeployerInfo: async function (deployer) {
confirmDeployment: async function (deployer, targetAddress) {
const gasPrice = await deployer.getGasPrice()
const chainId = await deployer.getChainId()
const balance = ethers.utils.formatUnits(
(await deployer.getBalance()).toString(),
EVM_NATIVE_TOKEN_DECIMALS
)
console.log(`\nNetwork: ${chainNames[chainId].toUpperCase()}`)
console.log(`Gas price: ${gasPrice / 10 ** 9} gwei`)
console.log(`\nDeployer: ${deployer.address}`)
console.log(`Balance: ${balance} ${chainCurrencies[chainId]}`)
console.log(`To ${chainNames[chainId].toUpperCase()}`)
console.log(`· Gas price ${gasPrice / 10 ** 9} gwei`)
console.log(`· Deployer wallet ${deployer.address}`)
console.log(`· Deployer balance ${balance} ${chainCurrencies[chainId]}`)

console.log(
`\nNext contract address will be:\n${ethers.utils.getContractAddress({
from: deployer.address,
nonce: await deployer.provider.getTransactionCount(deployer.address),
})}\n`
const nextAddress = ethers.utils.getContractAddress({
from: deployer.address,
nonce: await deployer.provider.getTransactionCount(deployer.address),
})

console.log(`· Contract address ${nextAddress}\n`)

const prompt = new Confirm(
nextAddress === targetAddress || !targetAddress
? 'Proceed to deploy?'
: 'Address would not match mainnet. Proceed anyway?'
)
return await prompt.run()
},
}
17 changes: 10 additions & 7 deletions scripts/wrappers-report.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
require('dotenv').config({ path: './.env' })
const { ethers } = require('ethers')
const { mainnets, testnets, chainNames, apiUrls } = require('@airswap/utils')
const { mainnets, chainNames, apiUrls } = require('@airswap/utils')
const swapERC20Deploys = require('@airswap/swap-erc20/deploys.js')

const chains = mainnets.concat(testnets)

async function main() {
console.log()
for (let c = 0; c < chains.length; c++) {
const chainId = chains[c]
for (const chainId of mainnets) {
const apiUrl = apiUrls[chainId]
const provider = new ethers.providers.JsonRpcProvider(apiUrl)
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
Expand Down Expand Up @@ -40,11 +37,17 @@ async function main() {
console.log(
chainNames[chainId].toUpperCase(),
`(${chainId})`,
'✘ Not deployed'
'✘ SwapERC20 not deployed'
)
}
console.log()
} else {
console.log(
chainNames[chainId].toUpperCase(),
`(${chainId})`,
'✘ Wrapper not deployed'
)
}
console.log()
}
}

Expand Down
14 changes: 4 additions & 10 deletions source/batch-call/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable no-console */
const fs = require('fs')
const prettier = require('prettier')
const Confirm = require('prompt-confirm')
const { ethers, run } = require('hardhat')
const { ChainIds, chainLabels } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const batchCallDeploys = require('../deploys.js')
const batchCallBlocks = require('../deploys-blocks.js')
const batchCallCommits = require('../deploys-commits.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')
const { confirmDeployment } = require('../../../scripts/deployer-info')

async function main() {
await run('compile')
Expand All @@ -19,14 +18,9 @@ async function main() {
console.log('Value for --network flag is required')
return
}
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = batchCallDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
console.log(`\nDeploy BATCHCALL\n`)

if (await confirmDeployment(deployer, batchCallDeploys)) {
const batchFactory = await ethers.getContractFactory('BatchCall')
const batchCallContract = await batchFactory.deploy()
console.log(
Expand Down
20 changes: 11 additions & 9 deletions source/delegate/contracts/Delegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { SafeTransferLib } from "solady/src/utils/SafeTransferLib.sol";
*/
contract Delegate is IDelegate, Ownable {
// The SwapERC20 contract to be used to execute orders
ISwapERC20 public swapERC20;
ISwapERC20 public swapERC20Contract;

// Mapping of sender to senderToken to to signerToken to Rule
mapping(address => mapping(address => mapping(address => Rule))) public rules;
Expand All @@ -25,9 +25,9 @@ contract Delegate is IDelegate, Ownable {
/**
* @notice Contract Constructor
*/
constructor(ISwapERC20 _swapERC20) {
constructor(ISwapERC20 _swapERC20Contract) {
_initializeOwner(msg.sender);
swapERC20 = _swapERC20;
swapERC20Contract = _swapERC20Contract;
}

/**
Expand Down Expand Up @@ -153,12 +153,12 @@ contract Delegate is IDelegate, Ownable {

SafeTransferLib.safeApprove(
_senderToken,
address(swapERC20),
address(swapERC20Contract),
_senderAmount
);

// Execute the swap
swapERC20.swapLight(
swapERC20Contract.swapLight(
_nonce,
_expiry,
_signerWallet,
Expand Down Expand Up @@ -203,10 +203,12 @@ contract Delegate is IDelegate, Ownable {

/**
* @notice Sets the SwapERC20 contract
* @param _swapERC20 ISwapERC20 The SwapERC20 contract
* @param _swapERC20Contract ISwapERC20 The SwapERC20 contract
*/
function setSwapERC20Contract(ISwapERC20 _swapERC20) external onlyOwner {
if (address(_swapERC20) == address(0)) revert AddressInvalid();
swapERC20 = _swapERC20;
function setSwapERC20Contract(
ISwapERC20 _swapERC20Contract
) external onlyOwner {
if (address(_swapERC20Contract) == address(0)) revert AddressInvalid();
swapERC20Contract = _swapERC20Contract;
}
}
18 changes: 6 additions & 12 deletions source/delegate/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-console */
const fs = require('fs')
const prettier = require('prettier')
const Confirm = require('prompt-confirm')

const { ethers, run } = require('hardhat')
const swapERC20Deploys = require('@airswap/swap-erc20/deploys.js')
const { ChainIds, chainLabels } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const delegateDeploys = require('../deploys.js')
const delegateBlocks = require('../deploys-blocks.js')
const delegateCommits = require('../deploys-commits.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')
const { confirmDeployment } = require('../../../scripts/deployer-info')

async function main() {
await run('compile')
Expand All @@ -20,18 +20,12 @@ async function main() {
console.log('Value for --network flag is required')
return
}
await displayDeployerInfo(deployer)

console.log(`swapERC20Contract: ${swapERC20Deploys[chainId]}\n`)
console.log(`\nDeploy DELEGATE`)

console.log(`· swapERC20Contract ${swapERC20Deploys[chainId]}\n`)

const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = delegateDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
if (await confirmDeployment(deployer, delegateDeploys[ChainIds.MAINNET])) {
const delegateFactory = await ethers.getContractFactory('Delegate')
const delegateContract = await delegateFactory.deploy(
swapERC20Deploys[chainId]
Expand Down
6 changes: 4 additions & 2 deletions source/delegate/test/Delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ describe('Delegate Unit', () => {

describe('Constructor and admin functions', async () => {
it('swap ERC20 address is set', async () => {
expect(await delegate.swapERC20()).to.equal(swapERC20.address)
expect(await delegate.swapERC20Contract()).to.equal(swapERC20.address)
})

it('sets the swapERC20Contract address', async () => {
await delegate.setSwapERC20Contract(UPDATE_SWAP_ERC20_ADDRESS)
expect(await delegate.swapERC20()).to.equal(UPDATE_SWAP_ERC20_ADDRESS)
expect(await delegate.swapERC20Contract()).to.equal(
UPDATE_SWAP_ERC20_ADDRESS
)
})

it('the swapERC20Contract address cannot be address(0)', async () => {
Expand Down
19 changes: 6 additions & 13 deletions source/pool/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable no-console */
const fs = require('fs')
const prettier = require('prettier')
const Confirm = require('prompt-confirm')
const { ethers, run } = require('hardhat')
const { chainLabels, ChainIds } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const poolDeploys = require('../deploys.js')
const poolBlocks = require('../deploys-blocks.js')
const poolCommits = require('../deploys-commits.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')
const { confirmDeployment } = require('../../../scripts/deployer-info')

async function main() {
await run('compile')
Expand All @@ -19,22 +18,16 @@ async function main() {
console.log('Value for --network flag is required')
return
}
await displayDeployerInfo(deployer)

const scale = 10
const max = 100

console.log(`scale: ${scale}`)
console.log(`max: ${max}`)
console.log(`\nDeploy POOL`)

const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = poolDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
console.log(`· max ${max}`)
console.log(`· scale ${scale}\n`)

if (await confirmDeployment(deployer, poolDeploys[ChainIds.MAINNET])) {
const poolFactory = await ethers.getContractFactory('Pool')
const poolContract = await poolFactory.deploy(scale, max)
console.log(
Expand Down
21 changes: 7 additions & 14 deletions source/registry/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable no-console */
const fs = require('fs')
const prettier = require('prettier')
const Confirm = require('prompt-confirm')
const { ethers, run } = require('hardhat')
const { ChainIds, chainLabels } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const registryDeploys = require('../deploys.js')
const registryBlocks = require('../deploys-blocks.js')
const registryCommits = require('../deploys-commits.js')
const config = require('./config.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')
const { confirmDeployment } = require('../../../scripts/deployer-info')

async function main() {
await run('compile')
Expand All @@ -20,7 +19,6 @@ async function main() {
console.log('Value for --network flag is required')
return
}
await displayDeployerInfo(deployer)

let stakingToken
let stakingCost
Expand All @@ -32,18 +30,13 @@ async function main() {
;({ stakingToken, stakingCost, supportCost } = config[ChainIds.MAINNET])
}

console.log(`stakingToken: ${stakingToken}`)
console.log(`stakingCost: ${stakingCost}`)
console.log(`supportCost: ${supportCost}\n`)
console.log(`\nDeploy REGISTRY`)

const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = registryDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
console.log(`· stakingCost ${stakingCost}`)
console.log(`· supportCost ${supportCost}`)
console.log(`· stakingToken ${stakingToken}\n`)

if (await confirmDeployment(deployer, registryDeploys)) {
const registryFactory = await ethers.getContractFactory('Registry')
const registryContract = await registryFactory.deploy(
stakingToken,
Expand Down
Loading
Loading