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/update-gif-20240813-1 #77

Merged
merged 6 commits into from
Aug 14, 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ node_modules
/coverage.json

# custom
deployment_state_*.json
deploy.log

/deployments

soljson*.js
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.remoteColor": "#559485",
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a"
"solidity.defaultCompiler": "localFile",
"solidity.compileUsingLocalVersion": "/workspaces/gif-next/soljson-v0.8.26+commit.8a97fa7a.js",
}
43 changes: 22 additions & 21 deletions contracts/Deployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {IRegistry} from "gif-next/contracts/registry/IRegistry.sol";
import {InstanceReader} from "gif-next/contracts/instance/InstanceReader.sol";
import {MyProduct} from "./MyProduct.sol";
import {INSTANCE} from "gif-next/contracts/type/ObjectType.sol";
import {NftId} from "gif-next/contracts/type/NftId.sol";
import {PRODUCT_OWNER_ROLE, DISTRIBUTION_OWNER_ROLE, POOL_OWNER_ROLE} from "gif-next/contracts/type/RoleId.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 {SecondsLib} from "gif-next/contracts/type/Seconds.sol";
Expand Down Expand Up @@ -62,43 +61,44 @@ contract Deployer {
// deploy token and components
usdc = new UsdcMock();

IAuthorization productAuth = new BasicProductAuthorization(string.concat("MyProduct", deploymentId));
product = MyProduct(productAddress);
product.initialize(
registryAddress,
instanceNftId,
string.concat("MyProduct", deploymentId),
address(usdc),
productAuth,
address(this)
);
instance.registerProduct(address(product));


IAuthorization distributionAuth = new BasicDistributionAuthorization(string.concat("MyDistribution", deploymentId));
distribution = MyDistribution(distributionAddress);
distribution.initialize(
registryAddress,
instanceNftId,
getProductNftId(),
distributionAuth,
address(this),
string.concat("MyDistribution", deploymentId),
address(usdc));
distribution.register();
product.registerComponent(address(distribution));


IAuthorization poolAuth = new BasicPoolAuthorization(string.concat("MyPool", deploymentId));
pool = MyPool(poolAddress);
pool.initialize(
registryAddress,
instanceNftId,
getProductNftId(),
address(usdc),
poolAuth,
address(this),
string.concat("MyPool", deploymentId)
);
pool.register();
pool.approveTokenHandler(AmountLib.max());
product.registerComponent(address(pool));
pool.approveTokenHandler(usdc, AmountLib.max());

IAuthorization productAuth = new BasicProductAuthorization(string.concat("MyProduct", deploymentId));
product = MyProduct(productAddress);
product.initialize(
registryAddress,
instanceNftId,
address(this),
string.concat("MyProduct", deploymentId),
productAuth,
address(usdc),
false,
address(pool),
address(distribution));
product.register();


// create a bundle with a coverage of 10k for 30 days
Expand Down Expand Up @@ -215,7 +215,7 @@ contract Deployer {
}

function underwritePolicy(NftId policyNftId) public {
product.collateralize(policyNftId, true, TimestampLib.blockTimestamp());
product.createPolicy(policyNftId, true, TimestampLib.blockTimestamp());
}

function getPolicyState(NftId policyNftId) public view returns (StateId) {
Expand All @@ -226,4 +226,5 @@ contract Deployer {
return instanceReader.getBalanceAmount(bundleNftId).toInt();
}


}
8 changes: 4 additions & 4 deletions contracts/MyDistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {Timestamp} from "gif-next/contracts/type/Timestamp.sol";
import {UFixed} from "gif-next/contracts/type/UFixed.sol";

contract MyDistribution is BasicDistribution {

function initialize(
address registry,
NftId instanceNftId,
NftId productNftId,
IAuthorization authorization,
address initialOwner,
address initialOwner,
string memory name,
address token
)
Expand All @@ -25,7 +25,7 @@ contract MyDistribution is BasicDistribution {
{
_initializeBasicDistribution(
registry,
instanceNftId,
productNftId,
authorization,
initialOwner,
name,
Expand Down
28 changes: 19 additions & 9 deletions contracts/MyPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ pragma solidity ^0.8.20;

import {AmountLib} from "gif-next/contracts/type/Amount.sol";
import {BasicPool} from "gif-next/contracts/pool/BasicPool.sol";
import {Fee} from "gif-next/contracts/type/Fee.sol";
import {Fee, FeeLib} from "gif-next/contracts/type/Fee.sol";
import {IAuthorization} from "gif-next/contracts/authorization/IAuthorization.sol";
import {IComponents} from "gif-next/contracts/instance/module/IComponents.sol";
import {NftId} from "gif-next/contracts/type/NftId.sol";
import {Seconds} from "gif-next/contracts/type/Timestamp.sol";
import {UFixed} from "gif-next/contracts/type/UFixed.sol";
import {UFixed, UFixedLib} from "gif-next/contracts/type/UFixed.sol";

contract MyPool is BasicPool {

function initialize(
address registry,
NftId instanceNftId,
NftId productNftId,
address token,
IAuthorization authorization,
address initialOwner,
Expand All @@ -25,10 +26,19 @@ contract MyPool is BasicPool {
{
_initializeBasicPool(
registry,
instanceNftId,
authorization,
token,
productNftId,
name,
token,
IComponents.PoolInfo({
maxBalanceAmount: AmountLib.max(),
isInterceptingBundleTransfers: false,
isProcessingConfirmedClaims: false,
isExternallyManaged: false,
isVerifyingApplications: false,
collateralizationLevel: UFixedLib.one(),
retentionLevel: UFixedLib.one()
}),
authorization,
initialOwner);
}

Expand All @@ -43,13 +53,13 @@ contract MyPool is BasicPool {
virtual
returns(NftId bundleNftId)
{
(bundleNftId,) = _createBundle(
bundleNftId = _createBundle(
owner,
fee,
AmountLib.toAmount(initialAmount),
lifetime,
filter
);
_stake(bundleNftId, AmountLib.toAmount(initialAmount));
}

}
60 changes: 42 additions & 18 deletions contracts/MyProduct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ pragma solidity ^0.8.20;
import {Amount, AmountLib} from "gif-next/contracts/type/Amount.sol";
import {BasicProduct} from "gif-next/contracts/product/BasicProduct.sol";
import {ClaimId} from "gif-next/contracts/type/ClaimId.sol";
import {Fee} from "gif-next/contracts/type/Fee.sol";
import {Fee, FeeLib} from "gif-next/contracts/type/Fee.sol";
import {IAuthorization} from "gif-next/contracts/authorization/IAuthorization.sol";
import {NftId} from "gif-next/contracts/type/NftId.sol";
import {IComponents} from "gif-next/contracts/instance/module/IComponents.sol";
import {NftId, NftIdLib} from "gif-next/contracts/type/NftId.sol";
import {PayoutId} from "gif-next/contracts/type/PayoutId.sol";
import {ReferralId} from "gif-next/contracts/type/Referral.sol";
import {RequestId} from "gif-next/contracts/type/RequestId.sol";
Expand All @@ -24,28 +25,38 @@ contract MyProduct is BasicProduct {
function initialize(
address registry,
NftId instanceNftid,
address initialOwner,
string memory name,
IAuthorization authorization,
address token,
bool isInterceptor,
address pool,
address distribution
IAuthorization authorization,
address initialOwner
)
public
virtual
initializer()
{
_initializeBasicProduct(
registry,
instanceNftid,
authorization,
initialOwner,
name,
token,
isInterceptor,
pool,
distribution);
IComponents.ProductInfo({
isProcessingFundedClaims: false,
isInterceptingPolicyTransfers: false,
hasDistribution: true,
expectedNumberOfOracles: 0,
numberOfOracles: 0,
poolNftId: NftIdLib.zero(),
distributionNftId: NftIdLib.zero(),
oracleNftId: new NftId[](0),
productFee: FeeLib.zero(),
processingFee: FeeLib.zero(),
distributionFee: FeeLib.zero(),
minDistributionOwnerFee: FeeLib.zero(),
poolFee: FeeLib.zero(),
stakingFee: FeeLib.zero(),
performanceFee: FeeLib.zero()
}),
authorization,
initialOwner);
}

function createRisk(
Expand Down Expand Up @@ -81,29 +92,42 @@ contract MyProduct is BasicProduct {
function createApplication(
address applicationOwner,
RiskId riskId,
uint256 sumInsuredAmount,
uint256 sumInsured,
Seconds lifetime,
bytes memory applicationData,
NftId bundleNftId,
ReferralId referralId
) public returns (NftId nftId) {
Amount sumInsuredAmount = AmountLib.toAmount(sumInsured);
Amount premiumAmount = calculatePremium(
sumInsuredAmount,
riskId,
lifetime,
applicationData,
bundleNftId,
referralId);

return _createApplication(
applicationOwner,
riskId,
AmountLib.toAmount(sumInsuredAmount),
sumInsuredAmount,
premiumAmount,
lifetime,
bundleNftId,
referralId,
applicationData
);
}

function collateralize(
NftId policyNftId,
function createPolicy(
NftId applicationNftId,
bool requirePremiumPayment,
Timestamp activateAt
) public {
_collateralize(policyNftId, requirePremiumPayment, activateAt);
_createPolicy(applicationNftId, activateAt);
if (requirePremiumPayment == true) {
_collectPremium(applicationNftId, activateAt);
}
}

function collectPremium(
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ out = 'artifacts_forge'
libs = ['node_modules', 'lib']
test = 'test_forge'
cache_path = 'cache_forge'
solc_version = "0.8.20"
solc_version = "0.8.26"

ffi = true

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dotEnvConfig();

const config: HardhatUserConfig = {
solidity: {
version: "0.8.20",
version: "0.8.26",
settings: {
evmVersion: 'paris',
optimizer: {
Expand Down
2 changes: 1 addition & 1 deletion lib/gif-next
Submodule gif-next updated 295 files
Loading