-
Notifications
You must be signed in to change notification settings - Fork 11
/
MockBalancerCallback.sol
100 lines (85 loc) · 3.34 KB
/
MockBalancerCallback.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import {Deployments} from "../../global/Deployments.sol";
import {IBalancerVault, IAsset} from "../../../interfaces/balancer/IBalancerVault.sol";
import {IStrategyVault} from "../../../interfaces/notional/IStrategyVault.sol";
import {NotionalProxy} from "../../../interfaces/notional/NotionalProxy.sol";
import {TokenUtils, IERC20} from "../../utils/TokenUtils.sol";
contract MockBalancerCallback {
using TokenUtils for IERC20;
NotionalProxy public immutable NOTIONAL;
address public immutable BALANCER_POOL_TOKEN;
mapping(address => address) internal underlyingToAsset;
CallbackParams internal callbackParams;
event AccountCollateral(
int256 collateralRatio,
int256 minCollateralRatio,
int256 maxLiquidatorDepositAssetCash,
uint256 vaultSharesToLiquidator
);
event AccountDeleveraged(address account);
struct CallbackParams {
address account;
address vault;
bytes redeemData;
}
constructor(NotionalProxy notional_, address balancerPool_) {
NOTIONAL = notional_;
BALANCER_POOL_TOKEN = balancerPool_;
}
function deleverage(
uint256 primaryAmount,
uint256 secondaryAmount,
CallbackParams calldata params
) external {
IERC20(address(Deployments.WRAPPED_STETH)).checkApprove(address(Deployments.BALANCER_VAULT), type(uint256).max);
callbackParams = params;
IAsset[] memory assets = new IAsset[](2);
assets[1] = IAsset(address(0));
assets[0] = IAsset(address(Deployments.WRAPPED_STETH));
uint256[] memory amounts = new uint256[](2);
// Join with 1 gWei less than msgValue to trigger callback
amounts[1] = primaryAmount - 1e9;
amounts[0] = secondaryAmount;
uint256 msgValue;
msgValue = primaryAmount;
Deployments.BALANCER_VAULT.joinPool{value: msgValue}(
0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080,
address(this),
address(this),
IBalancerVault.JoinPoolRequest(
assets,
amounts,
abi.encode(
IBalancerVault.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT,
amounts,
0
),
false // Don't use internal balances
)
);
}
receive() external payable {
if (msg.sender == address(Deployments.BALANCER_VAULT)) {
(
int256 collateralRatio,
int256 minCollateralRatio,
int256 maxLiquidatorDepositAssetCash,
uint256 vaultSharesToLiquidator
) = NOTIONAL.getVaultAccountCollateralRatio(
callbackParams.account,
callbackParams.vault
);
emit AccountCollateral(collateralRatio, minCollateralRatio, maxLiquidatorDepositAssetCash, vaultSharesToLiquidator);
IStrategyVault(callbackParams.vault).deleverageAccount(
callbackParams.account,
callbackParams.vault,
address(this),
uint256(maxLiquidatorDepositAssetCash),
true,
callbackParams.redeemData
);
emit AccountDeleveraged(callbackParams.account);
}
}
}