Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into 20240503-events-di…
Browse files Browse the repository at this point in the history
…scountcost
  • Loading branch information
benjaminbollen committed May 10, 2024
2 parents ab09171 + 4c0d5a5 commit f5a3099
Show file tree
Hide file tree
Showing 23 changed files with 429 additions and 122 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## latest

- [PR141] consented flow with bi-directional trust, with opt-out to v1 protocol of uni-directional trust
- [PR138] storage-based reentrency guard for operateFlowMatrix
- [PR136] total supply, name and symbol for ERC1155 (out of specification)

## v0.3.3

- [PR132] bug fix in groupMint(); initial test coverage for group mint
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Chiado deployment
=================
Deployment Date: 2024-04-12 15:12:00
Version: 0.3.3-alpha
Git Commit: 7b78c749b91175265f2cf934fcc4f51a2085358d
Deployer Address: 0x7619F26728Ced663E50E578EB6ff42430931564c, Intitial nonce: 108
Compiler Version: v0.8.23+commit.f704f362

Deployed Contracts:
Hub: 0xFFfbD3E62203B888bb8E09c1fcAcE58242674964
Migration: 0x9c7E2AfAc052743944d5d8F80Db90E1E14A663aE
NameRegistry: 0x0A1D308a39A6dF8972A972E586E4b4b3Dc73520f
ERC20Lift: 0xaA20efff0511175C091F156D095DD3b62951Be48
StandardTreasury: 0x97c28CCC374570C2b10f7569197919418D702F99
BaseGroupMintPolicy: 0x95fbD8D52c18b6AA453e9cB06851543f125DCedE
MastercopyDemurrageERC20: 0x44A47EC79B45A13e884328018320D90DE86Bb932
MastercopyInflationaryERC20: 0xb4A1012a0564a25dF5a8311d1B6DF47b098BdfdB
MastercopyStandardVault: 0x8E0115358DC2Dc984c0C1d9530BEE19616492177
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{"contractName":"Hub","deployedAddress":"0xFFfbD3E62203B888bb8E09c1fcAcE58242674964","sourcePath":"src/hub/Hub.sol:Hub","constructor-args":"0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0x0A1D308a39A6dF8972A972E586E4b4b3Dc73520f 0x9c7E2AfAc052743944d5d8F80Db90E1E14A663aE 0xaA20efff0511175C091F156D095DD3b62951Be48 0x97c28CCC374570C2b10f7569197919418D702F99 1675209600 31540000 https://fallback.aboutcircles.com/v1/circles/{id}.json","argumentsFile":"constructorArgs_Hub.txt"}
{"contractName":"Migration","deployedAddress":"0x9c7E2AfAc052743944d5d8F80Db90E1E14A663aE","sourcePath":"src/migration/Migration.sol:Migration","constructor-args":"0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0xFFfbD3E62203B888bb8E09c1fcAcE58242674964 1675209600","argumentsFile":"constructorArgs_Migration.txt"}
{"contractName":"NameRegistry","deployedAddress":"0x0A1D308a39A6dF8972A972E586E4b4b3Dc73520f","sourcePath":"src/names/NameRegistry.sol:NameRegistry","constructor-args":"0xFFfbD3E62203B888bb8E09c1fcAcE58242674964","argumentsFile":"constructorArgs_NameRegistry.txt"}
{"contractName":"ERC20Lift","deployedAddress":"0xaA20efff0511175C091F156D095DD3b62951Be48","sourcePath":"src/lift/ERC20Lift.sol:ERC20Lift","constructor-args":"0xFFfbD3E62203B888bb8E09c1fcAcE58242674964 0x0A1D308a39A6dF8972A972E586E4b4b3Dc73520f 0x44A47EC79B45A13e884328018320D90DE86Bb932 0xb4A1012a0564a25dF5a8311d1B6DF47b098BdfdB","argumentsFile":"constructorArgs_ERC20Lift.txt"}
{"contractName":"StandardTreasury","deployedAddress":"0x97c28CCC374570C2b10f7569197919418D702F99","sourcePath":"src/treasury/StandardTreasury.sol:StandardTreasury","constructor-args":"0xFFfbD3E62203B888bb8E09c1fcAcE58242674964 0x8E0115358DC2Dc984c0C1d9530BEE19616492177","argumentsFile":"constructorArgs_StandardTreasury.txt"}
{"contractName":"BaseGroupMintPolicy","deployedAddress":"0x95fbD8D52c18b6AA453e9cB06851543f125DCedE","sourcePath":"src/groups/BaseMintPolicy.sol:MintPolicy","constructor-args":"","argumentsFile":"constructorArgs_BaseGroupMintPolicy.txt"}
{"contractName":"MastercopyDemurrageERC20","deployedAddress":"0x44A47EC79B45A13e884328018320D90DE86Bb932","sourcePath":"src/lift/DemurrageCircles.sol:DemurrageCircles","constructor-args":"","argumentsFile":"constructorArgs_MastercopyDemurrageERC20.txt"}
{"contractName":"MastercopyInflationaryERC20","deployedAddress":"0xb4A1012a0564a25dF5a8311d1B6DF47b098BdfdB","sourcePath":"src/lift/InflationaryCircles.sol:InflationaryCircles","constructor-args":"","argumentsFile":"constructorArgs_MastercopyInflationaryERC20.txt"}
{"contractName":"MastercopyStandardVault","deployedAddress":"0x8E0115358DC2Dc984c0C1d9530BEE19616492177","sourcePath":"src/treasury/StandardVault.sol:StandardVault","constructor-args":"","argumentsFile":"constructorArgs_MastercopyStandardVault.txt"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xFFfbD3E62203B888bb8E09c1fcAcE58242674964 0x0A1D308a39A6dF8972A972E586E4b4b3Dc73520f 0x44A47EC79B45A13e884328018320D90DE86Bb932 0xb4A1012a0564a25dF5a8311d1B6DF47b098BdfdB
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0x0A1D308a39A6dF8972A972E586E4b4b3Dc73520f 0x9c7E2AfAc052743944d5d8F80Db90E1E14A663aE 0xaA20efff0511175C091F156D095DD3b62951Be48 0x97c28CCC374570C2b10f7569197919418D702F99 1675209600 31540000 https://fallback.aboutcircles.com/v1/circles/{id}.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0xFFfbD3E62203B888bb8E09c1fcAcE58242674964 1675209600
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xFFfbD3E62203B888bb8E09c1fcAcE58242674964
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xFFfbD3E62203B888bb8E09c1fcAcE58242674964 0x8E0115358DC2Dc984c0C1d9530BEE19616492177
44 changes: 41 additions & 3 deletions src/circles/Circles.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.24;

import "../errors/Errors.sol";
import "../lib/Math64x64.sol";
import "./ERC1155.sol";

contract Circles is ERC1155 {
contract Circles is ERC1155, ICirclesErrors {
// Type declarations

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ contract Circles is ERC1155 {
* and the status of the v1 Circles minting.
* @dev This is used to store the last mint time for each avatar.
*/
mapping(address => MintTime) public mintTimes;
mapping(address => MintTime) internal mintTimes;

// Events

Expand Down Expand Up @@ -140,13 +141,50 @@ contract Circles is ERC1155 {
return;
}
// mint personal Circles to the human
_mint(_human, toTokenId(_human), issuance, "");
_mintAndUpdateTotalSupply(_human, toTokenId(_human), issuance, "");
// update the last mint time
mintTimes[_human].lastMintTime = uint96(block.timestamp);

emit PersonalMint(_human, issuance, startPeriod, endPeriod);
}

function _mintAndUpdateTotalSupply(address _account, uint256 _id, uint256 _value, bytes memory _data) internal {
_mint(_account, _id, _value, _data);

uint64 today = day(block.timestamp);
DiscountedBalance storage totalSupplyBalance = discountedTotalSupplies[_id];
uint256 newTotalSupply =
_calculateDiscountedBalance(totalSupplyBalance.balance, today - totalSupplyBalance.lastUpdatedDay) + _value;
if (newTotalSupply > MAX_VALUE) {
// DiscountedBalances: balance exceeds maximum value
revert CirclesDemurrageAmountExceedsMaxUint190(_account, _id, newTotalSupply, 2);
}
totalSupplyBalance.balance = uint192(newTotalSupply);
totalSupplyBalance.lastUpdatedDay = today;
}

function _burnAndUpdateTotalSupply(address _account, uint256 _id, uint256 _value) internal {
// _update will discount the balance before subtracting the value
_burn(_account, _id, _value);

uint64 today = day(block.timestamp);
DiscountedBalance storage totalSupplyBalance = discountedTotalSupplies[_id];
uint256 discountedTotalSupply =
_calculateDiscountedBalance(totalSupplyBalance.balance, today - totalSupplyBalance.lastUpdatedDay);
if (discountedTotalSupply < _value) {
// Logically impossible to burn more than the total supply
// however if the total supply nears dust, the discounting of the balance
// and the total supply might differ on the least significant bits.
// There is no good way to handle this, so user should burn a few attoCRC less,
// or wait a day for the total supply to be discounted to zero automatically.
revert CirclesLogicAssertion(4);
}
unchecked {
totalSupplyBalance.balance = uint192(discountedTotalSupply - _value);
}
totalSupplyBalance.lastUpdatedDay = today;
}

// Private functions

/**
Expand Down
27 changes: 16 additions & 11 deletions src/circles/DiscountedBalances.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ contract DiscountedBalances is Demurrage {
* @dev stores the discounted balances of the accounts privately.
* Mapping from Circles identifiers to accounts to the discounted balance.
*/
mapping(uint256 => mapping(address => DiscountedBalance)) public discountedBalances;
mapping(uint256 => mapping(address => DiscountedBalance)) internal discountedBalances;

/**
* @dev stores the total supply for each Circles identifier
*/
mapping(uint256 => DiscountedBalance) internal discountedTotalSupplies;

// Constructor

Expand Down Expand Up @@ -56,17 +61,17 @@ contract DiscountedBalances is Demurrage {
return (balanceOnDay_, discountCost_);
}

// Internal functions
/**
* @notice Total supply of a Circles identifier.
* @param _id Circles identifier for which to calculate the total supply
*/
function totalSupply(uint256 _id) public view returns (uint256) {
DiscountedBalance memory totalSupplyBalance = discountedTotalSupplies[_id];
uint64 today = day(block.timestamp);
return _calculateDiscountedBalance(totalSupplyBalance.balance, today - totalSupplyBalance.lastUpdatedDay);
}

// /**
// * @dev Calculate the inflationary balance of a discounted balance
// * @param _account Address of the account to calculate the balance of
// * @param _id Circles identifier for which to calculate the balance
// */
// function _inflationaryBalanceOf(address _account, uint256 _id) internal view returns (uint256) {
// DiscountedBalance memory discountedBalance = discountedBalances[_id][_account];
// return _calculateInflationaryBalance(discountedBalance.balance, discountedBalance.lastUpdatedDay);
// }
// Internal functions

/**
* @dev Update the balance of an account for a given Circles identifier
Expand Down
25 changes: 13 additions & 12 deletions src/circles/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ abstract contract ERC1155 is DiscountedBalances, Context, ERC165, IERC1155, IERC
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
// function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal {
// if (to == address(0)) {
// revert ERC1155InvalidReceiver(address(0));
// }
// _updateWithAcceptanceCheck(address(0), to, ids, values, data);
// }

/**
* @dev Destroys a `value` amount of tokens of type `id` from `from`
Expand Down Expand Up @@ -376,13 +376,14 @@ abstract contract ERC1155 is DiscountedBalances, Context, ERC165, IERC1155, IERC
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
* - `ids` and `values` must have the same length.
* //
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
// function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal {
// if (from == address(0)) {
// revert ERC1155InvalidSender(address(0));
// }
// _updateWithAcceptanceCheck(from, address(0), ids, values, "");
// }

/**
* @dev Approve `operator` to operate on all of `owner` tokens
Expand Down
Loading

0 comments on commit f5a3099

Please sign in to comment.