-
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.
Merge pull request #1 from NicoAcosta/raffle
add ultra violet experience raffle
- Loading branch information
Showing
7 changed files
with
230 additions
and
1 deletion.
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,7 @@ | ||
[ | ||
"constructor(string)", | ||
"function raffled() view returns (bool)", | ||
"function snapshotURL() view returns (string)", | ||
"function winnerId() view returns (uint256)", | ||
"function winnerRaffle()" | ||
] |
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 @@ | ||
[ | ||
"constructor(string)", | ||
"function raffled() view returns (bool)", | ||
"function snapshotURL() view returns (string)", | ||
"function winnerId() view returns (uint256)", | ||
"function winnerRaffle()" | ||
] |
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,42 @@ | ||
//SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.0; | ||
|
||
/// @title Ultra Violet Experience Raffle | ||
/// @author Nicolás Acosta - nicoacosta.eth - @0xnico_ - gh/NicoAcosta | ||
contract UltraVioletExperienceRaffle { | ||
address private immutable _deployer; | ||
|
||
uint256 public winnerId; | ||
|
||
string public snapshotURL; | ||
|
||
bool public raffled; // false by default | ||
|
||
constructor(string memory _snapshotURL) { | ||
_deployer = msg.sender; | ||
snapshotURL = _snapshotURL; | ||
} | ||
|
||
function winnerRaffle() external { | ||
require(msg.sender == _deployer, "Caller is not contract deployer"); | ||
|
||
require(!raffled, "Already raffled"); | ||
|
||
raffled = true; | ||
|
||
winnerId = _randomId(); | ||
} | ||
|
||
function _randomId() private view returns (uint256) { | ||
return | ||
(uint256( | ||
keccak256( | ||
abi.encodePacked( | ||
blockhash(block.number), | ||
block.timestamp, | ||
msg.sender | ||
) | ||
) | ||
) % 66) + 5; // from 5 to 70 | ||
} | ||
} |
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,73 @@ | ||
Holder Snapshot | ||
|
||
tokenId,owner | ||
"1","0x94A8F46E3e05d8aB61Fb22eDc2893bE249C11D66" | ||
"2","0xab468Aec9bB4b9bc59b2B2A5ce7F0B299293991f" | ||
"3","0x94A8F46E3e05d8aB61Fb22eDc2893bE249C11D66" | ||
"4","0x94A8F46E3e05d8aB61Fb22eDc2893bE249C11D66" | ||
"5","0xe0c87789dF2c506F5EeAAB10BF4C31a92866720B" | ||
"6","0x65D6f46c346cf45F3160B9a59d4c758BB2b02EB4" | ||
"7","0x0a17A9EC3d10B3209d8f7dF2e094043cC4Ff9916" | ||
"8","0x7e8C38Ad50622c0b26906C9Cf81D2825fC78A38B" | ||
"9","0xF823668826C24Ae56e3976EcE3Ae90De5d808Df5" | ||
"10","0x7097CbF2Dd1502551DEa0eB0828373B2F121f43c" | ||
"11","0x7097CbF2Dd1502551DEa0eB0828373B2F121f43c" | ||
"12","0xE4E8d6650A8Dc5EBf91F9EE563d71378483D90c3" | ||
"13","0x87C59E0b19e358190c5Fd576E61fE82e0b64141A" | ||
"14","0x2e69fc5871C642D045354A3988D1F071102B49aE" | ||
"15","0xEE9846B0E2e56fa0EEa38eA90E992e23a52EE1f9" | ||
"16","0x8962B4ebe444f2fa4eF74e631a084726Ad9BDc3D" | ||
"17","0x93BB3dc705Fb2ad98B696BCC17a0fb7d439d12F4" | ||
"18","0xdB297810D387C5a602f9E6219c9dfA9Bb0e99Ce8" | ||
"19","0x82372E90F72772556Ef8974E93575DB4cb383814" | ||
"20","0xc785fD4e9aee80A6d6cBFcc57380b92aA92DeEF3" | ||
"21","0x29F5DeE65E1Fb856B816EaB4f0B702c10e5Eaa34" | ||
"22","0x17BD26d95Eeae83E83EE7D2886AE3252Eb053B2E" | ||
"23","0xf7Ef198a88AC34e7F8d048Fdcaa954b333FAE9b1" | ||
"24","0x7e89DAF03D3E81d81bA6a242FD05646FaEF524B8" | ||
"25","0x0922B9c1C508Fb2447D0fe60A84F47EA2A862aCE" | ||
"26","0x372DfA084E004A9039a5926eC332dbf674678bBD" | ||
"27","0x8A19EE2B23EF483C6c9B2De1e65D8c799Cd80EA1" | ||
"28","0x326486311f2D69a2cd9Ec5bb9f5F5e22a1634781" | ||
"29","0x3c79B593B50FE7AfC9140Eb4735DB5f8c8c8e327" | ||
"30","0x7B635FD7a61ee8E344faf749CD7BBc670aadECb8" | ||
"31","0x0C4FE81Ad359d6518e4485626F6966eA619cD8A4" | ||
"32","0x5AC60D44585F04AE5C82dB2F21f272f15d7A1675" | ||
"33","0xF163ae41b39556Bc538146ade6B568FCA84D26a9" | ||
"34","0xF1E9bFb37484C0f882e4A403A025543B46a5dcc9" | ||
"35","0x619708a880A255F82c3b47b1A5e83AB2d217602b" | ||
"36","0xc117Ca9d4e409Bb3657D79e59475f450592E0911" | ||
"37","0xB5F11F09E5a99437e08EC523d05fC3F1E6BF0F42" | ||
"38","0xB5F11F09E5a99437e08EC523d05fC3F1E6BF0F42" | ||
"39","0x20e6af36fD433821f704B12ec03f644dc406A5Dc" | ||
"40","0x75d514b6040727C19ae06aE8F1a1c7912c4C91C0" | ||
"41","0x2d9cBC4ECFBd1B8F66Aa798FD51585AE058dAA8B" | ||
"42","0x0F79F4d6f2C3233b36B8Cb2fCE90f576F188035e" | ||
"43","0xa6a02363987B367C449381b3B41C158829eFA03C" | ||
"44","0xed95E6608a15B1ED2B15b32336A9b9779Bc64bf8" | ||
"45","0x50A308f8395D58295c90E666A457257e911D1620" | ||
"46","0x09E23AA3529c4E9DE7D15CE07bea134A7dc2B411" | ||
"47","0xf9ba31763CA3445e5770cDC70284f990406bCA84" | ||
"48","0x2f2581c49A79880561032094887F59bd6d777F75" | ||
"49","0x2B440b531C1056EAB1243b69872979fC365808f0" | ||
"50","0xbf46D2161045251cB97D0B41929bc1D36044E1a0" | ||
"51","0xC1202B2da243467882439944885339f9Fd71279C" | ||
"52","0x0a7C3007f2156fF8DB9579EFB7aDBbd7212D3c3C" | ||
"53","0x120ACBe09175be31c013456Daf3F4406d9744953" | ||
"54","0x198F7e5f79B6efe3D67591ee62b527e99a6F2F38" | ||
"55","0x5AC60D44585F04AE5C82dB2F21f272f15d7A1675" | ||
"56","0x3Deaf8134c9aeBF84e9C8870c4AC1DcDB5E37E15" | ||
"57","0x48BFB74bEF9bfa3C5896e8A168b413d8458146f4" | ||
"58","0xb41E1D0e85AFB7A0e2b94F92B97a24fc132182A7" | ||
"59","0x4bcaC160CE0Fb9015C2b8C28726cb1EAc879a960" | ||
"60","0x4bcaC160CE0Fb9015C2b8C28726cb1EAc879a960" | ||
"61","0x802529aF4BAf0f726Ba00C727362737BbeE846a8" | ||
"62","0xd8F5bA4b9b6f29b9b4AcA3cDc3b46BF5BCc9B7eD" | ||
"63","0x567B5E79cE0d465a0FF1e1eeeFE65d180b4C5D41" | ||
"64","0x1E9a81aFa411E1887711Ca4c8Bf35aFde846b348" | ||
"65","0xbe5DB9E33A2309898D44d9f7A6EE9229EB4d5415" | ||
"66","0x84730BB3FCeb9171CD93e6f98CBdfa50e2Da8635" | ||
"67","0x20e6af36fD433821f704B12ec03f644dc406A5Dc" | ||
"68","0x20e6af36fD433821f704B12ec03f644dc406A5Dc" | ||
"69","0x127917BbbA3420Fa9ae7F13BfAEbC2e86838F4ad" | ||
"70","0x8876F907C45EC53847838e19b9d609E7A9561BBf" |
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,35 @@ | ||
const {BigNumber} = require('ethers') | ||
const hre = require('hardhat') | ||
|
||
const snapshotURL = | ||
'https://ipfs.io/ipfs/bafybeidsanm573nvzzliztvwtzw7l6eo235kkksyad7ebyegayprgwjpzm' | ||
|
||
let deployer, addrs | ||
|
||
async function deploy() { | ||
const Raffle = await hre.ethers.getContractFactory( | ||
'UltraVioletExperienceRaffle' | ||
) | ||
const raffle = await Raffle.deploy(snapshotURL, { | ||
gasPrice: BigNumber.from(process.env.MAINNET_GAS_PRICE) | ||
}) | ||
|
||
const tx = raffle.deployTransaction | ||
console.log('Deployment tx:', tx.hash) | ||
|
||
await raffle.deployed() | ||
;[deployer, ...addrs] = await ethers.getSigners() | ||
|
||
console.log('UltraVioletExperienceRaffle deployed to:', raffle.address) | ||
console.log('Deployed by:', deployer.address) | ||
} | ||
|
||
const tryToDeploy = async () => { | ||
// Repeat deploy() until gasPrice < block base fee | ||
deploy().catch((error) => { | ||
console.error(error) | ||
tryToDeploy() | ||
}) | ||
} | ||
|
||
tryToDeploy() |
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,65 @@ | ||
const {expect} = require('chai') | ||
const {BigNumber} = require('ethers') | ||
const {ethers} = require('hardhat') | ||
|
||
const snapshotURL = | ||
'https://ipfs.io/ipfs/bafybeidsanm573nvzzliztvwtzw7l6eo235kkksyad7ebyegayprgwjpzm' | ||
|
||
describe.only('Raffle', async function () { | ||
let raffle | ||
|
||
let deployer, addr1, addr2, addrs | ||
|
||
beforeEach(async function () { | ||
;[deployer, addr1, addr2, ...addrs] = await ethers.getSigners() | ||
|
||
const Raffle = await ethers.getContractFactory( | ||
'UltraVioletExperienceRaffle' | ||
) | ||
raffle = await Raffle.deploy(snapshotURL) | ||
|
||
await raffle.deployed() | ||
}) | ||
|
||
describe('Deployment', async function () { | ||
describe('Set snapshot URL', async function () { | ||
it('Should set snapshot URL', async function () { | ||
expect(await raffle.snapshotURL()).to.equal(snapshotURL) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Raffle', async function () { | ||
it('Should return 0 before raffle', async function () { | ||
expect(await raffle.winnerId()).to.equal(0) | ||
}) | ||
|
||
async function checkId() { | ||
const tx = await raffle.winnerRaffle() | ||
await tx.wait() | ||
|
||
const _id = await raffle.winnerId() | ||
const id = _id.toNumber() | ||
|
||
console.log('id:', id) | ||
|
||
expect(id).to.be.greaterThanOrEqual(5) | ||
expect(id).to.be.lessThanOrEqual(70) | ||
} | ||
|
||
it('Should set random id from 5 to 70', async function () { | ||
// for (let i = 0; i <= 500; i++) { | ||
await checkId() | ||
// } | ||
}) | ||
|
||
it('Should revert when trying to raffle twice', async function () { | ||
const tx = await raffle.winnerRaffle() | ||
await tx.wait() | ||
|
||
await expect(raffle.winnerRaffle()).to.be.revertedWith( | ||
'Already raffled' | ||
) | ||
}) | ||
}) | ||
}) |