-
Notifications
You must be signed in to change notification settings - Fork 12
Simple rollover operation #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
be05c4b
simple rollover function
aalavandhan 170553e
fee handling
aalavandhan 572a5a3
renamed inclusion function
aalavandhan 00efb54
renamed paramter
aalavandhan 0c56f8f
Apply suggestions from code review
aalavandhan cc10c31
Update contracts/ACash.sol
aalavandhan 2ae84a7
Update contracts/FeeStrategy.sol
aalavandhan 10bf436
gas optimization
aalavandhan d50c3a6
applying yield on tranche
aalavandhan c78aa4b
Added burn function
aalavandhan 583e1cb
updated pricing math
aalavandhan 3d13411
using uint8 for decimals
aalavandhan e38f8f8
updated fee logic
aalavandhan 27d3648
Added yield to rollover function
aalavandhan f4ffa37
added duration to issuer
aalavandhan 0b1d5dd
updated bond config handling
aalavandhan 6dc56e6
computing seniority from memory
aalavandhan d231c00
Update contracts/ACash.sol
aalavandhan a35f2a8
code review fixes
aalavandhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,19 @@ | ||
| //SPDX-License-Identifier: Unlicense | ||
| pragma solidity ^0.8.0; | ||
| import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
| import { IBondController } from "./interfaces/button-wood/IBondController.sol"; | ||
| import { ITranche } from "./interfaces/button-wood/ITranche.sol"; | ||
| import { IPricingStrategy } from "./interfaces/IPricingStrategy.sol"; | ||
| import { IBondIssuer } from "./interfaces/IBondIssuer.sol"; | ||
|
|
||
| contract PricingStrategy is Ownable, IPricingStrategy { | ||
| uint256 public constant PRICE_DECIMALS = 18; | ||
|
|
||
| struct TrancheConfig { | ||
| IBondController bond; | ||
| uint256[] trancheRatios; | ||
| uint256 seniorityIDX; | ||
| } | ||
|
|
||
| // tranche_price => price_fn(tranche) * tranche_amount | ||
| function getTranchePrice(ITranche t, uint256 trancheAmt) external view override returns (uint256) { | ||
| return (computeTranchePrice(t) * trancheAmt) / (10**PRICE_DECIMALS); | ||
| } | ||
| uint8 private constant _decimals = 18; | ||
|
|
||
| // Tranche pricing function goes here: | ||
| function computeTranchePrice(ITranche t) private view returns (uint256) { | ||
| // TrancheConfig c = getTrancheConfig(t); | ||
| // based on => c.bond.collateralToken(), c.bond.cdr(), c.bond.maturityDate(), c.seniorityIDX | ||
| return (10**PRICE_DECIMALS); | ||
| // ie number of tranches of type t for 1 collateral token | ||
| function computeTranchePrice(ITranche t) public view override returns (uint256) { | ||
| return (10**_decimals); | ||
| } | ||
|
|
||
| // NOTE: this is very gas intensive | ||
| // rebuilding the tranche's pricing parameters though the parent bond | ||
| // Alternatively the bond issuer can map the tranche to these parameters for efficient recovery | ||
| function getTrancheConfig(ITranche t) private view returns (TrancheConfig memory) { | ||
| TrancheConfig memory c; | ||
| // TODO: this is still to be merged | ||
| // https://github.com/buttonwood-protocol/tranche/pull/30 | ||
| c.bond = IBondController(t.bondController()); | ||
| uint256 trancheCount = c.bond.trancheCount(); | ||
| for (uint256 i = 0; i < trancheCount; i++) { | ||
| (ITranche u, uint256 ratio) = c.bond.tranches(i); | ||
| c.trancheRatios[i] = ratio; | ||
| if (t == u) { | ||
| c.seniorityIDX = i; | ||
| } | ||
| } | ||
| return c; | ||
| function decimals() external view override returns (uint8) { | ||
| return _decimals; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| import { ITranche } from "./button-wood/ITranche.sol"; | ||
|
|
||
| interface IFeeStrategy { | ||
| function feeToken() external view returns (address); | ||
|
|
||
| // amount of spot being mint | ||
| function computeMintFee(uint256 amount) external view returns (int256); | ||
|
|
||
| // amount of spot being burnt | ||
| function computeBurnFee(uint256 amount) external view returns (int256); | ||
|
|
||
| // amount of tranche to be traded out for given amount of tranche in | ||
| function computeRolloverReward( | ||
| ITranche trancheIn, | ||
| ITranche trancheOut, | ||
| uint256 trancheInAmt, | ||
| uint256 trancheOutAmt | ||
| ) external view returns (int256); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import { ITranche } from "./button-wood/ITranche.sol"; | ||
|
|
||
| interface IPricingStrategy { | ||
| function getTranchePrice(ITranche tranche, uint256 trancheAmt) external view returns (uint256); | ||
| function computeTranchePrice(ITranche t) external view returns (uint256); | ||
|
|
||
| function decimals() external view returns (uint8); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.