Skip to content

Commit 4fa4bb9

Browse files
committed
Add new interface for Allocator.sol
1 parent cc245c0 commit 4fa4bb9

File tree

5 files changed

+278
-2
lines changed

5 files changed

+278
-2
lines changed

abis/IAllocator.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@
5454
],
5555
"stateMutability": "view"
5656
},
57+
{
58+
"type": "function",
59+
"name": "decreaseAllowance",
60+
"inputs": [
61+
{
62+
"name": "allocator",
63+
"type": "address",
64+
"internalType": "address"
65+
},
66+
{
67+
"name": "amount",
68+
"type": "uint256",
69+
"internalType": "uint256"
70+
}
71+
],
72+
"outputs": [],
73+
"stateMutability": "nonpayable"
74+
},
5775
{
5876
"type": "function",
5977
"name": "getAllocators",

abis/IAllocatorV1.json

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
[
2+
{
3+
"type": "function",
4+
"name": "addAllowance",
5+
"inputs": [
6+
{
7+
"name": "allocator",
8+
"type": "address",
9+
"internalType": "address"
10+
},
11+
{
12+
"name": "amount",
13+
"type": "uint256",
14+
"internalType": "uint256"
15+
}
16+
],
17+
"outputs": [],
18+
"stateMutability": "nonpayable"
19+
},
20+
{
21+
"type": "function",
22+
"name": "addVerifiedClient",
23+
"inputs": [
24+
{
25+
"name": "clientAddress",
26+
"type": "bytes",
27+
"internalType": "bytes"
28+
},
29+
{
30+
"name": "amount",
31+
"type": "uint256",
32+
"internalType": "uint256"
33+
}
34+
],
35+
"outputs": [],
36+
"stateMutability": "nonpayable"
37+
},
38+
{
39+
"type": "function",
40+
"name": "allowance",
41+
"inputs": [
42+
{
43+
"name": "allocator",
44+
"type": "address",
45+
"internalType": "address"
46+
}
47+
],
48+
"outputs": [
49+
{
50+
"name": "allowance",
51+
"type": "uint256",
52+
"internalType": "uint256"
53+
}
54+
],
55+
"stateMutability": "view"
56+
},
57+
{
58+
"type": "function",
59+
"name": "getAllocators",
60+
"inputs": [],
61+
"outputs": [
62+
{
63+
"name": "allocators",
64+
"type": "address[]",
65+
"internalType": "address[]"
66+
}
67+
],
68+
"stateMutability": "view"
69+
},
70+
{
71+
"type": "function",
72+
"name": "setAllowance",
73+
"inputs": [
74+
{
75+
"name": "allocator",
76+
"type": "address",
77+
"internalType": "address"
78+
},
79+
{
80+
"name": "amount",
81+
"type": "uint256",
82+
"internalType": "uint256"
83+
}
84+
],
85+
"outputs": [],
86+
"stateMutability": "nonpayable"
87+
},
88+
{
89+
"type": "event",
90+
"name": "AllowanceChanged",
91+
"inputs": [
92+
{
93+
"name": "allocator",
94+
"type": "address",
95+
"indexed": true,
96+
"internalType": "address"
97+
},
98+
{
99+
"name": "allowanceBefore",
100+
"type": "uint256",
101+
"indexed": false,
102+
"internalType": "uint256"
103+
},
104+
{
105+
"name": "allowanceAfter",
106+
"type": "uint256",
107+
"indexed": false,
108+
"internalType": "uint256"
109+
}
110+
],
111+
"anonymous": false
112+
},
113+
{
114+
"type": "event",
115+
"name": "DatacapAllocated",
116+
"inputs": [
117+
{
118+
"name": "allocator",
119+
"type": "address",
120+
"indexed": true,
121+
"internalType": "address"
122+
},
123+
{
124+
"name": "client",
125+
"type": "bytes",
126+
"indexed": true,
127+
"internalType": "bytes"
128+
},
129+
{
130+
"name": "amount",
131+
"type": "uint256",
132+
"indexed": false,
133+
"internalType": "uint256"
134+
}
135+
],
136+
"anonymous": false
137+
},
138+
{
139+
"type": "error",
140+
"name": "AlreadyHasAllowance",
141+
"inputs": []
142+
},
143+
{
144+
"type": "error",
145+
"name": "AlreadyZero",
146+
"inputs": []
147+
},
148+
{
149+
"type": "error",
150+
"name": "AmountEqualZero",
151+
"inputs": []
152+
},
153+
{
154+
"type": "error",
155+
"name": "FunctionDisabled",
156+
"inputs": []
157+
},
158+
{
159+
"type": "error",
160+
"name": "InsufficientAllowance",
161+
"inputs": []
162+
}
163+
]

src/AllocatorV1.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity 0.8.25;
55
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
66
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
77
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
8-
import {IAllocator} from "./interfaces/IAllocator.sol";
8+
import {IAllocatorV1} from "./interfaces/IAllocatorV1.sol";
99
import {VerifRegAPI} from "filecoin-solidity/contracts/v0.8/VerifRegAPI.sol";
1010
import {VerifRegTypes} from "filecoin-solidity/contracts/v0.8/types/VerifRegTypes.sol";
1111
import {CommonTypes} from "filecoin-solidity/contracts/v0.8/types/CommonTypes.sol";
@@ -20,7 +20,7 @@ import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap
2020
* allowance on the contract, assigned by contract owner.
2121
* @dev Contract is upgradeable via UUPS by contract owner.
2222
*/
23-
contract AllocatorV1 is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IAllocator {
23+
contract AllocatorV1 is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IAllocatorV1 {
2424
using EnumerableMap for EnumerableMap.AddressToUintMap;
2525

2626
/**

src/interfaces/IAllocatorV1.sol

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity 0.8.25;
3+
4+
/**
5+
* @title Interface for Allocator contract
6+
* @notice Definition of core functions and events of the Allocator contract
7+
*/
8+
interface IAllocatorV1 {
9+
/**
10+
* @dev Thrown if caller doesn't have enough allowance for given action
11+
*/
12+
error InsufficientAllowance();
13+
14+
/**
15+
* @dev Thrown if trying to add 0 allowance or grant 0 datacap
16+
*/
17+
error AmountEqualZero();
18+
19+
/**
20+
* @dev Thrown if trying to set allowance bigger than 0 when user has allowance, set allowance to 0 first if you want to set specific value
21+
*/
22+
error AlreadyHasAllowance();
23+
24+
/**
25+
* @dev Thrown if trying to set allowance to 0 when it's already 0
26+
*/
27+
error AlreadyZero();
28+
29+
/**
30+
* @dev Thrown if trying to call disabled function
31+
*/
32+
error FunctionDisabled();
33+
34+
/**
35+
* @notice Emitted when allocator's allowance is changed by manager
36+
* @param allocator Allocator whose allowance has changed
37+
* @param allowanceBefore Allowance before the change
38+
* @param allowanceAfter Allowance after the change
39+
*/
40+
event AllowanceChanged(address indexed allocator, uint256 allowanceBefore, uint256 allowanceAfter);
41+
42+
/**
43+
* @notice Emitted when datacap is granted to a client
44+
* @param allocator Allocator who granted the datacap
45+
* @param client Client that received datacap (Filecoin address)
46+
* @param amount Amount of datacap
47+
*/
48+
event DatacapAllocated(address indexed allocator, bytes indexed client, uint256 amount);
49+
50+
/**
51+
* @notice Get all allocators with non-zero allowance
52+
* @return allocators List of allocators with non-zero allowance
53+
*/
54+
function getAllocators() external view returns (address[] memory allocators);
55+
56+
/**
57+
* @notice Get allowance of an allocator
58+
* @param allocator Allocator to get allowance for
59+
* @return allowance Allocator's allowance
60+
*/
61+
function allowance(address allocator) external view returns (uint256 allowance);
62+
63+
/**
64+
* @notice Add allowance to Allocator
65+
* @param allocator Allocator that will receive allowance
66+
* @param amount Amount of allowance to add
67+
* @dev Emits AllowanceChanged event
68+
* @dev Reverts if not called by contract owner
69+
* @dev Reverts if trying to add 0 allowance
70+
*/
71+
function addAllowance(address allocator, uint256 amount) external;
72+
73+
/**
74+
* @notice Set allowance of an Allocator. Can be used to remove allowance.
75+
* @param allocator Allocator
76+
* @param amount Amount of allowance to set
77+
* @dev Emits AllowanceChanged event
78+
* @dev Reverts if not called by contract owner
79+
* @dev Reverts if setting to 0 when allocator already has 0 allowance
80+
*/
81+
function setAllowance(address allocator, uint256 amount) external;
82+
83+
/**
84+
* @notice Grant allowance to a client.
85+
* @param clientAddress Filecoin address of the client
86+
* @param amount Amount of datacap to grant
87+
* @dev Emits DatacapAllocated event
88+
* @dev Reverts with InsufficientAllowance if caller doesn't have sufficient allowance
89+
*/
90+
function addVerifiedClient(bytes calldata clientAddress, uint256 amount) external;
91+
}

test/Allocator.t.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,15 @@ contract AllocatorTest is Test {
192192
ERC1967Proxy proxy = new ERC1967Proxy(oldImpl, abi.encodeCall(Allocator.initialize, (address(this))));
193193
AllocatorV1 allocatorContract = AllocatorV1(address(proxy));
194194
allocatorContract.addAllowance(vm.addr(1), 100);
195+
address[] memory allocators = allocatorContract.getAllocators();
196+
assertEq(allocators[0], vm.addr(1));
195197
uint256 allowanceBeforeUpdate = allocatorContract.allowance(vm.addr(1));
196198
address newImpl = address(new Allocator());
197199
allocatorContract.upgradeToAndCall(newImpl, "");
198200
uint256 allowanceAfterUpdate = allocatorContract.allowance(vm.addr(1));
199201
assertEq(allowanceBeforeUpdate, allowanceAfterUpdate);
202+
allocators = allocatorContract.getAllocators();
203+
assertEq(allocators[0], vm.addr(1));
200204
}
201205

202206
function testRevertAlreadyZeroAllowance() public {

0 commit comments

Comments
 (0)