Skip to content

Commit

Permalink
0.4.0: getMerklStrategies, jest, ci, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
a17 committed Jun 11, 2024
1 parent 7c0fc0a commit 49fd3d1
Show file tree
Hide file tree
Showing 12 changed files with 2,330 additions and 56 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test and coverage
on: [push, pull_request]
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Run yarn install
uses: borales/actions-yarn@v4
with:
cmd: install # will run `yarn install` command
- name: Run tests and collect coverage
uses: borales/actions-yarn@v4
with:
cmd: coverage # will run `yarn coverage` command
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
out
.tmp
coverage
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ DeFi organizations, protocols, their integration statuses, usage and other infor
```shell
yarn overview
yarn overview-full
yarn test
yarn coverage
```
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
preset: "ts-jest",
transform: {'^.+\\.ts?$': 'ts-jest'},
testEnvironment: 'node',
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
modulePathIgnorePatterns: ["out"],
collectCoverageFrom: ["src/**/*.ts"]
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stabilitydao/stability",
"version": "0.3.0",
"version": "0.4.0",
"description": "Stability Integration Library",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand All @@ -16,12 +16,17 @@
"private": false,
"scripts": {
"build": "tsc",
"test": "jest",
"coverage": "jest --collect-coverage",
"overview": "ts-node tools/overview.ts",
"overview-full": "ts-node tools/overview-full.ts"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"ansis": "^3.2.0",
"console-table-printer": "^2.12.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
Expand Down
98 changes: 49 additions & 49 deletions src/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type DeFiProtocol = {
coreContracts?: string[]
}

export enum IntegrationStatus {
export const enum IntegrationStatus {
LIVE = 'Live',
IN_USE = 'In use',
BEING_DEPLOYED = 'Being deployed',
Expand All @@ -44,54 +44,6 @@ export enum DefiCategory {
LST = 'Liquid staking',
}

export const getIntegrationStatus = (p: DeFiProtocol): IntegrationStatus => {
if (p.coreContracts && p.coreContracts.length > 0) {
return IntegrationStatus.LIVE
}
if (p.adapters && p.adapters.length > 0) {
return IntegrationStatus.LIVE
}
if (p.strategies) {
for (const strategy of p.strategies) {
if (strategies[strategy]?.state == StrategyState.LIVE) {
return IntegrationStatus.LIVE
}
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
return IntegrationStatus.BEING_DEPLOYED
}
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
return IntegrationStatus.DEVELOPMENT
}
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
return IntegrationStatus.AWAITING
}
}
}
if (p.intermediaryStrategies) {
for (const strategy of p.intermediaryStrategies) {
if (strategies[strategy]?.state == StrategyState.LIVE) {
return IntegrationStatus.IN_USE
}
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
return IntegrationStatus.BEING_DEPLOYED
}
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
return IntegrationStatus.DEVELOPMENT
}
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
return IntegrationStatus.AWAITING
}
}
}
const supportedNetWorkIds = Object.keys(deployments).map(chainIdString => networks[chainIdString].id)
for (const protocolNetworkId of p.networks) {
if (supportedNetWorkIds.includes(protocolNetworkId as NetworkId)) {
return IntegrationStatus.POSSIBLE
}
}
return IntegrationStatus.PROPOSED
}

export const integrations: { [org: string]: DeFiOrganization } = {
// oracle
chainlink: {
Expand Down Expand Up @@ -655,3 +607,51 @@ export const integrations: { [org: string]: DeFiOrganization } = {
defiLlama: 'stader',
},
};

export const getIntegrationStatus = (p: DeFiProtocol): IntegrationStatus => {
if (p.coreContracts && p.coreContracts.length > 0) {
return IntegrationStatus.LIVE
}
if (p.adapters && p.adapters.length > 0) {
return IntegrationStatus.LIVE
}
if (p.strategies) {
for (const strategy of p.strategies) {
if (strategies[strategy]?.state == StrategyState.LIVE) {
return IntegrationStatus.LIVE
}
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
return IntegrationStatus.BEING_DEPLOYED
}
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
return IntegrationStatus.DEVELOPMENT
}
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
return IntegrationStatus.AWAITING
}
}
}
if (p.intermediaryStrategies) {
for (const strategy of p.intermediaryStrategies) {
if (strategies[strategy]?.state == StrategyState.LIVE) {
return IntegrationStatus.IN_USE
}
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
return IntegrationStatus.BEING_DEPLOYED
}
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
return IntegrationStatus.DEVELOPMENT
}
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
return IntegrationStatus.AWAITING
}
}
}
const supportedNetWorkIds = Object.keys(deployments).map(chainIdString => networks[chainIdString].id)
for (const protocolNetworkId of p.networks) {
if (supportedNetWorkIds.includes(protocolNetworkId as NetworkId)) {
return IntegrationStatus.POSSIBLE
}
}
return IntegrationStatus.PROPOSED
}
14 changes: 12 additions & 2 deletions src/strategies.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {integrations} from "./integrations";

export type Strategy = {
id: string
shortId: StrategyShortId
Expand All @@ -7,7 +9,7 @@ export type Strategy = {
bgColor: string
}

export enum StrategyShortId {
export const enum StrategyShortId {
QSMF = 'QSMF',
DQMF = 'DQMF',
IQMF = 'IQMF',
Expand Down Expand Up @@ -36,7 +38,7 @@ export enum StrategyState {
PROPOSED = 'Proposed',
}

export const strategies: {[shortId in StrategyShortId]?:Strategy} = {
export const strategies: {[shortId in StrategyShortId]:Strategy} = {
[StrategyShortId.QSMF]: {
id: 'QuickSwap Static Merkl Farm',
shortId: StrategyShortId.QSMF,
Expand Down Expand Up @@ -190,3 +192,11 @@ export const strategies: {[shortId in StrategyShortId]?:Strategy} = {
bgColor: "#000000",
},
};

export const getMerklStrategies = (): string[] => {
const strategyShortIds = integrations.angle.protocols.merkl.strategies as StrategyShortId[]
return strategyShortIds.map(shortId => {
const strategy = strategies[shortId] as Strategy
return strategy.id
})
}
16 changes: 16 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {NetworkId, networks, strategies, deployments, integrations, StrategyShortId} from "../src";

describe('index', () => {
test('deployments', () => {
expect(deployments["137"].platform).toBe("0xb2a0737ef27b5Cc474D24c779af612159b1c3e60")
})
test('networks', () => {
expect(networks["1"].id).toBe(NetworkId.ETHEREUM)
})
test('strategies', () => {
expect(strategies[StrategyShortId.CCF].id).toBe('Curve Convex Farm')
})
test('integrations', () => {
expect(integrations["chainlink"].name).toBe('ChainLink')
})
})
39 changes: 39 additions & 0 deletions tests/integrations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getIntegrationStatus} from "../src/integrations";
import {NetworkId, strategies, StrategyShortId, StrategyState, DefiCategory, DeFiProtocol, IntegrationStatus} from "../src";

describe('testing integrations', () => {
test('get protocol integration status', () => {
const protocol: DeFiProtocol = {
name: 'Test',
category: DefiCategory.AMM,
networks: [NetworkId.BSC,],
}
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.PROPOSED)
protocol.networks = [NetworkId.POLYGON,]
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.POSSIBLE)
protocol.coreContracts = ['PriceReader',]
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.LIVE)
protocol.coreContracts = undefined
protocol.adapters = ['TestAdapter',]
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.LIVE)
protocol.adapters = undefined
protocol.strategies = [StrategyShortId.IQMF,]
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.LIVE)
strategies[StrategyShortId.IQMF].state = StrategyState.AWAITING_DEPLOYMENT
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.BEING_DEPLOYED)
strategies[StrategyShortId.IQMF].state = StrategyState.DEVELOPMENT
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.DEVELOPMENT)
strategies[StrategyShortId.IQMF].state = StrategyState.PROPOSED
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.AWAITING)
protocol.strategies = undefined
protocol.intermediaryStrategies = [StrategyShortId.IQMF,]
strategies[StrategyShortId.IQMF].state = StrategyState.LIVE
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.IN_USE)
strategies[StrategyShortId.IQMF].state = StrategyState.AWAITING_DEPLOYMENT
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.BEING_DEPLOYED)
strategies[StrategyShortId.IQMF].state = StrategyState.DEVELOPMENT
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.DEVELOPMENT)
strategies[StrategyShortId.IQMF].state = StrategyState.PROPOSED
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.AWAITING)
})
})
10 changes: 10 additions & 0 deletions tests/strategies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {getMerklStrategies} from "../src/strategies";

describe('testing strategies', () => {
test('get merkl strategies', () => {
const merklStrategies = getMerklStrategies();
expect(merklStrategies.includes('Gamma UniswapV3 Merkl Farm')).toBe(true);
expect(merklStrategies.includes('A51 BaseSwap Merkl Farm')).toBe(true);
expect(merklStrategies.length).toBeGreaterThan(13)
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"outDir": "./out",
"rootDir": "./src",
"resolveJsonModule": true,
"esModuleInterop": true,
},
"include": ["src/**/*", "tests/**/*"]
"include": ["src/**/*",]
}
Loading

0 comments on commit 49fd3d1

Please sign in to comment.