-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathCommon.sol
More file actions
162 lines (145 loc) · 6.12 KB
/
Common.sol
File metadata and controls
162 lines (145 loc) · 6.12 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// SPDX-License-Identifier: MIT
pragma solidity =0.8.25;
import {SettlerBase} from "../../SettlerBase.sol";
import {IERC20} from "@forge-std/interfaces/IERC20.sol";
import {IPSM, MakerPSM} from "../../core/MakerPSM.sol";
import {MaverickV2, IMaverickV2Pool} from "../../core/MaverickV2.sol";
import {CurveTricrypto} from "../../core/CurveTricrypto.sol";
import {DodoV1, IDodoV1} from "../../core/DodoV1.sol";
import {DodoV2, IDodoV2} from "../../core/DodoV2.sol";
import {UniswapV4} from "../../core/UniswapV4.sol";
import {IPoolManager} from "../../core/UniswapV4Types.sol";
import {BalancerV3} from "../../core/BalancerV3.sol";
import {FreeMemory} from "../../utils/FreeMemory.sol";
import {ISettlerActions} from "../../ISettlerActions.sol";
import {ISignatureTransfer} from "@permit2/interfaces/ISignatureTransfer.sol";
import {UnknownForkId} from "../../core/SettlerErrors.sol";
import {
uniswapV3MainnetFactory,
uniswapV3InitHash,
uniswapV3ForkId,
IUniswapV3Callback
} from "../../core/univ3forks/UniswapV3.sol";
import {
pancakeSwapV3Factory,
pancakeSwapV3InitHash,
pancakeSwapV3ForkId,
IPancakeSwapV3Callback
} from "../../core/univ3forks/PancakeSwapV3.sol";
import {sushiswapV3MainnetFactory, sushiswapV3ForkId} from "../../core/univ3forks/SushiswapV3.sol";
import {
solidlyV3Factory,
solidlyV3InitHash,
solidlyV3ForkId,
ISolidlyV3Callback
} from "../../core/univ3forks/SolidlyV3.sol";
import {MAINNET_POOL_MANAGER} from "../../core/UniswapV4Addresses.sol";
// Solidity inheritance is stupid
import {SettlerAbstract} from "../../SettlerAbstract.sol";
abstract contract MainnetMixin is
FreeMemory,
SettlerBase,
MakerPSM,
MaverickV2,
CurveTricrypto,
DodoV1,
DodoV2,
UniswapV4,
BalancerV3
{
constructor() {
assert(block.chainid == 1 || block.chainid == 31337);
}
function _dispatch(uint256 i, uint256 action, bytes calldata data)
internal
virtual
override(SettlerAbstract, SettlerBase)
DANGEROUS_freeMemory
returns (bool)
{
if (super._dispatch(i, action, data)) {
return true;
} else if (action == uint32(ISettlerActions.UNISWAPV4.selector)) {
(
address recipient,
IERC20 sellToken,
uint256 bps,
bool feeOnTransfer,
uint256 hashMul,
uint256 hashMod,
bytes memory fills,
uint256 amountOutMin
) = abi.decode(data, (address, IERC20, uint256, bool, uint256, uint256, bytes, uint256));
sellToUniswapV4(recipient, sellToken, bps, feeOnTransfer, hashMul, hashMod, fills, amountOutMin);
} else if (action == uint32(ISettlerActions.MAKERPSM.selector)) {
(address recipient, uint256 bps, bool buyGem, uint256 amountOutMin) =
abi.decode(data, (address, uint256, bool, uint256));
sellToMakerPsm(recipient, bps, buyGem, amountOutMin);
} else if (action == uint32(ISettlerActions.BALANCERV3.selector)) {
(
address recipient,
IERC20 sellToken,
uint256 bps,
bool feeOnTransfer,
uint256 hashMul,
uint256 hashMod,
bytes memory fills,
uint256 amountOutMin
) = abi.decode(data, (address, IERC20, uint256, bool, uint256, uint256, bytes, uint256));
sellToBalancerV3(recipient, sellToken, bps, feeOnTransfer, hashMul, hashMod, fills, amountOutMin);
} else if (action == uint32(ISettlerActions.MAVERICKV2.selector)) {
(
address recipient,
IERC20 sellToken,
uint256 bps,
IMaverickV2Pool pool,
bool tokenAIn,
uint256 minBuyAmount
) = abi.decode(data, (address, IERC20, uint256, IMaverickV2Pool, bool, uint256));
sellToMaverickV2(recipient, sellToken, bps, pool, tokenAIn, minBuyAmount);
} else if (action == uint32(ISettlerActions.DODOV2.selector)) {
(address recipient, IERC20 sellToken, uint256 bps, IDodoV2 dodo, bool quoteForBase, uint256 minBuyAmount) =
abi.decode(data, (address, IERC20, uint256, IDodoV2, bool, uint256));
sellToDodoV2(recipient, sellToken, bps, dodo, quoteForBase, minBuyAmount);
} else if (action == uint32(ISettlerActions.DODOV1.selector)) {
(IERC20 sellToken, uint256 bps, IDodoV1 dodo, bool quoteForBase, uint256 minBuyAmount) =
abi.decode(data, (IERC20, uint256, IDodoV1, bool, uint256));
sellToDodoV1(sellToken, bps, dodo, quoteForBase, minBuyAmount);
} else {
return false;
}
return true;
}
function _uniV3ForkInfo(uint8 forkId)
internal
pure
override
returns (address factory, bytes32 initHash, uint32 callbackSelector)
{
if (forkId == uniswapV3ForkId) {
factory = uniswapV3MainnetFactory;
initHash = uniswapV3InitHash;
callbackSelector = uint32(IUniswapV3Callback.uniswapV3SwapCallback.selector);
} else if (forkId == pancakeSwapV3ForkId) {
factory = pancakeSwapV3Factory;
initHash = pancakeSwapV3InitHash;
callbackSelector = uint32(IPancakeSwapV3Callback.pancakeV3SwapCallback.selector);
} else if (forkId == sushiswapV3ForkId) {
factory = sushiswapV3MainnetFactory;
initHash = uniswapV3InitHash;
callbackSelector = uint32(IUniswapV3Callback.uniswapV3SwapCallback.selector);
} else if (forkId == solidlyV3ForkId) {
factory = solidlyV3Factory;
initHash = solidlyV3InitHash;
callbackSelector = uint32(ISolidlyV3Callback.solidlyV3SwapCallback.selector);
} else {
revert UnknownForkId(forkId);
}
}
function _curveFactory() internal pure override returns (address) {
return 0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963;
}
function _POOL_MANAGER() internal pure override returns (IPoolManager) {
return MAINNET_POOL_MANAGER;
}
}