Comments (7)
@maraoz have a look at my draft prototype of this function.
I analysed several ICOs, only few of them used stepped function for token price and for bonuses. Inside function they use such param as timestamp
, startDate
, endDate
, deadlines
, amounts
. Most efficient way to check it is simply make an array of deadlines, as amount of them is
small (no binary search, mapping etc.).
enum timeType {
second, minute, hour, day, month, year
}
// pre: startDate < endDate, startDate < deadlines[i] <= endDate, every deadlines[i] < deadlines[i + 1]
// pre: amounts.length > 0 and deadlines.length > 0
// startDate and endDate in seconds
function get_amount(
uint256[] deadlines,
uint256[] amounts,
uint256 startDate,
uint256 endDate,
timeType time_type) returns (uint256) {
if(now < startDate && now > endDate)
throw;
if(amounts.length == 0 && deadlines.length == 0 && deadlines.length != amounts.length)
throw;
for(var i = 0; i < deadlines.length; i++){
if(i + 1 < deadlines.length)
if(startDate > deadlines[i] && deadlines[i] > endDate && deadlines[i] >= deadlines[i + 1])
throw;
}
uint256 convertedMeasure = 1;
uint256[] timeValue; //can't be memrory, as push operates in storage
timeValue.push(60);
timeValue.push(60);
timeValue.push(24);
timeValue.push(30);
timeValue.push(365);
timeType[] timeTypeArr;
timeTypeArr.push(timeType.second);
timeTypeArr.push(timeType.minute);
timeTypeArr.push(timeType.hour);
timeTypeArr.push(timeType.day);
timeTypeArr.push(timeType.month);
timeTypeArr.push(timeType.year);
for(i = 0; i < 6; i++){
convertedMeasure *= timeValue[i];
if(time_type == timeTypeArr[i])
break;
// maybe check if enum type is wrong
}
for(i = 0; i < deadlines.length; i++){
if(now < convertedMeasure * deadlines[i])
return amounts[i];
}
// never reached, but should ensure to prevent this
}
}
I don't like timestamp type, we might use just seconds and leave convertation on user's side. Also we can move "check bounds" logic to modifiers.
from openzeppelin-contracts.
@maraoz do you like design of contract?
from openzeppelin-contracts.
I'd do it with block heights, not timestamps, to be consistent with our security recommendations.
from openzeppelin-contracts.
@maraoz won't this be harder for avarage developer?
from openzeppelin-contracts.
@misteraverin possibly. But our focus with OpenZeppelin is security over ease of use.
Some extra feedback: consider writing this contract not as a standalone function, but as other helper contracts we used, with state and a constructor. I'd do this as a contract one can inherit from and which gives you access to a getSteppedValue()
or something
from openzeppelin-contracts.
We have an IncreasingPriceCrowdsale that grows linearly, but shows how getCurrentRate
can be used for more interesting functions. @misteraverin are you still interesting in contributing here? If so, let us know how we can help you.
FTR, there's also some experimentation with BondingCurves, which adjust the rate of the token and can be used to incentivize or disincentivize different things. This could be more interesting than a hard-coded stepped rate.
from openzeppelin-contracts.
Closing due to staleness. There was some talk about bonding curves a couple months ago, but it doesn't seem to have caused large repercussions.
from openzeppelin-contracts.
Related Issues (20)
- Fixing "Invalid OpCode" Truffle Error with Openzeppelin Library Installed HOT 6
- ERC20 _update customization is not practical. HOT 17
- Consider changing `memory-safe` NatSpec annotations to `assembly('memory-safe')` dialect string HOT 3
- A new utility contract to enhances the security of deploying and managing upgradable contracts in Hardhat plugin.
- A new utility contract to enhances the security of deploying and managing upgradable contracts in Hardhat plugin HOT 8
- Codecov result don't show up in the PR summary anymore
- Incorrect link formatting in NatSpec causing broken URLs HOT 2
- Consider making `Votes._moveDelegateVotes` internal virtual
- Consider using transient storage in Governor and AccessManager HOT 1
- Incorrect pragma
- bugs in the docs code? ERC721 HOT 1
- AccessManager restricted should not default to admin role HOT 1
- Mark AccessManagerUpgradeable abstract or implement initializer function HOT 1
- Fix API documentation broken links in the doc-site
- Make `_moveDelegateVotes` internal in Votes.sol HOT 1
- Request to Add Upgradable Interfaces in contracts/interfaces Directory of the OpenZeppelin Contracts Upgradeable Repository HOT 2
- Semi abstracted nonce support
- Low level call library
- UUPSUpgradeable is not ERC1882 (draft) compatible, but rather only ERC1967 compatible. HOT 2
- ERC1967Utils and/or UUPSUpgradeable should enforce that only ADMIN is allowed to upgrade the implementation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openzeppelin-contracts.