Skip to content
37 changes: 37 additions & 0 deletions dexs/boson/constants.ts
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)";
42 changes: 42 additions & 0 deletions dexs/boson/index.ts
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);
Comment thread
zajck marked this conversation as resolved.
Outdated

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.",
Comment thread
zajck marked this conversation as resolved.
Outdated
},
};

export default adapter;
108 changes: 108 additions & 0 deletions dexs/boson/utils.ts
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;
});
Comment thread
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({
Comment thread
levalleux-ludo marked this conversation as resolved.
Outdated
target: protocolDiamondAddress,
abi: getOffer_v2_5_0,
params: [offerId.toString()],
});
Comment thread
zajck marked this conversation as resolved.
Outdated

Comment thread
zajck marked this conversation as resolved.
Outdated
if (offer.quantityAvailable !== MaxUint256) continue; // skip limited offers
Comment thread
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;
}
}
53 changes: 53 additions & 0 deletions fees/boson/index.ts
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)";
Comment thread
zajck marked this conversation as resolved.
const protocolFeeCollectedTopic =
"0x9399ed37d26489264206ddf87ad81aaa13557b4e56b5443503a2b64a24ec42db";
Comment thread
zajck marked this conversation as resolved.
const protocolDiamondAddress = "0x59A4C19b55193D5a2EAD0065c54af4d516E18Cb5";
Comment thread
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;
Loading