selfkey-staking
v1.0.0
Published
Contracts that provide access to a marketplace based on the staking of KEY by participants
Downloads
2
Readme
staked-access
Contracts that provide access to a marketplace based on the staking of KEY by participants
Overview
The StakedAccess
contract provides the following functionality.
Addresses are able to "stake" KEY into a smart contract, reserving an amount of tokens to indicate their willingness to participate in a particular Selfkey Marketplace. The tokens staked in this manner are kept "locked" for a set amount of time defined by the
period
attribute in theStakedAccess
contract.Staked tokens can only be retrieved by the owner once the staking period has passed.
For the staking functionality to work, owner (or ID-Wallet in our specific case) has to invoke
approve(stakingContractAddress, stakingPrice)
against on the token contract, passing the staking contract address and the corresponding staking price (including all decimal places). This is to allow the staking contract to spend funds (up to the limit set) on behalf of its owner.
StakedAccess Contract Interface
All staking functionality is implemented by the StakedAccess
contract, which includes the
following attributes:
Public State Variables
releaseDates[address]
: A mapping from addresses to a datetime in Unix format, stating the moment at which the staking can be released.price
: The token amount to be staked. This number should include all 18 decimals (e.g. for a staking price of 30 KEY,price
should be set to30000000000000000000
).period:
The minimum amount of seconds that each stake should be locked for before allowing token retrieval.
Public Functions
stake()
: On invoking thestake()
function, an mount of tokens defined byprice
will be deducted from the sender address balance, and be kept locked in the staking contract until the due staking period has been fulfilled. For the contract to be able to deduct tokens on behalf of the user, the user must previously call the approve method of the token contract.retrieve()
: If the corresponding release date for the sender has already been reached, the sender can invoke theretrieve()
function, in which case the staked amount is sent back to the owner wallet.hasStake(address)
: returns true if the given address has a stake above zero on the contract, otherwise it returns false.setPrice(uint)
(only owner): Staking price can be changed anytime by the contract owner.setPeriod(uint)
(only owner): Staking period can be changed anytime by the contract owner. This won't affect the release date of stakes already in place.
Events
KEYStaked(address by, uint amount)
: Emitted when an address has successfully staked an amount of KEY.KEYRetrieved(address to, uint amount)
: Emitted when a KEY owner has released the tokens previously staked.
Development
The smart contracts are being implemented in Solidity 0.4.19
.
Prerequisites
- NodeJS, version 9.5+ (I use
nvm
to manage Node versions —brew install nvm
.) - truffle, which is a comprehensive framework for Ethereum development.
npm install -g truffle
— this should install Truffle v4+. Check that withtruffle version
. - Access to the KYC_Chain Jira
Initialization
npm install
Testing
Standalone
npm test
or with code coverage
npm run test:cov
From within Truffle
Run the truffle
development environment
truffle develop
then from the prompt you can run
compile
migrate
test
as well as other Truffle commands. See truffleframework.com for more.
Linting
We provide the following linting options
npm run lint:sol
— to lint the Solidity files, andnpm run lint:js
— to lint the Javascript.
Deployment
Deploy the contracts as follows
(TO DO)
Contributing
Please see the contributing notes.