diff --git a/contracts/crucible/CrucibleFactory.sol b/contracts/crucible/CrucibleFactory.sol index 7c02635..c92c891 100644 --- a/contracts/crucible/CrucibleFactory.sol +++ b/contracts/crucible/CrucibleFactory.sol @@ -95,9 +95,9 @@ contract CrucibleFactory is Ownable, IFactory, IInstanceRegistry, ERC721 { string memory base = baseURI(); - uint256 id; + uint256 chainId; assembly { - id := chainid() + chainId := chainid() } // concatenate the tokenID and chain id to the baseURI diff --git a/tasks/transmuter.ts b/tasks/transmuter.ts index 476f6c4..e317b7a 100644 --- a/tasks/transmuter.ts +++ b/tasks/transmuter.ts @@ -5,7 +5,8 @@ import { formatEther, parseUnits, randomBytes } from 'ethers/lib/utils' import { task } from 'hardhat/config' import { deployContract, signPermission, signPermitEIP2612 } from './utils' -task('deploy-transmuter-v1', 'Deploy TransmuterV1 contract') +task('deploy-transmuter', 'Deploy a transmuter contract') + .addParam('transmuterName', 'the transmuter contract name') .addFlag('verify', 'verify contracts on etherscan') .setAction(async (args, { ethers, run, network }) => { // log config @@ -29,8 +30,8 @@ task('deploy-transmuter-v1', 'Deploy TransmuterV1 contract') // deploy contract const transmuter = await deployContract( - 'TransmuterV1', - await ethers.getContractFactory('TransmuterV1'), + args.transmuterName, + await ethers.getContractFactory(args.transmuterName), signer, ) @@ -91,7 +92,6 @@ task('mint-and-lock', 'Mint Crucible and lock in Aludel') args.transmuter, signer, ) - // declare config const amount = parseUnits(args.amount, await stakingToken.decimals()) @@ -148,3 +148,103 @@ task('mint-and-lock', 'Mint Crucible and lock in Aludel') ) console.log(' in', tx.hash) }) + + + task('v2-mint-and-lock', 'Mint Crucible and lock in Aludel') + .addParam('aludel', 'Aludel reward contract') + .addParam('crucibleFactory', 'Crucible factory contract') + .addParam('transmuter', 'TransmuterV2 contract') + .addParam('amount', 'Amount of staking tokens with decimals') + .setAction(async (args, { ethers, run, network }) => { + // log config + + console.log('Network') + console.log(' ', network.name) + console.log('Task Args') + console.log(args) + + // compile + + await run('compile') + + // get signer + + const signer = (await ethers.getSigners())[0] + console.log('Signer') + console.log(' at', signer.address) + console.log(' ETH', formatEther(await signer.getBalance())) + const signerWallet = Wallet.fromMnemonic(process.env.DEV_MNEMONIC || '') + expect(signer.address).to.be.eq(signerWallet.address) + + // fetch contracts + + const aludel = await ethers.getContractAt('Aludel', args.aludel, signer) + const stakingToken = await ethers.getContractAt( + IUniswapV2ERC20.abi, + (await aludel.getAludelData()).stakingToken, + signer, + ) + const crucibleFactory = await ethers.getContractAt( + 'CrucibleFactory', + args.crucibleFactory, + signer, + ) + const transmuter = await ethers.getContractAt( + 'TransmuterV2', + args.transmuter, + signer, + ) + // declare config + + const amount = parseUnits(args.amount, await stakingToken.decimals()) + const salt = randomBytes(32) + const deadline = + (await ethers.provider.getBlock('latest')).timestamp + 60 * 60 * 24 + + // validate balances + expect(await stakingToken.balanceOf(signer.address)).to.be.gte(amount) + + // craft permission + + const crucible = await ethers.getContractAt( + 'Crucible', + await transmuter.predictDeterministicAddress( + await crucibleFactory.getTemplate(), + salt, + crucibleFactory.address, + ), + signer, + ) +1 + console.log('Sign Permit') + + const permit = await signPermitEIP2612( + signerWallet, + stakingToken, + transmuter.address, + amount, + deadline, + ) + + console.log('Sign Lock') + + const permission = await signPermission( + 'Lock', + crucible, + signerWallet, + aludel.address, + stakingToken.address, + amount, + 0, + ) + + console.log('Mint, Deposit, Stake') + const tx = await transmuter.mintCruciblePermitAndStake( + aludel.address, + crucibleFactory.address, + salt, + permit, + permission, + ) + console.log(' in', tx.hash) + })