Skip to content

Commit

Permalink
Merge branch 'server/stargateAPI' into feat/tokenApi1216
Browse files Browse the repository at this point in the history
  • Loading branch information
Halibao-Lala committed Dec 23, 2024
2 parents 1744cd7 + fe8b484 commit bcd6263
Show file tree
Hide file tree
Showing 46 changed files with 996 additions and 453 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ on:

paths:
- apps/canonical-bridge-server/**

permissions:
contents: read
- .github/**

jobs:
cicd:
Expand Down
132 changes: 132 additions & 0 deletions apps/canonical-bridge-server/src/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,135 @@ export const JOB_KEY = {
CORN_TOKEN_PREFIX: 'corn:token:',
CORN_PRICE_PREFIX: 'corn:price:',
};

export const STARGATE_CHAIN_INFO = [
{
chainId: 1,
chainName: 'Ethereum',
endpointID: 30101,
},
{
chainId: 10,
chainName: 'Optimism',
endpointID: 30110,
},
{
chainId: 14,
chainName: 'Flare',
endpointID: 30295,
},
{
chainId: 56,
chainName: 'BSC',
endpointID: 30102,
},
{
chainId: 97,
chainName: 'BSC Testnet',
network: 'testnet',
endpointID: 40102,
},
{
chainId: 137,
chainName: 'Polygon',
endpointID: 30109,
},
{
chainId: 1088,
chainName: 'Metis',
endpointID: 30151,
},
{
chainId: 1116,
chainName: 'coredao',
endpointID: 30153,
},
{
chainId: 1329,
chainName: 'Sei',
endpointID: 30280,
},
{
chainId: 1625,
chainName: 'Gravity',
endpointID: 30294,
},
{
chainId: 2222,
chainName: 'Kava',
endpointID: 30177,
},
{
chainId: 5000,
chainName: 'Mantle',
endpointID: 30181,
},
{
chainId: 8217,
chainName: 'Klaytn',
endpointID: 30150,
},
{
chainId: 8453,
chainName: 'Base',
endpointID: 30184,
},
{
chainId: 8822,
chainName: 'IOTA',
endpointID: 30284,
},
{
chainId: 42161,
chainName: 'Arbitrum',
endpointID: 30110,
},
{
chainId: 43114,
chainName: 'Avalanche',
endpointID: 30106,
},
{
chainId: 59144,
chainName: 'Linea',
endpointID: 30183,
},
{
chainId: 167000,
chainName: 'Taiko',
endpointID: 30290,
},
{
chainId: 421614,
chainName: 'Arbitrum Sepolia',
network: 'testnet',
endpointID: 40231,
},
{
chainId: 11155420,
chainName: 'OP Sepolia Testnet',
network: 'testnet',
endpointID: 40232,
},
{
chainId: 534352,
chainName: 'Scroll',
endpointID: 30214,
},
{
chainId: 11155111,
chainName: 'Sepolia',
network: 'testnet',
endpointID: 40161,
},
{
chainId: 1313161554,
chainName: 'Aurora',
endpointID: 30211,
},
{
chainId: 1380012617,
chainName: 'rarible',
endpointID: 30235,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ export interface IStargateBridgeTokenInfo {
decimals: number;
symbol: string;
};
lpToken: {
lpToken?: {
address: `0x${string}`;
decimals: number;
symbol: string;
};
farm: {
farm?: {
stargateStaking: {
address: `0x${string}`;
rewardTokens: [
Expand Down
17 changes: 16 additions & 1 deletion apps/canonical-bridge-server/src/shared/web3/web3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MESON_ENDPOINT,
LLAMA_COINS_ENDPOINT,
TOKEN_REQUEST_LIMIT,
STARGATE_CHAIN_INFO,
} from '@/common/constants';
import { values } from 'lodash';

Expand Down Expand Up @@ -86,7 +87,21 @@ export class Web3Service {
const { data } = await this.httpService.axiosRef.get<IStargateTokenList>(
`${STARGATE_ENDPOINT}`,
);
return data;
const processedTokenList = [];
try {
const v2List = data.v2;
v2List.forEach((token) => {
const chainInfo = STARGATE_CHAIN_INFO.filter(
(chain) => chain.chainName.toUpperCase() === token.chainKey.toUpperCase(),
);
if (chainInfo && chainInfo.length > 0) {
processedTokenList.push({ ...token, endpointID: chainInfo[0].endpointID });
}
});
} catch (e) {
console.log(`Failed to retrieve Stargate API data at ${new Date().getTime()}`, e);
}
return processedTokenList;
}

async getMesonConfigs() {
Expand Down
7 changes: 4 additions & 3 deletions apps/canonical-bridge-ui/core/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export function Layout({ children }: React.PropsWithChildren) {
<Header />
<Flex
as="main"
flexDir="column"
flex={1}
w={['100%', '100%', '100%', 'auto']}
p={['24px 20px', '24px 20px', '40px']}
alignItems="center"
w={['100%']}
mb={['120px', '120px', '160px']}
alignItems={'flex-start'}
justifyContent={'center'}
>
{children}
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion apps/canonical-bridge-ui/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
30 changes: 27 additions & 3 deletions apps/canonical-bridge-ui/pages/mainnet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
CanonicalBridgeProvider,
ICanonicalBridgeConfig,
TransferWidget,
BridgeTransfer,
BridgeRoutes,
} from '@bnb-chain/canonical-bridge-widget';
import { useMemo } from 'react';
import { useAccount } from 'wagmi';

import { useTransferConfig } from '@/token-config/mainnet/useTransferConfig';
import { chains } from '@/token-config/mainnet/chains';
Expand All @@ -13,6 +16,13 @@ import { useWalletModal } from '@/core/wallet/hooks/useWalletModal';
import { WalletProvider } from '@/core/wallet/WalletProvider';
import { Layout } from '@/core/components/Layout';

const unsupportedChainsInWallets = [
{
wallets: ['BinanceW3WSDK', 'binanceWeb3Wallet'],
chains: [1101],
},
];

export const bridgeConfig: ICanonicalBridgeConfig = {
appName: env.APP_NAME,
assetPrefix: env.ASSET_PREFIX,
Expand Down Expand Up @@ -43,15 +53,29 @@ function BridgeWidget() {
const transferConfig = useTransferConfig();
const { onOpen } = useWalletModal();

const { connector } = useAccount();
const supportedChains = useMemo(() => {
return chains.filter((e) => {
if (connector) {
const unsupportedChains = unsupportedChainsInWallets.find((e) =>
e.wallets.includes(connector.id),
)?.chains;
return !unsupportedChains?.includes(e.id);
}
return true;
});
}, [connector]);

return (
<CanonicalBridgeProvider
config={bridgeConfig}
transferConfig={transferConfig}
chains={chains}
chains={supportedChains}
onClickConnectWalletButton={onOpen}
>
<Layout>
<TransferWidget />
<BridgeTransfer />
<BridgeRoutes />
</Layout>
</CanonicalBridgeProvider>
);
Expand Down
6 changes: 4 additions & 2 deletions apps/canonical-bridge-ui/pages/testnet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
CanonicalBridgeProvider,
ICanonicalBridgeConfig,
TransferWidget,
BridgeTransfer,
BridgeRoutes,
} from '@bnb-chain/canonical-bridge-widget';

import { useTestnetTransferConfig } from '@/token-config/testnet/useTestnetTransferConfig';
Expand Down Expand Up @@ -52,7 +53,8 @@ function BridgeWidget() {
onClickConnectWalletButton={onOpen}
>
<Layout>
<TransferWidget />
<BridgeTransfer />
<BridgeRoutes />
</Layout>
</CanonicalBridgeProvider>
);
Expand Down
Binary file modified apps/canonical-bridge-ui/public/images/tokens/CAKE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export function useTransferConfig() {
'0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4': 'USDC',
'0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4': 'USDC.e',
},
1101: {
'0x37eAA0eF3549a5Bb7D431be78a3D99BD360d19e5': 'USDC.e',
},
42161: {
'0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8': 'USDC.e',
},
Expand Down Expand Up @@ -131,11 +134,15 @@ export function useTransferConfig() {
56: [
'0x67d66e8ec1fd25d98b3ccd3b19b7dc4b4b7fc493',
'0x0000000000000000000000000000000000000000',
'0x9c7beba8f6ef6643abd725e45a4e8387ef260649',
],
137: ['cUSDCv3'],
42161: ['cUSDCv3'],
43114: ['BNB'],
7565164: ['So11111111111111111111111111111111111111112'],
7565164: [
'So11111111111111111111111111111111111111112',
'FmqVMWXBESyu4g6FT1uz1GABKdJ4j6wbuuLFwPJtqpmu',
],
},
},
bridgedTokenGroups: [
Expand Down
6 changes: 6 additions & 0 deletions packages/canonical-bridge-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @bnb-chain/canonical-bridge-sdk

## 0.4.5

### Patch Changes

- 0c42d50: Fix layerzero min amount decimal issue

## 0.4.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/canonical-bridge-sdk",
"version": "0.4.4",
"version": "0.4.5",
"description": "canonical bridge sdk",
"author": "bnb-chain",
"private": false,
Expand Down
7 changes: 6 additions & 1 deletion packages/canonical-bridge-sdk/src/core/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ export function removeAfterDecimals(num: string | number, decimals = 8) {
return result;
}

export const formatNumber = (value: number, decimals = 18) => {
export const formatNumber = (
value: number,
decimals = 18,
useGrouping = true
) => {
const num = removeAfterDecimals(value, decimals);
return num.toLocaleString('fullwide', {
maximumFractionDigits: decimals,
useGrouping,
});
};

Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-sdk/src/layerZero/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class LayerZero {
];
const nativeFee = fees[0];
const minAmount = parseUnits(
String(formatNumber(Number(formatUnits(amount, 18)), 8)),
String(formatNumber(Number(formatUnits(amount, 18)), 8, false)),
18
);
const cakeArgs = {
Expand Down
Loading

0 comments on commit bcd6263

Please sign in to comment.