Skip to content

Commit

Permalink
Fix Ethfinex v1 fee #69
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaBalances committed Apr 12, 2019
1 parent eafaa02 commit df45e7f
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 228 deletions.
42 changes: 35 additions & 7 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4328,7 +4328,7 @@ DeltaBalances.prototype.processUnpackedInput = function (tx, unpacked) {
}

}
// 0x v1 trade input
// 0x v1 trade input, ethfinex v1 input
// 0x v2 trade input
// 0x v2 Forwarder input
else if (unpacked.name === 'fillOrder' // 0xv1 0xv2
Expand Down Expand Up @@ -6873,8 +6873,11 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
};
}
}
// 0x v1 & v2 trade output event
// 0x v1 & v2 trade output event, (ethfinex)
else if (unpacked.name == "LogFill" || unpacked.name == "Fill") {
//ethfinex uses a forked 0x v1 contract
const isEthfinex = (unpacked.address.toLowerCase() == '0xdcdb42c9a256690bd153a7b409751adfc8dd5851');

//0x v1: LogFill (index_topic_1 address maker, address taker, index_topic_2 address feeRecipient, address makerToken, address takerToken, uint256 filledMakerTokenAmount, uint256 filledTakerTokenAmount, uint256 paidMakerFee, uint256 paidTakerFee, index_topic_3 bytes32 tokens, bytes32 orderHash)
/* v2: event Fill(
address indexed makerAddress, // Address that created the order.
Expand All @@ -6890,7 +6893,7 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
bytes takerAssetData // Encoded data specific to takerAsset.
); */

let maker, taker, makerToken, takerToken, makerAmount, takerAmount, makerFee, takerFee, relayer, sender;
let maker, taker, makerToken, takerToken, makerAmount, takerAmount, makerFee, takerFee, relayer, sender, ethfinexFee;
//zrx fee
let feeCurrency = this.setToken('0xe41d2489571d322189246dafa5ebde1f4699f498');

Expand All @@ -6909,6 +6912,12 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
takerFee = utility.weiToToken(unpacked.events[8].value, feeCurrency);

relayer = unpacked.events[2].value.toLowerCase();

if (isEthfinex) {
feeCurrency = takerToken;
ethfinexFee = new BigNumber(unpacked.events[6].value).div(400);
makerFee = utility.weiToToken(ethfinexFee, feeCurrency);
}
}
//0x v2
else {
Expand Down Expand Up @@ -6961,7 +6970,6 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
transType = 'Maker';
}


if (this.isBaseToken(takerToken, makerToken)) // get eth -> sell
{
tradeType = 'Buy';
Expand Down Expand Up @@ -7000,6 +7008,16 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
price = baseAmount.div(amount);
}

if (isEthfinex) {
if (tradeType === 'Sell') {
rawAmount = takerAmount.minus(ethfinexFee);
amount = utility.weiToToken(rawAmount, token);
} else {
rawBaseAmount = takerAmount.minus(ethfinexFee);
baseAmount = utility.weiToToken(rawBaseAmount, base);
}
}

// single units if erc721
if (token.erc721) {
amount = new BigNumber(1);
Expand All @@ -7018,13 +7036,17 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
} else {
fee = takerFee;
}
if (isEthfinex) {
feeCurrency = takerToken;
}

if (isMyAddress(buyUser))
if (isMyAddress(buyUser)) {
tradeType = "Buy";
else if (isMyAddress(sellUser))
} else if (isMyAddress(sellUser)) {
tradeType = "Sell";
}

return {
let obj = {
'type': transType + ' ' + tradeType,
'exchange': exchange,
'note': utility.addressLink(taker, true, true) + ' selected ' + utility.addressLink(maker, true, true) + '\'s order in the orderbook to trade.',
Expand All @@ -7037,11 +7059,17 @@ DeltaBalances.prototype.processUnpackedEvent = function (unpacked, myAddresses)
'buyer': buyUser,
'seller': sellUser,
'fee': fee,
'makerFee': makerFee, //ethfinex v1
'feeCurrency': feeCurrency,
'transType': transType,
'tradeType': tradeType,
'relayer': relayer
};

if (!isEthfinex) {
delete obj.makerFee;
}
return obj;
}
}
//Bancor trade
Expand Down
Loading

0 comments on commit df45e7f

Please sign in to comment.