Skip to content

Commit

Permalink
remove upgradeability from FlightProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Oct 9, 2024
1 parent ae93035 commit e0ca318
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 76 deletions.
67 changes: 23 additions & 44 deletions contracts/examples/flight/FlightProduct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ import {RequestId} from "../../type/RequestId.sol";
import {Seconds, SecondsLib} from "../../type/Seconds.sol";
import {Str} from "../../type/String.sol";
import {Timestamp, TimestampLib} from "../../type/Timestamp.sol";
import {Version, VersionLib} from "../../type/Version.sol";
import {Versionable} from "../../upgradeability/Versionable.sol";


/// @dev FlightProduct implements the flight delay product.
contract FlightProduct is
Versionable,
Product
{

Expand Down Expand Up @@ -112,27 +109,24 @@ contract FlightProduct is
}


// constructor(
// address registry,
// NftId instanceNftId,
// string memory componentName,
// IAuthorization authorization
// )
// {
// address initialOwner = msg.sender;

// _initialize(
// registry,
// instanceNftId,
// componentName,
// authorization,
// initialOwner);
// }

function getVersion() public pure virtual override (Component, Versionable) returns(Version) {
return VersionLib.toVersion(1, 0, 0);
constructor(
address registry,
NftId instanceNftId,
string memory componentName,
IAuthorization authorization
)
{
address initialOwner = msg.sender;

_initialize(
registry,
instanceNftId,
componentName,
authorization,
initialOwner);
}


//--- external functions ------------------------------------------------//
//--- unpermissioned functions ------------------------------------------//

Expand Down Expand Up @@ -620,31 +614,16 @@ contract FlightProduct is
}


// function _initialize(
// address registry,
// NftId instanceNftId,
// string memory componentName,
// IAuthorization authorization,
// address initialOwner
// )
// internal
// initializer

function _initialize(
address initialOwner,
bytes memory data
)
address registry,
NftId instanceNftId,
string memory componentName,
IAuthorization authorization,
address initialOwner
)
internal
onlyInitializing()
virtual override
initializer()
{
(
address registry,
NftId instanceNftId,
string memory componentName,
IAuthorization authorization
) = abi.decode(data, (address, NftId, string, IAuthorization));

__Product_init(
registry,
instanceNftId,
Expand Down
28 changes: 14 additions & 14 deletions contracts/examples/flight/FlightProductManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ contract FlightProductManager is ProxyManager {
IAuthorization authorization
)
{
FlightProduct prd = new FlightProduct{salt: _salt}();
bytes memory data = abi.encode(
registry,
instanceNftId,
componentName,
authorization);

IVersionable versionable = initialize(
registry,
address(prd),
data,
_salt);

_flightProduct = FlightProduct(address(versionable));
// FlightProduct prd = new FlightProduct{salt: _salt}();
// bytes memory data = abi.encode(
// registry,
// instanceNftId,
// componentName,
// authorization);

// IVersionable versionable = initialize(
// registry,
// address(prd),
// data,
// _salt);

// _flightProduct = FlightProduct(address(versionable));
}

//--- view functions ----------------------------------------------------//
Expand Down
14 changes: 10 additions & 4 deletions contracts/instance/InstanceReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {RiskId} from "../type/RiskId.sol";
import {RiskSet} from "./RiskSet.sol";
import {RoleId, INSTANCE_OWNER_ROLE} from "../type/RoleId.sol";
import {StateId} from "../type/StateId.sol";
import {Str, StrLib} from "../type/String.sol";
import {TokenHandler} from "../shared/TokenHandler.sol";
import {UFixed, UFixedLib} from "../type/UFixed.sol";

Expand Down Expand Up @@ -601,13 +602,18 @@ contract InstanceReader {
}


function toUFixed(uint256 value, int8 exp) public pure returns (UFixed) {
return UFixedLib.toUFixed(value, exp);
function toInt(UFixed value) public pure returns (uint256) {
return UFixedLib.toInt(value);
}


function toInt(UFixed value) public pure returns (uint256) {
return UFixedLib.toInt(value);
function toString(Str str) public pure returns (string memory) {
return StrLib.toString(str);
}


function toUFixed(uint256 value, int8 exp) public pure returns (UFixed) {
return UFixedLib.toUFixed(value, exp);
}

//--- internal functions ----------------------------------------------------//
Expand Down
29 changes: 27 additions & 2 deletions scripts/deploy_flightdelay_components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export async function deployFlightDelayComponentContracts(libraries: LibraryAddr
ObjectTypeLib: objectTypeLibAddress,
ReferralLib: referralLibAddress,
SecondsLib: secondsLibAddress,
StrLib: strLibAddress,
TimestampLib: timestampLibAddress,
VersionLib: versionLibAddress,
}
Expand All @@ -209,9 +210,31 @@ export async function deployFlightDelayComponentContracts(libraries: LibraryAddr
[IInstance__factory.createInterface()]
);
const flightProductNftId = await flightProduct.getNftId();

// // grant statistics provider role to statistics provider
// (RoleId statisticProviderRoleId, bool exists) = instanceReader.getRoleForName(
// productAuthz.STATISTICS_PROVIDER_ROLE_NAME());

// instance.grantRole(statisticProviderRoleId, statisticsProvider);
// vm.stopPrank();

// old function
// await executeTx(async () =>
// await flightProduct.completeSetup(),
// "fd - completeSetup",
// [FlightProduct__factory.createInterface()]
// );
await executeTx(async () =>
await flightProduct.completeSetup(),
"fd - completeSetup",
await flightProduct.setConstants(
15 * 10 ** 6, // 15 USD min premium
15 * 10 ** 6, // 15 USD max premium
200 * 10 ** 6, // 15 USD max premium
600 * 10 ** 6, // 15 USD max premium
14 * 24 * 3600, // 14 days min time before departure
90 * 24 * 3600, // 90 days max time before departure
5, // max policies to process in one tx
),
"fd - setConstants",
[FlightProduct__factory.createInterface()]
);

Expand Down Expand Up @@ -305,6 +328,8 @@ export async function deployFlightDelayComponentContracts(libraries: LibraryAddr
ContractLib: contractLibAddress,
NftIdLib: nftIdLibAddress,
LibRequestIdSet: libRequestIdSetAddress,
StrLib: strLibAddress,
TimestampLib: timestampLibAddress,
VersionLib: versionLibAddress,
}
});
Expand Down
1 change: 1 addition & 0 deletions scripts/libs/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export async function deployAndRegisterMasterInstance(
RequestIdLib: libraries.requestIdLibAddress,
RiskIdLib: libraries.riskIdLibAddress,
RoleIdLib: libraries.roleIdLibAddress,
StrLib: libraries.strLibAddress,
UFixedLib: libraries.uFixedLibAddress,
}
}
Expand Down
22 changes: 10 additions & 12 deletions test/examples/flight/FlightBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {FlightOracleAuthorization} from "../../../contracts/examples/flight/Flig
import {FlightPool} from "../../../contracts/examples/flight/FlightPool.sol";
import {FlightPoolAuthorization} from "../../../contracts/examples/flight/FlightPoolAuthorization.sol";
import {FlightProduct} from "../../../contracts/examples/flight/FlightProduct.sol";
import {FlightProductManager} from "../../../contracts/examples/flight/FlightProductManager.sol";
import {FlightProductAuthorization} from "../../../contracts/examples/flight/FlightProductAuthorization.sol";
import {FlightUSD} from "../../../contracts/examples/flight/FlightUSD.sol";
import {GifTest} from "../../base/GifTest.sol";
Expand All @@ -39,7 +38,6 @@ contract FlightBaseTest is GifTest {
FlightOracle public flightOracle;
FlightPool public flightPool;

FlightProductManager public flightProductManager;
FlightProduct public flightProduct;

NftId public flightOracleNftId;
Expand Down Expand Up @@ -185,20 +183,20 @@ contract FlightBaseTest is GifTest {

vm.startPrank(flightOwner);
FlightProductAuthorization productAuthz = new FlightProductAuthorization("FlightProduct");
// flightProduct = new FlightProduct(
// address(registry),
// instanceNftId,
// "FlightProduct",
// productAuthz
// );

flightProductManager = new FlightProductManager(
flightProduct = new FlightProduct(
address(registry),
instanceNftId,
"FlightProduct",
productAuthz);
productAuthz
);

// flightProductManager = new FlightProductManager(
// address(registry),
// instanceNftId,
// "FlightProduct",
// productAuthz);

flightProduct = flightProductManager.getFlightProduct();
// flightProduct = flightProductManager.getFlightProduct();

vm.stopPrank();

Expand Down

0 comments on commit e0ca318

Please sign in to comment.