From ff9b76cd14a32300f5cf1126ca533d42e80b991d Mon Sep 17 00:00:00 2001 From: Alien Deployer Date: Fri, 18 Oct 2024 02:07:08 +0300 Subject: [PATCH 1/6] implement getChainByName --- package.json | 2 +- src/chains.ts | 10 ++++++++++ src/index.ts | 4 +++- tests/networks.test.ts | 11 ++++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 63008fc..4419c96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stabilitydao/stability", - "version": "0.18.2", + "version": "0.18.3", "description": "Stability Integration Library", "main": "out/index.js", "types": "out/index.d.ts", diff --git a/src/chains.ts b/src/chains.ts index 40a058d..216cd58 100644 --- a/src/chains.ts +++ b/src/chains.ts @@ -573,3 +573,13 @@ export const getChainsTotals = (): { [status in ChainStatus]: number } => { [ChainStatus.NOT_SUPPORTED]: ids.filter(networkId => chains[networkId].status == ChainStatus.NOT_SUPPORTED).length, } } + +export const getChainByName = (chainName: ChainName): Chain => { + for (const chainId in chains) { + const chain = chains[chainId] + if (chain && chain.name === chainName) { + return chain + } + } + throw new Error(`Incorrect chain name ${chainName}`) +} diff --git a/src/index.ts b/src/index.ts index fb4efbf..9376fbc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,8 @@ import { Chain, ChainStatusInfo, getSupportedChainNames, - getChainsTotals + getChainsTotals, + getChainByName } from "./chains"; import { strategies, @@ -71,6 +72,7 @@ export { getChainProtocols, getChainStrategies, getSupportedChainNames, + getChainByName, assets, Asset, getAsset, diff --git a/tests/networks.test.ts b/tests/networks.test.ts index c0fca83..27fe849 100644 --- a/tests/networks.test.ts +++ b/tests/networks.test.ts @@ -1,4 +1,4 @@ -import {getChainsTotals, getSupportedChainNames} from "../src"; +import {ChainName, getChainByName, getChainsTotals, getSupportedChainNames} from "../src"; describe('testing chains', () => { test('get supported network IDs', () => { @@ -8,4 +8,13 @@ describe('testing chains', () => { const s = getChainsTotals() expect(s.SUPPORTED).toBeGreaterThan(1) }) + test('getChainByName', () => { + let s = getChainByName(ChainName.POLYGON) + expect(s.name).toEqual("Polygon") + const t = () => { + s = getChainByName('incorrect' as ChainName) + }; + expect(t).toThrow(Error); + }) + }) From 19d47eef42b6ad4777942401e3a45af173ed0fcf Mon Sep 17 00:00:00 2001 From: Alien Deployer Date: Fri, 18 Oct 2024 02:24:11 +0300 Subject: [PATCH 2/6] cover contest types by tests --- tests/contests.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/contests.test.ts b/tests/contests.test.ts index 758cadf..9425dc8 100644 --- a/tests/contests.test.ts +++ b/tests/contests.test.ts @@ -1,4 +1,4 @@ -import {contests} from "../src"; +import {contests, RewardType, YieldContest} from "../src"; describe('testing contests', () => { test('check start less then end', () => { @@ -6,4 +6,8 @@ describe('testing contests', () => { expect(contests[contestId].start).toBeLessThan(contests[contestId].end) } }) + test('types', () => { + const c: YieldContest = contests["y1"] + expect(c.rewards[0].type).toEqual(RewardType.POINTS) + }) }) From b2d37c9362d761888eb24297846fcd0a0acbf2db Mon Sep 17 00:00:00 2001 From: Alien Deployer Date: Fri, 18 Oct 2024 02:27:23 +0300 Subject: [PATCH 3/6] refactor chain tests --- tests/{networks.test.ts => chains.test.ts} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename tests/{networks.test.ts => chains.test.ts} (86%) diff --git a/tests/networks.test.ts b/tests/chains.test.ts similarity index 86% rename from tests/networks.test.ts rename to tests/chains.test.ts index 27fe849..c845fce 100644 --- a/tests/networks.test.ts +++ b/tests/chains.test.ts @@ -1,10 +1,10 @@ import {ChainName, getChainByName, getChainsTotals, getSupportedChainNames} from "../src"; describe('testing chains', () => { - test('get supported network IDs', () => { + test('get supported chain names', () => { expect(getSupportedChainNames().length).toBeGreaterThan(1) }) - test('getNetworksTotals', () => { + test('getChainsTotals', () => { const s = getChainsTotals() expect(s.SUPPORTED).toBeGreaterThan(1) }) @@ -16,5 +16,4 @@ describe('testing chains', () => { }; expect(t).toThrow(Error); }) - }) From 7b3488be5c2def29273d2e9629b6e44a0aa15b6c Mon Sep 17 00:00:00 2001 From: Alien Deployer Date: Fri, 18 Oct 2024 02:30:42 +0300 Subject: [PATCH 4/6] fix readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bdd281c..f6ffba2 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ Blockchains known to the platform and their integration statuses. Each chain has * `getSupportedChainNames(): ChainName[]` * `getChainsTotals(): {[status in ChainStatus]: number}` +* `getChainByName(chainName: ChainName): Chain` ### 🌐 Integrations From 5ba0ce7eaa25f3832a13d3fe728760481bea9068 Mon Sep 17 00:00:00 2001 From: Alien Deployer Date: Fri, 18 Oct 2024 02:51:27 +0300 Subject: [PATCH 5/6] minEarn and rewards can be "TBA", add 2 contests --- src/contests.ts | 21 +++++++++++++++++++-- tools/create-contests.ts | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/contests.ts b/src/contests.ts index 6e31f0a..abf0ec6 100644 --- a/src/contests.ts +++ b/src/contests.ts @@ -7,9 +7,10 @@ export interface YieldContest { start: number, // end timestamp end: number, - minEarn: number, + // minimal USD income to pass contest + minEarn: number|"TBA", // contest rewards - rewards: Reward[], + rewards: Reward[]|"TBA", // integration of quest platform campaign integration?: { // Intract campaign id @@ -144,4 +145,20 @@ export const contests: { [contestId: string]: YieldContest } = { }, ], }, + "y4": { + // 05 Dec 2024 - 18 Dec 2024 + name: "Yield Contest #4", + start: 1733356800, // Thu, 05 Dec 2024 00:00:00 GMT + end: 1734566399, // Wed, 18 Dec 2024 23:59:59 GMT + minEarn: "TBA", + rewards: "TBA", + }, + "y5": { + // 19 Dec 2024 - 01 Jan 2025 + name: "Yield Contest #5", + start: 1734566400, // Thu, 19 Dec 2024 00:00:00 GMT + end: 1735775999, // Wed, 01 Jan 2025 23:59:59 GMT + minEarn: "TBA", + rewards: "TBA", + }, } diff --git a/tools/create-contests.ts b/tools/create-contests.ts index 889b586..43c7b2b 100644 --- a/tools/create-contests.ts +++ b/tools/create-contests.ts @@ -20,6 +20,8 @@ for (let i = +(lastId.replace('y', '') || 0) + 1; i < +(lastId.replace('y', '') name: "${name}", start: ${start}, // ${new Date(start * 1000).toUTCString()} end: ${end}, // ${new Date(end * 1000).toUTCString()} + minEarn: "TBA", + rewards: "TBA", \},`) prevTs += PERIOD } From e5d0ccee2c69ab5d2fd4466772a51479ef6f3ef2 Mon Sep 17 00:00:00 2001 From: Alien Deployer Date: Fri, 18 Oct 2024 02:57:22 +0300 Subject: [PATCH 6/6] fix contest types test --- tests/contests.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/contests.test.ts b/tests/contests.test.ts index 9425dc8..f81d078 100644 --- a/tests/contests.test.ts +++ b/tests/contests.test.ts @@ -1,4 +1,4 @@ -import {contests, RewardType, YieldContest} from "../src"; +import {contests, Reward, RewardType, YieldContest} from "../src"; describe('testing contests', () => { test('check start less then end', () => { @@ -8,6 +8,6 @@ describe('testing contests', () => { }) test('types', () => { const c: YieldContest = contests["y1"] - expect(c.rewards[0].type).toEqual(RewardType.POINTS) + expect((c.rewards[0] as Reward).type).toEqual(RewardType.POINTS) }) })