Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2debe33
Added provider selector
RyRy79261 Apr 28, 2021
2fd9d60
Reworked app.tsx
RyRy79261 Apr 28, 2021
57a21f4
Working on adaptors
RyRy79261 Apr 30, 2021
b19ab3b
Working on new interfaces
RyRy79261 May 6, 2021
d8220b1
EVM wired
RyRy79261 May 7, 2021
5724715
Merge branch 'main' into feat/chain-adapters-68
RyRy79261 May 7, 2021
cb8bed2
Compiles now
RyRy79261 May 10, 2021
a575cbd
Merge branch 'feat/chain-adapters-68' of github.com:ChainSafe/chainbr…
RyRy79261 May 10, 2021
b758c7e
Tinkering
RyRy79261 May 10, 2021
630b3b7
Refactored home adapter to context (#73)
RyRy79261 May 24, 2021
f4289f3
Updating comments
RyRy79261 May 26, 2021
6e27838
Polkadot...
RyRy79261 May 27, 2021
23c0b4a
Balance fetched
RyRy79261 May 27, 2021
7d9d9b1
Selecting token
RyRy79261 May 27, 2021
7c09fff
Transfer sub to evm works
RyRy79261 May 27, 2021
de45a50
Added test listener logic
RyRy79261 May 27, 2021
e3ebcdf
Web3 issues
RyRy79261 May 28, 2021
361d44e
Revert
RyRy79261 May 28, 2021
8cb033b
Web3 eish
RyRy79261 May 28, 2021
6de6685
fix EVM home chain
FSM1 May 31, 2021
f5f211a
setup for GETH chainId 5
FSM1 Jun 1, 2021
7f81f4b
Present state
RyRy79261 Jun 1, 2021
6e5adef
Unsubscribe logic
RyRy79261 Jun 1, 2021
86402c8
update onbaord to latest version
FSM1 Jun 2, 2021
1ed6552
Init mutex
RyRy79261 Jun 2, 2021
2c6b8e0
Merge branch 'feat/chain-adapters-68' of github.com:ChainSafe/chainbr…
RyRy79261 Jun 2, 2021
27a8373
Mutex test
RyRy79261 Jun 2, 2021
c56ae6c
Block status not reported
RyRy79261 Jun 2, 2021
d7df802
Fixed cycle in evm
RyRy79261 Jun 2, 2021
91386d8
Removed consoles
RyRy79261 Jun 3, 2021
4a960e2
step 1
Tbaut Jun 3, 2021
165ed8c
fix typo
FSM1 Jun 3, 2021
cdfeda2
add substrate destination event handlers
FSM1 Jun 3, 2021
8864b93
cleanup
Tbaut Jun 3, 2021
b3d0406
Update src/Modules/TransferActiveModal.tsx
Tbaut Jun 3, 2021
a766c12
substrate address formatting
FSM1 Jun 3, 2021
9971d7e
Cleared
RyRy79261 Jun 4, 2021
c5b83aa
Added disconnect
RyRy79261 Jun 4, 2021
8906d4f
Resolved
RyRy79261 Jun 4, 2021
27fcb57
Token values matching
RyRy79261 Jun 4, 2021
9027175
Reset functionall
RyRy79261 Jun 4, 2021
5f16ed1
Removed keyring
RyRy79261 Jun 4, 2021
877d9d6
Merge remote-tracking branch 'origin/main' into feat/chain-adapters-68
FSM1 Jun 8, 2021
59414ef
Merge branch 'feat/chain-adapters-68' into tbaut/status
FSM1 Jun 8, 2021
8229030
auto set destination network
FSM1 Jun 8, 2021
a3f8bb7
Spruced
RyRy79261 Jun 8, 2021
56799f1
clean up config, add validation, add more readme
FSM1 Jun 9, 2021
efad8dd
Adapter modularity refactor (#77)
ansermino Jun 14, 2021
21ad0f9
update readme and config
FSM1 Jun 15, 2021
225c887
update readme, clean up Chainbridge API
FSM1 Jun 15, 2021
7e6cf09
fix relayer config and substrate deposit decimals
FSM1 Jun 15, 2021
b70cda0
use correct BN lib
FSM1 Jun 15, 2021
3bf6b1e
make adaptors dynamic
FSM1 Jun 16, 2021
9136d65
update readme
FSM1 Jun 16, 2021
32291fc
clear all warnings
FSM1 Jun 16, 2021
d47430e
fix package json scripts typo
FSM1 Jun 16, 2021
951d7f5
make function name generic
FSM1 Jun 16, 2021
c9a7423
update readme
FSM1 Jun 16, 2021
48e5b87
Apply suggestions from code review
FSM1 Jun 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up config, add validation, add more readme
  • Loading branch information
FSM1 committed Jun 9, 2021
commit 56799f10b9bb9ff2c071f57df764191f7f7b3dcf
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ For running a local instance use the command:
yarn start
```

The codebase is configured to be run against the Geth <> Substrate node that can be set up by following th guide (here)[https://chainbridge.chainsafe.io/local/].

All substrate specific configuration should be adjusted in `/src/Adaptors/SubstrateAdaptor.tsx`. The substrate adaptor's functionality is divided into 2 portions. Should the Substrate chain not implement things using the exact same pallet and method names, the Substrate adaptor will need to be updated to ensure correct operation.

First, update the `src/bridgeTypes.json` file with the desired Substrate Chain configuration.

- Home Chain

- Get relayer threshold from Chainbridge pallet
- Confirming current chainId from Chainbridge pallet
- Retrieving user token balance
- Handle deposit call `example.transferNative` and listening for emitted deposit nonce `chainbridge.chainNonces`

- Destination Chain
- Subscribe to all `system.events`, parse these and filter all events with `event.section=chainbridge` and `event.method = VoteFor` or `event.method = ProposalApproved` and fire the correct actions against the reducer.

### Build

Update the configs for the bridge in `src/chainbridgeContext.ts`. There should be at least 2 chains configured for correct functioning of the bridge. Each chain accepts the following configuration parameters:
Expand Down
22 changes: 12 additions & 10 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ if (
}

const App: React.FC<{}> = () => {
const tokens = chainbridgeConfig.chains.reduce((tca, bc) => {
if (bc.networkId) {
return {
...tca,
[bc.networkId]: bc.tokens,
};
} else {
return tca;
}
}, {});
const tokens = chainbridgeConfig.chains
.filter((c) => c.type === "Ethereum")
.reduce((tca, bc) => {
if (bc.networkId) {
return {
...tca,
[bc.networkId]: bc.tokens,
};
} else {
return tca;
}
}, {});

return (
<ErrorBoundary
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Pages/TransferPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { utils } from "ethers";
import FeesFormikWrapped from "./FormikContextElements/Fees";
import { useNetworkManager } from "../../Contexts/NetworkManagerContext";
import NetworkUnsupportedModal from "../../Modules/NetworkUnsupportedModal";
import { isValidSubstrateAddress } from "../../Utils/Helpers";

const useStyles = makeStyles(({ constants, palette }: ITheme) =>
createStyles({
Expand Down Expand Up @@ -274,8 +275,7 @@ const TransferPage = () => {
receiver: string()
.test("Valid address", "Please add a valid address", (value) => {
if (destinationChainConfig?.type === "Substrate") {
// TODO: Figure out how to validate Substrate addresses
return true;
return isValidSubstrateAddress(value as string);
}
return utils.isAddress(value as string);
})
Expand Down
21 changes: 12 additions & 9 deletions src/Contexts/Adaptors/SubstrateAdaptors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const SubstrateHomeAdaptorProvider = ({
}, [api, api?.isConnected, getRelayerThreshold, confirmChainID]);

useEffect(() => {
if (!homeChainConfig) return;
let unsubscribe: VoidFn | undefined;
if (api) {
api.query.system
Expand All @@ -119,12 +120,14 @@ export const SubstrateHomeAdaptorProvider = ({
data: { free: balance },
} = result.toJSON() as any;
setTokens({
CSS: {
balance: parseInt(utils.formatUnits(balance, 15)),
balanceBN: new BN(balance),
decimals: 15,
name: "Chainbridge",
symbol: "CSS",
[homeChainConfig.tokens[0].symbol || "TOKEN"]: {
decimals: homeChainConfig.decimals,
balance: parseInt(
utils.formatUnits(balance, homeChainConfig.decimals)
),
balanceBN: new BN(balance).shiftedBy(-homeChainConfig.decimals),
name: homeChainConfig.tokens[0].name,
symbol: homeChainConfig.tokens[0].symbol,
},
});
})
Expand All @@ -136,7 +139,7 @@ export const SubstrateHomeAdaptorProvider = ({
return () => {
unsubscribe && unsubscribe();
};
}, [api, address]);
}, [api, address, homeChainConfig]);

const handleConnect = useCallback(async () => {
// Requests permission to inject the wallet
Expand Down Expand Up @@ -283,7 +286,6 @@ export const SubstrateHomeAdaptorProvider = ({
export const SubstrateDestinationAdaptorProvider = ({
children,
}: IDestinationBridgeProviderProps) => {
// Comment out everything till the return statement for evm transfers to work
const {
depositNonce,
destinationChainConfig,
Expand All @@ -298,7 +300,8 @@ export const SubstrateDestinationAdaptorProvider = ({

const [initiaising, setInitialising] = useState(false);
useEffect(() => {
// Once the chain ID has been set in the network context, the destination configuration will be automatically set thus triggering this
// Once the chain ID has been set in the network context, the destination configuration will be automatically
// set thus triggering this
if (!destinationChainConfig || initiaising || api) return;
setInitialising(true);
const provider = new WsProvider(destinationChainConfig.rpcUrl);
Expand Down
13 changes: 13 additions & 0 deletions src/Utils/Helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
const { decodeAddress, encodeAddress } = require("@polkadot/keyring");
const { hexToU8a, isHex } = require("@polkadot/util");

export const shortenAddress = (address: string) => {
return `${address.substr(0, 6)}...${address.substr(address.length - 6, 6)}`;
};

export const isValidSubstrateAddress = (address: string) => {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));

return true;
} catch (error) {
return false;
}
};
126 changes: 8 additions & 118 deletions src/chainbridgeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,71 +34,8 @@ export type ChainbridgeConfig = {
};

export const chainbridgeConfig: ChainbridgeConfig = {
// Goerli - Kotti Bridge
// Local GETH <> Local Substrate
chains: [
// {
// chainId: 1,
// networkId: 5,
// name: "Ethereum - Goerli",
// decimals: 18,
// bridgeAddress: "0x2524d71D163f60747630c4EBeB077a9832329646",
// erc20HandlerAddress: "0xDc26320258ADfd806d125223Fb0F94e54D13FA51",
// rpcUrl: "https://goerli.prylabs.net",
// type: "Ethereum",
// blockExplorer: "https://goerli.etherscan.io/tx",
// nativeTokenSymbol: "ETH",
// deployedBlockNumber: 3554182,
// tokens: [
// {
// address: "0x735B895bCb37cBba5812154f4F34480EcE1B672C",
// name: "Wrapped ETC",
// symbol: "wETC",
// imageUri: WETHIcon,
// resourceId:
// "0x000000000000000000000023A9FD05ef0c5fb9dDE964C4d4191A169Fd221f802",
// },
// {
// address: "0x14dD060dB55c0E7cc072BD3ab4709d55583119c0",
// name: "An ERC20",
// symbol: "ERC20",
// imageUri: ETHIcon,
// resourceId:
// "0x000000000000000000000014dD060dB55c0E7cc072BD3ab4709d55583119c001",
// },
// ],
// },
// {
// chainId: 2,
// networkId: 6,
// name: "Ethereum Classic - Kotti",
// decimals: 18,
// bridgeAddress: "0x2524d71D163f60747630c4EBeB077a9832329646",
// erc20HandlerAddress: "0xDc26320258ADfd806d125223Fb0F94e54D13FA51",
// rpcUrl: "https://www.ethercluster.com/kotti",
// type: "Ethereum",
// blockExplorer: "https://blockscout.com/etc/kotti/tx",
// nativeTokenSymbol: "ETC",
// deployedBlockNumber: 0,
// tokens: [
// {
// address: "0x23A9FD05ef0c5fb9dDE964C4d4191A169Fd221f8",
// name: "Wrapped ETC",
// symbol: "wETC",
// imageUri: WETHIcon,
// resourceId:
// "0x000000000000000000000023A9FD05ef0c5fb9dDE964C4d4191A169Fd221f802",
// isNativeWrappedToken: true,
// },
// {
// address: "0x14dD060dB55c0E7cc072BD3ab4709d55583119c0",
// name: "An ERC20",
// symbol: "ERC20",
// imageUri: ETHIcon,
// resourceId:
// "0x000000000000000000000014dD060dB55c0E7cc072BD3ab4709d55583119c001",
// },
// ],
// },
{
chainId: 0,
networkId: 5,
Expand All @@ -110,14 +47,6 @@ export const chainbridgeConfig: ChainbridgeConfig = {
type: "Ethereum",
nativeTokenSymbol: "ETH",
tokens: [
// {
// address: "0x735B895bCb37cBba5812154f4F34480EcE1B672C",
// name: "Wrapped ETC",
// symbol: "wETC",
// imageUri: WETHIcon,
// resourceId:
// "0x000000000000000000000023A9FD05ef0c5fb9dDE964C4d4191A169Fd221f802",
// },
{
address: "0x21605f71845f372A9ed84253d2D024B7B10999f4",
name: "TOKEN",
Expand All @@ -131,60 +60,21 @@ export const chainbridgeConfig: ChainbridgeConfig = {
{
chainId: 1,
name: "Substrate - Local",
decimals: 18,
decimals: 15,
bridgeAddress: "0x2524d71D163f60747630c4EBeB077a9832329646",
erc20HandlerAddress: "0xDc26320258ADfd806d125223Fb0F94e54D13FA51",
rpcUrl: "ws://localhost:9944",
// rpcUrl: "wss://dev-node.substrate.dev:9944",
// const WS_PROVIDER = 'wss://dev-node.substrate.dev:9944';
// const WS_PROVIDER = 'wss://kusama-rpc.polkadot.io';
// const WS_PROVIDER = 'wss://westend-rpc.polkadot.io';
type: "Substrate",
nativeTokenSymbol: "DOT",
deployedBlockNumber: 0,
tokens: [
// TODO: get token data
{
address: "substrate-native",
name: "TOKEN",
symbol: "TOKEN",
resourceId: "substrate-native",
},
],
},
],

// DEVNET
// erc20ResourceId:
// "0x00000000000000000000000021605f71845f372A9ed84253d2D024B7B10999f4",
// chains: [
// {
// chainId: 1,
// networkId: 5,
// name: "Ethereum - A",
// bridgeAddress: "0x62877dDCd49aD22f5eDfc6ac108e9a4b5D2bD88B",
// erc20HandlerAddress: "0x3167776db165D8eA0f51790CA2bbf44Db5105ADF",
// rpcUrl: "http://localhost:8545",
// type: "Ethereum",
// tokens: [
// {
// address: "0x21605f71845f372A9ed84253d2D024B7B10999f4",
// name: "Test EthA",
// symbol: "TESTA",
// imageUri: ETHIcon,
// },
// ],
// },
// {
// chainId: 2,
// networkId: 6,
// name: "Ethereum - B",
// bridgeAddress: "0x62877dDCd49aD22f5eDfc6ac108e9a4b5D2bD88B",
// erc20HandlerAddress: "0x3167776db165D8eA0f51790CA2bbf44Db5105ADF",
// rpcUrl: "http://localhost:8546",
// type: "Ethereum",
// tokens: [
// {
// address: "0x21605f71845f372A9ed84253d2D024B7B10999f4",
// name: "Test EthB",
// symbol: "TESTB",
// imageUri: ETHIcon,
// },
// ],
// },
// ]
};