Skip to content

Commit

Permalink
Merge pull request #199 from bnb-chain/feat/tokenApi1216
Browse files Browse the repository at this point in the history
feat: Add Meson and Stargate server API endpoint
  • Loading branch information
wenty22 authored Dec 17, 2024
2 parents 94005a7 + 7f60dd7 commit e01a4af
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/canonical-bridge-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions apps/canonical-bridge-server/src/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,6 +31,8 @@ export enum Tasks {
fetchLlamaPrice = 'fetchLlamaPrice',
fetchCbridge = 'fetchCbridge',
fetchDebridge = 'fetchDebridge',
fetchStargate = 'fetchStargate',
fetchMeson = 'fetchMeson',
cacheCmcConfig = 'cacheCmcConfig',
cacheLlamaConfig = 'cacheLlamaConfig',
}
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions apps/canonical-bridge-server/src/module/bridge/bridge.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
59 changes: 59 additions & 0 deletions apps/canonical-bridge-server/src/shared/web3/web3.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
18 changes: 18 additions & 0 deletions apps/canonical-bridge-server/src/shared/web3/web3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
ICryptoCurrencyQuoteEntity,
IDebridgeChain,
IDebridgeToken,
IMesonChain,
IStargateTokenList,
ITransferConfigsForAll,
} from '@/shared/web3/web3.interface';
import {
Expand All @@ -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';
Expand Down Expand Up @@ -78,6 +82,20 @@ export class Web3Service {
return data;
}

async getStargateConfigs() {
const { data } = await this.httpService.axiosRef.get<IStargateTokenList>(
`${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<IAssetPlatform[]>(
`${COINGECKO_ENDPOINT}/v3/asset_platforms`,
Expand Down

0 comments on commit e01a4af

Please sign in to comment.