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: added layerzero bridge #1267

Merged
merged 22 commits into from May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -30,6 +30,7 @@
"@astar-network/metamask-astar-adapter": "^0.5.4",
"@astar-network/metamask-astar-types": "^0.6.1",
"@ethersproject/bignumber": "^5.5.0",
"@layerzerolabs/scan-client": "^0.0.8",
"@polkadot/api": "^10.9.1",
"@polkadot/api-contract": "^10.9.1",
"@polkadot/extension-dapp": "0.46.5",
Expand Down
13 changes: 8 additions & 5 deletions src/components/assets/EvmNativeToken.vue
Expand Up @@ -43,15 +43,15 @@
</q-tooltip>
</router-link>

<a v-if="isAstar" :href="stargateUrl" target="_blank" rel="noopener noreferrer">
<router-link v-if="isAstar" :to="buildLzBridgePageLink()">
<button class="btn btn--icon">
<astar-icon-bridge />
</button>
<span class="text--mobile-menu">{{ $t('assets.bridge') }}</span>
<q-tooltip>
<span class="text--tooltip">{{ $t('assets.bridge') }}</span>
</q-tooltip>
</a>
</router-link>

<router-link v-if="isZkEvm" :to="buildEthereumBridgePageLink()">
<button class="btn btn--icon">
Expand Down Expand Up @@ -113,9 +113,12 @@ import ModalFaucet from 'src/components/assets/modals/ModalFaucet.vue';
import { useAccount, useBreakpoints, useFaucet, useNetworkInfo } from 'src/hooks';
import { faucetSethLink } from 'src/links';
import { getTokenImage } from 'src/modules/token';
import { buildEthereumBridgePageLink, buildTransferPageLink } from 'src/router/routes';
import {
buildEthereumBridgePageLink,
buildTransferPageLink,
buildLzBridgePageLink,
} from 'src/router/routes';
import { useStore } from 'src/store';
import { stargateUrl } from '../../modules/zk-evm-bridge';
import { computed, defineComponent, ref, watchEffect } from 'vue';

export default defineComponent({
Expand Down Expand Up @@ -195,12 +198,12 @@ export default defineComponent({
width,
screenSize,
isTruncate,
stargateUrl,
isAstar,
truncate,
handleModalFaucet,
buildTransferPageLink,
buildEthereumBridgePageLink,
buildLzBridgePageLink,
};
},
});
Expand Down
16 changes: 5 additions & 11 deletions src/components/assets/ZkAstr.vue
Expand Up @@ -42,21 +42,15 @@
</q-tooltip>
</router-link>

<a
v-if="t.symbol === 'ASTR'"
:href="stargateUrl"
target="_blank"
rel="noopener noreferrer"
class="box--icon"
>
<router-link v-if="t.symbol === 'ASTR'" :to="buildLzBridgePageLink()" class="box--icon">
<button class="btn btn--icon">
<astar-icon-bridge />
</button>
<span class="text--mobile-menu">{{ $t('assets.bridge') }}</span>
<q-tooltip>
<span class="text--tooltip">{{ $t('assets.bridge') }}</span>
</q-tooltip>
</a>
</router-link>

<a v-else :href="vAstrOmniLink" target="_blank" rel="noopener noreferrer" class="box--icon">
<button class="btn btn--icon">
Expand Down Expand Up @@ -118,9 +112,9 @@ import { useNetworkInfo } from 'src/hooks';
import { useEthProvider } from 'src/hooks/custom-signature/useEthProvider';
import { addToEvmProvider } from 'src/hooks/helper/wallet';
import { Erc20Token, getErc20Explorer } from 'src/modules/token';
import { buildTransferPageLink } from 'src/router/routes';
import { buildTransferPageLink, buildLzBridgePageLink } from 'src/router/routes';
import { PropType, defineComponent } from 'vue';
import { stargateUrl, vAstrOmniLink } from '../../modules/zk-evm-bridge';
import { vAstrOmniLink } from '../../modules/zk-evm-bridge';

export default defineComponent({
components: {},
Expand All @@ -140,7 +134,7 @@ export default defineComponent({

return {
ethProvider,
stargateUrl,
buildLzBridgePageLink,
vAstrOmniLink,
truncate,
addToEvmProvider,
Expand Down
84 changes: 65 additions & 19 deletions src/components/assets/transfer/Information.vue
Expand Up @@ -43,6 +43,11 @@
<transaction-history :tx="tx" />
</div>
</div>
<div v-else-if="lztTxHistories.length > 0" class="box--histories">
<div v-for="tx in lztTxHistories" :key="tx.timestamp">
<lz-history :tx="tx" />
</div>
</div>
<div v-else>
<span> {{ $t('assets.transferPage.noTxRecords') }} </span>
</div>
Expand Down Expand Up @@ -75,6 +80,7 @@
</template>
<script lang="ts">
import TransactionHistory from 'src/components/common/TransactionHistory.vue';
import LzHistory from 'src/components/common/LzHistory.vue';
import { useAccount, useNetworkInfo } from 'src/hooks';
import { socialUrl } from 'src/links';
import { HistoryTxType } from 'src/modules/account';
Expand All @@ -92,10 +98,14 @@ import {
} from 'src/modules/information';
import { getXvmAssetsTransferHistories } from 'src/modules/information/recent-history';
import { useStore } from 'src/store';
import { computed, defineComponent, PropType, ref, watchEffect } from 'vue';
import { computed, defineComponent, PropType, ref, watchEffect, onUnmounted } from 'vue';
import { RecentLzHistory } from '../../../modules/information/index';
import { getLzTxHistories } from '../../../modules/information/recent-history/transfer/index';
import { LOCAL_STORAGE } from '../../../config/localStorage';
import { endpointKey, providerEndpoints } from '../../../config/chainEndpoints';

export default defineComponent({
components: { TransactionHistory },
components: { TransactionHistory, LzHistory },
props: {
transferType: {
type: String as PropType<HistoryTxType>,
Expand All @@ -110,9 +120,10 @@ export default defineComponent({
setup(props) {
const store = useStore();
const txHistories = ref<RecentHistory[]>([]);
const lztTxHistories = ref<RecentLzHistory[]>([]);
const isLoadingTxHistories = ref<boolean>(true);
const { senderSs58Account, isMultisig } = useAccount();
const { currentNetworkName } = useNetworkInfo();
const { senderSs58Account, isMultisig, currentAccount } = useAccount();
const { currentNetworkName, isAstarZkEvm } = useNetworkInfo();

const isH160 = computed<boolean>(() => store.getters['general/isH160Formatted']);
const faqs = computed<Faq[]>(() => {
Expand All @@ -125,35 +136,70 @@ export default defineComponent({
if (props.transferType === HistoryTxType.ZK_ETHEREUM_BRIDGE) {
return faqZkEthereumBridge;
}
if (props.transferType === HistoryTxType.LZ_BRIDGE) {
return faqZkEthereumBridge;
}
return faqSs58XvmTransfer;
});

const setTxHistories = async (): Promise<void> => {
if (!senderSs58Account.value || !currentNetworkName.value) return;
const network = isAstarZkEvm.value
? providerEndpoints[endpointKey.ASTAR_ZKEVM].networkAlias
: currentNetworkName.value.toLowerCase();

if (props.transferType === HistoryTxType.Xvm) {
txHistories.value = await getXvmAssetsTransferHistories({
address: senderSs58Account.value,
network,
});
} else if (props.transferType === HistoryTxType.LZ_BRIDGE) {
lztTxHistories.value = await getLzTxHistories({
address: currentAccount.value,
network,
});
} else {
txHistories.value = await getTxHistories({
address: isH160.value ? currentAccount.value : senderSs58Account.value,
network,
});
}
};

watchEffect(async () => {
try {
isLoadingTxHistories.value = true;
const network = currentNetworkName.value.toLowerCase();
if (props.transferType === HistoryTxType.Xvm) {
txHistories.value = await getXvmAssetsTransferHistories({
address: senderSs58Account.value,
network,
});
} else {
txHistories.value = await getTxHistories({
address: senderSs58Account.value,
network,
});
}
await setTxHistories();
} catch (error) {
console.error(error);
} finally {
isLoadingTxHistories.value = false;
}
};
});

const autoFetchHistoryHandler = setInterval(async () => {
if (props.transferType === HistoryTxType.LZ_BRIDGE) {
try {
await setTxHistories();
} catch (error) {
console.error(error);
}
}
}, 10 * 1000);

watchEffect(setTxHistories);
onUnmounted(() => {
clearInterval(autoFetchHistoryHandler);
});

return { faqs, hotTopics, txHistories, isLoadingTxHistories, socialUrl, isMultisig };
return {
faqs,
hotTopics,
txHistories,
isLoadingTxHistories,
socialUrl,
isMultisig,
lztTxHistories,
};
},
});
</script>
Expand Down
31 changes: 24 additions & 7 deletions src/components/bridge/BridgeSelection.vue
Expand Up @@ -42,8 +42,12 @@
</div>

<div class="column--selection">
<button>
<a :href="stargateUrl" target="_blank" rel="noopener noreferrer" class="button--bridge">
<button :disabled="!isEnableLzBridge">
<component
:is="isEnableLzBridge ? 'router-link' : 'div'"
:to="buildLzBridgePageLink()"
class="button--bridge"
>
<div class="row--logo-bg">
<div class="img--logo-bg">
<img
Expand All @@ -66,8 +70,11 @@
</span>
</div>
</div>
</a>
</component>
</button>
<p v-if="!isEnableLzBridge" class="text--bridge-details">
{{ $t('bridge.astarBridge.text2') }}
</p>
</div>
<div v-if="isZkyoto" class="column--selection">
<button :disabled="!isEnableEthBridge">
Expand Down Expand Up @@ -182,15 +189,20 @@
import { cbridgeAppLink } from 'src/c-bridge';
import { useAccount, useNetworkInfo } from 'src/hooks';
import { EthBridgeNetworkName } from 'src/modules/zk-evm-bridge';
import { Path as RoutePath, buildEthereumBridgePageLink } from 'src/router/routes';
import {
Path as RoutePath,
buildEthereumBridgePageLink,
buildLzBridgePageLink,
} from 'src/router/routes';
import { computed, defineComponent } from 'vue';
import { stargateUrl, layerSwapLink, zKatanaBridgeUrl } from 'src/modules/zk-evm-bridge/index';
import { layerSwapLink, zKatanaBridgeUrl } from 'src/modules/zk-evm-bridge/index';

export default defineComponent({
components: {},
setup() {
const { currentAccount } = useAccount();
const { isZkEvm, networkNameSubstrate, isMainnet, isZkyoto } = useNetworkInfo();
const { isZkEvm, networkNameSubstrate, isMainnet, isZkyoto, isAstarZkEvm, isAstar, isH160 } =
useNetworkInfo();

const l1Name = computed<string>(() => {
return isZkyoto.value ? EthBridgeNetworkName.Sepolia : EthBridgeNetworkName.Ethereum;
Expand All @@ -211,6 +223,10 @@ export default defineComponent({
return true;
});

const isEnableLzBridge = computed<boolean>(() => {
return isH160.value && (isAstar.value || isAstarZkEvm.value);
});

return {
currentAccount,
cbridgeAppLink,
Expand All @@ -220,10 +236,11 @@ export default defineComponent({
l2Name,
cbridgeNetworkName,
buildEthereumBridgePageLink,
stargateUrl,
buildLzBridgePageLink,
layerSwapLink,
zKatanaBridgeUrl,
isZkyoto,
isEnableLzBridge,
};
},
});
Expand Down