-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Factor in speedup in relays, add more general entry point and a…
…dd docker file (#12) * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * feat: Implement HubPoolEventClient.validateFill * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> * nit Signed-off-by: chrismaree <[email protected]> Co-authored-by: ubuntu <>
- Loading branch information
1 parent
4f09ba8
commit 7d66c00
Showing
40 changed files
with
492 additions
and
222 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.github | ||
node_modules | ||
package-lock.json | ||
env | ||
dist | ||
.DS_Store |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM node:14 | ||
|
||
WORKDIR /relayer-v2 | ||
|
||
COPY . ./ | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y libudev-dev libusb-1.0-0-dev jq yarn rsync | ||
RUN yarn | ||
|
||
RUN yarn build | ||
|
||
ENTRYPOINT ["/bin/bash", "scripts/runCommand.sh"] |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Logger } from "@uma/financial-templates-lib"; | ||
|
||
import { runRelayer } from "./src/relayer"; | ||
|
||
export async function run(): Promise<void> { | ||
if (process.argv.includes("--relayer")) await runRelayer(Logger); | ||
else if (process.argv.includes("--dataworker")) console.log("NOT YET IMPLEMENTED"); | ||
else console.log("Select either relayer OR dataworker"); | ||
} | ||
|
||
if (require.main === module) { | ||
run() | ||
.then(() => { | ||
process.exit(0); | ||
}) | ||
.catch((error) => { | ||
console.error("Process exited with", error); | ||
process.exit(1); | ||
}); | ||
} |
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,6 +1,6 @@ | ||
{ | ||
"name": "relayer-v2", | ||
"version": "1.0.0", | ||
"version": "0.0.1", | ||
"description": "Across Protocol V2 Relayer Bot", | ||
"repository": "[email protected]:across-protocol/relayer-v2.git", | ||
"author": "UMA Team", | ||
|
@@ -15,8 +15,6 @@ | |
"hardhat": "^2.9.0" | ||
}, | ||
"files": [ | ||
"/contracts/**/*.sol", | ||
"/artifacts/**/*", | ||
"/dist/**/*" | ||
], | ||
"types": "dist/index.d.ts", | ||
|
@@ -25,7 +23,8 @@ | |
"lint": "yarn prettier --list-different", | ||
"lint-fix": "yarn prettier --write", | ||
"prettier": "prettier .", | ||
"test": "hardhat test" | ||
"test": "hardhat test", | ||
"build": "tsc && rsync -a --include '*/' --include '*.d.ts' --exclude '*' ./dist/" | ||
}, | ||
"devDependencies": { | ||
"@nomiclabs/hardhat-ethers": "^2.0.0", | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
#!/bin/bash | ||
|
||
# Simple script that simply runs a command input as an environment variable. | ||
$COMMAND |
Empty file.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import winston from "winston"; | ||
import { getProvider, getSigner, contractAt, Contract } from "../utils"; | ||
import { SpokePoolClient, HubPoolClient, RateModelClient, MultiCallBundler } from "./"; | ||
import { RelayerConfig } from "../relayer/RelayerConfig"; | ||
|
||
export function constructClients(logger: winston.Logger, config: RelayerConfig) { | ||
// Create signers for each chain. Each is connected to an associated provider for that chain. | ||
const baseSigner = getSigner(); | ||
|
||
const hubSigner = baseSigner.connect(getProvider(config.hubPoolChainId)); | ||
const spokeSigners = config.spokePoolChains | ||
.map((networkId) => getProvider(networkId)) | ||
.map((provider) => baseSigner.connect(provider)); | ||
|
||
// Create contract instances for each chain for each required contract. | ||
const hubPool = contractAt("HubPool", getAddress("HubPool", config.hubPoolChainId), hubSigner); | ||
|
||
const rateModelStore = contractAt("RateModelStore", getAddress("RateModelStore", config.hubPoolChainId), hubSigner); | ||
|
||
const spokePools = config.spokePoolChains.map((networkId, index) => { | ||
return { networkId, contract: contractAt("SpokePool", getAddress("SpokePool", networkId), spokeSigners[index]) }; | ||
}); | ||
|
||
// Create clients for each contract for each chain. | ||
|
||
const hubPoolClient = new HubPoolClient(logger, hubPool); | ||
|
||
const rateModelClient = new RateModelClient(logger, rateModelStore, hubPoolClient); | ||
|
||
let spokePoolClients = {}; | ||
spokePools.forEach((obj: { networkId: number; contract: Contract }) => { | ||
spokePoolClients[obj.networkId] = new SpokePoolClient(logger, obj.contract, rateModelClient, obj.networkId); | ||
}); | ||
|
||
// const gasEstimator = new GasEstimator() // todo when this is implemented in the SDK. | ||
const multiCallBundler = new MultiCallBundler(logger, null); | ||
|
||
return { hubPoolClient, rateModelClient, spokePoolClients, multiCallBundler }; | ||
} | ||
|
||
// If this is the first run then the hubPoolClient will have no whitelisted routes. If this is the case then first | ||
// update the hubPoolClient and the rateModelClients followed by the spokePoolClients. Else, update all at once. | ||
export async function updateClients( | ||
logger: winston.Logger, | ||
hubPoolClient: HubPoolClient, | ||
rateModelClient: RateModelClient, | ||
spokePoolClients: { [chainId: number]: SpokePoolClient } | ||
) { | ||
if (Object.keys(hubPoolClient.getL1TokensToDestinationTokens()).length === 0) { | ||
logger.debug({ at: "ClientHelper", message: "Updating clients for first run" }); | ||
await Promise.all([hubPoolClient.update(), rateModelClient.update()]); | ||
await updateSpokePoolClients(spokePoolClients); | ||
} else { | ||
logger.debug({ at: "ClientHelper", message: "Updating clients for standard run" }); | ||
await Promise.all([hubPoolClient.update(), rateModelClient.update(), updateSpokePoolClients(spokePoolClients)]); | ||
} | ||
} | ||
|
||
async function updateSpokePoolClients(spokePoolClients: { [chainId: number]: SpokePoolClient }) { | ||
await Promise.all(Object.values(spokePoolClients).map((client) => client.update())); | ||
} | ||
|
||
// TODO: this method is temp to enable this constructor to work. this should be replaced by a method from the contracts | ||
// package that exports the relationship between contractName and the associated chain they are deployed on. | ||
function getAddress(contractName: string, chainId: number) { | ||
const mapping = { | ||
RateModelStore: { 42: "0x5923929DF7A2D6E038bb005B167c1E8a86cd13C8" }, | ||
HubPool: { 42: "0xD449Af45a032Df413b497A709EeD3E8C112EbcE3" }, | ||
SpokePool: { | ||
42: "0x73549B5639B04090033c1E77a22eE9Aa44C2eBa0", | ||
69: "0x2b7b7bAE341089103dD22fa4e8D7E4FA63E11084", | ||
}, | ||
}; | ||
return mapping[contractName][chainId]; | ||
} |
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
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
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
Oops, something went wrong.