forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Claims accounting as minimal balance (Uniswap#379)
* Add MinimalBalance * Initial commmit * Router custodies Claims, has access to priviledged burnFrom anbd tests * updategas * remove 6909 lib * yarn snapshots * Add gas snaps for swapping from claims balance * fix gas snaps by removing aux logic in router * gas * remove lib * Add transfer to minimalBalance, update tests * nit: rename * add back custom errors * move addition out of unchecked * Add transfer overflow check * Rename impl test * nit comments * comment# * Remove unused inheritance * remove comment * Remove poolClaimTest * fix interfaces * Feedback * Add address(0) and address(this) check for transfer * remove address(0) check * Remove batchBurn * Move mock claims to diff file * Add gas snaps for collect protocol fees * Add balance checks, make balances mapping private * Fix imports * fix fs perms * Remove uint256 in mapping and use Currency * feedback * Add gas snaps
- Loading branch information
Showing
29 changed files
with
368 additions
and
203 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/before swap hook, already cached dynamic fee.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
197590 | ||
197447 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
184225 | ||
184082 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
95961 | ||
95906 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
153292 | ||
153271 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
25011 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
58562 | ||
58439 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
38123 | ||
38079 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
307130 | ||
307014 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
275102 | ||
275044 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
293738 | ||
293680 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
36677 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
29853 | ||
24366 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
151412 | ||
151298 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
125053 | ||
124939 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
109741 | ||
109627 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
126356 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
166380 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
196825 | ||
196682 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
109719 | ||
109605 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
203442 | ||
203277 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.20; | ||
|
||
import {Currency, CurrencyLibrary} from "./types/Currency.sol"; | ||
import {IClaims} from "./interfaces/IClaims.sol"; | ||
|
||
/// An intentionally barebones balance mapping only supporting mint/burn/transfer | ||
contract Claims is IClaims { | ||
using CurrencyLibrary for Currency; | ||
|
||
// Mapping from Currency to account balances | ||
mapping(Currency currency => mapping(address account => uint256)) private balances; | ||
|
||
/// @inheritdoc IClaims | ||
function balanceOf(address account, Currency currency) public view returns (uint256) { | ||
return balances[currency][account]; | ||
} | ||
|
||
/// @inheritdoc IClaims | ||
function transfer(address to, Currency currency, uint256 amount) public { | ||
if (to == address(this)) revert InvalidAddress(); | ||
|
||
if (amount > balances[currency][msg.sender]) revert InsufficientBalance(); | ||
unchecked { | ||
balances[currency][msg.sender] -= amount; | ||
} | ||
balances[currency][to] += amount; | ||
emit Transfer(msg.sender, to, currency, amount); | ||
} | ||
|
||
/// @notice Mint `amount` of currency to address | ||
/// @param to The address to mint to | ||
/// @param currency The currency to mint | ||
/// @param amount The amount to mint | ||
function _mint(address to, Currency currency, uint256 amount) internal { | ||
balances[currency][to] += amount; | ||
emit Mint(to, currency, amount); | ||
} | ||
|
||
/// @notice Burn `amount` of currency from msg.sender | ||
/// @param currency The currency to mint | ||
/// @param amount The amount to burn | ||
/// @dev Will revert if the sender does not have enough balance | ||
function _burn(Currency currency, uint256 amount) internal { | ||
if (amount > balances[currency][msg.sender]) revert InsufficientBalance(); | ||
unchecked { | ||
balances[currency][msg.sender] -= amount; | ||
} | ||
emit Burn(msg.sender, currency, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Currency} from "../types/Currency.sol"; | ||
|
||
interface IClaims { | ||
/// @notice Thrown when user has insufficient Claims balance | ||
error InsufficientBalance(); | ||
|
||
/// @notice Thrown when transferring Claims to this address | ||
error InvalidAddress(); | ||
|
||
/// @notice Get the balance of `account` for `currency` | ||
/// @param account The account to get the balance of | ||
/// @param currency The currency to get the balance of | ||
function balanceOf(address account, Currency currency) external returns (uint256); | ||
|
||
/// @notice Transfer `amount` of `currency` from sender to `to` | ||
/// @param to The address to transfer to | ||
/// @param currency The currency to transfer | ||
/// @param amount The amount to transfer | ||
/// @dev Will revert if the sender does not have enough balance | ||
function transfer(address to, Currency currency, uint256 amount) external; | ||
|
||
/// @notice Emitted when minting `amount` of currency Claims to address | ||
event Mint(address indexed to, Currency indexed currency, uint256 amount); | ||
/// @notice Emitted when burning `amount` of currency Claims from address | ||
event Burn(address indexed from, Currency indexed currency, uint256 amount); | ||
/// @notice Emitted when transferring `amount` of currency Claims | ||
event Transfer(address indexed from, address indexed to, Currency indexed currency, uint256 amount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {Claims} from "../Claims.sol"; | ||
import {IClaims} from "../interfaces/IClaims.sol"; | ||
import {CurrencyLibrary, Currency} from "../types/Currency.sol"; | ||
|
||
contract MockClaims is Claims { | ||
using CurrencyLibrary for Currency; | ||
|
||
function mint(address to, Currency currency, uint256 amount) public { | ||
_mint(to, currency, amount); | ||
} | ||
|
||
function burn(Currency currency, uint256 amount) public { | ||
_burn(currency, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.