|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.4; |
| 3 | + |
| 4 | +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 5 | +import { IEventImplementation } from "../../interfaces/IEventImplementation.sol"; |
| 6 | + |
| 7 | +interface IEconomics { |
| 8 | + // Data structure containing all the different rates for a particular relayer. |
| 9 | + // 100% (1) 1_000_000, |
| 10 | + // 10% (0.1) = 100_000, |
| 11 | + // 1% (0.01) = 10_000, |
| 12 | + // 0.1% (0.001) = 1_000, |
| 13 | + // 0.01% (0.0001) = 100, |
| 14 | + // 0.001% (0,00001) = 10, |
| 15 | + // 0.0001% = (0.000001) = 1 |
| 16 | + // All scaled by 1_000_000. |
| 17 | + // |
| 18 | + // USD values (e.g. minFee, maxFee) are scaled by 1_000 (tenth of a cent). |
| 19 | + struct DynamicRates { |
| 20 | + uint24 minFeePrimary; |
| 21 | + uint24 maxFeePrimary; |
| 22 | + uint24 primaryRate; |
| 23 | + uint24 minFeeSecondary; |
| 24 | + uint24 maxFeeSecondary; |
| 25 | + uint24 secondaryRate; |
| 26 | + uint24 salesTaxRate; |
| 27 | + } |
| 28 | + |
| 29 | + // Largely unnecesary to define separately but helps avoid stack too deep errors within reserved fuel calculations. |
| 30 | + struct Rate { |
| 31 | + uint24 minFee; |
| 32 | + uint24 maxFee; |
| 33 | + uint24 rate; |
| 34 | + } |
| 35 | + |
| 36 | + struct IntegratorData { |
| 37 | + uint32 index; |
| 38 | + uint32 activeTicketCount; |
| 39 | + bool isBillingEnabled; |
| 40 | + bool isConfigured; |
| 41 | + uint256 price; |
| 42 | + uint256 availableFuel; |
| 43 | + uint256 reservedFuel; |
| 44 | + uint256 reservedFuelProtocol; |
| 45 | + string name; |
| 46 | + bool onCredit; |
| 47 | + } |
| 48 | + |
| 49 | + struct RelayerData { |
| 50 | + uint32 integratorIndex; |
| 51 | + } |
| 52 | + |
| 53 | + struct SpentFuel { |
| 54 | + uint256 total; |
| 55 | + uint256 protocol; |
| 56 | + uint32 ticketCount; |
| 57 | + } |
| 58 | + |
| 59 | + event IntegratorToppedUp( |
| 60 | + uint32 indexed integratorIndex, |
| 61 | + uint256 indexed total, |
| 62 | + uint256 price, |
| 63 | + uint256 indexed newAveragePrice, |
| 64 | + uint256 salesTax |
| 65 | + ); |
| 66 | + event FuelReservedPrimary(uint32 integratorIndex, uint32 ticketCount, uint256 fuel, uint256 fuelProtocol); |
| 67 | + event FuelReservedSecondary(uint32 integratorIndex, uint32 ticketCount, uint256 fuel, uint256 fuelProtocol); |
| 68 | + event BasicTaxCharged(uint32 integratorIndex, uint32 actionCount, uint256 fuel, uint256 fuelProtocol); |
| 69 | + event TicketFuelEmptied(uint32 integratorIndex, uint32 ticketCount, uint256 fuel, uint256 fuelProtocol); |
| 70 | + event SalesTaxFuelCollected(address salesTaxFuelDesintation, uint256 salesTaxFuel); |
| 71 | + event AccountBalanceCorrected( |
| 72 | + uint32 integratorIndex, |
| 73 | + uint256 oldAvailableFuel, |
| 74 | + uint256 newAvailableFuel, |
| 75 | + uint256 oldReservedBalance, |
| 76 | + uint256 newReservedBalance, |
| 77 | + uint256 oldReservedBalanceProtocol, |
| 78 | + uint256 newReservedBalanceProtocol |
| 79 | + ); |
| 80 | + event UpdateBasicTaxRate(uint24 old, uint24 updated); |
| 81 | + event UpdateFuelToken(address old, address updated); |
| 82 | + event UpdateSpentFuel(SpentFuel spentFuel); |
| 83 | + event UpdateSpentFuelOnCredit(uint256 spentFuelOnCredit); |
| 84 | + event UpdateDynamicRates(uint32 integratorIndex, DynamicRates dynamicRates); |
| 85 | + event UpdateProtocolRates(DynamicRates protocolRates); |
| 86 | + event UpdateSalesTaxFuelDestination(address salesTaxFuelDestination); |
| 87 | + event IntegratorConfigured(uint32 integratorIndex, string name, address relayerAddress, DynamicRates dynamicRates); |
| 88 | + event IntegratorActivated(uint32 integratorIndex); |
| 89 | + event IntegratorDisabled(uint32 integratorIndex); |
| 90 | + event RelayerAdded(address relayerAddress, uint32 integratorIndex); |
| 91 | + event RelayerRemoved(address relayerAddress, uint32 integratorIndex); |
| 92 | + event BillingStatusUpdated(uint32 integeratorIndex, bool status); |
| 93 | + event ConfigurationStatusUpdated(uint32 integratorIndex, bool status); |
| 94 | + event EnableIntegratorBilling(uint32 integratorIndex); |
| 95 | + event DisableIntegratorBilling(uint32 integratorIndex); |
| 96 | + event UpdateIntegratorTicketCount(uint32 integratorIndex, uint256 activeTicketCount); |
| 97 | + event UpdateIntegratorPrice(uint32 integratorIndex, uint256 price); |
| 98 | + event UpdateIntegratorName(uint32 integratorIndex, string name); |
| 99 | + event UpdateIntegratorOnCredit(uint32 integratorIndex, bool onCredit); |
| 100 | + |
| 101 | + function fuelToken() external returns (IERC20); |
| 102 | + |
| 103 | + function basicTaxRate() external returns (uint24); |
| 104 | + |
| 105 | + function spentFuel() external returns (uint256, uint256, uint32); |
| 106 | + |
| 107 | + function integratorCount() external returns (uint32); |
| 108 | + |
| 109 | + function topUpIntegrator( |
| 110 | + uint32 _integratorIndex, |
| 111 | + address _sender, |
| 112 | + uint256 _amount, |
| 113 | + uint256 _price |
| 114 | + ) external returns (uint256); |
| 115 | + |
| 116 | + function reserveFuelPrimarySale( |
| 117 | + address _relayerAddress, |
| 118 | + IEventImplementation.TicketAction[] memory _ticketActions |
| 119 | + ) external returns (uint256, uint256); |
| 120 | + |
| 121 | + function reserveFuelSecondarySale( |
| 122 | + address _relayerAddress, |
| 123 | + IEventImplementation.TicketAction[] memory _ticketActions |
| 124 | + ) external returns (uint256, uint256); |
| 125 | + |
| 126 | + function spendBasicAction(address _relayerAddress, uint32 _actionCount) external returns (uint256, uint256); |
| 127 | + |
| 128 | + function spendTicketReserved(address _relayerAddress, uint32 _ticketCount) external returns (uint256, uint256); |
| 129 | + |
| 130 | + function collectSalesTaxFuel() external; |
| 131 | + |
| 132 | + function correctAccountBalance( |
| 133 | + uint32 _integratorIndex, |
| 134 | + uint256 _newAvailableFuel, |
| 135 | + uint256 _newReservedFuel |
| 136 | + ) external; |
| 137 | + |
| 138 | + function setupIntegrator( |
| 139 | + string calldata _name, |
| 140 | + address _relayerAddress, |
| 141 | + DynamicRates calldata _dynamicRates, |
| 142 | + uint256 _price |
| 143 | + ) external; |
| 144 | + |
| 145 | + function activateIntegrator(uint32 _integratorIndex) external; |
| 146 | + |
| 147 | + function disableIntegrator(uint32 _integratorIndex) external; |
| 148 | + |
| 149 | + function addRelayer(address _relayerAddress, uint32 _integratorIndex) external; |
| 150 | + |
| 151 | + function removeRelayer(address _relayerAddress) external; |
| 152 | + |
| 153 | + function setDynamicRates(uint32 _integratorIndex, DynamicRates memory dynamicRates) external; |
| 154 | + |
| 155 | + function setProtocolRates(DynamicRates memory dynamicRates) external; |
| 156 | + |
| 157 | + function setSalesTaxFuelDestination(address _salesTaxFuelDestination) external; |
| 158 | + |
| 159 | + function enableIntegratorBilling(uint32 _integratorIndex) external; |
| 160 | + |
| 161 | + function disableIntegratorBilling(uint32 _integratorIndex) external; |
| 162 | + |
| 163 | + function setBasicTaxRate(uint24 _basicTaxRate) external; |
| 164 | + |
| 165 | + function setSpentFuel(SpentFuel calldata _spentFuel, uint256 _spentFuelOnCredit) external; |
| 166 | + |
| 167 | + function migrateEconomicsData() external returns (IntegratorData[] memory, DynamicRates[] memory); |
| 168 | + |
| 169 | + function emergencyWithdraw(address _asset, address _to, uint256 _amount) external; |
| 170 | + |
| 171 | + function setBillingStatus(uint32 _integratorIndex, bool status) external; |
| 172 | + |
| 173 | + function setConfigurationStatus(uint32 _integratorIndex, bool status) external; |
| 174 | + |
| 175 | + function setIntegratorPrice(uint32 _integratorIndex, uint256 _price) external; |
| 176 | +} |
0 commit comments