Skip to content

Commit

Permalink
Merge branch 'epic-subscription' into bqeth_script
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Jul 23, 2024
2 parents 8bcf5ad + 7bb50e8 commit 35c599d
Show file tree
Hide file tree
Showing 11 changed files with 1,299 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable

GlobalAllowList public immutable accessController;
IERC20 public immutable feeToken;
address public immutable adopter;
address public immutable adopterSetter;

uint256 public immutable initialBaseFeeRate;
uint256 public immutable baseFeeRateIncrease;
Expand All @@ -35,6 +35,7 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable

uint32 public activeRitualId;
mapping(uint256 periodNumber => Billing billing) public billingInfo;
address public adopter;

uint256[20] private gap;

Expand Down Expand Up @@ -79,7 +80,7 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable
* @param _coordinator The address of the coordinator contract
* @param _accessController The address of the global allow list
* @param _feeToken The address of the fee token contract
* @param _adopter The address of the adopter
* @param _adopterSetter Address that can set the adopter address
* @param _initialBaseFeeRate Fee rate per node per second
* @param _baseFeeRateIncrease Increase of base fee rate per each period (fraction of INCREASE_BASE)
* @param _encryptorFeeRate Fee rate per encryptor per second
Expand All @@ -92,7 +93,7 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable
Coordinator _coordinator,
GlobalAllowList _accessController,
IERC20 _feeToken,
address _adopter,
address _adopterSetter,
uint256 _initialBaseFeeRate,
uint256 _baseFeeRateIncrease,
uint256 _encryptorFeeRate,
Expand All @@ -109,7 +110,7 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable
)
{
require(address(_feeToken) != address(0), "Fee token cannot be the zero address");
require(_adopter != address(0), "Adopter cannot be the zero address");
require(_adopterSetter != address(0), "Adopter setter cannot be the zero address");
require(
address(_accessController) != address(0),
"Access controller cannot be the zero address"
Expand All @@ -119,7 +120,7 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable
"Base fee rate increase must be fraction of INCREASE_BASE"
);
feeToken = _feeToken;
adopter = _adopter;
adopterSetter = _adopterSetter;
initialBaseFeeRate = _initialBaseFeeRate;
baseFeeRateIncrease = _baseFeeRateIncrease;
encryptorFeeRate = _encryptorFeeRate;
Expand Down Expand Up @@ -152,6 +153,15 @@ contract BqETHSubscription is EncryptorSlotsSubscription, Initializable, Ownable
__Ownable_init(_treasury);
}

function setAdopter(address _adopter) external {
require(msg.sender == adopterSetter, "Only adopter setter can set adopter");
require(
adopter == address(0) && _adopter != address(0),
"Adopter can be set only once with not zero address"
);
adopter = _adopter;
}

function baseFees() public view returns (uint256) {
uint256 currentPeriodNumber = getCurrentPeriodNumber();
return baseFees(currentPeriodNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ abstract contract EncryptorSlotsSubscription is AbstractSubscription {
usedEncryptorSlots += addresses.length;
require(usedEncryptorSlots <= encryptorSlots, "Encryptors slots filled up");
} else {
usedEncryptorSlots -= addresses.length;
if (usedEncryptorSlots >= addresses.length) {
usedEncryptorSlots -= addresses.length;
} else {
usedEncryptorSlots = 0;
}
}
}

Expand Down
Loading

0 comments on commit 35c599d

Please sign in to comment.