Skip to content

Commit f780e9c

Browse files
authored
Save ipfs rules string instead of bytes32 (#159)
* Test decoding of claim * Save ipfs hash as string * Change naming from rulesHash to rules to allow for more flexibility in format / content * Fix outdated comment * Undo accidental replacement * Fix test
1 parent 3fc56f4 commit f780e9c

File tree

3 files changed

+45
-53
lines changed

3 files changed

+45
-53
lines changed

contracts/adapters/OptimisticAuctionRebalanceExtensionV1.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
4949
IERC20 indexed setToken,
5050
address indexed manager,
5151
OptimisticRebalanceParams optimisticParams,
52-
bytes32 indexed rulesHash
52+
string rules
5353
);
5454

5555
event RebalanceProposed(
@@ -66,7 +66,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
6666
event AssertedClaim(
6767
IERC20 indexed setToken,
6868
address indexed _assertedBy,
69-
bytes32 indexed rulesHash,
69+
string rules,
7070
bytes32 _assertionId,
7171
bytes _claimData
7272
);
@@ -99,7 +99,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
9999

100100
struct ProductSettings{
101101
OptimisticRebalanceParams optimisticParams; // OptimisticRebalanceParams struct containing optimistic rebalance parameters.
102-
bytes32 rulesHash; // IPFS hash of the rules for the product.
102+
string rules; // Definition of rules for the product. (including ipfs hash pointing to full rules)
103103
}
104104

105105
/* ============ State Variables ============ */
@@ -111,7 +111,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
111111

112112
// Keys for assertion claim data.
113113
bytes public constant PROPOSAL_HASH_KEY = "proposalHash";
114-
bytes public constant RULES_KEY = "rulesIPFSHash";
114+
bytes public constant RULES_KEY = "rules";
115115

116116
/* ============ Constructor ============ */
117117

@@ -178,21 +178,21 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
178178
/**
179179
* @dev OPERATOR ONLY: sets product settings for a given set token
180180
* @param _optimisticParams OptimisticRebalanceParams struct containing optimistic rebalance parameters.
181-
* @param _rulesHash bytes32 containing the ipfs hash rules for the product.
181+
* @param _rules string describing the rules of the rebalance (including IPFS hash pointing to full rules)
182182
*/
183183
function setProductSettings(
184184
OptimisticRebalanceParams memory _optimisticParams,
185-
bytes32 _rulesHash
185+
string memory _rules
186186
)
187187
external
188188
onlyOperator
189189
{
190190
productSettings = ProductSettings({
191191
optimisticParams: _optimisticParams,
192-
rulesHash: _rulesHash
192+
rules: _rules
193193
});
194194

195-
emit ProductSettingsUpdated(setToken, setToken.manager(), _optimisticParams, _rulesHash);
195+
emit ProductSettingsUpdated(setToken, setToken.manager(), _optimisticParams, _rules);
196196
}
197197

198198
/**
@@ -232,10 +232,10 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
232232
_positionMultiplier
233233
));
234234
require(assertionIds[proposalHash] == bytes32(0), "Proposal already exists");
235-
require(productSettings.rulesHash != bytes32(""), "Rules not set");
235+
require(bytes(productSettings.rules).length > 0, "Rules not set");
236236
require(address(productSettings.optimisticParams.optimisticOracleV3) != address(0), "Oracle not set");
237237

238-
bytes memory claim = _constructClaim(proposalHash, productSettings.rulesHash);
238+
bytes memory claim = _constructClaim(proposalHash, productSettings.rules);
239239
uint256 totalBond = _pullBond(productSettings.optimisticParams);
240240

241241
bytes32 assertionId = productSettings.optimisticParams.optimisticOracleV3.assertTruth(
@@ -254,7 +254,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
254254
assertionIdToProposalHash[assertionId] = proposalHash;
255255

256256
emit RebalanceProposed( setToken, _quoteAsset, _oldComponents, _newComponents, _newComponentsAuctionParams, _oldComponentsAuctionParams, _rebalanceDuration, _positionMultiplier);
257-
emit AssertedClaim(setToken, msg.sender, productSettings.rulesHash, assertionId, claim);
257+
emit AssertedClaim(setToken, msg.sender, productSettings.rules, assertionId, claim);
258258
}
259259

260260
/**
@@ -369,14 +369,14 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
369369

370370
// Constructs the claim that will be asserted at the Optimistic Oracle V3.
371371
// @dev Inspired by the equivalent function in the OptimisticGovernor: https://github.com/UMAprotocol/protocol/blob/96cf5be32a3f57ac761f004890dd3466c63e1fa5/packages/core/contracts/optimistic-governor/implementation/OptimisticGovernor.sol#L437
372-
function _constructClaim(bytes32 proposalHash, bytes32 rulesHash) internal pure returns (bytes memory) {
372+
function _constructClaim(bytes32 proposalHash, string memory rules) internal pure returns (bytes memory) {
373373
return
374374
abi.encodePacked(
375375
AncillaryData.appendKeyValueBytes32("", PROPOSAL_HASH_KEY, proposalHash),
376376
",",
377377
RULES_KEY,
378378
":\"",
379-
rulesHash,
379+
rules,
380380
"\""
381381
);
382382
}

test/adapters/optimisticAuctionRebalanceExtensionV1.spec.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "module-alias/register";
22

33
import { Address, Account } from "@utils/types";
4-
import { base58ToHexString } from "@utils/common";
54
import { ADDRESS_ZERO, ZERO } from "@utils/constants";
65
import {
76
BaseManager,
@@ -52,6 +51,8 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
5251
let useAssetAllowlist: boolean;
5352
let allowedAssets: Address[];
5453

54+
const ipfsHash = "Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z";
55+
5556
before(async () => {
5657
[owner, methodologist, operator] = await getAccounts();
5758

@@ -305,12 +306,10 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
305306
});
306307

307308
context("when the product settings have been set", () => {
308-
let rulesHash: Uint8Array;
309+
let rules: string;
309310
let bondAmount: BigNumber;
310311
beforeEach(async () => {
311-
rulesHash = utils.arrayify(
312-
base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"),
313-
);
312+
rules = ipfsHash;
314313
bondAmount = ether(140); // 140 INDEX minimum bond
315314
await auctionRebalanceExtension.connect(operator.wallet).setProductSettings(
316315
{
@@ -320,7 +319,7 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
320319
identifier: utils.formatBytes32String(""),
321320
optimisticOracleV3: optimisticOracleV3Mock.address,
322321
},
323-
rulesHash,
322+
rules,
324323
);
325324
});
326325

@@ -442,12 +441,7 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
442441
],
443442
),
444443
);
445-
const firstPart = utils.toUtf8Bytes(
446-
"proposalHash:" + proposalHash.slice(2) + ',rulesIPFSHash:"',
447-
);
448-
const lastPart = utils.toUtf8Bytes('"');
449-
450-
return utils.hexlify(utils.concat([firstPart, rulesHash, lastPart]));
444+
return `proposalHash:${proposalHash.slice(2)},rules:"${rules}"`;
451445
}
452446

453447
context("when the extension is open for rebalance", () => {
@@ -528,10 +522,10 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
528522
expect(emittedSetToken).to.eq(setToken.address);
529523
const assertedBy = assertEvent.args._assertedBy;
530524
expect(assertedBy).to.eq(operator.wallet.address);
531-
const emittedRulesHash = assertEvent.args.rulesHash;
532-
expect(emittedRulesHash).to.eq(utils.hexlify(rulesHash));
525+
const emittedRules = assertEvent.args.rules;
526+
expect(emittedRules).to.eq(rules);
533527
const claim = assertEvent.args._claimData;
534-
expect(claim).to.eq(constructClaim());
528+
expect(utils.toUtf8String(claim)).to.eq(constructClaim());
535529
});
536530

537531
context("when the same rebalance has been proposed already", () => {
@@ -570,7 +564,7 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
570564
const currentSettings = await auctionRebalanceExtension.productSettings();
571565
await auctionRebalanceExtension.setProductSettings(
572566
currentSettings.optimisticParams,
573-
constants.HashZero,
567+
"",
574568
);
575569
});
576570

@@ -891,9 +885,7 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
891885
identifier: utils.formatBytes32String(""),
892886
optimisticOracleV3: optimisticOracleV3MockUpgraded.address,
893887
},
894-
utils.arrayify(
895-
base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"),
896-
),
888+
ipfsHash,
897889
);
898890

899891
const proposalHash = await auctionRebalanceExtension

test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import "module-alias/register";
33
import { Address, Account } from "@utils/types";
44
import { increaseTimeAsync } from "@utils/test";
55
import { setBlockNumber } from "@utils/test/testingUtils";
6-
import { base58ToHexString } from "@utils/common";
76
import { ONE_HOUR_IN_SECONDS, ZERO } from "@utils/constants";
87
import { OptimisticAuctionRebalanceExtensionV1 } from "@utils/contracts/index";
98
import {
@@ -45,6 +44,7 @@ if (process.env.INTEGRATIONTEST) {
4544
describe("OptimisticAuctionRebalanceExtensionV1 - Integration Test dsEth", () => {
4645
const contractAddresses = PRODUCTION_ADDRESSES;
4746

47+
const rules = "Rules stored on ipfs under hash: Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z";
4848
const liveness = BigNumber.from(60 * 60 * 24 * 2); // 2 days
4949
const minimumBond = ether(140); // 140 INDEX Minimum Bond
5050

@@ -154,7 +154,7 @@ if (process.env.INTEGRATIONTEST) {
154154
let identifier: string;
155155

156156
beforeEach(async () => {
157-
identifier = "0x4153534552545f54525554480000000000000000000000000000000000000000"; // ASSERT_TRUTH identifier
157+
identifier = "0x4153534552545f54525554480000000000000000000000000000000000000000"; // ASSERT_TTH identifier
158158

159159
productSettings = {
160160
collateral: collateralAssetAddress,
@@ -166,10 +166,7 @@ if (process.env.INTEGRATIONTEST) {
166166

167167
await auctionRebalanceExtension
168168
.connect(operator)
169-
.setProductSettings(
170-
productSettings,
171-
utils.arrayify(base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z")),
172-
);
169+
.setProductSettings(productSettings, rules);
173170
});
174171

175172
context("when the extension is open to rebalances", () => {
@@ -198,9 +195,13 @@ if (process.env.INTEGRATIONTEST) {
198195

199196
subjectOldComponents = await dsEth.getComponents();
200197

201-
subjectNewComponents = [contractAddresses.tokens.swETH, contractAddresses.tokens.ETHx];
198+
subjectNewComponents = [
199+
contractAddresses.tokens.swETH,
200+
contractAddresses.tokens.ETHx,
201+
];
202202
subjectNewComponentsAuctionParams = [
203-
{ // swETH: https://etherscan.io/address/0xf951E335afb289353dc249e82926178EaC7DEd78#readProxyContract#F6
203+
{
204+
// swETH: https://etherscan.io/address/0xf951E335afb289353dc249e82926178EaC7DEd78#readProxyContract#F6
204205
targetUnit: "155716754710815260",
205206
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
206207
priceAdapterConfigData: await priceAdapter.getEncodedData(
@@ -212,7 +213,8 @@ if (process.env.INTEGRATIONTEST) {
212213
ether(1.043),
213214
),
214215
},
215-
{ // ETHx: https://etherscan.io/address/0xcf5ea1b38380f6af39068375516daf40ed70d299#readProxyContract#F5
216+
{
217+
// ETHx: https://etherscan.io/address/0xcf5ea1b38380f6af39068375516daf40ed70d299#readProxyContract#F5
216218
targetUnit: "162815732702576500",
217219
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
218220
priceAdapterConfigData: await priceAdapter.getEncodedData(
@@ -287,17 +289,17 @@ if (process.env.INTEGRATIONTEST) {
287289
.add(effectiveBond)
288290
.toHexString();
289291

290-
// set operator balance to effective bond
292+
// set operator balance to effective bond
291293
await ethers.provider.send("hardhat_setBalance", [
292294
await subjectCaller.getAddress(),
293295
quantity,
294296
]);
295297

296298
await getIndexTokens(await subjectCaller.getAddress(), effectiveBond);
297-
await indexToken
298-
.connect(subjectCaller)
299-
.approve(auctionRebalanceExtension.address, effectiveBond);
300-
});
299+
await indexToken
300+
.connect(subjectCaller)
301+
.approve(auctionRebalanceExtension.address, effectiveBond);
302+
});
301303

302304
describe("#startRebalance", () => {
303305
async function subject(): Promise<ContractTransaction> {
@@ -450,7 +452,9 @@ if (process.env.INTEGRATIONTEST) {
450452
expect(proposalHash).to.not.eq(ethers.constants.HashZero);
451453

452454
await getIndexTokens(await subjectCaller.getAddress(), effectiveBond);
453-
await indexToken.connect(subjectCaller).approve(optimisticOracleV3.address, effectiveBond);
455+
await indexToken
456+
.connect(subjectCaller)
457+
.approve(optimisticOracleV3.address, effectiveBond);
454458
await optimisticOracleV3
455459
.connect(subjectCaller)
456460
.disputeAssertion(proposalId, owner.address);
@@ -471,9 +475,7 @@ if (process.env.INTEGRATIONTEST) {
471475
identifier,
472476
optimisticOracleV3: optimisticOracleV3Mock.address,
473477
},
474-
utils.arrayify(
475-
base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"),
476-
),
478+
rules,
477479
);
478480

479481
const proposalHash = await auctionRebalanceExtension
@@ -506,9 +508,7 @@ if (process.env.INTEGRATIONTEST) {
506508
identifier,
507509
optimisticOracleV3: optimisticOracleV3Mock.address,
508510
},
509-
utils.arrayify(
510-
base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"),
511-
),
511+
rules,
512512
);
513513
const tx = await auctionRebalanceExtension
514514
.connect(subjectCaller)

0 commit comments

Comments
 (0)