Skip to content

Commit d2ed311

Browse files
committed
Initial deploy script
1 parent 0b33c47 commit d2ed311

21 files changed

Lines changed: 233 additions & 382 deletions

contracts/GPv2AllowListAuthentication.sol

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import "./mixins/StorageAccessible.sol";
88

99
/// @title Gnosis Protocol v2 Access Control Contract
1010
/// @author Gnosis Developers
11-
contract GPv2AllowListAuthentication is
12-
GPv2Authentication,
13-
Initializable,
14-
StorageAccessible
15-
{
11+
contract GPv2AllowListAuthentication is GPv2Authentication, Initializable, StorageAccessible {
1612
/// @dev The address of the manager that has permissions to add and remove
1713
/// solvers.
1814
address public manager;
@@ -57,10 +53,7 @@ contract GPv2AllowListAuthentication is
5753
/// This modifier assumes that the proxy uses an EIP-1967 compliant storage
5854
/// slot for the admin.
5955
modifier onlyManagerOrOwner() {
60-
require(
61-
manager == msg.sender || GPv2EIP1967.getAdmin() == msg.sender,
62-
"GPv2: not authorized"
63-
);
56+
require(manager == msg.sender || GPv2EIP1967.getAdmin() == msg.sender, "GPv2: not authorized");
6457
_;
6558
}
6659

@@ -100,9 +93,7 @@ contract GPv2AllowListAuthentication is
10093
}
10194

10295
/// @inheritdoc GPv2Authentication
103-
function isSolver(
104-
address prospectiveSolver
105-
) external view override returns (bool) {
96+
function isSolver(address prospectiveSolver) external view override returns (bool) {
10697
return solvers[prospectiveSolver];
10798
}
10899
}

contracts/GPv2Settlement.sol

Lines changed: 30 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
126126
) external nonReentrant onlySolver {
127127
executeInteractions(interactions[0]);
128128

129-
(
130-
GPv2Transfer.Data[] memory inTransfers,
131-
GPv2Transfer.Data[] memory outTransfers
132-
) = computeTradeExecutions(tokens, clearingPrices, trades);
129+
(GPv2Transfer.Data[] memory inTransfers, GPv2Transfer.Data[] memory outTransfers) =
130+
computeTradeExecutions(tokens, clearingPrices, trades);
133131

134132
vaultRelayer.transferFromAccounts(inTransfers);
135133

@@ -150,26 +148,22 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
150148
/// @param trade The trade to match directly against Balancer liquidity. The
151149
/// order will always be fully executed, so the trade's `executedAmount`
152150
/// field is used to represent a swap limit amount.
153-
function swap(
154-
IVault.BatchSwapStep[] calldata swaps,
155-
IERC20[] calldata tokens,
156-
GPv2Trade.Data calldata trade
157-
) external nonReentrant onlySolver {
151+
function swap(IVault.BatchSwapStep[] calldata swaps, IERC20[] calldata tokens, GPv2Trade.Data calldata trade)
152+
external
153+
nonReentrant
154+
onlySolver
155+
{
158156
RecoveredOrder memory recoveredOrder = allocateRecoveredOrder();
159157
GPv2Order.Data memory order = recoveredOrder.data;
160158
recoverOrderFromTrade(recoveredOrder, tokens, trade);
161159

162-
IVault.SwapKind kind = order.kind == GPv2Order.KIND_SELL
163-
? IVault.SwapKind.GIVEN_IN
164-
: IVault.SwapKind.GIVEN_OUT;
160+
IVault.SwapKind kind = order.kind == GPv2Order.KIND_SELL ? IVault.SwapKind.GIVEN_IN : IVault.SwapKind.GIVEN_OUT;
165161

166162
IVault.FundManagement memory funds;
167163
funds.sender = recoveredOrder.owner;
168-
funds.fromInternalBalance =
169-
order.sellTokenBalance == GPv2Order.BALANCE_INTERNAL;
164+
funds.fromInternalBalance = order.sellTokenBalance == GPv2Order.BALANCE_INTERNAL;
170165
funds.recipient = payable(recoveredOrder.receiver);
171-
funds.toInternalBalance =
172-
order.buyTokenBalance == GPv2Order.BALANCE_INTERNAL;
166+
funds.toInternalBalance = order.buyTokenBalance == GPv2Order.BALANCE_INTERNAL;
173167

174168
int256[] memory limits = new int256[](tokens.length);
175169
uint256 limitAmount = trade.executedAmount;
@@ -205,27 +199,19 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
205199
);
206200

207201
bytes memory orderUid = recoveredOrder.uid;
208-
uint256 executedSellAmount = tokenDeltas[trade.sellTokenIndex]
209-
.toUint256();
210-
uint256 executedBuyAmount = (-tokenDeltas[trade.buyTokenIndex])
211-
.toUint256();
202+
uint256 executedSellAmount = tokenDeltas[trade.sellTokenIndex].toUint256();
203+
uint256 executedBuyAmount = (-tokenDeltas[trade.buyTokenIndex]).toUint256();
212204

213205
// NOTE: Check that the orders were completely filled and update their
214206
// filled amounts to avoid replaying them. The limit price and order
215207
// validity has already been verified when executing the swap through
216208
// the `limit` and `deadline` parameters.
217209
require(filledAmount[orderUid] == 0, "GPv2: order filled");
218210
if (order.kind == GPv2Order.KIND_SELL) {
219-
require(
220-
executedSellAmount == order.sellAmount,
221-
"GPv2: sell amount not respected"
222-
);
211+
require(executedSellAmount == order.sellAmount, "GPv2: sell amount not respected");
223212
filledAmount[orderUid] = order.sellAmount;
224213
} else {
225-
require(
226-
executedBuyAmount == order.buyAmount,
227-
"GPv2: buy amount not respected"
228-
);
214+
require(executedBuyAmount == order.buyAmount, "GPv2: buy amount not respected");
229215
filledAmount[orderUid] = order.buyAmount;
230216
}
231217

@@ -248,7 +234,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
248234
/// must be the sender of this message. See [`extractOrderUidParams`]
249235
/// for details on orderUid.
250236
function invalidateOrder(bytes calldata orderUid) external {
251-
(, address owner, ) = orderUid.extractOrderUidParams();
237+
(, address owner,) = orderUid.extractOrderUidParams();
252238
require(owner == msg.sender, "GPv2: caller does not own order");
253239
filledAmount[orderUid] = type(uint256).max;
254240
emit OrderInvalidated(owner, orderUid);
@@ -259,9 +245,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
259245
///
260246
/// @param orderUids The unique identifiers of the expired order to free
261247
/// storage for.
262-
function freeFilledAmountStorage(
263-
bytes[] calldata orderUids
264-
) external onlyInteraction {
248+
function freeFilledAmountStorage(bytes[] calldata orderUids) external onlyInteraction {
265249
freeOrderStorage(filledAmount, orderUids);
266250
}
267251

@@ -270,9 +254,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
270254
///
271255
/// @param orderUids The unique identifiers of the expired order to free
272256
/// storage for.
273-
function freePreSignatureStorage(
274-
bytes[] calldata orderUids
275-
) external onlyInteraction {
257+
function freePreSignatureStorage(bytes[] calldata orderUids) external onlyInteraction {
276258
freeOrderStorage(preSignature, orderUids);
277259
}
278260

@@ -291,13 +273,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
291273
IERC20[] calldata tokens,
292274
uint256[] calldata clearingPrices,
293275
GPv2Trade.Data[] calldata trades
294-
)
295-
internal
296-
returns (
297-
GPv2Transfer.Data[] memory inTransfers,
298-
GPv2Transfer.Data[] memory outTransfers
299-
)
300-
{
276+
) internal returns (GPv2Transfer.Data[] memory inTransfers, GPv2Transfer.Data[] memory outTransfers) {
301277
RecoveredOrder memory recoveredOrder = allocateRecoveredOrder();
302278

303279
inTransfers = new GPv2Transfer.Data[](trades.length);
@@ -365,10 +341,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
365341
// amount_y = amount_x * price_x / price_y
366342
// ```
367343

368-
require(
369-
order.sellAmount.mul(sellPrice) >= order.buyAmount.mul(buyPrice),
370-
"GPv2: limit price not respected"
371-
);
344+
require(order.sellAmount.mul(sellPrice) >= order.buyAmount.mul(buyPrice), "GPv2: limit price not respected");
372345

373346
uint256 executedSellAmount;
374347
uint256 executedBuyAmount;
@@ -378,31 +351,20 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
378351
if (order.kind == GPv2Order.KIND_SELL) {
379352
if (order.partiallyFillable) {
380353
executedSellAmount = executedAmount;
381-
executedFeeAmount = order.feeAmount.mul(executedSellAmount).div(
382-
order.sellAmount
383-
);
354+
executedFeeAmount = order.feeAmount.mul(executedSellAmount).div(order.sellAmount);
384355
} else {
385356
executedSellAmount = order.sellAmount;
386357
executedFeeAmount = order.feeAmount;
387358
}
388359

389-
executedBuyAmount = executedSellAmount.mul(sellPrice).ceilDiv(
390-
buyPrice
391-
);
360+
executedBuyAmount = executedSellAmount.mul(sellPrice).ceilDiv(buyPrice);
392361

393-
currentFilledAmount = filledAmount[orderUid].add(
394-
executedSellAmount
395-
);
396-
require(
397-
currentFilledAmount <= order.sellAmount,
398-
"GPv2: order filled"
399-
);
362+
currentFilledAmount = filledAmount[orderUid].add(executedSellAmount);
363+
require(currentFilledAmount <= order.sellAmount, "GPv2: order filled");
400364
} else {
401365
if (order.partiallyFillable) {
402366
executedBuyAmount = executedAmount;
403-
executedFeeAmount = order.feeAmount.mul(executedBuyAmount).div(
404-
order.buyAmount
405-
);
367+
executedFeeAmount = order.feeAmount.mul(executedBuyAmount).div(order.buyAmount);
406368
} else {
407369
executedBuyAmount = order.buyAmount;
408370
executedFeeAmount = order.feeAmount;
@@ -411,10 +373,7 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
411373
executedSellAmount = executedBuyAmount.mul(buyPrice).div(sellPrice);
412374

413375
currentFilledAmount = filledAmount[orderUid].add(executedBuyAmount);
414-
require(
415-
currentFilledAmount <= order.buyAmount,
416-
"GPv2: order filled"
417-
);
376+
require(currentFilledAmount <= order.buyAmount, "GPv2: order filled");
418377
}
419378

420379
executedSellAmount = executedSellAmount.add(executedFeeAmount);
@@ -443,25 +402,16 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
443402

444403
/// @dev Execute a list of arbitrary contract calls from this contract.
445404
/// @param interactions The list of interactions to execute.
446-
function executeInteractions(
447-
GPv2Interaction.Data[] calldata interactions
448-
) internal {
405+
function executeInteractions(GPv2Interaction.Data[] calldata interactions) internal {
449406
for (uint256 i; i < interactions.length; ++i) {
450407
GPv2Interaction.Data calldata interaction = interactions[i];
451408

452409
// To prevent possible attack on user funds, we explicitly disable
453410
// any interactions with the vault relayer contract.
454-
require(
455-
interaction.target != address(vaultRelayer),
456-
"GPv2: forbidden interaction"
457-
);
411+
require(interaction.target != address(vaultRelayer), "GPv2: forbidden interaction");
458412
GPv2Interaction.execute(interaction);
459413

460-
emit Interaction(
461-
interaction.target,
462-
interaction.value,
463-
GPv2Interaction.selector(interaction)
464-
);
414+
emit Interaction(interaction.target, interaction.value, GPv2Interaction.selector(interaction));
465415
}
466416
}
467417

@@ -471,14 +421,11 @@ contract GPv2Settlement is GPv2Signing, ReentrancyGuard, StorageAccessible {
471421
///
472422
/// @param orderUids Order refund data for freeing storage.
473423
/// @param orderStorage Order storage mapped on a UID.
474-
function freeOrderStorage(
475-
mapping(bytes => uint256) storage orderStorage,
476-
bytes[] calldata orderUids
477-
) internal {
424+
function freeOrderStorage(mapping(bytes => uint256) storage orderStorage, bytes[] calldata orderUids) internal {
478425
for (uint256 i; i < orderUids.length; ++i) {
479426
bytes calldata orderUid = orderUids[i];
480427

481-
(, , uint32 validTo) = orderUid.extractOrderUidParams();
428+
(,, uint32 validTo) = orderUid.extractOrderUidParams();
482429
// solhint-disable-next-line not-rely-on-time
483430
require(validTo < block.timestamp, "GPv2: order still valid");
484431

contracts/GPv2VaultRelayer.sol

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ contract GPv2VaultRelayer {
3838
/// - Any ERC20 transfer fails
3939
///
4040
/// @param transfers The transfers to execute.
41-
function transferFromAccounts(
42-
GPv2Transfer.Data[] calldata transfers
43-
) external onlyCreator {
41+
function transferFromAccounts(GPv2Transfer.Data[] calldata transfers) external onlyCreator {
4442
vault.transferFromAccounts(transfers, msg.sender);
4543
}
4644

@@ -72,14 +70,7 @@ contract GPv2VaultRelayer {
7270
uint256 deadline,
7371
GPv2Transfer.Data calldata feeTransfer
7472
) external onlyCreator returns (int256[] memory tokenDeltas) {
75-
tokenDeltas = vault.batchSwap(
76-
kind,
77-
swaps,
78-
tokens,
79-
funds,
80-
limits,
81-
deadline
82-
);
73+
tokenDeltas = vault.batchSwap(kind, swaps, tokens, funds, limits, deadline);
8374
vault.fastTransferFromAccount(feeTransfer, msg.sender);
8475
}
8576
}

contracts/interfaces/GPv2EIP1271.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@ interface EIP1271Verifier {
2424
/// solc > 0.5)
2525
/// MUST allow external calls
2626
///
27-
function isValidSignature(
28-
bytes32 _hash,
29-
bytes memory _signature
30-
) external view returns (bytes4 magicValue);
27+
function isValidSignature(bytes32 _hash, bytes memory _signature) external view returns (bytes4 magicValue);
3128
}

contracts/interfaces/IERC20.sol

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ interface IERC20 {
4444
*
4545
* Emits a {Transfer} event.
4646
*/
47-
function transfer(
48-
address recipient,
49-
uint256 amount
50-
) external returns (bool);
47+
function transfer(address recipient, uint256 amount) external returns (bool);
5148

5249
/**
5350
* @dev Returns the remaining number of tokens that `spender` will be
@@ -56,10 +53,7 @@ interface IERC20 {
5653
*
5754
* This value changes when {approve} or {transferFrom} are called.
5855
*/
59-
function allowance(
60-
address owner,
61-
address spender
62-
) external view returns (uint256);
56+
function allowance(address owner, address spender) external view returns (uint256);
6357

6458
/**
6559
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
@@ -86,11 +80,7 @@ interface IERC20 {
8680
*
8781
* Emits a {Transfer} event.
8882
*/
89-
function transferFrom(
90-
address sender,
91-
address recipient,
92-
uint256 amount
93-
) external returns (bool);
83+
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
9484

9585
/**
9686
* @dev Emitted when `value` tokens are moved from one account (`from`) to
@@ -104,9 +94,5 @@ interface IERC20 {
10494
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
10595
* a call to {approve}. `value` is the new allowance.
10696
*/
107-
event Approval(
108-
address indexed owner,
109-
address indexed spender,
110-
uint256 value
111-
);
97+
event Approval(address indexed owner, address indexed spender, uint256 value);
11298
}

contracts/interfaces/IVault.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface IVault {
4444

4545
/**
4646
* @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
47-
without manual WETH wrapping or unwrapping.
47+
* without manual WETH wrapping or unwrapping.
4848
*/
4949
struct UserBalanceOp {
5050
UserBalanceOpKind kind;
@@ -164,12 +164,10 @@ interface IVault {
164164
*
165165
* Emits a `Swap` event.
166166
*/
167-
function swap(
168-
SingleSwap memory singleSwap,
169-
FundManagement memory funds,
170-
uint256 limit,
171-
uint256 deadline
172-
) external payable returns (uint256);
167+
function swap(SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline)
168+
external
169+
payable
170+
returns (uint256);
173171

174172
/**
175173
* @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on

contracts/libraries/GPv2EIP1967.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ pragma solidity >=0.7.6 <0.9.0;
44
library GPv2EIP1967 {
55
/// @dev The storage slot where the proxy administrator is stored, defined
66
/// as `keccak256('eip1967.proxy.admin') - 1`.
7-
bytes32 internal constant ADMIN_SLOT =
8-
hex"b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
7+
bytes32 internal constant ADMIN_SLOT = hex"b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
98

109
/// @dev Returns the address stored in the EIP-1967 administrator storage
1110
/// slot for the current contract. If this method is not called from an

0 commit comments

Comments
 (0)