From 7f60dd71570a344529e2e275a1bc416e2e701a30 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 16 Dec 2024 19:55:39 +1000 Subject: [PATCH] feat: Add Meson and Stargate server API endpoint --- apps/canonical-bridge-server/.env.example | 2 + .../src/common/constants/index.ts | 7 +++ .../src/module/bridge/bridge.controller.ts | 10 ++++ .../src/module/bridge/bridge.processor.ts | 12 ++++ .../src/module/bridge/bridge.schedule.ts | 8 +++ .../src/shared/web3/web3.interface.ts | 59 +++++++++++++++++++ .../src/shared/web3/web3.service.ts | 18 ++++++ 7 files changed, 116 insertions(+) diff --git a/apps/canonical-bridge-server/.env.example b/apps/canonical-bridge-server/.env.example index 596837d2..db801b5b 100644 --- a/apps/canonical-bridge-server/.env.example +++ b/apps/canonical-bridge-server/.env.example @@ -6,6 +6,8 @@ CMC_API_KEY= CMC_API_ENDPOINT=https://pro-api.coinmarketcap.com CBRIDGE_ENDPOINT=https://cbridge-prod2.celer.app DEBRIDGE_ENDPOINT=https://deswap.debridge.finance/v1.0 +STARGATE_ENDPOINT='https://mainnet.stargate-api.com/v1/metadata?version=v2' +MESON_ENDPOINT=https://relayer.meson.fi/api/v1 REDIS_URL=http://127.0.0.1:6379 DATABASE_URL=mysql://test:xxx@localhost:3306/bridge diff --git a/apps/canonical-bridge-server/src/common/constants/index.ts b/apps/canonical-bridge-server/src/common/constants/index.ts index 3f8460eb..6b26445a 100644 --- a/apps/canonical-bridge-server/src/common/constants/index.ts +++ b/apps/canonical-bridge-server/src/common/constants/index.ts @@ -8,6 +8,9 @@ export const CMC_API_ENDPOINT = process.env.CMC_API_ENDPOINT || 'https://pro-api export const CBRIDGE_ENDPOINT = process.env.CBRIDGE_ENDPOINT || 'https://cbridge-prod2.celer.app'; export const DEBRIDGE_ENDPOINT = process.env.DEBRIDGE_ENDPOINT || 'https://deswap.debridge.finance/v1.0'; +export const STARGATE_ENDPOINT = + process.env.STARGATE_ENDPOINT || 'https://mainnet.stargate-api.com/v1/metadata?version=v2'; +export const MESON_ENDPOINT = process.env.MESON_ENDPOINT || 'https://relayer.meson.fi/api/v1'; export const LLAMA_COINS_ENDPOINT = process.env.LLMA_COINS__ENDPOINT || 'https://coins.llama.fi'; export const COINGECKO_ENDPOINT = process.env.COINGECKO_ENDPOINT || 'https://api.coingecko.com/api'; @@ -28,6 +31,8 @@ export enum Tasks { fetchLlamaPrice = 'fetchLlamaPrice', fetchCbridge = 'fetchCbridge', fetchDebridge = 'fetchDebridge', + fetchStargate = 'fetchStargate', + fetchMeson = 'fetchMeson', cacheCmcConfig = 'cacheCmcConfig', cacheLlamaConfig = 'cacheLlamaConfig', } @@ -43,6 +48,8 @@ export const CACHE_KEY = { CMC_CRYPTO_TOKEN: 'cmc:token', CBRIDGE_CONFIG: 'bridge:cbridge', DEBRIDGE_CONFIG: 'bridge:debridge', + STARGATE_CONFIG: 'bridge:stargate', + MESON_CONFIG: 'bridge:meson', CMC_CONFIG: 'cmc:config', LLAMA_CONFIG: 'llama:config', PLATFORM_MAPPING: 'llama:platform', diff --git a/apps/canonical-bridge-server/src/module/bridge/bridge.controller.ts b/apps/canonical-bridge-server/src/module/bridge/bridge.controller.ts index ff407b44..8f311f18 100644 --- a/apps/canonical-bridge-server/src/module/bridge/bridge.controller.ts +++ b/apps/canonical-bridge-server/src/module/bridge/bridge.controller.ts @@ -17,4 +17,14 @@ export class BridgeController { getDeBridgeConfig() { return this.cache.get(CACHE_KEY.DEBRIDGE_CONFIG); } + + @Get('/stargate') + getStargateConfig() { + return this.cache.get(CACHE_KEY.STARGATE_CONFIG); + } + + @Get('/meson') + getMesonConfig() { + return this.cache.get(CACHE_KEY.MESON_CONFIG); + } } diff --git a/apps/canonical-bridge-server/src/module/bridge/bridge.processor.ts b/apps/canonical-bridge-server/src/module/bridge/bridge.processor.ts index 71b74774..b4e339e2 100644 --- a/apps/canonical-bridge-server/src/module/bridge/bridge.processor.ts +++ b/apps/canonical-bridge-server/src/module/bridge/bridge.processor.ts @@ -49,4 +49,16 @@ export class BridgeProcessor extends WorkerHost { if (!config) return; await this.cache.set(`${CACHE_KEY.CBRIDGE_CONFIG}`, config); } + + async fetchStargate() { + const config = await this.web3Service.getStargateConfigs(); + if (!config) return; + await this.cache.set(`${CACHE_KEY.STARGATE_CONFIG}`, config); + } + + async fetchMeson() { + const config = await this.web3Service.getMesonConfigs(); + if (!config) return; + await this.cache.set(`${CACHE_KEY.MESON_CONFIG}`, config); + } } diff --git a/apps/canonical-bridge-server/src/module/bridge/bridge.schedule.ts b/apps/canonical-bridge-server/src/module/bridge/bridge.schedule.ts index 70dffcf1..96317135 100644 --- a/apps/canonical-bridge-server/src/module/bridge/bridge.schedule.ts +++ b/apps/canonical-bridge-server/src/module/bridge/bridge.schedule.ts @@ -21,6 +21,14 @@ export class BridgeSchedule implements OnModuleInit { jobId: Tasks.fetchDebridge, removeOnComplete: true, }); + await this.syncBridge.add(Tasks.fetchStargate, null, { + jobId: Tasks.fetchStargate, + removeOnComplete: true, + }); + await this.syncBridge.add(Tasks.fetchMeson, null, { + jobId: Tasks.fetchMeson, + removeOnComplete: true, + }); } async onModuleInit() { diff --git a/apps/canonical-bridge-server/src/shared/web3/web3.interface.ts b/apps/canonical-bridge-server/src/shared/web3/web3.interface.ts index 4da2eb57..1a604707 100644 --- a/apps/canonical-bridge-server/src/shared/web3/web3.interface.ts +++ b/apps/canonical-bridge-server/src/shared/web3/web3.interface.ts @@ -137,3 +137,62 @@ export interface ICoinPrice { price: number; decimals: number; } + +export interface IStargateBridgeTokenInfo { + stargateType: string; + address: `0x${string}`; + token: { + address: `0x${string}`; + decimals: number; + symbol: string; + }; + lpToken: { + address: `0x${string}`; + decimals: number; + symbol: string; + }; + farm: { + stargateStaking: { + address: `0x${string}`; + rewardTokens: [ + { + address: `0x${string}`; + decimals: number; + symbol: string; + }, + { + address: `0x${string}`; + decimals: number; + symbol: string; + }, + ]; + }; + }; + id: string; + assetId: string; + chainKey: string; + chainName: string; + tokenMessaging: `0x${string}`; + sharedDecimals: number; +} +export interface IStargateTokenList { + v1: IStargateBridgeTokenInfo[]; + v2: IStargateBridgeTokenInfo[]; +} + +export interface IMesonToken { + id: string; + symbol: string; + name: string; + decimals: number; + addr?: string; + min: string; + max: string; +} +export interface IMesonChain { + id: string; + name: string; + chainId: string; + address: string; + tokens: IMesonToken[]; +} diff --git a/apps/canonical-bridge-server/src/shared/web3/web3.service.ts b/apps/canonical-bridge-server/src/shared/web3/web3.service.ts index 9a225ecb..1a6ac4e2 100644 --- a/apps/canonical-bridge-server/src/shared/web3/web3.service.ts +++ b/apps/canonical-bridge-server/src/shared/web3/web3.service.ts @@ -9,6 +9,8 @@ import { ICryptoCurrencyQuoteEntity, IDebridgeChain, IDebridgeToken, + IMesonChain, + IStargateTokenList, ITransferConfigsForAll, } from '@/shared/web3/web3.interface'; import { @@ -17,6 +19,8 @@ import { CMC_API_KEY, COINGECKO_ENDPOINT, DEBRIDGE_ENDPOINT, + STARGATE_ENDPOINT, + MESON_ENDPOINT, LLAMA_COINS_ENDPOINT, TOKEN_REQUEST_LIMIT, } from '@/common/constants'; @@ -78,6 +82,20 @@ export class Web3Service { return data; } + async getStargateConfigs() { + const { data } = await this.httpService.axiosRef.get( + `${STARGATE_ENDPOINT}`, + ); + return data; + } + + async getMesonConfigs() { + const { data } = await this.httpService.axiosRef.get<{ result: IMesonChain[] }>( + `${MESON_ENDPOINT}/limits`, + ); + return data; + } + async getAssetPlatforms() { const { data } = await this.httpService.axiosRef.get( `${COINGECKO_ENDPOINT}/v3/asset_platforms`,