IFrictionlessFXSwap
Inherits: IAbstractFeeModule
Author: DEFYCA Labs S.à.r.l
Copyright © 2023 DEFYCA Labs S.à.r.l Permission is hereby granted, free of charge, to any person obtaining a copy of the Frictionless protocol smart contracts (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL DEFYCA LABS S.à.r.l BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Interface defining the frictionless conversion and atomic swapping of any FrictionlessFundDepositToken
currency pair on the Frictionless protocol. The FX rates are set from the live spot & forward FX partners on the protocol.
Functions
setFXDeskFeeAddr
Sets the address of the FXDesk fee recipient Only Owner (PROTOCOL_ADMIN) can call this function
Parameters
newFXDeskFeeAddr_
address
The new address of the FXDesk fee recipient
setSwapFees
Set the swap fees for the swaps of a token pair. The fees can be any combination of zero (0%) or upto 10000 bps (100%) on any directional transfer. Fees can only be set by the Owner (PROTOCOL_ADMIN).
Parameters
token0FeeInfo_
FrictionlessTokenFXFeeInfo
The fees associated with the token0 (first token) in the token pair during the swap.
token1FeeInfo_
FrictionlessTokenFXFeeInfo
The fees associated with the token1 (second token) in the token pair during the swap. throws FrictionlessFXSwapInvalidTokenAddresses
if the token addresses are invalid. throws FrictionlessFXSwapInvalidFeeRecipientAddr
if the feeRecipientAddr doesn't equal to the fxDeskFeeAddr
. throws AbstractFeeModuleInvalidFeeRecipient
if the feeRecipientAddr is a zero address throws AbstractFeeModuleInvalidFee
if the feeInBps is not in the valid range (ZERO_FEES_IN_BPS to MAX_FEES_IN_BPS) emits FrictionlessFeeSet
upon completion of the setting of the fee info for the token in either set of fees
setTokenFee
Set the fee associated with the swap of a Token and manages the mapping of the key to this set of Fees. Can only be set by the Owner (PROTOCOL_ADMIN).
Parameters
tokenFeeKey_
bytes32
The key, generated by the function getTokenFeeKey
, which is used to map a specific swap polarity for tokens.
tokenFeeInfo_
FrictionlessTokenFXFeeInfo
The fees associated with the swap of token, used in the calculation and disbursement of fees during swap of a token pair. throws FrictionlessFXSwapInvalidTokenAddresses
if the token addresses are invalid. throws FrictionlessFXSwapInvalidFeeRecipientAddr
if the feeRecipientAddr doesn't equal to the fxDeskFeeAddr
. throws AbstractFeeModuleInvalidFeeRecipient
if the feeRecipientAddr is a zero address throws AbstractFeeModuleInvalidFee
if the feeInBps is not in the valid range (ZERO_FEES_IN_BPS to MAX_FEES_IN_BPS) emits FrictionlessTokenFeeSet
upon completion of the setting of the fee info for the token
swapTokens
Swaps tokens between addresses at a specified exchange rate Only PROTOCOL_TREASURY can call this function
Parameters
sellingTokenAddr_
address
The address of the token to be sold
buyingTokenAddr_
address
The address of the token to be bought
tokenSender_
address
The address of the sender initiating the swap
tokenRecipient_
address
The address where the bought tokens will be sent
buyingTokensAmount_
uint256
The amount of tokens being bought
buyingTokenExchangeRate_
uint256
The exchange rate of the token being bought to the token being sold
fxDeskFeeAddr
Retrieves the address of the FXDesk fee recipient
Returns
<none>
address
The address of the FXDesk fee recipient
treasuryManager
Retrieves the Frictionless Treasury Manager contract
Returns
<none>
IFrictionlessTreasuryManager
The address of the Frictionless Treasury Manager contract
permissionManager
Retrieves the Frictionless Permissions Manager contract
Returns
<none>
IFrictionlessPermissionsManager
The address of the Frictionless Permissions Manager contract
getSwapFeesInfo
get the tokenFeeInfo set for the fees associated per token in an exchange.
Parameters
token0_
address
the address of the first token in an exchange
token1_
address
the address of the second token in an exchange
Returns
<none>
FeeInfo
FeeInfo set for the fees associated per token in an exchange.
<none>
FeeInfo
getSwapFeeKeys
Generates keys based on the packed encoding of the addresses of sets of tokens using the keccak256 hashing function. Used to store tokenFees in mappings.
Parameters
token0_
address
the address of the token 0 in a transfer fee calculation
token1_
address
the address of the token 1 in a transfer fee calculation
Returns
<none>
bytes32
keys based on the packed encoding of the addresses of sets of tokens using the keccak256 hashing function.
<none>
bytes32
getTokenFeeKey
Generates a key based on the packed encoding of the addresses of both tokens using the keccak256 hashing function. Used to store tokenFees in mappings.
Parameters
token0_
address
the address of the token 0 in a transfer fee calculation
token1_
address
the address of the token 1 in a transfer fee calculation
Returns
<none>
bytes32
generates a key based on the packed encoding of the addresses of both tokens using the keccak256 hashing function.
getSellingTokensAmount
Calculates the amount of selling tokens based on the buying amount and exchange rate
Parameters
buyingTokensAmount_
uint256
The amount of tokens being bought
buyingTokenExchangeRate_
uint256
The exchange rate of the token being bought to the token being sold
Returns
<none>
uint256
The amount of selling tokens
Events
FrictionlessFXTokensSwapped
Event emitted upon successful token swaps
Errors
FrictionlessFXSwapInvalidTokenAddresses
error thrown during setSwapFees
if token adresses are invalid (zero addresses, equals addresses and etc.).
FrictionlessFXSwapInvalidFeeRecipientAddr
error thrown during setSwapFees
, setTokenFee
and swapTokens
if the fxDeskFeeRecipient doesn't equal to the stored fxDeskFeeAddr
FrictionlessFXSwapNotEnoughPermissions
error thrown during swapTokens
if the msg.sender is not a PROTOCOL_TREASURY.
Structs
FrictionlessTokenFXFeeInfo
Structure representing token fee information including the token address and fee information