Created
April 7, 2022 02:38
-
-
Save kevupton/a44f528b3b810ba8c04c903dab61c346 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
contract PooNami is ERC20 { | |
constructor() ERC20('PooNami', 'POO') { | |
_mint(msg.sender, 1e24); | |
} | |
} | |
interface IMintable { | |
function mint(uint256 amount) external; | |
} | |
interface IBurnable { | |
function burn(uint256 amount) external; | |
} | |
/* | |
- Get list of addresses | |
- Distributes turds to the list of addresses | |
- Mint a turd NFT -> to someones account | |
- Contract owns subtokens | |
- Send an address and amount | |
*/ | |
contract AirGrap { | |
event GrabCreated(Grab, address); | |
struct Grab { | |
IERC20 token; | |
uint256 totalAmount; | |
uint256 amountPerGrab; | |
uint256 totalGrabsPossible; | |
uint256 currentGrabCount; | |
} | |
Grab[] private _grabs; | |
// grabId => walletAddress => hasGrabbed | |
mapping(uint256 => mapping(address => bool)) public hasGrabbed; | |
function getGrab(uint256 grabId) external view returns (Grab memory) { | |
return _grabs[grabId]; | |
} | |
receive() payable external { | |
} | |
// deposit an amount of a token, and how much per user someone can grab | |
function depositToken(IERC20 token, uint256 totalAmount, uint256 totalGrabsPossible) external returns (uint256 grabId) { | |
// transfer token to this contract | |
token.transferFrom(msg.sender, address(this), totalAmount); | |
grabId = _grabs.length; | |
Grab memory grab = Grab( | |
token, | |
totalAmount, | |
totalAmount / totalGrabsPossible, | |
totalGrabsPossible, | |
0 | |
); | |
// save the grab as a new grab | |
_grabs.push(grab); | |
emit GrabCreated(grab, msg.sender); | |
} | |
// claim function -> receive x tokens | |
function claim(uint256 grabId) external { | |
// make sure that the grab id exists | |
require(grabId < _grabs.length, 'Invalid grab id'); | |
// only allow one grab per wallet | |
require(!hasGrabbed[grabId][msg.sender], 'You have already grabbed'); | |
// only allow so many grabs | |
require(_grabs[grabId].currentGrabCount < _grabs[grabId].totalGrabsPossible, 'No more grabs to be claimed'); | |
_grabs[grabId].token.transfer(msg.sender, _grabs[grabId].amountPerGrab); | |
// makes sure they cannot do it again | |
hasGrabbed[grabId][msg.sender] = true; | |
_grabs[grabId].currentGrabCount++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment