Skip to content

Commit 05dc8f9

Browse files
authored
Sys5 bridge (#50)
* feat: hiding sys5 changes behind feature toggle * fix: filter deploy to stage for main only * fix: filter deploy to stage for main only * feat: add constants api * fix: sys5 changes on testnet * fix: remove unused import * fix: renable steps on nevm to sys * fix: add updated syscoinjs lib for mint sysx fix * chore: update syscoinjs lib to latest * fix: update switch wallet capabilities
1 parent 810e64e commit 05dc8f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+728
-339
lines changed

.github/workflows/ghcr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- "main"
77
- "support-pali-v1-backward-compatibility"
8+
- "sys5-bridge"
89

910
jobs:
1011
docker:
@@ -59,6 +60,7 @@ jobs:
5960

6061
deploy-staging:
6162
needs: docker
63+
if: github.ref_name == 'main'
6264
environment:
6365
name: staging
6466
permissions:

api/services/admin-transfer/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BlockbookAPIURL } from "@contexts/Transfer/constants";
21
import { utils as syscoinUtils } from "syscoinjs-lib";
32

43
export const CONFIRM_UTXO_TRANSACTION = "Confirm UTXO Transaction";
@@ -11,7 +10,7 @@ export const verifyTxTokenTransfer = async (
1110
tokenType: string
1211
) => {
1312
const rawTransaction = await syscoinUtils.fetchBackendRawTx(
14-
BlockbookAPIURL,
13+
process.env.UTXO_RPC_URL!,
1514
txId
1615
);
1716

api/services/admin-transfer/handle-freeze-burn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const handleFreezeBurn = async (
4444
const receipt = await validateTransactionReceipt(
4545
web3,
4646
txHash,
47-
ERC20_MANAGER_CONTRACT_ADDRESS
47+
ERC20_MANAGER_CONTRACT_ADDRESS!
4848
);
4949

5050
if (clearAll) {

api/services/admin-transfer/handle-submit-proofs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const handleSubmitProofs = async (
4444
const receipt = await validateTransactionReceipt(
4545
web3,
4646
txHash,
47-
RELAY_CONTRACT_ADDRESS
47+
RELAY_CONTRACT_ADDRESS!
4848
);
4949
if (clearAll) {
5050
transfer.logs = transfer.logs.filter(

components/Bridge/NEVMStepWrapepr.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import {
2-
MAINNET_CHAIN_ID,
3-
useNEVM,
4-
} from "@contexts/ConnectedWallet/NEVMProvider";
1+
import { useNEVM } from "@contexts/ConnectedWallet/NEVMProvider";
52
import { usePaliWalletV2 } from "@contexts/PaliWallet/usePaliWallet";
3+
import { useConstants } from "@contexts/useConstants";
64
import { Button } from "@mui/material";
75
import { isValidEthereumAddress } from "@pollum-io/sysweb3-utils";
86

@@ -14,6 +12,8 @@ const NEVMStepWrapper: React.FC<Props> = ({ children }) => {
1412
const { version, isBitcoinBased, switchTo, isEVMInjected, connectWallet } =
1513
usePaliWalletV2();
1614

15+
const { constants } = useConstants();
16+
1717
const { connect, account, chainId, switchToMainnet } = useNEVM();
1818

1919
if (version === "v2" && isBitcoinBased && isEVMInjected) {
@@ -38,7 +38,7 @@ const NEVMStepWrapper: React.FC<Props> = ({ children }) => {
3838
);
3939
}
4040

41-
if (chainId !== MAINNET_CHAIN_ID) {
41+
if (chainId !== constants?.chain_id) {
4242
return (
4343
<Button variant="contained" onClick={switchToMainnet}>
4444
Switch to NEVM Network

components/Bridge/Stepper.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ import {
66
SYS_TO_ETH_TRANSFER_STATUS,
77
} from "@contexts/Transfer/types";
88

9-
const NEVMToSYSStepper: React.FC<{ activeStep: number }> = ({ activeStep }) => (
10-
<Stepper activeStep={activeStep}>
11-
<Step key="connect-and-validate">
12-
<StepLabel>Connect and Validated</StepLabel>
13-
</Step>
14-
<Step key="freeze-and-burn">
15-
<StepLabel>Freeze and Burn SYS</StepLabel>
16-
</Step>
17-
<Step key="mint-sysx">
18-
<StepLabel>Mint SYSX</StepLabel>
19-
</Step>
20-
<Step key="burn-sysx">
21-
<StepLabel>Burn SYSX</StepLabel>
22-
</Step>
23-
<Step key="Completed">
24-
<StepLabel>Completed</StepLabel>
25-
</Step>
26-
</Stepper>
27-
);
9+
const NEVMToSYSStepper: React.FC<{ activeStep: number }> = ({ activeStep }) => {
10+
return (
11+
<Stepper activeStep={activeStep}>
12+
<Step key="connect-and-validate">
13+
<StepLabel>Connect and Validated</StepLabel>
14+
</Step>
15+
<Step key="freeze-and-burn">
16+
<StepLabel>Freeze and Burn SYS</StepLabel>
17+
</Step>
18+
<Step key="mint-sysx">
19+
<StepLabel>Mint SYSX</StepLabel>
20+
</Step>
21+
<Step key="burn-sysx">
22+
<StepLabel>Burn SYSX</StepLabel>
23+
</Step>
24+
<Step key="Completed">
25+
<StepLabel>Completed</StepLabel>
26+
</Step>
27+
</Stepper>
28+
);
29+
};
2830

2931
const SYSToNEVMStepper: React.FC<{ activeStep: number }> = ({ activeStep }) => {
3032
const { transfer } = useTransfer();

components/Bridge/Steps/CompleteNevmToSys.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { ITransfer } from "@contexts/Transfer/types";
2+
import { useConstants } from "@contexts/useConstants";
23
import { Alert, Box, Typography, Link } from "@mui/material";
34

45
import React from "react";
56

6-
const SYSCOIN_TX_BLOCKCHAIN_URL = "https://blockbook.syscoin.org/tx/";
7-
const NEVM_TX_BLOCKCHAIN_URL = "https://explorer.syscoin.org/tx/";
8-
97
type Props = {
108
transfer: ITransfer;
119
};
1210

1311
const BridgeCompleteNevmToSys: React.FC<Props> = ({ transfer }) => {
1412
const { logs } = transfer;
13+
const { constants } = useConstants();
14+
const SYSCOIN_TX_BLOCKCHAIN_URL = `${constants?.explorer.utxo}/tx/`;
15+
const NEVM_TX_BLOCKCHAIN_URL = `${constants?.explorer.nevm}/tx/`;
16+
1517
const mintSysTx = logs.find(
1618
(log) => log.status === "mint-sysx" && log.payload.data.tx !== undefined
1719
);

components/Bridge/Steps/CompleteSysToNevm.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { ITransfer } from "@contexts/Transfer/types";
2+
import { useConstants } from "@contexts/useConstants";
23
import { Alert, Box, Typography, Link } from "@mui/material";
34

45
import React from "react";
56

6-
const SYSCOIN_TX_BLOCKCHAIN_URL = "https://blockbook.syscoin.org/tx/";
7-
const NEVM_TX_BLOCKCHAIN_URL = "https://explorer.syscoin.org/tx/";
8-
97
type Props = {
108
transfer: ITransfer;
119
};
1210

1311
const BridgeCompleteSysToNevm: React.FC<Props> = ({ transfer }) => {
12+
const { constants } = useConstants();
13+
const SYSCOIN_TX_BLOCKCHAIN_URL = `${constants?.explorer.utxo}/tx/`;
14+
const NEVM_TX_BLOCKCHAIN_URL = `${constants?.explorer.nevm}/tx/`;
1415
const { logs } = transfer;
1516
const burnSysTx =
1617
transfer.useSysx || transfer.utxoAssetType === "sysx"

components/Bridge/Steps/ConfirmNEVMTransaction.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { useTransfer } from "../context/TransferContext";
33
import { Alert, CircularProgress, Link } from "@mui/material";
44
import { useNevmTransaction } from "../hooks/useNevmTransaction";
55
import { useEffect } from "react";
6-
import { NEVM_TX_BLOCKCHAIN_URL } from "@constants";
76
import NEVMStepWrapper from "../NEVMStepWrapepr";
7+
import { useConstants } from "@contexts/useConstants";
88

99
type Props = {
1010
successStatus: TransferStatus;
@@ -19,15 +19,18 @@ const BridgeConfirmNEVMTransaction: React.FC<Props> = ({
1919
invalidStateMessage,
2020
loadingMessage,
2121
}) => {
22+
const { constants } = useConstants();
2223
const { transfer, saveTransfer } = useTransfer();
2324

2425
const sourceLog: ITransferLog | undefined = transfer?.logs?.find(
25-
(log) => log.status === sourceStatus && Boolean(log?.payload?.data.hash)
26+
(log) => log.status === sourceStatus && Boolean(log?.payload?.data?.hash)
2627
);
2728

2829
const sourceTxHash = sourceLog?.payload.data.hash;
2930

30-
const { data, isFetched } = useNevmTransaction(sourceTxHash, { refetch: true });
31+
const { data, isFetched } = useNevmTransaction(sourceTxHash, {
32+
refetch: true,
33+
});
3134

3235
useEffect(() => {
3336
if (!isFetched || !data) {
@@ -63,7 +66,10 @@ const BridgeConfirmNEVMTransaction: React.FC<Props> = ({
6366
{loadingMessage}
6467
<CircularProgress size={"1rem"} />
6568
<br />
66-
<Link href={`${NEVM_TX_BLOCKCHAIN_URL}${sourceTxHash}`} target="_blank">
69+
<Link
70+
href={`${constants?.explorer.nevm}/tx/${sourceTxHash}`}
71+
target="_blank"
72+
>
6773
View on Explorer
6874
</Link>
6975
</Alert>

components/Bridge/Steps/ConfirmUTXOTransaction.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { useTransfer } from "../context/TransferContext";
33
import { useUtxoTransaction } from "components/Bridge/hooks/useUtxoTransaction";
44
import { ITransferLog, TransferStatus } from "@contexts/Transfer/types";
55
import React, { useEffect } from "react";
6-
import { SYSCOIN_TX_BLOCKCHAIN_URL } from "@constants";
76
import UTXOStepWrapper from "../UTXOStepWrapper";
7+
import { useConstants } from "@contexts/useConstants";
88

99
type Props = {
1010
invalidStateMessage: string;
@@ -22,6 +22,7 @@ const BridgeStepConfirmUTXOTransaction: React.FC<Props> = ({
2222
confirmations,
2323
}) => {
2424
const { transfer, saveTransfer } = useTransfer();
25+
const { constants } = useConstants();
2526

2627
const utxoStepLog = transfer.logs.find(
2728
(log) => log.status === sourceStatus && Boolean(log.payload?.data?.tx)
@@ -70,7 +71,7 @@ const BridgeStepConfirmUTXOTransaction: React.FC<Props> = ({
7071
{loadingMessage} &nbsp;
7172
<CircularProgress size={"1rem"} />
7273
<br />
73-
<Link href={`${SYSCOIN_TX_BLOCKCHAIN_URL}${txId}`} target="_blank">
74+
<Link href={`${constants?.explorer.utxo}/tx/${txId}`} target="_blank">
7475
View on Explorer
7576
</Link>
7677
</Alert>

components/Bridge/Steps/ConnectValidate/StartTransferButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { useFormContext } from "react-hook-form";
1111
import { useNevmBalance, useUtxoBalance } from "utils/balance-hooks";
1212
import { useFeatureFlags } from "../../hooks/useFeatureFlags";
13+
import { useConstants } from "@contexts/useConstants";
1314

1415
const ErrorMessage = ({ message }: { message: string }) => (
1516
<Box sx={{ display: "flex", mb: 2 }}>
@@ -23,6 +24,7 @@ export const ConnectValidateStartTransferButton: React.FC<{
2324
transfer: ITransfer;
2425
isSaving: boolean;
2526
}> = ({ isSaving, transfer }) => {
27+
const { constants } = useConstants();
2628
const {
2729
watch,
2830
formState: { errors, isValid },
@@ -64,7 +66,7 @@ export const ConnectValidateStartTransferButton: React.FC<{
6466
(sysxBalance.data < MIN_AMOUNT || sysxBalance.data < amount);
6567

6668
const isUtxoValid =
67-
isValidSYSAddress(utxoAddress, 57) &&
69+
isValidSYSAddress(utxoAddress, constants?.isTestnet ? 5700 : 57) &&
6870
!isUtxoNotEnoughGas &&
6971
!isSysxNotEnoughBalance &&
7072
utxoAssetType !== undefined;

components/Bridge/UTXOStepWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
usePaliWallet,
33
usePaliWalletV2,
44
} from "@contexts/PaliWallet/usePaliWallet";
5+
import { useConstants } from "@contexts/useConstants";
56
import { Button } from "@mui/material";
67
import { isValidSYSAddress } from "@pollum-io/sysweb3-utils";
78

@@ -10,6 +11,7 @@ type UTXOStepWrapperProps = {
1011
};
1112

1213
const UTXOStepWrapper: React.FC<UTXOStepWrapperProps> = ({ children }) => {
14+
const { constants } = useConstants();
1315
const { version, connectedAccount, connectWallet } = usePaliWallet();
1416

1517
const { isBitcoinBased, switchTo, changeAccount } = usePaliWalletV2();
@@ -26,7 +28,7 @@ const UTXOStepWrapper: React.FC<UTXOStepWrapperProps> = ({ children }) => {
2628
return <Button onClick={connectWallet}>Connect Pali Wallet</Button>;
2729
}
2830

29-
if (!isValidSYSAddress(connectedAccount, 57)) {
31+
if (!isValidSYSAddress(connectedAccount, constants?.isTestnet ? 5700 : 57)) {
3032
return (
3133
<>
3234
<Button variant="contained" onClick={changeAccount}>

components/Bridge/context/RelayContract.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

components/Bridge/context/Syscoin.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
import { BlockbookAPIURL } from "@contexts/Transfer/constants";
1+
import { useConstants } from "@contexts/useConstants";
22
import { createContext, useContext, useMemo } from "react";
33

44
import { syscoin, utils as syscoinUtils } from "syscoinjs-lib";
55

6-
export const SyscoinContext = createContext<syscoin>(
7-
new syscoin(null, BlockbookAPIURL, syscoinUtils.syscoinNetworks.mainnet)
8-
);
6+
export const SyscoinContext = createContext({} as syscoin);
97

108
export const useSyscoin = () => useContext(SyscoinContext);
119

1210
export const SyscoinProvider: React.FC<{ children: React.ReactNode }> = ({
1311
children,
1412
}) => {
15-
const instance = useMemo(
16-
() =>
17-
new syscoin(null, BlockbookAPIURL, syscoinUtils.syscoinNetworks.mainnet),
18-
[]
19-
);
13+
const { data } = useConstants();
14+
const instance = useMemo(() => {
15+
if (!data) {
16+
return null;
17+
}
18+
return new syscoin(
19+
null,
20+
data.rpc.utxo,
21+
data.isTestnet
22+
? syscoinUtils.syscoinNetworks.testnet
23+
: syscoinUtils.syscoinNetworks.mainnet
24+
);
25+
}, [data]);
26+
27+
if (!instance) {
28+
return null;
29+
}
30+
2031
return (
2132
<SyscoinContext.Provider value={instance}>
2233
{children}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { useMemo } from "react";
22
import { useWeb3 } from "../context/Web";
33
import SyscoinERC20ManagerABI from "@contexts/Transfer/abi/SyscoinERC20Manager";
4+
import { useFeatureFlags } from "./useFeatureFlags";
5+
import { useConstants } from "@contexts/useConstants";
46

57
export const useErc20ManagerContract = () => {
68
const web3 = useWeb3();
9+
const flags = useFeatureFlags();
10+
const { data: constants } = useConstants();
711
return useMemo(
812
() =>
913
new web3.eth.Contract(
1014
SyscoinERC20ManagerABI,
11-
"0xA738a563F9ecb55e0b2245D1e9E380f0fE455ea1"
15+
flags.isEnabled("isSys5Enabled")
16+
? constants?.contracts.ecr20ManagerContract.address
17+
: "0xA738a563F9ecb55e0b2245D1e9E380f0fE455ea1"
1218
),
13-
[web3]
19+
[web3, flags, constants?.contracts.ecr20ManagerContract.address]
1420
);
1521
};

components/Bridge/hooks/useFeatureFlags.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useQuery } from "react-query";
33
type FeatureFlags = {
44
foundationFundingAvailable: boolean;
55
adminEnabled: boolean;
6+
isSys5Enabled: boolean;
67
};
78

89
export const useFeatureFlags = () => {

0 commit comments

Comments
 (0)