-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
274 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
Oops, something went wrong.