CurrencyConverter

Git Source

Inherits: Base, ICurrencyConverter

This smart contract is responsible for converting between different currencies in a financial ecosystem. It allows for the conversion of USD to another currency (e.g., won) and vice versa, using a specified exchange rate. The main functions include setting the exchange rate, retrieving the current exchange rate and its last update timestamp, converting a specified amount from USD to the target currency, and converting a specified amount from the target currency to USD. This contract works in conjunction with other financial contracts to facilitate currency conversions in a portfolio.

Use decimal 18 for won.

State Variables

WON_DECIMALS

uint256 constant WON_DECIMALS = 18;

EXCHANGE_RATE_DECIMALS

uint256 constant EXCHANGE_RATE_DECIMALS = 2;

usd

IERC20Metadata public usd;

exchangeRate

uint256 public exchangeRate;

updatedTs

uint256 public updatedTs;

Functions

constructor

constructor(
    IProtocolConfig _protocolConfig,
    IERC20Metadata _usd,
    address _manager,
    uint256 _exchangeRate
)
    Base(_protocolConfig.protocolAdmin(), _protocolConfig.pauser());

setExchangeRate

set the exchange rate between WON and USD

the caller is contract keeper

function setExchangeRate(uint256 _exchangeRate) external;

getExchangeRate

get the exchange rate between WON and USD

function getExchangeRate() external view returns (uint256, uint256);

convertFromUSD

constructor guarantees 18 = won decimals >= usd decimals

function convertFromUSD(uint256 usdAmount) external view returns (uint256 wonAmount);

Parameters

NameTypeDescription
usdAmountuint256the amount of USD received

Returns

NameTypeDescription
wonAmountuint256the amount of WON to give

convertToUSD

constructor guarantees 18 = won decimals >= usd decimals

function convertToUSD(uint256 wonAmount) external view returns (uint256 usdAmount);

Parameters

NameTypeDescription
wonAmountuint256the amount of WON received

Returns

NameTypeDescription
usdAmountuint256the amount of USD to give

_setExchangeRate

function _setExchangeRate(uint256 _exchangeRate) internal;