-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGlvLiquidity.sol
More file actions
105 lines (94 loc) · 3.59 KB
/
GlvLiquidity.sol
File metadata and controls
105 lines (94 loc) · 3.59 KB
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
101
102
103
104
105
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {console} from "forge-std/Test.sol";
import {IERC20} from "../interfaces/IERC20.sol";
import {IGlvRouter} from "../interfaces/IGlvRouter.sol";
import {GlvDepositUtils} from "../types/GlvDepositUtils.sol";
import {GlvWithdrawalUtils} from "../types/GlvWithdrawalUtils.sol";
import "../Constants.sol";
contract GlvLiquidity {
IERC20 constant weth = IERC20(WETH);
IERC20 constant usdc = IERC20(USDC);
IERC20 constant glvToken = IERC20(GLV_TOKEN_WETH_USDC);
IGlvRouter constant glvRouter = IGlvRouter(GLV_ROUTER);
// Task 1 - Receive execution fee refund from GMX
receive() external payable {}
// Task 2 - Create an order to deposit USDC into GLV vault
function createGlvDeposit(uint256 usdcAmount, uint256 minGlvAmount)
external
payable
returns (bytes32 key)
{
uint256 executionFee = 0.1 * 1e18;
usdc.transferFrom(msg.sender, address(this), usdcAmount);
// Task 2.1 - Send execution fee to GLV vault
glvRouter.sendWnt{value: executionFee}({
receiver: GLV_VAULT,
amount: executionFee
});
// Task 2.2 - Send USDC to GLV vault
usdc.approve(ROUTER, usdcAmount);
glvRouter.sendTokens({
token: USDC,
receiver: GLV_VAULT,
amount: usdcAmount
});
// Task 2.3 - Create an order to deposit USDC
return glvRouter.createGlvDeposit(
GlvDepositUtils.CreateGlvDepositParams({
glv: address(glvToken),
market: GM_TOKEN_ETH_WETH_USDC,
receiver: address(this),
callbackContract: address(0),
uiFeeReceiver: address(0),
initialLongToken: WETH,
initialShortToken: USDC,
longTokenSwapPath: new address[](0),
shortTokenSwapPath: new address[](0),
minGlvTokens: minGlvAmount,
executionFee: executionFee,
callbackGasLimit: 0,
shouldUnwrapNativeToken: false,
isMarketTokenDeposit: false
})
);
}
// Task 3 - Create an order to withdraw liquidity
function createGlvWithdrawal(uint256 minWethAmount, uint256 minUsdcAmount)
external
payable
returns (bytes32 key)
{
uint256 executionFee = 0.1 * 1e18;
uint256 glvTokenAmount = glvToken.balanceOf(address(this));
// 3.1 Send execution fee to GLV vault
glvRouter.sendWnt{value: executionFee}({
receiver: GLV_VAULT,
amount: executionFee
});
// 3.2 - Send USDC to GLV vault
glvToken.approve(ROUTER, glvTokenAmount);
glvRouter.sendTokens({
token: address(glvToken),
receiver: GLV_VAULT,
amount: glvTokenAmount
});
// 3.3 Create an order to withdraw liquidity
return glvRouter.createGlvWithdrawal(
GlvWithdrawalUtils.CreateGlvWithdrawalParams({
receiver: address(this),
callbackContract: address(0),
uiFeeReceiver: address(0),
market: GM_TOKEN_ETH_WETH_USDC,
glv: address(glvToken),
longTokenSwapPath: new address[](0),
shortTokenSwapPath: new address[](0),
minLongTokenAmount: minWethAmount,
minShortTokenAmount: minUsdcAmount,
shouldUnwrapNativeToken: false,
executionFee: executionFee,
callbackGasLimit: 0
})
);
}
}