-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
committed
Dec 21, 2024
1 parent
ae805c7
commit 6c8a85c
Showing
11 changed files
with
12,828 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
RPC_URL= | ||
PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require('dotenv').config(); | ||
const { ethers } = require('ethers'); | ||
|
||
const RPC_URL = process.env.RPC_URL; | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(RPC_URL); | ||
|
||
// デプロイされたアドレス | ||
const factoryAddress = '0xbF603B840D958FAD0021872506b64a66d613F824'; | ||
const pairAddress = '0xe86eF760CD9EB0D6627e6A7776b31e85F5c996F5'; | ||
const erc20Address = '0xF130DCa1d24b58378a6f0d521eB4189f54897372'; | ||
|
||
const checkDeployment = async () => { | ||
try { | ||
// コントラクトの検証 | ||
const codeFactory = await provider.getCode(factoryAddress); | ||
const codePair = await provider.getCode(pairAddress); | ||
const codeERC20 = await provider.getCode(erc20Address); | ||
|
||
console.log(`Factory contract deployed: ${codeFactory !== '0x' ? 'Yes' : 'No'}`); | ||
console.log(`Pair contract deployed: ${codePair !== '0x' ? 'Yes' : 'No'}`); | ||
console.log(`ERC20 contract deployed: ${codeERC20 !== '0x' ? 'Yes' : 'No'}`); | ||
} catch (error) { | ||
console.error('Error checking deployment:', error); | ||
} | ||
}; | ||
|
||
checkDeployment(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require('dotenv').config(); | ||
const { ethers } = require('ethers'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// RPC URL | ||
const RPC_URL = process.env.RPC_URL; | ||
|
||
if (!RPC_URL) { | ||
console.error('Please ensure RPC_URL is set in the .env file'); | ||
process.exit(1); | ||
} | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(RPC_URL); | ||
|
||
// Factory コントラクトのアドレスとABI | ||
const factoryAddress = '0xbF603B840D958FAD0021872506b64a66d613F824'; // Replace with your Factory contract address | ||
const factoryABI = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, 'build/UniswapV2Factory.json'), 'utf8') | ||
).abi; | ||
|
||
// トークンアドレス | ||
const tokenA = '0x73d53c0e08baa93362c4825b836dbce45855abf4'; | ||
const tokenB = '0x6497ce5dbe25ad343bef8a5be82c19802ba7cd71'; | ||
|
||
const checkPair = async () => { | ||
try { | ||
const factoryContract = new ethers.Contract(factoryAddress, factoryABI, provider); | ||
|
||
console.log(`Checking pair for tokens ${tokenA} and ${tokenB}...`); | ||
const pairAddress = await factoryContract.getPair(tokenA, tokenB); | ||
|
||
if (pairAddress !== ethers.constants.AddressZero) { | ||
console.log(`Pair exists at address: ${pairAddress}`); | ||
} else { | ||
console.log('No pair exists for the given tokens.'); | ||
} | ||
} catch (error) { | ||
console.error('Error checking pair:', error); | ||
} | ||
}; | ||
|
||
checkPair(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require('dotenv').config(); | ||
const { ethers } = require('ethers'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Load environment variables | ||
const RPC_URL = process.env.RPC_URL; | ||
|
||
if (!RPC_URL) { | ||
console.error('Please ensure RPC_URL is set in the .env file'); | ||
process.exit(1); | ||
} | ||
|
||
// Initialize provider | ||
const provider = new ethers.providers.JsonRpcProvider(RPC_URL); | ||
|
||
// Load compiled Factory contract | ||
const loadContract = (fileName) => { | ||
const filePath = path.resolve(__dirname, 'build', fileName); | ||
const contractJson = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(contractJson); | ||
}; | ||
|
||
// Specify the transaction hash | ||
const txHash = '0xd74807dadf593dbd2d2c7bc9b191515b29f71c675743cd55fc7c2705413037d2'; // Replace with your transaction hash | ||
|
||
const checkTransaction = async () => { | ||
try { | ||
const receipt = await provider.getTransactionReceipt(txHash); | ||
console.log('Transaction Receipt:', receipt); | ||
|
||
// Load Factory contract ABI | ||
const factoryJson = loadContract('UniswapV2Factory.json'); | ||
const factoryAddress = '0x9184676B5E9a2Fc02e1aEb019cD4DAC60CA89e0C'; // Replace with your Factory contract address | ||
|
||
const factoryContract = new ethers.Contract(factoryAddress, factoryJson.abi, provider); | ||
|
||
// Parse logs to find the event | ||
const event = receipt.logs.find(log => | ||
log.address.toLowerCase() === factoryContract.address.toLowerCase() | ||
); | ||
|
||
if (event) { | ||
console.log('Event found:', event); | ||
} else { | ||
console.log('No relevant event found in the logs.'); | ||
} | ||
} catch (error) { | ||
console.error('Error checking transaction logs:', error); | ||
} | ||
}; | ||
|
||
checkTransaction(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const solc = require('solc'); | ||
|
||
// Set the path to the contracts directory | ||
const contractsPath = path.resolve(__dirname, 'contracts'); | ||
|
||
// Set the path to the build directory | ||
const buildPath = path.resolve(__dirname, 'build'); | ||
|
||
// Remove the existing build directory if it exists | ||
fs.removeSync(buildPath); | ||
|
||
// Create the build directory | ||
fs.ensureDirSync(buildPath); | ||
|
||
// Read all Solidity files in the contracts directory | ||
const contractFiles = fs.readdirSync(contractsPath).filter(file => file.endsWith('.sol')); | ||
|
||
// Read and compile each contract | ||
contractFiles.forEach(file => { | ||
const filePath = path.resolve(contractsPath, file); | ||
const source = fs.readFileSync(filePath, 'utf8'); | ||
|
||
const input = { | ||
language: 'Solidity', | ||
sources: { | ||
[file]: { | ||
content: source, | ||
}, | ||
}, | ||
settings: { | ||
evmVersion: 'byzantium', | ||
outputSelection: { | ||
'*': { | ||
'*': ['abi', 'evm.bytecode.object'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
console.log(`Compiling ${file}...`); | ||
|
||
// Import callback to resolve relative paths | ||
function findImports(importPath) { | ||
const resolvedPath = path.resolve(contractsPath, importPath); | ||
if (fs.existsSync(resolvedPath)) { | ||
return { contents: fs.readFileSync(resolvedPath, 'utf8') }; | ||
} else { | ||
return { error: `File not found: ${importPath}` }; | ||
} | ||
} | ||
|
||
const output = JSON.parse(solc.compile(JSON.stringify(input), { import: findImports })); | ||
|
||
// Check for compilation errors | ||
if (output.errors) { | ||
output.errors.forEach(err => { | ||
console.error(err.formattedMessage); | ||
}); | ||
process.exit(1); // Exit on compilation error | ||
} | ||
|
||
// Save compiled contract output to the build directory | ||
const contracts = output.contracts[file]; | ||
for (let contractName in contracts) { | ||
const contractOutput = contracts[contractName]; | ||
const outputFilePath = path.resolve(buildPath, `${contractName}.json`); | ||
fs.outputJsonSync(outputFilePath, contractOutput); | ||
console.log(`Compiled and saved: ${contractName}`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require('dotenv').config(); | ||
const { ethers } = require('ethers'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// RPC URLと秘密鍵 | ||
const RPC_URL = process.env.RPC_URL; | ||
const PRIVATE_KEY = process.env.PRIVATE_KEY; | ||
|
||
if (!RPC_URL || !PRIVATE_KEY) { | ||
console.error('Please ensure RPC_URL and PRIVATE_KEY are set in the .env file'); | ||
process.exit(1); | ||
} | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(RPC_URL); | ||
const wallet = new ethers.Wallet(PRIVATE_KEY, provider); | ||
|
||
// Factory コントラクトのアドレスとABI | ||
const factoryAddress = '0xbF603B840D958FAD0021872506b64a66d613F824'; // Replace with your Factory contract address | ||
const factoryABI = JSON.parse( | ||
fs.readFileSync(path.resolve(__dirname, 'build/UniswapV2Factory.json'), 'utf8') | ||
).abi; | ||
|
||
// トークンアドレス | ||
const tokenA = '0x73d53c0e08baa93362c4825b836dbce45855abf4'; | ||
const tokenB = '0x6497ce5dbe25ad343bef8a5be82c19802ba7cd71'; | ||
|
||
const createPair = async () => { | ||
try { | ||
const factoryContract = new ethers.Contract(factoryAddress, factoryABI, wallet); | ||
|
||
console.log(`Creating pair for tokens ${tokenA} and ${tokenB}...`); | ||
const tx = await factoryContract.createPair(tokenA, tokenB); | ||
console.log(`Transaction sent: ${tx.hash}`); | ||
|
||
const receipt = await tx.wait(); | ||
console.log(`Transaction confirmed: ${receipt.transactionHash}`); | ||
} catch (error) { | ||
console.error('Error creating pair:', error); | ||
} | ||
}; | ||
|
||
createPair(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require('dotenv').config(); | ||
const { ethers } = require('ethers'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Load environment variables | ||
const RPC_URL = process.env.RPC_URL; | ||
const PRIVATE_KEY = process.env.PRIVATE_KEY; | ||
|
||
if (!RPC_URL || !PRIVATE_KEY) { | ||
console.error('Please ensure RPC_URL and PRIVATE_KEY are set in the .env file'); | ||
process.exit(1); | ||
} | ||
|
||
// Initialize provider and wallet | ||
const provider = new ethers.providers.JsonRpcProvider(RPC_URL); | ||
const wallet = new ethers.Wallet(PRIVATE_KEY, provider); | ||
|
||
// Load compiled contracts | ||
const loadContract = (fileName) => { | ||
const filePath = path.resolve(__dirname, 'build', fileName); | ||
const contractJson = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(contractJson); | ||
}; | ||
|
||
// Deploy a contract | ||
const deployContract = async (contractName, args = []) => { | ||
const contractJson = loadContract(`${contractName}.json`); | ||
const contractFactory = new ethers.ContractFactory( | ||
contractJson.abi, | ||
contractJson.evm.bytecode.object, | ||
wallet | ||
); | ||
|
||
console.log(`Deploying ${contractName}...`); | ||
const contract = await contractFactory.deploy(...args); | ||
await contract.deployed(); | ||
console.log(`${contractName} deployed at: ${contract.address}`); | ||
return contract.address; | ||
}; | ||
|
||
// Main deployment function | ||
const main = async () => { | ||
try { | ||
// Deploy UniswapV2Factory | ||
const factoryAddress = await deployContract('UniswapV2Factory', [wallet.address]); | ||
|
||
// Deploy UniswapV2ERC20 (Optional, for testing or standalone token deployment) | ||
const erc20Address = await deployContract('UniswapV2ERC20'); | ||
|
||
// Deploy UniswapV2Pair (Will typically be created by the factory) | ||
const pairAddress = await deployContract('UniswapV2Pair'); | ||
|
||
console.log('Deployment complete!'); | ||
console.log('Factory Address:', factoryAddress); | ||
console.log('ERC20 Address (if deployed):', erc20Address); | ||
console.log('Pair Address (if deployed):', pairAddress); | ||
} catch (error) { | ||
console.error('Error during deployment:', error); | ||
} | ||
}; | ||
|
||
main(); |
Oops, something went wrong.