Skip to content

Commit c8a9fb7

Browse files
authored
Merge pull request #3 from zkLinkProtocol/feat/bnb
fix tx gas issue
2 parents d6d951f + df6e7cf commit c8a9fb7

File tree

4 files changed

+100
-102
lines changed

4 files changed

+100
-102
lines changed

.env

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
1-
# Important: Inline comments are currently not supported in this env file
2-
3-
# ETHEREUM
4-
VITE_ETHEREUM_RPC_URL=http://43.207.234.164:8545
5-
VITE_ETHEREUM_EXPLORER_URL=https://goerli.etherscan.io
6-
VITE_ETHEREUM_BRIDGE_CONTRACT_ADDRESS=0x12494fE98D3f67EB0c9e2512a4cd18e703aDe49d
7-
VITE_ETHEREUM_BRIDGE_CONTRACT_ADDRESS=0x12494fE98D3f67EB0c9e2512a4cd18e703aDe49d
1+
VITE_ETHEREUM_RPC_URL=https://bsc-testnet.blockpi.network/v1/rpc/3eb6e39baca81574a0a35e746a984c4e6ae11fa8
2+
VITE_ETHEREUM_EXPLORER_URL=https://testnet.bscscan.com
3+
VITE_ETHEREUM_BRIDGE_CONTRACT_ADDRESS=0x15Fa1aBF66bD706eFdC837105068192586f8744e
84
VITE_ETHEREUM_FORCE_UPDATE_GLOBAL_EXIT_ROOT=true
9-
VITE_ETHEREUM_PROOF_OF_EFFICIENCY_CONTRACT_ADDRESS=0x28eb6e90A1d4C8ba008d89d13482EdeFFf595461
10-
VITE_ETHEREUM_ROLLUP_MANAGER_ADDRESS=0x35b75f623311c87863Dd34a1fFE9A62a69fd4F87
11-
5+
VITE_ETHEREUM_PROOF_OF_EFFICIENCY_CONTRACT_ADDRESS=0x0b44DDf3B879b6a5973E823531dC45De8ca6E1Aa
6+
VITE_ETHEREUM_ROLLUP_MANAGER_ADDRESS=0x7cB48adCFa630876659b9e2A7b83795a804D3960
127

138
# POLYGON ZK EVM
149
VITE_POLYGON_ZK_EVM_RPC_URL=http://43.207.234.164:51710
15-
VITE_POLYGON_ZK_EVM_EXPLORER_URL=http://localhost:3000
16-
VITE_POLYGON_ZK_EVM_BRIDGE_CONTRACT_ADDRESS=0x12494fE98D3f67EB0c9e2512a4cd18e703aDe49d
17-
VITE_POLYGON_ZK_EVM_NETWORK_ID=1
18-
10+
VITE_POLYGON_ZK_EVM_EXPLORER_URL=http://43.207.234.164:3000/
11+
VITE_POLYGON_ZK_EVM_BRIDGE_CONTRACT_ADDRESS=0x15Fa1aBF66bD706eFdC837105068192586f8744e
12+
VITE_POLYGON_ZK_EVM_NETWORK_ID=810188
1913

2014
# BRIDGE API
2115
VITE_BRIDGE_API_URL=http://43.207.234.164:51200
2216

2317
# FIAT EXCHANGE RATES API
2418
VITE_ENABLE_FIAT_EXCHANGE_RATES=false
25-
VITE_FIAT_EXCHANGE_RATES_API_URL=https://api.exchangeratesapi.io/v1/latest
26-
VITE_FIAT_EXCHANGE_RATES_API_KEY=
27-
VITE_FIAT_EXCHANGE_RATES_ETHEREUM_USDC_ADDRESS=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
2819

2920
# OUTDATED NETWORK MODAL
30-
VITE_ENABLE_OUTDATED_NETWORK_MODAL=true
31-
VITE_OUTDATED_NETWORK_MODAL_TITLE=Welcome to the new Polygon zkEVM testnet!
32-
VITE_OUTDATED_NETWORK_MODAL_MESSAGE_PARAGRAPH_1=To connect, follow the instructions available at this site.
33-
VITE_OUTDATED_NETWORK_MODAL_MESSAGE_PARAGRAPH_2=The previous network is still available until January 5th. You can access using the information available at:
34-
VITE_OUTDATED_NETWORK_MODAL_URL=https://deprecated.zkevm-test.net
21+
VITE_ENABLE_OUTDATED_NETWORK_MODAL=false
3522

36-
# DEPOSIT WARNING
23+
# DEPOSIT WARNING
3724
VITE_ENABLE_DEPOSIT_WARNING=false
3825

3926
# REPORT FORM
4027
VITE_ENABLE_REPORT_FORM=false
41-
VITE_REPORT_FORM_URL=https://docs.google.com/forms/d/xxxxxx/viewform
42-
VITE_REPORT_FORM_ERROR_ENTRY=entry.xxxxxx
43-
VITE_REPORT_FORM_PLATFORM_ENTRY=entry.xxxxxx
44-
VITE_REPORT_FORM_URL_ENTRY=entry.xxxxxx
28+
29+
# Resolve relative urls
30+
VITE_RESOLVE_RELATIVE_URLS=true

src/contexts/bridge.context.tsx

Lines changed: 80 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ type FetchBridgesParams = {
7373
env: Env;
7474
ethereumAddress: string;
7575
} & (
76-
| {
76+
| {
7777
limit: number;
7878
offset: number;
7979
type: "load";
8080
}
81-
| {
81+
| {
8282
quantity: number;
8383
type: "reload";
8484
}
85-
);
85+
);
8686

8787
interface BridgeParams {
8888
amount: BigNumber;
@@ -191,14 +191,14 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
191191
claim_tx_hash !== null
192192
? { status: "claimed", txHash: claim_tx_hash }
193193
: ready_for_claim
194-
? { status: "ready" }
195-
: { status: "pending" };
194+
? { status: "ready" }
195+
: { status: "pending" };
196196

197197
const tokenPrice: BigNumber | undefined = env.fiatExchangeRates.areEnabled
198198
? await getTokenPrice({
199-
chain: from,
200-
token,
201-
}).catch(() => undefined)
199+
chain: from,
200+
token,
201+
}).catch(() => undefined)
202202
: undefined;
203203

204204
const fiatAmount =
@@ -319,12 +319,16 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
319319

320320
const from = env.chains.find((chain) => chain.networkId === network_id);
321321
if (from === undefined) {
322-
return acc.then((accDeposits) => {return accDeposits})
322+
return acc.then((accDeposits) => {
323+
return accDeposits;
324+
});
323325
}
324326

325327
const to = env.chains.find((chain) => chain.networkId === dest_net);
326328
if (to === undefined) {
327-
return acc.then((accDeposits) => {return accDeposits})
329+
return acc.then((accDeposits) => {
330+
return accDeposits;
331+
});
328332
}
329333

330334
return acc.then((accDeposits) =>
@@ -342,8 +346,8 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
342346
claim_tx_hash !== null
343347
? { status: "claimed", txHash: claim_tx_hash }
344348
: ready_for_claim
345-
? { status: "ready" }
346-
: { status: "pending" },
349+
? { status: "ready" }
350+
: { status: "pending" },
347351
depositCount: deposit_cnt,
348352
depositTxHash: tx_hash,
349353
destinationAddress: dest_addr,
@@ -364,26 +368,26 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
364368

365369
const tokenPrices: TokenPrices = env.fiatExchangeRates.areEnabled
366370
? await deposits.reduce(
367-
async (
368-
accTokenPrices: Promise<TokenPrices>,
369-
deposit: Deposit
370-
): Promise<TokenPrices> => {
371-
const tokenPrices = await accTokenPrices;
372-
const tokenCachedPrice = tokenPrices[deposit.token.address];
373-
const tokenPrice =
374-
tokenCachedPrice !== undefined
375-
? tokenCachedPrice
376-
: await getTokenPrice({ chain: deposit.from, token: deposit.token }).catch(
377-
() => null
378-
);
379-
380-
return {
381-
...tokenPrices,
382-
[deposit.token.address]: tokenPrice,
383-
};
384-
},
385-
Promise.resolve({})
386-
)
371+
async (
372+
accTokenPrices: Promise<TokenPrices>,
373+
deposit: Deposit
374+
): Promise<TokenPrices> => {
375+
const tokenPrices = await accTokenPrices;
376+
const tokenCachedPrice = tokenPrices[deposit.token.address];
377+
const tokenPrice =
378+
tokenCachedPrice !== undefined
379+
? tokenCachedPrice
380+
: await getTokenPrice({ chain: deposit.from, token: deposit.token }).catch(
381+
() => null
382+
);
383+
384+
return {
385+
...tokenPrices,
386+
[deposit.token.address]: tokenPrice,
387+
};
388+
},
389+
Promise.resolve({})
390+
)
387391
: {};
388392

389393
const bridges = deposits.map((partialDeposit): Bridge => {
@@ -406,16 +410,16 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
406410
const fiatAmount =
407411
tokenPrice !== undefined && tokenPrice !== null
408412
? multiplyAmounts(
409-
{
410-
precision: FIAT_DISPLAY_PRECISION,
411-
value: tokenPrice,
412-
},
413-
{
414-
precision: token.decimals,
415-
value: amount,
416-
},
417-
FIAT_DISPLAY_PRECISION
418-
)
413+
{
414+
precision: FIAT_DISPLAY_PRECISION,
415+
value: tokenPrice,
416+
},
417+
{
418+
precision: token.decimals,
419+
value: amount,
420+
},
421+
FIAT_DISPLAY_PRECISION
422+
)
419423
: undefined;
420424

421425
const id = serializeBridgeId({
@@ -701,30 +705,29 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
701705
const gasLimit =
702706
from.key === "ethereum"
703707
? await contract.estimateGas
704-
.bridgeAsset(
705-
to.networkId,
706-
destinationAddress,
707-
amount,
708-
tokenAddress,
709-
forceUpdateGlobalExitRoot,
710-
"0x",
711-
overrides
712-
)
713-
.then((gasLimit) => {
714-
const gasLimitIncrease = gasLimit
715-
.div(BigNumber.from(100))
716-
.mul(BRIDGE_CALL_GAS_LIMIT_INCREASE_PERCENTAGE);
717-
718-
const increasedGasLimit = gasLimit.add(gasLimitIncrease);
719-
720-
return tokenSpendPermission.type === "permit"
721-
? increasedGasLimit.add(BRIDGE_CALL_PERMIT_GAS_LIMIT_INCREASE)
722-
: increasedGasLimit;
723-
})
708+
.bridgeAsset(
709+
to.networkId,
710+
destinationAddress,
711+
amount,
712+
tokenAddress,
713+
forceUpdateGlobalExitRoot,
714+
"0x",
715+
overrides
716+
)
717+
.then((gasLimit) => {
718+
const gasLimitIncrease = gasLimit
719+
.div(BigNumber.from(100))
720+
.mul(BRIDGE_CALL_GAS_LIMIT_INCREASE_PERCENTAGE);
721+
722+
const increasedGasLimit = gasLimit.add(gasLimitIncrease);
723+
724+
return tokenSpendPermission.type === "permit"
725+
? increasedGasLimit.add(BRIDGE_CALL_PERMIT_GAS_LIMIT_INCREASE)
726+
: increasedGasLimit;
727+
})
724728
: BigNumber.from(300000);
725729

726730
const { gasPrice, maxFeePerGas } = await from.provider.getFeeData();
727-
728731
if (maxFeePerGas) {
729732
return { data: { gasLimit, maxFeePerGas }, type: "eip-1559" };
730733
} else {
@@ -770,21 +773,21 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
770773
...(gas
771774
? gas.data
772775
: (await estimateBridgeGas({ destinationAddress, from, to, token, tokenSpendPermission }))
773-
.data),
776+
.data),
774777
};
775-
778+
overrides.maxFeePerGas = Number(overrides.maxFeePerGas?.toString()) * 2;
776779
const executeBridge = async () => {
777780
const permitData =
778781
tokenSpendPermission.type === "permit"
779782
? await permit({
780-
account: account,
781-
from: from,
782-
permit: tokenSpendPermission.permit,
783-
provider: provider,
784-
spender: from.bridgeContractAddress,
785-
token,
786-
value: amount,
787-
})
783+
account: account,
784+
from: from,
785+
permit: tokenSpendPermission.permit,
786+
provider: provider,
787+
spender: from.bridgeContractAddress,
788+
token,
789+
value: amount,
790+
})
788791
: "0x";
789792

790793
const forceUpdateGlobalExitRoot =
@@ -813,6 +816,10 @@ const BridgeProvider: FC<PropsWithChildren> = (props) => {
813816
});
814817

815818
return txData;
819+
})
820+
.catch((err) => {
821+
console.log("xxxxxxxxxxxxx: ", err);
822+
throw err;
816823
});
817824
};
818825

src/views/bridge-confirmation/bridge-confirmation.styles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export const useBridgeConfirmationStyles = createUseStyles((theme: Theme) => ({
5050
textOverflow: "ellipsis",
5151
whiteSpace: "nowrap",
5252
},
53+
chainIcon: {
54+
width: 20,
55+
height: 20,
56+
},
5357
chainsRow: {
5458
alignItems: "center",
5559
borderBottom: `1px solid ${theme.palette.grey.light}`,

src/views/bridge-confirmation/bridge-confirmation.view.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ export const BridgeConfirmation: FC = () => {
346346
setFormData(undefined);
347347
})
348348
.catch((error) => {
349+
console.log("xxxxxxxxxxxxx: ", error);
349350
callIfMounted(() => {
350351
setIsBridgeInProgress(false);
351352
if (isMetaMaskUserRejectedRequestError(error) === false) {
@@ -443,14 +444,14 @@ export const BridgeConfirmation: FC = () => {
443444
)}
444445
<div className={classes.chainsRow}>
445446
<div className={classes.chainBox}>
446-
<from.Icon />
447+
<from.Icon className={classes.chainIcon} />
447448
<Typography className={classes.chainName} type="body1">
448449
{from.name}
449450
</Typography>
450451
</div>
451452
<ArrowRightIcon className={classes.arrowIcon} />
452453
<div className={classes.chainBox}>
453-
<to.Icon />
454+
<to.Icon className={classes.chainIcon} />
454455
<Typography className={classes.chainName} type="body1">
455456
{to.name}
456457
</Typography>

0 commit comments

Comments
 (0)