1
Watch
2
Star
0
Fork
0
Issue

final project for Consensys blockchain certification

adeelhasan
adeelhasan
pushedAt 8 months ago

adeelhasan/kitty_party

Kitty Party

A Kitty Party is an informal savings scheme in which participants pool money each month, and a rotating winner gets that aggregated sum. There are as many iterations as participants, and the primary benefit is to be able to access a lump sum amount. There are variations on how the claimant is decided each cycle.

The primary goal of this project is to model this process, keeping best practices and Consensys final project requirements in mind.


Overview of Design

Installation

Aside from truffle, the only noteworthy item is that to test oraclize, we need the Ethereum Bridge to be installed. More details below in the testing section.

Use of a Library

A very basic library that checks array bounds, linked with ExternalUintArrayStorage.sol.

Use of a Circuit Breaker

  • CircuitBreaker.sol has modifiers
      modifier notInEmergency(){require(circuitBreakerState == CircuitBreakerState.NoEmergency,"no emergency"); _;}
      modifier inEmergency(){require(circuitBreakerState != CircuitBreakerState.NoEmergency, "not in emergency"); _;}
      modifier inRedAlert(){require(circuitBreakerState == CircuitBreakerState.RedAlert, "in red alert"); _;}
  • KittyPartyBase.sol descends from CircuitBreaker, and uses the modifiers

Stretch Goal - Upgradable Contract

The lottery for a kitty party needs some form of randomization, and the goal was to be able to upgrade the randomization part of a deployed contract. This then meant that the storage needed to be separated out, and passed to a new randomizer, whose requirement is to implement IRandomizeRangeToArray.sol. It also meant that there was need for a uniform interface to be able to call the randomization that was currently installed.

/// @dev abstract function implementation, that makes the randomizer fill out the results
function doInitialLottery() internal {
    IRandomizeRangeToArray randomizer = IRandomizeRangeToArray(upgradableRandomizerAddress);
    randomizer.randomize(numberOfParticipants, externalStorageAddress);
}

There are two implementations of IRandomizeRangeToArray.sol:

Stretch Goal - Use of Oraclize

In determining a random order of winners, a Wolfram Alpha query is used through Oraclize. This is wrapped in the contract RandomIndicesOraclizeBase.sol, which will produce a list of n integers within the range of 0 to y.

Stretch Goal - Use of ENS

sequential.kittyparty.test is registered on ropsten, please visit with Metamask in a ropsten account.

This currently points to the deployed KittyPartySequential.sol contract, and is utilized in the frontend code:

//when on ropsten, can use ENS for contract address
var myContractAddress = "";
var myContractAbi = [..];
web3.eth.ens.getAddress('sequential.kittyparty.test').then((address)=>{
  window.myContract = new window.web3.eth.Contract (myContractAbi,address);
  refreshContractInfo();
});

Testing

truffle test

The only noteworthy item is that to test oraclize, we need the Ethereum Bridge to be installed

Testnet Address

Front End

Deployed :

  • https://adeelhasan.github.io/kitty_party/
  • this is connected to a KittyPartySequential contract
  • have a ropsten account with at least 1 gWei
  • click "Contribute to this Cycle"
  • the metamask confirmation should come up
  • state will get updated to reflect that the participant has contriuted for current cycle

Presenatation

https://vimeo.com/340220008 PowerPoint used in the video


ucloud ads