Skip to content

Commit

Permalink
👷🏻 🧹 Add withdrawFromMargin helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyrharper committed Jul 10, 2024
1 parent 4ce483e commit 0bec185
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/MarginPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,7 @@ contract MarginPaymaster is IPaymaster, Zap {

uint256 sUSDToWithdrawFromMargin = (costOfGasInUSDC -
availableUSDCInWallet) * 1e12;
/// @dev: note, this impl assumes the user has only one account
/// @dev: further development efforts would be required to support multiple accounts
uint128 accountId = uint128(
snxV3AccountsModule.tokenOfOwnerByIndex(sender, 0)
);
// pull sUSD from margin
perpsMarketSNXV3.modifyCollateral(
accountId,
sUSDId,
-int256(sUSDToWithdrawFromMargin)
);
withdrawFromMargin(sender, sUSDToWithdrawFromMargin);
// zap sUSD into USDC
USDCToSwapForWETH =
_zapOut(sUSDToWithdrawFromMargin) +
Expand All @@ -161,6 +151,23 @@ contract MarginPaymaster is IPaymaster, Zap {
HELPERS
//////////////////////////////////////////////////////////////*/

function withdrawFromMargin(
address sender,
uint256 sUSDToWithdrawFromMargin
) internal {
/// @dev: note, this impl assumes the user has only one account
/// @dev: further development efforts would be required to support multiple accounts
uint128 accountId = uint128(
snxV3AccountsModule.tokenOfOwnerByIndex(sender, 0)
);
// pull sUSD from margin
perpsMarketSNXV3.modifyCollateral(
accountId,
sUSDId,
-int256(sUSDToWithdrawFromMargin)
);
}

function swapUSDCForWETH(uint256 amountIn) internal returns (uint256) {
IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter
.ExactInputSingleParams({
Expand Down

0 comments on commit 0bec185

Please sign in to comment.