Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdt committed Feb 16, 2024
1 parent d3ba843 commit 8b9d76b
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 237 deletions.
128 changes: 65 additions & 63 deletions src/exec/lightbridge-instance.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,77 @@
import {providers} from "ethers";
import {BobaChains} from "../utils/chains";
import {ChainInfo, SupportedAssets} from "../utils/types";
import {LightBridgeService} from "../service";
import {ENetworkMode, ILightBridgeOpts} from "./types";
import path from "path";
import { providers } from 'ethers'
import { BobaChains } from '../utils/chains'
import { ChainInfo, SupportedAssets } from '../utils/types'
import { LightBridgeService } from '../service'
import { ENetworkMode, ILightBridgeOpts } from './types'
import path from 'path'

export const lightBridgeWorkerFileName = path.resolve(__filename)

/** This extra file is needed to execute light bridge instances in parallel.
* I used by piscina, thus it seems to be unused. */
export const startLightBridgeForNetwork = async (opts: ILightBridgeOpts) => {
const {
rpcUrl,
networkMode,
pollingInterval,
blockRangePerPolling,
envModeIsDevelopment,
awsKmsConfig,
airdropConfig,
} = opts
const {
rpcUrl,
networkMode,
pollingInterval,
blockRangePerPolling,
envModeIsDevelopment,
awsKmsConfig,
airdropConfig,
} = opts

console.log("Light bridge starting up for rpcUrl: ", rpcUrl, opts)
console.log('Light bridge starting up for rpcUrl: ', rpcUrl, opts)

const l2RpcProvider = new providers.StaticJsonRpcProvider(rpcUrl)
const l2RpcProvider = new providers.StaticJsonRpcProvider(rpcUrl)

// get all boba chains and exclude the current chain
const chainId = (await l2RpcProvider.getNetwork()).chainId
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!')
}
let originSupportedAssets: SupportedAssets
const selectedBobaChains: ChainInfo[] = 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
},
[]
)
const teleportationAddress = BobaChains[chainId].teleportationAddress
// get all boba chains and exclude the current chain
const chainId = (await l2RpcProvider.getNetwork()).chainId
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!')
}
let originSupportedAssets: SupportedAssets
const selectedBobaChains: ChainInfo[] = 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
},
[]
)
const teleportationAddress = BobaChains[chainId].teleportationAddress

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,
},
airdropConfig,
})
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,
},
airdropConfig,
})

await service.start()
await service.start()
}

Loading

0 comments on commit 8b9d76b

Please sign in to comment.