```\n   function emergencyClose(GMXTypes.Store storage self, uint256 deadline) external {\n        // Revert if the status is Paused.\n        GMXChecks.beforeEmergencyCloseChecks(self);\n\n        // Repay all borrowed assets; 1e18 == 100% shareRatio to repay\n        GMXTypes.RepayParams memory _rp;\n        (_rp.repayTokenAAmt, _rp.repayTokenBAmt) = GMXManager.calcRepay(self, 1e18);\n\n        (bool _swapNeeded, address _tokenFrom, address _tokenTo, uint256 _tokenToAmt) =\n            GMXManager.calcSwapForRepay(self, _rp);\n\n        if (_swapNeeded) {\n            ISwap.SwapParams memory _sp;\n\n            _sp.tokenIn = _tokenFrom;\n            _sp.tokenOut = _tokenTo;\n            _sp.amountIn = IERC20(_tokenFrom).balanceOf(address(this));\n            _sp.amountOut = _tokenToAmt;\n            _sp.slippage = self.minSlippage;\n            _sp.deadline = deadline;\n\n            GMXManager.swapTokensForExactTokens(self, _sp);\n        }\n        GMXManager.repay(self, _rp.repayTokenAAmt, _rp.repayTokenBAmt);\n\n        self.status = GMXTypes.Status.Closed;\n\n        emit EmergencyClose(_rp.repayTokenAAmt, _rp.repayTokenBAmt);\n    }\n  }\n```\n