Skip to content

Commit

Permalink
Deploy voucher proxy from protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
zajck committed Jul 4, 2023
1 parent c992439 commit ec4a4a1
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 71 deletions.
1 change: 1 addition & 0 deletions contracts/domain/BosonConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ string constant ESCALATION_NOT_ALLOWED = "Disputes without dispute resolver cann
// Revert Reasons: Config related
string constant FEE_PERCENTAGE_INVALID = "Percentage representation must be less than 10000";
string constant VALUE_ZERO_NOT_ALLOWED = "Value must be greater than 0";
bytes32 constant VOUCHER_PROXY_SALT = keccak256(abi.encodePacked("BosonVoucherProxy"));

// EIP712Lib
string constant PROTOCOL_NAME = "Boson Protocol";
Expand Down
9 changes: 1 addition & 8 deletions contracts/protocol/bases/SellerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,7 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {
storeSeller(_seller, _authToken, lookups);

// Create clone and store its address cloneAddress
address voucherCloneAddress = cloneBosonVoucher(
sellerId,
0,
_seller.admin,
_seller.assistant,
_voucherInitValues,
""
);
address voucherCloneAddress = cloneBosonVoucher(sellerId, 0, sender, _seller.assistant, _voucherInitValues, "");
lookups.cloneAddress[sellerId] = voucherCloneAddress;

// Notify watchers of state change
Expand Down
7 changes: 6 additions & 1 deletion contracts/protocol/facets/ConfigHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DiamondLib } from "../../diamond/DiamondLib.sol";
import { ProtocolBase } from "../bases/ProtocolBase.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { EIP712Lib } from "../libs/EIP712Lib.sol";
import { BeaconClientProxy } from "../../protocol/clients/proxy/BeaconClientProxy.sol";

/**
* @title ConfigHandlerFacet
Expand All @@ -32,10 +33,10 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase {
DiamondLib.addSupportedInterface(type(IBosonConfigHandler).interfaceId);

// Initialize protocol config params
// _addresses.beaconProxy is ignored, since it's deployed later in this function
setTokenAddress(_addresses.token);
setTreasuryAddress(_addresses.treasury);
setVoucherBeaconAddress(_addresses.voucherBeacon);
setBeaconProxyAddress(_addresses.beaconProxy);
setProtocolFeePercentage(_fees.percentage);
setProtocolFeeFlatBoson(_fees.flatBoson);
setMaxExchangesPerBatch(_limits.maxExchangesPerBatch);
Expand Down Expand Up @@ -71,6 +72,10 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase {
ProtocolLib.ProtocolMetaTxInfo storage pmti = protocolMetaTxInfo();
pmti.domainSeparator = EIP712Lib.buildDomainSeparator(PROTOCOL_NAME, PROTOCOL_VERSION);
pmti.cachedChainId = block.chainid;

// Deploy Boson Voucher proxy contract
address beaconProxy = address(new BeaconClientProxy{ salt: VOUCHER_PROXY_SALT }());
setBeaconProxyAddress(beaconProxy);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IBosonProtocolInitializationHandler } from "../../interfaces/handlers/I
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { ProtocolBase } from "../bases/ProtocolBase.sol";
import { DiamondLib } from "../../diamond/DiamondLib.sol";
import { BeaconClientProxy } from "../../protocol/clients/proxy/BeaconClientProxy.sol";

/**
* @title BosonProtocolInitializationHandler
Expand Down Expand Up @@ -153,6 +154,9 @@ contract ProtocolInitializationHandlerFacet is IBosonProtocolInitializationHandl

lookups.sellerCreator[sellerIds[i]] = sellerCreators[i];
}

// Deploy a new voucher proxy
protocolAddresses().beaconProxy = address(new BeaconClientProxy{ salt: VOUCHER_PROXY_SALT }());
}

/**
Expand Down
6 changes: 0 additions & 6 deletions scripts/deploy-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ async function main(env, facetConfig) {
);
await transactionResponse.wait(confirmations);

transactionResponse = await bosonConfigHandler.setBeaconProxyAddress(
bosonVoucherProxy.address,
await getFees(maxPriorityFeePerGas)
);
await transactionResponse.wait(confirmations);

// Add NFT auth token addresses to protocol config
// LENS
transactionResponse = await bosonConfigHandler.setAuthTokenContract(
Expand Down
2 changes: 1 addition & 1 deletion scripts/util/deploy-protocol-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function deployProtocolClients(
// Deploy Protocol Client proxy contracts
const protocolClientProxies = await deployProtocolClientProxies(protocolClientBeacons, maxPriorityFeePerGas);

// Cast the proxies to their implementation interfaces
// Cast the proxies to their implementation interfaces ?? ToDo: what is this even needed?
const protocolClients = await castProtocolClientProxies(protocolClientProxies);

return [protocolClientImpls, protocolClientBeacons, protocolClientProxies, protocolClients];
Expand Down
9 changes: 6 additions & 3 deletions test/integration/01-update-account-roles-addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { oneMonth } = require("../util/constants");
const {
setNextBlockTimestamp,
calculateCloneAddress,
calculateBosonProxyAddress,
prepareDataSignatureParameters,
applyPercentage,
setupTestEnvironment,
Expand Down Expand Up @@ -48,19 +49,21 @@ describe("[@skip-on-coverage] Update account roles addresses", function () {
disputeHandler: "IBosonDisputeHandler",
};

let protocolDiamondAddress;
({
diamondAddress: protocolDiamondAddress,
signers: [admin, treasury, buyer, rando, adminDR, treasuryDR, agent],
contractInstances: { accountHandler, offerHandler, exchangeHandler, fundsHandler, disputeHandler },
protocolConfig: [, , { buyerEscalationDepositPercentage }],
extraReturnValues: {
proxy: { address: beaconProxyAddress },
},
} = await setupTestEnvironment(contracts));

// make all account the same
assistant = clerk = admin;
assistantDR = clerkDR = adminDR;

// Get the beacon proxy address
beaconProxyAddress = await calculateBosonProxyAddress(protocolDiamondAddress);

// Get snapshot id
snapshotId = await getSnapshot();
});
Expand Down
8 changes: 4 additions & 4 deletions test/integration/04-DR-removes-fees.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { DisputeResolverFee } = require("../../scripts/domain/DisputeResolverFee"
const {
setNextBlockTimestamp,
calculateCloneAddress,
calculateBosonProxyAddress,
applyPercentage,
setupTestEnvironment,
getSnapshot,
Expand All @@ -35,7 +36,6 @@ describe("[@skip-on-coverage] DR removes fee", function () {
let exchangeId;
let disputeResolverFeeNative;
let snapshotId;
let beaconProxyAddress;

before(async function () {
accountId.next(true);
Expand All @@ -49,19 +49,19 @@ describe("[@skip-on-coverage] DR removes fee", function () {
disputeHandler: "IBosonDisputeHandler",
};

let protocolDiamondAddress;
({
diamondAddress: protocolDiamondAddress,
signers: [admin, treasury, buyer, adminDR, treasuryDR],
contractInstances: { accountHandler, offerHandler, exchangeHandler, fundsHandler, disputeHandler },
protocolConfig: [, , { buyerEscalationDepositPercentage }],
extraReturnValues: {
proxy: { address: beaconProxyAddress },
},
} = await setupTestEnvironment(contracts));

// make all account the same
assistant = clerk = admin;
assistantDR = clerkDR = adminDR;

const beaconProxyAddress = await calculateBosonProxyAddress(protocolDiamondAddress);
expectedCloneAddress = calculateCloneAddress(accountHandler.address, beaconProxyAddress, admin.address, "");
emptyAuthToken = mockAuthToken();
expect(emptyAuthToken.isValid()).is.true;
Expand Down
13 changes: 8 additions & 5 deletions test/protocol/BuyerHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const Buyer = require("../../scripts/domain/Buyer");
const { DisputeResolverFee } = require("../../scripts/domain/DisputeResolverFee");
const PausableRegion = require("../../scripts/domain/PausableRegion.js");
const { RevertReasons } = require("../../scripts/config/revert-reasons.js");
const { calculateCloneAddress, setupTestEnvironment, getSnapshot, revertToSnapshot } = require("../util/utils.js");
const {
calculateCloneAddress,
calculateBosonProxyAddress,
setupTestEnvironment,
getSnapshot,
revertToSnapshot,
} = require("../util/utils.js");
const {
mockOffer,
mockSeller,
Expand Down Expand Up @@ -34,7 +40,6 @@ describe("BuyerHandler", function () {
let bosonVoucher;
let voucherInitValues;
let snapshotId;
let beaconProxyAddress;

before(async function () {
accountId.next(true);
Expand All @@ -51,9 +56,6 @@ describe("BuyerHandler", function () {
({
signers: [pauser, admin, treasury, rando, other1, other2, other3, other4],
contractInstances: { accountHandler, offerHandler, exchangeHandler, fundsHandler, pauseHandler },
extraReturnValues: {
proxy: { address: beaconProxyAddress },
},
} = await setupTestEnvironment(contracts));

// make all account the same
Expand Down Expand Up @@ -395,6 +397,7 @@ describe("BuyerHandler", function () {
//Commit to offer
await exchangeHandler.connect(other1).commitToOffer(other1.address, offerId, { value: offer.price });

const beaconProxyAddress = await calculateBosonProxyAddress(accountHandler.address);
const bosonVoucherCloneAddress = calculateCloneAddress(
accountHandler.address,
beaconProxyAddress,
Expand Down
24 changes: 14 additions & 10 deletions test/protocol/ConfigHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { RevertReasons } = require("../../scripts/config/revert-reasons.js");
const { deployProtocolDiamond } = require("../../scripts/util/deploy-protocol-diamond.js");
const { oneWeek, oneMonth, maxPriorityFeePerGas } = require("../util/constants");
const AuthTokenType = require("../../scripts/domain/AuthTokenType");
const { getFacetsWithArgs, getSnapshot, revertToSnapshot } = require("../util/utils");
const { getFacetsWithArgs, getSnapshot, revertToSnapshot, calculateBosonProxyAddress } = require("../util/utils");
const { deployAndCutFacets } = require("../../scripts/util/deploy-protocol-handler-facets.js");

/**
Expand All @@ -16,7 +16,7 @@ const { deployAndCutFacets } = require("../../scripts/util/deploy-protocol-handl
describe("IBosonConfigHandler", function () {
// Common vars
let InterfaceIds, support;
let accounts, deployer, rando, token, treasury, beacon, proxy;
let accounts, deployer, rando, token, treasury, beacon;
let maxOffersPerGroup,
maxTwinsPerBundle,
maxOffersPerBundle,
Expand All @@ -43,7 +43,7 @@ describe("IBosonConfigHandler", function () {

// Make accounts available
accounts = await ethers.getSigners();
[deployer, rando, token, treasury, beacon, proxy] = accounts;
[deployer, rando, token, treasury, beacon] = accounts;

// Deploy the Protocol Diamond
[protocolDiamond, , , , accessController] = await deployProtocolDiamond(maxPriorityFeePerGas);
Expand Down Expand Up @@ -89,13 +89,15 @@ describe("IBosonConfigHandler", function () {
describe("Deploy tests", async function () {
context("📋 Initializer", async function () {
it("should initialize the config handler and emit set events", async function () {
const proxyAddress = await calculateBosonProxyAddress(protocolDiamond.address);

const protocolConfig = [
// Protocol addresses
{
token: token.address,
treasury: treasury.address,
voucherBeacon: beacon.address,
beaconProxy: proxy.address,
beaconProxy: ethers.constants.AddressZero,
},
// Protocol limits
{
Expand Down Expand Up @@ -148,7 +150,7 @@ describe("IBosonConfigHandler", function () {

await expect(cutTransaction)
.to.emit(configHandler, "BeaconProxyAddressChanged")
.withArgs(proxy.address, deployer.address);
.withArgs(proxyAddress, deployer.address);

await expect(cutTransaction)
.to.emit(configHandler, "ProtocolFeePercentageChanged")
Expand Down Expand Up @@ -230,7 +232,7 @@ describe("IBosonConfigHandler", function () {
treasury: treasury.address,
token: token.address,
voucherBeacon: beacon.address,
beaconProxy: proxy.address,
beaconProxy: ethers.constants.AddressZero,
},
// Protocol limits
{
Expand Down Expand Up @@ -607,7 +609,7 @@ describe("IBosonConfigHandler", function () {
proxy = accounts[9];
});

it("should emit a VoucherAddressChanged event", async function () {
it("should emit a BeaconProxyAddressChanged event", async function () {
// Set new proxy address, testing for the event
await expect(configHandler.connect(deployer).setBeaconProxyAddress(proxy.address))
.to.emit(configHandler, "BeaconProxyAddressChanged")
Expand Down Expand Up @@ -1269,11 +1271,13 @@ describe("IBosonConfigHandler", function () {
expect(await configHandler.connect(rando).getTokenAddress()).to.equal(token.address, "Invalid token address");
expect(await configHandler.connect(rando).getVoucherBeaconAddress()).to.equal(
beacon.address,
"Invalid voucher address"
"Invalid voucher beacon address"
);

const proxyAddress = await calculateBosonProxyAddress(protocolDiamond.address);
expect(await configHandler.connect(rando).getBeaconProxyAddress()).to.equal(
proxy.address,
"Invalid voucher address"
proxyAddress,
"Invalid voucher proxy address"
);
expect(await configHandler.connect(rando).getProtocolFeePercentage()).to.equal(
protocolFeePercentage,
Expand Down
11 changes: 5 additions & 6 deletions test/protocol/ExchangeHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const {
calculateVoucherExpiry,
prepareDataSignatureParameters,
calculateCloneAddress,
calculateBosonProxyAddress,
applyPercentage,
deriveTokenId,
setupTestEnvironment,
Expand Down Expand Up @@ -145,12 +146,7 @@ describe("IBosonExchangeHandler", function () {
configHandler,
},
protocolConfig: [, , { percentage: protocolFeePercentage }],
extraReturnValues: {
bosonVoucher,
voucherImplementation,
accessController,
proxy: { address: beaconProxyAddress },
},
extraReturnValues: { bosonVoucher, voucherImplementation, accessController },
diamondAddress: protocolDiamondAddress,
} = await setupTestEnvironment(contracts));

Expand All @@ -163,6 +159,9 @@ describe("IBosonExchangeHandler", function () {
// Deploy the mock tokens
[foreign20, foreign721, foreign1155] = await deployMockTokens(["Foreign20", "Foreign721", "Foreign1155"]);

// Get the beacon proxy address
beaconProxyAddress = await calculateBosonProxyAddress(configHandler.address);

// Get snapshot id
snapshotId = await getSnapshot();
});
Expand Down
9 changes: 5 additions & 4 deletions test/protocol/FundsHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
prepareDataSignatureParameters,
applyPercentage,
calculateCloneAddress,
calculateBosonProxyAddress,
setupTestEnvironment,
getSnapshot,
revertToSnapshot,
Expand Down Expand Up @@ -130,10 +131,7 @@ describe("IBosonFundsHandler", function () {
},
protocolConfig: [, , { percentage: protocolFeePercentage, buyerEscalationDepositPercentage }],
diamondAddress: protocolDiamondAddress,
extraReturnValues: {
accessController,
proxy: { address: beaconProxyAddress },
},
extraReturnValues: { accessController },
} = await setupTestEnvironment(contracts));

// make all account the same
Expand All @@ -145,6 +143,9 @@ describe("IBosonFundsHandler", function () {
// Deploy the mock token
[mockToken] = await deployMockTokens(["Foreign20"]);

// Get the beacon proxy address
beaconProxyAddress = await calculateBosonProxyAddress(configHandler.address);

// Get snapshot id
snapshotId = await getSnapshot();
});
Expand Down
7 changes: 4 additions & 3 deletions test/protocol/OfferHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { deployMockTokens } = require("../../scripts/util/deploy-mock-tokens");
const {
applyPercentage,
calculateCloneAddress,
calculateBosonProxyAddress,
setupTestEnvironment,
getSnapshot,
revertToSnapshot,
Expand Down Expand Up @@ -126,16 +127,16 @@ describe("IBosonOfferHandler", function () {
,
{ percentage: protocolFeePercentage, flatBoson: protocolFeeFlatBoson, buyerEscalationDepositPercentage },
],
extraReturnValues: {
proxy: { address: beaconProxyAddress },
},
} = await setupTestEnvironment(contracts, { bosonTokenAddress: bosonToken.address }));

// make all account the same
assistant = clerk = admin;
assistantDR = clerkDR = adminDR;
[deployer] = await ethers.getSigners();

// Get the beacon proxy address
beaconProxyAddress = await calculateBosonProxyAddress(configHandler.address);

// Get snapshot id
snapshotId = await getSnapshot();
});
Expand Down
Loading

0 comments on commit ec4a4a1

Please sign in to comment.