Skip to content

Commit

Permalink
Merge pull request DefiLlama#3 from DefiLlama/master
Browse files Browse the repository at this point in the history
update mater
  • Loading branch information
Mar-Alex authored May 9, 2024
2 parents f2605d9 + 8db48a0 commit ea26674
Show file tree
Hide file tree
Showing 1,042 changed files with 31,225 additions and 23,396 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Adapters

Find the instructions to list, write, test and submit an adapter [here](https://docs.llama.fi/list-your-project/other-dashboards)
Find the instructions to list, write, test and submit an adapter [here](https://docs.llama.fi/list-your-project/other-dashboards)

Example: `yarn test fees bitcoin`
128 changes: 89 additions & 39 deletions adapters/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { util } from '@defillama/sdk';
import { Balances, ChainApi, util } from '@defillama/sdk';

const { blocks: { getChainBlocks } } = util

Expand All @@ -13,23 +13,66 @@ export type FetchResultBase = {
block?: number;
};

export type FetchResultV2 = {
[key: string]: FetchResponseValue | undefined;
};

export type FetchResultGeneric = FetchResultBase & {
[key: string]: number | string | undefined | IJSON<string>
[key: string]: FetchResponseValue | undefined;
}

export type FetchOptions = {
createBalances: () => Balances;
getBlock: (timestamp: number, chain: string, chainBlocks: ChainBlocks) => Promise<number>;
getLogs: (params: FetchGetLogsOptions) => Promise<any[]>;
toTimestamp: number;
fromTimestamp: number;
startOfDay: number;
getFromBlock: () => Promise<number>;
getToBlock: () => Promise<number>;
chain: string,
api: ChainApi,
fromApi: ChainApi,
toApi: ChainApi,
startTimestamp: number,
endTimestamp: number,
getStartBlock: () => Promise<number>,
getEndBlock: () => Promise<number>,
}

export type FetchGetLogsOptions = {
eventAbi?: string,
topic?: string,
target?: string,
targets?: string[],
onlyArgs?: boolean,
fromBlock?: number,
toBlock?: number,
flatten?: boolean,
cacheInCloud?: boolean,
entireLog?: boolean,
skipCacheRead?: boolean,
topics?: string[],
}

export type Fetch = (
timestamp: number,
chainBlocks: ChainBlocks
chainBlocks: ChainBlocks,
options: FetchOptions,
) => Promise<FetchResult>;

export type FetchV2 = (
options: FetchOptions,
) => Promise<FetchResultV2>;

export type IStartTimestamp = () => Promise<number>

export type BaseAdapter = {
[chain: string]: {
start: IStartTimestamp
fetch: Fetch;
start: IStartTimestamp | number
fetch: Fetch|FetchV2;
runAtCurrTime?: boolean;
customBackfill?: Fetch;
customBackfill?: Fetch|FetchV2;
meta?: {
methodology?: string | IJSON<string>
hallmarks?: [number, string][]
Expand All @@ -45,70 +88,76 @@ export enum ProtocolType {
COLLECTION = 'collection',
}

export type SimpleAdapter = {
adapter: BaseAdapter
export type AdapterBase = {
timetravel?: boolean
isExpensiveAdapter?: boolean,
protocolType?: ProtocolType;
version?: number;
}

export type SimpleAdapter = AdapterBase & {
adapter: BaseAdapter
}

export type BreakdownAdapter = {
export type BreakdownAdapter = AdapterBase & {
breakdown: {
[version: string]: BaseAdapter
};
protocolType?: ProtocolType;
};

export type Adapter = SimpleAdapter | BreakdownAdapter;
export type FetchResponseValue = string | number | Balances;

/**
* Include here new adaptors types
*/

// VOLUME
export type FetchResultVolume = FetchResultBase & {
dailyVolume?: string // | IJSON<string>;
totalVolume?: string // | IJSON<string>;
dailyShortOpenInterest?: string // | IJSON<string>;
dailyLongOpenInterest?: string;
dailyOpenInterest?: string;
dailyVolume?: FetchResponseValue
totalVolume?: FetchResponseValue
dailyShortOpenInterest?: FetchResponseValue
dailyLongOpenInterest?: FetchResponseValue
dailyOpenInterest?: FetchResponseValue
};

// FEES
export type FetchResultFees = FetchResultBase & {
totalFees?: string | IJSON<string>;
dailyFees?: string | IJSON<string>;
dailyUserFees?: string | IJSON<string>;
totalRevenue?: string | IJSON<string>;
dailyRevenue?: string | IJSON<string>;
dailyProtocolRevenue?: string | IJSON<string>;
dailyHoldersRevenue?: string | IJSON<string>;
dailySupplySideRevenue?: string | IJSON<string>;
totalProtocolRevenue?: string | IJSON<string>;
totalSupplySideRevenue?: string | IJSON<string>;
totalUserFees?: string | IJSON<string>;
dailyBribesRevenue?: string | IJSON<string>;
dailyTokenTaxes?: string | IJSON<string>;
totalFees?: FetchResponseValue;
dailyFees?: FetchResponseValue;
dailyUserFees?: FetchResponseValue;
totalRevenue?: FetchResponseValue;
dailyRevenue?: FetchResponseValue;
dailyProtocolRevenue?: FetchResponseValue;
dailyHoldersRevenue?: FetchResponseValue;
dailySupplySideRevenue?: FetchResponseValue;
totalProtocolRevenue?: FetchResponseValue;
totalSupplySideRevenue?: FetchResponseValue;
totalUserFees?: FetchResponseValue;
dailyBribesRevenue?: FetchResponseValue;
dailyTokenTaxes?: FetchResponseValue;
};

// INCENTIVES
export type FetchResultIncentives = FetchResultBase & {
tokens?: IJSON<string> // | string
tokenIncentives?: FetchResponseValue
};

// AGGREGATORS
export type FetchResultAggregators = FetchResultBase & {
dailyVolume?: string // | IJSON<string>;
totalVolume?: string // | IJSON<string>;
dailyVolume?: FetchResponseValue
totalVolume?: FetchResponseValue
};

// OPTIONS
export type FetchResultOptions = FetchResultBase & {
totalPremiumVolume?: string // | IJSON<string>
totalNotionalVolume?: string // | IJSON<string>
dailyPremiumVolume?: string // | IJSON<string>
dailyNotionalVolume?: string // | IJSON<string>
dailyShortOpenInterest?: string // | IJSON<string>;
dailyLongOpenInterest?: string;
dailyOpenInterest?: string;
totalPremiumVolume?: FetchResponseValue
totalNotionalVolume?: FetchResponseValue
dailyPremiumVolume?: FetchResponseValue
dailyNotionalVolume?: FetchResponseValue
dailyShortOpenInterest?: FetchResponseValue
dailyLongOpenInterest?: FetchResponseValue
dailyOpenInterest?: FetchResponseValue
};


Expand All @@ -120,7 +169,8 @@ export enum AdapterType {
DERIVATIVES = 'derivatives',
OPTIONS = 'options',
PROTOCOLS = 'protocols',
ROYALTIES = 'royalties'
ROYALTIES = 'royalties',
AGGREGATOR_DERIVATIVES = 'aggregator-derivatives'
}

export type FetchResult = FetchResultVolume & FetchResultFees & FetchResultAggregators & FetchResultOptions & FetchResultIncentives
Expand Down
Loading

0 comments on commit ea26674

Please sign in to comment.