-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/bonding curve #827
Feature/bonding curve #827
Conversation
there are a few linting errors on Power.sol, primarily along the usage of the The error was caused by a ganache error, restarting the job now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore my comments on BancorFormula.sol and Power.sol
if they're supposed to be changed as little as possible from the original bancor contracts
|
||
/** | ||
* Bancor formula by Bancor | ||
* https://github.com/bancorprotocol/contracts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dev
prefixes
require(_supply > 0 && _connectorBalance > 0 && _connectorWeight > 0 && _connectorWeight <= MAX_WEIGHT); | ||
|
||
// special case for 0 deposit amount | ||
if (_depositAmount == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ }
to match codebase style
return 0; | ||
|
||
// special case if the weight = 100% | ||
if (_connectorWeight == MAX_WEIGHT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likewise { }
here
require(_supply > 0 && _connectorBalance > 0 && _connectorWeight > 0 && _connectorWeight <= MAX_WEIGHT && _sellAmount <= _supply); | ||
|
||
// special case for 0 sell amount | ||
if (_sellAmount == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ }
here
return 0; | ||
|
||
// special case for selling the entire supply | ||
if (_sellAmount == _supply) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
return _connectorBalance; | ||
|
||
// special case if the weight = 100% | ||
if (_connectorWeight == MAX_WEIGHT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
(result, precision) = power( | ||
_supply, baseD, MAX_WEIGHT, _connectorWeight | ||
); | ||
uint256 temp1 = _connectorBalance.mul(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a better name for temp1
and temp2
?
* https://github.com/ConsenSys/curationmarkets/blob/master/CurationMarkets.sol | ||
*/ | ||
contract BondingCurve is StandardToken, BancorFormula, Ownable { | ||
uint256 public poolBalance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation for this variable?
uint256 public poolBalance; | ||
|
||
/* | ||
reserve ratio, represented in ppm, 1-1000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the
/**
* asfsd
* asdf
*/
style for these block comments as we do elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they should probably also be prefixed with @dev
0ee47cc
to
d07663b
Compare
seems like |
LGTM, but I'd like an expert in BondingCurve theory to take a peek as well. Can Billy come review this as well? cc @spalladino as well, since I know you did some research into TCRs for zeppelin_os |
i'd sudgest to:
|
d6a8248
to
b209c46
Compare
Thanks @okwme commited all of those updates |
@balasan Cool stuff! Need to dive deeper into the code :D |
yeah, should be fairly easy to do this |
@balasan: With regards to "This function depends on some pre-generated constants and is beyond my understanding" - I can explain into details if you're interested. BTW, this contract has since been optimized (for performance mostly), and you can find it at https://github.com/bancorprotocol/contracts/tree/0.3.18 (though the implementation is slightly more cumbersome, so I doubt you would want to incorporate it into Zeppelin). With regards to testing - there are With regards to "the contract becomes stuck if everyone sells all tokens and totalSupply & poolBalance are 0" - the same thing would happen if everyone buys until supply/balance are Thanks |
hey @barakman! thanks for all the additional info |
Hello @balasan, and thank you for your interest and contribution! I'm sorry so much time has passed with no response from us. I really want for Bonding Curves to be added to OZ and want to get this merged, but worry that the PR as it is has become too large (there's the Bonding Curve itself, the Bancor formula, the Power library, tests, etc.). Would you be willing to split this into smaller, self-contained PRs so that we can more rapidly review changes and merge? Thanks! |
@nventuro I think it would make sense to break out the Power function into a separate PR. Bonding Curve and Bancor formula should probably go together — does that work? |
@balasan since the Bancor formula is its own contract, I think it makes sense for there for be a PR introducing it, with tests, etc., and then build on top of it (same with the power functions). |
Closing due to staleness. |
Fixes #819
🚀 Description
Adding a simple bonding curve contract (aka automatic market maker) based on Bancor formula. The codes is based on and includes code by Bancor: https://github.com/bancorprotocol/contracts.
I have extracted the
power
function from the originalBancorFormula.sol
contract into a separatePower.sol
contract in themath
folder. This function depends on some pre-generated constants and is beyond my understanding. Although there is a test for it, including it in the library does depend on trusting the Bancor code to some degree and might be hard to audit. I can see this being a reason to not merge this PR, but differing the decision to the Zeppelin team.I have also pushed the code to a separate repo: https://github.com/relevant-community/bonding-curve so in the case it is not a good fit for Zeppelin we can maintain it there.
Some background reading about bonding curves:
https://hackernoon.com/how-to-make-bonding-curves-for-continuous-token-models-3784653f8b17
https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5
and Bancor formula:
https://drive.google.com/file/d/0B3HPNP-GDn7aRkVaV3dkVl9NS2M/view
npm run lint:all:fix
).