Skip to content

Commit

Permalink
feat: add simple substitute deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
JhChoy committed Dec 28, 2023
1 parent 4dc0b53 commit 47a741c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions task/substitute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { task } from 'hardhat/config'
import { AAVE_V3_POOL, OWNER, SINGLETON_FACTORY, TOKEN_KEYS, TOKENS, TREASURY, verify } from '../utils'
import { hardhat } from 'viem/chains'
import AaveTokenSubstitute from '../artifacts/contracts/AaveTokenSubstitute.sol/AaveTokenSubstitute.json'
import SimpleTokenSubstitute from '../artifacts/contracts/SimpleTokenSubstitute.sol/SimpleTokenSubstitute.json'
import { encodeDeployData, Hex, getCreate2Address } from 'viem'

task('substitute:aave:deploy')
Expand Down Expand Up @@ -39,6 +40,34 @@ task('substitute:aave:deploy')
await verify(computedAddress, constructorArgs)
})

task('substitute:simple:deploy')
.addParam('asset', 'name of the asset')
.setAction(async ({ asset }, hre) => {
const singletonFactory = await hre.viem.getContractAt('ISingletonFactory', SINGLETON_FACTORY)
const chainId = hre.network.config.chainId ?? hardhat.id
const emptySimpleSubstitute = await hre.viem.getContractAt('SimpleTokenSubstitute', '0x')
const treasury = TREASURY[chainId]
if (!treasury) {
throw new Error('missing treasury')
}
const constructorArgs = [TOKENS[chainId][TOKEN_KEYS.WETH], TOKENS[chainId][asset], treasury, OWNER[chainId]]
const deployData = encodeDeployData({
abi: emptySimpleSubstitute.abi,
args: [TOKENS[chainId][TOKEN_KEYS.WETH], TOKENS[chainId][asset], treasury, OWNER[chainId]],
bytecode: SimpleTokenSubstitute.bytecode as Hex,
})
const computedAddress = getCreate2Address({ from: singletonFactory.address, bytecode: deployData, salt: '0x' })
const client = await hre.viem.getPublicClient()
const remoteBytecode = await client.getBytecode({ address: computedAddress })
if (remoteBytecode && remoteBytecode !== '0x') {
console.log(`${asset} Substitute Contract already deployed:`, computedAddress)
} else {
const transactionHash = await singletonFactory.write.deploy([deployData, '0x'])
console.log(`Deployed ${asset} SimpleTokenSubstitute(${computedAddress}) at tx`, transactionHash)
}
await verify(computedAddress, constructorArgs)
})

task('substitute:set-treasury')
.addParam('address', 'address of the substitute')
.setAction(async ({ address }, hre) => {
Expand Down

0 comments on commit 47a741c

Please sign in to comment.