Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gif next update 20240829 1 #88

Merged
merged 7 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions contracts/Deployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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));
Expand All @@ -81,8 +80,7 @@ contract Deployer {
getProductNftId(),
distributionAuth,
address(this),
string.concat("MyDistribution", deploymentId),
address(usdc));
string.concat("MyDistribution", deploymentId));
product.registerComponent(address(distribution));


Expand All @@ -91,7 +89,6 @@ contract Deployer {
pool.initialize(
registryAddress,
getProductNftId(),
address(usdc),
poolAuth,
address(this),
string.concat("MyPool", deploymentId)
Expand All @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions contracts/MyDistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ contract MyDistribution is BasicDistribution {
NftId productNftId,
IAuthorization authorization,
address initialOwner,
string memory name,
address token
string memory name
)
public
virtual
Expand All @@ -28,7 +27,6 @@ contract MyDistribution is BasicDistribution {
productNftId,
authorization,
initialOwner,
name,
token);
name);
}
}
14 changes: 11 additions & 3 deletions contracts/MyPool.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -15,7 +17,6 @@ contract MyPool is BasicPool {
function initialize(
address registry,
NftId productNftId,
address token,
IAuthorization authorization,
address initialOwner,
string memory name
Expand All @@ -28,7 +29,6 @@ contract MyPool is BasicPool {
registry,
productNftId,
name,
token,
IComponents.PoolInfo({
maxBalanceAmount: AmountLib.max(),
isInterceptingBundleTransfers: false,
Expand Down Expand Up @@ -62,4 +62,12 @@ contract MyPool is BasicPool {
_stake(bundleNftId, AmountLib.toAmount(initialAmount));
}

function approveTokenHandler(IERC20Metadata token, Amount amount)
external
onlyOwner()
{
_approveTokenHandler(token, amount);
}


}
14 changes: 7 additions & 7 deletions contracts/MyProduct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ contract MyProduct is BasicProduct {
address registry,
NftId instanceNftid,
string memory name,
address token,
IAuthorization authorization,
address initialOwner
)
Expand All @@ -37,7 +36,6 @@ contract MyProduct is BasicProduct {
registry,
instanceNftid,
name,
token,
IComponents.ProductInfo({
isProcessingFundedClaims: false,
isInterceptingPolicyTransfers: false,
Expand All @@ -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(),
Expand All @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/gif-next
Submodule gif-next updated 241 files
9 changes: 3 additions & 6 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -150,8 +150,7 @@ async function deployAndRegisterDistribution(
productNftId,
authAddr,
distributionOwner,
distName,
usdcMockAddress
distName
), null, [distribution.interface]);

console.log(`Registering distribution ...`);
Expand Down Expand Up @@ -214,7 +213,6 @@ async function deployAndRegisterPool(
await executeTx(() => pool.initialize(
registryAddress,
productNftId,
usdcMockAddress,
authAddr,
poolOwner,
poolName
Expand Down Expand Up @@ -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();
Expand Down
39 changes: 12 additions & 27 deletions test_forge/TestMyProduct.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;

Expand Down Expand Up @@ -52,14 +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());

RiskId riskId = RiskIdLib.toRiskId("42x4711");
bytes memory data = "bla di blubb";
testProduct.createRisk(riskId, data);
RiskId riskId = testProduct.createRisk("Risk_42", "");

vm.stopPrank();

Expand Down Expand Up @@ -91,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");
}
Expand All @@ -120,14 +108,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();

Expand All @@ -138,8 +125,7 @@ contract TestInsuranceProduct is GifTest {
testProductNftId,
new BasicDistributionAuthorization("MyDistribution"),
distributionOwner,
"MyDistribution",
address(token)
"MyDistribution"
);
vm.stopPrank();

Expand All @@ -153,7 +139,6 @@ contract TestInsuranceProduct is GifTest {
testPool.initialize(
address(registry),
testProductNftId,
address(token),
new BasicPoolAuthorization("MyPool"),
poolOwner,
"MyPool"
Expand Down