Skip to content

Commit 2491a4f

Browse files
committed
feat: add gateway
1 parent 5eef311 commit 2491a4f

File tree

10 files changed

+149
-17
lines changed

10 files changed

+149
-17
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<CommonAlert variant="warning" size="sm" :icon="ExclamationTriangleIcon" class="mb-block-gap">
4+
<p>
5+
Only {{ eraNetwork.nativeCurrency!.symbol }} is allowed for bridging {{ type === "withdraw" ? "from" : "to" }}
6+
{{ eraNetwork.name }}.
7+
</p>
8+
</CommonAlert>
9+
</div>
10+
</template>
11+
12+
<script lang="ts" setup>
13+
import { ExclamationTriangleIcon } from "@heroicons/vue/24/outline";
14+
15+
import type { ZkSyncNetwork } from "@/data/networks"; // Adjust the import path as needed
16+
17+
defineProps<{
18+
eraNetwork: ZkSyncNetwork;
19+
type: "withdraw" | "deposit";
20+
}>();
21+
</script>

composables/zksync/useFee.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default (
3333
}
3434
const feeTokenBalance = balances.value.find((e) => e.address === feeToken.value!.address);
3535
if (!feeTokenBalance) return true;
36-
if (totalFee.value && BigInt(totalFee.value) > feeTokenBalance.amount) {
36+
if (totalFee.value && BigInt(totalFee.value) > BigInt(feeTokenBalance.amount)) {
3737
return false;
3838
}
3939
return true;

composables/zksync/useWithdrawalFinalization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
3535
return calculateFee(gasLimit.value, gasPrice.value).toString();
3636
});
3737
const feeToken = computed(() => {
38-
return ethToken;
38+
return ethToken.value;
3939
});
4040

4141
const getFinalizationParams = async () => {

data/networks.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export type ZkSyncNetwork = {
5252
onramp?: boolean;
5353
showPartnerLinks?: boolean;
5454
};
55+
nativeCurrency?: { name: string; symbol: string; decimals: number; iconUrl: string; l1Address: string };
56+
nativeBridgingOnly?: boolean;
5557
getTokens?: () => Token[] | Promise<Token[]>; // If blockExplorerApi is specified, tokens will be fetched from there. Otherwise, this function will be used.
5658
};
5759

@@ -105,6 +107,7 @@ const publicChains: ZkSyncNetwork[] = [
105107
blockExplorerUrl: "https://sepolia-era.zksync.network",
106108
blockExplorerApi: "https://block-explorer-api.sepolia.zksync.dev",
107109
displaySettings: {
110+
onramp: false,
108111
showPartnerLinks: true,
109112
},
110113
l1Network: l1Networks.sepolia,
@@ -119,6 +122,74 @@ const publicChains: ZkSyncNetwork[] = [
119122
l1Network: l1Networks.sepolia,
120123
hidden: true,
121124
},
125+
{
126+
id: 9075,
127+
key: "gateway",
128+
name: "ZKsync Gateway Mainnet",
129+
rpcUrl: "https://rpc.era-gateway-mainnet.zksync.dev",
130+
blockExplorerUrl: "https://explorer.era-gateway-mainnet.zksync.dev",
131+
blockExplorerApi: "https://block-explorer-api.era-gateway-mainnet.zksync.dev",
132+
l1Network: l1Networks.mainnet,
133+
displaySettings: {
134+
onramp: false,
135+
showPartnerLinks: false,
136+
},
137+
nativeCurrency: {
138+
name: "ZKsync",
139+
symbol: "ZK",
140+
decimals: 18,
141+
iconUrl: "img/era.svg",
142+
l1Address: "0x66A5cFB2e9c529f14FE6364Ad1075dF3a649C0A5",
143+
},
144+
nativeBridgingOnly: true,
145+
getTokens: () => {
146+
return [
147+
{
148+
address: L2_BASE_TOKEN_ADDRESS,
149+
l1Address: "0x2569600E58850a0AaD61F7Dd2569516C3d909521",
150+
name: "ZKsync",
151+
symbol: "ZK",
152+
decimals: 18,
153+
iconUrl: "/img/era.svg",
154+
isETH: false,
155+
},
156+
];
157+
},
158+
},
159+
{
160+
id: 32657,
161+
key: "gateway-testnet",
162+
name: "ZKsync Gateway Testnet",
163+
rpcUrl: "https://rpc.era-gateway-testnet.zksync.dev",
164+
blockExplorerUrl: "https://explorer.era-gateway-testnet.zksync.dev",
165+
blockExplorerApi: "https://block-explorer.era-gateway-testnet.zksync.dev",
166+
l1Network: l1Networks.sepolia,
167+
displaySettings: {
168+
onramp: false,
169+
showPartnerLinks: false,
170+
},
171+
nativeCurrency: {
172+
name: "ZKsync",
173+
symbol: "ZK",
174+
decimals: 18,
175+
iconUrl: "img/era.svg",
176+
l1Address: "0x2569600E58850a0AaD61F7Dd2569516C3d909521",
177+
},
178+
nativeBridgingOnly: true,
179+
getTokens: () => {
180+
return [
181+
{
182+
address: L2_BASE_TOKEN_ADDRESS,
183+
l1Address: "0x2569600E58850a0AaD61F7Dd2569516C3d909521",
184+
name: "ZKsync",
185+
symbol: "ZK",
186+
decimals: 18,
187+
iconUrl: "/img/era.svg",
188+
isETH: false,
189+
},
190+
];
191+
},
192+
},
122193
];
123194

124195
const getHyperchains = (): ZkSyncNetwork[] => {

data/wagmi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const formatZkSyncChain = (network: ZkSyncNetwork) => {
2626
id: network.id,
2727
name: network.name,
2828
network: network.key,
29-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
29+
nativeCurrency: network.nativeCurrency ?? { name: "Ether", symbol: "ETH", decimals: 18 },
3030
rpcUrls: {
3131
default: { http: [network.rpcUrl] },
3232
public: { http: [network.rpcUrl] },

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"vue-tippy": "^6.0.0",
9292
"web3-avatar-vue": "^1.0.0",
9393
"zksync-easy-onramp": "3.2.1",
94-
"zksync-ethers": "^6.17.0"
94+
"zksync-ethers": "^6.18.0"
9595
},
9696
"overrides": {
9797
"vue": "latest"

store/zksync/tokens.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export const useZkSyncTokensStore = defineStore("zkSyncTokens", () => {
4747

4848
if (!baseToken) {
4949
baseToken = {
50-
address: "0x000000000000000000000000000000000000800A",
50+
address: L2_BASE_TOKEN_ADDRESS,
5151
l1Address: await provider.getBaseTokenContractAddress(),
52-
symbol: "BASETOKEN",
53-
name: "Base Token",
54-
decimals: 18,
55-
iconUrl: "/img/eth.svg",
52+
symbol: eraNetwork.value.nativeCurrency!.symbol ?? "BASETOKEN",
53+
name: eraNetwork.value.nativeCurrency!.name ?? "Base Token",
54+
decimals: eraNetwork.value.nativeCurrency!.decimals ?? 18,
55+
iconUrl: eraNetwork.value.nativeCurrency!.iconUrl ?? "/img/eth.svg",
5656
};
5757
}
5858
if (!ethToken) {
@@ -72,7 +72,7 @@ export const useZkSyncTokensStore = defineStore("zkSyncTokens", () => {
7272
);
7373
return [
7474
baseToken,
75-
...(baseToken.address.toUpperCase() !== ethToken.address.toUpperCase() ? [ethToken] : []),
75+
...(ethToken && baseToken.address.toUpperCase() !== ethToken.address.toUpperCase() ? [ethToken] : []),
7676
...nonBaseOrEthExplorerTokens,
7777
].map((token) => ({
7878
...token,

views/transactions/Deposit.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
class="mt-6"
112112
:custom-bridge-token="tokenCustomBridge"
113113
/>
114+
<TransactionNativeBridge
115+
v-if="nativeTokenBridgingOnly"
116+
:era-network="eraNetwork"
117+
type="deposit"
118+
class="mt-6"
119+
></TransactionNativeBridge>
114120
</template>
115121
<template v-else-if="step === 'wallet-warning'">
116122
<CommonAlert variant="warning" :icon="ExclamationTriangleIcon" class="mb-block-padding-1/2 sm:mb-block-gap">
@@ -158,7 +164,11 @@
158164
</template>
159165

160166
<template
161-
v-if="(!tokenCustomBridge || !tokenCustomBridge?.bridgingDisabled) && (step === 'form' || step === 'confirm')"
167+
v-if="
168+
!nativeTokenBridgingOnly &&
169+
(!tokenCustomBridge || !tokenCustomBridge?.bridgingDisabled) &&
170+
(step === 'form' || step === 'confirm')
171+
"
162172
>
163173
<CommonErrorBlock v-if="feeError" class="mt-2" @try-again="estimate">
164174
Fee estimation error: {{ feeError.message }}
@@ -290,7 +300,7 @@
290300
<EthereumTransactionFooter>
291301
<template #after-checks>
292302
<template v-if="step === 'form'">
293-
<template v-if="!enoughAllowance && !continueButtonDisabled">
303+
<template v-if="!enoughAllowance && !continueButtonDisabled && !nativeTokenBridgingOnly">
294304
<CommonButton
295305
type="submit"
296306
:disabled="continueButtonDisabled || setAllowanceInProgress"
@@ -645,6 +655,18 @@ watch(
645655
{ immediate: true }
646656
);
647657
658+
const nativeTokenBridgingOnly = computed(() => {
659+
if (
660+
eraNetwork.value.nativeBridgingOnly &&
661+
eraNetwork.value.nativeCurrency &&
662+
selectedToken.value &&
663+
selectedToken.value.symbol !== eraNetwork.value.nativeCurrency.symbol
664+
) {
665+
return true;
666+
}
667+
return false;
668+
});
669+
648670
const continueButtonDisabled = computed(() => {
649671
if (
650672
!transaction.value ||

views/transactions/Transfer.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
class="mt-6"
107107
:custom-bridge-token="tokenCustomBridge"
108108
/>
109+
<TransactionNativeBridge
110+
v-if="nativeTokenBridgingOnly"
111+
:era-network="eraNetwork"
112+
type="withdraw"
113+
class="mt-6"
114+
></TransactionNativeBridge>
109115
</template>
110116
<template v-else-if="step === 'withdrawal-finalization-warning'">
111117
<CommonAlert variant="warning" :icon="ExclamationTriangleIcon" class="mb-block-padding-1/2 sm:mb-block-gap">
@@ -190,7 +196,7 @@
190196
/>
191197
</template>
192198

193-
<template v-if="!tokenCustomBridge && (step === 'form' || step === 'confirm')">
199+
<template v-if="!nativeTokenBridgingOnly && !tokenCustomBridge && (step === 'form' || step === 'confirm')">
194200
<CommonErrorBlock v-if="feeError" class="mt-2" @try-again="estimate">
195201
Fee estimation error: {{ feeError.message }}
196202
</CommonErrorBlock>
@@ -553,6 +559,18 @@ watch(
553559
{ immediate: true }
554560
);
555561
562+
const nativeTokenBridgingOnly = computed(() => {
563+
if (
564+
eraNetwork.value.nativeBridgingOnly &&
565+
eraNetwork.value.nativeCurrency &&
566+
selectedToken.value &&
567+
selectedToken.value.symbol !== eraNetwork.value.nativeCurrency.symbol
568+
) {
569+
return true;
570+
}
571+
return false;
572+
});
573+
556574
const continueButtonDisabled = computed(() => {
557575
if (
558576
!isAddressInputValid.value ||

0 commit comments

Comments
 (0)