-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 2fb55c1.
- Loading branch information
Showing
2 changed files
with
107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,99 @@ | ||
import { FetchOptions, } from "../../adapters/types"; | ||
import ADDRESSES from '../../helpers/coreAssets.json' | ||
import * as sdk from "@defillama/sdk"; | ||
import { getBlock } from "../../helpers/getBlock"; | ||
import { getPrices } from "../../utils/prices"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { FetchResultFees } from "../../adapters/types"; | ||
|
||
interface ILog { | ||
address: string; | ||
data: string; | ||
transactionHash: string; | ||
topics: string[]; | ||
} | ||
|
||
interface IAmount { | ||
creator_fee: number; | ||
marketplace_fee: number; | ||
isHaveMPFees: boolean; | ||
} | ||
|
||
interface IConrtact { | ||
adddress: string; | ||
startBlcok: number; | ||
} | ||
|
||
const contract_v1_4 = '0x00000000000001ad428e4906ae43d8f9852d0dd6'; | ||
const contract_v1_5 = '0x00000000000000adc04c56bf30ac9d3c0aaf14dc'; | ||
const contract_v1_6 = '0x0000000000000068F116a894984e2DB1123eB395'; | ||
|
||
const contracts: IConrtact[] = [ | ||
{ | ||
adddress: contract_v1_4, | ||
startBlcok: 16655960, | ||
}, | ||
{ | ||
adddress: contract_v1_5, | ||
startBlcok: 17129405, | ||
} | ||
] | ||
const topic0 = '0x9d9af8e38d66c62e2c12f0225249fd9d721c54b83f48d9352c97c6cacdcb6f31'; | ||
const event_order_fulfilled = "event OrderFulfilled(bytes32 orderHash, address indexed offerer, address indexed zone, address recipient, (uint8 itemType, address token, uint256 identifier, uint256 amount)[] offer, (uint8 itemType, address token, uint256 identifier, uint256 amount, address recipient)[] consideration)" | ||
const fees_collectors = new Set(['0x0000a26b00c1f0df003000390027140000faa719', '0x31314e41E743A638FD485d537F4a2B5F57D662bb', '0x1208e7F7AED9d39Ed25ef582B8933e4a1D0DA6af'].map(i => i.toLowerCase())); | ||
|
||
export const fetch = async ({ createBalances, getLogs, }: FetchOptions) => { | ||
const dailyFees = createBalances() | ||
const dailyRevenue = createBalances() | ||
const fees_collector = '0x0000a26b00c1f0df003000390027140000faa719'; | ||
|
||
const logs = await getLogs({ targets: [contract_v1_4, contract_v1_5, contract_v1_6], eventAbi: event_order_fulfilled, }) | ||
export const fetch = async (timestamp: number): Promise<FetchResultFees> => { | ||
const fromTimestamp = timestamp - 60 * 60 * 24 | ||
const toTimestamp = timestamp | ||
const fromBlock = (await getBlock(fromTimestamp, CHAIN.ETHEREUM, {})); | ||
const toBlock = (await getBlock(toTimestamp, CHAIN.ETHEREUM, {})); | ||
const logs: ILog[] = (await Promise.all(contracts.filter(e => e.startBlcok <= fromBlock).map((contract: IConrtact) => sdk.getEventLogs({ | ||
target: contract.adddress, | ||
toBlock: toBlock, | ||
fromBlock: fromBlock, | ||
chain: CHAIN.ETHEREUM, | ||
topics: [topic0] | ||
})))).flat() as ILog[]; | ||
|
||
logs.forEach(log => { | ||
if (log.consideration.length < 2) return; | ||
const biggestValue = log.consideration.reduce((a: any, b: any) => a.amount > b.amount ? a : b).amount | ||
const fes_raw: IAmount[] = logs.filter(e => e.data.length === 1602) | ||
.map((e: ILog) => { | ||
const data = e.data.replace('0x', ''); | ||
const fees_1 = Number('0x' + data.slice(18 * 64, (18 * 64) + 64)) / 10 ** 18; | ||
const address_1 = data.slice((19 * 64), (19 * 64) + 64); | ||
const contract_address_1 = '0x' + address_1.slice(24, address_1.length); | ||
|
||
log.consideration.forEach((consideration: any) => { | ||
if (consideration.amount >= biggestValue) return; // this is sent to the NFT owner, rest are fees | ||
dailyFees.add(consideration.token, consideration.amount) | ||
if (fees_collectors.has(consideration.recipient.toLowerCase())) { | ||
dailyRevenue.add(consideration.token, consideration.amount) | ||
const fees_2 = Number('0x' + data.slice(23 * 64, (23 * 64) + 64)) / 10 ** 18; | ||
const address_2 = data.slice((24 * 64), (24 * 64) + 64); | ||
const contract_address_2 = '0x' + address_2.slice(24, address_2.length); | ||
const min = Math.min(fees_1, fees_2); | ||
const max = Math.max(fees_1, fees_2); | ||
const isHaveMPFees = [contract_address_1.toLowerCase(), contract_address_2.toLowerCase()].includes(fees_collector.toLowerCase()); | ||
return { | ||
creator_fee: max, | ||
marketplace_fee: min, | ||
isHaveMPFees | ||
} | ||
}) | ||
}) | ||
|
||
const marketplace_fee = fes_raw | ||
.filter(e => e.isHaveMPFees) | ||
.map(e => e.marketplace_fee as number) | ||
.filter((e) => !isNaN(e)) | ||
.filter(e => e < 100) | ||
.reduce((a: number, b: number) => a + b, 0) | ||
|
||
const creator_fee = fes_raw.map(e => e.creator_fee as number) | ||
.filter((e) => !isNaN(e)) | ||
.filter(e => e < 100) | ||
.reduce((a: number, b: number) => a + b, 0) | ||
|
||
const fees = (marketplace_fee + creator_fee); | ||
const rev = (marketplace_fee); | ||
const ethAddress = "ethereum:" + ADDRESSES.null; | ||
const ethPrice = (await getPrices([ethAddress], timestamp))[ethAddress].price; | ||
const dailyFees = (fees * ethPrice) | ||
const dailyRevenue = (rev * ethPrice) | ||
return { | ||
dailyFees, dailyRevenue, | ||
dailyFees: `${dailyFees}`, | ||
dailyRevenue: `${dailyRevenue}`, | ||
timestamp | ||
} | ||
|
||
} |