roll back

This commit is contained in:
TrooperCrypto
2022-03-27 15:39:37 +02:00
parent 819299ad04
commit 4a96390c73

View File

@@ -274,14 +274,12 @@ function isOrderFillable(order) {
return { fillable: true, reason: null, walletId: goodWalletIds[0]};
}
function genQuote(chainId, marketId, side, baseQuantity, quoteQuantity = 0) {
function genQuote(chainId, marketId, side, baseQuantity) {
const market = MARKETS[marketId];
if (CHAIN_ID !== chainId) throw new Error("badchain");
if (!market) throw new Error("badmarket");
if (!(['b','s']).includes(side)) throw new Error("badside");
if (baseQuantity < 0) throw new Error("badbasequantity");
if (quoteQuantity < 0) throw new Error("badquotequantity");
if (baseQuantity === 0 & quoteQuantity === 0) throw new Error("badquantity");
if (baseQuantity <= 0) throw new Error("badquantity");
validatePriceFeed(marketId);
@@ -293,25 +291,17 @@ function genQuote(chainId, marketId, side, baseQuantity, quoteQuantity = 0) {
const primaryPrice = PRICE_FEEDS[mmConfig.priceFeedPrimary];
if (!primaryPrice) throw new Error("badprice");
const SPREAD = mmConfig.minSpread + (baseQuantity * mmConfig.slippageRate);
if (baseQuantity && !quoteQuantity) {
let quoteQuantity;
if (side === 'b') {
quoteQuantity = (baseQuantity * primaryPrice * (1 + SPREAD)) + market.quoteFee;
} else if (side === 's') {
}
else if (side === 's') {
quoteQuantity = (baseQuantity - market.baseFee) * primaryPrice * (1 - SPREAD);
}
} else if (!baseQuantity && quoteQuantity){
if (side === 'b') {
baseQuantity = (quoteQuantity / (primaryPrice * (1 + SPREAD))) + market.baseFee;
} else if (side === 's') {
baseQuantity = (quoteQuantity - market.quoteFee) / (primaryPrice * (1 - SPREAD));
}
} else {
throw new Error("badbase/quotequantity");
}
const quotePrice = (quoteQuantity / baseQuantity).toPrecision(6);
if (quotePrice < 0) throw new Error("Amount is inadequate to pay fee");
if (isNaN(quotePrice)) throw new Error("Internal Error. No price generated.");
return { quotePrice, baseQuantity, quoteQuantity };
return { quotePrice, quoteQuantity };
}
function validatePriceFeed(marketId) {
@@ -358,25 +348,24 @@ async function sendFillRequest(orderreceipt, accountId) {
const side = orderreceipt[3];
const baseQuantity = orderreceipt[5];
const quoteQuantity = orderreceipt[6];
let quote, tokenSell, tokenBuy, sellQuantity, buyQuantity, buySymbol, sellSymbol;
const quote = genQuote(chainId, marketId, side, baseQuantity);
let tokenSell, tokenBuy, sellQuantity, buyQuantity, buySymbol, sellSymbol;
if (side === "b") {
quote = genQuote(chainId, marketId, side, baseQuantity);
tokenSell = market.baseAssetId;
tokenBuy = market.quoteAssetId;
sellSymbol = market.baseAsset.symbol;
buySymbol = market.quoteAsset.symbol;
// Add 1 bip to to protect against rounding errors
sellQuantity = baseQuantity.toFixed(market.baseAsset.decimals); // set by user
buyQuantity = quote.quoteQuantity.toFixed(market.quoteAsset.decimals);
sellQuantity = (baseQuantity * 1.0001).toFixed(market.baseAsset.decimals);
buyQuantity = (quote.quoteQuantity * 0.9999).toFixed(market.quoteAsset.decimals);
} else if (side === "s") {
quote = genQuote(chainId, marketId, side, 0, quoteQuantity);
tokenSell = market.quoteAssetId;
tokenBuy = market.baseAssetId;
sellSymbol = market.quoteAsset.symbol;
buySymbol = market.baseAsset.symbol;
// Add 1 bip to to protect against rounding errors
sellQuantity = quoteQuantity.toFixed(market.quoteAsset.decimals); // set by user
buyQuantity = quote.baseQuantity.toFixed(market.baseAsset.decimals);
sellQuantity = (quote.quoteQuantity * 1.0001).toFixed(market.quoteAsset.decimals);
buyQuantity = (baseQuantity * 0.9999).toFixed(market.baseAsset.decimals);
}
const sellQuantityParsed = syncProvider.tokenSet.parseToken(
tokenSell,