diff --git a/dexs/gambit/index.ts b/dexs/gambit/index.ts index e189fda918..418e9a3a4f 100644 --- a/dexs/gambit/index.ts +++ b/dexs/gambit/index.ts @@ -7,10 +7,11 @@ import { Chain } from "@defillama/sdk/build/general"; const topic0_limit_ex = '0x165b0f8d6347f7ebe92729625b03ace41aeea8fd7ebf640f89f2593ab0db63d1'; const topic0_market_ex = '0x2739a12dffae5d66bd9e126a286078ed771840f2288f0afa5709ce38c3330997'; -const USDC_DECIMAL = 6; +const USDC_DECIMAL = 6 +const LEVERAGE_DECIMAL = 18 type IAddress = { - [s: string | Chain]: string + [s: string | Chain]: string[] } interface ILog { @@ -19,8 +20,9 @@ interface ILog { topics: string[]; } -const contract_address: IAddress = { - [CHAIN.ERA]: '0xE95a6FCC476Dc306749c2Ac62fB4637c27ac578d', +const CONTRACT_ADDRESS: IAddress = { + [CHAIN.ERA]: ['0xE95a6FCC476Dc306749c2Ac62fB4637c27ac578d', "0x6cf71FaeA3771D56e72c72501e7172e79116E2A3", '0x50853A14cD14CC6A891BF034A204A15d294AF056'], + [CHAIN.ARBITRUM]: ['0x8d85f4615ea5F2Ea8D91C196aaD4C04D8416865C'], } const fetch = (chain: Chain) => { @@ -30,37 +32,56 @@ const fetch = (chain: Chain) => { const fromBlock = (await getBlock(fromTimestamp, chain, {})); const toBlock = (await getBlock(toTimestamp, chain, {})); + const contractAddressList = CONTRACT_ADDRESS[chain]; try { - const logs_limit_ex: ILog[] = (await sdk.api.util.getLogs({ - target: contract_address[chain], - topic: '', - toBlock: toBlock, - fromBlock: fromBlock, - keys: [], - chain: chain, - topics: [topic0_limit_ex] - })).output as ILog[]; + const logs_limit_ex: ILog[] = ( + await Promise.all( + contractAddressList.map(async (address) => { + return sdk.api.util.getLogs({ + target: address, + topic: '', + toBlock: toBlock, + fromBlock: fromBlock, + keys: [], + chain: chain, + topics: [topic0_limit_ex], + }); + }) + ) + ).flatMap((response) => (response as any).output) as ILog[]; - const logs_market_ex: ILog[] = (await sdk.api.util.getLogs({ - target: contract_address[chain], - topic: '', - toBlock: toBlock, - fromBlock: fromBlock, - keys: [], - chain: chain, - topics: [topic0_market_ex] - })).output as ILog[]; + const logs_market_ex: ILog[] = ( + await Promise.all( + contractAddressList.map(async (address) => { + return sdk.api.util.getLogs({ + target: address, + topic: '', + toBlock: toBlock, + fromBlock: fromBlock, + keys: [], + chain: chain, + topics: [topic0_market_ex], + }); + }) + ) + ).flatMap((response) => (response as any).output) as ILog[]; const limit_volume = logs_limit_ex.map((e: ILog) => { const data = e.data.replace('0x', ''); - const leverage = Number('0x' + data.slice(512, 576)); + let leverage = Number('0x' + data.slice(448, 512)); + if (leverage > 1000) { + leverage = leverage / 10 ** LEVERAGE_DECIMAL + } const positionSizeUsdc = Number('0x' + data.slice(896, 960)) / 10 ** USDC_DECIMAL; return (leverage * positionSizeUsdc) }).reduce((a: number, b: number) => a + b, 0); const market_volume = logs_market_ex.map((e: ILog) => { const data = e.data.replace('0x', ''); - const leverage = Number('0x' + data.slice(448, 512)); + let leverage = Number('0x' + data.slice(448, 512)); + if (leverage > 1000) { + leverage = leverage / 10 ** LEVERAGE_DECIMAL + } const positionSizeUsdc = Number('0x' + data.slice(832, 896)) / 10 ** USDC_DECIMAL; return (leverage * positionSizeUsdc) }).reduce((a: number, b: number) => a + b, 0); @@ -77,14 +98,16 @@ const fetch = (chain: Chain) => { } } - const adapter: SimpleAdapter = { adapter: { [CHAIN.ERA]: { fetch: fetch(CHAIN.ERA), - start: async () => 1684324400, + start: async () => 1690848000, // 2023/08/01 00:00:00 + }, + [CHAIN.ARBITRUM]: { + fetch: fetch(CHAIN.ARBITRUM), + start: async () => 1698883200, // 2023/11/02 00:00:00 } } }; - export default adapter; diff --git a/fees/gambit.ts b/fees/gambit.ts index 87935d14f9..22e4900ce2 100644 --- a/fees/gambit.ts +++ b/fees/gambit.ts @@ -35,41 +35,46 @@ interface ITx { data: string; } -const FEE_ADDRESS_ERA = "0xE95a6FCC476Dc306749c2Ac62fB4637c27ac578d"; const FEE_ADDRESS = { - [CHAIN.ERA]: FEE_ADDRESS_ERA + [CHAIN.ERA]: ["0xE95a6FCC476Dc306749c2Ac62fB4637c27ac578d", "0x6cf71FaeA3771D56e72c72501e7172e79116E2A3", "0x50853A14cD14CC6A891BF034A204A15d294AF056"], + [CHAIN.ARBITRUM]: ["0x8d85f4615ea5F2Ea8D91C196aaD4C04D8416865C"], }; const BIG_TEN = new BigNumber('10'); const USDC_DECIMAL = 6 -const fetch = (address: string, chain: Chain) => { +const fetch = (addressList: string[], chain: Chain) => { return async (timestamp: number): Promise => { const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp) const yesterdaysTimestamp = getTimestampAtStartOfNextDayUTC(timestamp) const todaysBlock = (await getBlock(todaysTimestamp, chain, {})); const yesterdaysBlock = (await getBlock(yesterdaysTimestamp, chain, {})); - const [devFeeCall, ssFeeCall, referralFeeCall, nftBotFeeCall]: any = await Promise.all( - event.map((e: IEvent) => sdk.api.util.getLogs({ - target: address, - topic: e.name, - toBlock: yesterdaysBlock, - fromBlock: todaysBlock, - keys: [], - chain: chain, - topics: [e.topic] - }))); + const [devFeeCall, ssFeeCall, referralFeeCall, nftBotFeeCall]: any = (await Promise.all( + event.map((e: IEvent) => { + return Promise.all( + addressList.map(async (address) => { + return sdk.api.util.getLogs({ + target: address, + topic: e.name, + toBlock: yesterdaysBlock, + fromBlock: todaysBlock, + keys: [], + chain: chain, + topics: [e.topic], + }); + }) + ); + }) + )).flat(); const devFeeValume = devFeeCall.output.map((p: ITx) => new BigNumber(p.data)).reduce((a: BigNumber, c: BigNumber) => a.plus(c), new BigNumber('0')); const ssFeeVol = ssFeeCall.output.map((p: ITx) => new BigNumber(p.data)).reduce((a: BigNumber, c: BigNumber) => a.plus(c), new BigNumber('0')); const referralFeeVol = referralFeeCall.output.map((p: ITx) => new BigNumber(p.data)).reduce((a: BigNumber, c: BigNumber) => a.plus(c), new BigNumber('0')); const usdcVaultFeeVol = nftBotFeeCall.output.map((p: ITx) => new BigNumber(p.data)).reduce((a: BigNumber, c: BigNumber) => a.plus(c), new BigNumber('0')); - const prices = await getPrices(['coingecko:usdc'], todaysTimestamp); const usdcPrice = prices['coingecko:usdc']?.price || 1; - const dailyRevenue = devFeeValume.plus(ssFeeVol).times(usdcPrice).div(BIG_TEN.pow(USDC_DECIMAL)).toString(); const dailyFees = devFeeValume.plus(ssFeeVol).plus(referralFeeVol).plus(usdcVaultFeeVol).times(usdcPrice).div(BIG_TEN.pow(USDC_DECIMAL)).toString(); return { @@ -85,9 +90,13 @@ const adapter: Adapter = { adapter: { [CHAIN.ERA]: { fetch: fetch(FEE_ADDRESS[CHAIN.ERA], CHAIN.ERA), - start: async () => 1684324400, - } - } -} + start: async () => 1690848000, // 2023/08/01 00:00:00 + }, + [CHAIN.ARBITRUM]: { + fetch: fetch(FEE_ADDRESS[CHAIN.ARBITRUM], CHAIN.ARBITRUM), + start: async () => 1698883200, // 2023/11/02 00:00:00 + }, + }, +}; export default adapter;