diff --git a/test/adapters/optimisticAuctionRebalanceExtension.spec.ts b/test/adapters/optimisticAuctionRebalanceExtension.spec.ts index 4c00b7ba..887ec684 100644 --- a/test/adapters/optimisticAuctionRebalanceExtension.spec.ts +++ b/test/adapters/optimisticAuctionRebalanceExtension.spec.ts @@ -5,7 +5,7 @@ import { ADDRESS_ZERO, ZERO } from "@utils/constants"; import { BaseManager, ConstantPriceAdapter, -OptimisticAuctionRebalanceExtension, + OptimisticAuctionRebalanceExtension, OptimisticOracleV3Mock, StandardTokenMock, } from "@utils/contracts/index"; @@ -122,26 +122,23 @@ describe("OptimisticAuctionRebalanceExtension", () => { describe("#constructor", () => { let subjectBaseManager: Address; let subjectAuctionRebalanceModule: Address; - let subjectUseAssetAllowlist: boolean; - let subjectAllowedAssets: Address[]; + let subjectUseAssetAllowlist: boolean; + let subjectAllowedAssets: Address[]; beforeEach(async () => { subjectBaseManager = baseManager.address; subjectAuctionRebalanceModule = setV2Setup.auctionModule.address; - subjectUseAssetAllowlist = false; - subjectAllowedAssets = []; + subjectUseAssetAllowlist = false; + subjectAllowedAssets = []; }); - async function subject(): Promise { - let extension = await deployer.extensions.deployOptimisticAuctionRebalanceExtension( + function subject(): Promise { + return deployer.extensions.deployOptimisticAuctionRebalanceExtension( subjectBaseManager, subjectAuctionRebalanceModule, - subjectUseAssetAllowlist, - allowedAssets, + subjectUseAssetAllowlist, + subjectAllowedAssets, ); - extension = extension.connect(operator.wallet); - await baseManager.addAdapter(extension.address); - return extension; } it("should set the correct manager core", async () => { @@ -157,239 +154,161 @@ describe("OptimisticAuctionRebalanceExtension", () => { const actualAuctionRebalanceModule = await auctionExtension.auctionModule(); expect(actualAuctionRebalanceModule).to.eq(subjectAuctionRebalanceModule); }); - it("should be able to initialize extension and module at the same time", async () => { - const auctionExtension = await subject(); - await expect( - auctionExtension - .initialize(), - ).to.not.be.reverted; - }); - - it("should revert if module is initialized without being added", async () => { - const extension = await deployer.extensions.deployOptimisticAuctionRebalanceExtension( - subjectBaseManager, - subjectAuctionRebalanceModule, - subjectUseAssetAllowlist, - subjectAllowedAssets, - ); - await expect( - extension.connect(operator.wallet).initialize(), - ).to.be.revertedWith("Must be adapter"); - }); - - it("should revert if extension is initialized without being added", async () => { - const extension = await deployer.extensions.deployOptimisticAuctionRebalanceExtension( - subjectBaseManager, - subjectAuctionRebalanceModule, - subjectUseAssetAllowlist, - allowedAssets, - ); - await expect( - extension.connect(operator.wallet).initialize(), - ).to.be.revertedWith("Must be adapter"); - }); }); - context("when auction rebalance extension is added as adapter and needs to be initialized", () => { - let subjectCaller: Account; - - beforeEach(async () => { - subjectCaller = operator; - await baseManager.addAdapter(auctionRebalanceExtension.address); - }); + context( + "when auction rebalance extension is added as adapter and needs to be initialized", + () => { + let subjectCaller: Account; - describe("#initialize", () => { - async function subject() { - return await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .initialize(); - } - - it("should initialize AuctionRebalanceModule", async () => { - await subject(); - const isInitialized = await setToken.isInitializedModule(setV2Setup.auctionModule.address); - expect(isInitialized).to.be.true; + beforeEach(async () => { + subjectCaller = operator; + await baseManager.addAdapter(auctionRebalanceExtension.address); }); - describe("when the initializer is not the owner", () => { - beforeEach(async () => { - subjectCaller = await getRandomAccount(); - }); + describe("#initialize", () => { + async function subject() { + return await auctionRebalanceExtension.connect(subjectCaller.wallet).initialize(); + } - it("should revert", async () => { - await expect(subject()).to.be.revertedWith("Must be operator"); + it("should initialize AuctionRebalanceModule", async () => { + await subject(); + const isInitialized = await setToken.isInitializedModule( + setV2Setup.auctionModule.address, + ); + expect(isInitialized).to.be.true; }); - }); - }); - context("when auction rebalance extension is deployed and initialized.", () => { - beforeEach(async () => { - await auctionRebalanceExtension - .connect(operator.wallet) - .initialize(); + describe("when the initializer is not the owner", () => { + beforeEach(async () => { + subjectCaller = await getRandomAccount(); + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Must be operator"); + }); + }); }); - context("when the product settings have been set", () => { + context("when auction rebalance extension is deployed and initialized.", () => { beforeEach(async () => { - await auctionRebalanceExtension.connect(operator.wallet).setProductSettings( - { - collateral: collateralAsset.address, - liveness: BigNumber.from(0), - bondAmount: BigNumber.from(0), - identifier: utils.formatBytes32String(""), - optimisticOracleV3: optimisticOracleV3Mock.address, - }, - utils.arrayify(base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z")), - ); + await auctionRebalanceExtension.connect(operator.wallet).initialize(); }); - context("when a rebalance has been proposed", () => { - let subjectQuoteAsset: Address; - let subjectOldComponents: Address[]; - let subjectNewComponents: Address[]; - let subjectNewComponentsAuctionParams: any[]; - let subjectOldComponentsAuctionParams: any[]; - let subjectShouldLockSetToken: boolean; - let subjectRebalanceDuration: BigNumber; - let subjectPositionMultiplier: BigNumber; - let subjectCaller: Account; + context("when the product settings have been set", () => { beforeEach(async () => { - subjectQuoteAsset = setV2Setup.weth.address; - - subjectOldComponents = [ - setV2Setup.dai.address, - setV2Setup.wbtc.address, - setV2Setup.weth.address, - ]; - subjectNewComponents = [setV2Setup.usdc.address]; - - subjectNewComponentsAuctionParams = [ - { - targetUnit: usdc(100), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), - }, - ]; - - subjectOldComponentsAuctionParams = [ - { - targetUnit: ether(50), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), - }, + await auctionRebalanceExtension.connect(operator.wallet).setProductSettings( { - targetUnit: bitcoin(0.01), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + collateral: collateralAsset.address, + liveness: BigNumber.from(0), + bondAmount: BigNumber.from(0), + identifier: utils.formatBytes32String(""), + optimisticOracleV3: optimisticOracleV3Mock.address, }, - { - targetUnit: ether(0.1), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), - }, - ]; - - subjectShouldLockSetToken = true; - subjectRebalanceDuration = BigNumber.from(86400); - subjectPositionMultiplier = ether(0.999); - subjectCaller = operator; + utils.arrayify(base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z")), + ); }); - describe("#startRebalance", () => { - async function subject(): Promise { - await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposeRebalance( - subjectQuoteAsset, - subjectOldComponents, - subjectNewComponents, - subjectNewComponentsAuctionParams, - subjectOldComponentsAuctionParams, - subjectShouldLockSetToken, - subjectRebalanceDuration, - subjectPositionMultiplier, - ); - return auctionRebalanceExtension - .connect(subjectCaller.wallet) - .startRebalance( - subjectQuoteAsset, - subjectOldComponents, - subjectNewComponents, - subjectNewComponentsAuctionParams, - subjectOldComponentsAuctionParams, - subjectShouldLockSetToken, - subjectRebalanceDuration, - subjectPositionMultiplier, - ); - } - it("should set the auction execution params correctly", async () => { - await subject(); - expect(1).to.eq(1); + context("when a rebalance has been proposed", () => { + let subjectQuoteAsset: Address; + let subjectOldComponents: Address[]; + let subjectNewComponents: Address[]; + let subjectNewComponentsAuctionParams: any[]; + let subjectOldComponentsAuctionParams: any[]; + let subjectShouldLockSetToken: boolean; + let subjectRebalanceDuration: BigNumber; + let subjectPositionMultiplier: BigNumber; + let subjectCaller: Account; + beforeEach(async () => { + subjectQuoteAsset = setV2Setup.weth.address; - const aggregateComponents = [...subjectOldComponents, ...subjectNewComponents]; - const aggregateAuctionParams = [ - ...subjectOldComponentsAuctionParams, - ...subjectNewComponentsAuctionParams, + subjectOldComponents = [ + setV2Setup.dai.address, + setV2Setup.wbtc.address, + setV2Setup.weth.address, ]; + subjectNewComponents = [setV2Setup.usdc.address]; - for (let i = 0; i < aggregateAuctionParams.length; i++) { - const executionInfo = await setV2Setup.auctionModule.executionInfo( - setToken.address, - aggregateComponents[i], - ); - expect(executionInfo.targetUnit).to.eq(aggregateAuctionParams[i].targetUnit); - expect(executionInfo.priceAdapterName).to.eq( - aggregateAuctionParams[i].priceAdapterName, - ); - expect(executionInfo.priceAdapterConfigData).to.eq( - aggregateAuctionParams[i].priceAdapterConfigData, - ); - } - }); - - it("should set the rebalance info correctly", async () => { - const txnTimestamp = await getTransactionTimestamp(subject()); - - const rebalanceInfo = await setV2Setup.auctionModule.rebalanceInfo(setToken.address); - - expect(rebalanceInfo.quoteAsset).to.eq(subjectQuoteAsset); - expect(rebalanceInfo.rebalanceStartTime).to.eq(txnTimestamp); - expect(rebalanceInfo.rebalanceDuration).to.eq(subjectRebalanceDuration); - expect(rebalanceInfo.positionMultiplier).to.eq(subjectPositionMultiplier); - expect(rebalanceInfo.raiseTargetPercentage).to.eq(ZERO); + subjectNewComponentsAuctionParams = [ + { + targetUnit: usdc(100), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + }, + ]; - const rebalanceComponents = await setV2Setup.auctionModule.getRebalanceComponents( - setToken.address, - ); - const aggregateComponents = [...subjectOldComponents, ...subjectNewComponents]; + subjectOldComponentsAuctionParams = [ + { + targetUnit: ether(50), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + }, + { + targetUnit: bitcoin(0.01), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + }, + { + targetUnit: ether(0.1), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + }, + ]; - for (let i = 0; i < rebalanceComponents.length; i++) { - expect(rebalanceComponents[i]).to.eq(aggregateComponents[i]); - } + subjectShouldLockSetToken = true; + subjectRebalanceDuration = BigNumber.from(86400); + subjectPositionMultiplier = ether(0.999); + subjectCaller = operator; }); - - describe("when there are no new components", () => { - beforeEach(async () => { - subjectNewComponents = []; - subjectNewComponentsAuctionParams = []; - }); + describe("#startRebalance", () => { + async function subject(): Promise { + await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .proposeRebalance( + subjectQuoteAsset, + subjectOldComponents, + subjectNewComponents, + subjectNewComponentsAuctionParams, + subjectOldComponentsAuctionParams, + subjectShouldLockSetToken, + subjectRebalanceDuration, + subjectPositionMultiplier, + ); + return auctionRebalanceExtension + .connect(subjectCaller.wallet) + .startRebalance( + subjectQuoteAsset, + subjectOldComponents, + subjectNewComponents, + subjectNewComponentsAuctionParams, + subjectOldComponentsAuctionParams, + subjectShouldLockSetToken, + subjectRebalanceDuration, + subjectPositionMultiplier, + ); + } it("should set the auction execution params correctly", async () => { await subject(); + expect(1).to.eq(1); - for (let i = 0; i < subjectOldComponents.length; i++) { + const aggregateComponents = [...subjectOldComponents, ...subjectNewComponents]; + const aggregateAuctionParams = [ + ...subjectOldComponentsAuctionParams, + ...subjectNewComponentsAuctionParams, + ]; + + for (let i = 0; i < aggregateAuctionParams.length; i++) { const executionInfo = await setV2Setup.auctionModule.executionInfo( setToken.address, - subjectOldComponents[i], - ); - expect(executionInfo.targetUnit).to.eq( - subjectOldComponentsAuctionParams[i].targetUnit, + aggregateComponents[i], ); + expect(executionInfo.targetUnit).to.eq(aggregateAuctionParams[i].targetUnit); expect(executionInfo.priceAdapterName).to.eq( - subjectOldComponentsAuctionParams[i].priceAdapterName, + aggregateAuctionParams[i].priceAdapterName, ); expect(executionInfo.priceAdapterConfigData).to.eq( - subjectOldComponentsAuctionParams[i].priceAdapterConfigData, + aggregateAuctionParams[i].priceAdapterConfigData, ); } }); @@ -410,323 +329,379 @@ describe("OptimisticAuctionRebalanceExtension", () => { const rebalanceComponents = await setV2Setup.auctionModule.getRebalanceComponents( setToken.address, ); + const aggregateComponents = [...subjectOldComponents, ...subjectNewComponents]; + for (let i = 0; i < rebalanceComponents.length; i++) { - expect(rebalanceComponents[i]).to.eq(subjectOldComponents[i]); + expect(rebalanceComponents[i]).to.eq(aggregateComponents[i]); } }); - }); - describe("when old components are passed in different order", () => { - beforeEach(async () => { - subjectOldComponents = [ - setV2Setup.dai.address, - setV2Setup.weth.address, - setV2Setup.wbtc.address, - ]; - }); - - it("should revert", async () => { - await expect(subject()).to.be.revertedWith("Mismatch: old and current components"); - }); - }); + describe("when there are no new components", () => { + beforeEach(async () => { + subjectNewComponents = []; + subjectNewComponentsAuctionParams = []; + }); + + it("should set the auction execution params correctly", async () => { + await subject(); + + for (let i = 0; i < subjectOldComponents.length; i++) { + const executionInfo = await setV2Setup.auctionModule.executionInfo( + setToken.address, + subjectOldComponents[i], + ); + expect(executionInfo.targetUnit).to.eq( + subjectOldComponentsAuctionParams[i].targetUnit, + ); + expect(executionInfo.priceAdapterName).to.eq( + subjectOldComponentsAuctionParams[i].priceAdapterName, + ); + expect(executionInfo.priceAdapterConfigData).to.eq( + subjectOldComponentsAuctionParams[i].priceAdapterConfigData, + ); + } + }); + + it("should set the rebalance info correctly", async () => { + const txnTimestamp = await getTransactionTimestamp(subject()); + + const rebalanceInfo = await setV2Setup.auctionModule.rebalanceInfo( + setToken.address, + ); - describe("when old components array is shorter than current components array", () => { - beforeEach(async () => { - subjectOldComponents = [setV2Setup.dai.address, setV2Setup.wbtc.address]; - subjectOldComponentsAuctionParams = [ - { - targetUnit: ether(50), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), - }, - { - targetUnit: bitcoin(0.01), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), - }, - ]; - }); + expect(rebalanceInfo.quoteAsset).to.eq(subjectQuoteAsset); + expect(rebalanceInfo.rebalanceStartTime).to.eq(txnTimestamp); + expect(rebalanceInfo.rebalanceDuration).to.eq(subjectRebalanceDuration); + expect(rebalanceInfo.positionMultiplier).to.eq(subjectPositionMultiplier); + expect(rebalanceInfo.raiseTargetPercentage).to.eq(ZERO); - it("should revert", async () => { - await expect(subject()).to.be.revertedWith( - "Mismatch: old and current components length", - ); + const rebalanceComponents = await setV2Setup.auctionModule.getRebalanceComponents( + setToken.address, + ); + for (let i = 0; i < rebalanceComponents.length; i++) { + expect(rebalanceComponents[i]).to.eq(subjectOldComponents[i]); + } + }); }); - }); - describe("when old components array is longer than current components array", () => { - beforeEach(async () => { - const price = await priceAdapter.getEncodedData(ether(1)); - subjectOldComponents = [ - setV2Setup.dai.address, - setV2Setup.wbtc.address, - setV2Setup.weth.address, - setV2Setup.usdc.address, - ]; - subjectOldComponentsAuctionParams = [ - { - targetUnit: ether(50), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: price, - }, - { - targetUnit: bitcoin(0.01), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: price, - }, - { - targetUnit: ether(0.1), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: price, - }, - { - targetUnit: usdc(100), - priceAdapterName: "ConstantPriceAdapter", - priceAdapterConfigData: price, - }, - ]; + describe("when old components are passed in different order", () => { + beforeEach(async () => { + subjectOldComponents = [ + setV2Setup.dai.address, + setV2Setup.weth.address, + setV2Setup.wbtc.address, + ]; + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith( + "Mismatch: old and current components", + ); + }); }); - it("should revert", async () => { - await expect(subject()).to.be.revertedWith( - "Mismatch: old and current components length", - ); + describe("when old components array is shorter than current components array", () => { + beforeEach(async () => { + subjectOldComponents = [setV2Setup.dai.address, setV2Setup.wbtc.address]; + subjectOldComponentsAuctionParams = [ + { + targetUnit: ether(50), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + }, + { + targetUnit: bitcoin(0.01), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: await priceAdapter.getEncodedData(ether(0.005)), + }, + ]; + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith( + "Mismatch: old and current components length", + ); + }); }); - }); - describe("when not all old components have an entry", () => { - beforeEach(async () => { - subjectOldComponents = [ - setV2Setup.dai.address, - setV2Setup.wbtc.address, - setV2Setup.usdc.address, - ]; + describe("when old components array is longer than current components array", () => { + beforeEach(async () => { + const price = await priceAdapter.getEncodedData(ether(1)); + subjectOldComponents = [ + setV2Setup.dai.address, + setV2Setup.wbtc.address, + setV2Setup.weth.address, + setV2Setup.usdc.address, + ]; + subjectOldComponentsAuctionParams = [ + { + targetUnit: ether(50), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: price, + }, + { + targetUnit: bitcoin(0.01), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: price, + }, + { + targetUnit: ether(0.1), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: price, + }, + { + targetUnit: usdc(100), + priceAdapterName: "ConstantPriceAdapter", + priceAdapterConfigData: price, + }, + ]; + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith( + "Mismatch: old and current components length", + ); + }); }); - it("should revert", async () => { - await expect(subject()).to.be.revertedWith("Mismatch: old and current components"); + describe("when not all old components have an entry", () => { + beforeEach(async () => { + subjectOldComponents = [ + setV2Setup.dai.address, + setV2Setup.wbtc.address, + setV2Setup.usdc.address, + ]; + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith( + "Mismatch: old and current components", + ); + }); }); - }); - describe("when the caller is not the operator", () => { - beforeEach(async () => { - subjectCaller = await getRandomAccount(); - }); + describe("when the caller is not the operator", () => { + beforeEach(async () => { + subjectCaller = await getRandomAccount(); + }); - it("should not revert", async () => { - await expect(subject()).not.to.be.reverted; + it("should not revert", async () => { + await expect(subject()).not.to.be.reverted; + }); }); }); - }); - describe("assertionDisputedCallback", () => { - it("should delete the proposal on a disputed callback", async () => { - await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposeRebalance( - subjectQuoteAsset, - subjectOldComponents, - subjectNewComponents, - subjectNewComponentsAuctionParams, - subjectOldComponentsAuctionParams, - subjectShouldLockSetToken, - subjectRebalanceDuration, - subjectPositionMultiplier, - ); - const proposal = await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposedProduct(utils.formatBytes32String("win")); - expect(proposal.product).to.eq(setToken.address); - - await expect( - optimisticOracleV3Mock + describe("assertionDisputedCallback", () => { + it("should delete the proposal on a disputed callback", async () => { + await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .proposeRebalance( + subjectQuoteAsset, + subjectOldComponents, + subjectNewComponents, + subjectNewComponentsAuctionParams, + subjectOldComponentsAuctionParams, + subjectShouldLockSetToken, + subjectRebalanceDuration, + subjectPositionMultiplier, + ); + const proposal = await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .proposedProduct(utils.formatBytes32String("win")); + expect(proposal.product).to.eq(setToken.address); + + await expect( + optimisticOracleV3Mock + .connect(subjectCaller.wallet) + .mockAssertionDisputedCallback( + auctionRebalanceExtension.address, + utils.formatBytes32String("win"), + ), + ).to.not.be.reverted; + + const proposalAfter = await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .proposedProduct(utils.formatBytes32String("win")); + expect(proposalAfter.product).to.eq(ADDRESS_ZERO); + }); + it("should delete the proposal on a disputed callback from currently set oracle", async () => { + await auctionRebalanceExtension .connect(subjectCaller.wallet) - .mockAssertionDisputedCallback( - auctionRebalanceExtension.address, - utils.formatBytes32String("win"), + .proposeRebalance( + subjectQuoteAsset, + subjectOldComponents, + subjectNewComponents, + subjectNewComponentsAuctionParams, + subjectOldComponentsAuctionParams, + subjectShouldLockSetToken, + subjectRebalanceDuration, + subjectPositionMultiplier, + ); + await auctionRebalanceExtension.connect(operator.wallet).setProductSettings( + { + collateral: collateralAsset.address, + liveness: BigNumber.from(0), + bondAmount: BigNumber.from(0), + identifier: utils.formatBytes32String(""), + optimisticOracleV3: optimisticOracleV3MockUpgraded.address, + }, + utils.arrayify( + base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z"), ), - ).to.not.be.reverted; - - const proposalAfter = await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposedProduct(utils.formatBytes32String("win")); - expect(proposalAfter.product).to.eq(ADDRESS_ZERO); - }); - it("should delete the proposal on a disputed callback from currently set oracle", async () => { - await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposeRebalance( - subjectQuoteAsset, - subjectOldComponents, - subjectNewComponents, - subjectNewComponentsAuctionParams, - subjectOldComponentsAuctionParams, - subjectShouldLockSetToken, - subjectRebalanceDuration, - subjectPositionMultiplier, ); - await auctionRebalanceExtension.connect(operator.wallet).setProductSettings( - { - collateral: collateralAsset.address, - liveness: BigNumber.from(0), - bondAmount: BigNumber.from(0), - identifier: utils.formatBytes32String(""), - optimisticOracleV3: optimisticOracleV3MockUpgraded.address, - }, - utils.arrayify(base58ToHexString("Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z")), - ); - const proposal = await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposedProduct(utils.formatBytes32String("win")); - expect(proposal.product).to.eq(setToken.address); - await expect( - optimisticOracleV3Mock + const proposal = await auctionRebalanceExtension .connect(subjectCaller.wallet) - .mockAssertionDisputedCallback( - auctionRebalanceExtension.address, - utils.formatBytes32String("win"), - ), - ).to.not.be.reverted; - const proposalAfter = await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposedProduct(utils.formatBytes32String("win")); - expect(proposalAfter.product).to.eq(ADDRESS_ZERO); + .proposedProduct(utils.formatBytes32String("win")); + expect(proposal.product).to.eq(setToken.address); + await expect( + optimisticOracleV3Mock + .connect(subjectCaller.wallet) + .mockAssertionDisputedCallback( + auctionRebalanceExtension.address, + utils.formatBytes32String("win"), + ), + ).to.not.be.reverted; + const proposalAfter = await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .proposedProduct(utils.formatBytes32String("win")); + expect(proposalAfter.product).to.eq(ADDRESS_ZERO); + }); }); - }); - describe("assertionResolvedCallback", () => { - it("should not revert on a resolved callback", async () => { - await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .proposeRebalance( - subjectQuoteAsset, - subjectOldComponents, - subjectNewComponents, - subjectNewComponentsAuctionParams, - subjectOldComponentsAuctionParams, - subjectShouldLockSetToken, - subjectRebalanceDuration, - subjectPositionMultiplier, - ); - await expect( - optimisticOracleV3Mock + describe("assertionResolvedCallback", () => { + it("should not revert on a resolved callback", async () => { + await auctionRebalanceExtension .connect(subjectCaller.wallet) - .mockAssertionResolvedCallback( - auctionRebalanceExtension.address, - utils.formatBytes32String("win"), - true, - ), - ).to.not.be.reverted; + .proposeRebalance( + subjectQuoteAsset, + subjectOldComponents, + subjectNewComponents, + subjectNewComponentsAuctionParams, + subjectOldComponentsAuctionParams, + subjectShouldLockSetToken, + subjectRebalanceDuration, + subjectPositionMultiplier, + ); + await expect( + optimisticOracleV3Mock + .connect(subjectCaller.wallet) + .mockAssertionResolvedCallback( + auctionRebalanceExtension.address, + utils.formatBytes32String("win"), + true, + ), + ).to.not.be.reverted; + }); }); }); - }); - describe("#setRaiseTargetPercentage", () => { - let subjectRaiseTargetPercentage: BigNumber; - let subjectCaller: Account; - - beforeEach(async () => { - subjectRaiseTargetPercentage = ether(0.001); - subjectCaller = operator; - }); + describe("#setRaiseTargetPercentage", () => { + let subjectRaiseTargetPercentage: BigNumber; + let subjectCaller: Account; - async function subject(): Promise { - return await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .setRaiseTargetPercentage( subjectRaiseTargetPercentage); - } + beforeEach(async () => { + subjectRaiseTargetPercentage = ether(0.001); + subjectCaller = operator; + }); - it("should correctly set the raiseTargetPercentage", async () => { - await subject(); + async function subject(): Promise { + return await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .setRaiseTargetPercentage(subjectRaiseTargetPercentage); + } - const actualRaiseTargetPercentage = ( - await setV2Setup.auctionModule.rebalanceInfo(setToken.address) - ).raiseTargetPercentage; + it("should correctly set the raiseTargetPercentage", async () => { + await subject(); - expect(actualRaiseTargetPercentage).to.eq(subjectRaiseTargetPercentage); - }); + const actualRaiseTargetPercentage = ( + await setV2Setup.auctionModule.rebalanceInfo(setToken.address) + ).raiseTargetPercentage; - describe("when the caller is not the operator", async () => { - beforeEach(async () => { - subjectCaller = await getRandomAccount(); + expect(actualRaiseTargetPercentage).to.eq(subjectRaiseTargetPercentage); }); - it("should revert", async () => { - await expect(subject()).to.be.revertedWith("Must be operator"); + describe("when the caller is not the operator", async () => { + beforeEach(async () => { + subjectCaller = await getRandomAccount(); + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Must be operator"); + }); }); }); - }); - - describe("#setBidderStatus", () => { - let subjectBidders: Address[]; - let subjectStatuses: boolean[]; - let subjectCaller: Account; - beforeEach(async () => { - subjectBidders = [methodologist.address]; - subjectStatuses = [true]; - subjectCaller = operator; - }); + describe("#setBidderStatus", () => { + let subjectBidders: Address[]; + let subjectStatuses: boolean[]; + let subjectCaller: Account; - async function subject(): Promise { - return await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .setBidderStatus( subjectBidders, subjectStatuses); - } + beforeEach(async () => { + subjectBidders = [methodologist.address]; + subjectStatuses = [true]; + subjectCaller = operator; + }); - it("should correctly set the bidder status", async () => { - await subject(); + async function subject(): Promise { + return await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .setBidderStatus(subjectBidders, subjectStatuses); + } - const isCaller = await setV2Setup.auctionModule.isAllowedBidder( - setToken.address, - subjectBidders[0], - ); + it("should correctly set the bidder status", async () => { + await subject(); - expect(isCaller).to.be.true; - }); + const isCaller = await setV2Setup.auctionModule.isAllowedBidder( + setToken.address, + subjectBidders[0], + ); - describe("when the caller is not the operator", () => { - beforeEach(async () => { - subjectCaller = await getRandomAccount(); + expect(isCaller).to.be.true; }); - it("should revert", async () => { - await expect(subject()).to.be.revertedWith("Must be operator"); + describe("when the caller is not the operator", () => { + beforeEach(async () => { + subjectCaller = await getRandomAccount(); + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Must be operator"); + }); }); }); - }); - describe("#setAnyoneBid", () => { - let subjectStatus: boolean; - let subjectCaller: Account; + describe("#setAnyoneBid", () => { + let subjectStatus: boolean; + let subjectCaller: Account; - beforeEach(async () => { - subjectStatus = true; - subjectCaller = operator; - }); - - async function subject(): Promise { - return await auctionRebalanceExtension - .connect(subjectCaller.wallet) - .setAnyoneBid(subjectStatus); - } + beforeEach(async () => { + subjectStatus = true; + subjectCaller = operator; + }); - it("should correctly set anyone bid", async () => { - await subject(); + async function subject(): Promise { + return await auctionRebalanceExtension + .connect(subjectCaller.wallet) + .setAnyoneBid(subjectStatus); + } - const anyoneBid = await setV2Setup.auctionModule.permissionInfo(setToken.address); + it("should correctly set anyone bid", async () => { + await subject(); - expect(anyoneBid).to.be.true; - }); + const anyoneBid = await setV2Setup.auctionModule.permissionInfo(setToken.address); - describe("when the caller is not the operator", () => { - beforeEach(async () => { - subjectCaller = await getRandomAccount(); + expect(anyoneBid).to.be.true; }); - it("should revert", async () => { - await expect(subject()).to.be.revertedWith("Must be operator"); + describe("when the caller is not the operator", () => { + beforeEach(async () => { + subjectCaller = await getRandomAccount(); + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Must be operator"); + }); }); }); }); }); - }); - }); + }, + ); });