Mean Finance
Search…
Withdrawing from a Position
Once a swap is executed for your position, it will contain "swapped balance". This balance can be withdrawn at any point. Now, it is important to remember that you can withdraw this balance from one of your positions, or many at the same time.

Withdrawing from one position

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
/// @notice Withdraws all swapped tokens from a position
14
/// @param _dcaId The position's id
15
/// @return _swapped How much was withdrawn
16
function withdrawSwapped(uint256 _dcaId) external returns (uint256 _swapped) {
17
_swapped = pair.withdrawSwapped(_dcaId);
18
}
19
}
Copied!

Withdrawing from many positions

If you'd like to withdraw all swapped tokens from many of your positions, you could technically execute withdrawSwapped for each of them. However, since this can be expensive, we also offer withdrawSwappedMany. This method will allow you to withdraw more than one position in the same transaction.
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
/// @notice Withdraws all swapped tokens from many positions
14
/// @param _dcaIds The positions' ids
15
/// @return _swappedTokenA How much was withdrawn in token A
16
/// @return _swappedTokenB How much was withdrawn in token B
17
function withdrawSwappedMany(uint256[] calldata _dcaIds) external returns (uint256 _swappedTokenA, uint256 _swappedTokenB) {
18
(_swappedTokenA, _swappedTokenB) = withdrawSwappedMany(_dcaIds);
19
}
20
}
Copied!
Last modified 3mo ago