forked from Lilly-Protocol/lily-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-61-Lilly-Protocol-lily-contracts.sol
More file actions
54 lines (47 loc) · 2.07 KB
/
Copy pathgithub-61-Lilly-Protocol-lily-contracts.sol
File metadata and controls
54 lines (47 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
contract Payments is Ownable {
// Fee configuration
uint256 public constant FEE_PRECISION = 10000; // 4 decimal places (e.g., 100 = 1%)
uint256 public fixedFee; // in wei
uint256 public variableFeeBasisPoints; // basis points (e.g., 250 = 2.5%)
constructor(uint256 _fixedFee, uint256 _variableFeeBasisPoints) Ownable(msg.sender) {
fixedFee = _fixedFee;
variableFeeBasisPoints = _variableFeeBasisPoints;
}
/**
* @notice Calculates the total fee for a given amount
* @param amount The transaction amount in wei
* @return totalFee The total fee in wei (fixed + variable)
*/
function quoteFee(uint256 amount) external view returns (uint256 totalFee) {
uint256 variableComponent = (amount * variableFeeBasisPoints) / FEE_PRECISION;
totalFee = fixedFee + variableComponent;
}
/**
* @notice Returns the breakdown of fees for a given amount
* @param amount The transaction amount in wei
* @return fixed The fixed fee component in wei
* @return variable The variable fee component in wei
*/
function getFeeBreakdown(uint256 amount) external view returns (uint256 fixed, uint256 variable) {
fixed = fixedFee;
variable = (amount * variableFeeBasisPoints) / FEE_PRECISION;
}
/**
* @notice Calculates the net amount received after fees for a given gross amount
* @param amount The gross transaction amount in wei
* @return netAmount The amount after deducting fees in wei
*/
function quoteNetAmount(uint256 amount) external view returns (uint256 netAmount) {
uint256 totalFee = quoteFee(amount);
require(amount >= totalFee, "Amount too low for fees");
netAmount = amount - totalFee;
}
// Update fee configuration (owner-only)
function setFees(uint256 _fixedFee, uint256 _variableFeeBasisPoints) external onlyOwner {
fixedFee = _fixedFee;
variableFeeBasisPoints = _variableFeeBasisPoints;
}
}