69 lines
2.7 KiB
Solidity
69 lines
2.7 KiB
Solidity
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
pragma solidity >=0.7.0 <0.9.0;
|
|
|
|
library StablePoolUserData {
|
|
enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
|
|
enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT, EXACT_BPT_IN_FOR_ALL_TOKENS_OUT }
|
|
|
|
function joinKind(bytes memory self) internal pure returns (JoinKind) {
|
|
return abi.decode(self, (JoinKind));
|
|
}
|
|
|
|
function exitKind(bytes memory self) internal pure returns (ExitKind) {
|
|
return abi.decode(self, (ExitKind));
|
|
}
|
|
|
|
// Joins
|
|
|
|
function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) {
|
|
(, amountsIn) = abi.decode(self, (JoinKind, uint256[]));
|
|
}
|
|
|
|
function exactTokensInForBptOut(bytes memory self)
|
|
internal
|
|
pure
|
|
returns (uint256[] memory amountsIn, uint256 minBPTAmountOut)
|
|
{
|
|
(, amountsIn, minBPTAmountOut) = abi.decode(self, (JoinKind, uint256[], uint256));
|
|
}
|
|
|
|
function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) {
|
|
(, bptAmountOut, tokenIndex) = abi.decode(self, (JoinKind, uint256, uint256));
|
|
}
|
|
|
|
function allTokensInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut) {
|
|
(, bptAmountOut) = abi.decode(self, (JoinKind, uint256));
|
|
}
|
|
|
|
// Exits
|
|
|
|
function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
|
|
(, bptAmountIn, tokenIndex) = abi.decode(self, (ExitKind, uint256, uint256));
|
|
}
|
|
|
|
function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) {
|
|
(, bptAmountIn) = abi.decode(self, (ExitKind, uint256));
|
|
}
|
|
|
|
function bptInForExactTokensOut(bytes memory self)
|
|
internal
|
|
pure
|
|
returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn)
|
|
{
|
|
(, amountsOut, maxBPTAmountIn) = abi.decode(self, (ExitKind, uint256[], uint256));
|
|
}
|
|
}
|