Mean Finance
Search…
Next Swap

Time Until Next Swap

As we explained before, all positions have a swap interval that determines when they can be swapped. So it could happen that at some point, a pair has no swaps to execute. If that is the case, trying to execute swap would end up reverting. That's why you should check when the next swap will be available.
You can call secondsUntilNextSwap , that returns the amount of seconds until the next swap is available.
1
pragma solidity 0.8.6;
2
3
import '@mean-finance/dca-v1/contracts/interfaces/IDCAPair.sol';
4
5
contract MyContract {
6
7
IDCAPair public immutable pair;
8
9
constructor(IDCAPair _pair) {
10
pair = _pair;
11
}
12
13
function secondsUntilNextSwap() external view returns (uint32) {
14
return pair.secondsUntilNextSwap();
15
}
16
17
}
Copied!

Next Swap's Information

When secondsUntilNextSwap returns 0, that means that you can execute a swap right now. If that's the case, you can call getNextSwapInfo to get all information regarding this swap, and determine if you want to execute it.
IfsecondsUntilNextSwapis not 0, you can still callgetNextSwapInfo, but the result will be zero-ed and meaningless.

The Result

When calling getNextSwapInfo, you will get a struct as a result with quite a few properties. The most important for you as a swapper are:
1
struct NextSwapInformation {
2
uint256 availableToBorrowTokenA; // How much is available for borrowing in token A
3
uint256 availableToBorrowTokenB; // How much is available for borrowing in token B
4
uint256 amountToBeProvidedBySwapper; // How much must be provided by the swapper before the end of the transaction
5
uint256 amountToRewardSwapperWith; // How much is the reward for calling swap and providing the needed liquidity
6
IERC20Metadata tokenToBeProvidedBySwapper; // The token that must be provided
7
IERC20Metadata tokenToRewardSwapperWith; // The token that will be rewarded
8
}
Copied!
Calling getNextSwapInfo is very similar to other pair calls:
1
pragma solidity 0.8.6;
2
3
import '@mean-finance/dca-v1/contracts/interfaces/IDCAPair.sol';
4
5
contract MyContract {
6
7
IDCAPair public immutable pair;
8
9
constructor(IDCAPair _pair) {
10
pair = _pair;
11
}
12
13
function getNextSwapInfo() external view returns (IDCAPair.NextSwapInformation memory) {
14
return pair.getNextSwapInfo();
15
}
16
17
}
Copied!
Last modified 2mo ago