Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Meson & Stargate token API #211

Merged
merged 42 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
517bf53
feat: Aggregate Meson API
Halibao-Lala Dec 18, 2024
1744cd7
feat: Update meson token name, symbol and address
Halibao-Lala Dec 18, 2024
bcd6263
Merge branch 'server/stargateAPI' into feat/tokenApi1216
Halibao-Lala Dec 23, 2024
adb2607
feat: Stargate token aggregation
Halibao-Lala Dec 23, 2024
b930ad4
feat: Add more token info to token element
wenty22 Dec 23, 2024
9879ab1
Merge pull request #213 from bnb-chain/wenty/token-info
wenty22 Dec 23, 2024
30af8b3
chore: Release
wenty22 Dec 23, 2024
61cbb0e
fix: Modify optimism endpointID to 30111
wenty22 Dec 24, 2024
ef7a857
fix: Fix security issues
wenty22 Dec 24, 2024
7488a4b
feat: Use all chains for bridge
wenty22 Dec 24, 2024
9244015
chore: Update dockerfile
wenty22 Dec 24, 2024
320933b
Merge pull request #215 from bnb-chain/wenty/api
wenty22 Dec 24, 2024
8b2f3c3
chore: Update dockerfile
wenty22 Dec 24, 2024
ad8aa32
Merge pull request #216 from bnb-chain/wenty/api
wenty22 Dec 24, 2024
0aece29
Merge branch 'main' into feat/tokenApi1216
wenty22 Dec 24, 2024
18ad352
chore: Update dockerfile
wenty22 Dec 24, 2024
8e29d84
Merge pull request #217 from bnb-chain/wenty/api
wenty22 Dec 24, 2024
68a8453
chore: Update dockerfile
wenty22 Dec 24, 2024
c4f3ee7
feat: Update token element's info
wenty22 Dec 25, 2024
d037d3b
chore: Running app as a non-root user
wenty22 Dec 25, 2024
635b330
chore: Running app as a non-root user
wenty22 Dec 25, 2024
2f58d3c
Merge pull request #220 from bnb-chain/alpha/server
wenty22 Dec 25, 2024
2538636
feat: Remove duplicated tokens for stargate
wenty22 Dec 26, 2024
9db88fb
chore: Update code owners
wenty22 Dec 27, 2024
d13f59d
fix: Modify klaytn's rpc url
wenty22 Dec 27, 2024
008c36a
fix: Filter native token for meson
wenty22 Dec 27, 2024
7174249
fix: Remove duplicated token on meson
wenty22 Dec 27, 2024
7caf17e
fix: Fix meson token display symbol issue
wenty22 Dec 27, 2024
46c3814
fix: Fix tron does not display due to its id
wenty22 Dec 27, 2024
fb84eb5
fix: Fix tron does not display due to its id
wenty22 Dec 27, 2024
e19a76c
feat: Add cache time to server
wenty22 Dec 27, 2024
2cfa824
feat: Add cache time to server
wenty22 Dec 27, 2024
22ef9ea
feat: Remove simulation logic
wenty22 Dec 27, 2024
10212b5
feat: Handle adaptor error
Halibao-Lala Dec 30, 2024
10d6a39
feat: Filter out stargate token without endpointID
Halibao-Lala Dec 30, 2024
6a85850
fix: Fix stargate fee display issue
Halibao-Lala Dec 30, 2024
9827ecd
feat: Add api error handler
Halibao-Lala Dec 30, 2024
68de75d
chore: Add error return value
Halibao-Lala Dec 30, 2024
0854dd5
chore: Display proper error messages
Halibao-Lala Dec 30, 2024
003572b
chore: Remove error return value
Halibao-Lala Dec 30, 2024
5d08223
fix: Fix stargate fee display text and handle api error
Halibao-Lala Dec 30, 2024
be8248c
chore: Remove unused files
Halibao-Lala Dec 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @aiden-cao @wenty22 @Halibao-Lala @doge95
* @aiden-cao @wenty22 @Halibao-Lala @doge95 @robot-ux
6 changes: 6 additions & 0 deletions .release/.changeset/bright-impalas-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bnb-chain/canonical-bridge-widget": patch
"@bnb-chain/canonical-bridge-sdk": patch
---

Use stargate & meson api to fetch chain & token config
6 changes: 6 additions & 0 deletions .release/.changeset/dull-moose-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bnb-chain/canonical-bridge-widget": patch
"@bnb-chain/canonical-bridge-sdk": patch
---

Remove duplicated tokens for stargate
5 changes: 5 additions & 0 deletions .release/.changeset/giant-rings-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Fix stargate fee display and handle api error
6 changes: 6 additions & 0 deletions .release/.changeset/hungry-doors-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bnb-chain/canonical-bridge-widget": patch
"@bnb-chain/canonical-bridge-sdk": patch
---

Update token element's info
6 changes: 6 additions & 0 deletions .release/.changeset/itchy-dots-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bnb-chain/canonical-bridge-widget": patch
"@bnb-chain/canonical-bridge-sdk": patch
---

Fix meson token display symbol issue
5 changes: 5 additions & 0 deletions .release/.changeset/poor-kings-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Fix tron does not display due to its id
16 changes: 16 additions & 0 deletions .release/.changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"@bnb-chain/canonical-bridge-sdk": "0.4.5",
"@bnb-chain/canonical-bridge-widget": "0.5.15"
},
"changesets": [
"bright-impalas-sniff",
"dull-moose-deliver",
"hungry-doors-lick",
"itchy-dots-enjoy",
"poor-kings-compete",
"serious-cars-worry"
]
}
5 changes: 5 additions & 0 deletions .release/.changeset/serious-cars-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Add more token info to token element
1 change: 0 additions & 1 deletion .release/scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ process.chdir(rootDir);

console.log('Install changeset dependencies...');
exec('pnpm install', (err, stdout) => {
console.log('shshshshsh');
if (stdout) {
console.log(stdout);
}
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"tronwallet",
"tronweb",
"unauthenticate",
"vconsole",
"viem",
"Wagmi",
"walletkit"
Expand Down
2 changes: 1 addition & 1 deletion apps/canonical-bridge-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ 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
DATABASE_URL=
9 changes: 5 additions & 4 deletions apps/canonical-bridge-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
FROM busybox:1.36.1 as builder
FROM busybox:1.36.1 AS builder
FROM node:20-buster

RUN useradd -u 9000 appuser
USER appuser

WORKDIR /opt/deploy

COPY . .
Expand All @@ -14,6 +11,10 @@ COPY --from=builder /bin/sleep /usr/local/bin/sleep

WORKDIR /opt/deploy/apps/canonical-bridge-server

RUN useradd -u 9000 appuser
RUN chown -R appuser /opt/deploy/apps/canonical-bridge-server
USER appuser

EXPOSE 3000

ENV NODE_ENV production
Expand Down
3 changes: 2 additions & 1 deletion apps/canonical-bridge-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AllExceptionFilter } from './common/filters/all-exception.filter';
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
import { TimeoutInterceptor } from './common/interceptors/timeout.interceptor';
import { REDIS_HOST, REDIS_PORT } from './common/constants';
import { REDIS_HOST, REDIS_PORT, TIME } from './common/constants';
import { TokenModule } from './module/token/token.module';
import { BullModule } from '@nestjs/bullmq';
import { Web3Module } from '@/shared/web3/web3.module';
Expand All @@ -32,6 +32,7 @@ import { BridgeModule } from '@/module/bridge/bridge.module';
HealthModule,
ScheduleModule.forRoot(),
CacheModule.register<RedisOptions>({
ttl: TIME.DAY,
isGlobal: true,
store: () => redisStore({ host: REDIS_HOST, port: REDIS_PORT }),
}),
Expand Down
9 changes: 9 additions & 0 deletions apps/canonical-bridge-server/src/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export const JOB_KEY = {
CORN_PRICE_PREFIX: 'corn:price:',
};

export const TIME = {
SECOND: 1000,
MINUTE: 60 * 1000,
HOUR: 60 * 60 * 1000,
DAY: 24 * 60 * 60 * 1000,
WEEK: 7 * 24 * 60 * 60 * 1000,
MONTH: 30 * 24 * 60 * 60 * 1000,
};

export const STARGATE_CHAIN_INFO = [
{
chainId: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CACHE_KEY, Queues, Tasks } from '@/common/constants';
import { CACHE_KEY, Queues, Tasks, TIME } from '@/common/constants';
import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Inject, Logger } from '@nestjs/common';
import { Job } from 'bullmq';
Expand Down Expand Up @@ -45,24 +45,24 @@ export class BridgeProcessor extends WorkerHost {

const data = { chains: config.chains, tokens: tokenMap };

await this.cache.set(`${CACHE_KEY.DEBRIDGE_CONFIG}`, data);
await this.cache.set(`${CACHE_KEY.DEBRIDGE_CONFIG}`, data, TIME.DAY);
}

async fetchCBridge() {
const config = await this.web3Service.getTransferConfigsForAll();
if (!config) return;
await this.cache.set(`${CACHE_KEY.CBRIDGE_CONFIG}`, config);
await this.cache.set(`${CACHE_KEY.CBRIDGE_CONFIG}`, config, TIME.DAY);
}

async fetchStargate() {
const config = await this.web3Service.getStargateConfigs();
if (!config) return;
await this.cache.set(`${CACHE_KEY.STARGATE_CONFIG}`, config);
await this.cache.set(`${CACHE_KEY.STARGATE_CONFIG}`, config, TIME.DAY);
}

async fetchMeson() {
const config = await this.web3Service.getMesonConfigs();
if (!config) return;
await this.cache.set(`${CACHE_KEY.MESON_CONFIG}`, config);
await this.cache.set(`${CACHE_KEY.MESON_CONFIG}`, config, TIME.DAY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class BridgeSchedule implements OnModuleInit {

constructor(@InjectQueue(Queues.SyncBridge) private syncBridge: Queue) {}

@Cron(CronExpression.EVERY_3_HOURS)
@Cron(CronExpression.EVERY_5_MINUTES)
async syncBridgeInfo() {
this.logger.log('syncBridgeInfo');
await this.syncBridge.add(Tasks.fetchCbridge, null, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InjectQueue, Processor, WorkerHost } from '@nestjs/bullmq';
import { Inject, Logger } from '@nestjs/common';
import { CACHE_KEY, JOB_KEY, Queues, Tasks, TOKEN_REQUEST_LIMIT } from '@/common/constants';
import { CACHE_KEY, JOB_KEY, Queues, Tasks, TIME, TOKEN_REQUEST_LIMIT } from '@/common/constants';
import { Job, Queue } from 'bullmq';
import { ITokenJob } from '@/module/token/token.interface';
import { Web3Service } from '@/shared/web3/web3.service';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class TokenProcessor extends WorkerHost {
return r;
}, {});

await this.cache.set(`${CACHE_KEY.LLAMA_CONFIG}`, config);
await this.cache.set(`${CACHE_KEY.LLAMA_CONFIG}`, config, TIME.MONTH);
return config;
}

Expand All @@ -79,7 +79,7 @@ export class TokenProcessor extends WorkerHost {
return r;
}, {});

await this.cache.set(`${CACHE_KEY.CMC_CONFIG}`, config);
await this.cache.set(`${CACHE_KEY.CMC_CONFIG}`, config, TIME.MONTH);
return config;
}

Expand All @@ -101,7 +101,7 @@ export class TokenProcessor extends WorkerHost {
{} as Record<string, string>,
);

await this.cache.set(`${CACHE_KEY.PLATFORM_MAPPING}`, mapping);
await this.cache.set(`${CACHE_KEY.PLATFORM_MAPPING}`, mapping, TIME.MONTH);
this.tokenService.syncCoingeckoTokens(coins, platforms);
}

Expand Down
65 changes: 42 additions & 23 deletions apps/canonical-bridge-server/src/shared/web3/web3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,49 @@ export class Web3Service {
}

async getTransferConfigsForAll() {
const { data } = await this.httpService.axiosRef.get<ITransferConfigsForAll>(
`${CBRIDGE_ENDPOINT}/v2/getTransferConfigsForAll`,
);

return data;
try {
const { data } = await this.httpService.axiosRef.get<ITransferConfigsForAll>(
`${CBRIDGE_ENDPOINT}/v2/getTransferConfigsForAll`,
);
return data;
} catch (e) {
console.error(`Failed to retrieve cBridge data at ${new Date().getTime()}`, e.message);
}
}

async getDebridgeChains() {
const { data } = await this.httpService.axiosRef.get<{ chains: IDebridgeChain[] }>(
`${DEBRIDGE_ENDPOINT}/supported-chains-info`,
);
try {
const { data } = await this.httpService.axiosRef.get<{ chains: IDebridgeChain[] }>(
`${DEBRIDGE_ENDPOINT}/supported-chains-info`,
);

return data;
return data;
} catch (e) {
console.error(`Failed to retrieve DeBridge chain data at ${new Date().getTime()}`, e.message);
}
}

async getDebridgeChainTokens(chainId: number) {
const { data } = await this.httpService.axiosRef.get<{
tokens: Record<string, IDebridgeToken>;
}>(`${DEBRIDGE_ENDPOINT}/token-list?chainId=${chainId}`);
try {
const { data } = await this.httpService.axiosRef.get<{
tokens: Record<string, IDebridgeToken>;
}>(`${DEBRIDGE_ENDPOINT}/token-list?chainId=${chainId}`);

return data;
return data;
} catch (e) {
console.error(
`Failed to retrieve DeBridge token data from ${chainId} at ${new Date().getTime()}`,
e.message,
);
}
}

async getStargateConfigs() {
const { data } = await this.httpService.axiosRef.get<IStargateTokenList>(
`${STARGATE_ENDPOINT}`,
);
const processedTokenList = [];
try {
const { data } = await this.httpService.axiosRef.get<IStargateTokenList>(
`${STARGATE_ENDPOINT}`,
);
const processedTokenList = [];
const v2List = data.v2;
v2List.forEach((token) => {
const chainInfo = STARGATE_CHAIN_INFO.filter(
Expand All @@ -98,17 +112,22 @@ export class Web3Service {
processedTokenList.push({ ...token, endpointID: chainInfo[0].endpointID });
}
});
return processedTokenList;
} catch (e) {
console.log(`Failed to retrieve Stargate API data at ${new Date().getTime()}`, e);
console.error(`Failed to retrieve Stargate API data at ${new Date().getTime()}`, e.message);
}
return processedTokenList;
}

async getMesonConfigs() {
const { data } = await this.httpService.axiosRef.get<{ result: IMesonChain[] }>(
`${MESON_ENDPOINT}/limits`,
);
return data;
try {
const { data } = await this.httpService.axiosRef.get<{ result: IMesonChain[] }>(
`${MESON_ENDPOINT}/limits`,
);
return data;
} catch (e) {
console.log(`Failed to retrieve Meson API data at ${new Date().getTime()}`, e);
return [];
}
}

async getAssetPlatforms() {
Expand Down
15 changes: 15 additions & 0 deletions apps/canonical-bridge-ui/core/components/VConsole/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useMemo } from 'react';

export function VConsole() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be dev env only?

useMemo(async () => {
if (typeof window !== 'undefined') {
try {
new (await import('vconsole')).default();
} catch (err) {
// eslint-disable-next-line no-console
console.log(`Init vconsole error!`, err);
}
}
}, []);
return null;
}
6 changes: 3 additions & 3 deletions apps/canonical-bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
"@solana/web3.js": "~1.95.4",
"@tanstack/react-query": "~5.50.1",
"@tronweb3/tronwallet-adapter-react-hooks": "~1.1.9",
"axios": "~1.6.8",
"next": "~14.1.1",
"axios": "~1.7.4",
"next": "~14.2.21",
"pino-pretty": "~11.2.1",
"polished": "~4.3.1",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"supports-color": "~9.4.0",
"tronweb": "~6.0.0",
"vconsole": "~3.15.1",
"viem": "~2.21.14",
"wagmi": "^2"
},
Expand All @@ -51,7 +52,6 @@
"eslint-config-next": "14.2.3",
"lint-staged": "~13.0.3",
"prettier": "~2.7.1",
"supports-color": "8.1.1",
"typescript": "5.5.4"
},
"lint-staged": {
Expand Down
2 changes: 2 additions & 0 deletions apps/canonical-bridge-ui/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppProps } from 'next/app';

import { ThemeProvider } from '@/core/components/ThemeProvider';
import { SvgDefs } from '@/core/components/icons/SvgDefs';
import { VConsole } from '@/core/components/VConsole';

const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -19,6 +20,7 @@ const queryClient = new QueryClient({
export default function App({ Component, ...restProps }: AppProps) {
return (
<>
<VConsole />
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
</Head>
Expand Down
10 changes: 0 additions & 10 deletions apps/canonical-bridge-ui/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ export default class Document extends NextDocument {
<Html lang="en">
<Head>
<link rel="stylesheet" href={`${env.ASSET_PREFIX}/fonts/index.css`} />
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js" defer></script>
<script
dangerouslySetInnerHTML={{
__html: `
window.onload = () => {
new window.VConsole();
}
`,
}}
/>
<style
dangerouslySetInnerHTML={{
__html: `
Expand Down
Loading
Loading