Skip to content

add justbet fees & volume aggregator #2706

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 6 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dexs/justbet/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const WINR_VAULT_ADAPTER_CONTRACT =
"0xc942b79E51fe075c9D8d2c7501A596b4430b9Dd7";

export const JUSTBET_BANKROLL_INDEXES = [
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000004",
"0x0000000000000000000000000000000000000005",
"0x0000000000000000000000000000000000000006",
"0x0000000000000000000000000000000000000008",
"0x0000000000000000000000000000000000000009",
"0x000000000000000000000000000000000000000E",
"0x0000000000000000000000000000000000000012",
"0x0000000000000000000000000000000000000013",
"0x0000000000000000000000000000000000000014",
"0x0000000000000000000000000000000000000015",
"0x0000000000000000000000000000000000000018",
"0x0000000000000000000000000000000000000019",
"0x0000000000000000000000000000000000000007",
"0x0000000000000000000000000000000000000011",
"0x0000000000000000000000000000000000000017",
];
47 changes: 47 additions & 0 deletions dexs/justbet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ethers } from 'ethers'

import { CHAIN } from "../../helpers/chains";
import { Adapter, } from "../../adapters/types";
import {
JUSTBET_BANKROLL_INDEXES,
WINR_VAULT_ADAPTER_CONTRACT,
} from "./constants";

const abis = {
"returnEpochResultInActiveEpochByAddress": "function returnEpochResultInActiveEpochByAddress(address _bankrollIdentifierAddress) view returns ((uint256 totalPaidInNoRakeUSD, uint256 totalPaidInRakedUSD, uint256 totalPaidOutNoRakeUSD, uint256 totalPaidOutRakedUSD, uint256 totalPaidInAllTimeUSD, uint256 totalPaidOutAllTimeUSD, uint256 secondsLeftInEpoch) epochResult_)",
"returnBankrollTokenInfoByAddress": "function returnBankrollTokenInfoByAddress(address _bankrollIdentifierAddress) external view returns ((uint8 tokenType, address tokenAddress, string name, string symbol, uint8 decimals, uint256 totalAmount, uint256 priceInUSD, uint256 assetRatio, uint256 totalAmountInUsd) tokenInfo_)",
"getAllDataBatch": "function getAllDataBatch(address[] bankrollIndexes) view returns ((uint256 vaultIndex, address bankrollBytesIdentifier, address vaultAddress, address bankrollTokenAddress, address shareTokenAddress, address controllerAddress, address liquidityManagerAddress)[] vaultDetails_, (uint256 bankrollAmount, uint256 shareTokenAmount, uint256 epochAmount, uint256 totalAmount, uint256 totalAmountExcluding, uint64 bankrollTokenPrice, bool isProfitEpcoh, bool isProfitTotal, bool isProfitTotalExcluding)[] vaultAmounts_)"
}


export default {
adapter: {
[CHAIN.WINR]: {
fetch: (async ({ api, fromApi, }) => {
const volumeDetails = await api.multiCall({ abi: abis.returnEpochResultInActiveEpochByAddress, calls: JUSTBET_BANKROLL_INDEXES as any, target: WINR_VAULT_ADAPTER_CONTRACT, permitFailure: true })
const volumeDetailsYesterday = await fromApi.multiCall({ abi: abis.returnEpochResultInActiveEpochByAddress, calls: JUSTBET_BANKROLL_INDEXES as any, target: WINR_VAULT_ADAPTER_CONTRACT, permitFailure: true })
const vaultCurrentPrices = await api.multiCall({ abi: abis.returnBankrollTokenInfoByAddress, calls: JUSTBET_BANKROLL_INDEXES as any, target: WINR_VAULT_ADAPTER_CONTRACT, permitFailure: true })

let dailyVolume = 0
let totalVolume = 0

volumeDetails.forEach((vault, i) => {
if (!vault || !volumeDetailsYesterday[i] || !vaultCurrentPrices[i]) return;

const vaultDecimal = Number(vaultCurrentPrices[i].decimals)
const vaultCurrentPrice = Number(ethers.formatUnits(vaultCurrentPrices[i].priceInUSD, 8))
const totalVolumeUSDToday = Number(ethers.formatUnits(vault.totalPaidOutAllTimeUSD, vaultDecimal)) * vaultCurrentPrice
const totalVolumeUSDYesterday = Number(ethers.formatUnits(volumeDetailsYesterday[i].totalPaidOutAllTimeUSD, vaultDecimal)) * vaultCurrentPrice

dailyVolume += totalVolumeUSDToday - totalVolumeUSDYesterday
totalVolume += totalVolumeUSDToday
})

return { totalVolume, dailyVolume }

}),
start: 1732060800,
},
},
version: 2,
} as Adapter;
42 changes: 42 additions & 0 deletions fees/justbet/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const WINR_VAULT_ADAPTER_CONTRACT =
"0xc942b79E51fe075c9D8d2c7501A596b4430b9Dd7";

export const JUSTBET_BANKROLL_INDEXES = [
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000006",
"0x0000000000000000000000000000000000000013",
"0x0000000000000000000000000000000000000014",
"0x0000000000000000000000000000000000000015",
"0x0000000000000000000000000000000000000019",
];

export const TOKEN_DETAILS = {
"0xd77b108d4f6cefaa0cae9506a934e825becca46e": {
coingeckoId: "winr-protocol",
decimals: 18,
}, // WINR on arbitrum
"0xbf6fa9d2bf9f681e7b6521b49cf8eccf9ad8d31d": {
coingeckoId: "winr-protocol",
decimals: 18,
}, // WWINR on winr chain
"0x59edbb343991d30f77dcdbad94003777e9b09ba9": {
coingeckoId: "usd-coin",
decimals: 6,
}, // USDC on winr chain
"0x0381132632e9e27a8f37f1bc56bd5a62d21a382b": {
coingeckoId: "tether",
decimals: 6,
}, // Tether on winr chain
"0xf2857668777135e22f8cd53c97abf8821b7f0bdf": {
coingeckoId: "arbitrum",
decimals: 18,
}, // Arbitrum on winr chain
"0xe60256921ae414d7b35d6e881e47931f45e027cf": {
coingeckoId: "ethereum",
decimals: 18,
}, // Ether on winr chain
"0x5b20dcab6b91f157a39036c6c0e6f16e56d74cdb": {
coingeckoId: "solana",
decimals: 18,
}, // Solana on winr chain
};
60 changes: 60 additions & 0 deletions fees/justbet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ChainApi } from "@defillama/sdk";

import { CHAIN } from "../../helpers/chains";
import { Adapter, FetchOptions } from "../../adapters/types";

const abis = {
"getAllDataBatch": "function getAllDataBatch(address[] bankrollIndexes) view returns ((uint256 vaultIndex, address bankrollBytesIdentifier, address vaultAddress, address bankrollTokenAddress, address shareTokenAddress, address controllerAddress, address liquidityManagerAddress)[] vaultDetails, (uint256 bankrollAmount, uint256 shareTokenAmount, uint256 epochAmount, uint256 totalAmount, uint256 totalAmountExcluding, uint64 bankrollTokenPrice, bool isProfitEpcoh, bool isProfitTotal, bool isProfitTotalExcluding)[] vaultAmounts)",
"returnAllTimeProfitLossIncludingActiveEpoch": "function returnAllTimeProfitLossIncludingActiveEpoch() view returns (bool isProfit_, uint256 amountDelta_)",
"epochCounter": "uint256:epochCounter",
"currentEpochEnd": "uint256:currentEpochEnd",
"returnNetProfitOrLossInActiveEpoch": "function returnNetProfitOrLossInActiveEpoch() view returns (bool isProfit_, uint256 amountDelta_)"
}


import {
JUSTBET_BANKROLL_INDEXES,
WINR_VAULT_ADAPTER_CONTRACT,
} from "./constants";

const getVaultAddresses = async (api: ChainApi) => {
const { vaultDetails, } = await api.call({
abi: abis.getAllDataBatch,
target: WINR_VAULT_ADAPTER_CONTRACT,
params: [JUSTBET_BANKROLL_INDEXES as any],
});

return {vaults: vaultDetails.map(i => i.vaultAddress), tokens: vaultDetails.map(i => i.bankrollTokenAddress) };
};

export default {
adapter: {
[CHAIN.WINR]: {
fetch: (async ({ api, fromApi, createBalances, }: FetchOptions) => {
const { vaults, tokens } = await getVaultAddresses(api);
const yesterdayData = await fromApi.multiCall({ abi: abis.returnAllTimeProfitLossIncludingActiveEpoch, calls: vaults, permitFailure: true });
const todayData = await api.multiCall({ abi: abis.returnAllTimeProfitLossIncludingActiveEpoch, calls: vaults, permitFailure: true });
const dailyFees = createBalances()
const totalFees = createBalances()
tokens.forEach((token, i) => {
if (!todayData[i] || !yesterdayData[i]) return;
const vaultProfitToday = Number(todayData[i].amountDelta_) * (todayData[i].isProfit_ ? 1 : -1)
const vaultProfitYesterday = Number(yesterdayData[i].amountDelta_) * (yesterdayData[i].isProfit_ ? 1 : -1)
dailyFees.add(token, vaultProfitToday - vaultProfitYesterday)
totalFees.add(token, vaultProfitToday)
})

return {
dailyFees,
totalFees,
dailyRevenue: dailyFees.clone(60/100),
totalRevenue: totalFees.clone(60/100),
dailyHoldersRevenue: dailyFees.clone(20/100),
totalHoldersRevenue: totalFees.clone(20/100),
};
}),
start: 1732060800,
},
},
version: 2,
} as Adapter;
1 change: 1 addition & 0 deletions helpers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export enum CHAIN {
SUPERPOSITION = "spn",
SWELLCHAIN = "swellchain",
ANCIENT8 = "ancient8",
WINR = "winr",
SOPHON = "sophon",
KARAK = "karak",
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading