function _depositAndCreateTokens(TDS.Storage storage s, uint marginForPurchase, uint tokensToPurchase) external onlySponsorOrApDelegate(s) {
        s._remarginInternal();

        int newTokenNav = _computeNavForTokens(s.currentTokenState.tokenPrice, tokensToPurchase);

        if (newTokenNav < 0) {
            newTokenNav = 0;
        }

        uint positiveTokenNav = _safeUintCast(newTokenNav);

        
        
        uint refund = s._pullSentMargin(marginForPurchase);

        
        uint depositAmount = marginForPurchase.sub(positiveTokenNav);

        
        s._depositInternal(depositAmount);

        
        
        
        
        refund = refund.add(s._createTokensInternal(tokensToPurchase, positiveTokenNav));

        
        s._sendMargin(refund);
    }