-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 57c6670
Showing
15 changed files
with
16,579 additions
and
0 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,11 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
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,10 @@ | ||
node_modules | ||
package.json | ||
img | ||
artifacts | ||
cache | ||
coverage | ||
.env | ||
.* | ||
README.md | ||
coverage.json |
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,4 @@ | ||
{ | ||
"tabWidth": 4, | ||
"singleQuote": false | ||
} |
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,7 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"compiler-version": ["error", "^0.8.0"], | ||
"func-visibility": ["warn", { "ignoreConstructors": false }] | ||
} | ||
} |
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,10 @@ | ||
node_modules | ||
package.json | ||
img | ||
artifacts | ||
cache | ||
coverage | ||
.env | ||
.* | ||
README.md | ||
coverage.json |
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,13 @@ | ||
# Sample Hardhat Project | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. | ||
|
||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat node | ||
npx hardhat run scripts/deploy.js | ||
``` |
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 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.7; | ||
|
||
// errors | ||
error PaymentEscrow__NotArbiter(); | ||
error PaymentEscrow__TransactionUnsuccesful(); | ||
|
||
/**@title A Payment Escrow Contract | ||
* @author Ejim favour | ||
* @notice This contract ensures secure and credible payment for goods and services. | ||
*/ | ||
|
||
contract PaymentEscrow { | ||
// state variables | ||
address public s_arbiter; | ||
address public s_beneficiary; | ||
address public s_payer; | ||
bool public s_isApproved; | ||
|
||
// events | ||
event Approved( | ||
address indexed payer, | ||
address indexed beneficiary, | ||
uint amount | ||
); | ||
|
||
// modifiers | ||
modifier onlyArbiter() { | ||
if (msg.sender != s_arbiter) { | ||
revert PaymentEscrow__NotArbiter(); | ||
} | ||
_; | ||
} | ||
|
||
// functions | ||
|
||
receive() external payable {} | ||
|
||
function pay(address _beneficiary, address _arbiter) external payable { | ||
s_payer = msg.sender; | ||
s_beneficiary = _beneficiary; | ||
s_arbiter = _arbiter; | ||
(bool callSuccess, ) = address(this).call{value: msg.value}(""); | ||
|
||
if (!callSuccess) revert PaymentEscrow__TransactionUnsuccesful(); | ||
} | ||
|
||
function approve() external onlyArbiter { | ||
uint balance = address(this).balance; | ||
|
||
uint payedAmount = balance - (address(this).balance / 1000) * 5; | ||
|
||
(bool callSuccess, ) = s_beneficiary.call{value: payedAmount}(""); | ||
|
||
if (!callSuccess) revert PaymentEscrow__TransactionUnsuccesful(); | ||
|
||
emit Approved(s_payer, s_beneficiary, payedAmount); | ||
|
||
s_isApproved = true; | ||
} | ||
|
||
function revertTransaction() external {} | ||
} |
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,29 @@ | ||
const { network, ethers } = require("hardhat"); | ||
const { verify } = require("../utils/verify"); | ||
|
||
module.exports = async ({ getNamedAccounts, deployments }) => { | ||
const { payer, arbiter, beneficiary } = await getNamedAccounts(); | ||
const { deploy, log } = deployments; | ||
|
||
const amount = ethers.utils.parseEther("0.4"); | ||
|
||
const args = [arbiter, beneficiary]; | ||
|
||
const paymentEscrowContract = await deploy("PaymentEscrow", { | ||
from: payer, | ||
log: true, | ||
args, | ||
waitConfirmations: network.config.blockConfirmation || 1, | ||
value: amount, | ||
}); | ||
|
||
log("Contract deployed"); | ||
log("-------------------------"); | ||
|
||
// verify | ||
if (network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) { | ||
await verify(paymentEscrowContract.address, args); | ||
} | ||
}; | ||
|
||
module.exports.tags = ["all", "paymentEscrow"]; |
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,13 @@ | ||
·-----------------------------|----------------------------|-------------|-----------------------------· | ||
| Solc version: 0.8.18 · Optimizer enabled: false · Runs: 200 · Block limit: 30000000 gas │ | ||
······························|····························|·············|······························ | ||
| Methods · 15 gwei/gas · 1.11 usd/matic │ | ||
··················|···········|··············|·············|·············|···············|·············· | ||
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │ | ||
··················|···········|··············|·············|·············|···············|·············· | ||
| PaymentEscrow · approve · - · - · 62756 · 6 · 0.00 │ | ||
··················|···········|··············|·············|·············|···············|·············· | ||
| Deployments · · % of limit · │ | ||
······························|··············|·············|·············|···············|·············· | ||
| PaymentEscrow · - · - · 437471 · 1.5 % · 0.01 │ | ||
·-----------------------------|--------------|-------------|-------------|---------------|-------------· |
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("@nomicfoundation/hardhat-toolbox"); | ||
require("@nomiclabs/hardhat-ethers"); | ||
require("hardhat-deploy"); | ||
require("solidity-coverage"); | ||
require("dotenv").config(); | ||
require("hardhat-deploy-ethers"); | ||
require("hardhat-gas-reporter"); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
|
||
const TEST_SEPOLIA_URL = | ||
process.env.TEST_SEPOLIA_URL || "https:\\eth-sepolia/example"; | ||
const TEST_PRIVATE_KEY = process.env.TEST_PRIVATE_KEY || "key"; | ||
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "key"; | ||
const COIN_MARKET_CAP_API_KEY = process.env.COIN_MARKET_CAP_API_KEY || "key"; | ||
|
||
module.exports = { | ||
solidity: "0.8.18", | ||
networks: { | ||
sepolia: { | ||
url: TEST_SEPOLIA_URL, | ||
accounts: [TEST_PRIVATE_KEY], | ||
chainId: 11155111, | ||
blockConfirmations: 6, | ||
}, | ||
localhost: { | ||
url: "http://127.0.0.1:8545", | ||
chainId: 31337, | ||
}, | ||
}, | ||
etherscan: { | ||
api: ETHERSCAN_API_KEY, | ||
}, | ||
gasReporter: { | ||
enabled: true, | ||
outputFile: "gas-reporter.txt", | ||
noColors: true, | ||
currency: "USD", | ||
coinmarketcap: COIN_MARKET_CAP_API_KEY, | ||
token: "MATIC", | ||
}, | ||
namedAccounts: { | ||
payer: { | ||
default: 0, | ||
}, | ||
arbiter: { | ||
default: 1, | ||
}, | ||
beneficiary: { | ||
default: 2, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.