Skip to content

Instantly share code, notes, and snippets.

@naterush
Created June 4, 2017 21:30
Show Gist options
  • Save naterush/aa667c07c2f07fb2772b567c05bb245d to your computer and use it in GitHub Desktop.
Save naterush/aa667c07c2f07fb2772b567c05bb245d to your computer and use it in GitHub Desktop.
This set of contracts would allow a whale to easily buy many more tokens per block in the case of a sale w/ limited amount by addr, and a limited number of contributions per block. Has not been tested/reviewed :)
pragma solidity ^0.4.10;
import "ERCToken.sol"; //Assumes ERC Tokens standard
contract HoldTokens {
address owner = msg.sender;
ERCToken token;
function buyTokens(bytes data, address tokenAddress) payable {
if (msg.sender != owner) throw;
token = ERCToken(tokenAddress);
if (!token.call.value(msg.value)(data)) { //this call buys the tokens
throw;
}
}
function transferTokens() {
if (msg.sender != owner) throw;
if (!token.transfer(owner, token.balanceOf(this))) {
throw;
}
suicide(owner);
}
}
contract TokenBuyer {
HoldTokens[] tokenHolders;
uint startingIndex;
ERCToken token;
function buyTokens(address tokenAddress, bytes data, uint maxAmtByAdd) payable {
token = ERCToken(tokenAddress);
while (msg.gas > 50000) { //should find real gas cost
HoldTokens tokenHolder = new HoldTokens();
tokenHolder.buyTokens.value(maxAmtByAdd)(data, tokenAddress);
tokenHolders.push(tokenHolder);
}
}
function transferTokens(address to) {
for (uint i = startingIndex; i < tokenHolders.length; i++) {
if (msg.gas > 50000) { //should find real gas cost
tokenHolders[i].transferTokens();
} else {
break;
}
}
startingIndex = i;
token.transfer(to, token.balanceOf(this));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment