-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,3 @@ | ||
// https://developers.paraswap.network/smart-contracts | ||
const chains = [ | ||
"ethereum", | ||
"arbitrum", | ||
"avax", | ||
"bsc", | ||
"fantom", | ||
"optimism", | ||
"polygon", | ||
"base", | ||
"polygon_zkevm", | ||
]; | ||
import { getParaswapAdapter } from "./paraswapApi"; | ||
|
||
import { ChainBlocks, FetchOptions } from "../../adapters/types"; | ||
|
||
const abis = { | ||
"SwappedDirect": "event SwappedDirect(bytes16 uuid, address partner, uint256 feePercent, address initiator, uint8 kind, address indexed beneficiary, address indexed srcToken, address indexed destToken, uint256 srcAmount, uint256 receivedAmount, uint256 expectedAmount)", | ||
"SwappedV3": "event SwappedV3(bytes16 uuid, address partner, uint256 feePercent, address initiator, address indexed beneficiary, address indexed srcToken, address indexed destToken, uint256 srcAmount, uint256 receivedAmount, uint256 expectedAmount)", | ||
} | ||
|
||
const defaultSwapper = '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57' | ||
const fetch = async (timestamp: number, _: ChainBlocks, { createBalances, getLogs, chain, }: FetchOptions) => { | ||
const dailyVolume = createBalances() | ||
let target = defaultSwapper | ||
if (chain === "polygon_zkevm") target = '0xb83b554730d29ce4cb55bb42206c3e2c03e4a40a' | ||
const swappedDirectLogs = await getLogs({ target, eventAbi: abis.SwappedDirect, }) | ||
const swappedV3Logs = await getLogs({ target, eventAbi: abis.SwappedV3, }); | ||
[swappedDirectLogs, swappedV3Logs].flat().forEach((log: any) => { | ||
dailyVolume.add(log.destToken, log.receivedAmount) | ||
}) | ||
return { timestamp, dailyVolume } | ||
}; | ||
|
||
const adapter: any = { adapter: {}, }; | ||
|
||
chains.forEach((chain) => adapter.adapter[chain] = { fetch, start: 1676592000, }); | ||
|
||
export default adapter; | ||
export default getParaswapAdapter("volume"); |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Adapter, FetchResultFees, FetchResultVolume } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getTimestampAtStartOfDayUTC } from "../../utils/date"; | ||
import { Chain } from "@defillama/sdk/build/general"; | ||
import fetchURL from "../../utils/fetchURL"; | ||
|
||
|
||
const feesMMURL = "https://api.paraswap.io/stk/volume-stats/breakdown-by-chain"; | ||
type TChainId = { | ||
[l: string | Chain]: string; | ||
} | ||
const mapChainId: TChainId = { | ||
[CHAIN.ETHEREUM]: '1', | ||
[CHAIN.POLYGON]: '137', | ||
[CHAIN.BSC]: '56', | ||
[CHAIN.AVAX]: '43114', | ||
[CHAIN.FANTOM]: '250', | ||
[CHAIN.ARBITRUM]: '42161', | ||
[CHAIN.OPTIMISM]: '10', | ||
[CHAIN.BASE]: '8453', | ||
[CHAIN.POLYGON_ZKEVM]: '1101' | ||
} | ||
|
||
interface IResponse { | ||
daily: any[]; | ||
allTime: any; | ||
} | ||
|
||
export function getParaswapAdapter(type:"fees"|"volume"){ | ||
const fetch = (chain: Chain) => { | ||
return async (timestamp: number): Promise<FetchResultFees|FetchResultVolume> => { | ||
const timestampToday = getTimestampAtStartOfDayUTC(timestamp) | ||
const response: IResponse = (await fetchURL(feesMMURL)); | ||
const dailyResultFees: any[] = response.daily; | ||
const [totalVolume,totalPartnerRevenue, totalProtocolRevenue]: number[] = response.allTime[mapChainId[chain]]; | ||
const [dailyVolume, partnerRevenue, protocolRevenue]: number[] = dailyResultFees.filter(([time]: any) => time === timestampToday) | ||
.map(([_, data]: any) => data[mapChainId[chain]]).flat() | ||
const otherFees = partnerRevenue + protocolRevenue; | ||
const otherProtocolReveune = protocolRevenue; | ||
|
||
const dailyFees = otherFees; | ||
if (dailyFees > 1_000_000) { | ||
return {} as FetchResultFees; | ||
} | ||
const dailyRevenue = otherProtocolReveune; | ||
const totalFees = totalPartnerRevenue + totalProtocolRevenue; | ||
const totalRevenue = totalProtocolRevenue; | ||
if(type === "fees"){ | ||
return { | ||
dailyFees: dailyFees ? dailyFees.toString() : undefined, | ||
dailyRevenue: dailyRevenue ? dailyRevenue.toString() : undefined, | ||
totalRevenue: totalRevenue ? totalRevenue.toString() : undefined, | ||
totalFees: totalFees ? totalFees.toString(): undefined, | ||
timestamp | ||
} | ||
} else { | ||
return { | ||
dailyVolume: dailyVolume.toString(), | ||
totalVolume: totalVolume.toString(), | ||
timestamp | ||
} | ||
} | ||
} | ||
} | ||
|
||
const adapter: Adapter = { | ||
adapter: Object.keys(mapChainId).reduce((all, chain)=>({ | ||
...all, | ||
[chain]:{ | ||
fetch: fetch(chain), | ||
start: 1647907200, | ||
} | ||
}), {} as any) | ||
} | ||
|
||
return adapter | ||
} |
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,88 +1,3 @@ | ||
import { Adapter, FetchResultFees } from "../adapters/types"; | ||
import { CHAIN } from "../helpers/chains"; | ||
import { getTimestampAtStartOfDayUTC } from "../utils/date"; | ||
import { Chain } from "@defillama/sdk/build/general"; | ||
import fetchURL from "../utils/fetchURL"; | ||
import {getParaswapAdapter} from "../aggregators/paraswap/paraswapApi" | ||
|
||
|
||
const feesMMURL = "https://api.paraswap.io/stk/volume-stats/breakdown-by-chain"; | ||
type TChainId = { | ||
[l: string | Chain]: string; | ||
} | ||
const mapChainId: TChainId = { | ||
[CHAIN.ETHEREUM]: '1', | ||
[CHAIN.POLYGON]: '137', | ||
[CHAIN.BSC]: '56', | ||
[CHAIN.AVAX]: '43114', | ||
[CHAIN.FANTOM]: '250', | ||
[CHAIN.ARBITRUM]: '42161', | ||
[CHAIN.OPTIMISM]: '10', | ||
} | ||
|
||
interface IResponse { | ||
daily: any[]; | ||
allTime: any; | ||
} | ||
|
||
const fetch = (chain: Chain) => { | ||
return async (timestamp: number): Promise<FetchResultFees> => { | ||
const timestampToday = getTimestampAtStartOfDayUTC(timestamp) | ||
const response: IResponse = (await fetchURL(feesMMURL)); | ||
const dailyResultFees: any[] = response.daily; | ||
const [__,totalPartnerRevenue, totalProtocolRevenue]: number[] = response.allTime[mapChainId[chain]]; | ||
const [_, partnerRevenue, protocolRevenue]: number[] = dailyResultFees.filter(([time]: any) => time === timestampToday) | ||
.map(([_, data]: any) => data[mapChainId[chain]]).flat() | ||
const otherFees = partnerRevenue + protocolRevenue; | ||
const otherProtocolReveune = protocolRevenue; | ||
|
||
const dailyFees = otherFees; | ||
if (dailyFees > 1_000_000) { | ||
return {} as FetchResultFees; | ||
} | ||
const dailyRevenue = otherProtocolReveune; | ||
const totalFees = totalPartnerRevenue + totalProtocolRevenue; | ||
const totalRevenue = totalProtocolRevenue; | ||
return { | ||
dailyFees: dailyFees ? dailyFees.toString() : undefined, | ||
dailyRevenue: dailyRevenue ? dailyRevenue.toString() : undefined, | ||
totalRevenue: totalRevenue ? totalRevenue.toString() : undefined, | ||
totalFees: totalFees ? totalFees.toString(): undefined, | ||
timestamp | ||
} | ||
} | ||
} | ||
|
||
const adapter: Adapter = { | ||
adapter: { | ||
[CHAIN.ETHEREUM]: { | ||
fetch: fetch(CHAIN.ETHEREUM), | ||
start: 1647907200, | ||
}, | ||
[CHAIN.POLYGON]: { | ||
fetch: fetch(CHAIN.POLYGON), | ||
start: 1647907200, | ||
}, | ||
[CHAIN.BSC]: { | ||
fetch: fetch(CHAIN.BSC), | ||
start: 1647907200, | ||
}, | ||
[CHAIN.AVAX]: { | ||
fetch: fetch(CHAIN.AVAX), | ||
start: 1647907200, | ||
}, | ||
[CHAIN.FANTOM]: { | ||
fetch: fetch(CHAIN.FANTOM), | ||
start: 1647907200, | ||
}, | ||
[CHAIN.ARBITRUM]: { | ||
fetch: fetch(CHAIN.ARBITRUM), | ||
start: 1647907200, | ||
}, | ||
[CHAIN.OPTIMISM]: { | ||
fetch: fetch(CHAIN.OPTIMISM), | ||
start: 1647907200, | ||
} | ||
} | ||
} | ||
|
||
export default adapter; | ||
export default getParaswapAdapter("fees"); |