Skip to content

Instantly share code, notes, and snippets.

@HCharlanes
Last active September 12, 2016 23:19
Show Gist options
  • Save HCharlanes/673b6dd8e2490a53a3e421aad3d64aa7 to your computer and use it in GitHub Desktop.
Save HCharlanes/673b6dd8e2490a53a3e421aad3d64aa7 to your computer and use it in GitHub Desktop.
import "StablecoinTokenAPI.sol";
/// @title Simple bet contract using USD Stablecoins.
/// @author Hadrien Charlanes - <hadrien.charlanes@consensys.net>
contract USDPool {
//Address of the private stablecoin Contract previously ordered by the SimpleBet dapp.
address public stablecoinLicensedAddress;
//Private Stablecoin service Contract Instance.
StablecoinTokenAPI public licensedStablecoin;
//Name of the pool
string public poolName;
//Receiver of the pot
address public receiver;
//Price of the USD gift in USDcents;
uint public giftPriceInCents;
//Status of the USDPot
bool public potIsFull;
//Price of the USD gift in WEI at the time of the pot Creation (To manage edge cases)
uint public giftPriceInWEI;
//events
event PoolFull();
event PoolFilled(address indexed sender, uint indexed amountInCents);
event PoolEmptied();
///@dev Constructor, sets a pot for a USD gift.
function USDPool (address _stablecoinLicensedAddress, uint _giftPriceInCents, address _receiver, string _poolName) {
stablecoinLicensedAddress = _stablecoinLicensedAddress;
licensedStablecoin = StablecoinTokenAPI(stablecoinLicensedAddress);
if (licensedStablecoin.creator() == address(0)) throw;
poolName = _poolName;
giftPriceInCents = _giftPriceInCents;
giftPriceInWEI = licensedStablecoin.getUSDcentstoWEIPrice(_giftPriceInCents);
receiver = _receiver;
}
modifier poolFull (bool boolean) {if (potIsFull==boolean) throw; _}
function fillThePool () poolFull(true) public returns(bool) {
uint amountInCents = licensedStablecoin.convertToUSD.value(msg.value)();
if (licensedStablecoin.balanceOf(address(this)) + licensedStablecoin.getUSDcentstoWEIPrice(this.balance) >= giftPriceInCents) {
potIsFull = true;
PoolFull();
}
PoolFilled(msg.sender, amountInCents);
}
function sendThePool () poolFull(false) public returns (bool) {
// Might do nothing in case of already withdrawn stablecoins.
licensedStablecoin.convertToETH(licensedStablecoin.balanceOf(address(this)));
receiver.send(this.balance);
PoolEmptied();
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment