From 0865e9a2756863631c77d2164c1877bad842864b Mon Sep 17 00:00:00 2001 From: aggre Date: Tue, 2 Feb 2021 15:52:35 +0900 Subject: [PATCH 1/6] add dip: Fixed Maximum APY --- DIPS/dip-fixed-max-apy.md | 125 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 DIPS/dip-fixed-max-apy.md diff --git a/DIPS/dip-fixed-max-apy.md b/DIPS/dip-fixed-max-apy.md new file mode 100644 index 00000000..191f75bc --- /dev/null +++ b/DIPS/dip-fixed-max-apy.md @@ -0,0 +1,125 @@ +``` +DIP: <# to be assigned> +Title: Fixed Maximum APY +Author(s): aggre +Contributors: +Type: Policy +Status: +Date Proposed: 2021-02-02 +Date Ratified: +Dependencies: +Replaces: +License: CC0 +``` + +## References + +## Sentence Summary + +Remove "number of assets" from the formula for inflation rate. + +## Paragraph Summary + +"Asset count" and "deposit amount" are used as variables to calculate the Dev Protocol's inflation rate. + +Using these variables, the user-proposed Policy determines the inflation rate. + +Removing "asset count" from those variables eliminates the risk that a new Market will be an attack on the protocol. + +## Component Summary + +- Remove "asset count" from `Policy.rewards` method's interface. +- The upper limit of APY is fixed. +- Users need new Policies to be proposed/voted to correct the decline in APY. + +## Motivation + +Increasing asset count works to increase APY, which reduces the disincentive (= risk that "asset increase" leads to "APY plunge") for creators. + +However, the issues surrounding the Market scheme have become increasingly complex. And in some cases, the increase in APY can act as a disincentive for some creators, so using asset count as a variable can be seen as introducing too much complexity into the protocol and hindering upgradability. + +## Specification + +### Proposed Code + +#### Policy Interface + +```solidity +function rewards(uint256 _deposits) external view returns (uint256); +``` + +##### Actual + +https://github.com/dev-protocol/protocol/blob/76e57682e7f9f2e375413b445189a38edc66ff97/contracts/interface/IPolicy.sol#L5-L8 + +#### Allocator Contract + +```solidity +function calculateMaxRewardsPerBlock() external view returns (uint256) { + return IPolicy(config().policy()).rewards(ILockup(config().lockup()).getAllValue()); +} +``` + +##### Actual + +https://github.com/dev-protocol/protocol/blob/76e57682e7f9f2e375413b445189a38edc66ff97/contracts/src/allocator/Allocator.sol#L25-L30 + +### Test Cases + +```solidity +interface IPolicy { + function rewards(uint256 _deposits) external view returns(uint256); +} + +interface ILockup { + function getAllValue() external view returns(uint256); +} + +contract Policy is IPolicy { + function rewards(uint256 _deposits) external view returns(uint256) { + return _deposits * 2; + } +} + +contract Lockup is ILockup { + function getAllValue() external view returns(uint256) { + return 100000000000000000000; + } +} +``` + +```ts +const policy: PolicyInstance; + +describe("Policy.rewards", () => { + it("Returns 2x the passed value", async () => { + const result = await policy.rewards(100); + expect(result).to.be(200); + }); +}); +``` + +```ts +const allocator: AllocatorInstance; +const lockup: LockupInstance; +const policy: PolicyInstance; + +describe("Allocator.calculateMaxRewardsPerBlock", () => { + it("Returns the result when the argument of Policy.rewards is set to the value of Lockup.getAllValue", async () => { + const result = await allocator.calculateMaxRewardsPerBlock(); + const allValue = await lockup.getAllValue(); + const expected = await policy.rewards(allValue); + expect(result).to.be(expected); + }); +}); +``` + +### Security Considerations + +The obvious risk to the protocol is an "unexpected increase in the inflation rate," and this proposal eliminates that risk. + +There is no additional technical risk associated with this proposal. + +## Copyright + +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From c8f8b53e8769589ea58f602bb62a8174b66e156e Mon Sep 17 00:00:00 2001 From: aggre Date: Tue, 2 Feb 2021 15:56:03 +0900 Subject: [PATCH 2/6] assign the number --- DIPS/{dip-fixed-max-apy.md => dip-46.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename DIPS/{dip-fixed-max-apy.md => dip-46.md} (99%) diff --git a/DIPS/dip-fixed-max-apy.md b/DIPS/dip-46.md similarity index 99% rename from DIPS/dip-fixed-max-apy.md rename to DIPS/dip-46.md index 191f75bc..8aac2d8a 100644 --- a/DIPS/dip-fixed-max-apy.md +++ b/DIPS/dip-46.md @@ -1,5 +1,5 @@ ``` -DIP: <# to be assigned> +DIP: 46 Title: Fixed Maximum APY Author(s): aggre Contributors: From 38b31fbdf9a3762e41a686ea8a20b34dfbaafeb2 Mon Sep 17 00:00:00 2001 From: aggre Date: Tue, 2 Feb 2021 16:07:02 +0900 Subject: [PATCH 3/6] add some explain and proposed code --- DIPS/dip-46.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/DIPS/dip-46.md b/DIPS/dip-46.md index 8aac2d8a..bc8b594b 100644 --- a/DIPS/dip-46.md +++ b/DIPS/dip-46.md @@ -31,6 +31,7 @@ Removing "asset count" from those variables eliminates the risk that a new Marke - Remove "asset count" from `Policy.rewards` method's interface. - The upper limit of APY is fixed. - Users need new Policies to be proposed/voted to correct the decline in APY. +- When this DIP is applied, the latest "inflation upper limit by old scheme" is used as the inflation upper limit's initial value. ## Motivation @@ -52,6 +53,52 @@ function rewards(uint256 _deposits) external view returns (uint256); https://github.com/dev-protocol/protocol/blob/76e57682e7f9f2e375413b445189a38edc66ff97/contracts/interface/IPolicy.sol#L5-L8 +#### Policy for DIP46 + +```solidity +contract DIP46 is DIP1 { + uint256 private constant basis = 10000000000000000000000000; + uint256 private constant power_basis = 10000000000; + uint256 private constant mint_per_block = 120000000000000; // **SHOULD REWRITE WITH THE LATEST VALUE** + + constructor(address _config) public DIP1(_config) {} + + function rewards(uint256 _deposits) + external + view + returns (uint256) + { + uint256 t = ERC20(config().token()).totalSupply(); + uint256 s = (_deposits.mul(basis)).div(t); + uint256 max = mint_per_block; + uint256 _d = basis.sub(s); + uint256 _p = + ( + (power_basis.mul(12)).sub( + s.div((basis.div((power_basis.mul(10))))) + ) + ) + .div(2); + uint256 p = _p.div(power_basis); + uint256 rp = p.add(1); + uint256 f = _p.sub(p.mul(power_basis)); + uint256 d1 = _d; + uint256 d2 = _d; + for (uint256 i = 0; i < p; i++) { + d1 = (d1.mul(_d)).div(basis); + } + for (uint256 i = 0; i < rp; i++) { + d2 = (d2.mul(_d)).div(basis); + } + uint256 g = ((d1.sub(d2)).mul(f)).div(power_basis); + uint256 d = d1.sub(g); + uint256 mint = max.mul(d); + mint = mint.div(basis).div(basis); + return mint; + } +} +``` + #### Allocator Contract ```solidity From 74d4bd6cd06bc2ce19939d722d03f9d0d314f34d Mon Sep 17 00:00:00 2001 From: aggre Date: Tue, 2 Feb 2021 16:08:19 +0900 Subject: [PATCH 4/6] unified terms --- DIPS/dip-46.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIPS/dip-46.md b/DIPS/dip-46.md index bc8b594b..7628f817 100644 --- a/DIPS/dip-46.md +++ b/DIPS/dip-46.md @@ -16,7 +16,7 @@ License: CC0 ## Sentence Summary -Remove "number of assets" from the formula for inflation rate. +Remove "asset count" from the formula for inflation rate. ## Paragraph Summary From a9424bdb2f4d843cabd2b7a95729391771faa568 Mon Sep 17 00:00:00 2001 From: aggre Date: Tue, 2 Feb 2021 16:22:00 +0900 Subject: [PATCH 5/6] proofreading --- DIPS/dip-46.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DIPS/dip-46.md b/DIPS/dip-46.md index 7628f817..bad14c9f 100644 --- a/DIPS/dip-46.md +++ b/DIPS/dip-46.md @@ -16,7 +16,7 @@ License: CC0 ## Sentence Summary -Remove "asset count" from the formula for inflation rate. +Remove "asset count" from the formula for Dev Protocol's inflation rate. ## Paragraph Summary @@ -29,9 +29,10 @@ Removing "asset count" from those variables eliminates the risk that a new Marke ## Component Summary - Remove "asset count" from `Policy.rewards` method's interface. -- The upper limit of APY is fixed. +- The inflation rate does not change even if asset count increases. - Users need new Policies to be proposed/voted to correct the decline in APY. - When this DIP is applied, the latest "inflation upper limit by old scheme" is used as the inflation upper limit's initial value. + The inflation rate decreases only with increasing deposit (=staking). That inflation curve is similar to the validator rewards from deposits on the Ethereum 2.0 beacon chain. ## Motivation From d38290487d0d9ff5f69114a5a618d10b9d6d9a2b Mon Sep 17 00:00:00 2001 From: aggre Date: Tue, 2 Feb 2021 16:24:13 +0900 Subject: [PATCH 6/6] fixed a paragraph error --- DIPS/dip-46.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIPS/dip-46.md b/DIPS/dip-46.md index bad14c9f..903d5927 100644 --- a/DIPS/dip-46.md +++ b/DIPS/dip-46.md @@ -32,7 +32,7 @@ Removing "asset count" from those variables eliminates the risk that a new Marke - The inflation rate does not change even if asset count increases. - Users need new Policies to be proposed/voted to correct the decline in APY. - When this DIP is applied, the latest "inflation upper limit by old scheme" is used as the inflation upper limit's initial value. - The inflation rate decreases only with increasing deposit (=staking). That inflation curve is similar to the validator rewards from deposits on the Ethereum 2.0 beacon chain. +- The inflation rate decreases only with increasing deposit (=staking). That inflation curve is similar to the validator rewards from deposits on the Ethereum 2.0 beacon chain. ## Motivation