Skip to content

Commit 49fd3d1

Browse files
committed
0.4.0: getMerklStrategies, jest, ci, refactoring
1 parent 7c0fc0a commit 49fd3d1

12 files changed

+2330
-56
lines changed

.github/workflows/test.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test and coverage
2+
on: [push, pull_request]
3+
jobs:
4+
run:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v4
9+
- name: Set up Node 18
10+
uses: actions/setup-node@v3
11+
with:
12+
node-version: 18
13+
- name: Run yarn install
14+
uses: borales/actions-yarn@v4
15+
with:
16+
cmd: install # will run `yarn install` command
17+
- name: Run tests and collect coverage
18+
uses: borales/actions-yarn@v4
19+
with:
20+
cmd: coverage # will run `yarn coverage` command
21+
- name: Upload coverage to Codecov
22+
uses: codecov/codecov-action@v4
23+
env:
24+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
node_modules
33
out
44
.tmp
5+
coverage

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ DeFi organizations, protocols, their integration statuses, usage and other infor
3939
```shell
4040
yarn overview
4141
yarn overview-full
42+
yarn test
43+
yarn coverage
4244
```

jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
transform: {'^.+\\.ts?$': 'ts-jest'},
4+
testEnvironment: 'node',
5+
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
6+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7+
modulePathIgnorePatterns: ["out"],
8+
collectCoverageFrom: ["src/**/*.ts"]
9+
};

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stabilitydao/stability",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Stability Integration Library",
55
"main": "out/index.js",
66
"types": "out/index.d.ts",
@@ -16,12 +16,17 @@
1616
"private": false,
1717
"scripts": {
1818
"build": "tsc",
19+
"test": "jest",
20+
"coverage": "jest --collect-coverage",
1921
"overview": "ts-node tools/overview.ts",
2022
"overview-full": "ts-node tools/overview-full.ts"
2123
},
2224
"devDependencies": {
25+
"@types/jest": "^29.5.12",
2326
"ansis": "^3.2.0",
2427
"console-table-printer": "^2.12.0",
28+
"jest": "^29.7.0",
29+
"ts-jest": "^29.1.4",
2530
"ts-node": "^10.9.2",
2631
"typescript": "^5.4.5"
2732
}

src/integrations.ts

+49-49
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type DeFiProtocol = {
2020
coreContracts?: string[]
2121
}
2222

23-
export enum IntegrationStatus {
23+
export const enum IntegrationStatus {
2424
LIVE = 'Live',
2525
IN_USE = 'In use',
2626
BEING_DEPLOYED = 'Being deployed',
@@ -44,54 +44,6 @@ export enum DefiCategory {
4444
LST = 'Liquid staking',
4545
}
4646

47-
export const getIntegrationStatus = (p: DeFiProtocol): IntegrationStatus => {
48-
if (p.coreContracts && p.coreContracts.length > 0) {
49-
return IntegrationStatus.LIVE
50-
}
51-
if (p.adapters && p.adapters.length > 0) {
52-
return IntegrationStatus.LIVE
53-
}
54-
if (p.strategies) {
55-
for (const strategy of p.strategies) {
56-
if (strategies[strategy]?.state == StrategyState.LIVE) {
57-
return IntegrationStatus.LIVE
58-
}
59-
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
60-
return IntegrationStatus.BEING_DEPLOYED
61-
}
62-
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
63-
return IntegrationStatus.DEVELOPMENT
64-
}
65-
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
66-
return IntegrationStatus.AWAITING
67-
}
68-
}
69-
}
70-
if (p.intermediaryStrategies) {
71-
for (const strategy of p.intermediaryStrategies) {
72-
if (strategies[strategy]?.state == StrategyState.LIVE) {
73-
return IntegrationStatus.IN_USE
74-
}
75-
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
76-
return IntegrationStatus.BEING_DEPLOYED
77-
}
78-
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
79-
return IntegrationStatus.DEVELOPMENT
80-
}
81-
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
82-
return IntegrationStatus.AWAITING
83-
}
84-
}
85-
}
86-
const supportedNetWorkIds = Object.keys(deployments).map(chainIdString => networks[chainIdString].id)
87-
for (const protocolNetworkId of p.networks) {
88-
if (supportedNetWorkIds.includes(protocolNetworkId as NetworkId)) {
89-
return IntegrationStatus.POSSIBLE
90-
}
91-
}
92-
return IntegrationStatus.PROPOSED
93-
}
94-
9547
export const integrations: { [org: string]: DeFiOrganization } = {
9648
// oracle
9749
chainlink: {
@@ -655,3 +607,51 @@ export const integrations: { [org: string]: DeFiOrganization } = {
655607
defiLlama: 'stader',
656608
},
657609
};
610+
611+
export const getIntegrationStatus = (p: DeFiProtocol): IntegrationStatus => {
612+
if (p.coreContracts && p.coreContracts.length > 0) {
613+
return IntegrationStatus.LIVE
614+
}
615+
if (p.adapters && p.adapters.length > 0) {
616+
return IntegrationStatus.LIVE
617+
}
618+
if (p.strategies) {
619+
for (const strategy of p.strategies) {
620+
if (strategies[strategy]?.state == StrategyState.LIVE) {
621+
return IntegrationStatus.LIVE
622+
}
623+
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
624+
return IntegrationStatus.BEING_DEPLOYED
625+
}
626+
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
627+
return IntegrationStatus.DEVELOPMENT
628+
}
629+
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
630+
return IntegrationStatus.AWAITING
631+
}
632+
}
633+
}
634+
if (p.intermediaryStrategies) {
635+
for (const strategy of p.intermediaryStrategies) {
636+
if (strategies[strategy]?.state == StrategyState.LIVE) {
637+
return IntegrationStatus.IN_USE
638+
}
639+
if (strategies[strategy]?.state == StrategyState.AWAITING_DEPLOYMENT) {
640+
return IntegrationStatus.BEING_DEPLOYED
641+
}
642+
if (strategies[strategy]?.state == StrategyState.DEVELOPMENT) {
643+
return IntegrationStatus.DEVELOPMENT
644+
}
645+
if (strategies[strategy]?.state == StrategyState.PROPOSED) {
646+
return IntegrationStatus.AWAITING
647+
}
648+
}
649+
}
650+
const supportedNetWorkIds = Object.keys(deployments).map(chainIdString => networks[chainIdString].id)
651+
for (const protocolNetworkId of p.networks) {
652+
if (supportedNetWorkIds.includes(protocolNetworkId as NetworkId)) {
653+
return IntegrationStatus.POSSIBLE
654+
}
655+
}
656+
return IntegrationStatus.PROPOSED
657+
}

src/strategies.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {integrations} from "./integrations";
2+
13
export type Strategy = {
24
id: string
35
shortId: StrategyShortId
@@ -7,7 +9,7 @@ export type Strategy = {
79
bgColor: string
810
}
911

10-
export enum StrategyShortId {
12+
export const enum StrategyShortId {
1113
QSMF = 'QSMF',
1214
DQMF = 'DQMF',
1315
IQMF = 'IQMF',
@@ -36,7 +38,7 @@ export enum StrategyState {
3638
PROPOSED = 'Proposed',
3739
}
3840

39-
export const strategies: {[shortId in StrategyShortId]?:Strategy} = {
41+
export const strategies: {[shortId in StrategyShortId]:Strategy} = {
4042
[StrategyShortId.QSMF]: {
4143
id: 'QuickSwap Static Merkl Farm',
4244
shortId: StrategyShortId.QSMF,
@@ -190,3 +192,11 @@ export const strategies: {[shortId in StrategyShortId]?:Strategy} = {
190192
bgColor: "#000000",
191193
},
192194
};
195+
196+
export const getMerklStrategies = (): string[] => {
197+
const strategyShortIds = integrations.angle.protocols.merkl.strategies as StrategyShortId[]
198+
return strategyShortIds.map(shortId => {
199+
const strategy = strategies[shortId] as Strategy
200+
return strategy.id
201+
})
202+
}

tests/index.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {NetworkId, networks, strategies, deployments, integrations, StrategyShortId} from "../src";
2+
3+
describe('index', () => {
4+
test('deployments', () => {
5+
expect(deployments["137"].platform).toBe("0xb2a0737ef27b5Cc474D24c779af612159b1c3e60")
6+
})
7+
test('networks', () => {
8+
expect(networks["1"].id).toBe(NetworkId.ETHEREUM)
9+
})
10+
test('strategies', () => {
11+
expect(strategies[StrategyShortId.CCF].id).toBe('Curve Convex Farm')
12+
})
13+
test('integrations', () => {
14+
expect(integrations["chainlink"].name).toBe('ChainLink')
15+
})
16+
})

tests/integrations.test.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { getIntegrationStatus} from "../src/integrations";
2+
import {NetworkId, strategies, StrategyShortId, StrategyState, DefiCategory, DeFiProtocol, IntegrationStatus} from "../src";
3+
4+
describe('testing integrations', () => {
5+
test('get protocol integration status', () => {
6+
const protocol: DeFiProtocol = {
7+
name: 'Test',
8+
category: DefiCategory.AMM,
9+
networks: [NetworkId.BSC,],
10+
}
11+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.PROPOSED)
12+
protocol.networks = [NetworkId.POLYGON,]
13+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.POSSIBLE)
14+
protocol.coreContracts = ['PriceReader',]
15+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.LIVE)
16+
protocol.coreContracts = undefined
17+
protocol.adapters = ['TestAdapter',]
18+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.LIVE)
19+
protocol.adapters = undefined
20+
protocol.strategies = [StrategyShortId.IQMF,]
21+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.LIVE)
22+
strategies[StrategyShortId.IQMF].state = StrategyState.AWAITING_DEPLOYMENT
23+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.BEING_DEPLOYED)
24+
strategies[StrategyShortId.IQMF].state = StrategyState.DEVELOPMENT
25+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.DEVELOPMENT)
26+
strategies[StrategyShortId.IQMF].state = StrategyState.PROPOSED
27+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.AWAITING)
28+
protocol.strategies = undefined
29+
protocol.intermediaryStrategies = [StrategyShortId.IQMF,]
30+
strategies[StrategyShortId.IQMF].state = StrategyState.LIVE
31+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.IN_USE)
32+
strategies[StrategyShortId.IQMF].state = StrategyState.AWAITING_DEPLOYMENT
33+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.BEING_DEPLOYED)
34+
strategies[StrategyShortId.IQMF].state = StrategyState.DEVELOPMENT
35+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.DEVELOPMENT)
36+
strategies[StrategyShortId.IQMF].state = StrategyState.PROPOSED
37+
expect(getIntegrationStatus(protocol)).toBe(IntegrationStatus.AWAITING)
38+
})
39+
})

tests/strategies.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {getMerklStrategies} from "../src/strategies";
2+
3+
describe('testing strategies', () => {
4+
test('get merkl strategies', () => {
5+
const merklStrategies = getMerklStrategies();
6+
expect(merklStrategies.includes('Gamma UniswapV3 Merkl Farm')).toBe(true);
7+
expect(merklStrategies.includes('A51 BaseSwap Merkl Farm')).toBe(true);
8+
expect(merklStrategies.length).toBeGreaterThan(13)
9+
});
10+
});

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"outDir": "./out",
1111
"rootDir": "./src",
1212
"resolveJsonModule": true,
13+
"esModuleInterop": true,
1314
},
14-
"include": ["src/**/*", "tests/**/*"]
15+
"include": ["src/**/*",]
1516
}

0 commit comments

Comments
 (0)