@pendle/core-v2 2.17.0-tradingbot → 2.17.1-tradingbot
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/core/TradingBot/BotDecisionLib.sol +5 -5
- package/contracts/core/TradingBot/LongYieldTradingBot.sol +16 -10
- package/contracts/core/TradingBot/TradingBotBase.sol +15 -4
- package/contracts/core/TradingBot/TradingBotOffchain.sol +16 -10
- package/contracts/interfaces/TradingBot/ILongYieldTradingBot.sol +2 -2
- package/contracts/interfaces/TradingBot/ITradingBotBase.sol +5 -2
- package/package.json +1 -1
|
@@ -31,7 +31,7 @@ struct StrategyState {
|
|
|
31
31
|
StrategyFlag syRatioFlag;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
contract BotDecisionLib {
|
|
35
35
|
using MarketExtLib for MarketExtState;
|
|
36
36
|
using MarketExtLib for ApproxParams;
|
|
37
37
|
using BotSimulationLib for BotState;
|
|
@@ -57,7 +57,7 @@ library BotDecisionLib {
|
|
|
57
57
|
*
|
|
58
58
|
* @param botParams ApproxParams for this binary search function
|
|
59
59
|
* @param oldState The initial StrategyState, to be moved away from
|
|
60
|
-
* @param intParams ApproxParams for
|
|
60
|
+
* @param intParams ApproxParams for public action's approximation (e.g. for router's swap)
|
|
61
61
|
* @dev For `botParams`, eps = the precision such that slightly lower
|
|
62
62
|
* ((return value) * (1 - eps)) does not reach a new state
|
|
63
63
|
*
|
|
@@ -78,7 +78,7 @@ library BotDecisionLib {
|
|
|
78
78
|
StrategyState memory oldState,
|
|
79
79
|
ApproxParams memory botParams,
|
|
80
80
|
ApproxParams memory intParams
|
|
81
|
-
)
|
|
81
|
+
) public pure returns (uint256) {
|
|
82
82
|
RebalanceDetails memory rebalance = RebalanceDetails(
|
|
83
83
|
bot,
|
|
84
84
|
marketExt,
|
|
@@ -225,7 +225,7 @@ library BotDecisionLib {
|
|
|
225
225
|
BotState memory bot,
|
|
226
226
|
MarketExtState memory marketExt,
|
|
227
227
|
LongTradingSpecs memory specs
|
|
228
|
-
)
|
|
228
|
+
) public pure returns (StrategyState memory currentState) {
|
|
229
229
|
uint256 iy = marketExt.impliedYield();
|
|
230
230
|
(, uint256 ptInLp) = marketExt.previewAssetsFromLp(bot.lpBalance);
|
|
231
231
|
uint256 currentYtPtRatio = (
|
|
@@ -248,7 +248,7 @@ library BotDecisionLib {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
function actionToTake(StrategyState memory currentState)
|
|
251
|
+
function actionToTake(StrategyState memory currentState) public pure returns (ActionType) {
|
|
252
252
|
if (currentState.iyFlag == StrategyFlag.TOO_LOW) {
|
|
253
253
|
if (currentState.syRatioFlag == StrategyFlag.TOO_HIGH) {
|
|
254
254
|
return ActionType.SwapSyToYt;
|
|
@@ -14,22 +14,28 @@ contract LongYieldTradingBot is
|
|
|
14
14
|
UUPSUpgradeable
|
|
15
15
|
{
|
|
16
16
|
LongTradingSpecs public specs;
|
|
17
|
+
address public immutable decisionLib;
|
|
17
18
|
|
|
18
19
|
constructor(
|
|
19
20
|
address _market,
|
|
20
21
|
address _PENDLE,
|
|
21
|
-
|
|
22
|
+
address _decisionLib
|
|
22
23
|
) TradingBotBase(_market, _PENDLE) {
|
|
23
|
-
|
|
24
|
+
decisionLib = _decisionLib;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
function _authorizeUpgrade(address) internal override onlyOwner {}
|
|
27
28
|
|
|
28
|
-
function initialize() external initializer {
|
|
29
|
+
function initialize(LongTradingSpecs memory _specs) external initializer {
|
|
30
|
+
_setSpecs(_specs);
|
|
29
31
|
__BoringOwnable_init();
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
function setSpecs(LongTradingSpecs calldata _specs) external onlyOwner {
|
|
35
|
+
_setSpecs(_specs);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function _setSpecs(LongTradingSpecs memory _specs) internal {
|
|
33
39
|
specs = _specs;
|
|
34
40
|
}
|
|
35
41
|
|
|
@@ -40,7 +46,7 @@ contract LongYieldTradingBot is
|
|
|
40
46
|
uint256 minYtOut,
|
|
41
47
|
uint256 maxSyIn
|
|
42
48
|
) external onlyOwner returns (uint256 exactYtOut, uint256 netSyIn) {
|
|
43
|
-
exactYtOut = BotDecisionLib.binarySearchUntilSwitchState(
|
|
49
|
+
exactYtOut = BotDecisionLib(decisionLib).binarySearchUntilSwitchState(
|
|
44
50
|
readBotState(),
|
|
45
51
|
readMarketExtState(router),
|
|
46
52
|
specs,
|
|
@@ -64,7 +70,7 @@ contract LongYieldTradingBot is
|
|
|
64
70
|
uint256 minLpOut,
|
|
65
71
|
uint256 minYtOut
|
|
66
72
|
) external onlyOwner returns (uint256 netSyIn, uint256 netLpOut, uint256 netYtOut) {
|
|
67
|
-
netSyIn = BotDecisionLib.binarySearchUntilSwitchState(
|
|
73
|
+
netSyIn = BotDecisionLib(decisionLib).binarySearchUntilSwitchState(
|
|
68
74
|
readBotState(),
|
|
69
75
|
readMarketExtState(router),
|
|
70
76
|
specs,
|
|
@@ -85,8 +91,8 @@ contract LongYieldTradingBot is
|
|
|
85
91
|
ApproxParams calldata botParams,
|
|
86
92
|
uint256 minLpOut,
|
|
87
93
|
uint256 maxSyIn
|
|
88
|
-
) external onlyOwner returns (uint256 netLpOut, uint256 netSyIn) {
|
|
89
|
-
|
|
94
|
+
) external onlyOwner returns (uint256 netPtFromSwap, uint256 netLpOut, uint256 netSyIn) {
|
|
95
|
+
netPtFromSwap = BotDecisionLib(decisionLib).binarySearchUntilSwitchState(
|
|
90
96
|
readBotState(),
|
|
91
97
|
readMarketExtState(address(this)),
|
|
92
98
|
specs,
|
|
@@ -106,8 +112,8 @@ contract LongYieldTradingBot is
|
|
|
106
112
|
ApproxParams calldata botParams,
|
|
107
113
|
uint256 minLpOut,
|
|
108
114
|
uint256 maxYtIn
|
|
109
|
-
) external onlyOwner returns (uint256 netLpOut, uint256 netYtIn) {
|
|
110
|
-
|
|
115
|
+
) external onlyOwner returns (uint256 netPtFromSwap, uint256 netLpOut, uint256 netYtIn) {
|
|
116
|
+
netPtFromSwap = BotDecisionLib(decisionLib).binarySearchUntilSwitchState(
|
|
111
117
|
readBotState(),
|
|
112
118
|
readMarketExtState(address(this)),
|
|
113
119
|
specs,
|
|
@@ -128,7 +134,7 @@ contract LongYieldTradingBot is
|
|
|
128
134
|
uint256 maxLpRemoved,
|
|
129
135
|
uint256 minYtOut
|
|
130
136
|
) external onlyOwner returns (uint256 netLpRemoved, uint256 netYtOut) {
|
|
131
|
-
netLpRemoved = BotDecisionLib.binarySearchUntilSwitchState(
|
|
137
|
+
netLpRemoved = BotDecisionLib(decisionLib).binarySearchUntilSwitchState(
|
|
132
138
|
readBotState(),
|
|
133
139
|
readMarketExtState(address(this)),
|
|
134
140
|
specs,
|
|
@@ -52,10 +52,6 @@ abstract contract TradingBotBase is BoringOwnableUpgradeable, TokenHelper, ITrad
|
|
|
52
52
|
emit WithdrawFunds(token, amount);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function approveInf(address token, address spender) external onlyOwner {
|
|
56
|
-
_safeApproveInf(token, spender);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
55
|
function claimAndCompound(
|
|
60
56
|
address router,
|
|
61
57
|
TokenInput[] calldata inps,
|
|
@@ -117,4 +113,19 @@ abstract contract TradingBotBase is BoringOwnableUpgradeable, TokenHelper, ITrad
|
|
|
117
113
|
value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0
|
|
118
114
|
}(address(this), SY, minSyOut, inp);
|
|
119
115
|
}
|
|
116
|
+
|
|
117
|
+
function approveInf(MultiApproval[] calldata arr) external onlyOwner {
|
|
118
|
+
for (uint256 i = 0; i < arr.length; ) {
|
|
119
|
+
MultiApproval calldata ele = arr[i];
|
|
120
|
+
for (uint256 j = 0; j < ele.tokens.length; ) {
|
|
121
|
+
_safeApproveInf(ele.tokens[j], ele.spender);
|
|
122
|
+
unchecked {
|
|
123
|
+
j++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
unchecked {
|
|
127
|
+
i++;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
120
131
|
}
|
|
@@ -11,6 +11,12 @@ contract TradingBotOffchain {
|
|
|
11
11
|
using MarketApproxPtInLib for MarketState;
|
|
12
12
|
using PYIndexLib for PYIndex;
|
|
13
13
|
|
|
14
|
+
address immutable public decisionLib;
|
|
15
|
+
|
|
16
|
+
constructor(address _decisionLib) {
|
|
17
|
+
decisionLib = _decisionLib;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
/// SY interest from YT is excluded
|
|
15
21
|
function claimForBot(
|
|
16
22
|
address bot,
|
|
@@ -37,7 +43,7 @@ contract TradingBotOffchain {
|
|
|
37
43
|
ActionType action,
|
|
38
44
|
uint256 botParam,
|
|
39
45
|
ApproxParams memory swapApproxParams
|
|
40
|
-
) external
|
|
46
|
+
) external view returns (bool success, BotState memory bot, MarketExtState memory marketExt) {
|
|
41
47
|
bot = botCalldata;
|
|
42
48
|
marketExt = marketExtCalldata;
|
|
43
49
|
|
|
@@ -64,9 +70,9 @@ contract TradingBotOffchain {
|
|
|
64
70
|
StrategyState calldata initialState,
|
|
65
71
|
ApproxParams calldata botParams,
|
|
66
72
|
ApproxParams calldata intParams
|
|
67
|
-
) external
|
|
73
|
+
) external view returns (uint256) {
|
|
68
74
|
return
|
|
69
|
-
BotDecisionLib.binarySearchUntilSwitchState(
|
|
75
|
+
BotDecisionLib(decisionLib).binarySearchUntilSwitchState(
|
|
70
76
|
bot,
|
|
71
77
|
marketExt,
|
|
72
78
|
specs,
|
|
@@ -82,7 +88,7 @@ contract TradingBotOffchain {
|
|
|
82
88
|
ActionType action,
|
|
83
89
|
uint256 botParam,
|
|
84
90
|
ApproxParams calldata intParams
|
|
85
|
-
) external
|
|
91
|
+
) external view returns (uint256) {
|
|
86
92
|
if (action == ActionType.RemoveLiqToYt) {
|
|
87
93
|
return _searchForIntParamRemoveLiqToYt(marketExt, botParam, intParams);
|
|
88
94
|
} else {
|
|
@@ -94,18 +100,18 @@ contract TradingBotOffchain {
|
|
|
94
100
|
BotState calldata bot,
|
|
95
101
|
MarketExtState calldata marketExt,
|
|
96
102
|
LongTradingSpecs calldata specs
|
|
97
|
-
) external
|
|
98
|
-
return BotDecisionLib.strategyState(bot, marketExt, specs);
|
|
103
|
+
) external view returns (StrategyState memory) {
|
|
104
|
+
return BotDecisionLib(decisionLib).strategyState(bot, marketExt, specs);
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
function actionToTake(StrategyState memory currentState) external
|
|
102
|
-
return BotDecisionLib.actionToTake(currentState);
|
|
107
|
+
function actionToTake(StrategyState memory currentState) external view returns (ActionType) {
|
|
108
|
+
return BotDecisionLib(decisionLib).actionToTake(currentState);
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
function tvlInSy(
|
|
106
112
|
BotState calldata bot,
|
|
107
113
|
MarketExtState calldata marketExt
|
|
108
|
-
) external
|
|
114
|
+
) external view returns (uint256) {
|
|
109
115
|
return BotSimulationLib.tvlInSy(bot, marketExt);
|
|
110
116
|
}
|
|
111
117
|
|
|
@@ -113,7 +119,7 @@ contract TradingBotOffchain {
|
|
|
113
119
|
MarketExtState memory marketExt,
|
|
114
120
|
uint256 netLpToRemove,
|
|
115
121
|
ApproxParams memory intParams
|
|
116
|
-
) private
|
|
122
|
+
) private view returns (uint256 totalPtToSwap) {
|
|
117
123
|
(uint256 netSyRemoved, uint256 netPtRemoved) = marketExt.state.removeLiquidity(
|
|
118
124
|
netLpToRemove
|
|
119
125
|
);
|
|
@@ -70,14 +70,14 @@ interface ILongYieldTradingBot {
|
|
|
70
70
|
ApproxParams calldata botParams,
|
|
71
71
|
uint256 minLpOut,
|
|
72
72
|
uint256 maxSyIn
|
|
73
|
-
) external returns (uint256 netLpOut, uint256 netSyIn);
|
|
73
|
+
) external returns (uint256 netPtFromSwap, uint256 netLpOut, uint256 netSyIn);
|
|
74
74
|
|
|
75
75
|
function addLiqFromYt(
|
|
76
76
|
StrategyState memory oldState,
|
|
77
77
|
ApproxParams calldata botParams,
|
|
78
78
|
uint256 minLpOut,
|
|
79
79
|
uint256 maxYtIn
|
|
80
|
-
) external returns (uint256 netLpOut, uint256 netYtIn);
|
|
80
|
+
) external returns (uint256 netPtFromSwap, uint256 netLpOut, uint256 netYtIn);
|
|
81
81
|
|
|
82
82
|
function removeLiqToYt(
|
|
83
83
|
StrategyState memory oldState,
|
|
@@ -5,6 +5,11 @@ import "../IPAllAction.sol";
|
|
|
5
5
|
import "../../core/TradingBot/BotSimulationLib.sol";
|
|
6
6
|
|
|
7
7
|
interface ITradingBotBase {
|
|
8
|
+
struct MultiApproval {
|
|
9
|
+
address[] tokens;
|
|
10
|
+
address spender;
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
event DepositSy(uint256 netSyIn);
|
|
9
14
|
|
|
10
15
|
event DepositToken(address indexed token, uint256 netTokenIn);
|
|
@@ -26,8 +31,6 @@ interface ITradingBotBase {
|
|
|
26
31
|
|
|
27
32
|
function withdrawFunds(address token, uint256 amount) external;
|
|
28
33
|
|
|
29
|
-
function approveInf(address token, address spender) external;
|
|
30
|
-
|
|
31
34
|
function claimAndCompound(
|
|
32
35
|
address router,
|
|
33
36
|
TokenInput[] calldata inps,
|
package/package.json
CHANGED