Skip to content

Commit

Permalink
interface added
Browse files Browse the repository at this point in the history
  • Loading branch information
pahor167 committed Jan 29, 2024
1 parent 7671925 commit 71796da
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 30 deletions.
64 changes: 34 additions & 30 deletions packages/protocol/contracts-0.8/stability/FeeCurrencyAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import "../../contracts/common/FixidityLib.sol";
import "../../contracts/stability/interfaces/ISortedOracles.sol";
import "./interfaces/IFeeCurrency.sol";
import "./interfaces/IDecimals.sol";
import "./interfaces/IFeeCurrencyAdapter.sol";

contract FeeCurrencyAdapter is Initializable, CalledByVm {
contract FeeCurrencyAdapter is Initializable, CalledByVm, IFeeCurrencyAdapter {
IFeeCurrency public adaptedToken;

uint96 public digitDifference;
Expand Down Expand Up @@ -46,37 +47,15 @@ contract FeeCurrencyAdapter is Initializable, CalledByVm {
_setAdaptedToken(_adaptedToken);
name = _name;
symbol = _symbol;
uint8 decimals = IDecimals(_adaptedToken).decimals();
require(decimals < _expectedDecimals, "Decimals of adapted token must be < expected decimals.");
digitDifference = uint96(10**(_expectedDecimals - decimals));
uint8 _decimals = IDecimals(_adaptedToken).decimals();
require(
_decimals < _expectedDecimals,
"Decimals of adapted token must be < expected decimals."
);
digitDifference = uint96(10**(_expectedDecimals - _decimals));
expectedDecimals = _expectedDecimals;
}

/**
* @notice Gets the balance of the specified address with correct digits.
* @param account The address to query the balance of.
* @return The balance of the specified address.
*/
function balanceOf(address account) public view returns (uint256) {
return upscale(adaptedToken.balanceOf(account));
}

/**
* @notice Gets the total supply with correct digits.
* @return The total supply.
*/
function totalSupply() public view returns (uint256) {
return upscale(adaptedToken.totalSupply());
}

/**
* @notice Gets the total supply with correct digits.
* @return The total supply.
*/
function decimals() public view returns (uint8) {
return expectedDecimals;
}

/**
* Downscales value to the adapted token's native digits and debits it.
* @param from from address
Expand Down Expand Up @@ -108,7 +87,7 @@ contract FeeCurrencyAdapter is Initializable, CalledByVm {
uint256 tipAmount,
uint256 _gatewayFeeAmount,
uint256 baseFeeAmount
) public onlyVm {
) external onlyVm {
if (debited == 0) {
// When eth.estimateGas is called, this function is called but we don't want to credit anything.
return;
Expand Down Expand Up @@ -150,6 +129,31 @@ contract FeeCurrencyAdapter is Initializable, CalledByVm {
return address(adaptedToken);
}

/**
* @notice Gets the balance of the specified address with correct digits.
* @param account The address to query the balance of.
* @return The balance of the specified address.
*/
function balanceOf(address account) external view returns (uint256) {
return upscale(adaptedToken.balanceOf(account));
}

/**
* @notice Gets the total supply with correct digits.
* @return The total supply.
*/
function totalSupply() external view returns (uint256) {
return upscale(adaptedToken.totalSupply());
}

/**
* @notice Gets the total supply with correct digits.
* @return The total supply.
*/
function decimals() external view returns (uint8) {
return expectedDecimals;
}

function upscale(uint256 value) internal view returns (uint256) {
return value * digitDifference;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.7 <0.8.20;

interface IFeeCurrencyAdapter {
function getAdaptedToken() external view returns (address);

function digitDifference() external view returns (uint96);

function debited() external view returns (uint256);

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function expectedDecimals() external view returns (uint8);

function decimals() external view returns (uint8);

function debitGasFees(address from, uint256 value) external;

function creditGasFees(
address refundRecipient,
address tipRecipient,
address _gatewayFeeRecipient,
address baseFeeRecipient,
uint256 refundAmount,
uint256 tipAmount,
uint256 _gatewayFeeAmount,
uint256 baseFeeAmount
) external;
}

0 comments on commit 71796da

Please sign in to comment.