@@ -3,113 +3,63 @@ pragma solidity ^0.8.0;
33import {IBondFactory} from "./interfaces/button-wood/IBondFactory.sol " ;
44import {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}
0 commit comments