mirror of
https://github.com/emo2007/block-accounting.git
synced 2025-01-18 15:36:27 +00:00
smart contract deployed
This commit is contained in:
parent
f2c85ca84f
commit
d3c421471e
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"solidity.compileUsingRemoteVersion": "v0.8.25+commit.b61c2a91"
|
||||||
|
}
|
@ -1,10 +1,13 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
pragma solidity ^0.8.20;
|
pragma solidity ^0.8.19;
|
||||||
|
// The wallet owners can
|
||||||
|
// submit a transaction
|
||||||
|
// approve and revoke approval of pending transactions
|
||||||
|
// anyone can execute a transaction after enough owners has approved it.
|
||||||
contract MultiSigWallet {
|
contract MultiSigWallet {
|
||||||
event Deposit (address indexed sender, uint amount, uint balance);
|
event Deposit(address indexed sender, uint amount, uint balance);
|
||||||
event SubmitTransaction (
|
event SubmitTransaction(
|
||||||
address indexed owener,
|
address indexed owener,
|
||||||
uint indexed txIndex,
|
uint indexed txIndex,
|
||||||
address indexed to,
|
address indexed to,
|
||||||
@ -34,7 +37,12 @@ contract MultiSigWallet {
|
|||||||
|
|
||||||
Transaction[] public transactions;
|
Transaction[] public transactions;
|
||||||
|
|
||||||
modifier txExists(uint _txIndex){
|
modifier onlyOwner() {
|
||||||
|
require(isOwner[msg.sender], "not owner");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier txExists(uint _txIndex) {
|
||||||
require(_txIndex < transactions.length, "tx does not exist");
|
require(_txIndex < transactions.length, "tx does not exist");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
@ -44,15 +52,18 @@ contract MultiSigWallet {
|
|||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifier notExecuted(uint _txIndex){
|
modifier notExecuted(uint _txIndex) {
|
||||||
require(!transactions[_txIndex].executed, "tx already confirmed");
|
require(!transactions[_txIndex].executed, "tx already confirmed");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(address[] memory _owners, uint _numConfirmationsRequired){
|
constructor(address[] memory _owners, uint _numConfirmationsRequired) {
|
||||||
require(_owners.length > 0, "owners required");
|
require(_owners.length > 0, "owners required");
|
||||||
require(_numConfirmationsRequired > 0 && _numConfirmationsRequired <= owners.length,
|
require(
|
||||||
"invalid number of required confirmations");
|
_numConfirmationsRequired > 0 &&
|
||||||
|
_numConfirmationsRequired <= _owners.length,
|
||||||
|
"invalid number of required confirmations"
|
||||||
|
);
|
||||||
for (uint i = 0; i < _owners.length; i++) {
|
for (uint i = 0; i < _owners.length; i++) {
|
||||||
address owner = _owners[i];
|
address owner = _owners[i];
|
||||||
require(owner != address(0), "invalid owner");
|
require(owner != address(0), "invalid owner");
|
||||||
@ -67,7 +78,11 @@ contract MultiSigWallet {
|
|||||||
emit Deposit(msg.sender, msg.value, address(this).balance);
|
emit Deposit(msg.sender, msg.value, address(this).balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitTransaction(address _to, uint _value, bytes memory _data) public onlyOwner {
|
function submitTransaction(
|
||||||
|
address _to,
|
||||||
|
uint _value,
|
||||||
|
bytes memory _data
|
||||||
|
) public onlyOwner {
|
||||||
uint txIndex = transactions.length;
|
uint txIndex = transactions.length;
|
||||||
transactions.push(
|
transactions.push(
|
||||||
Transaction({
|
Transaction({
|
||||||
@ -83,27 +98,74 @@ contract MultiSigWallet {
|
|||||||
|
|
||||||
function confirmTransaction(
|
function confirmTransaction(
|
||||||
uint _txIndex
|
uint _txIndex
|
||||||
) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) notConfirmed(_txIndex) {
|
)
|
||||||
|
public
|
||||||
|
onlyOwner
|
||||||
|
txExists(_txIndex)
|
||||||
|
notExecuted(_txIndex)
|
||||||
|
notConfirmed(_txIndex)
|
||||||
|
{
|
||||||
Transaction storage transaction = transactions[_txIndex];
|
Transaction storage transaction = transactions[_txIndex];
|
||||||
transaction.numConfirmations +=1;
|
transaction.numConfirmations += 1;
|
||||||
isConfirmed[_txIndex][msg.sender] = true;
|
isConfirmed[_txIndex][msg.sender] = true;
|
||||||
emit ConfirmTransaction(msg.sender, _txIndex);
|
emit ConfirmTransaction(msg.sender, _txIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeTransaction(uint _txIndex) public onlyOwner txExists(_txIndex) notExecuted(_txIndex){
|
function executeTransaction(
|
||||||
Transaction storage transaction = transactions[_txIndex];
|
uint _txIndex
|
||||||
require(
|
) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
|
||||||
transaction.numConfirmations >=numConfirmationsRequired, "cannot execute tx"
|
Transaction storage transaction = transactions[_txIndex];
|
||||||
);
|
require(
|
||||||
transaction.executed = true;
|
transaction.numConfirmations >= numConfirmationsRequired,
|
||||||
(bool, success, ) = transaction.to.call{value: transaction.value}(transaction.data);
|
"cannot execute tx"
|
||||||
require(success, "tx failed");
|
);
|
||||||
emit ExecuteTransaction(msg.sender, _txIndex);
|
transaction.executed = true;
|
||||||
}
|
(bool success, ) = transaction.to.call{value: transaction.value}(
|
||||||
|
transaction.data
|
||||||
function revokeConfirmation(uint _txIndex) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
|
);
|
||||||
|
require(success, "tx failed");
|
||||||
|
emit ExecuteTransaction(msg.sender, _txIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function revokeConfirmation(
|
||||||
|
uint _txIndex
|
||||||
|
) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
|
||||||
|
Transaction storage transaction = transactions[_txIndex];
|
||||||
|
require(isConfirmed[_txIndex][msg.sender], "tx not confirmed");
|
||||||
|
transaction.numConfirmations -= 1;
|
||||||
|
isConfirmed[_txIndex][msg.sender] = false;
|
||||||
|
|
||||||
}
|
emit RevokeConfirmation(msg.sender, _txIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOwners() public view returns (address[] memory) {
|
||||||
|
return owners;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTransactionCount() public view returns (uint) {
|
||||||
|
return transactions.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTransaction(
|
||||||
|
uint _txIndex
|
||||||
|
)
|
||||||
|
public
|
||||||
|
view
|
||||||
|
returns (
|
||||||
|
address to,
|
||||||
|
uint value,
|
||||||
|
bytes memory data,
|
||||||
|
bool executed,
|
||||||
|
uint numConfirmations
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Transaction storage transaction = transactions[_txIndex];
|
||||||
|
return (
|
||||||
|
transaction.to,
|
||||||
|
transaction.value,
|
||||||
|
transaction.data,
|
||||||
|
transaction.executed,
|
||||||
|
transaction.numConfirmations
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import {HardhatUserConfig, vars} from "hardhat/config";
|
import { HardhatUserConfig, vars } from "hardhat/config";
|
||||||
import "@nomicfoundation/hardhat-toolbox";
|
import "@nomicfoundation/hardhat-toolbox";
|
||||||
const INFURA_API_KEY = vars.get("INFURA_API_KEY");
|
import dotenv from "dotenv";
|
||||||
|
dotenv.config();
|
||||||
const config: HardhatUserConfig = {
|
const config: HardhatUserConfig = {
|
||||||
solidity: "0.8.24",
|
solidity: "0.8.24",
|
||||||
networks: {
|
networks: {
|
||||||
sepolia: {
|
polygon: {
|
||||||
url: `https://sepolia.infura.io/v3/${INFURA_API_KEY}`,
|
url: `https://polygon-amoy.g.alchemy.com/v2/pEtFFy_Qr_NrM1vMnlzSXmYXkozVNzLy`,
|
||||||
|
accounts: [process.env.POLYGON_PK || ""],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"_format": "hh-sol-dbg-1",
|
||||||
|
"buildInfo": "../build-info/61afe259f874fc3da9eb2666746c2273.json"
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"MultiSigWallet#MultiSigWallet": "0x375A5bbF574Cd10EaDCd9B632369Ce3644AcaE15"
|
||||||
|
}
|
7
contract/ignition/deployments/chain-80002/journal.jsonl
Normal file
7
contract/ignition/deployments/chain-80002/journal.jsonl
Normal file
File diff suppressed because one or more lines are too long
17
contract/ignition/modules/MultiSigWallet.ts
Normal file
17
contract/ignition/modules/MultiSigWallet.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||||
|
|
||||||
|
const JAN_1ST_2030 = 1893456000;
|
||||||
|
const ONE_GWEI: bigint = 1_000_000_000n;
|
||||||
|
|
||||||
|
const owners = ["0xfE87F7EF2a58a1f363a444332df6c131C683e35f"];
|
||||||
|
|
||||||
|
const MultiSigModule = buildModule("MultiSigWallet", (m) => {
|
||||||
|
const ownerP = m.getParameter("owners", owners);
|
||||||
|
const confirmationsP = m.getParameter("_numConfirmationsRequired", 1);
|
||||||
|
|
||||||
|
const deploy = m.contract("MultiSigWallet", [ownerP, confirmationsP]);
|
||||||
|
|
||||||
|
return { deploy };
|
||||||
|
});
|
||||||
|
|
||||||
|
export default MultiSigModule;
|
16
contract/package-lock.json
generated
16
contract/package-lock.json
generated
@ -1,9 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "block-accounting",
|
"name": "contract",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^16.4.5"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
|
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
|
||||||
"@types/chai": "^4.3.14",
|
"@types/chai": "^4.3.14",
|
||||||
@ -3301,6 +3304,17 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dotenv": {
|
||||||
|
"version": "16.4.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
|
||||||
|
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://dotenvx.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/elliptic": {
|
"node_modules/elliptic": {
|
||||||
"version": "6.5.4",
|
"version": "6.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
|
||||||
|
@ -8,5 +8,8 @@
|
|||||||
"hardhat": "^2.22.3",
|
"hardhat": "^2.22.3",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.4.5"
|
"typescript": "^5.4.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^16.4.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user