Commit b40aa685 authored by luxq's avatar luxq

add new scripts

parent def735e7
This diff is collapsed.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
contract WMDD {
string public name = "Wrapped MMDD";
string public symbol = "MMDD";
uint8 public decimals = 18;
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
event Deposit(address indexed dst, uint wad);
event Withdrawal(address indexed src, uint wad);
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
// 接收以太币
receive() external payable {
deposit();
}
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint wad) public {
require(balanceOf[msg.sender] >= wad, "Insufficient balance");
balanceOf[msg.sender] -= wad;
// 使用 call 发送以太币
(bool success, ) = msg.sender.call{value: wad}("");
require(success, "Transfer failed");
emit Withdrawal(msg.sender, wad);
}
function totalSupply() public view returns (uint) {
return address(this).balance;
}
function approve(address guy, uint wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
function transfer(address dst, uint wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint wad) public returns (bool) {
require(balanceOf[src] >= wad, "Insufficient balance");
if (src != msg.sender && allowance[src][msg.sender] != type(uint).max) {
require(allowance[src][msg.sender] >= wad, "Allowance exceeded");
allowance[src][msg.sender] -= wad;
}
balanceOf[src] -= wad;
balanceOf[dst] += wad;
emit Transfer(src, dst, wad);
return true;
}
}
\ No newline at end of file
This diff is collapsed.
pragma solidity >=0.5.0;
pragma experimental ABIEncoderV2;
/// @title Multicall2 - Aggregate results from multiple read-only function calls
/// @author Michael Elliot <mike@makerdao.com>
/// @author Joshua Levine <joshua@makerdao.com>
/// @author Nick Johnson <arachnid@notdot.net>
contract Multicall2 {
struct Call {
address target;
bytes callData;
}
struct Result {
bool success;
bytes returnData;
}
function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) {
blockNumber = block.number;
returnData = new bytes[](calls.length);
for(uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
require(success, "Multicall aggregate: call failed");
returnData[i] = ret;
}
}
function blockAndAggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {
(blockNumber, blockHash, returnData) = tryBlockAndAggregate(true, calls);
}
function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
blockHash = blockhash(blockNumber);
}
function getBlockNumber() public view returns (uint256 blockNumber) {
blockNumber = block.number;
}
function getCurrentBlockCoinbase() public view returns (address coinbase) {
coinbase = block.coinbase;
}
function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
difficulty = block.difficulty;
}
function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
gaslimit = block.gaslimit;
}
function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
timestamp = block.timestamp;
}
function getEthBalance(address addr) public view returns (uint256 balance) {
balance = addr.balance;
}
function getLastBlockHash() public view returns (bytes32 blockHash) {
blockHash = blockhash(block.number - 1);
}
function tryAggregate(bool requireSuccess, Call[] memory calls) public returns (Result[] memory returnData) {
returnData = new Result[](calls.length);
for(uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
if (requireSuccess) {
require(success, "Multicall2 aggregate: call failed");
}
returnData[i] = Result(success, ret);
}
}
function tryBlockAndAggregate(bool requireSuccess, Call[] memory calls) public returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {
blockNumber = block.number;
blockHash = blockhash(block.number);
returnData = tryAggregate(requireSuccess, calls);
}
}
\ No newline at end of file
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.10;
contract RevertContract {
event log(string message);
modifier minimumEther(uint256 _amount) {
require(_amount >= 1*10**18, "minimum 1 ether");
_;
......@@ -12,12 +13,14 @@ contract RevertContract {
}
function sendViaSend(address payable _to, uint256 _amount) public payable minimumEther(_amount) returns (bool) {
emit log("sendViaSend");
bool sent = _to.send(_amount);
require(sent, "Send failed");
return sent;
}
function sendViaCall(address payable _to, uint256 _amount) public payable minimumEther(_amount) returns (bool) {
emit log("sendViaCall");
(bool success, ) = _to.call{value: _amount}("");
require(success, "Call failed");
return success;
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract TestToken is ERC20 {
constructor(string memory name, string memory symbol) ERC20(name, symbol) {
_mint(msg.sender, 1000000000 * 10 ** decimals());
}
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -33,6 +33,7 @@ const accounts = { mnemonic }
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: {
evmVersion: "istanbul",
compilers: [
{
version: "0.8.20",
......@@ -43,11 +44,26 @@ module.exports = {
},
},
},
{
version: "0.8.10",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
],
},
sourcify: {
enabled: false
},
etherscan: {
apiKey: {
'achain': 'empty',
'hole': 'empty',
'movadev': 'empty',
'mova': 'empty',
'bsc':'AVZIFYCHUFHPG9FDKNMHEWJ1VAW1H5U66T'
},
customChains: [
......@@ -58,6 +74,30 @@ module.exports = {
apiURL: "https://scan.cmp20.bitheart.org/api",
browserURL: "https://scan.cmp20.bitheart.org"
}
},
{
network: "hole",
chainId: 6174,
urls: {
apiURL: "https://holescan.bitheart.org/api",
browserURL: "https://holescan.bitheart.org"
}
},
{
network: "movadev",
chainId: 8891,
urls: {
apiURL: "https://scan.mova.bitheart.org/api",
browserURL: "https://scan.mova.bitheart.org"
}
},
{
network: "mova",
chainId: 10323,
urls: {
apiURL: "https://scan.mars.movachain.com/api",
browserURL: "https://scan.mars.movachain.com"
}
}
]
},
......@@ -65,13 +105,19 @@ module.exports = {
hardhat: {
accounts: [{ privateKey, balance: "10000000000000000000000" }], // Example balance
gas: 10000000,
gasPrice: 10000000000,
gasPrice: 10000000000
},
hole: {
url: "https://rpc.hole.bitheart.org",
accounts: [privateKey]
},
achain: {
// url: "https://achain.bitheart.org",
// url: "http://192.168.1.39:28545",
url: "http://15.206.56.79:28545",
accounts: [privateKey],
movadev: {
url: "https://rpc.mova.bitheart.org",
accounts: [privateKey]
},
mova: {
url: "https://mars.rpc.movachain.com",
accounts: [privateKey]
}
},
};
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
let initialValidators = process.env.BRIDGE_VALIDATORS
async function addValidators(contract, validators) {
let validatorList = validators.split(',')
for (let i = 0; i < validatorList.length; i++) {
var tx = await contract.addValidator(validatorList[i])
await tx.wait();
console.log("Added validator:", validatorList[i]);
}
}
// Define the script
async function deployAtSourceChain() {
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"Bridge"
);
const contract = await factory.deploy();
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed for source at:", depAddr);
await initForSourceChain(contract);
}
async function initForSourceChain(bridge) {
// add validator
await addValidators(bridge, initialValidators);
// set
}
async function deployAtMovaChain() {
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"Bridge"
);
const contract = await factory.deploy();
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed for mova at:", depAddr);
await initForMovaChain(contract);
}
async function initForMovaChain(bridge) {
await addValidators(bridge, initialValidators);
}
// Define the script
async function main() {
await deployAtSourceChain();
await deployAtMovaChain();
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
var addrlist = [
"0xaccf7aacd00bb765120f10685e58d916d3ec3057",
"0x4631638617F6CF476BeC1AA9A892D308AaE2062A",
"0x43Fa8B58AaBeF30bE4221C7c435Fa38d34f0ccb1",
"0x193b7fBA150679AC96c675964180dA078B73fE3c",
"0x5b89a423416B00769ecB9F148411CD686d165A43",
"0xDF2cf3eE3E4E36490F5f942372fF4c975040bBd0",
"0xdD9720aBe15CD07cc2BF9213C1f08CFf1AE0b37D",
"0xD7FB4128F5451f88A5e525ef5303d714633435A7",
"0xf5c5C8cC784C8183316f4d1f0E50c46DF45920c8",
"0x9923f67774A4250bf2B2eA34Da9cBbc6aBd98caD",
"0xe40701772cCBA7a515CE557c3eaeB4B29B92C71e"
]
async function test() {
for (let i = 0; i < addrlist.length; i++) {
const balance = await hre.ethers.provider.getBalance(addrlist[i]);
console.log("Address:", addrlist[i], " Balance:", hre.ethers.formatEther(balance), " ETH");
}
}
// Define the script
async function main() {
await test()
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
const { ContractFactory, ethers} = require("ethers");
const hre = require("hardhat");
// Define the script
async function main() {
const factoryAddress = '0xedd8Da22D948f3F594FdC37840d961461814EeA3'
const bytecode = await hre.ethers.provider.getCode(factoryAddress)
const codeHash = hre.ethers.keccak256(bytecode);
console.log('Factory Code Hash:', codeHash);
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
......@@ -9,18 +9,28 @@ async function forceRevert() {
await contract.waitForDeployment();
const contractAddress = await contract.getAddress();
console.log("Contract deployed at:", contractAddress);
return
const signer = new hre.ethers.Wallet(process.env.DEPLOY_PRIVATE_KEY, hre.ethers.provider);
const transferAmount = hre.ethers.parseEther("0.0005"); // 小于 1 ETH
var nonce = await hre.ethers.provider.getTransactionCount(signer.address)
const chainid = await hre.ethers.provider.getNetwork().then(network => network.chainId);
// Encode the function call
const abi = ["function sendViaTransfer(address payable _to, uint256 _amount)"];
const iface = new hre.ethers.Interface(abi);
const data = iface.encodeFunctionData("sendViaTransfer", ['0xAD4143Df8Fe9E31B1C4318e8dE555872085f481d', transferAmount]);
// 签名交易
const signedTx = await signer.signTransaction({
type: 0,
chainId: 100,
chainId: chainid,
nonce: nonce,
to: contractAddress,
data: '0xd27f8e66000000000000000000000000a686b69111eadc74d45eeb3be4ae487fd61497e60000000000000000000000000000000000000000000000000001c6bf52634000',
data: data,
value: transferAmount,
gasLimit: 1000000, // 设置 gas 限制
gasPrice: hre.ethers.parseUnits("1", "gwei"), // 设置 gas 价格
......
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
// Define the script
async function main() {
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"HandoutContract"
);
const contract = await factory.deploy();
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed at:", depAddr);
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
......@@ -10,13 +10,14 @@ async function test() {
nonce = nonce + 1
const signedTx = await signer.signTransaction({
type: 0,
chainId: 100,
chainId: 10323,
nonce: nonce,
to: "0x88395111AB1586a4030dAC62a183542762929bbC",
to: "0x88395111AB1586a4030dAC62a183542762929bbC", // first
// to: "0x6ddb3A03366e218956483A840D8BfB490ADE1beB", // second
data: '',
value: transferAmount,
gasLimit: 1000000,
gasPrice: hre.ethers.parseUnits("1", "gwei"),
gasPrice: hre.ethers.parseUnits("4", "gwei"),
});
// 发送交易
......
......@@ -5,14 +5,15 @@ const hre = require("hardhat");
async function test() {
const signer = new hre.ethers.Wallet(process.env.DEPLOY_PRIVATE_KEY, hre.ethers.provider);
const transferAmount = hre.ethers.parseEther("0.0001");
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId);
var nonce = await hre.ethers.provider.getTransactionCount(signer.address)
nonce = nonce - 1
const signedTx = await signer.signTransaction({
type: 0,
chainId: 100,
chainId: chainId,
nonce: nonce,
to: "0x88395111AB1586a4030dAC62a183542762929bbC",
to: "0x820b54e2446941213F09d576994B84c32D1ebA2B",
data: '',
value: transferAmount,
gasLimit: 1000000,
......
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
// Define the script
async function main() {
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"Multicall2"
);
const contract = await factory.deploy();
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed at:", depAddr);
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
......@@ -7,7 +7,6 @@ async function main() {
const factory = await hre.ethers.getContractFactory(
"RevertContract"
);
// const contract = await factory.deploy({ value: hre.ethers.parseEther("0.0008") });
const contract = await factory.deploy();
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
......
......@@ -5,11 +5,12 @@ const hre = require("hardhat");
async function test() {
const signer = new hre.ethers.Wallet(process.env.DEPLOY_PRIVATE_KEY, hre.ethers.provider);
const transferAmount = hre.ethers.parseEther("0.0001");
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId);
var nonce = await hre.ethers.provider.getTransactionCount(signer.address)
const signedTx = await signer.signTransaction({
type: 0,
chainId: 100,
chainId: chainId,
nonce: nonce,
to: "0x88395111AB1586a4030dAC62a183542762929bbC",
data: '',
......
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
var addrlist = [
"0xaccf7aacd00bb765120f10685e58d916d3ec3057",
"0x4631638617F6CF476BeC1AA9A892D308AaE2062A",
"0x43Fa8B58AaBeF30bE4221C7c435Fa38d34f0ccb1",
"0x193b7fBA150679AC96c675964180dA078B73fE3c",
"0x5b89a423416B00769ecB9F148411CD686d165A43",
"0xDF2cf3eE3E4E36490F5f942372fF4c975040bBd0",
"0xdD9720aBe15CD07cc2BF9213C1f08CFf1AE0b37D",
"0xD7FB4128F5451f88A5e525ef5303d714633435A7",
"0xf5c5C8cC784C8183316f4d1f0E50c46DF45920c8",
"0x9923f67774A4250bf2B2eA34Da9cBbc6aBd98caD",
"0xe40701772cCBA7a515CE557c3eaeB4B29B92C71e"
]
async function test() {
const transferAmount = hre.ethers.parseEther("100000");
const signer = new hre.ethers.Wallet(process.env.DEPLOY_PRIVATE_KEY, hre.ethers.provider);
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId);
var nonce = await hre.ethers.provider.getTransactionCount(signer.address)
for (let i = 0; i < addrlist.length; i++) {
const signedTx = await signer.signTransaction({
type: 0,
chainId: chainId,
nonce: nonce + i,
to: addrlist[i],
data: '',
value: transferAmount,
gasLimit: 210000,
gasPrice: hre.ethers.parseUnits("1", "gwei"),
});
// 发送交易
const txResponse = await hre.ethers.provider.broadcastTransaction(signedTx);
console.log("Transaction sent to:", addrlist[i], " tx hash:", txResponse.hash);
}
console.log("All transactions sent.");
}
// Define the script
async function main() {
await test()
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
......@@ -7,13 +7,13 @@ async function test() {
const transferAmount = hre.ethers.parseEther("0.0005");
var nonce = await hre.ethers.provider.getTransactionCount(signer.address)
nonce = nonce + 1;
nonce = 27;
const signedTx = await signer.signTransaction({
type: 0,
chainId: 100,
nonce: nonce,
// to: "0x88395111AB1586a4030dAC62a183542762929bbC", // first
to: "0x6ddb3A03366e218956483A840D8BfB490ADE1beB", // second
to: "0x88395111AB1586a4030dAC62a183542762929bbC", // first
// to: "0x6ddb3A03366e218956483A840D8BfB490ADE1beB", // second
data: '',
value: transferAmount,
gasLimit: 1000000,
......
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
async function getTokenInfo(contract) {
const name = await contract.name();
console.log("Token Name:", name);
const symbol = await contract.symbol();
const totalSupply = await contract.totalSupply();
console.log("Token Symbol:", symbol);
console.log("Total Supply:", totalSupply.toString());
}
// Define the script
async function main() {
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"TestToken"
);
{
const contract = await factory.deploy("TestTokenAlice", "TTA");
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("TTA deployed at:", depAddr);
await getTokenInfo(contract);
}
{
const contract = await factory.deploy("TestTokenBob", "TTB");
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("TTB deployed at:", depAddr);
await getTokenInfo(contract);
}
{
const contract = await factory.deploy("TestTokenCharlie", "TTC");
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("TTC deployed at:", depAddr);
await getTokenInfo(contract);
}
{
const contract = await factory.deploy("TestTokenDoody", "TTD");
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("TTD deployed at:", depAddr);
await getTokenInfo(contract);
}
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
const {ethers} = require("hardhat");
async function deploy() {
[owner] = await ethers.getSigners();
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"TestAbi"
);
const contract = await factory.deploy(owner.address);
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed for mova at:", depAddr);
const params = {
toChainID: 2,
receiver: "0x000000000000000000000000000000000000dead",
token: "0x000000000000000000000000000000000000beef",
amount: hre.ethers.parseEther("10"),
outId: 1,
fromChainID: 1,
sender: "0x000000000000000000000000000000000000cafe",
sendToken: "0x000000000000000000000000000000000000babe",
sendAmount: hre.ethers.parseEther("10"),
signature: "0x000000000000000000000000000000000000babe000000000000000000000000",
};
const tx = await contract.getSubmitData(params);
console.log("Computed hash:", tx);
}
async function initForMovaChain(bridge) {
await addValidators(bridge, initialValidators);
}
// Define the script
async function main() {
await deploy();
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
async function getTokenInfo(contract) {
const name = await contract.name();
console.log("Token Name:", name);
const symbol = await contract.symbol();
const totalSupply = await contract.totalSupply();
console.log("Token Symbol:", symbol);
console.log("Total Supply:", totalSupply.toString());
}
// Define the script
async function main() {
......@@ -13,6 +23,11 @@ async function main() {
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed at:", depAddr);
await getTokenInfo(contract);
// const minttx = await contract.mint('0x88395111AB1586a4030dAC62a183542762929bbC', 10000);
// console.log("mint tx:", minttx.hash);
}
// Run the script
......
const { ContractFactory } = require("ethers");
const hre = require("hardhat");
// Define the script
async function main() {
// Deploy the contract
const factory = await hre.ethers.getContractFactory(
"WMDD"
);
const contract = await factory.deploy();
await contract.waitForDeployment();
const depAddr = await contract.getAddress();
console.log("Contract deployed at:", depAddr);
}
// Run the script
main().catch((error) => {
console.error("Error:", error);
});
\ No newline at end of file
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("TestAbi Contract", function () {
let TestAbi, testAbi, owner;
beforeEach(async function () {
// Deploy the TestAbi contract
[owner] = await ethers.getSigners();
const TestAbiFactory = await ethers.getContractFactory("TestAbi");
testAbi = await TestAbiFactory.deploy(owner.address);
await testAbi.waitForDeployment();
});
it("should return the correct keccak256 hash for getSubmitData", async function () {
// Define the input parameters for getSubmitData
const params = {
toChainID: 2,
receiver: "0x000000000000000000000000000000000000dead",
token: "0x000000000000000000000000000000000000beef",
amount: ethers.parseEther("10"),
outId: 1,
fromChainID: 1,
sender: "0x000000000000000000000000000000000000cafe",
sendToken: "0x000000000000000000000000000000000000babe",
sendAmount: ethers.parseEther("10"),
signature: "0x000000000000000000000000000000000000babe000000000000000000000000",
};
// Compute the expected hash
var data = ethers.AbiCoder.defaultAbiCoder().encode(
[
"uint256",
"uint256",
"address",
"address",
"uint256",
"uint256",
"address",
"address",
],
[
params.outId,
params.fromChainID,
params.sender,
params.sendToken,
params.sendAmount,
params.toChainID,
params.receiver,
params.token,
]
);
console.log("Encoded data:", data);
const expectedHash = ethers.keccak256(data);
// Call the getSubmitData function
const result = await testAbi.getSubmitData(params);
console.log("Computed hash:", result);
console.log("Expected hash:", expectedHash);
// Assert that the result matches the expected hash
expect(result).to.equal(expectedHash);
});
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment