Skip to content

Commit ed61b97

Browse files
committed
feat: view function for slippage
1 parent a27dcd1 commit ed61b97

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/interfaces/Utils/IAutoSwapperWusdnSdex.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ interface IAutoSwapperWusdnSdex {
3232
*/
3333
function sweep(address token, address to, uint256 amount) external;
3434

35+
/**
36+
* @notice Get the current swap slippage setting (in basis points)
37+
* @return Current slippage tolerance
38+
*/
39+
function getSwapSlippage() external view returns (uint256);
40+
3541
/**
3642
* @notice Updates the allowed slippage percentage for swaps.
3743
* @param swapSlippage The new slippage value (in basis points).

src/utils/AutoSwapperWusdnSdex.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ISmardexPair } from "@smardex-dex-contracts/contracts/ethereum/core/v2/
99
import { ISmardexSwapCallback } from
1010
"@smardex-dex-contracts/contracts/ethereum/core/v2/interfaces/ISmardexSwapCallback.sol";
1111
import { SmardexLibrary } from "@smardex-dex-contracts/contracts/ethereum/core/v2/libraries/SmardexLibrary.sol";
12+
import { FixedPointMathLib } from "solady/src/utils/FixedPointMathLib.sol";
1213

1314
import { IFeeCollectorCallback } from "./../interfaces/UsdnProtocol/IFeeCollectorCallback.sol";
1415
import { IAutoSwapperWusdnSdex } from "./../interfaces/Utils/IAutoSwapperWusdnSdex.sol";
@@ -36,10 +37,10 @@ contract AutoSwapperWusdnSdex is
3637
ISmardexPair internal constant SMARDEX_WUSDN_SDEX_PAIR = ISmardexPair(0x11443f5B134c37903705e64129BEFc20e35a3725);
3738

3839
/// @notice Fee rates for LP on the SmarDex pair.
39-
uint128 immutable FEE_LP;
40+
uint128 internal immutable FEE_LP;
4041

4142
/// @notice Fee rates for the pool on the SmarDex pair.
42-
uint128 immutable FEE_POOL;
43+
uint128 internal immutable FEE_POOL;
4344

4445
/// @notice Allowed slippage for swaps (in basis points).
4546
uint256 internal _swapSlippage = 100; // 1%
@@ -61,7 +62,7 @@ contract AutoSwapperWusdnSdex is
6162
uint256 wusdnAmount = WUSDN.balanceOf(address(this));
6263

6364
uint256 quoteAmountSdexOut = _quoteAmountOut(wusdnAmount);
64-
uint256 minSdexAmount = quoteAmountSdexOut * (BPS_DIVISOR - _swapSlippage) / BPS_DIVISOR;
65+
uint256 minSdexAmount = FixedPointMathLib.mulDiv(quoteAmountSdexOut, BPS_DIVISOR - _swapSlippage, BPS_DIVISOR);
6566
(int256 amountSdexOut,) = SMARDEX_WUSDN_SDEX_PAIR.swap(address(0xdead), false, int256(wusdnAmount), "");
6667

6768
if (uint256(-amountSdexOut) < minSdexAmount) {
@@ -83,6 +84,11 @@ contract AutoSwapperWusdnSdex is
8384
IERC20(token).safeTransfer(to, amount);
8485
}
8586

87+
/// @inheritdoc IAutoSwapperWusdnSdex
88+
function getSwapSlippage() external view returns (uint256) {
89+
return _swapSlippage;
90+
}
91+
8692
/// @inheritdoc IAutoSwapperWusdnSdex
8793
function updateSwapSlippage(uint256 newSwapSlippage) external onlyOwner {
8894
if (newSwapSlippage == 0) {

0 commit comments

Comments
 (0)