Skip to content

Commit 47aeaf4

Browse files
authored
refactor(funding-rate-proposer): Remove truffle and uma/core deps (#3334)
1 parent e5d6002 commit 47aeaf4

File tree

8 files changed

+199
-139
lines changed

8 files changed

+199
-139
lines changed

packages/funding-rate-proposer/hardhat.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const configOverride = {
1414
},
1515
};
1616

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

packages/funding-rate-proposer/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
const { FundingRateProposer } = require("./src/proposer");
1515

1616
// Contract ABIs and network Addresses.
17-
const { getAbi, getAddress } = require("@uma/core");
17+
const { getAbi, getAddress } = require("@uma/contracts-node");
1818
const { getWeb3, PublicNetworks } = require("@uma/common");
1919

2020
/**
@@ -68,7 +68,7 @@ async function run({
6868
logger,
6969
getAbi("PerpetualCreator"),
7070
web3,
71-
getAddress("PerpetualCreator", networkId),
71+
await getAddress("PerpetualCreator", networkId),
7272
0 // Force startingBlock=0 so we can get ALL deployed contracts.
7373
// Leave endingBlock=null so that we can get all events up to latest block.
7474
);

packages/funding-rate-proposer/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
"description": "UMA Perpetual Funding Rate Keeper",
55
"dependencies": {
66
"@uma/common": "^2.6.0",
7-
"@uma/core": "^2.7.0",
7+
"@uma/contracts-node": "^0.1.0",
88
"@uma/financial-templates-lib": "^2.6.1",
99
"async-retry": "^1.3.1",
1010
"dotenv": "^6.2.0"
1111
},
1212
"devDependencies": {
1313
"sinon": "^9.0.2",
14-
"truffle": "^5.2.3",
1514
"winston": "^3.2.1"
1615
},
1716
"homepage": "https://umaproject.org",
@@ -30,8 +29,7 @@
3029
],
3130
"bin": "index.js",
3231
"scripts": {
33-
"test": "yarn hardhat-test",
34-
"hardhat-test": "hardhat test"
32+
"test": "hardhat test"
3533
},
3634
"bugs": {
3735
"url": "https://github.com/UMAprotocol/protocol/issues"

packages/funding-rate-proposer/src/proposer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
aggregateTransactionsAndCall,
77
} = require("@uma/financial-templates-lib");
88
const { createObjectFromDefaultProps, runTransaction } = require("@uma/common");
9-
const { getAbi } = require("@uma/core");
9+
const { getAbi } = require("@uma/contracts-node");
1010
const Promise = require("bluebird");
1111
const assert = require("assert");
1212

packages/funding-rate-proposer/test/index.js

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,30 @@ const Main = require("../index.js");
33
const winston = require("winston");
44
const sinon = require("sinon");
55

6+
const { SpyTransport, spyLogIncludes, spyLogLevel } = require("@uma/financial-templates-lib");
7+
const { interfaceName, RegistryRolesEnum } = require("@uma/common");
8+
const { getAddress } = require("@uma/contracts-node");
9+
const { assert } = require("chai");
10+
const { deployments, getContract, web3, getChainId } = require("hardhat");
11+
612
const { toWei, utf8ToHex, padRight } = web3.utils;
713

8-
const { SpyTransport, spyLogIncludes, spyLogLevel } = require("@uma/financial-templates-lib");
9-
const { addGlobalHardhatTestingAddress, interfaceName, RegistryRolesEnum } = require("@uma/common");
10-
const { getTruffleContract } = require("@uma/core");
11-
12-
const PerpetualLib = getTruffleContract("PerpetualLib", web3);
13-
const PerpetualCreator = getTruffleContract("PerpetualCreator", web3);
14-
const IdentifierWhitelist = getTruffleContract("IdentifierWhitelist", web3);
15-
const Token = getTruffleContract("ExpandedERC20", web3);
16-
const AddressWhitelist = getTruffleContract("AddressWhitelist", web3);
17-
const Timer = getTruffleContract("Timer", web3);
18-
const TokenFactory = getTruffleContract("TokenFactory", web3);
19-
const Finder = getTruffleContract("Finder", web3);
20-
const Registry = getTruffleContract("Registry", web3);
21-
const OptimisticOracle = getTruffleContract("OptimisticOracle", web3);
22-
const Store = getTruffleContract("Store", web3);
23-
const MulticallMock = getTruffleContract("MulticallMock", web3);
24-
25-
contract("index.js", function (accounts) {
26-
const deployer = accounts[0];
14+
const PerpetualLib = getContract("PerpetualLib");
15+
const PerpetualCreator = getContract("PerpetualCreator");
16+
const IdentifierWhitelist = getContract("IdentifierWhitelist");
17+
const Token = getContract("ExpandedERC20");
18+
const AddressWhitelist = getContract("AddressWhitelist");
19+
const Timer = getContract("Timer");
20+
const TokenFactory = getContract("TokenFactory");
21+
const Finder = getContract("Finder");
22+
const Registry = getContract("Registry");
23+
const OptimisticOracle = getContract("OptimisticOracle");
24+
const Store = getContract("Store");
25+
const MulticallMock = getContract("MulticallMock");
26+
27+
describe("index.js", function () {
28+
// Accounts
29+
let deployer;
2730

2831
// Contracts
2932
let perpFactory;
@@ -71,63 +74,93 @@ contract("index.js", function (accounts) {
7174
const optimisticOracleLiveness = 100;
7275

7376
before(async function () {
74-
const timer = await Timer.new();
75-
const tokenFactory = await TokenFactory.new();
76-
const finder = await Finder.new();
77-
multicall = await MulticallMock.new();
77+
[deployer] = await web3.eth.getAccounts();
78+
79+
const timer = await Timer.new().send({ from: deployer });
80+
const tokenFactory = await TokenFactory.new().send({ from: deployer });
81+
const finder = await Finder.new().send({ from: deployer });
82+
multicall = await MulticallMock.new().send({ from: deployer });
7883

7984
// Whitelist an initial identifier so we can deploy.
80-
identifierWhitelist = await IdentifierWhitelist.new();
81-
await identifierWhitelist.addSupportedIdentifier(defaultCreationParams.priceFeedIdentifier);
82-
await identifierWhitelist.addSupportedIdentifier(defaultCreationParams.fundingRateIdentifier);
83-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.IdentifierWhitelist), identifierWhitelist.address);
85+
identifierWhitelist = await IdentifierWhitelist.new().send({ from: deployer });
86+
await identifierWhitelist.methods
87+
.addSupportedIdentifier(defaultCreationParams.priceFeedIdentifier)
88+
.send({ from: deployer });
89+
await identifierWhitelist.methods
90+
.addSupportedIdentifier(defaultCreationParams.fundingRateIdentifier)
91+
.send({ from: deployer });
92+
await finder.methods
93+
.changeImplementationAddress(utf8ToHex(interfaceName.IdentifierWhitelist), identifierWhitelist.options.address)
94+
.send({ from: deployer });
8495

8596
// Deploy new registry so perp factory can register contracts.
86-
const registry = await Registry.new();
87-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.Registry), registry.address);
97+
const registry = await Registry.new().send({ from: deployer });
98+
await finder.methods
99+
.changeImplementationAddress(utf8ToHex(interfaceName.Registry), registry.options.address)
100+
.send({ from: deployer });
88101

89102
// Store is neccessary to set up because contracts will need to read final fees before allowing
90103
// a proposal.
91-
const store = await Store.new({ rawValue: "0" }, { rawValue: "0" }, timer.address);
92-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.Store), store.address);
104+
const store = await Store.new({ rawValue: "0" }, { rawValue: "0" }, timer.options.address).send({ from: deployer });
105+
await finder.methods
106+
.changeImplementationAddress(utf8ToHex(interfaceName.Store), store.options.address)
107+
.send({ from: deployer });
93108

94109
// Funding rates are proposed to an OptimisticOracle.
95-
const optimisticOracle = await OptimisticOracle.new(optimisticOracleLiveness, finder.address, timer.address);
96-
await registry.addMember(RegistryRolesEnum.CONTRACT_CREATOR, optimisticOracle.address);
97-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.OptimisticOracle), optimisticOracle.address);
110+
const optimisticOracle = await OptimisticOracle.new(
111+
optimisticOracleLiveness,
112+
finder.options.address,
113+
timer.options.address
114+
).send({ from: deployer });
115+
await registry.methods
116+
.addMember(RegistryRolesEnum.CONTRACT_CREATOR, optimisticOracle.options.address)
117+
.send({ from: deployer });
118+
await finder.methods
119+
.changeImplementationAddress(utf8ToHex(interfaceName.OptimisticOracle), optimisticOracle.options.address)
120+
.send({ from: deployer });
98121

99122
// Whitelist collateral and use the same collateral for all contracts.
100-
collateral = await Token.new("Wrapped Ether", "WETH", "18");
101-
collateralWhitelist = await AddressWhitelist.new();
102-
await collateralWhitelist.addToWhitelist(collateral.address);
103-
defaultCreationParams = { ...defaultCreationParams, collateralAddress: collateral.address };
104-
await finder.changeImplementationAddress(utf8ToHex(interfaceName.CollateralWhitelist), collateralWhitelist.address);
105-
106-
await PerpetualCreator.link(await PerpetualLib.new());
107-
perpFactory = await PerpetualCreator.new(finder.address, tokenFactory.address, timer.address);
108-
await registry.addMember(RegistryRolesEnum.CONTRACT_CREATOR, perpFactory.address);
109-
// Set the address in the global name space to enable proposer's index.js to access it via `core/getAddressTest`.
110-
addGlobalHardhatTestingAddress("PerpetualCreator", perpFactory.address);
111-
112-
// Deploy new Perp
113-
const perpAddress = await perpFactory.createPerpetual.call(defaultCreationParams, configStoreParams, {
114-
from: deployer,
115-
});
116-
const perpCreation = await perpFactory.createPerpetual(defaultCreationParams, configStoreParams, {
123+
collateral = await Token.new("Wrapped Ether", "WETH", "18").send({ from: deployer });
124+
collateralWhitelist = await AddressWhitelist.new().send({ from: deployer });
125+
await collateralWhitelist.methods.addToWhitelist(collateral.options.address).send({ from: deployer });
126+
defaultCreationParams = { ...defaultCreationParams, collateralAddress: collateral.options.address };
127+
await finder.methods
128+
.changeImplementationAddress(utf8ToHex(interfaceName.CollateralWhitelist), collateralWhitelist.options.address)
129+
.send({ from: deployer });
130+
131+
// Deploy new Perpetual factory such that it is retrievable by the client via getAddress
132+
// Note: use hre.deployments.deploy method to link libraries.
133+
const perpetualLib = await PerpetualLib.new().send({ from: deployer });
134+
await deployments.deploy("PerpetualCreator", {
117135
from: deployer,
136+
args: [finder.options.address, tokenFactory.options.address, timer.options.address],
137+
libraries: { PerpetualLib: perpetualLib.options.address },
118138
});
139+
perpFactory = await PerpetualCreator.at(await getAddress("PerpetualCreator", parseInt(await getChainId())));
140+
await registry.methods
141+
.addMember(RegistryRolesEnum.CONTRACT_CREATOR, perpFactory.options.address)
142+
.send({ from: deployer });
143+
144+
// Deploy new Perp
145+
const perpAddress = await perpFactory.methods
146+
.createPerpetual(defaultCreationParams, configStoreParams)
147+
.call({ from: deployer });
148+
const perpCreation = await perpFactory.methods
149+
.createPerpetual(defaultCreationParams, configStoreParams)
150+
.send({ from: deployer });
119151
perpsCreated.push({ transaction: perpCreation, address: perpAddress });
152+
120153
// This is the time that the funding rate applier's update time is initialized to:
121-
let contractStartTime = await timer.getCurrentTime();
154+
let contractStartTime = await timer.methods.getCurrentTime().call({ from: deployer });
122155

123156
// Set the pricefeed's latestUpdateTime to be +1 second from the funding rate applier's
124157
// initialized update time, otherwise any proposals will fail because the new proposal timestamp
125158
// must always be > than the last update time.
126-
let lastUpdateTime = contractStartTime.toNumber() + 1;
159+
let lastUpdateTime = parseInt(contractStartTime) + 1;
127160
commonPriceFeedConfig = { ...commonPriceFeedConfig, lastUpdateTime };
128161
// Advance the perpetual contract forward in time to match pricefeed's update time, otherwise
129162
// the proposal will fail because it is "in the future".
130-
await timer.setCurrentTime(lastUpdateTime);
163+
await timer.methods.setCurrentTime(lastUpdateTime).send({ from: deployer });
131164
});
132165
it("Completes one iteration without logging any errors", async function () {
133166
// We will create a new spy logger, listening for debug events because success logs are tagged with the
@@ -145,7 +178,7 @@ contract("index.js", function (accounts) {
145178
errorRetries,
146179
errorRetriesTimeout,
147180
commonPriceFeedConfig,
148-
multicallAddress: multicall.address,
181+
multicallAddress: multicall.options.address,
149182
isTest: true, // Need to set this to true so that proposal uses correct request timestamp for test environment
150183
});
151184

0 commit comments

Comments
 (0)