-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Canonic volume and fees adapters (MegaETH) #5832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,38 @@ | ||
| import { FetchOptions, SimpleAdapter } from "../../adapters/types"; | ||
| import { CHAIN } from "../../helpers/chains"; | ||
|
|
||
| const USDM = '0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7' | ||
|
|
||
| const MAOBS = [ | ||
| '0xaD7e5CBfB535ceC8d2E58Dca17b11d9bA76f555E', // BTC.b / USDm | ||
| '0x23469683e25b780DFDC11410a8e83c923caDF125', // WETH / USDm | ||
| '0xDf1576c3C82C9f8B759C69f4cF256061C6Fe1f9e', // USDT0 / USDm | ||
| ] | ||
|
|
||
| const EVENT_ABI = 'event RungFilled(address indexed taker, bool indexed isBuy, uint16 indexed rung, uint256 baseAmount, uint256 quoteAmount, uint256 priceE18)' | ||
|
|
||
| const fetch = async (options: FetchOptions) => { | ||
| const dailyVolume = options.createBalances() | ||
|
|
||
| for (const maob of MAOBS) { | ||
| const logs = await options.getLogs({ target: maob, eventAbi: EVENT_ABI }) | ||
| for (const log of logs) { | ||
| // quoteAmount is denominated in USDm (USD-pegged) for all markets | ||
| dailyVolume.add(USDM, log.quoteAmount) | ||
| } | ||
| } | ||
|
|
||
| return { dailyVolume } | ||
| } | ||
|
|
||
| const adapter: SimpleAdapter = { | ||
| version: 2, | ||
| adapter: { | ||
| [CHAIN.MEGAETH]: { | ||
| fetch, | ||
| start: '2026-02-09', // TODO: update to actual first trade date | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| export default adapter | ||
This file contains hidden or 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,74 @@ | ||
| import { FetchOptions, SimpleAdapter } from "../../adapters/types"; | ||
| import { CHAIN } from "../../helpers/chains"; | ||
|
|
||
| const USDM = '0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7' | ||
| const BTC_B = '0xB0F70C0bD6FD87dbEb7C10dC692a2a6106817072' | ||
| const WETH = '0x4200000000000000000000000000000000000006' | ||
| const USDT0 = '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb' | ||
|
|
||
| const FEE_DENOM = 1_000_000n | ||
|
|
||
| const MAOBS = [ | ||
| { address: '0xaD7e5CBfB535ceC8d2E58Dca17b11d9bA76f555E', base: BTC_B, quote: USDM }, // BTC.b / USDm | ||
| { address: '0x23469683e25b780DFDC11410a8e83c923caDF125', base: WETH, quote: USDM }, // WETH / USDm | ||
| { address: '0xDf1576c3C82C9f8B759C69f4cF256061C6Fe1f9e', base: USDT0, quote: USDM }, // USDT0 / USDm | ||
| ] | ||
|
|
||
| const EVENT_ABI = 'event RungFilled(address indexed taker, bool indexed isBuy, uint16 indexed rung, uint256 baseAmount, uint256 quoteAmount, uint256 priceE18)' | ||
|
|
||
| const fetch = async (options: FetchOptions) => { | ||
| const dailyFees = options.createBalances() | ||
| const dailyVolume = options.createBalances() | ||
|
|
||
| for (const maob of MAOBS) { | ||
| const takerFee = await options.api.call({ target: maob.address, abi: 'uint32:takerFee' }) | ||
| const logs = await options.getLogs({ target: maob.address, eventAbi: EVENT_ABI }) | ||
|
|
||
| for (const log of logs) { | ||
| dailyVolume.add(maob.quote, log.quoteAmount) | ||
|
|
||
| // Buy: fee charged on base output; Sell: fee charged on quote output | ||
| // Use ceiling division to match on-chain Math.Rounding.Ceil | ||
| const takerFeeBig = BigInt(takerFee) | ||
| if (log.isBuy) { | ||
| const amount = BigInt(log.baseAmount) | ||
| const fee = (amount * takerFeeBig + FEE_DENOM - 1n) / FEE_DENOM | ||
| dailyFees.add(maob.base, fee) | ||
| } else { | ||
| const amount = BigInt(log.quoteAmount) | ||
| const fee = (amount * takerFeeBig + FEE_DENOM - 1n) / FEE_DENOM | ||
| dailyFees.add(maob.quote, fee) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| dailyVolume, | ||
| dailyFees, | ||
| dailyUserFees: dailyFees, | ||
| dailyRevenue: dailyFees, // 100% of fees go to protocol | ||
| dailyProtocolRevenue: dailyFees, // collected by feeCollector | ||
| dailySupplySideRevenue: 0, // LPs earn from spread, not from fees | ||
| } | ||
| } | ||
|
|
||
| const adapter: SimpleAdapter = { | ||
| version: 2, | ||
| adapter: { | ||
| [CHAIN.MEGAETH]: { | ||
| fetch, | ||
| start: '2026-02-09', // TODO: update to actual first trade date | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| meta: { | ||
| methodology: { | ||
| Fees: 'Taker fees charged on every trade. Buy orders pay fees in the base token, sell orders pay in the quote token.', | ||
| UserFees: 'Same as Fees — all fees are paid by takers.', | ||
| Revenue: '100% of taker fees are sent to the protocol fee collector.', | ||
| ProtocolRevenue: 'All collected fees go to the protocol treasury.', | ||
| SupplySideRevenue: 'CLP vault LPs earn from market-making spread, not from protocol fees.', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| export default adapter | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.