Skip to content

Commit

Permalink
enable different fee tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtrooper committed Apr 2, 2022
1 parent 6d42268 commit 9a7620d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion marketmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MARKETS = {};
const CHAINLINK_PROVIDERS = {};
const UNISWAP_V3_PROVIDERS = {};
const PAST_ORDER_LIST = {};
const FEE_TOKENS = [];

let uniswap_error_counter = 0;
let chainlink_error_counter = 0;
Expand Down Expand Up @@ -195,6 +196,18 @@ async function handleMessage(json) {
const newBaseFee = MARKETS[marketId].baseFee;
const newQuoteFee = MARKETS[marketId].quoteFee;
console.log(`marketinfo ${marketId} - update baseFee ${oldBaseFee} -> ${newBaseFee}, quoteFee ${oldQuoteFee} -> ${newQuoteFee}`);
if(
marketInfo.baseAsset.enabledForFees &&
!FEE_TOKENS.includes(marketInfo.baseAsset.id)
) {
FEE_TOKENS.push(marketInfo.baseAsset.id);
}
if(
marketInfo.quoteAsset.enabledForFees &&
!FEE_TOKENS.includes(marketInfo.quoteAsset.id)
) {
FEE_TOKENS.push(marketInfo.quoteAsset.id);
}
break
default:
break
Expand Down Expand Up @@ -415,11 +428,15 @@ async function broadcastFill(chainId, orderId, swapOffer, fillOrder, wallet) {
zigzagws.send(JSON.stringify(orderCommitMsg));
return;
}
// select token to match user's fee token
const feeToken = (FEE_TOKENS.includes(swapOffer.tokenSell))
? swapOffer.tokenSell
: 0
const randInt = (Math.random()*1000).toFixed(0);
console.time('syncswap' + randInt);
const swap = await wallet['syncWallet'].syncSwap({
orders: [swapOffer, fillOrder],
feeToken: "ETH",
feeToken: feeToken,
nonce: fillOrder.nonce
});
const txHash = swap.txHash.split(":")[1];
Expand Down

0 comments on commit 9a7620d

Please sign in to comment.