Currency and CurrencyLibrary
Currency
is a custom type that represents either native currency (ETH) or ERC20 tokens.
Type Definition
type Currency is address;
Global Functions
equals
function equals(Currency currency, Currency other) pure returns (bool)
Checks if two Currency
values are equal.
Param Name | Type | Description |
---|---|---|
currency | Currency | The first Currency value |
other | Currency | The second Currency value |
Returns true
if the Currency values are equal, false
otherwise.
greaterThan
function greaterThan(Currency currency, Currency other) pure returns (bool)
Compares two Currency
values based on their underlying addresses.
Param Name | Type | Description |
---|---|---|
currency | Currency | The first Currency value |
other | Currency | The second Currency value |
Returns true
if the underlying address of currency
is numerically greater than the underlying address of other
, false
otherwise.
Note: This comparison is based on the numerical value of the addresses and does not imply any inherent ordering or value relationship between different currencies. It's primarily used for consistent ordering in data structures.
lessThan
function lessThan(Currency currency, Currency other) pure returns (bool)
Compares two Currency
values based on their underlying addresses.
Param Name | Type | Description |
---|---|---|
currency | Currency | The first Currency value |
other | Currency | The second Currency value |
Returns true
if the underlying address of currency
is numerically less than the underlying address of other
, false
otherwise.
Note: As with greaterThan
, this comparison is based on address values and does not imply any inherent ordering or value relationship between currencies.
greaterThanOrEqualTo
function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool)
Checks if one Currency
value is greater than or equal to another, based on their underlying addresses.
Param Name | Type | Description |
---|---|---|
currency | Currency | The first Currency value |
other | Currency | The second Currency value |
Returns true
if the underlying address of currency
is numerically greater than or equal to the underlying address of other
, false
otherwise.
CurrencyLibrary
The CurrencyLibrary
provides utility functions for handling both native currency (ETH) and ERC20 tokens.
Constants
Currency public constant NATIVE = Currency.wrap(address(0));
NATIVE
represents the native currency (ETH). It is defined as a Currency
with the underlying address of address(0)
.
Functions
transfer
function transfer(Currency currency, address to, uint256 amount) internal
Transfers amount
of currency
to the to
address.
Param Name | Type | Description |
---|---|---|
currency | Currency | The currency to transfer |
to | address | The recipient address |
amount | uint256 | The amount of currency to transfer |
balanceOfSelf
function balanceOfSelf(Currency currency) internal view returns (uint256)
Returns the balance of currency
held by the contract itself.
Param Name | Type | Description |
---|---|---|
currency | Currency | The currency to check |
Returns the balance of the specified currency.
balanceOf
function balanceOf(Currency currency, address owner) internal view returns (uint256)
Returns the balance of currency
held by the owner
address.
Param Name | Type | Description |
---|---|---|
currency | Currency | The currency to check |
owner | address | The address to check |
Returns the balance of the specified currency for the given address.
isNative
function isNative(Currency currency) internal pure returns (bool)
Checks if the given currency
is the native currency (ETH).
Param Name | Type | Description |
---|---|---|
currency | Currency | The currency to check |
Returns true
if the currency is native (ETH), false
otherwise.
toId
function toId(Currency currency) internal pure returns (uint256)
Converts a Currency
to its corresponding ID.
Param Name | Type | Description |
---|---|---|
currency | Currency | The currency to convert |
Returns the ID of the currency.
fromId
function fromId(uint256 id) internal pure returns (Currency)
Converts an ID to its corresponding Currency
.
Param Name | Type | Description |
---|---|---|
id | uint256 | The ID to convert |
Returns the Currency corresponding to the given ID.