LibAsset
Last updated
Last updated
The LibAsset
library provides a convenient interface for interacting with different types of assets in Solidity, whether they are native assets or ERC20 tokens.
This function checks if the given address (self
) represents a native asset (Ether). It returns true
if the address is the native asset ID (0x0).
Input:
Field | Type | Description |
---|---|---|
Output:
Field | Type | Description |
---|---|---|
This function retrieves the balance of the current contract for a given asset (self
). If the asset is a native asset, it returns the Ether balance of the contract. Otherwise, it uses the ERC20 balanceOf
function to fetch the token balance.
Input:
Field | Type | Description |
---|---|---|
Output:
Field | Type | Description |
---|---|---|
Retrieves the balance of the target address for a given asset (self).
Input:
Output:
This function performs a safeTransferFrom
operation for a given asset (self
) from one address (from
) to another address (to
). It uses the SafeERC20
library to ensure safe token transfers.
Input:
This function performs a transfer of a given amount of an asset (self
) to a recipient address (recipient
). If the asset is a native asset, it uses Address.sendValue
to send Ether. Otherwise, it uses the ERC20 safeTransfer
function.
Input:
This function approves a spender address (spender
) to spend a specified amount of an asset (self
). It uses the SafeERC20
library's forceApprove
function.
Input:
This function allows for the deposit of a specified amount of an asset (self
). If the asset is a native asset, it checks if the received Ether amount is sufficient and then converts it to the wrapped Ether token (weth
) using the IWETH
interface's deposit
function. Otherwise, it performs a safeTransferFrom
operation to transfer the asset from the sender address to the current contract.
Input:
This function retrieves the allowance amount that a spender address (spender
) is approved to spend from an owner address (owner
) for a given asset (self
). It uses the ERC20 allowance
function.
Input:
Output:
This function allows for the withdrawal of a specified amount of an asset (self
) to a designated address (to
). If the asset is a native asset, it uses the IWETH
interface's withdraw
function to convert the wrapped Ether token back to Ether. Then, it performs a transfer of the native asset to the specified address. If the asset is an ERC20 token, it performs a transfer of the token to the specified address.
Input:
This function retrieves the decimal precision of an ERC20 token. If the asset is a native asset, it defaults to 18 decimal places. Otherwise, it uses the decimals
function of the ERC20 token to fetch the decimal precision.
Input:
Output:
Determines if a call was successful.
Input:
Output:
Executes a low level call.
Input:
Output:
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
The asset that will be checked for a native token.
Flag to identify if the asset is native or not.
Asset whose balance needs to be found
Balance of the asset
Asset whose balance needs to be found.
The address where the balance is checked from.
Balance of the specific asset.
Asset that will be transferred
address that will send the asset
address that will receive the transferred asset
amount of an asset that will be transferred
Asset that will be transferred
address that will receive the transferred asset
amount of an asset that will be transferred
The asset that will be approved.
Address of a contract that will use the owners asset.
Asset amount that can be spent.
Address of the asset that will be deposited
Address of the Wrapped Ether (WETH) contract.
Depositing amount
The asset whose allowance will be granted to the spender.
Address of the owner who owns the asset.
Address of a contract that will use the owners allowance.
The allowed amount
The asset that will be withdrawn
Address of the Wrapped Ether (WETH) contract.
Address that will receive withdrawn token.
Amount that needs to be withdrawn
The asset address whose decimals we are finding.
The decimals of the asset address
Address of the target contract.
To check if the call to the contract was successful or not.
The data was sent while calling the target contract.
The success of the call.
The address of the contract to which the call is being made.
The parameters or data to be sent in the call.
The success of the call.