Skip to content

Commit

Permalink
Merge pull request #1339 from airswap/develop
Browse files Browse the repository at this point in the history
Publish latest / V5
  • Loading branch information
dmosites authored Oct 1, 2024
2 parents 8b67963 + 7501afc commit a11509a
Show file tree
Hide file tree
Showing 74 changed files with 1,941 additions and 349 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "airswap-protocols",
"version": "0.0.1",
"version": "5.0.0",
"private": true,
"license": "MIT",
"workspaces": {
Expand All @@ -13,12 +13,14 @@
"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",
"test": "lerna run test",
"test:ci": "lerna run test:ci",
"drain": "node ./scripts/drain-deployer.js",
"migrate-pool": "node ./scripts/migrate-pool.js",
"prepare": "husky install",
"prettier": "prettier --write \"./**/*.sol\" \"./**/*.ts\" \"./**/*.js\" \"./**/*.json\""
},
Expand Down Expand Up @@ -52,6 +54,7 @@
"nx": "^16.5.5",
"prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.1.2",
"prompt-confirm": "^2.0.4",
"solidity-coverage": "^0.8.5",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
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()
},
}
36 changes: 27 additions & 9 deletions source/pool/scripts/migrate.js → scripts/migrate-pool.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
require('dotenv').config({ path: './.env' })
const Confirm = require('prompt-confirm')
const { ethers } = require('hardhat')
const { chainNames, ChainIds } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const {
ChainIds,
chainNames,
apiUrls,
getReceiptUrl,
} = require('@airswap/utils')

const { Pool__factory } = require('../typechain/factories/contracts')
const { abi } = require('./migrate-abis/4-1-1.js')
const deploys = require('../deploys.js')
const { Pool__factory } = require('@airswap/pool/typechain/factories/contracts')
const { abi } = require('@airswap/pool/legacy-abis/4-1-1.js')
const deploys = require('@airswap/pool/deploys.js')

const CONFIRMATIONS = 2
const PREVIOUS_POOL = '0xEEcD248D977Fd4D392915b4AdeF8154BA3aE9c02'
const NEW_POOL = '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11'

async function main() {
const [account] = await ethers.getSigners()
const chainId = await account.getChainId()
if (chainId === ChainIds.HARDHAT) {
let chainId
if (process.argv[2] === '--network') {
chainId = ChainIds[process.argv[3].toUpperCase()]
}

if (!chainId) {
console.log('Value for --network flag is required')
return
}

const provider = new ethers.providers.JsonRpcProvider(apiUrls[chainId])
const account = new ethers.Wallet(process.env.PRIVATE_KEY, provider)

console.log(`Account: ${account.address}`)
console.log(`Network: ${chainNames[chainId].toUpperCase()}\n`)
console.log(`From-pool: ${PREVIOUS_POOL}`)
console.log(`To-pool: ${NEW_POOL}`)

const previousPool = new ethers.Contract(PREVIOUS_POOL, abi, account.provider)
const logs = await previousPool.queryFilter(previousPool.filters.UseClaim())
let logs
try {
logs = await previousPool.queryFilter(previousPool.filters.UseClaim())
} catch (error) {
console.log('\n✘ Error querying claim events on from-pool.\n\n', error.body)
return
}

if (!logs.length) {
console.log('\n✘ No claim events found on from-pool.\n')
Expand Down
1 change: 1 addition & 0 deletions scripts/owners-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
} = require('@airswap/utils')

const contracts = [
['delegate', 'Delegate'],
['pool', 'Pool'],
['staking', 'Staking'],
['swap', 'Swap'],
Expand Down
8 changes: 6 additions & 2 deletions scripts/owners-update.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const Confirm = require('prompt-confirm')
const { ethers } = require('hardhat')
const { chainNames, ChainIds, ownerAddresses } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const {
chainNames,
ChainIds,
ownerAddresses,
getReceiptUrl,
} = require('@airswap/utils')

const CONFIRMATIONS = 2
const TRANSFER_STARTED =
Expand Down
2 changes: 1 addition & 1 deletion scripts/receivers-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const {
chainNames,
apiUrls,
protocolFeeReceiverAddresses,
ADDRESS_ZERO,
} = require('@airswap/utils')
const poolDeploys = require('@airswap/pool/deploys.js')
const { ADDRESS_ZERO } = require('@airswap/utils')

const contracts = [
['swap', 'Swap'],
Expand Down
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
19 changes: 19 additions & 0 deletions source/batch-call/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
1: '863586ae7594b5088619f243dbee83c8d8e0075f',
31: '863586ae7594b5088619f243dbee83c8d8e0075f',
41: '863586ae7594b5088619f243dbee83c8d8e0075f',
56: '863586ae7594b5088619f243dbee83c8d8e0075f',
97: '863586ae7594b5088619f243dbee83c8d8e0075f',
137: '863586ae7594b5088619f243dbee83c8d8e0075f',
8453: '863586ae7594b5088619f243dbee83c8d8e0075f',
17000: '863586ae7594b5088619f243dbee83c8d8e0075f',
42161: '863586ae7594b5088619f243dbee83c8d8e0075f',
43113: '863586ae7594b5088619f243dbee83c8d8e0075f',
43114: '863586ae7594b5088619f243dbee83c8d8e0075f',
59140: '863586ae7594b5088619f243dbee83c8d8e0075f',
59144: '863586ae7594b5088619f243dbee83c8d8e0075f',
80001: '863586ae7594b5088619f243dbee83c8d8e0075f',
84532: '863586ae7594b5088619f243dbee83c8d8e0075f',
421614: '863586ae7594b5088619f243dbee83c8d8e0075f',
11155111: '863586ae7594b5088619f243dbee83c8d8e0075f',
}
1 change: 1 addition & 0 deletions source/batch-call/deploys-commits.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/batch-call/deploys-commits.js'
17 changes: 7 additions & 10 deletions source/batch-call/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@airswap/batch-call",
"version": "4.2.3",
"description": "Batch balance, allowance, order validity checks",
"version": "5.0.0",
"description": "AirSwap: Balance, Allowance, Validity Checks",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -10,9 +10,7 @@
"files": [
"./build",
"./typechain",
"./deploys.js",
"./deploys-blocks.js",
"./deploys.js.d.ts"
"./deploys*"
],
"scripts": {
"clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain",
Expand All @@ -26,11 +24,10 @@
"owners": "hardhat run ./scripts/owner.js"
},
"devDependencies": {
"@airswap/utils": "4.3.4",
"@airswap/swap": "4.2.2",
"@airswap/swap-erc20": "4.3.1",
"@openzeppelin/contracts": "^4.8.3",
"prompt-confirm": "^2.0.4"
"@airswap/utils": "5.0.0",
"@airswap/swap": "5.0.0",
"@airswap/swap-erc20": "5.0.0",
"@openzeppelin/contracts": "^4.8.3"
},
"publishConfig": {
"access": "public"
Expand Down
36 changes: 29 additions & 7 deletions source/batch-call/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* 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 { ChainIds, chainLabels, getReceiptUrl } = require('@airswap/utils')
const batchCallDeploys = require('../deploys.js')
const batchCallBlocks = require('../deploys-blocks.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')
const batchCallCommits = require('../deploys-commits.js')
const { confirmDeployment } = require('../../../scripts/deployer-info')

async function main() {
await run('compile')
Expand All @@ -18,10 +17,9 @@ async function main() {
console.log('Value for --network flag is required')
return
}
await displayDeployerInfo(deployer)
console.log(`\nDeploy BATCHCALL\n`)

const prompt = new Confirm('Proceed to deploy?')
if (await prompt.run()) {
if (await confirmDeployment(deployer, batchCallDeploys)) {
const batchFactory = await ethers.getContractFactory('BatchCall')
const batchCallContract = await batchFactory.deploy()
console.log(
Expand All @@ -48,6 +46,30 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)

batchCallBlocks[chainId] = (
await batchCallContract.deployTransaction.wait()
).blockNumber
fs.writeFileSync(
'./deploys-blocks.js',
prettier.format(
`module.exports = ${JSON.stringify(batchCallBlocks, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)

batchCallCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(batchCallCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)

console.log(
`Deployed: ${batchCallDeploys[chainId]} @ ${batchCallBlocks[chainId]}`
)
Expand Down
2 changes: 1 addition & 1 deletion source/batch-call/test/BatchCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const {
createOrderSignature,
createOrderERC20,
createOrderERC20Signature,
TokenKinds,
} = require('@airswap/utils')
const { TokenKinds } = require('@airswap/utils')

const CHAIN_ID = 31337
const PROTOCOL_FEE = '30'
Expand Down
Loading

0 comments on commit a11509a

Please sign in to comment.