Skip to content

Commit

Permalink
[FEA-792] added multiplier (#127)
Browse files Browse the repository at this point in the history
* added multiplier for flightclass
  • Loading branch information
Purva-Chaudhari authored Dec 19, 2024
1 parent d0fb773 commit 18e9346
Showing 1 changed file with 63 additions and 4 deletions.
67 changes: 63 additions & 4 deletions plume/src/Faucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ contract Faucet is Initializable, UUPSUpgradeable {
/// @notice Indicates a failure because the address is invalid
error InvalidAddress();

/// @notice Indicates a failure because the flightClass is invalid
error InvalidFlightClass(uint256 flightClass);

/**
* @notice Indicates a failure because the sender is not authorized to perform the action
* @param sender Address of the sender that is not authorized
Expand Down Expand Up @@ -187,6 +190,7 @@ contract Faucet is Initializable, UUPSUpgradeable {
/**
* @notice Get tokens from the faucet
* @param token Name of the token requested
* @param flightClass User's flight class
* @param salt Random value to prevent replay attacks
* @param signature Signature of the message signed by the owner
*/
Expand All @@ -198,11 +202,14 @@ contract Faucet is Initializable, UUPSUpgradeable {
) external onlySignedByOwner(token, flightClass, salt, signature) {
FaucetStorage storage $ = _getFaucetStorage();
address tokenAddress = $.tokens[token];
uint256 amount = $.dripAmounts[tokenAddress];
if (tokenAddress == address(0) || amount == 0) {
uint256 baseAmount = $.dripAmounts[tokenAddress];

if (tokenAddress == address(0) || baseAmount == 0) {
revert InvalidToken();
}

uint256 amount = _calculateDripAmount(baseAmount, flightClass);

if (tokenAddress == ETH_ADDRESS) {
if (address(this).balance < amount) {
revert InsufficientBalance(amount, token);
Expand Down Expand Up @@ -253,6 +260,40 @@ contract Faucet is Initializable, UUPSUpgradeable {
emit Withdrawn(recipient, amount, token);
}

/**
* @notice Calculate the amount of tokens to mint based on the base amount and flight class
* @dev Internal function to calculate the drip amount based on the flight class multiplier
* Flight classes correspond to:
* - Class 1: Economy
* - Class 2: Plus
* - Class 3: Premium
* - Class 4: Business
* - Class 5: First
* - Class 6: Private
* @param baseAmount Base amount of tokens to mint
* @param flightClass User flight class
*/
function _calculateDripAmount(uint256 baseAmount, uint256 flightClass) internal pure returns (uint256) {
uint256 multiplier;
if (flightClass == 1) {
multiplier = 1; // 1x
} else if (flightClass == 2) {
multiplier = 11; // 1.1x (scaled by 10)
} else if (flightClass == 3) {
multiplier = 125; // 1.25x (scaled by 100)
} else if (flightClass == 4) {
multiplier = 200; // 2x (scaled by 100)
} else if (flightClass == 5) {
multiplier = 300; // 3x (scaled by 100)
} else if (flightClass == 6) {
multiplier = 500; // 5x (scaled by 100)
} else {
revert InvalidFlightClass(flightClass);
}

return (baseAmount * multiplier) / 100; // Normalize for scaling
}

/**
* @notice Set ownership of the faucet contract to the given address
* @dev Only the owner can call this function
Expand Down Expand Up @@ -302,9 +343,9 @@ contract Faucet is Initializable, UUPSUpgradeable {
}

/**
* @notice Get the amount of tokens to mint per faucet call for the given token
* @notice Get the base amount of tokens to mint per faucet call for the given token
* @param token Name of the token to get the amount for
* @return dripAmount Amount of tokens to mint per faucet call
* @return dripAmount Base amount of tokens to mint per faucet call
*/
function getDripAmount(
string calldata token
Expand All @@ -313,6 +354,24 @@ contract Faucet is Initializable, UUPSUpgradeable {
return $.dripAmounts[$.tokens[token]];
}

/**
* @notice Get the amount of tokens to mint per user call for the given token
* @param token Name of the token to get the amount for
* @param flightClass User's flight class
* @return dripAmount Amount of tokens to mint per faucet call
*/
function getDripAmount(string calldata token, uint256 flightClass) public view returns (uint256 dripAmount) {
FaucetStorage storage $ = _getFaucetStorage();
address tokenAddress = $.tokens[token];
uint256 baseAmount = $.dripAmounts[tokenAddress];

if (tokenAddress == address(0) || baseAmount == 0) {
revert InvalidToken();
}

return _calculateDripAmount(baseAmount, flightClass);
}

/**
* @notice Get the address of the given token
* @param token Name of the token to get the address for
Expand Down

0 comments on commit 18e9346

Please sign in to comment.