tempo_contracts/precompiles/
tip_fee_manager.rs1pub use IFeeManager::{IFeeManagerErrors as FeeManagerError, IFeeManagerEvents as FeeManagerEvent};
2pub use ITIPFeeAMM::{ITIPFeeAMMErrors as TIPFeeAMMError, ITIPFeeAMMEvents as TIPFeeAMMEvent};
3
4use alloy::sol;
5
6sol! {
7 #[derive(Debug, PartialEq, Eq)]
20 #[sol(rpc, abi)]
21 interface IFeeManager {
22 struct FeeInfo {
24 uint128 amount;
25 bool hasBeenSet;
26 }
27
28 function userTokens(address user) external view returns (address);
30 function validatorTokens(address validator) external view returns (address);
31 function setUserToken(address token) external;
32 function setValidatorToken(address token) external;
33
34 function getFeeTokenBalance(address sender, address validator) external view returns (address, uint256);
36 function executeBlock() external;
37 event UserTokenSet(address indexed user, address indexed token);
42 event ValidatorTokenSet(address indexed validator, address indexed token);
43
44 error OnlyValidator();
46 error OnlySystemContract();
47 error InvalidToken();
48 error PoolDoesNotExist();
49 error InsufficientFeeTokenBalance();
50 error InternalError();
51 error CannotChangeWithinBlock();
52 error CannotChangeWithPendingFees();
53 error TokenPolicyForbids();
54 }
55
56 #[derive(Debug, PartialEq, Eq)]
63 #[sol(rpc)]
64 #[allow(clippy::too_many_arguments)]
65 interface ITIPFeeAMM {
66 struct Pool {
68 uint128 reserveUserToken;
69 uint128 reserveValidatorToken;
70 }
71
72 struct PoolKey {
73 address token0;
74 address token1;
75 }
76
77
78 function M() external view returns (uint256);
80 function N() external view returns (uint256);
81 function SCALE() external view returns (uint256);
82 function MIN_LIQUIDITY() external view returns (uint256);
83
84 function getPoolId(address userToken, address validatorToken) external pure returns (bytes32);
86 function getPool(address userToken, address validatorToken) external view returns (Pool memory);
87 function pools(bytes32 poolId) external view returns (Pool memory);
88
89 function mint(address userToken, address validatorToken, uint256 amountUserToken, uint256 amountValidatorToken, address to) external returns (uint256 liquidity);
91 function mintWithValidatorToken(address userToken, address validatorToken, uint256 amountValidatorToken, address to) external returns (uint256 liquidity);
92 function burn(address userToken, address validatorToken, uint256 liquidity, address to) external returns (uint256 amountUserToken, uint256 amountValidatorToken);
93
94 function totalSupply(bytes32 poolId) external view returns (uint256);
96 function liquidityBalances(bytes32 poolId, address user) external view returns (uint256);
97
98 function rebalanceSwap(address userToken, address validatorToken, uint256 amountOut, address to) external returns (uint256 amountIn);
100
101 event Mint(address indexed sender, address indexed userToken, address indexed validatorToken, uint256 amountUserToken, uint256 amountValidatorToken, uint256 liquidity);
103 event Burn(address indexed sender, address indexed userToken, address indexed validatorToken, uint256 amountUserToken, uint256 amountValidatorToken, uint256 liquidity, address to);
104 event RebalanceSwap(address indexed userToken, address indexed validatorToken, address indexed swapper, uint256 amountIn, uint256 amountOut);
105 event FeeSwap(
106 address indexed userToken,
107 address indexed validatorToken,
108 uint256 amountIn,
109 uint256 amountOut
110 );
111
112 error IdenticalAddresses();
114 error ZeroAddress();
115 error PoolExists();
116 error PoolDoesNotExist();
117 error InvalidToken();
118 error InsufficientLiquidity();
119 error OnlyProtocol();
120 error InsufficientPoolBalance();
121 error InsufficientReserves();
122 error InsufficientLiquidityBalance();
123 error MustDepositLowerBalanceToken();
124 error InvalidAmount();
125 error InvalidRebalanceState();
126 error InvalidRebalanceDirection();
127 error InvalidNewReserves();
128 error CannotSupportPendingSwaps();
129 error DivisionByZero();
130 error InvalidSwapCalculation();
131 error InsufficientLiquidityForPending();
132 error TokenTransferFailed();
133 error InternalError();
134 }
135}
136
137impl FeeManagerError {
138 pub const fn only_validator() -> Self {
140 Self::OnlyValidator(IFeeManager::OnlyValidator {})
141 }
142
143 pub const fn only_system_contract() -> Self {
145 Self::OnlySystemContract(IFeeManager::OnlySystemContract {})
146 }
147
148 pub const fn invalid_token() -> Self {
150 Self::InvalidToken(IFeeManager::InvalidToken {})
151 }
152
153 pub const fn pool_does_not_exist() -> Self {
155 Self::PoolDoesNotExist(IFeeManager::PoolDoesNotExist {})
156 }
157
158 pub const fn insufficient_fee_token_balance() -> Self {
160 Self::InsufficientFeeTokenBalance(IFeeManager::InsufficientFeeTokenBalance {})
161 }
162
163 pub const fn internal_error() -> Self {
165 Self::InternalError(IFeeManager::InternalError {})
166 }
167
168 pub const fn cannot_change_within_block() -> Self {
170 Self::CannotChangeWithinBlock(IFeeManager::CannotChangeWithinBlock {})
171 }
172
173 pub const fn cannot_change_with_pending_fees() -> Self {
175 Self::CannotChangeWithPendingFees(IFeeManager::CannotChangeWithPendingFees {})
176 }
177
178 pub const fn token_policy_forbids() -> Self {
180 Self::TokenPolicyForbids(IFeeManager::TokenPolicyForbids {})
181 }
182}
183
184impl TIPFeeAMMError {
185 pub const fn identical_addresses() -> Self {
187 Self::IdenticalAddresses(ITIPFeeAMM::IdenticalAddresses {})
188 }
189
190 pub const fn zero_address() -> Self {
192 Self::ZeroAddress(ITIPFeeAMM::ZeroAddress {})
193 }
194
195 pub const fn pool_exists() -> Self {
197 Self::PoolExists(ITIPFeeAMM::PoolExists {})
198 }
199
200 pub const fn pool_does_not_exist() -> Self {
202 Self::PoolDoesNotExist(ITIPFeeAMM::PoolDoesNotExist {})
203 }
204
205 pub const fn invalid_token() -> Self {
207 Self::InvalidToken(ITIPFeeAMM::InvalidToken {})
208 }
209
210 pub const fn insufficient_liquidity() -> Self {
212 Self::InsufficientLiquidity(ITIPFeeAMM::InsufficientLiquidity {})
213 }
214
215 pub const fn insufficient_pool_balance() -> Self {
217 Self::InsufficientPoolBalance(ITIPFeeAMM::InsufficientPoolBalance {})
218 }
219
220 pub const fn insufficient_reserves() -> Self {
222 Self::InsufficientReserves(ITIPFeeAMM::InsufficientReserves {})
223 }
224
225 pub const fn insufficient_liquidity_balance() -> Self {
227 Self::InsufficientLiquidityBalance(ITIPFeeAMM::InsufficientLiquidityBalance {})
228 }
229
230 pub const fn must_deposit_lower_balance_token() -> Self {
232 Self::MustDepositLowerBalanceToken(ITIPFeeAMM::MustDepositLowerBalanceToken {})
233 }
234
235 pub const fn invalid_amount() -> Self {
237 Self::InvalidAmount(ITIPFeeAMM::InvalidAmount {})
238 }
239
240 pub const fn token_transfer_failed() -> Self {
242 Self::TokenTransferFailed(ITIPFeeAMM::TokenTransferFailed {})
243 }
244
245 pub const fn invalid_swap_calculation() -> Self {
247 Self::InvalidSwapCalculation(ITIPFeeAMM::InvalidSwapCalculation {})
248 }
249
250 pub const fn insufficient_liquidity_for_pending() -> Self {
252 Self::InsufficientLiquidityForPending(ITIPFeeAMM::InsufficientLiquidityForPending {})
253 }
254
255 pub const fn division_by_zero() -> Self {
257 Self::DivisionByZero(ITIPFeeAMM::DivisionByZero {})
258 }
259
260 pub const fn invalid_new_reserves() -> Self {
262 Self::InvalidNewReserves(ITIPFeeAMM::InvalidNewReserves {})
263 }
264
265 pub const fn internal_error() -> Self {
267 Self::InternalError(ITIPFeeAMM::InternalError {})
268 }
269}