IFrictionlessFXSwap

Git Source

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

function setFXDeskFeeAddr(address newFXDeskFeeAddr_) external;

Parameters

NameTypeDescription

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).

function setSwapFees(
    FrictionlessTokenFXFeeInfo calldata token0FeeInfo_,
    FrictionlessTokenFXFeeInfo calldata token1FeeInfo_
) external;

Parameters

NameTypeDescription

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).

function setTokenFee(bytes32 tokenFeeKey_, FrictionlessTokenFXFeeInfo calldata tokenFeeInfo_) external;

Parameters

NameTypeDescription

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

function swapTokens(
    address sellingTokenAddr_,
    address buyingTokenAddr_,
    address tokenSender_,
    address tokenRecipient_,
    uint256 buyingTokensAmount_,
    uint256 buyingTokenExchangeRate_
) external;

Parameters

NameTypeDescription

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

function fxDeskFeeAddr() external view returns (address);

Returns

NameTypeDescription

<none>

address

The address of the FXDesk fee recipient

treasuryManager

Retrieves the Frictionless Treasury Manager contract

function treasuryManager() external view returns (IFrictionlessTreasuryManager);

Returns

NameTypeDescription

<none>

IFrictionlessTreasuryManager

The address of the Frictionless Treasury Manager contract

permissionManager

Retrieves the Frictionless Permissions Manager contract

function permissionManager() external view returns (IFrictionlessPermissionsManager);

Returns

NameTypeDescription

<none>

IFrictionlessPermissionsManager

The address of the Frictionless Permissions Manager contract

getSwapFeesInfo

get the tokenFeeInfo set for the fees associated per token in an exchange.

function getSwapFeesInfo(address token0_, address token1_) external view returns (FeeInfo memory, FeeInfo memory);

Parameters

NameTypeDescription

token0_

address

the address of the first token in an exchange

token1_

address

the address of the second token in an exchange

Returns

NameTypeDescription

<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.

function getSwapFeeKeys(address token0_, address token1_) external view returns (bytes32, bytes32);

Parameters

NameTypeDescription

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

NameTypeDescription

<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.

function getTokenFeeKey(address token0_, address token1_) external view returns (bytes32);

Parameters

NameTypeDescription

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

NameTypeDescription

<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

function getSellingTokensAmount(uint256 buyingTokensAmount_, uint256 buyingTokenExchangeRate_)
    external
    view
    returns (uint256);

Parameters

NameTypeDescription

buyingTokensAmount_

uint256

The amount of tokens being bought

buyingTokenExchangeRate_

uint256

The exchange rate of the token being bought to the token being sold

Returns

NameTypeDescription

<none>

uint256

The amount of selling tokens

Events

FrictionlessFXTokensSwapped

Event emitted upon successful token swaps

event FrictionlessFXTokensSwapped(
    address sellingTokenAddr,
    address buyingTokenAddr,
    address tokenSender,
    address tokenRecipient,
    uint256 sellingTokensAmount,
    uint256 buyingTokensAmount,
    uint256 buyingTokenExchangeRate
);

Errors

FrictionlessFXSwapInvalidTokenAddresses

error thrown during setSwapFees if token adresses are invalid (zero addresses, equals addresses and etc.).

error FrictionlessFXSwapInvalidTokenAddresses(address token0, address token1);

FrictionlessFXSwapInvalidFeeRecipientAddr

error thrown during setSwapFees, setTokenFee and swapTokens if the fxDeskFeeRecipient doesn't equal to the stored fxDeskFeeAddr

error FrictionlessFXSwapInvalidFeeRecipientAddr(address newFeeRecipient);

FrictionlessFXSwapNotEnoughPermissions

error thrown during swapTokens if the msg.sender is not a PROTOCOL_TREASURY.

error FrictionlessFXSwapNotEnoughPermissions();

Structs

FrictionlessTokenFXFeeInfo

Structure representing token fee information including the token address and fee information

struct FrictionlessTokenFXFeeInfo {
    address tokenAddr;
    uint256 feeAbsoluteLimit;
    FeeInfo feeInfo;
}
Logo

Copyright © 2024 Frictionless Markets S.à.r.l