Mean Finance
Search…
Modifying a Position
There are a few different ways you can modify your existing position. Now, remember that when modifying your position, you can get some tokens back, or you might need to deposit some extra tokens. For example, let's assume that you have a position where:
  • Rate: 5 DAI
  • Amount of swaps left: 10
That means that you have 50 DAI deposited. If you were to change your position to:
  • Rate: 8 DAI
  • Amount of swaps: 5
You would only need to have 40 DAI. Since you had 50 DAI deposited, you will get 10 DAI back. Now if instead you were to change your position to :
  • Rate: 10 DAI
  • Amount of swaps: 10
You would need to have 100 DAI in total. Since you had 50 DAI deposited, you will need to send 50 more DAI to the pair.

Modify the rate

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 Modifies the rate of a position. Could request more funds or return deposited funds
14
/// depending on whether the new rate is greater than the previous one.
15
/// @param _dcaId The position's id
16
/// @param _newRate The new rate to set
17
function modifyRate(uint256 _dcaId, uint160 _newRate) external {
18
pair.modifyRate(_dcaId, _newRate);
19
};
20
}
Copied!

Modify the amount of swaps

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 Modifies the amount of swaps of a position. Could request more funds or return
14
/// deposited funds depending on whether the new amount of swaps is greater than the swaps left.
15
/// @param _dcaId The position's id
16
/// @param _newSwaps The new amount of swaps
17
function modifySwaps(uint256 _dcaId, uint32 _newSwaps) external {
18
pair.modifySwaps(_dcaId, _newSwaps);
19
}
20
}
Copied!

Modify both the rate and the amount of swaps

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 Modifies both the rate and amount of swaps of a position. Could request more funds or return
14
/// deposited funds depending on whether the new parameters require more or less than the the unswapped funds.
15
/// @param _dcaId The position's id
16
/// @param _newRate The new rate to set
17
/// @param _newSwaps The new amount of swaps
18
function modifyRateAndSwaps(
19
uint256 _dcaId,
20
uint160 _newRate,
21
uint32 _newSwaps
22
) external {
23
pair.modifyRateAndSwaps(_dcaId, _newRate, _newSwaps);
24
}
25
}
Copied!

Add funds

There is one last action that can be performed against a pair. Going back to our example, let's say you have the following position:
  • Rate: 5 DAI
  • Amount of swaps left: 10
If you wanted to add 100 more DAI into your position, you would need to understand how much is left in your position. In order to make everyones lives easier, you can just call addFundsToPosition and set the extra amount and the new amount of swaps.
So if you called addFundsToPosition(_dcaId, 100 DAI, 20)the position would end up like this:
  • Rate: (50DAI (already there) + 100DAI (just added)) / amountOfSwaps = 150DAI / 20 = 7.5DAI
  • Amount of swaps: 20
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 Takes the unswapped balance, adds the new deposited funds and modifies the position so that
14
/// it is executed in _newSwaps swaps
15
/// @param _dcaId The position's id
16
/// @param _amount Amounts of funds to add to the position
17
/// @param _newSwaps The new amount of swaps
18
function addFundsToPosition(
19
uint256 _dcaId,
20
uint256 _amount,
21
uint32 _newSwaps
22
) external {
23
pair.addFundsToPosition(_dcaId, _amount, _newSwaps);
24
}
25
}
Copied!
Last modified 3mo ago