forked from DefiLlama/dimension-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.
Merge pull request DefiLlama#1288 from 0xShad0w/nile-exchange
add nile-exchange
- Loading branch information
Showing
5 changed files
with
166 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,16 @@ | ||
import { SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getDexVolumeExports } from "../../helpers/dexVolumeLogs"; | ||
|
||
const FACTORY_ADDRESS = '0xAAA16c016BF556fcD620328f0759252E29b1AB57' | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.LINEA]: { | ||
fetch: getDexVolumeExports({ chain: CHAIN.LINEA, factory: FACTORY_ADDRESS }), | ||
start: 1768897, | ||
}, | ||
} | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume"; | ||
|
||
const adapters = univ2Adapter({ | ||
[CHAIN.LINEA]: "https://graph-query.linea.build/subgraphs/name/nileexchange/cl-subgraph" | ||
}, { | ||
factoriesName: "factories", | ||
dayData: "uniswapDayData", | ||
dailyVolume: "volumeUSD", | ||
totalVolume: "totalVolumeUSD", | ||
}); | ||
|
||
adapters.adapter.linea.start = async () => 1768897; | ||
export default adapters; |
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,16 @@ | ||
import { SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getDexFeesExports } from "../../helpers/dexVolumeLogs"; | ||
|
||
const FACTORY_ADDRESS = '0xAAA16c016BF556fcD620328f0759252E29b1AB57'; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.LINEA]: { | ||
fetch: getDexFeesExports({ chain: CHAIN.LINEA, factory: FACTORY_ADDRESS,}), | ||
start: 1705053913, | ||
}, | ||
} | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import request from "graphql-request"; | ||
import { Balances } from "@defillama/sdk"; | ||
|
||
interface IBribes { | ||
amount: number; | ||
token: { | ||
id: string; | ||
decimals: number; | ||
}; | ||
} | ||
|
||
export const fees_bribes = async (fromBlock: number, timestamp: number, balances: Balances) => { | ||
const endpoint = 'https://api.studio.thegraph.com/query/66247/nile-cl/version/latest'; | ||
const graphQuery = ` | ||
query GetBribes($fromBlock: Int!) { | ||
bribes( | ||
where: { timestamp_gte: ${timestamp} } | ||
) { | ||
amount | ||
token { | ||
id | ||
decimals | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const graphRes: { bribes: IBribes[] } = await request(endpoint, graphQuery, { fromBlock, }); | ||
|
||
const logs_bribes = graphRes.bribes; | ||
|
||
logs_bribes.map((e: IBribes) => { | ||
balances.add(e.token.id, e.amount * Math.pow(10, e.token.decimals)); | ||
}) | ||
}; |
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,85 @@ | ||
import { Adapter, FetchOptions } from "../../adapters/types"; | ||
import { ARBITRUM, CHAIN } from "../../helpers/chains"; | ||
import { fees_bribes } from './bribes'; | ||
import { | ||
getGraphDimensions, | ||
DEFAULT_DAILY_VOLUME_FACTORY, | ||
DEFAULT_TOTAL_VOLUME_FIELD, | ||
} from "../../helpers/getUniSubgraph" | ||
|
||
type TStartTime = { | ||
[key: string]: number; | ||
} | ||
const startTimeV2: TStartTime = { | ||
[CHAIN.LINEA]: 1705053913, | ||
} | ||
|
||
const getBribes = async ({ fromTimestamp, toTimestamp, createBalances, getFromBlock, }: FetchOptions): Promise<any> => { | ||
const fromBlock = await getFromBlock() | ||
const bribes = createBalances(); | ||
const bribes_delta = createBalances(); | ||
await fees_bribes(fromBlock, toTimestamp, bribes_delta); | ||
await fees_bribes(fromBlock, fromTimestamp, bribes); | ||
bribes.subtract(bribes_delta); | ||
return { | ||
timestamp: toTimestamp, | ||
dailyBribesRevenue: bribes, | ||
}; | ||
}; | ||
|
||
const v2Endpoints = { | ||
[CHAIN.LINEA]: "https://api.studio.thegraph.com/query/66247/nile-cl/version/latest/", | ||
}; | ||
|
||
const VOLUME_USD = "volumeUSD"; | ||
|
||
const v2Graphs = getGraphDimensions({ | ||
graphUrls: v2Endpoints, | ||
totalVolume: { | ||
factory: "factories", | ||
field: DEFAULT_TOTAL_VOLUME_FIELD, | ||
}, | ||
dailyVolume: { | ||
factory: DEFAULT_DAILY_VOLUME_FACTORY, | ||
field: VOLUME_USD, | ||
}, | ||
feesPercent: { | ||
type: "fees", | ||
HoldersRevenue: 50, | ||
ProtocolRevenue: 5, | ||
SupplySideRevenue: 45, | ||
UserFees: 100, // User fees are 100% of collected fees | ||
Revenue: 50 // Revenue is 100% of collected fees | ||
} | ||
}); | ||
// https://docs.ramses.exchange/ramses-cl-v2/concentrated-liquidity/fee-distribution | ||
const methodology = { | ||
UserFees: "User pays 0.3% fees on each swap.", | ||
ProtocolRevenue: "Revenue going to the protocol. 5% of collected fees. (is probably right because the distribution is dynamic.)", | ||
HoldersRevenue: "User fees are distributed among holders. 75% of collected fees. (is probably right because the distribution is dynamic.)", | ||
SupplySideRevenue: "20% of collected fees are distributed among LPs. (is probably right because the distribution is dynamic.)" | ||
} | ||
|
||
const adapter: Adapter = { | ||
version: 2, | ||
adapter: { | ||
[CHAIN.LINEA]: { | ||
fetch: async (options: FetchOptions) => { | ||
const v2Result = await v2Graphs(CHAIN.LINEA)(options) | ||
const bribesResult = await getBribes(options); | ||
v2Result.dailyBribesRevenue = bribesResult.dailyBribesRevenue; | ||
|
||
return v2Result; | ||
}, | ||
start: startTimeV2[CHAIN.LINEA], | ||
meta: { | ||
methodology: { | ||
...methodology, | ||
UserFees: "User pays 0.05%, 0.30%, or 1% on each swap.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default adapter; |