Skip to content

Commit 494df50

Browse files
committed
using config hash to map tranche yield
1 parent b0663a5 commit 494df50

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

contracts/BondMinter.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {IBondMinter} from "./interfaces/IBondMinter.sol";
1010
// Minor Modification to button wood's version
1111
// https://github.com/buttonwood-protocol/tranche/blob/main/contracts/bondMinter/
1212
// in ours configs are immutable and we limit one config per minter
13+
// and we have a way of checking the config hash of a given bond
14+
// This can be extened to multi-config
1315
contract BondMinter is IBondMinter {
1416
// bond factory
1517
IBondFactory public immutable bondFactory;
@@ -20,7 +22,7 @@ contract BondMinter is IBondMinter {
2022

2123
// minter bond config
2224
IBondMinter.BondConfig public config;
23-
bytes32 public immutable override configHash;
25+
bytes32 private immutable _configHash;
2426

2527
// mapping of minted bonds
2628
mapping(address => bool) mintedBonds;
@@ -30,7 +32,7 @@ contract BondMinter is IBondMinter {
3032
bondFactory = bondFactory_;
3133
waitingPeriod = waitingPeriod_;
3234
config = config_;
33-
configHash = computeHash(config_);
35+
_configHash = computeHash(config_);
3436
lastMintTimestamp = 0;
3537

3638
emit BondConfigAdded(config);
@@ -59,6 +61,10 @@ contract BondMinter is IBondMinter {
5961
emit BondMinted(bond);
6062
}
6163

64+
function getConfigHash(address bond) external view override returns (bytes32) {
65+
return mintedBonds[bond] ? _configHash : bytes32(0);
66+
}
67+
6268
function computeHash(IBondMinter.BondConfig memory config_) private pure returns (bytes32) {
6369
return keccak256(abi.encode(config_.collateralToken, config_.trancheRatios, config_.duration));
6470
}

contracts/YieldStrategy.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ contract YieldStrategy is Ownable, IYieldStrategy {
1111

1212
// todo: add setters
1313

14-
// tranche yield is specific to a bond minter (which mints a specific class of bonds)
14+
// tranche yield is specific a bond class (which is indexed by its config hash)
1515
// a bond class is uniquely identified by {collateralToken, trancheRatios, duration}
16-
mapping(IBondMinter => uint256[]) private _trancheYields;
16+
// the minter returns the config hash for each bond its creates
17+
mapping(bytes32 => uint256[]) private _trancheYields;
1718

1819
function computeTrancheYield(IBondMinter minter, IBondController bond, uint256 seniorityIDX, uint256 trancheAmt) external view override returns (uint256) {
1920
return trancheAmt * computeTrancheYieldPerc(minter, bond, seniorityIDX) / (10 ** PCT_DECIMALS);
2021
}
2122

2223
function computeTrancheYieldPerc(IBondMinter minter, IBondController bond, uint256 seniorityIDX) public view returns (uint256) {
23-
// assert(minter.isInstance(bond));
2424
return trancheYields(minter, bond, seniorityIDX) * computeTranchePrice(bond, seniorityIDX) / (10 ** PRICE_DECIMALS);
2525
}
2626

2727
function trancheYields(IBondMinter minter, IBondController bond, uint256 seniorityIDX) public view returns (uint256) {
28-
return _trancheYields[minter][seniorityIDX];
28+
// if the bond was not minted by the minter, this will return 0x00..
29+
// and thus yeilds will be [0,0...]
30+
return _trancheYields[minter.getConfigHash(address(bond))][seniorityIDX];
2931
}
3032

3133
// Tranche pricing function goes here:

contracts/interfaces/IBondMinter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ interface IBondMinter {
1313

1414
function isInstance(address bond) external view returns (bool);
1515

16-
function configHash() external view returns (bytes32);
16+
function getConfigHash(address bond) external view returns (bytes32);
1717
}

0 commit comments

Comments
 (0)