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/crop insurance #827

Merged
merged 8 commits into from
Dec 20, 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 .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ services:
dockerfile: .devcontainer/Dockerfile.anvil
volumes:
- anvil-state:/anvil
# ports:
# - "7545:7545"
ports:
- "7545:7545"
contracts:
# See https://aka.ms/vscode-remote/containers/non-root for details.
user: node
Expand Down
26 changes: 26 additions & 0 deletions contracts/examples/crop/AccountingToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/// @dev FireUSD is a stablecoin with 6 decimals and an initial supply of 1 Billion tokens.
contract AccountingToken is ERC20 {

string public constant NAME = "Local Currency (Accounting Token)";
string public constant SYMBOL = "LCA";
uint8 public constant DECIMALS = 6;
uint256 public constant INITIAL_SUPPLY = 10**12 * 10**DECIMALS;

constructor()
ERC20(NAME, SYMBOL)
{
_mint(
_msgSender(),
INITIAL_SUPPLY
);
}

function decimals() public pure override returns(uint8) {
return DECIMALS;
}
}
89 changes: 89 additions & 0 deletions contracts/examples/crop/CropPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import {IAuthorization} from "../../authorization/IAuthorization.sol";
import {IComponents} from "../../instance/module/IComponents.sol";

import {Amount, AmountLib} from "../../type/Amount.sol";
import {BasicPool} from "../../pool/BasicPool.sol";
import {FeeLib} from "../../type/Fee.sol";
import {NftId} from "../../type/NftId.sol";
import {SecondsLib} from "../../type/Seconds.sol";
import {UFixedLib} from "../../type/UFixed.sol";


/// @dev CropPool implements the pool for the crop product.
/// Only the pool owner is allowed to create and manage bundles.
contract CropPool is
BasicPool
{
constructor(
address registry,
NftId productNftId,
string memory componentName,
IAuthorization authorization
)
{
address initialOwner = msg.sender;
_intialize(
registry,
productNftId,
componentName,
IComponents.PoolInfo({
maxBalanceAmount: AmountLib.max(),
isInterceptingBundleTransfers: false,
isProcessingConfirmedClaims: false,
isExternallyManaged: false,
isVerifyingApplications: false,
collateralizationLevel: UFixedLib.one(),
retentionLevel: UFixedLib.one()
}),
authorization,
initialOwner);
}

function _intialize(
address registry,
NftId productNftId,
string memory componentName,
IComponents.PoolInfo memory poolInfo,
IAuthorization authorization,
address initialOwner
)
internal
initializer
{
_initializeBasicPool(
registry,
productNftId,
componentName,
poolInfo,
authorization,
initialOwner);
}

function createBundle(
Amount initialAmount
)
external
virtual
restricted()
onlyOwner()
returns(NftId bundleNftId)
{
address owner = msg.sender;
bundleNftId = _createBundle(
owner,
FeeLib.zero(),
SecondsLib.fromDays(90),
"" // filter
);

_stake(bundleNftId, initialAmount);
}

function approveTokenHandler(IERC20Metadata token, Amount amount) external restricted() onlyOwner() { _approveTokenHandler(token, amount); }
function setWallet(address newWallet) external restricted() onlyOwner() { _setWallet(newWallet); }
}
37 changes: 37 additions & 0 deletions contracts/examples/crop/CropPoolAuthorization.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {IAccess} from "../../../contracts/authorization/IAccess.sol";

import {BasicPoolAuthorization} from "../../pool/BasicPoolAuthorization.sol";
import {CropPool} from "./CropPool.sol";
import {PUBLIC_ROLE} from "../../../contracts/type/RoleId.sol";

contract CropPoolAuthorization
is BasicPoolAuthorization
{

constructor(string memory poolName)
BasicPoolAuthorization(poolName)
{}


function _setupTargetAuthorizations()
internal
virtual override
{
super._setupTargetAuthorizations();
IAccess.FunctionInfo[] storage functions;

// authorize public role (also protected by onlyOwner)
functions = _authorizeForTarget(getMainTargetName(), PUBLIC_ROLE());

// only owner
_authorize(functions, CropPool.createBundle.selector, "createBundle");
_authorize(functions, CropPool.approveTokenHandler.selector, "approveTokenHandler");
_authorize(functions, CropPool.setWallet.selector, "setWallet");
}
}

Loading
Loading