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

Release candidate v0.3.7 alpha #57

Merged
merged 64 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9f3a0df
(hub): non-Reentrant modifier had unused error code; remove
benjaminbollen Sep 25, 2024
1db4d65
(circles): correct order of check and effect in _claimIssuance to pre…
benjaminbollen Sep 25, 2024
3a209d7
(hub): on update v1 status, never reduce lastMintTime to avoid resett…
benjaminbollen Sep 26, 2024
fbc7824
Merge branch 'v0.3.7-patch02-check-lastminttime-before-updating-v1-st…
benjaminbollen Sep 26, 2024
fcde687
(Hub, InflatCRC, Circles): tidy up unused variable, docstring, comment
benjaminbollen Sep 26, 2024
2c8363d
Merge branch 'v0.3.7-patch03-wrong-value-welcome-bonus-docs' into rc-…
benjaminbollen Sep 26, 2024
7efb87f
(erc20Lift): only deploy erc20 wrapper for humans or groups (not for …
benjaminbollen Sep 26, 2024
99220e6
Merge branch 'v0.3.7-patch04-deploy-erc20-only-for-humans-and-orgs' i…
benjaminbollen Sep 26, 2024
c2a520f
(erc20Lift): quick extra cleanup of comments
benjaminbollen Sep 26, 2024
e25ede4
(Circles): correct issuance function for calculating exactly on a com…
benjaminbollen Sep 30, 2024
678a4dd
Merge branch 'v0.3.7-patch05-missing-hour-when-minting-exactly-on-the…
benjaminbollen Sep 30, 2024
a6cd3ea
(hub): correct trivial error in error in _matchNettedFlows
benjaminbollen Sep 30, 2024
b505892
Merge branch 'v0.3.7-patch06-trivial-error-correction-in-matchNettedF…
benjaminbollen Sep 30, 2024
61be206
(hub, circles): suppress group mint's acceptance call if along a path…
benjaminbollen Sep 30, 2024
5a58fa1
Merge branch 'v0.3.7-patch07-dont-make-explicit-acceptance-call-in-pa…
benjaminbollen Sep 30, 2024
5a55b0c
(demurrage): small possible gas optimisation
benjaminbollen Sep 30, 2024
8337c73
Merge branch 'v0.3.7-patch08-issue44-gas-optimisation-demurrage' into…
benjaminbollen Sep 30, 2024
8c857ce
(migration): require migration amount to be greater than zero
benjaminbollen Oct 1, 2024
212783b
Merge branch 'v0.3.7-patch09-zero-amount-migration' into rc-v0.3.7
benjaminbollen Oct 1, 2024
f8a5e08
(circles): improve the impl so save compile size and improve readability
benjaminbollen Oct 1, 2024
d2c1a41
Merge branch 'v0.3.7-patch05-missing-hour-when-minting-exactly-on-the…
benjaminbollen Oct 1, 2024
10bb27a
(InflationaryOperator): initialise inflationDayZero from Hub
benjaminbollen Oct 1, 2024
d6ebb20
Merge branch 'v0.3.7-patch10-initialise-inflationDayZero-for-operator…
benjaminbollen Oct 1, 2024
78cc375
(StandardTreasury): improve accuracy of name of events and func
benjaminbollen Oct 1, 2024
cf4ba33
(hub): adding explicit GroupMint event to Hub, TBD if we can find spa…
benjaminbollen Oct 1, 2024
8a50969
Merge branch 'v0.3.7-patch11-improve-events-in-standardTreasury' into…
benjaminbollen Oct 1, 2024
7ca31f9
(hub): simplify GroupMint event to reduce code size
benjaminbollen Oct 1, 2024
670839c
Merge branch 'v0.3.7-patch11-improve-events-in-standardTreasury' into…
benjaminbollen Oct 1, 2024
d7406b5
(errors): rename variable in error for correctness
benjaminbollen Oct 1, 2024
4da6217
Merge branch 'v0.3.7-patch12-correct-error-name' into rc-v0.3.7
benjaminbollen Oct 1, 2024
3954035
(nameRegistry): check short name is not zero
benjaminbollen Oct 1, 2024
51ef19f
Merge branch 'v0.3.7-patch13-protect-shortName-zero' into rc-v0.3.7
benjaminbollen Oct 1, 2024
ae3e110
(nameRegistry): remove restriction only registered address can regist…
benjaminbollen Oct 1, 2024
3755c3a
Merge branch 'v0.3.7-patch14-open-name-registry' into rc-v0.3.7
benjaminbollen Oct 1, 2024
ce7d2ad
(circles): update check for calculate issuance to more accurately che…
benjaminbollen Oct 2, 2024
b58261d
Merge branch 'v0.3.7-patch15-improve-hourly-check' into rc-v0.3.7
benjaminbollen Oct 2, 2024
408b7ce
(circles): remove commented out code
benjaminbollen Oct 2, 2024
faea261
Merge branch 'v0.3.7-patch15-improve-hourly-check' into rc-v0.3.7
benjaminbollen Oct 2, 2024
5998835
Merge branch 'v0.3.7-patch04-deploy-erc20-only-for-humans-and-orgs' i…
benjaminbollen Oct 2, 2024
b00072c
(StandardTreasury): correct data passed to be user data to policy for…
benjaminbollen Oct 2, 2024
50c784b
Merge branch 'v0.3.7-patch16-fix-group-redeem' into rc-v0.3.7
benjaminbollen Oct 2, 2024
4b44c29
(error): CirclesErrorNoArgs <- 0: CirclesAddressCannotBeZero
benjaminbollen Oct 2, 2024
0889ad3
(error): CirclesErrorNoArgs <- 1: CirclesArrayMustNotBeEmpty
benjaminbollen Oct 2, 2024
2fdacd7
(errors): adopt hex error code to reduce code size
benjaminbollen Oct 2, 2024
caaca32
(errors): uint8 conversion saves compile size... who knew?
benjaminbollen Oct 2, 2024
eb5ae88
(errors): first signs of nett benefit
benjaminbollen Oct 2, 2024
3d8323b
(errors): continue replacing errors, but only limited benefit so far
benjaminbollen Oct 3, 2024
353601d
(errors): churning along, also starting to reduce some params in adva…
benjaminbollen Oct 3, 2024
7e4fbe3
(circles): start collapsing if-statements of separate condition check…
benjaminbollen Oct 3, 2024
1135f83
(errors): reduce error detail on RejectBurn by mint policy
benjaminbollen Oct 3, 2024
98d9af3
(errors): repeat the trick! another 80 bytes down
benjaminbollen Oct 3, 2024
7025fef
(errors): covering more green territory
benjaminbollen Oct 3, 2024
320a002
(errors): simplify revert cases in registerGroup
benjaminbollen Oct 3, 2024
8f46b36
(errors): further compaction of errors, esp relevant for hub
benjaminbollen Oct 4, 2024
e28ef69
(errors): compact errors
benjaminbollen Oct 4, 2024
b94d28e
(hub): collapsing if-cond in upsert avatar
benjaminbollen Oct 4, 2024
9143ed7
(hub): more collapsing if clauses
benjaminbollen Oct 4, 2024
8c703d0
(hub): more if collapsing
benjaminbollen Oct 4, 2024
1f7c24d
(hub): extend RegisterHuman event with inviter data
benjaminbollen Oct 5, 2024
6290810
(hub): discount event and advanced usage flag set event
benjaminbollen Oct 5, 2024
4a98b0e
(hub): scope effects of flow edge wit separator events
benjaminbollen Oct 6, 2024
9d72d67
(nameRegistry): register hub as Circles (CRC) in name registry
benjaminbollen Oct 7, 2024
b824758
(version): update to rc-v0.3.7-alpha
benjaminbollen Oct 7, 2024
be6b97d
(deploy): artefacts of rc-v0.3.7-alpha
benjaminbollen Oct 7, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{"contractName":"Hub","deployedAddress":"0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb","sourcePath":"src/hub/Hub.sol:Hub","constructor-args":"0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0x1De4cea0c6A4a67FA7Ce2Ff9c628D43D5AEA1984 0xA8366F19208FaE17f3707f5164bDC3c73eea2219 0xC7E57f5356c46b53A2A1395766B90A5d57981eDf 0x86eA22F850F7fe97De700d841200e148347Ca231 1675209600 31540000 https://gateway.aboutcircles.com/v1/circles/{id}.json","argumentsFile":"constructorArgs_Hub.txt"}
{"contractName":"Migration","deployedAddress":"0xA8366F19208FaE17f3707f5164bDC3c73eea2219","sourcePath":"src/migration/Migration.sol:Migration","constructor-args":"0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb 1675209600","argumentsFile":"constructorArgs_Migration.txt"}
{"contractName":"NameRegistry","deployedAddress":"0x1De4cea0c6A4a67FA7Ce2Ff9c628D43D5AEA1984","sourcePath":"src/names/NameRegistry.sol:NameRegistry","constructor-args":"0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb","argumentsFile":"constructorArgs_NameRegistry.txt"}
{"contractName":"ERC20Lift","deployedAddress":"0xC7E57f5356c46b53A2A1395766B90A5d57981eDf","sourcePath":"src/lift/ERC20Lift.sol:ERC20Lift","constructor-args":"0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb 0x1De4cea0c6A4a67FA7Ce2Ff9c628D43D5AEA1984 0xcB42B236c3e58857A7F3D45df427535976e09027 0x0d52CBB59F817f23861b4571F1c056e7E3FaC6cE","argumentsFile":"constructorArgs_ERC20Lift.txt"}
{"contractName":"StandardTreasury","deployedAddress":"0x86eA22F850F7fe97De700d841200e148347Ca231","sourcePath":"src/treasury/StandardTreasury.sol:StandardTreasury","constructor-args":"0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb 0x7881Eca1d73a2Da217Ac206Ae281048BdA0E1a94","argumentsFile":"constructorArgs_StandardTreasury.txt"}
{"contractName":"BaseGroupMintPolicy","deployedAddress":"0x92bfAbDc2D2608751C617e48469278CF19ef3C77","sourcePath":"src/groups/BaseMintPolicy.sol:MintPolicy","constructor-args":"","argumentsFile":"constructorArgs_BaseGroupMintPolicy.txt"}
{"contractName":"MastercopyDemurrageERC20","deployedAddress":"0xcB42B236c3e58857A7F3D45df427535976e09027","sourcePath":"src/lift/DemurrageCircles.sol:DemurrageCircles","constructor-args":"","argumentsFile":"constructorArgs_MastercopyDemurrageERC20.txt"}
{"contractName":"MastercopyInflationaryERC20","deployedAddress":"0x0d52CBB59F817f23861b4571F1c056e7E3FaC6cE","sourcePath":"src/lift/InflationaryCircles.sol:InflationaryCircles","constructor-args":"","argumentsFile":"constructorArgs_MastercopyInflationaryERC20.txt"}
{"contractName":"MastercopyStandardVault","deployedAddress":"0x7881Eca1d73a2Da217Ac206Ae281048BdA0E1a94","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,18 @@
Chiado deployment
=================
Deployment Date: 2024-10-07 12:03:49
Version: rc-0.3.7-alpha
Git Commit: b824758e79ab581278c0f17bd03bde7855161afc
Deployer Address: 0x7619F26728Ced663E50E578EB6ff42430931564c, Intitial nonce: 193
Compiler Version: v0.8.23+commit.f704f362

Deployed Contracts:
Hub: 0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb
Migration: 0xA8366F19208FaE17f3707f5164bDC3c73eea2219
NameRegistry: 0x1De4cea0c6A4a67FA7Ce2Ff9c628D43D5AEA1984
ERC20Lift: 0xC7E57f5356c46b53A2A1395766B90A5d57981eDf
StandardTreasury: 0x86eA22F850F7fe97De700d841200e148347Ca231
BaseGroupMintPolicy: 0x92bfAbDc2D2608751C617e48469278CF19ef3C77
MastercopyDemurrageERC20: 0xcB42B236c3e58857A7F3D45df427535976e09027
MastercopyInflationaryERC20: 0x0d52CBB59F817f23861b4571F1c056e7E3FaC6cE
MastercopyStandardVault: 0x7881Eca1d73a2Da217Ac206Ae281048BdA0E1a94
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 @@
0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb 0x1De4cea0c6A4a67FA7Ce2Ff9c628D43D5AEA1984 0xcB42B236c3e58857A7F3D45df427535976e09027 0x0d52CBB59F817f23861b4571F1c056e7E3FaC6cE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xdbF22D4e8962Db3b2F1d9Ff55be728A887e47710 0x1De4cea0c6A4a67FA7Ce2Ff9c628D43D5AEA1984 0xA8366F19208FaE17f3707f5164bDC3c73eea2219 0xC7E57f5356c46b53A2A1395766B90A5d57981eDf 0x86eA22F850F7fe97De700d841200e148347Ca231 1675209600 31540000 https://gateway.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 0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb 1675209600
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xa1d3Bc93D3b9BE137721A597796c1E7ae6598aEb 0x7881Eca1d73a2Da217Ac206Ae281048BdA0E1a94
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 @@
0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb 0x6192069E85afBD09D03f7e85eB6c35982A847e16 0xBF2F902d56d7ad2F2B1d674DC8B4d8C58354e7e5 0xD3529a99A7881DF7D11829135759AD0e4A8Ab587
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x29b9a7fBb8995b2423a71cC17cf9810798F6C543 0x6192069E85afBD09D03f7e85eB6c35982A847e16 0x3483cE5904413bc4Fb83DA2E43540eD769752C88 0x1CAc5fE351EFFa130223aC0f84EB6B7Efc7a66AD 0x421ae522F756412808Ff62F74C20e5ebDA8C4208 1602720000 31540000 https://gateway.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 @@
0x29b9a7fBb8995b2423a71cC17cf9810798F6C543 0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb 1602720000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb 0x6604C8eBDD57F3771e4D0Cb3A174AfaEAf38C463
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{"contractName":"Hub","deployedAddress":"0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb","sourcePath":"src/hub/Hub.sol:Hub","constructor-args":"0x29b9a7fBb8995b2423a71cC17cf9810798F6C543 0x6192069E85afBD09D03f7e85eB6c35982A847e16 0x3483cE5904413bc4Fb83DA2E43540eD769752C88 0x1CAc5fE351EFFa130223aC0f84EB6B7Efc7a66AD 0x421ae522F756412808Ff62F74C20e5ebDA8C4208 1602720000 31540000 https://gateway.aboutcircles.com/v1/circles/{id}.json","argumentsFile":"constructorArgs_Hub.txt"}
{"contractName":"Migration","deployedAddress":"0x3483cE5904413bc4Fb83DA2E43540eD769752C88","sourcePath":"src/migration/Migration.sol:Migration","constructor-args":"0x29b9a7fBb8995b2423a71cC17cf9810798F6C543 0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb 1602720000","argumentsFile":"constructorArgs_Migration.txt"}
{"contractName":"NameRegistry","deployedAddress":"0x6192069E85afBD09D03f7e85eB6c35982A847e16","sourcePath":"src/names/NameRegistry.sol:NameRegistry","constructor-args":"0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb","argumentsFile":"constructorArgs_NameRegistry.txt"}
{"contractName":"ERC20Lift","deployedAddress":"0x1CAc5fE351EFFa130223aC0f84EB6B7Efc7a66AD","sourcePath":"src/lift/ERC20Lift.sol:ERC20Lift","constructor-args":"0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb 0x6192069E85afBD09D03f7e85eB6c35982A847e16 0xBF2F902d56d7ad2F2B1d674DC8B4d8C58354e7e5 0xD3529a99A7881DF7D11829135759AD0e4A8Ab587","argumentsFile":"constructorArgs_ERC20Lift.txt"}
{"contractName":"StandardTreasury","deployedAddress":"0x421ae522F756412808Ff62F74C20e5ebDA8C4208","sourcePath":"src/treasury/StandardTreasury.sol:StandardTreasury","constructor-args":"0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb 0x6604C8eBDD57F3771e4D0Cb3A174AfaEAf38C463","argumentsFile":"constructorArgs_StandardTreasury.txt"}
{"contractName":"BaseGroupMintPolicy","deployedAddress":"0x48F6B0aa3Ca905C9DbE41717c7664639107257da","sourcePath":"src/groups/BaseMintPolicy.sol:MintPolicy","constructor-args":"","argumentsFile":"constructorArgs_BaseGroupMintPolicy.txt"}
{"contractName":"MastercopyDemurrageERC20","deployedAddress":"0xBF2F902d56d7ad2F2B1d674DC8B4d8C58354e7e5","sourcePath":"src/lift/DemurrageCircles.sol:DemurrageCircles","constructor-args":"","argumentsFile":"constructorArgs_MastercopyDemurrageERC20.txt"}
{"contractName":"MastercopyInflationaryERC20","deployedAddress":"0xD3529a99A7881DF7D11829135759AD0e4A8Ab587","sourcePath":"src/lift/InflationaryCircles.sol:InflationaryCircles","constructor-args":"","argumentsFile":"constructorArgs_MastercopyInflationaryERC20.txt"}
{"contractName":"MastercopyStandardVault","deployedAddress":"0x6604C8eBDD57F3771e4D0Cb3A174AfaEAf38C463","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,18 @@
Gnosis Chain deployment
=================
Deployment Date: 2024-10-07 12:11:12
Version: rc-0.3.7-alpha
Git Commit: b824758e79ab581278c0f17bd03bde7855161afc
Deployer Address: 0x7619F26728Ced663E50E578EB6ff42430931564c, Initial nonce: 86
Compiler Version: v0.8.23+commit.f704f362

Deployed Contracts:
Hub: 0x3a0F7848071f067c25b0747eC5bEdc77cb3778eb
Migration: 0x3483cE5904413bc4Fb83DA2E43540eD769752C88
NameRegistry: 0x6192069E85afBD09D03f7e85eB6c35982A847e16
ERC20Lift: 0x1CAc5fE351EFFa130223aC0f84EB6B7Efc7a66AD
StandardTreasury: 0x421ae522F756412808Ff62F74C20e5ebDA8C4208
BaseGroupMintPolicy: 0x48F6B0aa3Ca905C9DbE41717c7664639107257da
MastercopyDemurrageERC20: 0xBF2F902d56d7ad2F2B1d674DC8B4d8C58354e7e5
MastercopyInflationaryERC20: 0xD3529a99A7881DF7D11829135759AD0e4A8Ab587
MastercopyStandardVault: 0x6604C8eBDD57F3771e4D0Cb3A174AfaEAf38C463
2 changes: 1 addition & 1 deletion script/deployments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deploy-circles",
"version": "rc-0.3.6-alpha",
"version": "rc-0.3.7-alpha",
"type": "module",
"dependencies": {
"dotenv": "^16.4.5",
Expand Down
57 changes: 35 additions & 22 deletions src/circles/Circles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ contract Circles is ERC1155, ICirclesErrors {

// Constants

/**
* @notice Issue one Circle per hour for each human in demurraged units.
* So per second issue 10**18 / 3600 = 277777777777778 attoCircles.
*/
uint256 private constant ISSUANCE_PER_SECOND = uint256(277777777777778);

/**
* @notice Upon claiming, the maximum claim is upto two weeks
* of history. Unclaimed older Circles are unclaimable.
Expand Down Expand Up @@ -88,12 +82,16 @@ contract Circles is ERC1155, ICirclesErrors {
MintTime memory mintTime = mintTimes[_human];
if (mintTime.mintV1Status != address(0) && mintTime.mintV1Status != CIRCLES_STOPPED_V1) {
// Circles v1 contract cannot be active.
revert CirclesERC1155MintBlocked(_human, mintTime.mintV1Status);
// revert CirclesERC1155MintBlocked(_human, mintTime.mintV1Status);
revert CirclesErrorOneAddressArg(_human, 0xC0);
}

if (uint256(mintTime.lastMintTime) + 1 hours > block.timestamp) {
// Mint time is set to indefinite future for stopped mints in v2
// and only complete hours get minted, so shortcut the calculation
// Check if at least one new completed hour is mintable
uint256 lastCompletedHour = mintTime.lastMintTime / 1 hours;
uint256 currentCompletedHour = block.timestamp / 1 hours;

if (lastCompletedHour >= currentCompletedHour || mintTime.lastMintTime == INDEFINITE_FUTURE) {
// No new completed hour to mint, or stopped
return (0, 0, 0);
}

Expand All @@ -112,10 +110,17 @@ contract Circles is ERC1155, ICirclesErrors {
// calculate the number of completed hours in day A until `startMint`
int128 k = Math64x64.fromUInt((startMint - (dA * 1 days + inflationDayZero)) / 1 hours);

// Calculate the number of incompleted hours remaining in day B from current timestamp
int128 l = Math64x64.fromUInt(((dB + 1) * 1 days + inflationDayZero - block.timestamp) / 1 hours + 1);
// Calculate the number of seconds remaining in the current day (dB)
uint256 secondsRemainingInB = ((dB + 1) * 1 days + inflationDayZero - block.timestamp);
// Calculate the number of complete hours remaining
uint256 hoursRemainingInB = secondsRemainingInB / 1 hours;
// Calculate l:
// If there are any seconds beyond complete hours, add 1 to account for the incomplete hour
// Convert the result to int128 using Math64x64.fromUInt
int128 l = Math64x64.fromUInt(hoursRemainingInB + (secondsRemainingInB % 1 hours > 0 ? 1 : 0));

// calculate the overcounted (demurraged) k (in day A) and l (in day B) hours
// note that the hours l are not demurraged as it is current day by construction
int128 overcount = Math64x64.add(Math64x64.mul(R[n], k), l);

// subtract the overcount from the total issuance, and convert to attoCircles
Expand All @@ -138,24 +143,33 @@ contract Circles is ERC1155, ICirclesErrors {
// No issuance to claim, simply return without reverting
return;
}
// mint personal Circles to the human
_mintAndUpdateTotalSupply(_human, toTokenId(_human), issuance, "");
// update the last mint time

// update the last mint time, before minting as mint time determines the check (guard for reeentrancy attack)
mintTimes[_human].lastMintTime = uint96(block.timestamp);

// mint personal Circles to the human; ERC1155 mint will perform acceptance call
_mintAndUpdateTotalSupply(_human, toTokenId(_human), issuance, "", true);

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

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

uint64 today = day(block.timestamp);
DiscountedBalance memory 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);
// revert CirclesDemurrageAmountExceedsMaxUint192(_account, _id, newTotalSupply, 2);
revert CirclesErrorAddressUintArgs(_account, _id, 0x80);
}
totalSupplyBalance.balance = uint192(newTotalSupply);
totalSupplyBalance.lastUpdatedDay = today;
Expand All @@ -176,7 +190,8 @@ contract Circles is ERC1155, ICirclesErrors {
// 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);
// revert CirclesLogicAssertion(4);
revert CirclesErrorNoArgs(0x84);
}
unchecked {
totalSupplyBalance.balance = uint192(discountedTotalSupply - _value);
Expand All @@ -185,14 +200,12 @@ contract Circles is ERC1155, ICirclesErrors {
discountedTotalSupplies[_id] = totalSupplyBalance;
}

// Private functions

/**
* @dev Max function to compare two values.
* @param a Value a
* @param b Value b
*/
function _max(uint256 a, uint256 b) private pure returns (uint256) {
function _max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
7 changes: 4 additions & 3 deletions src/circles/Demurrage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.24;
import {ABDKMath64x64 as Math64x64} from "lib/abdk-libraries-solidity/ABDKMath64x64.sol";
import "../errors/Errors.sol";

contract Demurrage is ICirclesDemurrageErrors {
contract Demurrage is ICirclesCompactErrors, ICirclesDemurrageErrors {
// Type declarations

/**
Expand Down Expand Up @@ -256,9 +256,10 @@ contract Demurrage is ICirclesDemurrageErrors {
R[_dayDifference] = demurrageFactor;
}
return demurrageFactor;
} else {
return Math64x64.pow(GAMMA_64x64, _dayDifference);
}
// if the day difference is for older than 14 days, calculate the value
// and do not cache it
return Math64x64.pow(GAMMA_64x64, _dayDifference);
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/circles/DiscountedBalances.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ contract DiscountedBalances is Demurrage {
*/
mapping(uint256 => DiscountedBalance) internal discountedTotalSupplies;

// Events

event DiscountCost(address indexed account, uint256 indexed id, uint256 discountCost);

// Constructor

/**
Expand Down Expand Up @@ -46,7 +50,8 @@ contract DiscountedBalances is Demurrage {
DiscountedBalance memory discountedBalance = discountedBalances[_id][_account];
if (_day < discountedBalance.lastUpdatedDay) {
// DiscountedBalances: day is before last updated day
revert CirclesDemurrageDayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 0);
// revert CirclesDemurrageDayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 0);
revert CirclesErrorAddressUintArgs(_account, discountedBalance.lastUpdatedDay, 0xA0);
}
uint256 dayDifference;
unchecked {
Expand Down Expand Up @@ -93,7 +98,8 @@ contract DiscountedBalances is Demurrage {
function _updateBalance(address _account, uint256 _id, uint256 _balance, uint64 _day) internal {
if (_balance > MAX_VALUE) {
// DiscountedBalances: balance exceeds maximum value
revert CirclesDemurrageAmountExceedsMaxUint190(_account, _id, _balance, 0);
// revert CirclesDemurrageAmountExceedsMaxUint192(_account, _id, _balance, 0);
revert CirclesErrorAddressUintArgs(_account, _id, 0x81);
}
DiscountedBalance memory discountedBalance = discountedBalances[_id][_account];
discountedBalance.balance = uint192(_balance);
Expand All @@ -112,7 +118,8 @@ contract DiscountedBalances is Demurrage {
DiscountedBalance memory discountedBalance = discountedBalances[_id][_account];
if (_day < discountedBalance.lastUpdatedDay) {
// DiscountedBalances: day is before last updated day
revert CirclesDemurrageDayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 1);
// revert CirclesDemurrageDayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 1);
revert CirclesErrorAddressUintArgs(_account, discountedBalance.lastUpdatedDay, 0xA1);
}
uint256 dayDifference;
unchecked {
Expand All @@ -124,12 +131,14 @@ contract DiscountedBalances is Demurrage {
uint256 discountCost = discountedBalance.balance - discountedBalanceOnDay;
if (discountCost > 0) {
emit IERC1155.TransferSingle(msg.sender, _account, address(0), _id, discountCost);
emit DiscountCost(_account, _id, discountCost);
}
}
uint256 updatedBalance = discountedBalanceOnDay + _value;
if (updatedBalance > MAX_VALUE) {
// DiscountedBalances: balance exceeds maximum value
revert CirclesDemurrageAmountExceedsMaxUint190(_account, _id, updatedBalance, 1);
// revert CirclesDemurrageAmountExceedsMaxUint190(_account, _id, updatedBalance, 1);
revert CirclesErrorAddressUintArgs(_account, _id, 0x82);
}
discountedBalance.balance = uint192(updatedBalance);
discountedBalance.lastUpdatedDay = _day;
Expand Down
Loading
Loading