Skip to content

Commit

Permalink
feat: add lnv2 relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Jan 22, 2024
1 parent e25bc73 commit cfeef3b
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 71 deletions.
77 changes: 48 additions & 29 deletions docs/helixbridge/mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,63 @@ order: 1
## Ethereum

- chainId: 1
- ProxyAdmin: [0x66D86a686e50C98BaC236105eFAFb99Ee7605dc5](https://etherscan.io/address/0x66D86a686e50C98BaC236105eFAFb99Ee7605dc5)
- To Arbitrum
- LnBridgeLogicV1: [0xd12917F42E09e216623010EB5f15c39d4978d322](https://etherscan.io/address/0xd12917F42E09e216623010EB5f15c39d4978d322)
- LnBridgeProxyV1: [0xeAb1F01a8f4A2687023B159c2063639Adad5304E](https://etherscan.io/address/0xeAb1F01a8f4A2687023B159c2063639Adad5304E)
- To Darwinia
- LnBridgeLogicV1: [0xD4d94a7dDF49be9917DD89AC136149D5Dcb44717](https://etherscan.io/address/0xD4d94a7dDF49be9917DD89AC136149D5Dcb44717)
- LnBridgeProxyV1: [0x5F8D4232367759bCe5d9488D3ade77FCFF6B9b6B](https://etherscan.io/address/0x5F8D4232367759bCe5d9488D3ade77FCFF6B9b6B)
- mappingTokenFactoryLogic: [0x1928C29b8eCD6c877A2E6bEF01bD50C72E1be0cC](https://etherscan.io/address/0x1928C29b8eCD6c877A2E6bEF01bD50C72E1be0cC)
- mappingTokenFactoryProxy: [0xFBAD806Bdf9cEC2943be281FB355Da05068DE925](https://etherscan.io/address/0xFBAD806Bdf9cEC2943be281FB355Da05068DE925)
- LnBridge(v1): [0x5F8D4232367759bCe5d9488D3ade77FCFF6B9b6B](https://etherscan.io/address/0x5F8D4232367759bCe5d9488D3ade77FCFF6B9b6B)
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://etherscan.io/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)
- LnOppositeBridge(v2): [0x48d769d5C7ff75703cDd1543A1a2ed9bC9044A23](https://etherscan.io/address/0x48d769d5C7ff75703cDd1543A1a2ed9bC9044A23)

## Arbitrum One

- chainId: 42161
- ProxyAdmin: [0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1](https://arbiscan.io/address/0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1)
- To Ethereum
- LnBridgeLogicV1: [0x2FC7Def96561ca5e1f0Aa333cb78cFA51DeE3218](https://arbiscan.io/address/0x2FC7Def96561ca5e1f0Aa333cb78cFA51DeE3218)
- LnBridgeProxyV1: [0xD1B10B114f1975d8BCc6cb6FC43519160e2AA978](https://arbiscan.io/address/0xD1B10B114f1975d8BCc6cb6FC43519160e2AA978)
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://arbiscan.io/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)
- LnOppositeBridge(v2): [0x48d769d5C7ff75703cDd1543A1a2ed9bC9044A23](https://arbiscan.io/address/0x48d769d5C7ff75703cDd1543A1a2ed9bC9044A23)

## Darwinia

- chainId: 46
- ProxyAdmin: [0x2FC7Def96561ca5e1f0Aa333cb78cFA51DeE3218](https://darwinia.subscan.io/address/0x2FC7Def96561ca5e1f0Aa333cb78cFA51DeE3218)
- To Ethereum
- LnBridgeLogicV1: [0xb95e74D3ECaA6270559466576bFD62CE9745764B](https://darwinia.subscan.io/address/0xb95e74D3ECaA6270559466576bFD62CE9745764B)
- LnBridgeProxyV1: [0x84f7a56483C100ECb12CbB4A31b7873dAE0d8E9B](https://darwinia.subscan.io/address/0x84f7a56483C100ECb12CbB4A31b7873dAE0d8E9B)
- backingLogic: [0x8A87497488073307E1a17e8A12475a94Afcb413f](https://darwinia.subscan.io/address/0x8A87497488073307E1a17e8A12475a94Afcb413f)
- backingProxy: [0xD1B10B114f1975d8BCc6cb6FC43519160e2AA978](https://darwinia.subscan.io/address/0xD1B10B114f1975d8BCc6cb6FC43519160e2AA978)
- To Crab
- backingLogic: [0x3141fEB844049B7b0f922542a4cf5Bcae9e1367d](https://darwinia.subscan.io/address/0x3141fEB844049B7b0f922542a4cf5Bcae9e1367d)
- backingProxy: [0xF3c1444CD449bD66Ef6DA7CA6c3E7884840A3995](https://darwinia.subscan.io/address/0xF3c1444CD449bD66Ef6DA7CA6c3E7884840A3995)
- mappingTokenFactoryLogic: [0xcc357d5A8E5dBD52bC508E0FE491137d912F6bc8](https://darwinia.subscan.io/address/0xcc357d5A8E5dBD52bC508E0FE491137d912F6bc8)
- mappingTokenFactoryProxy: [0x8c585F9791EE5b4B23fe82888cE576DBB69607eB](https://darwinia.subscan.io/address/0x8c585F9791EE5b4B23fe82888cE576DBB69607eB)
- LnBridge(v1): [0x84f7a56483C100ECb12CbB4A31b7873dAE0d8E9B](https://darwinia.subscan.io/address/0x84f7a56483C100ECb12CbB4A31b7873dAE0d8E9B)
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://darwinia.subscan.io/account/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## Pologon Pos

- chainId: 137
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://polygonscan.com/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## zkSync era

- chainId: 324
- LnDefaultBridge(v2): [0x767Bc046c989f5e63683fB530f939DD34b91ceAC](https://explorer.zksync.io/address/0x767Bc046c989f5e63683fB530f939DD34b91ceAC)

## Binance Smart Chain

- chinaId: 56
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://bscscan.com/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## Linea

- chainId: 59144
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://lineascan.build/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## Mantle

- chainId: 5000
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://explorer.mantle.xyz/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## Scroll

- chainId: 534352
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://scrollscan.com/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## OP

- chainId: 10
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://optimistic.etherscan.io/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## Gnosis Chain

- chainId: 100
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://gnosisscan.io/address/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)

## Crab

- chainId: 44
- To Darwinia
- mappingTokenFactoryLogic: [0x31588a248550a90Bb6Bf784434e17D9470Ea0659](https://crab.subscan.io/address/0x31588a248550a90Bb6Bf784434e17D9470Ea0659)
- mappingTokenFactoryProxy: [0x8738A64392b71617aF4C685d0E827855c741fDF7](https://crab.subscan.io/address/0x8738A64392b71617aF4C685d0E827855c741fDF7)
- backingLogic: [0x3d33856dCf74f110690f5a2647C7dFb9BB5Ff2d0](https://crab.subscan.io/address/0x3d33856dCf74f110690f5a2647C7dFb9BB5Ff2d0)
- backingProxy: [0xCF8923ebF4244cedC647936a0281dd10bDFCBF18](https://crab.subscan.io/address/0xCF8923ebF4244cedC647936a0281dd10bDFCBF18)
- LnDefaultBridge(v2): [0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337](https://crab.subscan.io/account/0x94C614DAeFDbf151E1BB53d6A201ae5fF56A9337)
170 changes: 170 additions & 0 deletions docs/helixbridge/relayer_register.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
group:
title: 🔹 Relayer
order: 5
order: 3
title: Run a Relayer Node(V2)
---

## Overview

Helix is a completely open system where anyone can register as a Relayer without any barriers, contribute liquidity to the system, and earn profits. Before becoming a Relayer, you should have basic knowledge of blockchain, especially in the area of contract interaction. The code for Helix is open-source, and Relayers can either use the default code to run a Node or optimize the client according to their needs, promptly fixing any issues encountered.

Each Relayer entity is associated with two chains (the source chain and the target chain of the bridge) and a Token.

Prerequisites:

1. Prepare two accounts with same address on the two intended chains and deposit a certain amount of Token in each.
2. Register as a Relayer on the Helix UI, which involves staking a certain amount of collateral.
3. Pull the client code to your local environment, configure bridge information, and compile and run the code.

Now, let's run a Relayer Node on the testnet using the example of (arbitrum-sepolia -> sepolia, USDC).

## Registration

Open the Helix UI and navigate to the [Relayer Dashboard](https://testnet.helixbridge.app/relayer/dashboard).

- **(1/3) Select Chain and Token**

Choose the source chain as `arbitrum-sepolia`, the target chain as `sepolia`, and the Token as `USDC`. Click **Confirm** and the page will provide basic information about the bridge you are about to register. Here, you can find the bridge type is Opposite. Click **Next** to proceed.
:::info{title=BridgeType}
For LnBridge V2, there are only two types: Default and Opposite. The difference between these two types lies in the location of the Relayer's staked collateral. In Default type, the collateral is staked on the target chain, while in Opposite type, the collateral is staked on the source chain.
:::

- **(2/3) Deposit Collateral & Set Fees**

- Enter the desired amount of collateral and click **Confirm**. Subsequently, a wallet confirmation prompt will appear (this transaction is executed on the target chain). If your wallet is not currently connected to the target chain, you will be prompted to switch to the target chain before proceeding with the collateral pledge.
:::info{title=Collateral}
Helix does not impose any restrictions on the amount of collateral that a Relayer can stake; it is entirely specified by the Relayer. The more collateral pledged, the better the depth available for each transfer. However, it's important to note that higher collateral amounts correspond to increased pledge costs for the Relayer.
:::

- Entering the baseFee and liquidityFee rate. Click **Confirm**, and a wallet confirmation prompt will appear afterward(this transaction is executed on the source chain).
:::info{title=Fee}
The Relayer's final income per transfer is calculated as the `baseFee + liquidityFeeRate * Amount`, where Amount is the transfer amount.
:::

- **(3/3) Approve**

Authorize the contract to transfer Token `USDC` on the target chain. This authorization ensures that the `Relayer Client` can perform relay operations successfully on the target chain. Since there is also authorization in the second step, this step can be skipped if the authorized amount is sufficiently large.

After completing the registration, you can open the `Manage` tab to view the registered information. You will notice that the status of the relayer is `Offline` because you have not ye started the relayer client. Please note that there may be some delay in the synchronization of registration information.

<img src="/register.gif" style="width:90%; height:30%; text-align:middle; margin-left:5%; margin-right:5%">

## Run the client

Access the client code on [GitHub](https://github.com/helix-bridge/relayer) and pull it to your local machine.

### Configuration

The configuration information for the Relayer is stored in the file `.maintain/configure.json`.

```js
{
"indexer": "https://apollo-test.helixbridge.app/graphql",
"relayGasLimit": 600000,
"chains": [
{
"name": "sepolia",
"rpc": "https://rpc2.sepolia.org",
"native": "ETH",
"chainId": 11155111
},
{
"name": "arbitrum-sepolia",
"rpc": "https://sepolia-rollup.arbitrum.io/rpc",
"native": "ETH",
"chainId": 300
}
],
"bridges": [
{
"fromChain": "arbitrum-sepolia",
"toChain": "sepolia",
"sourceBridgeAddress": "0xbA96d83E2A04c4E50F2D6D7eCA03D70bA2426e5f",
"targetBridgeAddress": "0xbA96d83E2A04c4E50F2D6D7eCA03D70bA2426e5f",
"encryptedPrivateKey": "<ENCRYPTED_PRIVATEKEY>",
"feeLimit": 0.01,
"reorgThreshold": 20,
"bridgeType": "lnv2-opposite",
"providers": [
{
"fromAddress": "0x8A87497488073307E1a17e8A12475a94Afcb413f",
"toAddress": "0x0ac58Df0cc3542beC4cDa71B16D06C3cCc39f405",
"swapRate": 2000
}
]
}
]
}
```

- **indexer**: It's the second-layer index service introduced in this [section](https://docs.helixbridge.app/helixbridge/relayer_indexer) can be accessed through the following link.
<table style="width:80%">
<tr>
<th style="width:20%">Network</th><th>URL</th>
</tr>
<tr>
<td>Testnet</td><td>https://apollo-test.helixbridge.app/graphql</td>
</tr>
<tr>
<td>Mainnet</td><td>https://apollo.helixbridge.app/graphql</td>
</tr>
</table>

- **relayGasLimit**: The gas limit for the client to send the relay transaction. If not set, it will automatically estimate a reasonable value.
- **chains**: The list of information about the chains that the relayer needs, including name, chainId, and the URL for accessing the RPC node.
- **bridges**: The list of token bridge paths that can support multiple directions simultaneously. The fields include:
- **fromChain** and **toChain**: Must match the names defined in fileld **chains**
- **sourceBridge** and **targetBridge**: Representing the addresses of the Helix LnBridgeV2 contract (can be queried in section [Contract Address](https://docs.helixbridge.app/helixbridge/testnet))
- **encryptedPrivateKey**: It's the relayer's encrypted private key, corresponding to the account registered during registration
:::info{title=EncryptPrivateKey}
Execute the command `yarn crypto`. Follow the prompts to input your password and private key. After pressing Enter, it will print the private key encrypted with the provided password. Then replace the `<ENCRYPTED_PRIVATEKEY>` in the configuration file with the encrypted private key obtained.
:::
- **feeLimit**: Controls the maximum cost of a relay operation, protecting the relayer from excessive gas fees
- **reorgThreshold**: It's an assumption about the block confirmation of transactions initiated by users on the source chain – the larger, the safer
- **bridgeType**: Indicates the type of bridge, currently taking values of `lnv2-default`, `lnv2-opposite`, and `lnv3`, consistent with the type displayed during relayer registration
- **providers**: List the addresses of token pairs on the source and target chains, as well as the exchange rate for the native token on the target chain.
:::info{title=swapRate}
The swapRate is the conversion rate from the native token on the target chain to the transfer token. For example, the native token on Ethereum is ETH, and the token to be transferred is USDC, the conversion rate might be approximately 2500 at 16/01/2024. As prices fluctuate, the Relayer needs to periodically adjust this ratio.
:::

### Install & Run

After completing the configuration, you can execute the following commands one by one to compile and start the client:

```
>> yarn install
>> yarn build
>> yarn start
```

After the execution is complete, it will prompt you to enter a password. This password is the one used to encrypt the private key using `yarn crypto`.

```
>> yarn start
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [NestFactory] Starting Nest application...
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] UtilsModule dependencies initialized +49ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] DataworkerModule dependencies initialized +0ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] DiscoveryModule dependencies initialized +1ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] TasksModule dependencies initialized +0ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] ScheduleModule dependencies initialized +0ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] ConfigureModule dependencies initialized +1ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [InstanceLoader] RelayerModule dependencies initialized +1ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [RoutesResolver] AppController {/}: +6ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [RouterExplorer] Mapped {/, GET} route +3ms
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [dataworker] data worker started
[Nest] 46997 - 01/16/2024, 5:42:11 PM LOG [relayer] relayer service start
Password:******
```

### Client Run Status

Return to the Relayer Dashboard page on the UI, enter the **Manage** page, and you will observe that the status of your Relayer has changed to `Online`.

## Tips

If the token bridge is the `Default` type, there will be slight differences in the registration process, and in the client's configuration, the bridgeType should be modified to lnv2-default.
Loading

0 comments on commit cfeef3b

Please sign in to comment.