Skip to content

Commit df66c7d

Browse files
nicholaspaimrice32
andauthored
refactor(fx-tunnel-relayer): Remove truffle and uma/core deps (#3332)
* refactor(fx-tunnel-relayer): Remove truffle and uma/core deps * Update packages/fx-tunnel-relayer/hardhat.config.ts Co-authored-by: Matt Rice <[email protected]> Co-authored-by: Matt Rice <[email protected]>
1 parent 47aeaf4 commit df66c7d

File tree

5 files changed

+83
-74
lines changed

5 files changed

+83
-74
lines changed

packages/fx-tunnel-relayer/hardhat.config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import "@nomiclabs/hardhat-web3";
2-
import "@nomiclabs/hardhat-truffle5";
3-
41
import { getHardhatConfig } from "@uma/common";
52
import path from "path";
63

@@ -17,4 +14,4 @@ const configOverride = {
1714
},
1815
};
1916

20-
module.exports = getHardhatConfig(configOverride, coreWkdir);
17+
export default getHardhatConfig(configOverride, coreWkdir, false);

packages/fx-tunnel-relayer/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
"description": "Relayer bot to support UMA's Polygon-Ethereum oracle bridge",
55
"dependencies": {
66
"@maticnetwork/maticjs": "^2.0.40",
7-
"@uma/core": "^2.7.0",
87
"@uma/common": "^2.6.0",
8+
"@uma/contracts-node": "^0.1.0",
99
"@uma/financial-templates-lib": "^2.6.1",
1010
"async-retry": "^1.3.1",
11-
"dotenv": "^8.2.0",
12-
"hardhat": "^2.4.3"
11+
"dotenv": "^8.2.0"
1312
},
1413
"devDependencies": {
1514
"@tsconfig/node14": "^1.0.0",

packages/fx-tunnel-relayer/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import retry from "async-retry";
44
import { config } from "dotenv";
55
import MaticJs from "@maticnetwork/maticjs";
66
import { averageBlockTimeSeconds, getWeb3 } from "@uma/common";
7-
import { getAddress, getAbi } from "@uma/core";
7+
import { getAddress, getAbi } from "@uma/contracts-node";
88
import { GasEstimator, Logger, waitForLogger, delay } from "@uma/financial-templates-lib";
99

1010
import { Relayer } from "./Relayer";
@@ -47,11 +47,11 @@ export async function run(logger: winston.Logger, web3: Web3): Promise<void> {
4747
// Construct contracts that we'll pass to the Relayer bot.
4848
const oracleChildTunnel = new polygonWeb3.eth.Contract(
4949
getAbi("OracleChildTunnel"),
50-
getAddress("OracleChildTunnel", polygonNetworkId) || undefined
50+
await getAddress("OracleChildTunnel", polygonNetworkId)
5151
);
5252
const oracleRootTunnel = new web3.eth.Contract(
5353
getAbi("OracleRootTunnel"),
54-
getAddress("OracleRootTunnel", ethNetworkId) || undefined
54+
await getAddress("OracleRootTunnel", ethNetworkId)
5555
);
5656

5757
// If pollingDelay === 0 then the bot is running in serverless mode and should send a `debug` level log.

packages/fx-tunnel-relayer/test/Relayer.ts

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import winston from "winston";
2-
import { assert, web3 } from "hardhat";
2+
import { assert } from "chai";
33
import { Contract } from "web3-eth-contract";
4-
import { getTruffleContract } from "@uma/core";
54
import sinon from "sinon";
65
import { Relayer } from "../src/Relayer";
6+
import { getAbi } from "@uma/contracts-node";
77
import { SpyTransport, GasEstimator, lastSpyLogIncludes } from "@uma/financial-templates-lib";
88
import { ZERO_ADDRESS, interfaceName, RegistryRolesEnum } from "@uma/common";
99

10+
const { getContract, deployments, web3 } = require("hardhat");
11+
1012
const { utf8ToHex, hexToUtf8 } = web3.utils;
11-
const Finder = getTruffleContract("Finder", web3);
12-
const OracleChildTunnel = getTruffleContract("OracleChildTunnel", web3);
13-
const Registry = getTruffleContract("Registry", web3);
14-
const OracleRootTunnel = getTruffleContract("OracleRootTunnelMock", web3);
15-
const MockOracle = getTruffleContract("MockOracleAncillary", web3);
16-
const StateSync = getTruffleContract("StateSyncMock", web3);
17-
const FxChild = getTruffleContract("FxChildMock", web3);
18-
const FxRoot = getTruffleContract("FxRootMock", web3);
13+
const Finder = getContract("Finder");
14+
const OracleChildTunnel = getContract("OracleChildTunnel");
15+
const Registry = getContract("Registry");
16+
const OracleRootTunnel = getContract("OracleRootTunnelMock");
17+
const MockOracle = getContract("MockOracleAncillary");
18+
const StateSync = getContract("StateSyncMock");
19+
const FxChild = getContract("FxChildMock");
20+
const FxRoot = getContract("FxRootMock");
1921

2022
// This function should return a bytes string.
2123
type customPayloadFn = () => Promise<string>;
@@ -57,33 +59,34 @@ describe("Relayer unit tests", function () {
5759
// Note: We deploy all contracts on local hardhat network to make testing more convenient.
5860

5961
// Set up mocked Fx tunnel:
60-
stateSync = await StateSync.new();
61-
fxRoot = await FxRoot.new(stateSync.address);
62-
fxChild = await FxChild.new(systemSuperUser);
63-
await fxChild.setFxRoot(fxRoot.address, { from: owner });
64-
await fxRoot.setFxChild(fxChild.address, { from: owner });
62+
stateSync = await StateSync.new().send({ from: owner });
63+
fxRoot = await FxRoot.new(stateSync.options.address).send({ from: owner });
64+
fxChild = await FxChild.new(systemSuperUser).send({ from: owner });
65+
await fxChild.methods.setFxRoot(fxRoot.options.address).send({ from: owner });
66+
await fxRoot.methods.setFxChild(fxChild.options.address).send({ from: owner });
6567

6668
// Set up mocked Oracle infrastructure
67-
finder = await Finder.new();
68-
mockOracle = await MockOracle.new(finder.address, ZERO_ADDRESS);
69-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.Oracle), mockOracle.address);
70-
registry = await Registry.new();
71-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.Registry), registry.address);
72-
await registry.addMember(RegistryRolesEnum.CONTRACT_CREATOR, owner, { from: owner });
73-
await registry.registerContract([], owner, { from: owner });
69+
finder = await Finder.new().send({ from: owner });
70+
mockOracle = await MockOracle.new(finder.options.address, ZERO_ADDRESS).send({ from: owner });
71+
await finder.methods
72+
.changeImplementationAddress(utf8ToHex(interfaceName.Oracle), mockOracle.options.address)
73+
.send({ from: owner });
74+
registry = await Registry.new().send({ from: owner });
75+
await finder.methods
76+
.changeImplementationAddress(utf8ToHex(interfaceName.Registry), registry.options.address)
77+
.send({ from: owner });
78+
await registry.methods.addMember(RegistryRolesEnum.CONTRACT_CREATOR, owner).send({ from: owner });
79+
await registry.methods.registerContract([], owner).send({ from: owner });
7480
});
7581

7682
beforeEach(async function () {
7783
// Deploy new tunnel contracts so that event logs are fresh for each test
78-
const _oracleChild = await OracleChildTunnel.new(fxChild.address, finder.address);
79-
const _oracleRoot = await OracleRootTunnel.new(checkpointManager, fxRoot.address, finder.address);
80-
await _oracleChild.setFxRootTunnel(_oracleRoot.address, { from: owner });
81-
await _oracleRoot.setFxChildTunnel(_oracleChild.address, { from: owner });
82-
83-
// Create Web3.eth.Contract versions of Tunnel contracts so that we can interact with them the same way
84-
// that the relayer bot does.
85-
oracleChild = new web3.eth.Contract(OracleChildTunnel.abi, _oracleChild.address);
86-
oracleRoot = new web3.eth.Contract(OracleRootTunnel.abi, _oracleRoot.address);
84+
oracleChild = await OracleChildTunnel.new(fxChild.options.address, finder.options.address).send({ from: owner });
85+
oracleRoot = await OracleRootTunnel.new(checkpointManager, fxRoot.options.address, finder.options.address).send({
86+
from: owner,
87+
});
88+
await oracleChild.methods.setFxRootTunnel(oracleRoot.options.address).send({ from: owner });
89+
await oracleRoot.methods.setFxChildTunnel(oracleChild.options.address).send({ from: owner });
8790

8891
// The OracleChildTunnel should stamp ",childRequester:<requester-address>,childChainId:<chain-id>" to the original
8992
// ancillary data.
@@ -107,6 +110,11 @@ describe("Relayer unit tests", function () {
107110
}),
108111
},
109112
};
113+
114+
// Save to hre.deployments so that client can fetch contract addresses via getAddress.
115+
deployments.save("OracleChildTunnel", { address: oracleChild.options.address, abi: getAbi("OracleChildTunnel") });
116+
deployments.save("OracleRootTunnel", { address: oracleChild.options.address, abi: getAbi("OracleRootTunnel") });
117+
110118
// Construct Relayer that should relay messages without fail.
111119
relayer = new Relayer(spyLogger, owner, gasEstimator, maticPosClient, oracleChild, oracleRoot, web3, 0);
112120
});

packages/fx-tunnel-relayer/test/index.ts

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import winston from "winston";
2-
import { assert, web3 } from "hardhat";
2+
import { assert } from "chai";
33
import { Contract } from "web3-eth-contract";
44
import sinon from "sinon";
55
import { run } from "../src/index";
6-
import { getTruffleContract } from "@uma/core";
7-
import { addGlobalHardhatTestingAddress, interfaceName, ZERO_ADDRESS, RegistryRolesEnum } from "@uma/common";
6+
import { interfaceName, ZERO_ADDRESS, RegistryRolesEnum } from "@uma/common";
87

98
import { SpyTransport } from "@uma/financial-templates-lib";
9+
import { getAbi } from "@uma/contracts-node";
10+
11+
const { getContract, deployments, web3 } = require("hardhat");
1012

1113
const { utf8ToHex } = web3.utils;
12-
const Finder = getTruffleContract("Finder", web3);
13-
const OracleChildTunnel = getTruffleContract("OracleChildTunnel", web3);
14-
const Registry = getTruffleContract("Registry", web3);
15-
const OracleRootTunnel = getTruffleContract("OracleRootTunnelMock", web3);
16-
const MockOracle = getTruffleContract("MockOracleAncillary", web3);
17-
const StateSync = getTruffleContract("StateSyncMock", web3);
18-
const FxChild = getTruffleContract("FxChildMock", web3);
19-
const FxRoot = getTruffleContract("FxRootMock", web3);
14+
const Finder = getContract("Finder");
15+
const OracleChildTunnel = getContract("OracleChildTunnel");
16+
const Registry = getContract("Registry");
17+
const OracleRootTunnel = getContract("OracleRootTunnelMock");
18+
const MockOracle = getContract("MockOracleAncillary");
19+
const StateSync = getContract("StateSyncMock");
20+
const FxChild = getContract("FxChildMock");
21+
const FxRoot = getContract("FxRootMock");
2022

2123
let spyLogger: any;
2224
let spy: any;
@@ -46,34 +48,37 @@ describe("index.ts", function () {
4648
// Note: We deploy all contracts on local hardhat network to make testing more convenient.
4749

4850
// Set up mocked Fx tunnel:
49-
stateSync = await StateSync.new();
50-
fxRoot = await FxRoot.new(stateSync.address);
51-
fxChild = await FxChild.new(systemSuperUser);
52-
await fxChild.setFxRoot(fxRoot.address, { from: owner });
53-
await fxRoot.setFxChild(fxChild.address, { from: owner });
51+
stateSync = await StateSync.new().send({ from: owner });
52+
fxRoot = await FxRoot.new(stateSync.options.address).send({ from: owner });
53+
fxChild = await FxChild.new(systemSuperUser).send({ from: owner });
54+
await fxChild.methods.setFxRoot(fxRoot.options.address).send({ from: owner });
55+
await fxRoot.methods.setFxChild(fxChild.options.address).send({ from: owner });
5456

5557
// Set up mocked Oracle infrastructure
56-
finder = await Finder.new();
57-
mockOracle = await MockOracle.new(finder.address, ZERO_ADDRESS);
58-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.Oracle), mockOracle.address);
59-
registry = await Registry.new();
60-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.Registry), registry.address);
61-
await registry.addMember(RegistryRolesEnum.CONTRACT_CREATOR, owner, { from: owner });
62-
await registry.registerContract([], owner, { from: owner });
58+
finder = await Finder.new().send({ from: owner });
59+
mockOracle = await MockOracle.new(finder.options.address, ZERO_ADDRESS).send({ from: owner });
60+
await finder.methods
61+
.changeImplementationAddress(utf8ToHex(interfaceName.Oracle), mockOracle.options.address)
62+
.send({ from: owner });
63+
registry = await Registry.new().send({ from: owner });
64+
await finder.methods
65+
.changeImplementationAddress(utf8ToHex(interfaceName.Registry), registry.options.address)
66+
.send({ from: owner });
67+
await registry.methods.addMember(RegistryRolesEnum.CONTRACT_CREATOR, owner).send({ from: owner });
68+
await registry.methods.registerContract([], owner).send({ from: owner });
6369
});
6470
beforeEach(async function () {
6571
// Deploy new tunnel contracts so that event logs are fresh for each test
66-
const _oracleChild = await OracleChildTunnel.new(fxChild.address, finder.address);
67-
const _oracleRoot = await OracleRootTunnel.new(checkpointManager, fxRoot.address, finder.address);
68-
await _oracleChild.setFxRootTunnel(_oracleRoot.address, { from: owner });
69-
await _oracleRoot.setFxChildTunnel(_oracleChild.address, { from: owner });
72+
oracleChild = await OracleChildTunnel.new(fxChild.options.address, finder.options.address).send({ from: owner });
73+
oracleRoot = await OracleRootTunnel.new(checkpointManager, fxRoot.options.address, finder.options.address).send({
74+
from: owner,
75+
});
76+
await oracleChild.methods.setFxRootTunnel(oracleRoot.options.address).send({ from: owner });
77+
await oracleRoot.methods.setFxChildTunnel(oracleChild.options.address).send({ from: owner });
7078

71-
// Create Web3.eth.Contract versions of Tunnel contracts so that we can interact with them the same way
72-
// that the relayer bot does.
73-
oracleChild = new web3.eth.Contract(OracleChildTunnel.abi, _oracleChild.address);
74-
addGlobalHardhatTestingAddress("OracleChildTunnel", oracleChild.options.address);
75-
oracleRoot = new web3.eth.Contract(OracleRootTunnel.abi, _oracleRoot.address);
76-
addGlobalHardhatTestingAddress("OracleRootTunnel", oracleRoot.options.address);
79+
// Save to hre.deployments so that client can fetch contract addresses via getAddress.
80+
deployments.save("OracleChildTunnel", { address: oracleChild.options.address, abi: getAbi("OracleChildTunnel") });
81+
deployments.save("OracleRootTunnel", { address: oracleChild.options.address, abi: getAbi("OracleRootTunnel") });
7782

7883
spy = sinon.spy();
7984
spyLogger = winston.createLogger({

0 commit comments

Comments
 (0)