@@ -27,7 +27,7 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
2727 super .setUp ();
2828
2929 // Deploy the collateral swap wrapper
30- collateralSwapWrapper = new CowEvcCollateralSwapWrapper (address (evc ), COW_SETTLEMENT);
30+ collateralSwapWrapper = new CowEvcCollateralSwapWrapper (address (EVC ), COW_SETTLEMENT);
3131
3232 // Add wrapper as a solver
3333 GPv2AllowListAuthentication allowList = GPv2AllowListAuthentication (address (COW_SETTLEMENT.authenticator ()));
@@ -36,7 +36,7 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
3636 allowList.addSolver (address (collateralSwapWrapper));
3737 vm.stopPrank ();
3838
39- ecdsa = new SignerECDSA (evc );
39+ ecdsa = new SignerECDSA (EVC );
4040
4141 // sUSDS is not currently a collateral for WETH borrow, fix it
4242 vm.startPrank (IEVault (EWETH).governorAdmin ());
@@ -68,8 +68,8 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
6868 IERC20 (SUSDS).approve (ESUSDS, type (uint256 ).max);
6969
7070 // Enable collateral and controller on the account
71- evc .enableCollateral (account, ESUSDS);
72- evc .enableController (account, EWETH);
71+ EVC .enableCollateral (account, ESUSDS);
72+ EVC .enableController (account, EWETH);
7373
7474 // Deposit collateral to the account, and add the approximate amount after swapping the borrowed collateral
7575 IERC4626 (ESUSDS).deposit (collateralAmount + borrowAmount * 2500e18 / 0.99e18 , account);
@@ -162,10 +162,10 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
162162 value: 0 ,
163163 data: abi.encodeCall (IERC20 .approve, (address (collateralSwapWrapper), type (uint256 ).max))
164164 });
165- evc .batch (items);
165+ EVC .batch (items);
166166
167167 // Set wrapper as operator for the subaccount
168- evc .setAccountOperator (account, address (collateralSwapWrapper), true );
168+ EVC .setAccountOperator (account, address (collateralSwapWrapper), true );
169169
170170 // Pre-approve the operation hash
171171 bytes32 hash = collateralSwapWrapper.getApprovalHash (params);
@@ -183,32 +183,9 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
183183 address buyVaultToken ,
184184 uint256 sellAmount ,
185185 uint256 buyAmount
186- ) public view returns (SettlementData memory r ) {
186+ ) public returns (SettlementData memory r ) {
187187 uint32 validTo = uint32 (block .timestamp + 1 hours);
188188
189- // Create order data - using KIND_SELL to sell exact amount of collateral
190- r.orderData = GPv2Order.Data ({
191- sellToken: CowERC20 (sellVaultToken),
192- buyToken: CowERC20 (buyVaultToken),
193- receiver: receiver,
194- sellAmount: sellAmount,
195- buyAmount: buyAmount,
196- validTo: validTo,
197- appData: bytes32 (0 ),
198- feeAmount: 0 ,
199- kind: GPv2Order.KIND_SELL,
200- partiallyFillable: false ,
201- sellTokenBalance: GPv2Order.BALANCE_ERC20,
202- buyTokenBalance: GPv2Order.BALANCE_ERC20
203- });
204-
205- // Get order UID
206- r.orderUid = getOrderUid (owner, r.orderData);
207-
208- // Get trade data
209- r.trades = new ICowSettlement.Trade [](1 );
210- r.trades[0 ] = getTradeData (sellAmount, buyAmount, validTo, owner, r.orderData.receiver, false );
211-
212189 // Get tokens and prices
213190 r.tokens = new address [](2 );
214191 r.tokens[0 ] = sellVaultToken;
@@ -218,6 +195,12 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
218195 r.clearingPrices[0 ] = milkSwap.prices (IERC4626 (sellVaultToken).asset ());
219196 r.clearingPrices[1 ] = milkSwap.prices (IERC4626 (buyVaultToken).asset ()) * 1 ether / 0.98 ether ;
220197
198+ // Get trade data
199+ r.trades = new ICowSettlement.Trade [](1 );
200+ (r.trades[0 ], r.orderData, r.orderUid) = setupCowOrder (
201+ r.tokens, 0 , 1 , sellAmount, buyAmount, validTo, owner, receiver, false
202+ );
203+
221204 // Setup interactions - withdraw from sell vault, swap underlying assets, deposit to buy vault
222205 r.interactions = [
223206 new ICowSettlement.Interaction [](0 ),
@@ -250,21 +233,22 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
250233 function test_CollateralSwapWrapper_MainAccount () external {
251234 vm.skip (bytes (forkRpcUrl).length == 0 );
252235
253- // User deposits SUSDS collateral
254- vm.startPrank (user);
255- IERC20 (SUSDS).approve (ESUSDS, type (uint256 ).max);
256- uint256 depositAmount = 1000e18 ;
257- IERC4626 (ESUSDS).deposit (depositAmount, user);
258-
259236 // Create params using helper
260237 CowEvcCollateralSwapWrapper.CollateralSwapParams memory params = _createDefaultParams (user, user);
261238
262239 // Get settlement data
263240 SettlementData memory settlement =
264241 getCollateralSwapSettlement (user, user, ESUSDS, EWBTC, DEFAULT_SWAP_AMOUNT, DEFAULT_BUY_AMOUNT);
265242
266- // User signs the order and approves vault shares for settlement
267- COW_SETTLEMENT.setPreSignature (settlement.orderUid, true );
243+ // User deposits SUSDS collateral
244+ vm.startPrank (user);
245+ IERC20 (SUSDS).approve (ESUSDS, type (uint256 ).max);
246+ uint256 depositAmount = 1000e18 ;
247+ IERC4626 (ESUSDS).deposit (depositAmount, user);
248+
249+ // User signs the order and approves vault shares for settlement (already done in setupCowOrder)
250+
251+ // Approve spending of the ESUSDS to repay debt
268252 IEVault (ESUSDS).approve (COW_SETTLEMENT.vaultRelayer (), type (uint256 ).max);
269253 vm.stopPrank ();
270254
@@ -307,18 +291,18 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
307291 // Create params using helper
308292 CowEvcCollateralSwapWrapper.CollateralSwapParams memory params = _createDefaultParams (user, account);
309293
294+ // Get settlement data - receiver is the subaccount
295+ SettlementData memory settlement =
296+ getCollateralSwapSettlement (user, account, ESUSDS, EWBTC, DEFAULT_SWAP_AMOUNT, DEFAULT_BUY_AMOUNT);
297+
310298 // User deposits SUSDS collateral to subaccount
311299 vm.startPrank (user);
312300 IERC20 (SUSDS).approve (ESUSDS, type (uint256 ).max);
313301 uint256 depositAmount = 1000e18 ;
314302 IERC4626 (ESUSDS).deposit (depositAmount, account);
315303
316- // Get settlement data - receiver is the subaccount
317- SettlementData memory settlement =
318- getCollateralSwapSettlement (user, account, ESUSDS, EWBTC, DEFAULT_SWAP_AMOUNT, DEFAULT_BUY_AMOUNT);
304+ // User signs the order on cowswap (already done in setupCowOrder)
319305
320- // User signs the order on cowswap
321- COW_SETTLEMENT.setPreSignature (settlement.orderUid, true );
322306 vm.stopPrank ();
323307
324308 // Setup subaccount approvals and pre-approved hash
@@ -416,10 +400,7 @@ contract CowEvcCollateralSwapWrapperTest is CowBaseTest {
416400 SettlementData memory settlement =
417401 getCollateralSwapSettlement (user, account, ESUSDS, EWBTC, sellAmount, buyAmount);
418402
419- // User signs the order on cowswap
420- vm.startPrank (user);
421- COW_SETTLEMENT.setPreSignature (settlement.orderUid, true );
422- vm.stopPrank ();
403+ // User signs the order on cowswap (already done in setupCowOrder)
423404
424405 // Setup subaccount approvals and pre-approved hash
425406 _setupSubaccountApprovals (account, params);
0 commit comments