-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
11 changed files
with
45,050 additions
and
10 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
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 @@ | ||
ALCHEMY_API_KEY= | ||
ROPSTEN_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,8 @@ | ||
node_modules | ||
.env | ||
|
||
#Hardhat files | ||
cache | ||
artifacts | ||
dist | ||
typechain |
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,16 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 120, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"explicitTypes": "always", | ||
"semi": true | ||
} | ||
} | ||
] | ||
} |
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,104 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.7; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
interface IERC721 { | ||
function safeTransferFrom( | ||
address from, | ||
address to, | ||
uint256 tokenId | ||
) external; | ||
|
||
function transferFrom( | ||
address from, | ||
address to, | ||
uint256 tokenId | ||
) external; | ||
} | ||
|
||
contract EnglishAuction is Ownable { | ||
event Started(); | ||
event Bid(address indexed bidder, uint256 amount); | ||
event Withdrawn(address indexed bidder, uint256 amount); | ||
event Ended(address winner, uint256 amount); | ||
|
||
IERC721 public immutable nft; | ||
uint256 public immutable tokenId; | ||
|
||
uint256 public endAt; | ||
bool public started; | ||
bool public ended; | ||
|
||
address public highestBidder; | ||
uint256 public highestBid; | ||
|
||
mapping(address => uint256) public bids; | ||
|
||
constructor( | ||
address _nft, | ||
uint256 _tokenId, | ||
uint256 _startingBid | ||
) { | ||
require(_nft != address(0), "!nft"); | ||
|
||
nft = IERC721(_nft); | ||
tokenId = _tokenId; | ||
highestBid = _startingBid; | ||
} | ||
|
||
function start(uint256 duration) external onlyOwner { | ||
require(!started, "already started"); | ||
require(duration > 0, "duration > 0"); | ||
|
||
nft.transferFrom(owner(), address(this), tokenId); | ||
started = true; | ||
endAt = block.timestamp + duration; | ||
|
||
emit Started(); | ||
} | ||
|
||
function bid() external payable { | ||
require(started, "!started"); | ||
require(block.timestamp < endAt, "sale already ended"); | ||
|
||
uint256 newBid = bids[msg.sender] + msg.value; | ||
|
||
require(newBid > highestBid, "bid too low"); | ||
|
||
highestBidder = msg.sender; | ||
highestBid = newBid; | ||
|
||
bids[msg.sender] = newBid; | ||
|
||
emit Bid(msg.sender, newBid); | ||
} | ||
|
||
function withdraw() external { | ||
uint256 userBid = bids[msg.sender]; | ||
require(highestBidder != msg.sender, "highest bidder cant withdraw"); | ||
require(userBid > 0, "user has no bids"); | ||
|
||
bids[msg.sender] = 0; | ||
payable(msg.sender).transfer(userBid); | ||
|
||
emit Withdrawn(msg.sender, userBid); | ||
} | ||
|
||
function end() external { | ||
require(started, "!started"); | ||
require(!ended, "already ended"); | ||
require(block.timestamp > endAt, "auction didnt end yet"); | ||
|
||
ended = true; | ||
|
||
if (highestBidder != address(0)) { | ||
payable(owner()).transfer(highestBid); | ||
nft.transferFrom(address(this), highestBidder, tokenId); | ||
} else { | ||
nft.transferFrom(address(this), owner(), tokenId); | ||
} | ||
|
||
emit Ended(highestBidder, highestBid); | ||
} | ||
} |
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,56 @@ | ||
import { config as dotenvConfig } from "dotenv"; | ||
import "@typechain/hardhat"; | ||
import "@nomiclabs/hardhat-ethers"; | ||
import "@nomiclabs/hardhat-waffle"; | ||
import "@nomiclabs/hardhat-etherscan"; | ||
import "solidity-coverage"; | ||
import "hardhat-gas-reporter"; | ||
import { HardhatUserConfig } from "hardhat/types/config"; | ||
|
||
dotenvConfig(); | ||
|
||
const gasPrice = parseInt(process.env.GAS_PRICE || "1000000000"); | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: { | ||
compilers: [ | ||
{ | ||
version: "0.8.10", | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 200, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
networks: { | ||
hardhat: { | ||
initialBaseFeePerGas: 0, | ||
}, | ||
rinkeby: { | ||
url: process.env.RINKEBY_URL || "", | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
gasPrice, | ||
}, | ||
mainnet: { | ||
url: process.env.MAINNET_URL || "", | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
gasPrice, | ||
}, | ||
}, | ||
gasReporter: { | ||
enabled: process.env.REPORT_GAS !== undefined, | ||
currency: "USD", | ||
gasPrice: 120, | ||
coinmarketcap: process.env.COINMARKETCAP_API_KEY, | ||
}, | ||
etherscan: { | ||
apiKey: process.env.ETHERSCAN_API_KEY, | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.