Skip to main content

Coin Machine Extension (CoinMachine)

Coin Machine is a mechanism to sell tokens within a colony, simplifying the process for all participants involved. It introduces the functionality to sell limited amounts of tokens in fixed-price batches, adjusting prices up or down in between sale periods based on recent demand. Coin Machine sacrifices continual availability and real-time price adjustment for the simplicity of fixed price and fixed supply, thereby also sidestepping the challenges of price manipulation, volatility, and front-running.

See here for more information.

Interface Methods

buyTokens(uint256 _numTokens)

Purchase tokens from Coin Machine.

Parameters

NameTypeDescription
_numTokensuint256The number of tokens to purchase

deprecate(bool _deprecated)

Called when deprecating (or undeprecating) the extension

Parameters

NameTypeDescription
_deprecatedboolIndicates whether the extension should be deprecated or undeprecated

finishUpgrade()

Called when upgrading the extension

getActiveIntake():uint256 _intake

Get the number of tokens received in the period that the price was last updated for or a purchase was made

Return Parameters

NameTypeDescription
_intakeuint256Amount of tokens received

getActivePeriod():uint256 _period

Get the period that the price was last updated for or a purchase was made

Return Parameters

NameTypeDescription
_perioduint256The active period

getActiveSold():uint256 _sold

Get the number of tokens sold in the period that the price was last updated for or a purchase was made

Return Parameters

NameTypeDescription
_solduint256Amount of tokens sold

getCurrentPrice():uint256 _price

Get the current price per token

Return Parameters

NameTypeDescription
_priceuint256Current price

getEMAIntake():uint256 _amount

Get the EMA of the number of tokens received each period

Return Parameters

NameTypeDescription
_amountuint256Amount of tokens received

getEvolvePrice():bool _evolve

Get the evolvePrice boolean

Return Parameters

NameTypeDescription
_evolveboolThe evolvePrice boolean

getMaxPerPeriod():uint256 _max

Get the maximum number of tokens to sell per period

Return Parameters

NameTypeDescription
_maxuint256Maximum number of tokens

getMaxPurchase(address _user):uint256 _max

Get the maximum amount of tokens a user can purchase in a period

Parameters

NameTypeDescription
_useraddressThe user's address

Return Parameters

NameTypeDescription
_maxuint256Maximum amount of tokens

getMetatransactionNonce(address _userAddress):uint256 _nonce

Gets the next nonce for a meta-transaction

Parameters

NameTypeDescription
_userAddressaddressThe user's address

Return Parameters

NameTypeDescription
_nonceuint256The nonce

getPeriodLength():uint256 _length

Get the length of the sale period

Return Parameters

NameTypeDescription
_lengthuint256Length of the sale period

getPurchaseToken():address _token

Get the address of the token being used to make purchases

Return Parameters

NameTypeDescription
_tokenaddressThe token's address

getSellableTokens():uint256 _remaining

Get the number of remaining tokens for sale this period

Return Parameters

NameTypeDescription
_remaininguint256Tokens remaining

getTargetPerPeriod():uint256 _target

Get the target number of tokens to sell per period

Return Parameters

NameTypeDescription
_targetuint256Target number of tokens

getToken():address _token

Get the address of the token being sold

Return Parameters

NameTypeDescription
_tokenaddressThe token's address

getTokenBalance():uint256 _balance

Get the remaining balance of tokens

Return Parameters

NameTypeDescription
_balanceuint256Remaining token balance

getUserLimit(address _user):uint256 _max

Get the maximum amount of tokens a user can purchase in total

Parameters

NameTypeDescription
_useraddressThe user's address

Return Parameters

NameTypeDescription
_maxuint256Maximum amount of tokens

getWhitelist():address _whitelist

Get the address of the whitelist (if exists)

Return Parameters

NameTypeDescription
_whitelistaddressAddress of Whitelist contract

getWindowSize():uint256 _size

Get the size of the averaging window

Return Parameters

NameTypeDescription
_sizeuint256Size of the averaging window

identifier():bytes32 _identifier

Returns the identifier of the extension

Return Parameters

NameTypeDescription
_identifierbytes32The extension's identifier

initialise(address _token, address _purchaseToken, uint256 _periodLength, uint256 _windowSize, uint256 _targetPerPeriod, uint256 _maxPerPeriod, uint256 _userLimitFraction, uint256 _startingPrice, address _whitelist)

Must be called before any sales can be made

Parameters

NameTypeDescription
_tokenaddressThe token we are selling. Cannot be ether
_purchaseTokenaddressThe token to receive payments in. Use 0x0 for ether
_periodLengthuint256How long in seconds each period of the sale should last
_windowSizeuint256Characteristic number of periods that should be used for the moving average. In the long-term, 86% of the weighting will be in this window size. The higher the number, the slower the price will be to adjust
_targetPerPerioduint256The number of tokens to aim to sell per period
_maxPerPerioduint256The maximum number of tokens that can be sold per period
_userLimitFractionuint256The fraction of the total sale that a single user can buy (in WAD)
_startingPriceuint256The sale price to start at, expressed in units of _purchaseToken per token being sold, as a WAD
_whitelistaddressOptionally an address of a whitelist contract to use can be provided. Pass 0x0 if no whitelist being used

install(address _colony)

Configures the extension

Parameters

NameTypeDescription
_colonyaddressThe colony in which the extension holds permissions

setWhitelist(address _whitelist)

Set the address for an (optional) whitelist

Parameters

NameTypeDescription
_whitelistaddressThe address of the whitelist

uninstall()

Called when uninstalling the extension

updatePeriod()

Bring the token accounting current

version():uint256 _version

Returns the version of the extension

Return Parameters

NameTypeDescription
_versionuint256The extension's version number