Skip to content

Commit

Permalink
Merge pull request #206 from bnb-chain/hotfix/cakeDecimal
Browse files Browse the repository at this point in the history
hotfix: Fix layerzero decimal issue
  • Loading branch information
Halibao-Lala authored Dec 20, 2024
2 parents 2a3b51b + 745c29c commit 9f68f64
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 94 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
5 changes: 0 additions & 5 deletions .release/.changeset/cold-baboons-serve.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/happy-insects-give.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/hip-news-reflect.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/honest-adults-mate.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/large-jeans-jam.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/lazy-vans-applaud.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/long-rivers-type.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/metal-scissors-repeat.md

This file was deleted.

22 changes: 0 additions & 22 deletions .release/.changeset/pre.json

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/quiet-hotels-accept.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/silent-keys-fold.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/small-mangos-lay.md

This file was deleted.

5 changes: 0 additions & 5 deletions .release/.changeset/tough-carrots-report.md

This file was deleted.

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.
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
31 changes: 31 additions & 0 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# @bnb-chain/canonical-bridge-widget

## 0.5.14

### Patch Changes

- c245228: Add attribute `data-address` to all routes
- 0a61381: Use rpc in chainsConfig to get balance
- 2849332: Add more customizable configs
- 513791e: Keep the previous selected route after routes refreshing
- f9c82ec: Fixed an issue caused by sdk not building
- 0cf34de: Support custom toast for errors
- 513791e: Split `TransferWidget` into `BridgeTransfer` and `BridgeRoutes`
- 513791e: AlertIcon supports customize color
- 3f69a66: Add blocked rules to celer bridge
- fc7cd1c: Add to token address to route
- 0cf34de: Support custom toast for errors
- 0cf34de: Support custom toast for errors
- 513791e: Remove bridge bottom element if `routeContentBottom` not setted
- 99b14df: Support specific wallets to exclude unsupported chains

## 0.5.14-alpha.5

### Patch Changes

- Use rpc in chainsConfig to get balance

## 0.5.14-alpha.4

### Patch Changes

- Add blocked rules to celer bridge

## 0.5.14-alpha.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/canonical-bridge-widget",
"version": "0.5.14-alpha.3",
"version": "0.5.14",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
3 changes: 2 additions & 1 deletion packages/canonical-bridge-widget/src/core/utils/number.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ export class CBridgeAdapter extends BaseAdapter<
this.symbolMap = symbolMap;
}

private checkIsBlocked({
fromChainId,
toChainId,
tokenSymbol,
}: {
fromChainId: number;
toChainId: number;
tokenSymbol: string;
}) {
const blockedList = this.config.blocked_bridge_direct ?? [];
const isBlocked = blockedList.find((e) => {
return (
Number(e.src_chain_id) === fromChainId &&
Number(e.dst_chain_id) === toChainId &&
e.symbol.toUpperCase() === tokenSymbol.toUpperCase()
);
});
return isBlocked;
}

protected initTransferMap() {
const transferMap = new Map<
number,
Expand All @@ -104,10 +124,20 @@ export class CBridgeAdapter extends BaseAdapter<

const transferableTokenMap = new Map<string, ITransferTokenPair<ICBridgeToken>>();
fromTokens.forEach((fromToken) => {
const fromTokenSymbol = fromToken.token.symbol?.toUpperCase();
const isBlocked = this.checkIsBlocked({
fromChainId: fromChain.id,
toChainId: toChain.id,
tokenSymbol: fromTokenSymbol,
});
if (isBlocked) {
return;
}

const toToken = this.getToToken({
fromChainId: fromChain.id,
toChainId: toChain.id,
fromTokenSymbol: fromToken.token.symbol?.toUpperCase(),
fromTokenSymbol,
});
if (toToken) {
const tokenPair: ITransferTokenPair<ICBridgeToken> = {
Expand All @@ -118,7 +148,7 @@ export class CBridgeAdapter extends BaseAdapter<
fromToken,
toToken,
};
transferableTokenMap.set(fromToken.token.symbol?.toUpperCase(), tokenPair);
transferableTokenMap.set(fromTokenSymbol, tokenPair);
}
});

Expand All @@ -142,6 +172,15 @@ export class CBridgeAdapter extends BaseAdapter<
toToken: ICBridgeToken,
item: ICBridgePeggedPairConfig,
) => {
const isBlocked = this.checkIsBlocked({
fromChainId,
toChainId,
tokenSymbol: fromToken.token.symbol,
});
if (isBlocked) {
return;
}

if (
!transferMap.get(fromChainId)?.get(toChainId)?.get(fromToken.token.symbol?.toUpperCase())
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const useGetLayerZeroFees = () => {
];
const nativeFee = fees[0];
const minAmount = parseUnits(
String(formatNumber(Number(sendValue), 8)),
String(formatNumber(Number(sendValue), 8, false)),
selectedToken?.layerZero?.raw?.decimals ?? (18 as number),
);
const cakeArgs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { setIsLoadingTokenBalances, setTokenBalances } from '@/modules/aggregato
import { useTronWeb } from '@/core/hooks/useTronWeb';
import { useSolanaAccount } from '@/modules/wallet/hooks/useSolanaAccount';
import { useTronAccount } from '@/modules/wallet/hooks/useTronAccount';
import { useAggregator } from '@/modules/aggregator/components/AggregatorProvider';

export function TokenBalancesProvider() {
const { chainConfigs } = useAggregator();
const { address } = useAccount();
const { address: solanaAddress } = useSolanaAccount();
const { address: tronAddress } = useTronAccount();
Expand Down Expand Up @@ -41,6 +43,7 @@ export function TokenBalancesProvider() {
evmParams: {
account: address,
chain: chains?.find((item) => item.id === fromChain?.id),
chainConfig: chainConfigs?.find((item) => item.id === fromChain?.id),
},
solanaParams: {
account: solanaAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function useSelection() {
}

function useSortedTokens() {
const { transferConfig } = useAggregator();
const { transferConfig, chainConfigs } = useAggregator();
const { getTokenPrice } = useTokenPrice();

const { address } = useAccount();
Expand All @@ -243,6 +243,7 @@ function useSortedTokens() {
evmParams: {
account: address,
chain: chains?.find((item) => item.id === fromChainId),
chainConfig: chainConfigs?.find((item) => item.id === fromChainId),
},
solanaParams: {
account: solanaAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Connection, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import axios from 'axios';

import { ChainType, IBridgeToken } from '@/modules/aggregator/types';
import { ChainType, IBridgeToken, IChainConfig } from '@/modules/aggregator/types';
import { ERC20_TOKEN } from '@/core/contract/abi';
import { isChainOrTokenCompatible } from '@/modules/aggregator/shared/isChainOrTokenCompatible';
import { isSameAddress } from '@/core/utils/address';
Expand All @@ -23,6 +23,7 @@ export async function getTokenBalances({
evmParams: {
account?: string;
chain?: Chain;
chainConfig?: IChainConfig;
};
solanaParams: {
account?: string;
Expand Down Expand Up @@ -54,26 +55,30 @@ export async function getTokenBalances({
account: evmParams.account,
chain: evmParams.chain,
tokens: compatibleTokens,
chainConfig: evmParams.chainConfig,
});
}

async function getEvmTokenBalances({
account,
chain,
tokens,
chainConfig,
}: {
account?: string;
chain?: Chain;
tokens?: IBridgeToken[];
chainConfig?: IChainConfig;
}) {
try {
if (!chain || !account || !tokens?.length) {
return {};
}

const rpcUrl = chainConfig?.rpcUrl;
const client = createPublicClient({
chain,
transport: http(),
transport: http(rpcUrl),
});

const contracts = tokens.map((item) => ({
Expand Down

0 comments on commit 9f68f64

Please sign in to comment.