2024-11-23 06:27:20 +00:00
|
|
|
import path from 'path';
|
|
|
|
import { readFile } from 'fs/promises';
|
|
|
|
|
|
|
|
import { ethers } from 'hardhat';
|
2024-12-01 23:01:39 +00:00
|
|
|
import { parseEther } from 'ethers';
|
2024-11-23 06:27:20 +00:00
|
|
|
|
|
|
|
import * as constants from './constants';
|
|
|
|
|
|
|
|
const { permit2Address } = constants;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deploy Deterministic Deployment Proxy and Permit2
|
2024-12-01 23:01:39 +00:00
|
|
|
*
|
2024-11-23 06:27:20 +00:00
|
|
|
* https://github.com/Arachnid/deterministic-deployment-proxy
|
|
|
|
* https://github.com/Uniswap/permit2
|
|
|
|
*/
|
|
|
|
export async function deployPermit2() {
|
2024-12-01 23:01:39 +00:00
|
|
|
const [owner] = await ethers.getSigners();
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
const { provider } = owner;
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
const { deterministicProxy, deterministicSigner, deterministicSignerCost } = constants;
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
const deterministicSignedTx = await readFile(path.join(__dirname, './deterministicTx.txt'), { encoding: 'utf-8' });
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
// Send deployment cost for deterministicProxyDeploy contract
|
|
|
|
(await owner.sendTransaction({ to: deterministicSigner, value: parseEther(deterministicSignerCost) })).wait();
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
(await provider.broadcastTransaction(deterministicSignedTx)).wait();
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
console.log(`Deterministic Deployment Proxy code: ${await provider.getCode(deterministicProxy)}`);
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
// Send Permit2 tx
|
|
|
|
const data = await readFile(path.join(__dirname, './permit2tx.txt'), { encoding: 'utf-8' });
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
(await owner.sendTransaction({ to: deterministicProxy, data })).wait();
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
const permit2code = await provider.getCode(permit2Address);
|
2024-11-23 06:27:20 +00:00
|
|
|
|
2024-12-01 23:01:39 +00:00
|
|
|
console.log(`Permit2 code: ${permit2code ? permit2code.slice(0, 20) : ''}`);
|
|
|
|
}
|