-
Notifications
You must be signed in to change notification settings - Fork 89
/
utils.js
40 lines (31 loc) · 1.06 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// external
const { ethers } = require('ethers');
// local
const { currencies } = require('./currencies.js');
function _reducer(previous, current) {
const currency = currencies[current.token.toLowerCase()];
if (currency !== undefined) {
const result = previous + Number(ethers.utils.formatUnits(current.amount, currency.decimals));
return result;
} else {
return previous;
}
}
function getSeaportSalePrice(decodedLogData) {
const offer = decodedLogData.offer;
const consideration = decodedLogData.consideration;
const offerSideNfts = offer.some(
(item) => item.token.toLowerCase() === process.env.CONTRACT_ADDRESS.toLowerCase()
);
// if nfts are on the offer side, then consideration is the total price, otherwise the offer is the total price
if (offerSideNfts) {
const totalConsiderationAmount = consideration.reduce(_reducer, 0);
return totalConsiderationAmount;
} else {
const totalOfferAmount = offer.reduce(_reducer, 0);
return totalOfferAmount;
}
}
module.exports = {
getSeaportSalePrice: getSeaportSalePrice,
};