forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
62583be
commit e5440b6
Showing
4 changed files
with
148 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { DexVolumeAdapter } from "../dexVolume.type"; | ||
|
||
const { | ||
getChainVolume, | ||
DEFAULT_TOTAL_VOLUME_FIELD, | ||
DEFAULT_DAILY_VOLUME_FIELD, | ||
} = require("../helper/getUniSubgraphVolume"); | ||
const { BSC } = require("../helper/chains"); | ||
const { getStartTimestamp } = require("../helper/getStartTimestamp"); | ||
const endpoints = { | ||
[BSC]: "https://api.thegraph.com/subgraphs/name/champagneswap/exchangev3", | ||
}; | ||
|
||
const DAILY_VOLUME_FACTORY = "champagneDayData"; | ||
|
||
const graphs = getChainVolume({ | ||
graphUrls: { | ||
[BSC]: endpoints[BSC], | ||
}, | ||
totalVolume: { | ||
factory: "champagneFactories", | ||
field: DEFAULT_TOTAL_VOLUME_FIELD, | ||
}, | ||
dailyVolume: { | ||
factory: DAILY_VOLUME_FACTORY, | ||
field: DEFAULT_DAILY_VOLUME_FIELD, | ||
}, | ||
}); | ||
|
||
const adapter: DexVolumeAdapter = { | ||
volume: { | ||
[BSC]: { | ||
fetch: graphs(BSC), | ||
start: getStartTimestamp({ | ||
endpoints, | ||
chain: BSC, | ||
dailyDataField: `${DAILY_VOLUME_FACTORY}s`, | ||
}), | ||
}, | ||
}, | ||
}; | ||
|
||
export default 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
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,99 @@ | ||
const { request, gql } = require("graphql-request"); | ||
const sdk = require('@defillama/sdk') | ||
const { toUSDTBalances } = require('./helper/balances') | ||
|
||
async function fetch() { | ||
let response = await utils.fetchURL('https://api.thegraph.com/subgraphs/name/champagneswap/exchangev3') | ||
return response.data.total_value_locked_all; | ||
} | ||
|
||
const graphEndpoint = 'https://api.thegraph.com/subgraphs/name/champagneswap/exchangev3' | ||
const currentQuery = gql` | ||
query champagneFactories { | ||
champagneFactories(first: 1) { | ||
totalLiquidityUSD | ||
} | ||
} | ||
` | ||
const historicalQuery = gql` | ||
query champagneDayDatas { | ||
champagneDayDatas( | ||
first: 1000 | ||
orderBy: date | ||
orderDirection: asc | ||
) { | ||
date | ||
dailyVolumeUSD | ||
totalLiquidityUSD | ||
__typename | ||
} | ||
} | ||
` | ||
|
||
const graphUrl = 'https://api.thegraph.com/subgraphs/name/champagneswap/exchangev3' | ||
const graphQuery = gql` | ||
query get_tvl($block: Int) { | ||
uniswapFactories( | ||
block: { number: $block } | ||
) { | ||
totalVolumeUSD | ||
totalLiquidityUSD | ||
} | ||
} | ||
`; | ||
async function tvl(timestamp, ethBlock, chainBlocks) { | ||
if (Math.abs(timestamp - Date.now() / 1000) < 3600) { | ||
const tvl = await request(graphEndpoint, currentQuery, {}, { | ||
"referer": "https://champagne.finance/", | ||
"origin": "https://champagne.finance", | ||
}) | ||
return toUSDTBalances(tvl.champagneFactories[0].totalLiquidityUSD) | ||
} else { | ||
const tvl = (await request(graphEndpoint, historicalQuery)).champagneDayDatas | ||
let closest = tvl[0] | ||
tvl.forEach(dayTvl => { | ||
if (Math.abs(dayTvl.date - timestamp) < Math.abs(closest.date - timestamp)) { | ||
closest = dayTvl | ||
} | ||
}) | ||
if(Math.abs(closest.date - timestamp) > 3600*24){ // Oldest data is too recent | ||
const {uniswapFactories} = await request( | ||
graphUrl, | ||
graphQuery, | ||
{ | ||
block: chainBlocks['bsc'], | ||
} | ||
); | ||
const usdTvl = Number(uniswapFactories[0].totalLiquidityUSD) | ||
|
||
return toUSDTBalances(usdTvl) | ||
} | ||
return toUSDTBalances(closest.totalLiquidityUSD) | ||
} | ||
} | ||
|
||
const factory = '0xb31A337f1C3ee7fA2b2B83c6F8ee0CA643D807a0' | ||
const champagneToken = '0x4957c1c073557BFf33C01A7cA1436D0d2409d439' | ||
const masterChef = '0x15C17442eb2Cd3a56139e877ec7784b2dbD97270' | ||
async function staking(timestamp, ethBlock, chainBlocks) { | ||
const balances = {} | ||
const stakedCham = sdk.api.erc20.balanceOf({ | ||
target: champagneToken, | ||
owner: masterChef, | ||
chain: 'bsc', | ||
block: chainBlocks.bsc | ||
}) | ||
|
||
sdk.util.sumSingleBalance(balances, 'bsc:' + champagneToken, (await stakedCham).output) | ||
return balances | ||
} | ||
|
||
module.exports = { | ||
timetravel: true, | ||
misrepresentedTokens: true, | ||
methodology: 'TVL accounts for the liquidity on all AMM pools, using the TVL chart on https://champagne.finance/ as the source. Staking accounts for the CHAM locked in MasterChef (0x15C17442eb2Cd3a56139e877ec7784b2dbD97270)', | ||
bsc: { | ||
staking, | ||
tvl | ||
}, | ||
} |
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