Skip to content

Commit

Permalink
Merge branch 'feature/tokenlon-rfqv2-l2-volume' of github.com:0xkeen/…
Browse files Browse the repository at this point in the history
…dimension-adapters into feature/tokenlon-rfqv2-l2-volume
  • Loading branch information
0xkeen committed May 14, 2024
2 parents 491e6f0 + 084e398 commit beeab0a
Show file tree
Hide file tree
Showing 176 changed files with 6,079 additions and 1,464 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/getFileList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ALLOWED_ROOTS = ['volumes', 'dexs', 'options', 'derivatives', 'incentives', 'fees', 'options', 'protocols']
const ALLOWED_ROOTS = ['volumes', 'dexs', 'options', 'derivatives', 'incentives', 'fees', 'options', 'protocols', 'aggregators']
const MODIFIED = parse(process.env.MODIFIED)
const ADDED = parse(process.env.ADDED)
const fileSet = new Set();
Expand All @@ -13,4 +13,4 @@ console.log(JSON.stringify([...fileSet]))

function parse(data) {
return data.replace('[', '').replace(']', '').split(',')
}
}
14 changes: 11 additions & 3 deletions .github/workflows/test-adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ jobs:
uses: actions/checkout@v2
- name: Run changes files through test script
run: |
# Store the current commit hash in a variable
current_commit=$(git rev-parse HEAD)
# Checkout to master to check if new adapters files are of v2
git fetch origin master:master
# Checkout back to the original commit
git checkout $current_commit
RUN_FILES=$(
MODIFIED=${{ steps.file_changes.outputs.files_modified}} \
ADDED=${{ steps.file_changes.outputs.files_added}} \
Expand All @@ -24,16 +33,15 @@ jobs:
exit 0
fi
yarn install --production
yarn upgrade @defillama/sdk
npm ci
list=$(echo $RUN_FILES | tr -d '"[]' | tr "," "\n")
for i in ${list}
do
{
IFS='@' read -r -a array <<< "$i"
yarn test ${array[0]} ${array[1]} 2>&1 | tee output.txt
npm run test ${array[0]} ${array[1]} 2>&1 | tee output.txt
node ${{ github.workspace }}/.github/workflows/commentResult.js /home/runner/work/dimension-adapters/dimension-adapters/output.txt "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}" ${i}
if grep -q "\-\-\-\- ERROR \-\-\-\-" output.txt; then
exit 1;
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ts-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn run update-submodules
- name: Get Node.js
uses: actions/setup-node@v1
with:
node-version: '16'
- run: yarn
- run: npm ci
- name: Checking adapters
run: yarn run ts-check
run: npm run ts-check
- name: Checking cli
run: yarn run ts-check-cli
run: npm run ts-check-cli
44 changes: 44 additions & 0 deletions aggregator-derivatives/rage-trade/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { postURL } from '../../utils/fetchURL'
import { FetchResult, SimpleAdapter } from '../../adapters/types'
import { CHAIN } from '../../helpers/chains'

const URL = 'https://leaderboard-production.rage.trade'
const endpoint = '/api/stats/defillama'
const arbitrumStartTimestamp = 1701302400 // 2023-11-30 00:00:00
const optimismStartTimestamp = 1701302400 // 2023-11-30 00:00:00
const ethereumStartTimestamp = 1710374400 // 2023-11-30 00:00:00

const fetch =
(chain: string) =>
async (timestamp: number): Promise<FetchResult> => {
const { dailyVolume: dailyVolumeE30, totalVolume: totalVolumeE30 } =
await postURL(`${URL}${endpoint}`, {
timestamp,
chain,
})

return {
dailyVolume: dailyVolumeE30 ? dailyVolumeE30 / 1e30 : 0,
totalVolume: totalVolumeE30 ? totalVolumeE30 / 1e30 : 0,
timestamp,
}
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetch(CHAIN.ARBITRUM),
start: arbitrumStartTimestamp,
},
[CHAIN.ETHEREUM]: {
fetch: fetch(CHAIN.ETHEREUM),
start: ethereumStartTimestamp,
},
[CHAIN.OPTIMISM]: {
fetch: fetch(CHAIN.OPTIMISM),
start: optimismStartTimestamp,
},
},
}

export default adapter
130 changes: 130 additions & 0 deletions aggregators/aperture-swap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { httpGet } from "../../utils/fetchURL";
import { ChainBlocks, FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

const chainToId: Record<string, number> = {
[CHAIN.ETHEREUM]: 1,
[CHAIN.ARBITRUM]: 42161,
[CHAIN.AVAX]: 43114,
[CHAIN.BSC]: 56,
[CHAIN.FANTOM]: 250,
[CHAIN.OPTIMISM]: 10,
[CHAIN.POLYGON]: 137,
[CHAIN.LINEA]: 59144,
[CHAIN.SCROLL]: 534352,
[CHAIN.ERA]: 324,
[CHAIN.CRONOS]: 25,
[CHAIN.MANTA]: 169,
};


const url = "https://api.aperture.finance/getMetricsBreakDownSinceInception"

interface VolumeInfo {
chainId: number;
tve: number;
txCount: number;
}

interface VolumeResponse {
dailyVolume: VolumeInfo[];
totalVolume: VolumeInfo[];
}

const fetch = async (timestamp: number, _: ChainBlocks, options: FetchOptions) => {
const chainId = chainToId[options.chain]
if (!chainId) {
return {
dailyVolume: 0,
totalVolume: 0,
timestamp: timestamp,
}
}
const fetchUrl = `${url}?chainid=${chainId}&timestamp=${timestamp}`
const data: VolumeResponse = (await httpGet(fetchUrl, { timeout: 100000 }));

if (data) {
let dailyVolume :number = 0
let totalVolume :number = 0
if (data.dailyVolume) {
data.dailyVolume.forEach(r => {
if (r.chainId == chainId) {
dailyVolume = r.tve
}
})
}

if (data.totalVolume) {
data.totalVolume.forEach(r => {
if (r.chainId == chainId) {
totalVolume = r.tve
}
})
}

return {
dailyVolume: dailyVolume,
totalVolume: totalVolume,
timestamp: timestamp
}
} else {
//console.log("no data")
return {
dailyVolume: 0,
totalVolume: 0,
timestamp: timestamp,
}
}
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ETHEREUM]: {
fetch: fetch,
runAtCurrTime: false,
start: 1689657695,
},
[CHAIN.ARBITRUM]: {
fetch: fetch,
runAtCurrTime: false,
start: 1689014691,
},
[CHAIN.AVAX]: {
fetch: fetch,
runAtCurrTime: false,
start: 1696671295,
},
[CHAIN.BASE]: {
fetch: fetch,
runAtCurrTime: false,
start: 1697229723,
},
[CHAIN.BSC]: {
fetch: fetch,
runAtCurrTime: false,
start: 1696963675,
},
[CHAIN.OPTIMISM]: {
fetch: fetch,
runAtCurrTime: false,
start: 1696888429,
},
[CHAIN.POLYGON]: {
fetch: fetch,
runAtCurrTime: false,
start: 1696888519,
},
[CHAIN.MANTA]: {
fetch: fetch,
runAtCurrTime: false,
start: 1695079629,
},
[CHAIN.SCROLL]: {
fetch: fetch,
runAtCurrTime: false,
start: 1702694992,
}
}
};

export default adapter
1 change: 1 addition & 0 deletions aggregators/bebop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const adapter: any = {
bsc: { fetch, start: 1685491200, },
blast: { fetch, start: 1685491200, },
era: { fetch, start: 1685491200, },
optimism: { fetch, start: 1685491200, },
},
};

Expand Down
36 changes: 36 additions & 0 deletions aggregators/bountive/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import fetchURL from "../../utils/fetchURL";
import { FetchResultV2, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

const URL = 'https://app.bountive.fi';
const endpoint = '/api/metrics/volumes/';
const startTimestamp = 1709356735;// 02.03.2024

interface IAPIResponse {
date: number;
dailyVolume: string;
totalVolume: string;
}

const fetch = async ({ endTimestamp, startTimestamp }): Promise<FetchResultV2> => {
const { dailyVolume, totalVolume }: IAPIResponse = await fetchURL(
`${URL}${endpoint}${startTimestamp * 1000}/${endTimestamp * 1000}`,
);

return {
dailyVolume,
totalVolume,
};
};

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.STARKNET]: {
fetch: fetch,
start: startTimestamp,
},
},
};

export default adapter;
41 changes: 0 additions & 41 deletions aggregators/dodo-agg/index.ts

This file was deleted.

25 changes: 25 additions & 0 deletions aggregators/etaswap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import BigNumber from "bignumber.js";
import { CHAIN } from "../../helpers/chains";
import { httpGet } from "../../utils/fetchURL";

const fetchLogs = async (timestamp: number) => {
const res = await httpGet(`https://api.etaswap.com/v1/statistics/volume/total?timestamp=${timestamp}`);
return {
dailyVolume: new BigNumber(res.volume_USD_24h).div(100).toFixed(2),
totalVolume: new BigNumber(res.volume_USD_total).div(100).toFixed(2),
dailyFees: new BigNumber(res.fee_USD_24h).div(100).toFixed(2),
totalFees: new BigNumber(res.fee_USD_total).div(100).toFixed(2),
timestamp: timestamp,
};
};

const adapter: any = {
adapter: {
[CHAIN.HEDERA]: {
fetch: fetchLogs,
start: 1709395559,
},
},
};

export default adapter;
4 changes: 2 additions & 2 deletions aggregators/kanalabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ const adapter: SimpleAdapter = {
},
[CHAIN.APTOS]: {
fetch: async (timestamp: number) => {
const swap = await fetch(KanaChainID.aptos)(timestamp);
const swap = await fetch(KanaChainID.aptos)(timestamp);
const trade = await fetchDerivatives(KanaChainID.aptos)(timestamp);
return {
dailyVolume: (+swap.dailyVolume + +trade.dailyVolume).toString(),
dailyVolume: (+trade.dailyVolume).toString(),
totalVolume: (+swap.totalVolume + +trade.totalVolume).toString(),
timestamp,
};
Expand Down
Loading

0 comments on commit beeab0a

Please sign in to comment.