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

Scripts enhancements #1321

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
83 changes: 83 additions & 0 deletions populate_deploy_commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')

const subfolders = [
'batch-call',
'delegate',
'pool',
'registry',
'staking',
'swap',
'swap-erc20',
'wrapper',
]

function getLatestCommitForContract(contractPath) {
const branches = ['main', 'develop']
for (const branch of branches) {
try {
const commit = execSync(
`git log -1 --format=%H ${branch} -- ${contractPath}/contracts`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check ${contractPath}/contracts/deploys.js specifically.

)
.toString()
.trim()
let tag
try {
tag = execSync(`git describe --tags --contains ${commit}`)
.toString()
.trim()
.split('-')[0] // Get the most recent tag
} catch {
tag = 'No tag found'
}
return { branch, tag, commit }
} catch (error) {
// No changes in this branch, continue to the next one
}
}
return {
branch: 'No branch found',
tag: 'No tag found',
commit: 'No commit found',
}
}

const repoUrl = 'https://github.com/airswap/airswap-protocols'

subfolders.forEach((folder) => {
const contractPath = path.join('source', folder)
const deploysBlocksPath = path.join(
__dirname,
contractPath,
'deploys-blocks.js'
)
const deploysCommitsPath = path.join(
__dirname,
contractPath,
'deploys-commits.js'
)

const deploysBlocks = require(deploysBlocksPath)
const { branch, tag, commit } = getLatestCommitForContract(contractPath)

console.log(`Contract: ${folder}`)
console.log(`Branch: ${branch}`)
console.log(`Latest tag: ${tag}`)
console.log(`Commit: ${commit}`)
console.log(`Commit link: ${repoUrl}/commit/${commit}`)
console.log('---')

let content = 'module.exports = {\n'

Object.keys(deploysBlocks).forEach((chainId) => {
content += ` ${chainId}: '${commit}',\n`
})

content += '}\n'

fs.writeFileSync(deploysCommitsPath, content)
console.log(`Updated ${deploysCommitsPath}`)
})

console.log('All deploys-commits.js files have been updated successfully.')
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'
35 changes: 32 additions & 3 deletions source/batch-call/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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')

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

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = batchCallDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Mainnet address not matching target address. Proceed to deployment anyways?'
)
if (await prompt.run()) {
const batchFactory = await ethers.getContractFactory('BatchCall')
const batchCallContract = await batchFactory.deploy()
Expand Down Expand Up @@ -48,6 +53,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
3 changes: 3 additions & 0 deletions source/delegate/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
11155111: 'da05cb9528630f4f2e15ce3f9093b0f944bec1b7',
}
1 change: 1 addition & 0 deletions source/delegate/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'
20 changes: 19 additions & 1 deletion source/delegate/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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')

async function main() {
Expand All @@ -23,7 +24,13 @@ async function main() {

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

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = delegateDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Mainnet address not matching target address. Proceed to deployment anyways?'
)
if (await prompt.run()) {
const delegateFactory = await ethers.getContractFactory('Delegate')
const delegateContract = await delegateFactory.deploy(
Expand Down Expand Up @@ -53,6 +60,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
delegateCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(delegateCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(
`Deployed: ${delegateDeploys[chainId]} @ ${delegateBlocks[chainId]}`
)
Expand Down
22 changes: 22 additions & 0 deletions source/pool/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
1: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
5: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
30: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
31: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
40: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
41: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
56: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
97: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
137: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
8453: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
17000: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
42161: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
43113: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
43114: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
59140: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
59144: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
80001: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
84531: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
421613: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
11155111: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
}
1 change: 1 addition & 0 deletions source/pool/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'
20 changes: 19 additions & 1 deletion source/pool/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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')

async function main() {
Expand All @@ -26,7 +27,13 @@ async function main() {
console.log(`scale: ${scale}`)
console.log(`max: ${max}`)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = poolDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Mainnet address not matching target address. Proceed to deployment anyways?'
)
if (await prompt.run()) {
const poolFactory = await ethers.getContractFactory('Pool')
const poolContract = await poolFactory.deploy(scale, max)
Expand Down Expand Up @@ -54,6 +61,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
poolCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(poolCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(`Deployed: ${poolDeploys[chainId]} @ ${poolBlocks[chainId]}`)

console.log(
Expand Down
19 changes: 19 additions & 0 deletions source/registry/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/registry/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'
20 changes: 19 additions & 1 deletion source/registry/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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')

Expand Down Expand Up @@ -35,7 +36,13 @@ async function main() {
console.log(`stakingCost: ${stakingCost}`)
console.log(`supportCost: ${supportCost}\n`)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = registryDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Mainnet address not matching target address. Proceed to deployment anyways?'
)
if (await prompt.run()) {
const registryFactory = await ethers.getContractFactory('Registry')
const registryContract = await registryFactory.deploy(
Expand Down Expand Up @@ -67,6 +74,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
registryCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(registryCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(
`Deployed: ${registryDeploys[chainId]} @ ${registryBlocks[chainId]}`
)
Expand Down
5 changes: 5 additions & 0 deletions source/staking/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
1: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab',
17000: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab',
11155111: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab',
}
1 change: 1 addition & 0 deletions source/staking/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'
20 changes: 19 additions & 1 deletion source/staking/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { chainLabels, ChainIds } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const stakingDeploys = require('../deploys.js')
const stakingBlocks = require('../deploys-blocks.js')
const stakingCommits = require('../deploys-commits.js')
const config = require('./config.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')

Expand Down Expand Up @@ -35,7 +36,13 @@ async function main() {
console.log(`stakingDuration: ${stakingDuration}`)
console.log(`minDurationChangeDelay: ${minDurationChangeDelay}\n`)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = stakingDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Mainnet address not matching target address. Proceed to deployment anyways?'
)
if (await prompt.run()) {
const stakingFactory = await ethers.getContractFactory('Staking')
const stakingContract = await stakingFactory.deploy(
Expand Down Expand Up @@ -69,6 +76,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
stakingCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(stakingCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(
`Deployed: ${stakingDeploys[chainId]} @ ${stakingBlocks[chainId]}`
)
Expand Down
Loading
Loading