forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Boson protocol volume #2
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
Open
zajck
wants to merge
11
commits into
master
Choose a base branch
from
boson-fees-volume
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0ec84b6
Calculate protocol fee
zajck 0971424
rename `encumberedByToken` -> `collectedByToken`
zajck 7b39263
Daily volume calculation
zajck 125fa7f
Initial plan
Copilot 17ad86b
Update dexs/boson/utils.ts
zajck df175b9
Apply suggestions from code review
zajck 943936e
Merge pull request #3 from bosonprotocol/copilot/sub-pr-2
levalleux-ludo 3453893
Update daily volume calculation
zajck fb54e67
Merge branch 'boson-fees-volume' of github.com:bosonprotocol/dimensio…
zajck 3f1f7db
Update methodology.
zajck 7e3b8ba
remove dex adapter
zajck 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,37 @@ | ||
| export const protocolDiamondAddress = | ||
| "0x59A4C19b55193D5a2EAD0065c54af4d516E18Cb5"; | ||
|
|
||
| /** Event topics **/ | ||
| export const fundsEncumberedTopic = | ||
| "0x8080d30eb13935d67dfdc606fa5e4170aa03ffdfaf40136ef3fa4355c88b19f9"; | ||
| export const offerCreatedTopic_v2_0_0 = | ||
| "0x845c99b8425be384387e239b85d44b6cdf63aab6c45c2534f799743e341c74f8"; | ||
| export const offerCreatedTopic_v2_3_0 = | ||
| "0xb6a507882e43ec6bae2f276ce4a839f1ca9dcf2da73095eea9e633e96ecf6eb2"; | ||
| export const offerCreatedTopic_v2_4_0 = | ||
| "0xa76af238b31b285c9397e2a7c55650ca18a1baf6504de15d7dd1321693144cf7"; | ||
| export const offerCreatedTopic_v2_5_0 = | ||
| "0x5235a4f9db2e479e7353e22e7629a4556897ddaf0ab4eaeb9bb8660c8e49a903"; | ||
| export const rangeReservedTopic = | ||
| "0xede05ffdb8c59f6f9e12923efcf03736da40cda9a4c5ba60ac2b6238b8b86a60"; | ||
|
|
||
| /** Event definitions **/ | ||
| /** | ||
| * Some event changed over time, but kept their name, so we define multiple versions here | ||
| */ | ||
| export const OfferCreatedEvent_v2_0_0 = | ||
| "event OfferCreated(uint256 indexed offerId, uint256 indexed sellerId, (uint256 id, uint256 sellerId, uint256 price, uint256 sellerDeposit, uint256 buyerCancelPenalty, uint256 quantityAvailable, address exchangeToken, string metadataUri, string metadataHash, bool voided) offer, (uint256 validFrom, uint256 validUntil, uint256 voucherRedeemableFrom, uint256 voucherRedeemableUntil) offerDates, (uint256 disputePeriod, uint256 voucherValid, uint256 resolutionPeriod) offerDurations, (uint256 disputeResolverId, uint256 escalationResponsePeriod, uint256 feeAmount, uint256 buyerEscalationDeposit) disputeResolutionTerms, (uint256 protocolFee, uint256 agentFee) offerFees, uint256 indexed agentId, address executedBy)"; | ||
| export const OfferCreatedEvent_v2_3_0 = | ||
| "event OfferCreated(uint256 indexed offerId, uint256 indexed sellerId, (uint256 id, uint256 sellerId, uint256 price, uint256 sellerDeposit, uint256 buyerCancelPenalty, uint256 quantityAvailable, address exchangeToken, string metadataUri, string metadataHash, bool voided, uint256 collectionIndex) offer, (uint256 validFrom, uint256 validUntil, uint256 voucherRedeemableFrom, uint256 voucherRedeemableUntil) offerDates, (uint256 disputePeriod, uint256 voucherValid, uint256 resolutionPeriod) offerDurations, (uint256 disputeResolverId, uint256 escalationResponsePeriod, uint256 feeAmount, uint256 buyerEscalationDeposit) disputeResolutionTerms, (uint256 protocolFee, uint256 agentFee) offerFees, uint256 indexed agentId, address executedBy)"; | ||
| export const OfferCreatedEvent_v2_4_0 = | ||
| "event OfferCreated(uint256 indexed offerId, uint256 indexed sellerId, (uint256 id, uint256 sellerId, uint256 price, uint256 sellerDeposit, uint256 buyerCancelPenalty, uint256 quantityAvailable, address exchangeToken, uint8 priceType, string metadataUri, string metadataHash, bool voided, uint256 collectionIndex, (address[] recipients, uint256[] bps)[] royaltyInfo) offer, (uint256 validFrom, uint256 validUntil, uint256 voucherRedeemableFrom, uint256 voucherRedeemableUntil) offerDates, (uint256 disputePeriod, uint256 voucherValid, uint256 resolutionPeriod) offerDurations, (uint256 disputeResolverId, uint256 escalationResponsePeriod, uint256 feeAmount, uint256 buyerEscalationDeposit) disputeResolutionTerms, (uint256 protocolFee, uint256 agentFee) offerFees, uint256 indexed agentId, address executedBy)"; | ||
| export const OfferCreatedEvent_v2_5_0 = | ||
| "event OfferCreated(uint256 indexed offerId, uint256 indexed sellerId, (uint256 id, uint256 sellerId, uint256 price, uint256 sellerDeposit, uint256 buyerCancelPenalty, uint256 quantityAvailable, address exchangeToken, uint8 priceType, uint8 creator, string metadataUri, string metadataHash, bool voided, uint256 collectionIndex, (address[] recipients, uint256[] bps)[] royaltyInfo, uint256 buyerId) offer, (uint256 validFrom, uint256 validUntil, uint256 voucherRedeemableFrom, uint256 voucherRedeemableUntil) offerDates, (uint256 disputePeriod, uint256 voucherValid, uint256 resolutionPeriod) offerDurations, (uint256 disputeResolverId, uint256 escalationResponsePeriod, uint256 feeAmount, uint256 buyerEscalationDeposit, address mutualizerAddress) disputeResolutionTerms, (uint256 protocolFee, uint256 agentFee) offerFees, uint256 indexed agentId, address executedBy)"; | ||
| export const RangeReservedEvent = | ||
| "event RangeReserved(uint256 indexed offerId, uint256 indexed sellerId, uint256 startExchangeId, uint256 endExchangeId, address owner, address indexed executedBy)"; | ||
| export const FundsEncumberedEvent = | ||
| "event FundsEncumbered(uint256 indexed entityId, address indexed exchangeToken, uint256 amount, address indexed executedBy)"; | ||
|
|
||
| /** Contract Methods */ | ||
| export const getOffer_v2_5_0 = | ||
| "function getOffer(uint256 _offerId) view returns (bool exists, (uint256 id, uint256 sellerId, uint256 price, uint256 sellerDeposit, uint256 buyerCancelPenalty, uint256 quantityAvailable, address exchangeToken, uint8 priceType, uint8 creator, string metadataUri, string metadataHash, bool voided, uint256 collectionIndex, (address[] recipients, uint256[] bps)[] royaltyInfo, uint256 buyerId) offer, (uint256 validFrom, uint256 validUntil, uint256 voucherRedeemableFrom, uint256 voucherRedeemableUntil) offerDates, (uint256 disputePeriod, uint256 voucherValid, uint256 resolutionPeriod) offerDurations, (uint256 disputeResolverId, uint256 escalationResponsePeriod, uint256 feeAmount, uint256 buyerEscalationDeposit, address mutualizerAddress) disputeResolutionTerms, (uint256 protocolFee, uint256 agentFee) offerFees)"; |
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,42 @@ | ||
| import { Adapter, FetchOptions, FetchResultV2 } from "../../adapters/types"; | ||
| import { CHAIN } from "../../helpers/chains"; | ||
| import { getEncumberedFunds, getNewOffers, getReservedRanges } from "./utils"; | ||
|
|
||
| async function getProtocolVolume( | ||
| options: FetchOptions | ||
| ): Promise<FetchResultV2> { | ||
| const { createBalances } = options; | ||
| const dailyVolume = createBalances(); | ||
|
|
||
| const volumeByToken: Record<string, bigint> = {}; | ||
|
|
||
| await getEncumberedFunds(options, volumeByToken); | ||
| await getNewOffers(options, volumeByToken); | ||
| await getReservedRanges(options, volumeByToken); | ||
|
|
||
| for (const [token, amount] of Object.entries(volumeByToken)) { | ||
| dailyVolume.add(token, amount); | ||
| } | ||
|
|
||
| return { | ||
| dailyVolume, | ||
| }; | ||
| } | ||
|
|
||
| const adapter: Adapter = { | ||
| fetch: getProtocolVolume, | ||
| adapter: { | ||
| [CHAIN.POLYGON]: { start: "2022-10-12" }, | ||
| [CHAIN.ETHEREUM]: { start: "2023-09-29" }, | ||
| [CHAIN.BASE]: { start: "2025-01-31" }, | ||
| [CHAIN.ARBITRUM]: { start: "2025-04-01" }, | ||
| [CHAIN.OPTIMISM]: { start: "2025-03-10" }, | ||
| }, | ||
| version: 2, | ||
| methodology: { | ||
| Volume: | ||
| "Sum of funds encumbered in exchanges and total value of newly created offers on the Boson Protocol.", | ||
|
zajck marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }; | ||
|
|
||
| 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,108 @@ | ||
| import { ethers, MaxUint256 } from "ethers"; | ||
| import { FetchOptions } from "../../adapters/types"; | ||
|
|
||
| import { | ||
| protocolDiamondAddress, | ||
| fundsEncumberedTopic, | ||
| offerCreatedTopic_v2_0_0, | ||
| offerCreatedTopic_v2_3_0, | ||
| offerCreatedTopic_v2_4_0, | ||
| offerCreatedTopic_v2_5_0, | ||
| rangeReservedTopic, | ||
| OfferCreatedEvent_v2_0_0, | ||
| OfferCreatedEvent_v2_3_0, | ||
| OfferCreatedEvent_v2_4_0, | ||
| OfferCreatedEvent_v2_5_0, | ||
| RangeReservedEvent, | ||
| FundsEncumberedEvent, | ||
| getOffer_v2_5_0, | ||
| } from "./constants"; | ||
|
|
||
| export async function getNewOffers( | ||
| { getLogs }: FetchOptions, | ||
| volumeByToken: Record<string, bigint> | ||
| ) { | ||
| const response = await getLogs({ | ||
| target: protocolDiamondAddress, | ||
| topics: [ | ||
| [ | ||
| offerCreatedTopic_v2_0_0, | ||
| offerCreatedTopic_v2_3_0, | ||
| offerCreatedTopic_v2_4_0, | ||
| offerCreatedTopic_v2_5_0, | ||
| ], | ||
| ], | ||
| }); | ||
|
|
||
| // Combine all versions of the OfferCreated event | ||
| const iface = new ethers.Interface([ | ||
| OfferCreatedEvent_v2_0_0, | ||
| OfferCreatedEvent_v2_3_0, | ||
| OfferCreatedEvent_v2_4_0, | ||
| OfferCreatedEvent_v2_5_0, | ||
| ]); | ||
|
|
||
| const offerLogs = response.map((log) => { | ||
| return iface.parseLog(log)?.args; | ||
| }); | ||
|
zajck marked this conversation as resolved.
Outdated
|
||
|
|
||
| for (const offer of offerLogs) { | ||
| const quantityAvailable = BigInt(offer.offer.quantityAvailable); | ||
| if (quantityAvailable === MaxUint256) continue; // skip unlimited offers | ||
|
|
||
| const price = BigInt(offer.offer.price); | ||
| const amount = quantityAvailable * price; | ||
| const token = offer.offer.exchangeToken; | ||
| volumeByToken[token] = (volumeByToken[token] || 0n) + amount; | ||
| } | ||
| } | ||
|
|
||
| export async function getReservedRanges( | ||
| { getLogs, api }: FetchOptions, | ||
| volumeByToken: Record<string, bigint> | ||
| ) { | ||
| // only for unlimited offers, since they are not counted in getNewOffers | ||
| const logs = await getLogs({ | ||
| target: protocolDiamondAddress, | ||
| topics: [rangeReservedTopic], | ||
| eventAbi: RangeReservedEvent, | ||
| }); | ||
|
|
||
| for (const log of logs) { | ||
| const offerId = BigInt(log.offerId); | ||
| const startExchangeId = BigInt(log.startExchangeId); | ||
| const endExchangeId = BigInt(log.endExchangeId); | ||
| const quantityAvailable = endExchangeId - startExchangeId + 1n; | ||
|
|
||
| // get offer details | ||
| const [, offer] = await api.call({ | ||
|
levalleux-ludo marked this conversation as resolved.
Outdated
|
||
| target: protocolDiamondAddress, | ||
| abi: getOffer_v2_5_0, | ||
| params: [offerId.toString()], | ||
| }); | ||
|
zajck marked this conversation as resolved.
Outdated
|
||
|
|
||
|
zajck marked this conversation as resolved.
Outdated
|
||
| if (offer.quantityAvailable !== MaxUint256) continue; // skip limited offers | ||
|
zajck marked this conversation as resolved.
Outdated
|
||
|
|
||
| const price = BigInt(offer.price); | ||
| const amount = quantityAvailable * price; | ||
| const token = offer.exchangeToken; | ||
| volumeByToken[token] = (volumeByToken[token] || 0n) + amount; | ||
| } | ||
| } | ||
|
|
||
| export async function getEncumberedFunds( | ||
| { getLogs }: FetchOptions, | ||
| volumeByToken: Record<string, bigint> | ||
| ) { | ||
| const FundsEncumberedLogs = await getLogs({ | ||
| target: protocolDiamondAddress, | ||
| topics: [fundsEncumberedTopic], | ||
| eventAbi: FundsEncumberedEvent, | ||
| }); | ||
|
|
||
| for (const log of FundsEncumberedLogs) { | ||
| const token = log.exchangeToken; | ||
| const amount = BigInt(log.amount); | ||
| volumeByToken[token] = (volumeByToken[token] || 0n) + amount; | ||
| } | ||
| } | ||
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,53 @@ | ||
| import { Adapter, FetchOptions, FetchResultV2 } from "../../adapters/types"; | ||
| import { CHAIN } from "../../helpers/chains"; | ||
|
|
||
| const ProtocolFeeCollectedEvent = | ||
| "event ProtocolFeeCollected(uint256 indexed exchangeId, address indexed exchangeToken, uint256 amount, address indexed executedBy)"; | ||
|
zajck marked this conversation as resolved.
|
||
| const protocolFeeCollectedTopic = | ||
| "0x9399ed37d26489264206ddf87ad81aaa13557b4e56b5443503a2b64a24ec42db"; | ||
|
zajck marked this conversation as resolved.
|
||
| const protocolDiamondAddress = "0x59A4C19b55193D5a2EAD0065c54af4d516E18Cb5"; | ||
|
zajck marked this conversation as resolved.
|
||
|
|
||
| async function getProtocolFees(options: FetchOptions): Promise<FetchResultV2> { | ||
| const { getLogs, createBalances } = options; | ||
| const dailyFees = createBalances(); | ||
|
|
||
| const logs = await getLogs({ | ||
| target: protocolDiamondAddress, | ||
| topics: [protocolFeeCollectedTopic], | ||
| eventAbi: ProtocolFeeCollectedEvent, | ||
| }); | ||
|
|
||
| const collectedByToken: Record<string, bigint> = {}; | ||
| for (const log of logs) { | ||
| const token = log.exchangeToken; | ||
| const amount = BigInt(log.amount); | ||
| collectedByToken[token] = (collectedByToken[token] || 0n) + amount; | ||
| } | ||
|
|
||
| for (const [token, amount] of Object.entries(collectedByToken)) { | ||
| dailyFees.add(token, amount); | ||
| } | ||
|
|
||
| return { | ||
| dailyFees, | ||
| dailyRevenue: dailyFees, | ||
| dailyProtocolRevenue: dailyFees, | ||
| }; | ||
| } | ||
|
|
||
| const adapter: Adapter = { | ||
| fetch: getProtocolFees, | ||
| adapter: { | ||
| [CHAIN.POLYGON]: { start: "2022-10-12" }, | ||
| [CHAIN.ETHEREUM]: { start: "2023-09-29" }, | ||
| [CHAIN.BASE]: { start: "2025-01-31" }, | ||
| [CHAIN.ARBITRUM]: { start: "2025-04-01" }, | ||
| [CHAIN.OPTIMISM]: { start: "2025-03-10" }, | ||
| }, | ||
| version: 2, | ||
| methodology: { | ||
| Fees: "A fee is charged on every successful trade executed on the Boson Protocol.", | ||
| }, | ||
| }; | ||
|
|
||
| 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.