Skip to content

Commit

Permalink
Change naming from rulesHash to rules to allow for more flexibility i…
Browse files Browse the repository at this point in the history
…n format / content
  • Loading branch information
ckoopmann committed Jan 11, 2024
1 parent 823cfb5 commit 79d0b90
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 56 deletions.
26 changes: 13 additions & 13 deletions contracts/adapters/OptimisticAuctionRebalanceExtensionV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
IERC20 indexed setToken,
address indexed manager,
OptimisticRebalanceParams optimisticParams,
string rulesHash
string rules
);

event RebalanceProposed(
Expand All @@ -66,7 +66,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
event AssertedClaim(
IERC20 indexed setToken,
address indexed _assertedBy,
string rulesHash,
string rules,
bytes32 _assertionId,
bytes _claimData
);
Expand Down Expand Up @@ -99,7 +99,7 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As

struct ProductSettings{
OptimisticRebalanceParams optimisticParams; // OptimisticRebalanceParams struct containing optimistic rebalance parameters.
string rulesHash; // IPFS hash of the rules for the product.
string rules; // IPFS hash of the rules for the product.
}

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

// Keys for assertion claim data.
bytes public constant PROPOSAL_HASH_KEY = "proposalHash";
bytes public constant RULES_KEY = "rulesIPFSHash";
bytes public constant RULES_KEY = "rules";

/* ============ Constructor ============ */

Expand Down Expand Up @@ -178,21 +178,21 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As
/**
* @dev OPERATOR ONLY: sets product settings for a given set token
* @param _optimisticParams OptimisticRebalanceParams struct containing optimistic rebalance parameters.
* @param _rulesHash bytes32 containing the ipfs hash rules for the product.
* @param _rules string describing the rules of the rebalance (including IPFS hash pointing to full rules)
*/
function setProductSettings(
OptimisticRebalanceParams memory _optimisticParams,
string memory _rulesHash
string memory _rules
)
external
onlyOperator
{
productSettings = ProductSettings({
optimisticParams: _optimisticParams,
rulesHash: _rulesHash
rules: _rules
});

emit ProductSettingsUpdated(setToken, setToken.manager(), _optimisticParams, _rulesHash);
emit ProductSettingsUpdated(setToken, setToken.manager(), _optimisticParams, _rules);
}

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

bytes memory claim = _constructClaim(proposalHash, productSettings.rulesHash);
bytes memory claim = _constructClaim(proposalHash, productSettings.rules);
uint256 totalBond = _pullBond(productSettings.optimisticParams);

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

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

/**
Expand Down Expand Up @@ -369,14 +369,14 @@ contract OptimisticAuctionRebalanceExtensionV1 is AuctionRebalanceExtension, As

// Constructs the claim that will be asserted at the Optimistic Oracle V3.
// @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
function _constructClaim(bytes32 proposalHash, string memory rulesHash) internal pure returns (bytes memory) {
function _constructClaim(bytes32 proposalHash, string memory rules) internal pure returns (bytes memory) {
return
abi.encodePacked(
AncillaryData.appendKeyValueBytes32("", PROPOSAL_HASH_KEY, proposalHash),
",",
RULES_KEY,
":\"",
rulesHash,
rules,
"\""
);
}
Expand Down
12 changes: 6 additions & 6 deletions test/adapters/optimisticAuctionRebalanceExtensionV1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
});

context("when the product settings have been set", () => {
let rulesHash: string;
let rules: string;
let bondAmount: BigNumber;
beforeEach(async () => {
rulesHash = ipfsHash;
rules = ipfsHash;
bondAmount = ether(140); // 140 INDEX minimum bond
await auctionRebalanceExtension.connect(operator.wallet).setProductSettings(
{
Expand All @@ -319,7 +319,7 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
identifier: utils.formatBytes32String(""),
optimisticOracleV3: optimisticOracleV3Mock.address,
},
rulesHash,
rules,
);
});

Expand Down Expand Up @@ -441,7 +441,7 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
],
),
);
return `proposalHash:${proposalHash.slice(2)},rulesIPFSHash:"${rulesHash}"`;
return `proposalHash:${proposalHash.slice(2)},rulesIPFSHash:"${rules}"`;
}

context("when the extension is open for rebalance", () => {
Expand Down Expand Up @@ -522,8 +522,8 @@ describe("OptimisticAuctionRebalanceExtensionV1", () => {
expect(emittedSetToken).to.eq(setToken.address);
const assertedBy = assertEvent.args._assertedBy;
expect(assertedBy).to.eq(operator.wallet.address);
const emittedRulesHash = assertEvent.args.rulesHash;
expect(emittedRulesHash).to.eq(rulesHash);
const emittedRules = assertEvent.args.rules;
expect(emittedRules).to.eq(rules);
const claim = assertEvent.args._claimData;
expect(utils.toUtf8String(claim)).to.eq(constructClaim());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if (process.env.INTEGRATIONTEST) {
describe("OptimisticAuctionRebalanceExtensionV1 - Integration Test dsEth", () => {
const contractAddresses = PRODUCTION_ADDRESSES;

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

Expand Down Expand Up @@ -117,7 +118,7 @@ if (process.env.INTEGRATIONTEST) {
owner.wallet,
);

useAssetAllowlist = true;
useAssetAllowlist = te;

Check failure on line 121 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
allowedAssets = [contractAddresses.tokens.swETH, contractAddresses.tokens.ETHx]; // New dsETH components

dsEth = SetToken__factory.connect(contractAddresses.tokens.dsEth, owner.wallet);
Expand Down Expand Up @@ -153,7 +154,7 @@ if (process.env.INTEGRATIONTEST) {
let identifier: string;

beforeEach(async () => {
identifier = "0x4153534552545f54525554480000000000000000000000000000000000000000"; // ASSERT_TRUTH identifier
identifier = "0x4153534552545f54525554480000000000000000000000000000000000000000"; // ASSERT_TTH identifier

productSettings = {
collateral: collateralAssetAddress,
Expand All @@ -165,15 +166,12 @@ if (process.env.INTEGRATIONTEST) {

await auctionRebalanceExtension
.connect(operator)
.setProductSettings(
productSettings,
"Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z",
);
.setProductSettings(productSettings, rules);
});

context("when the extension is open to rebalances", () => {
beforeEach(async () => {
await auctionRebalanceExtension.updateIsOpen(true);
await auctionRebalanceExtension.updateIsOpen(te);

Check failure on line 174 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
});

context("when a rebalance has been proposed", () => {
Expand All @@ -197,9 +195,13 @@ if (process.env.INTEGRATIONTEST) {

subjectOldComponents = await dsEth.getComponents();

subjectNewComponents = [contractAddresses.tokens.swETH, contractAddresses.tokens.ETHx];
subjectNewComponents = [
contractAddresses.tokens.swETH,
contractAddresses.tokens.ETHx,
];
subjectNewComponentsAuctionParams = [
{ // swETH: https://etherscan.io/address/0xf951E335afb289353dc249e82926178EaC7DEd78#readProxyContract#F6
{
// swETH: https://etherscan.io/address/0xf951E335afb289353dc249e82926178EaC7DEd78#readProxyContract#F6
targetUnit: "155716754710815260",
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData: await priceAdapter.getEncodedData(
Expand All @@ -211,7 +213,8 @@ if (process.env.INTEGRATIONTEST) {
ether(1.043),
),
},
{ // ETHx: https://etherscan.io/address/0xcf5ea1b38380f6af39068375516daf40ed70d299#readProxyContract#F5
{
// ETHx: https://etherscan.io/address/0xcf5ea1b38380f6af39068375516daf40ed70d299#readProxyContract#F5
targetUnit: "162815732702576500",
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData: await priceAdapter.getEncodedData(
Expand All @@ -226,50 +229,54 @@ if (process.env.INTEGRATIONTEST) {
];

subjectOldComponentsAuctionParams = [
{ // wstETH: https://etherscan.io/address/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0#readContract#F10
{
// wstETH: https://etherscan.io/address/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0#readContract#F10
targetUnit: "148503139447300450",
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData: await priceAdapter.getEncodedData(
ether(1.155),
ether(0.001),
ONE_HOUR_IN_SECONDS,
true,
te,

Check failure on line 240 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
ether(1.155),
ether(1.149),
),
},
{ // rETH: https://etherscan.io/address/0xae78736Cd615f374D3085123A210448E74Fc6393#readContract#F6
{
// rETH: https://etherscan.io/address/0xae78736Cd615f374D3085123A210448E74Fc6393#readContract#F6
targetUnit: "233170302540761920",
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData: await priceAdapter.getEncodedData(
ether(1.097),
ether(0.001),
ONE_HOUR_IN_SECONDS,
true,
te,

Check failure on line 253 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
ether(1.097),
ether(1.091),
),
},
{ // sfrxETH: https://etherscan.io/address/0xac3E018457B222d93114458476f3E3416Abbe38F#readContract#F20
{
// sfrxETH: https://etherscan.io/address/0xac3E018457B222d93114458476f3E3416Abbe38F#readContract#F20
targetUnit: "123631627061020350",
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData: await priceAdapter.getEncodedData(
ether(1.073),
ether(0.001),
ONE_HOUR_IN_SECONDS,
true,
te,

Check failure on line 266 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
ether(1.073),
ether(1.067),
),
},
{ // osETH: https://etherscan.io/address/0x8023518b2192fb5384dadc596765b3dd1cdfe471#readContract#F3
{
// osETH: https://etherscan.io/address/0x8023518b2192fb5384dadc596765b3dd1cdfe471#readContract#F3
targetUnit: "153017509830141340",
priceAdapterName: "BoundedStepwiseLinearPriceAdapter",
priceAdapterConfigData: await priceAdapter.getEncodedData(
ether(1.005),
ether(0.001),
ONE_HOUR_IN_SECONDS,
true,
te,

Check failure on line 279 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
ether(1.005),
ether(1.004),
),
Expand All @@ -286,17 +293,17 @@ if (process.env.INTEGRATIONTEST) {
.add(effectiveBond)
.toHexString();

// set operator balance to effective bond
// set operator balance to effective bond
await ethers.provider.send("hardhat_setBalance", [
await subjectCaller.getAddress(),
quantity,
]);

await getIndexTokens(await subjectCaller.getAddress(), effectiveBond);
await indexToken
.connect(subjectCaller)
.approve(auctionRebalanceExtension.address, effectiveBond);
});
await indexToken
.connect(subjectCaller)
.approve(auctionRebalanceExtension.address, effectiveBond);
});

describe("#startRebalance", () => {
async function subject(): Promise<ContractTransaction> {
Expand Down Expand Up @@ -355,7 +362,7 @@ if (process.env.INTEGRATIONTEST) {
subjectRebalanceDuration,
subjectPositionMultiplier,
);
await auctionRebalanceExtension.updateIsOpen(true);
await auctionRebalanceExtension.updateIsOpen(te);

Check failure on line 365 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
});

it("should revert", async () => {
Expand Down Expand Up @@ -449,7 +456,9 @@ if (process.env.INTEGRATIONTEST) {
expect(proposalHash).to.not.eq(ethers.constants.HashZero);

await getIndexTokens(await subjectCaller.getAddress(), effectiveBond);
await indexToken.connect(subjectCaller).approve(optimisticOracleV3.address, effectiveBond);
await indexToken
.connect(subjectCaller)
.approve(optimisticOracleV3.address, effectiveBond);
await optimisticOracleV3
.connect(subjectCaller)
.disputeAssertion(proposalId, owner.address);
Expand All @@ -470,9 +479,7 @@ if (process.env.INTEGRATIONTEST) {
identifier,
optimisticOracleV3: optimisticOracleV3Mock.address,
},
utils.arrayify(
base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"),
),
rules,
);

const proposalHash = await auctionRebalanceExtension
Expand Down Expand Up @@ -505,9 +512,7 @@ if (process.env.INTEGRATIONTEST) {
identifier,
optimisticOracleV3: optimisticOracleV3Mock.address,
},
utils.arrayify(
base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"),
),
rules,
);
const tx = await auctionRebalanceExtension
.connect(subjectCaller)
Expand All @@ -530,7 +535,7 @@ if (process.env.INTEGRATIONTEST) {
.mockAssertionResolvedCallback(
auctionRebalanceExtension.address,
proposalId,
true,
te,

Check failure on line 538 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
);
});
});
Expand Down Expand Up @@ -579,7 +584,7 @@ if (process.env.INTEGRATIONTEST) {

beforeEach(async () => {
subjectBidders = [methodologist.address];
subjectStatuses = [true];
subjectStatuses = [te];

Check failure on line 587 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'te'.
subjectCaller = operator;
});

Expand All @@ -594,7 +599,7 @@ if (process.env.INTEGRATIONTEST) {

const isCaller = await auctionModule.isAllowedBidder(dsEth.address, subjectBidders[0]);

expect(isCaller).to.be.true;
expect(isCaller).to.be.te;

Check failure on line 602 in test/integration/ethereum/optimisticAuctionRebalanceExtenisonV1.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Property 'te' does not exist on type 'Assertion'.
});

describe("when the caller is not the operator", () => {
Expand All @@ -613,7 +618,7 @@ if (process.env.INTEGRATIONTEST) {
let subjectCaller: Signer;

beforeEach(async () => {
subjectStatus = true;
subjectStatus = te;
subjectCaller = operator;
});

Expand All @@ -628,7 +633,7 @@ if (process.env.INTEGRATIONTEST) {

const anyoneBid = await auctionModule.permissionInfo(dsEth.address);

expect(anyoneBid).to.be.true;
expect(anyoneBid).to.be.te;
});

describe("when the caller is not the operator", () => {
Expand All @@ -650,7 +655,7 @@ if (process.env.INTEGRATIONTEST) {
}

it("should remove the extension", async () => {
expect(await baseManager.isExtension(auctionRebalanceExtension.address)).to.be.true;
expect(await baseManager.isExtension(auctionRebalanceExtension.address)).to.be.te;
await subject();
expect(await baseManager.isExtension(auctionRebalanceExtension.address)).to.be.false;
});
Expand Down

0 comments on commit 79d0b90

Please sign in to comment.