Skip to content
2 changes: 1 addition & 1 deletion snapshots/ERC7683Allocator_open.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"open_simpleOrder": "168841"
"open_simpleOrder": "168974"
}
2 changes: 1 addition & 1 deletion snapshots/ERC7683Allocator_openFor.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"openFor_simpleOrder_userHimself": "172266"
"openFor_simpleOrder_userHimself": "172365"
}
2 changes: 1 addition & 1 deletion snapshots/HybridAllocatorTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"allocateAndRegister_nativeToken_emptyAmountInput": "139058",
"allocateAndRegister_second_erc20Token": "114865",
"allocateAndRegister_second_nativeToken": "104858",
"hybrid_execute_single": "174737"
"hybrid_execute_single": "174786"
}
15 changes: 8 additions & 7 deletions snapshots/OnChainAllocatorTest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"allocateFor_success_withRegistration": "134197",
"allocate_and_delete_expired_allocation": "66376",
"allocate_erc20": "129647",
"allocate_native": "129407",
"allocate_second_erc20": "97659",
"onchain_execute_double": "346191",
"onchain_execute_single": "219927"
"allocateFor_success_withRegistration": "134235",
"allocate_and_delete_expired_allocation": "79077",
"allocate_erc20": "129686",
"allocate_native": "129446",
"allocate_second_erc20": "97973",
"authorizeClaim_success_single_allocation": "32255",
"onchain_execute_double": "324623",
"onchain_execute_single": "220449"
}
573 changes: 386 additions & 187 deletions src/allocators/OnChainAllocator.sol

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/interfaces/IOnChainAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {Lock} from '@uniswap/the-compact/types/EIP712Types.sol';
/// @title IOnChainAllocator
/// @notice Interface for the on-chain token allocator that prevents double-spending in a fully decentralized manner
interface IOnChainAllocator is IOnChainAllocation {
struct Allocation {
uint32 expires;
struct BalanceExpiration {
uint32 nextExpiration;
uint224 amount;
bytes32 claimHash;
}

/// @notice Thrown if the allocator is not successfully registered
Expand Down Expand Up @@ -44,6 +43,9 @@ interface IOnChainAllocator is IOnChainAllocation {
/// @notice Thrown if the provided commitments are empty
error InvalidCommitments();

/// @notice Thrown if the provided allocatorData is invalid
error InvalidHint(uint256 allocatorDataLength, uint256 expectedAllocatorDataLength);

/// @notice Registers an allocation for a set of tokens
/// @param commitments The commitments of the allocations
/// @param arbiter The arbiter of the allocation
Expand Down Expand Up @@ -95,4 +97,9 @@ interface IOnChainAllocator is IOnChainAllocation {
bytes32 typehash,
bytes32 witness
) external payable returns (bytes32 claimHash, uint256[] memory registeredAmounts, uint256 nonce);

/// @notice Returns the normalized expiration for a claim
/// @param claimHash The hash of the claim
/// @return normalizedExpiration The normalized expiration for the claim
function getNormalizedExpirationForClaim(bytes32 claimHash) external view returns (uint32 normalizedExpiration);
}
8 changes: 4 additions & 4 deletions src/test/OnChainAllocationCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ contract OnChainAllocationCaller {
bytes32 typehash,
bytes32 witness,
uint8 todo
) external {
) external returns (bytes32 claimHash) {
uint256 nonce;
if (todo == 0) {
// Correctly deposit and register
nonce = ALLOCATOR.prepareAllocation(recipient, idsAndAmounts, arbiter, expires, typehash, witness, '');
ITheCompact(COMPACT).batchDepositAndRegisterFor(
(claimHash,) = ITheCompact(COMPACT).batchDepositAndRegisterFor(
recipient, idsAndAmounts, arbiter, nonce, expires, typehash, witness
);
} else if (todo == 1) {
Expand All @@ -35,15 +35,15 @@ contract OnChainAllocationCaller {
ITheCompact(COMPACT).batchDeposit(idsAndAmounts, recipient);
} else if (todo == 2) {
// Do not prepare, but deposit and register
ITheCompact(COMPACT).batchDepositAndRegisterFor(
(claimHash,) = ITheCompact(COMPACT).batchDepositAndRegisterFor(
recipient, idsAndAmounts, arbiter, nonce, expires, typehash, witness
);
} else if (todo == 3) {
nonce = ALLOCATOR.prepareAllocation(recipient, idsAndAmounts, arbiter, expires, typehash, witness, '');
} else {
// Correctly deposit and register
nonce = ALLOCATOR.prepareAllocation(recipient, idsAndAmounts, arbiter, expires, typehash, witness, '');
ITheCompact(COMPACT).batchDepositAndRegisterFor(
(claimHash,) = ITheCompact(COMPACT).batchDepositAndRegisterFor(
recipient, idsAndAmounts, arbiter, nonce, expires, typehash, witness
);
ALLOCATOR.executeAllocation(recipient, idsAndAmounts, arbiter, expires, typehash, witness, '');
Expand Down
Loading