SwapComponent
Inherits: ISwapComponent
Constants
MAX_BPS
Full scale value in basis points.
uint256 private constant MAX_BPS = 10_000;State Variables
_swapperTargets
mapping(uint16 swapperId => SwapperTargets targets) private _swapperTargets;_lastGuardedSwapTimestamp
uint256 private _lastGuardedSwapTimestamp;maxSwapLossBps
Max allowed value loss (in basis points) for token swaps while in FENCED or WALLED mode.
uint256 public maxSwapLossBps;Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
swapCooldownDuration
Cooldown duration (in seconds) for token swaps while in FENCED or WALLED mode.
uint256 public swapCooldownDuration;Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
swapFeeRate
Swap fee rate, 1e18 = 100%.
uint256 public swapFeeRate;Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
Functions
getSwapperTargets
Returns approval and execution targets for a given swapper ID.
function getSwapperTargets(uint16 swapperId)
external
view
returns (address approvalTarget, address executionTarget);Parameters
| Name | Type | Description |
|---|---|---|
| swapperId | uint16 | The swapper ID. |
Returns
| Name | Type | Description |
|---|---|---|
| approvalTarget | address | The approval target. |
| executionTarget | address | The execution target. |
_swap
Internal logic to swap tokens using a given swapper.
function _swap(SwapOrder calldata order, bool guarded) internal returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| order | SwapOrder | |
| guarded | bool |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
_setMaxSwapLossBps
Internal logic to set the maximum allowed relative value loss for token swaps.
function _setMaxSwapLossBps(uint256 newMaxSwapLossBps) internal;Parameters
| Name | Type | Description |
|---|---|---|
| newMaxSwapLossBps | uint256 |
_setSwapCooldownDuration
Internal logic to set the swap cooldown duration.
function _setSwapCooldownDuration(uint256 newSwapCooldownDuration) internal;Parameters
| Name | Type | Description |
|---|---|---|
| newSwapCooldownDuration | uint256 |
_setSwapFeeRate
Internal logic to set the swap fee rate.
function _setSwapFeeRate(uint256 newSwapFeeRate) internal;Parameters
| Name | Type | Description |
|---|---|---|
| newSwapFeeRate | uint256 |
_setSwapperTargets
Internal logic to set approval and execution targets for a given swapper ID.
function _setSwapperTargets(uint16 swapperId, address approvalTarget, address executionTarget) internal;Parameters
| Name | Type | Description |
|---|---|---|
| swapperId | uint16 | |
| approvalTarget | address | |
| executionTarget | address |
_checkAndSetCooldown
Checks cooldown for swaps and updates the last guarded swap timestamp.
function _checkAndSetCooldown() internal;_valueOf
Returns the value of baseTokenAmount of baseToken denominated in quoteToken, using the registered price route.
function _valueOf(address baseToken, address quoteToken, uint256 baseTokenAmount)
internal
view
virtual
returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| baseToken | address | |
| quoteToken | address | |
| baseTokenAmount | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |