From c248bc59129985373362a8c2e1381c25acb165bb Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 07:20:12 +0000 Subject: [PATCH 1/7] update gif-next --- lib/gif-next | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gif-next b/lib/gif-next index 9e03baf..239f4eb 160000 --- a/lib/gif-next +++ b/lib/gif-next @@ -1 +1 @@ -Subproject commit 9e03baf7b034f6614c8e76f5a1e1b8f59deb9148 +Subproject commit 239f4ebf49a27e3d7eadc1460f70f35537742e03 From b8acdad5195c42147ab9fefa6efe06e6c3d70a02 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 07:28:49 +0000 Subject: [PATCH 2/7] fix contracts --- .vscode/settings.json | 4 ++-- contracts/Deployer.sol | 13 ++++--------- contracts/MyDistribution.sol | 6 ++---- contracts/MyPool.sol | 15 ++++++++++++--- contracts/MyProduct.sol | 14 +++++++------- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2d297cb..b327fc3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,6 +19,6 @@ "titleBar.inactiveForeground": "#e7e7e799" }, "peacock.remoteColor": "#559485", - "solidity.defaultCompiler": "localFile", - "solidity.compileUsingLocalVersion": "/workspaces/gif-next/soljson-v0.8.26+commit.8a97fa7a.js", + "solidity.defaultCompiler": "localNodeModule", + "solidity.compileUsingLocalVersion": "/workspaces/gif-next-sandbox/soljson-v0.8.26+commit.8a97fa7a.js", } \ No newline at end of file diff --git a/contracts/Deployer.sol b/contracts/Deployer.sol index 95eb9a5..23cf04f 100644 --- a/contracts/Deployer.sol +++ b/contracts/Deployer.sol @@ -67,11 +67,10 @@ contract Deployer { registryAddress, instanceNftId, string.concat("MyProduct", deploymentId), - address(usdc), productAuth, address(this) ); - instance.registerProduct(address(product)); + instance.registerProduct(address(product), address(usdc)); IAuthorization distributionAuth = new BasicDistributionAuthorization(string.concat("MyDistribution", deploymentId)); @@ -81,8 +80,7 @@ contract Deployer { getProductNftId(), distributionAuth, address(this), - string.concat("MyDistribution", deploymentId), - address(usdc)); + string.concat("MyDistribution", deploymentId)); product.registerComponent(address(distribution)); @@ -91,7 +89,6 @@ contract Deployer { pool.initialize( registryAddress, getProductNftId(), - address(usdc), poolAuth, address(this), string.concat("MyPool", deploymentId) @@ -112,9 +109,8 @@ contract Deployer { ); // create risk - riskId = RiskIdLib.toRiskId("1234"); bytes memory data = "riskdata"; - product.createRisk(riskId, data); + riskId = product.createRisk("1234", data); // move ownership of instance, component and bundle nfts to instance owner chainNft.safeTransferFrom(address(this), theAllmighty, instanceNftId.toInt()); @@ -183,8 +179,7 @@ contract Deployer { } function createRisk(string memory riskIdStr, bytes memory data) public returns (RiskId riskId) { - RiskId riskId = RiskIdLib.toRiskId(riskIdStr); - product.createRisk(riskId, data); + return product.createRisk(riskIdStr, data); } function sendUsdcTokens(address recipient) public { diff --git a/contracts/MyDistribution.sol b/contracts/MyDistribution.sol index 7892cc2..9d3c32c 100644 --- a/contracts/MyDistribution.sol +++ b/contracts/MyDistribution.sol @@ -16,8 +16,7 @@ contract MyDistribution is BasicDistribution { NftId productNftId, IAuthorization authorization, address initialOwner, - string memory name, - address token + string memory name ) public virtual @@ -28,7 +27,6 @@ contract MyDistribution is BasicDistribution { productNftId, authorization, initialOwner, - name, - token); + name); } } \ No newline at end of file diff --git a/contracts/MyPool.sol b/contracts/MyPool.sol index 76cf667..a8d9ea2 100644 --- a/contracts/MyPool.sol +++ b/contracts/MyPool.sol @@ -1,7 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; -import {AmountLib} from "gif-next/contracts/type/Amount.sol"; +import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; + +import {Amount, AmountLib} from "gif-next/contracts/type/Amount.sol"; import {BasicPool} from "gif-next/contracts/pool/BasicPool.sol"; import {Fee, FeeLib} from "gif-next/contracts/type/Fee.sol"; import {IAuthorization} from "gif-next/contracts/authorization/IAuthorization.sol"; @@ -15,7 +17,6 @@ contract MyPool is BasicPool { function initialize( address registry, NftId productNftId, - address token, IAuthorization authorization, address initialOwner, string memory name @@ -28,7 +29,6 @@ contract MyPool is BasicPool { registry, productNftId, name, - token, IComponents.PoolInfo({ maxBalanceAmount: AmountLib.max(), isInterceptingBundleTransfers: false, @@ -62,4 +62,13 @@ contract MyPool is BasicPool { _stake(bundleNftId, AmountLib.toAmount(initialAmount)); } + function approveTokenHandler(IERC20Metadata token, Amount amount) + external + restricted() + onlyOwner() + { + _approveTokenHandler(token, amount); + } + + } \ No newline at end of file diff --git a/contracts/MyProduct.sol b/contracts/MyProduct.sol index 9fa2c78..7b610ce 100644 --- a/contracts/MyProduct.sol +++ b/contracts/MyProduct.sol @@ -26,7 +26,6 @@ contract MyProduct is BasicProduct { address registry, NftId instanceNftid, string memory name, - address token, IAuthorization authorization, address initialOwner ) @@ -37,7 +36,6 @@ contract MyProduct is BasicProduct { registry, instanceNftid, name, - token, IComponents.ProductInfo({ isProcessingFundedClaims: false, isInterceptingPolicyTransfers: false, @@ -46,7 +44,9 @@ contract MyProduct is BasicProduct { numberOfOracles: 0, poolNftId: NftIdLib.zero(), distributionNftId: NftIdLib.zero(), - oracleNftId: new NftId[](0), + oracleNftId: new NftId[](0) + }), + IComponents.FeeInfo({ productFee: FeeLib.zero(), processingFee: FeeLib.zero(), distributionFee: FeeLib.zero(), @@ -60,11 +60,11 @@ contract MyProduct is BasicProduct { } function createRisk( - RiskId id, + string memory id, bytes memory data - ) public { - _createRisk( - id, + ) public returns (RiskId) { + return _createRisk( + bytes32(abi.encodePacked(id)), data ); } From 9493a63d9d9db45c0eb10d7f31dfb203bbc98db2 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 08:59:59 +0000 Subject: [PATCH 3/7] update gif-next --- lib/gif-next | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gif-next b/lib/gif-next index 239f4eb..28f67b9 160000 --- a/lib/gif-next +++ b/lib/gif-next @@ -1 +1 @@ -Subproject commit 239f4ebf49a27e3d7eadc1460f70f35537742e03 +Subproject commit 28f67b912c3e0a6552335c5a293f08d457eac54f From 0406e9a13f02d1c92c0f574b4cc67172db8b3102 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 09:02:51 +0000 Subject: [PATCH 4/7] fix tests --- contracts/Deployer.sol | 2 +- contracts/MyPool.sol | 1 - test_forge/TestMyProduct.t.sol | 10 +++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/contracts/Deployer.sol b/contracts/Deployer.sol index 23cf04f..75b8293 100644 --- a/contracts/Deployer.sol +++ b/contracts/Deployer.sol @@ -52,7 +52,7 @@ contract Deployer { address theAllmighty = msg.sender; registry = IRegistry(registryAddress); IInstanceService instanceService = IInstanceService(registry.getServiceAddress(INSTANCE(), VersionPart.wrap(3))); - (instance, instanceNftId) = instanceService.createInstance(); + (instance, instanceNftId) = instanceService.createInstance(true); ChainNft chainNft = ChainNft(registry.getChainNftAddress()); instanceReader = instance.getInstanceReader(); diff --git a/contracts/MyPool.sol b/contracts/MyPool.sol index a8d9ea2..4ddb68b 100644 --- a/contracts/MyPool.sol +++ b/contracts/MyPool.sol @@ -64,7 +64,6 @@ contract MyPool is BasicPool { function approveTokenHandler(IERC20Metadata token, Amount amount) external - restricted() onlyOwner() { _approveTokenHandler(token, amount); diff --git a/test_forge/TestMyProduct.t.sol b/test_forge/TestMyProduct.t.sol index d74f50a..c03ea2f 100644 --- a/test_forge/TestMyProduct.t.sol +++ b/test_forge/TestMyProduct.t.sol @@ -57,9 +57,8 @@ contract TestInsuranceProduct is GifTest { // Fee memory productFee = FeeLib.toFee(UFixedLib.zero(), 10); // product.setFees(productFee, FeeLib.zeroFee()); - RiskId riskId = RiskIdLib.toRiskId("42x4711"); bytes memory data = "bla di blubb"; - testProduct.createRisk(riskId, data); + RiskId riskId = testProduct.createRisk("42x4711", data); vm.stopPrank(); @@ -120,14 +119,13 @@ contract TestInsuranceProduct is GifTest { address(registry), instanceNftId, "MyProduct", - address(token), new BasicProductAuthorization("MyProduct"), productOwner ); vm.stopPrank(); vm.startPrank(instanceOwner); - instance.registerProduct(address(testProduct)); + instance.registerProduct(address(testProduct), address(token)); testProductNftId = testProduct.getNftId(); vm.stopPrank(); @@ -138,8 +136,7 @@ contract TestInsuranceProduct is GifTest { testProductNftId, new BasicDistributionAuthorization("MyDistribution"), distributionOwner, - "MyDistribution", - address(token) + "MyDistribution" ); vm.stopPrank(); @@ -153,7 +150,6 @@ contract TestInsuranceProduct is GifTest { testPool.initialize( address(registry), testProductNftId, - address(token), new BasicPoolAuthorization("MyPool"), poolOwner, "MyPool" From 21bc515dfa4a7f535f9981077870c10237e386f3 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 09:05:37 +0000 Subject: [PATCH 5/7] fix deployment script --- scripts/deploy.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/deploy.ts b/scripts/deploy.ts index c55969b..bd87102 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -28,7 +28,7 @@ async function main() { const instanceService = IInstanceService__factory.connect(instanceServiceAddress!, productOwner); const instanceCreateTx = await executeTx( - async() => await instanceService.createInstance(), + async() => await instanceService.createInstance(true), "createinstance tx", [instanceService.interface]); @@ -150,8 +150,7 @@ async function deployAndRegisterDistribution( productNftId, authAddr, distributionOwner, - distName, - usdcMockAddress + distName ), null, [distribution.interface]); console.log(`Registering distribution ...`); @@ -214,7 +213,6 @@ async function deployAndRegisterPool( await executeTx(() => pool.initialize( registryAddress, productNftId, - usdcMockAddress, authAddr, poolOwner, poolName @@ -286,13 +284,12 @@ async function deployAndRegisterProduct( instanceNftId, productName, authAddr, - usdcMockAddress, productOwner ), "init product", [product.interface]); console.log(`Registering product at ${productAddress} ...`); const rcpt = await executeTx( - async () => await instance.registerProduct(productAddress), + async () => await instance.registerProduct(productAddress, usdcMockAddress), "register product", [IInstance__factory.createInterface()]); const productNftId = await product.getNftId(); From 268de2b28edb39a2c02ab28b3d0411e79c54d9bc Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 09:08:31 +0000 Subject: [PATCH 6/7] update docs --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fed1c06..58be431 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,10 @@ The deployer contract requires the following parameters: During the deployment the contract will - create a new instance on the GIF framework -- deploy a mock USDC token -- initialize the components `MyDistribution`, `MyPool` and `MyProduct` and register them with the new instance +- deploy a mock USDC token (and register it with the tokenregistry if not already done and instance has not disabled token registry) +- deploy the components `MyDistribution`, `MyPool` and `MyProduct` +- register `MyProduct` with the instance +- register the components on the product - create a new bundle in the pool with a coverage amount of 10000 USDC - a new riskId for creating new policies - transfer the ownership of the instance, components and bundle to the caller of the deployment From 11db0e6f30ef841cbb5a52d79f15bb6e668b3f46 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 29 Aug 2024 09:22:41 +0000 Subject: [PATCH 7/7] fix test --- test_forge/TestMyProduct.t.sol | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/test_forge/TestMyProduct.t.sol b/test_forge/TestMyProduct.t.sol index c03ea2f..4ed9977 100644 --- a/test_forge/TestMyProduct.t.sol +++ b/test_forge/TestMyProduct.t.sol @@ -8,7 +8,7 @@ import {IComponents} from "gif-next/contracts/instance/module/IComponents.sol"; import {IPolicy} from "gif-next/contracts/instance/module/IPolicy.sol"; import {NftId, NftIdLib} from "gif-next/contracts/type/NftId.sol"; import {ReferralLib} from "gif-next/contracts/type/Referral.sol"; -import {RiskId, RiskIdLib} from "gif-next/contracts/type/RiskId.sol"; +import {RiskId} from "gif-next/contracts/type/RiskId.sol"; import {Seconds, SecondsLib} from "gif-next/contracts/type/Seconds.sol"; import {GifTest} from "gif-next/test/base/GifTest.sol"; import {TimestampLib} from "gif-next/contracts/type/Timestamp.sol"; @@ -23,7 +23,7 @@ import {MyPool} from "../contracts/MyPool.sol"; import {MyProduct} from "../contracts/MyProduct.sol"; - +// solhint-disable func-name-mixedcase contract TestInsuranceProduct is GifTest { using NftIdLib for NftId; @@ -52,13 +52,7 @@ contract TestInsuranceProduct is GifTest { _prepareTestInsuranceProduct(); vm.startPrank(productOwner); - - // TODO: fix this - // Fee memory productFee = FeeLib.toFee(UFixedLib.zero(), 10); - // product.setFees(productFee, FeeLib.zeroFee()); - - bytes memory data = "bla di blubb"; - RiskId riskId = testProduct.createRisk("42x4711", data); + RiskId riskId = testProduct.createRisk("Risk_42", ""); vm.stopPrank(); @@ -90,23 +84,18 @@ contract TestInsuranceProduct is GifTest { // THEN assertTrue(instanceReader.getPolicyState(policyNftId) == COLLATERALIZED(), "policy state not COLLATERALIZED"); - // TODO: fix this - // IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId); - // assertEq(bundleInfo.lockedAmount.toInt(), 1000, "lockedAmount not 1000"); - // assertEq(bundleInfo.feeAmount.toInt(), 10, "feeAmount not 10"); - // assertEq(bundleInfo.capitalAmount.toInt(), 10000 + 100 - 10, "capitalAmount not 1100"); - + assertEq(instanceReader.getLockedAmount(bundleNftId).toInt(), 1000, "lockedAmount not 1000"); + assertEq(instanceReader.getFeeAmount(bundleNftId).toInt(), 10, "feeAmount not 10"); + assertEq(instanceReader.getBalanceAmount(bundleNftId).toInt(), 10000 + 100 + 10, "balance not 1100"); + + assertEq(token.balanceOf(address(customer)), 890, "customer balance not 880"); + assertEq(token.balanceOf(testPool.getWallet()), 10110, "pool balance not 10100"); + IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId); assertTrue(policyInfo.activatedAt.gtz(), "activatedAt not set"); assertTrue(policyInfo.expiredAt.gtz(), "expiredAt not set"); assertTrue(policyInfo.expiredAt.toInt() == policyInfo.activatedAt.addSeconds(sec30).toInt(), "expiredAt not activatedAt + 30"); - // TODO: fix this - // assertEq(token.balanceOf(testPproduct.getWallet()), 10, "product balance not 10"); - // assertEq(token.balanceOf(testDistribution.getWallet()), 10, "distibution balance not 10"); - // assertEq(token.balanceOf(address(customer)), 880, "customer balance not 880"); - // assertEq(token.balanceOf(testPool.getWallet()), 10100, "pool balance not 10100"); - assertEq(instanceBundleSet.activePolicies(bundleNftId), 1, "expected one active policy"); assertTrue(instanceBundleSet.getActivePolicy(bundleNftId, 0).eq(policyNftId), "active policy nft id in bundle manager not equal to policy nft id"); }