Skip to content

Commit

Permalink
run forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Dec 23, 2024
1 parent 30b653f commit 42daa56
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cache/solidity-files-cache.json

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions src/AccountingToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,45 @@
pragma solidity ^0.8.20;

contract AccountingToken {

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;
uint256 public constant INITIAL_SUPPLY = 10 ** 12 * 10 ** DECIMALS;

mapping(address => uint256) internal _balanceOf;
mapping(address => mapping(address => uint256)) internal _allowance;

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

constructor() {
_balanceOf[msg.sender] = INITIAL_SUPPLY;
emit Transfer(address(0), msg.sender, INITIAL_SUPPLY);
}

function totalSupply() external view returns (uint256) { return INITIAL_SUPPLY; }
function totalSupply() external view returns (uint256) {
return INITIAL_SUPPLY;
}

function balanceOf(address account) external view returns (uint256) {
function balanceOf(address account) external view returns (uint256) {
return _balanceOf[account];
}

function transfer(address to, uint256 value) external returns (bool) {
require(_balanceOf[msg.sender] >= value, "Insufficient balance");
_balanceOf[msg.sender] -= value;
_balanceOf[to] += value;
emit Transfer(msg.sender,to,value);
emit Transfer(msg.sender, to, value);
return true;
}

function allowance(address owner, address spender) external view returns (uint256) {
return _allowance[owner][spender];
}
}

function approve(address spender, uint256 value) external returns (bool) {
_allowance[msg.sender][spender] = value;
emit Approval(msg.sender,spender,value);
emit Approval(msg.sender, spender, value);
return true;
}

Expand All @@ -49,13 +50,19 @@ contract AccountingToken {
_allowance[from][msg.sender] -= value;
_balanceOf[from] -= value;
_balanceOf[to] += value;
emit Transfer(from,to,value);
emit Transfer(from, to, value);
return true;
}

function name() external view returns (string memory) { return NAME; }
function name() external view returns (string memory) {
return NAME;
}

function symbol() external view returns (string memory) { return SYMBOL; }
function symbol() external view returns (string memory) {
return SYMBOL;
}

function decimals() public pure returns(uint8) { return DECIMALS; }
function decimals() public pure returns (uint8) {
return DECIMALS;
}
}
41 changes: 8 additions & 33 deletions src/CropProduct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.20;
import {Amount, Location, NftId, RiskId, Str, Timestamp} from "./Types.sol";

contract CropProduct {

event LogCropPolicyCreated(NftId policyNftId);

error StringTooLong(string str);
Expand All @@ -22,30 +21,13 @@ contract CropProduct {
Str seasonStart, // ISO 8601 date, eg "2025-02-18"
Str seasonEnd,
uint16 seasonDays
)
external
{ }
) external {}

function createLocation(
Str locationId,
int32 latitude,
int32 longitude
)
external
returns (Location location)
{ }
function createLocation(Str locationId, int32 latitude, int32 longitude) external returns (Location location) {}

function createCrop(Str crop)
external
{ }
function createCrop(Str crop) external {}

function createRisk(
Str id,
Str seasonId,
Str locationId,
Str crop,
Timestamp seasonEndAt
)
function createRisk(Str id, Str seasonId, Str locationId, Str crop, Timestamp seasonEndAt)
external
returns (RiskId riskId)
{
Expand All @@ -60,23 +42,16 @@ contract CropProduct {
Timestamp activateAt,
Amount sumInsuredAmount,
Amount premiumAmount
)
external
returns (NftId policyNftId)
{
) external returns (NftId policyNftId) {
policyNftCounter++;
policyNftId = NftId.wrap(1000 * policyNftCounter + 101);
emit LogCropPolicyCreated(policyNftId);

return policyNftId;
}

function getRiskId(Str id)
external
view
returns (RiskId riskId)
{
return _riskId[id];
function getRiskId(Str id) external view returns (RiskId riskId) {
return _riskId[id];
}

/// @dev converts the provided string into a short string.
Expand Down Expand Up @@ -111,4 +86,4 @@ contract CropProduct {
}
return result;
}
}
}
4 changes: 1 addition & 3 deletions src/StrHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.20;
type Str is bytes32;

contract StrHelper {

error StringTooLong(string str);
error InvalidShortString();

Expand All @@ -31,7 +30,6 @@ contract StrHelper {
return str;
}


/// @dev returns the length of the provided short string.
/// code from OZ ShortStrings.byteLength
function length(Str sstr) public pure returns (uint256) {
Expand All @@ -41,4 +39,4 @@ contract StrHelper {
}
return result;
}
}
}
5 changes: 5 additions & 0 deletions src/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
pragma solidity ^0.8.20;

type Amount is uint96;

type Location is uint64;

type NftId is uint96;

type RiskId is bytes8;

type Str is bytes32;

type Timestamp is uint40;

0 comments on commit 42daa56

Please sign in to comment.