Skip to content

Commit

Permalink
add transmuter v2 task
Browse files Browse the repository at this point in the history
  • Loading branch information
itirabasso committed Mar 4, 2022
1 parent 969163c commit 6dd4824
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 6 deletions.
4 changes: 2 additions & 2 deletions contracts/crucible/CrucibleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
108 changes: 104 additions & 4 deletions tasks/transmuter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
})

0 comments on commit 6dd4824

Please sign in to comment.