Skip to content

Commit 94d83c5

Browse files
committed
single class minter
1 parent ee9d822 commit 94d83c5

File tree

3 files changed

+31
-88
lines changed

3 files changed

+31
-88
lines changed

contracts/BondMinter.sol

Lines changed: 24 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,113 +3,63 @@ pragma solidity ^0.8.0;
33
import {IBondFactory} from "./interfaces/button-wood/IBondFactory.sol";
44
import {IBondMinter} from "./interfaces/IBondMinter.sol";
55

6-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
7-
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
8-
9-
// A class of bonds are uniquely identified by collateralToken, trancheRatios and duration,
10-
// which are hashed to create the bond's config hash
11-
// Based on the provided frequency minter instantiates new bonds for each config when poked
6+
// A minter periodically mints a specified class of bonds or config
7+
// a config is uniquely identified by {collateralToken, trancheRatios and duration}
8+
// Based on the provided frequency minter instantiates new bonds with the given config when poked
129
//
13-
// Minor Modification to button wood's version keep track of the bond <-> config reference
10+
// Minor Modification to button wood's version
1411
// https://github.com/buttonwood-protocol/tranche/blob/main/contracts/bondMinter/
15-
// we want to know given a bond, was it minted by this minter and what is it's config hash
16-
contract BondMinter is IBondMinter, Ownable {
17-
using EnumerableSet for EnumerableSet.Bytes32Set;
18-
12+
// in ours configs are immutable and we limit one config per minter
13+
contract BondMinter is IBondMinter {
1914
// bond factory
2015
IBondFactory public immutable bondFactory;
2116

2217
// mint frequency parameters
2318
uint256 public immutable waitingPeriod;
2419
uint256 public lastMintTimestamp;
2520

21+
// minter bond config
22+
IBondMinter.BondConfig public config;
23+
bytes32 public immutable override configHash;
24+
2625
// mapping of minted bonds
2726
mapping(address => bool) mintedBonds;
2827

29-
// mapping to get the full bond config from config hash
30-
mapping(bytes32 => IBondMinter.BondConfig) private configHashesToConfigs;
31-
32-
// mapping to get bond config hash from bond address
33-
mapping(address => bytes32) private bondToConfigHashes;
34-
35-
// list of config hashes
36-
EnumerableSet.Bytes32Set private configHashes;
3728

38-
constructor(IBondFactory bondFactory_, uint256 waitingPeriod_) {
29+
constructor(IBondFactory bondFactory_, uint256 waitingPeriod_, IBondMinter.BondConfig memory config_) {
3930
bondFactory = bondFactory_;
4031
waitingPeriod = waitingPeriod_;
32+
config = config_;
33+
configHash = computeHash(config_);
4134
lastMintTimestamp = 0;
35+
36+
emit BondConfigAdded(config);
4237
}
4338

4439
// checks if bond has been minted using this minter
4540
function isInstance(address bond) external view override returns (bool) {
4641
return mintedBonds[bond];
4742
}
4843

49-
// gets the bond's config hash
50-
function getConfigHash(address bond) external view override returns (bytes32) {
51-
return bondToConfigHashes[bond];
52-
}
53-
54-
// get the bond's config
55-
function getConfig(address bond) external view override returns (IBondMinter.BondConfig memory) {
56-
return configHashesToConfigs[bondToConfigHashes[bond]];
57-
}
58-
59-
// counts all configs
60-
function numConfigs() public view override returns (uint256) {
61-
return configHashes.length();
62-
}
63-
64-
// gets configs
65-
function bondConfigAt(uint256 index) public view override returns (IBondMinter.BondConfig memory) {
66-
return configHashesToConfigs[configHashes.at(index)];
67-
}
68-
6944
function mintBonds() external override {
7045
require(
7146
block.timestamp - lastMintTimestamp >= waitingPeriod,
7247
"BondMinter: Not enough time has passed since last mint timestamp"
7348
);
7449
lastMintTimestamp = block.timestamp;
7550

76-
for (uint256 i = 0; i < numConfigs(); i++) {
77-
BondConfig memory bondConfig = bondConfigAt(i);
78-
bytes32 configHash = computeHash(bondConfig);
79-
address bond = bondFactory.createBond(
80-
bondConfig.collateralToken,
81-
bondConfig.trancheRatios,
82-
lastMintTimestamp + bondConfig.duration
83-
);
84-
85-
mintedBonds[bond] = true;
86-
bondToConfigHashes[bond] = configHash;
87-
88-
emit BondMinted(bond, configHash);
89-
}
90-
}
51+
address bond = bondFactory.createBond(
52+
config.collateralToken,
53+
config.trancheRatios,
54+
lastMintTimestamp + config.duration
55+
);
9156

92-
function addBondConfig(IBondMinter.BondConfig memory config) external onlyOwner returns (bool) {
93-
bytes32 hash = computeHash(config);
94-
if (configHashes.add(hash)) {
95-
configHashesToConfigs[hash] = config;
96-
emit BondConfigAdded(config);
97-
return true;
98-
}
99-
return false;
100-
}
57+
mintedBonds[bond] = true;
10158

102-
function removeBondConfig(IBondMinter.BondConfig memory config) external onlyOwner returns (bool) {
103-
bytes32 hash = computeHash(config);
104-
if (configHashes.remove(hash)) {
105-
delete configHashesToConfigs[hash];
106-
emit BondConfigRemoved(config);
107-
return true;
108-
}
109-
return false;
59+
emit BondMinted(bond);
11060
}
11161

112-
function computeHash(IBondMinter.BondConfig memory config) private pure returns (bytes32) {
113-
return keccak256(abi.encode(config.collateralToken, config.trancheRatios, config.duration));
62+
function computeHash(IBondMinter.BondConfig memory config_) private pure returns (bytes32) {
63+
return keccak256(abi.encode(config_.collateralToken, config_.trancheRatios, config_.duration));
11464
}
11565
}

contracts/YieldStrategy.sol

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

1212
// todo: add setters
1313

14-
// tranche yield is specific to each unique bond config
15-
// config => {collateralToken, trancheRatios, duration}
16-
mapping(bytes32 => uint256[]) private _trancheYields;
14+
// tranche yield is specific to a bond minter (which mints a specific class of bonds)
15+
// a bond class is uniquely identified by {collateralToken, trancheRatios, duration}
16+
mapping(IBondMinter => uint256[]) private _trancheYields;
1717

1818
function computeTrancheYield(IBondMinter minter, IBondController bond, uint256 seniorityIDX, uint256 trancheAmt) external view override returns (uint256) {
1919
return trancheAmt * computeTrancheYieldPerc(minter, bond, seniorityIDX) / (10 ** PCT_DECIMALS);
2020
}
2121

2222
function computeTrancheYieldPerc(IBondMinter minter, IBondController bond, uint256 seniorityIDX) public view returns (uint256) {
23+
// assert(minter.isInstance(bond));
2324
return trancheYields(minter, bond, seniorityIDX) * computeTranchePrice(bond, seniorityIDX) / (10 ** PRICE_DECIMALS);
2425
}
2526

2627
function trancheYields(IBondMinter minter, IBondController bond, uint256 seniorityIDX) public view returns (uint256) {
27-
return _trancheYields[minter.getConfigHash(address(bond))][seniorityIDX];
28+
return _trancheYields[minter][seniorityIDX];
2829
}
2930

3031
// Tranche pricing function goes here:

contracts/interfaces/IBondMinter.sol

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@ interface IBondMinter {
77

88
event BondConfigAdded(BondConfig config);
99

10-
event BondConfigRemoved(BondConfig config);
11-
12-
event BondMinted(address bond, bytes32 configHash);
10+
event BondMinted(address bond);
1311

1412
function mintBonds() external;
1513

1614
function isInstance(address bond) external view returns (bool);
1715

18-
function getConfigHash(address bond) external view returns (bytes32);
19-
20-
function getConfig(address bond) external view returns (BondConfig memory);
21-
22-
function numConfigs() external view returns (uint256);
23-
24-
function bondConfigAt(uint256 index) external view returns (BondConfig memory);
16+
function configHash() external view returns (bytes32);
2517
}

0 commit comments

Comments
 (0)