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: Unify all light bridge services into one #6

Merged
merged 40 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
681cc1a
refactoring for parallelization, step 1
wsdt Feb 16, 2024
d3ba843
feat: Unify services
wsdt Feb 16, 2024
8b9d76b
progress
wsdt Feb 16, 2024
80f06aa
started with parallelization tests
wsdt Feb 19, 2024
21d649b
started with parallelization tests
wsdt Feb 19, 2024
ae5ed84
Merge remote-tracking branch 'origin/main' into wsdt/unify
wsdt Feb 20, 2024
90984bc
chore: Deploy Boba BNB mainnet contracts
wsdt Feb 20, 2024
15b8300
chore: Replace bsc contracts in chains.ts
wsdt Feb 20, 2024
94074f4
fix: parallel test
wsdt Feb 22, 2024
f4831a6
feat: Add anvil bnb
wsdt Feb 23, 2024
e94e566
Merge branch 'wsdt/unify' of github.com-boba:bobanetwork/light-bridge…
wsdt Feb 23, 2024
88f1d81
test: add more tests
wsdt Feb 26, 2024
16a72d3
fix: lint
wsdt Feb 26, 2024
6e2264e
fix: test delay
wsdt Feb 26, 2024
bad6b16
cleanup
wsdt Feb 26, 2024
cf7e6ed
fix tests
wsdt Feb 26, 2024
b48f822
fixtests
wsdt Feb 26, 2024
7f2308b
feat: indepenendent airdrop config
wsdt Feb 26, 2024
20e7369
cleanup env
wsdt Feb 26, 2024
7320461
debugging
wsdt Feb 26, 2024
b3bc950
fix tests
wsdt Feb 26, 2024
1a72eca
debugging
wsdt Feb 26, 2024
6d1a96e
tests working
wsdt Feb 26, 2024
3c194c6
tests working
wsdt Feb 26, 2024
d7a7652
cleanup
wsdt Feb 26, 2024
4e78a1f
cleanup
wsdt Feb 26, 2024
88e182d
cleanup
wsdt Feb 26, 2024
ce57621
remove unneccessary if
wsdt Feb 27, 2024
ff49166
feat: Add sourceChain check for airdrop
wsdt Feb 27, 2024
fc54b5d
feat: Add sourceChain check for airdrop
wsdt Feb 27, 2024
73428e7
tests
wsdt Feb 27, 2024
a0d8417
tests
wsdt Feb 27, 2024
5291575
sourcechain check commented
wsdt Feb 28, 2024
83085da
included
wsdt Feb 28, 2024
a3d72e0
test-added
wsdt Feb 28, 2024
b719e63
feat: Sourcechain check & tests
wsdt Feb 28, 2024
5f6cfe9
prettier
wsdt Feb 28, 2024
8ab3af8
feat: Only allow airdropping from sourceChain ETH
wsdt Feb 29, 2024
f5b0bf3
fix: Networkmode to lowercase
wsdt Feb 29, 2024
62b8360
Update src/service.ts
wsdt Feb 29, 2024
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
14 changes: 4 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# dev = development, prod = productive
LIGHTBRIDGE_ENV=dev
# dev=false, prod=true
# dev=true, prod=false
LIGHTBRIDGE_REJECT_UNAUTHORIZED=false
# Main rpc this service is running on
RPC_URL=
# testnets | mainnets rpcs only
LIGHTBRIDGE_MODE=testnets
# Light bridge, supported networks
LIGHTBRIDGE_RPC_BOBAETHMAINNET=
LIGHTBRIDGE_RPC_BOBABNBMAINNET=
Expand All @@ -18,6 +18,7 @@ LIGHTBRIDGE_RPC_BNBTESTNET=
LIGHTBRIDGE_RPC_ARBITRUMMAINNET=
LIGHTBRIDGE_RPC_OPTIMISMMAINNET=
# DB settings
POSTGRES_HOST_AUTH_METHOD=trust # only for local debugging
LIGHTBRIDGE_POSTGRES_PASSWORD=abcdef
LIGHTBRIDGE_POSTGRES_CONNECT_TIMEOUT_MS=
LIGHTBRIDGE_POSTGRES_DB_HOST=LIGHTBRIDGE_db
Expand All @@ -29,13 +30,6 @@ LIGHTBRIDGE_AWS_KMS_SECRET_KEY=
LIGHTBRIDGE_AWS_KMS_KEY_ID=
LIGHTBRIDGE_AWS_KMS_ENDPOINT=
LIGHTBRIDGE_AWS_KMS_REGION=
# TBD best amount to airdrop
LIGHTBRIDGE_AIRDROP_GAS_AMOUNT_WEI=500000000000000
# TBD min Usd value
LIGHTBRIDGE_AIRDROP_MIN_USD_VALUE=15
# TBD
LIGHTBRIDGE_AIRDROP_COOLDOWN_SECONDS=86400
LIGHTBRIDGE_AIRDROP_ENABLED=false
# Optional
LIGHTBRIDGE_POLLING_INTERVAL=
LIGHTBRIDGE_BLOCK_RANGE_PER_POLLING=
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ All configuration is done via environment variables. See all variables at [.env.

| | Description | Default |
|-----------------------------------------|----------------------------------------------------|-----------------|
| RPC_URL | The endpoint of Layer 2 | |
| LIGHTBRIDGE_REJECT_UNAUTHORIZED | Allows self-signed certificates if false (TypeORM) | true |
| LIGHTBRIDGE_DISBURSER_KEY | The pk of disburser | |
| LIGHTBRIDGE_POLLING_INTERVAL | The polling interval of fetching events | 60s |
Expand All @@ -22,6 +21,7 @@ All configuration is done via environment variables. See all variables at [.env.
| LIGHTBRIDGE_POSTGRES_DB | The database name | postgres |
| LIGHTBRIDGE_POSTGRES_PORT | The database port | 5432 |
| LIGHTBRIDGE_POSTGRES_USER | The database user | postgres |
| LIGHTBRIDGE_MODE | Which rpcUrls to use? testnets or mainnets | testnets |
| LIGHTBRIDGE_ENV | The environment mode (dev or prod) | dev |

## Building & Running
Expand Down Expand Up @@ -67,6 +67,9 @@ Make sure disbursers have enough liquidity in form of the native asset (such as
- LightBridge deployed to: `0x670b130112C6f03E17192e63c67866e67D77c3ee`
- Proxy__LightBridge deployed to: `0x0dfFd3Efe9c3237Ad7bf94252296272c96237FF5`

### BSC Boba Mainnet
- LightBridge deployed to: `0x45B9877497d73C683D38e0C7FfCf089D5D9FDCDf`
- Proxy__LightBridge deployed to: `0x670b130112C6f03E17192e63c67866e67D77c3ee`

## Testnet deployments

Expand Down
4 changes: 2 additions & 2 deletions deploy/contract.deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function main() {
fileName = `${previousDeploymentAddress}-${currChainId}`
file.log(fileName, "Using previous deployment of LightBridge contract on " + previousDeploymentAddress)
Proxy__LightBridge = new ethers.Contract(
Proxy__LightBridge.address,
previousDeploymentAddress,
Factory__LightBridge.interface,
deployer
)
Expand Down Expand Up @@ -164,7 +164,7 @@ async function main() {
file.log(fileName, `Not initializing contract again as already done.`)
}
} catch (err) {
file.log(fileName, `Could not initialized not initialized contracts for already deployed contracts: ${JSON.stringify(err)}`)
file.log(fileName, `Could not initialize contracts for already deployed contracts: ${JSON.stringify(err)}`)
}
}

Expand Down
19 changes: 14 additions & 5 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
version: "3"

services:
anvil:
anvil_bnb:
image: ghcr.io/foundry-rs/foundry:latest
command:
- "anvil --hardfork berlin --chain-id 31338" # use legacy tx to emulate boba network
environment:
- ANVIL_IP_ADDR=0.0.0.0
# ports:
# - "8546:8545"
anvil_eth:
image: ghcr.io/foundry-rs/foundry:latest
command:
- "anvil --hardfork berlin" # use legacy tx to emulate boba network
environment:
- ANVIL_IP_ADDR=0.0.0.0
ports:
- "8545:8545"
# ports:
# - "8545:8545"

lightbridge:
depends_on:
- lightbridge_db
- kms
- anvil
- anvil_eth
- anvil_bnb
image: bobanetwork/lightbridge:latest
build:
context: .
dockerfile: ./Dockerfile
command: bash -c "npm test"
environment:
RPC_URL: "http://anvil:8545"
LIGHTBRIDGE_MODE: "testnets"
LIGHTBRIDGE_REJECT_UNAUTHORIZED: "true"
# KMS setup (incl. defaults)
LIGHTBRIDGE_ENV: "dev"
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ services:
dockerfile: ./Dockerfile.prod
command: bash -c "node ./build/src/exec/run.js"
environment:
RPC_URL: "${RPC_URL:-https://replica.goerli.boba.network}"
LIGHTBRIDGE_REJECT_UNAUTHORIZED: "${LIGHTBRIDGE_REJECT_UNAUTHORIZED:-false}"
LIGHTBRIDGE_MODE: "${LIGHTBRIDGE_MODE:-testnets}"
LIGHTBRIDGE_ENV: "${LIGHTBRIDGE_ENV:-dev}"
# KMS setup (incl. defaults)
LIGHTBRIDGE_ENV: "dev"
LIGHTBRIDGE_AWS_KMS_ACCESS_KEY: "${LIGHTBRIDGE_AWS_KMS_ACCESS_KEY:-1}"
LIGHTBRIDGE_AWS_KMS_SECRET_KEY: "${LIGHTBRIDGE_AWS_KMS_SECRET_KEY:-2}"
LIGHTBRIDGE_AWS_KMS_KEY_ID: "${LIGHTBRIDGE_AWS_KMS_KEY_ID:-lb_disburser_pk}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LightBridge deployed to: 0x45B9877497d73C683D38e0C7FfCf089D5D9FDCDf
Proxy__LightBridge deployed to: 0x670b130112C6f03E17192e63c67866e67D77c3ee
Initialized proxy: [object Object]
Added route for 56 chain, and token: 0x4200000000000000000000000000000000000023, receipt: [object Object]
Added route for 56 chain, and token: 0x0000000000000000000000000000000000000000, receipt: [object Object]
Added route for 288 chain, and token: 0x0000000000000000000000000000000000000000, receipt: [object Object]
Network iteration done
77 changes: 77 additions & 0 deletions src/exec/lightbridge-instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { providers } from 'ethers'
import { BobaChains } from '../utils/chains'
import { ENetworkMode, ILightBridgeOpts, SupportedAssets } from '../utils/types'
import { LightBridgeService } from '../service'

export const startLightBridgeForNetwork = async (opts: ILightBridgeOpts) => {
const {
rpcUrl,
networkMode,
pollingInterval,
blockRangePerPolling,
envModeIsDevelopment,
awsKmsConfig,
localNetworks,
} = opts

const l2RpcProvider = new providers.StaticJsonRpcProvider(rpcUrl)
let originSupportedAssets: SupportedAssets
let teleportationAddress: string

// get all boba chains and exclude the current chain
let chainId = (await l2RpcProvider.getNetwork()).chainId

let selectedBobaChains = localNetworks.selectedBobaNetworks

if (localNetworks && localNetworks.selectedBobaNetworks.length > 0) {
chainId = localNetworks.mainNetwork.chainId
originSupportedAssets = localNetworks.mainNetwork.supportedAssets
teleportationAddress = localNetworks.mainNetwork.teleportationAddress
} else {
const isTestnet = BobaChains[chainId].testnet
if (
(isTestnet && networkMode === ENetworkMode.MAINNETS) ||
(!isTestnet && networkMode === ENetworkMode.TESTNETS)
) {
throw new Error('FATAL error: Network Mode and chainConfig do not match!')
}
// do not override local networks, production code should ALWAYS go here, since localNetworks should be undefined.
selectedBobaChains = Object.keys(BobaChains).reduce((acc, cur) => {
const chain = BobaChains[cur]
if (isTestnet === chain.testnet) {
if (Number(cur) !== chainId) {
chain.provider = new providers.StaticJsonRpcProvider(chain.url)
acc.push({ chainId: cur, ...chain })
} else {
originSupportedAssets = chain.supportedAssets
}
}
return acc
}, [])
teleportationAddress = BobaChains[chainId].teleportationAddress
}

console.log('creating lightbridge service with chainId: ', chainId)
const service = new LightBridgeService({
l2RpcProvider,
chainId,
teleportationAddress,
selectedBobaChains,
ownSupportedAssets: originSupportedAssets,
pollingInterval: pollingInterval,
blockRangePerPolling: blockRangePerPolling,
awsConfig: {
awsKmsAccessKey: envModeIsDevelopment
? awsKmsConfig.awsKmsAccessKey
: null,
awsKmsSecretKey: envModeIsDevelopment
? awsKmsConfig.awsKmsSecretKey
: null,
awsKmsKeyId: awsKmsConfig.awsKmsKeyId,
awsKmsRegion: awsKmsConfig.awsKmsRegion,
awsKmsEndpoint: envModeIsDevelopment ? awsKmsConfig.awsKmsEndpoint : null,
},
})

await service.start()
}
Loading
Loading