Skip to content

Commit e94f75e

Browse files
authored
perf: burn with FVMPay (#296)
Reviewer @rvagg Similar to FilOzone/pdp#207 and FilOzone/filecoin-pay#234 #### Changes * burn with fvm pay * mock with MockFVMTest
1 parent 0a15c43 commit e94f75e

9 files changed

+32
-38
lines changed

service_contracts/abi/ServiceProviderRegistry.abi.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@
44
"inputs": [],
55
"stateMutability": "nonpayable"
66
},
7-
{
8-
"type": "function",
9-
"name": "BURN_ACTOR",
10-
"inputs": [],
11-
"outputs": [
12-
{
13-
"name": "",
14-
"type": "address",
15-
"internalType": "address"
16-
}
17-
],
18-
"stateMutability": "view"
19-
},
207
{
218
"type": "function",
229
"name": "MAX_CAPABILITIES",

service_contracts/foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ remappings = [
1818
'@fws-payments/=lib/fws-payments/src/',
1919
'@pdp/=lib/pdp/src/',
2020
'@session-key-registry/=lib/session-key-registry/src/',
21+
'@fvm-solidity/=lib/pdp/lib/fvm-solidity/src/',
2122
'@pythnetwork/pyth-sdk-solidity/=lib/pdp/lib/pyth-sdk-solidity/',
2223
]
2324

service_contracts/src/ServiceProviderRegistry.sol

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22
pragma solidity ^0.8.20;
33

4+
import {FVMPay} from "@fvm-solidity/FVMPay.sol";
45
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
56
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
67
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@@ -47,9 +48,6 @@ contract ServiceProviderRegistry is
4748
/// @notice Maximum length for location field
4849
uint256 private constant MAX_LOCATION_LENGTH = 128;
4950

50-
/// @notice Burn actor address for burning FIL
51-
address public constant BURN_ACTOR = 0xff00000000000000000000000000000000000063;
52-
5351
/// @notice Registration fee in attoFIL (5 FIL = 5 * 10^18 attoFIL)
5452
uint256 public constant REGISTRATION_FEE = 5e18;
5553

@@ -185,8 +183,7 @@ contract ServiceProviderRegistry is
185183
emit ProductAdded(providerId, productType, msg.sender, productData, capabilityKeys, capabilityValues);
186184

187185
// Burn the registration fee
188-
(bool burnSuccess,) = BURN_ACTOR.call{value: REGISTRATION_FEE}("");
189-
require(burnSuccess, "Burn failed");
186+
require(FVMPay.burn(REGISTRATION_FEE), "Burn failed");
190187
}
191188

192189
/// @notice Add a new product to an existing provider

service_contracts/test/FilecoinWarmStorageService.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4-
import {Test, console, Vm} from "forge-std/Test.sol";
4+
import {MockFVMTest} from "@fvm-solidity/mocks/MockFVMTest.sol";
5+
import {console, Test, Vm} from "forge-std/Test.sol";
56
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
67
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
78
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
@@ -21,7 +22,7 @@ import {Errors} from "../src/Errors.sol";
2122
import {ServiceProviderRegistryStorage} from "../src/ServiceProviderRegistryStorage.sol";
2223
import {ServiceProviderRegistry} from "../src/ServiceProviderRegistry.sol";
2324

24-
contract FilecoinWarmStorageServiceTest is Test {
25+
contract FilecoinWarmStorageServiceTest is MockFVMTest {
2526
using SafeERC20 for MockERC20;
2627
using FilecoinWarmStorageServiceStateLibrary for FilecoinWarmStorageService;
2728
// Testing Constants
@@ -92,7 +93,8 @@ contract FilecoinWarmStorageServiceTest is Test {
9293
bytes extraData;
9394
}
9495

95-
function setUp() public {
96+
function setUp() public override {
97+
super.setUp();
9698
// Setup test accounts
9799
deployer = address(this);
98100
client = address(0xf1);

service_contracts/test/FilecoinWarmStorageServiceOwner.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4-
import {Test, console} from "forge-std/Test.sol";
4+
import {MockFVMTest} from "@fvm-solidity/mocks/MockFVMTest.sol";
5+
import {console} from "forge-std/Test.sol";
56
import {FilecoinWarmStorageService} from "../src/FilecoinWarmStorageService.sol";
67
import {FilecoinWarmStorageServiceStateView} from "../src/FilecoinWarmStorageServiceStateView.sol";
78
import {ServiceProviderRegistry} from "../src/ServiceProviderRegistry.sol";
@@ -15,7 +16,7 @@ import {Errors} from "../src/Errors.sol";
1516
import {MockERC20, MockPDPVerifier} from "./mocks/SharedMocks.sol";
1617
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1718

18-
contract FilecoinWarmStorageServiceOwnerTest is Test {
19+
contract FilecoinWarmStorageServiceOwnerTest is MockFVMTest {
1920
using SafeERC20 for MockERC20;
2021

2122
// Constants
@@ -49,7 +50,8 @@ contract FilecoinWarmStorageServiceOwnerTest is Test {
4950
uint256 indexed dataSetId, address indexed oldServiceProvider, address indexed newServiceProvider
5051
);
5152

52-
function setUp() public {
53+
function setUp() public override {
54+
super.setUp();
5355
// Setup accounts
5456
owner = address(this);
5557
client = address(0x1);

service_contracts/test/ProviderValidation.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4-
import {Test} from "forge-std/Test.sol";
4+
import {MockFVMTest} from "@fvm-solidity/mocks/MockFVMTest.sol";
55
import {FilecoinPayV1} from "@fws-payments/FilecoinPayV1.sol";
66
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
@@ -16,7 +16,7 @@ import {ServiceProviderRegistryStorage} from "../src/ServiceProviderRegistryStor
1616
import {MockERC20, MockPDPVerifier} from "./mocks/SharedMocks.sol";
1717
import {Errors} from "../src/Errors.sol";
1818

19-
contract ProviderValidationTest is Test {
19+
contract ProviderValidationTest is MockFVMTest {
2020
using SafeERC20 for MockERC20;
2121

2222
FilecoinWarmStorageService public warmStorage;
@@ -40,7 +40,8 @@ contract ProviderValidationTest is Test {
4040
uint8(27)
4141
);
4242

43-
function setUp() public {
43+
function setUp() public override {
44+
super.setUp();
4445
owner = address(this);
4546
provider1 = address(0x1);
4647
provider2 = address(0x2);

service_contracts/test/ServiceProviderRegistry.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import {Test} from "forge-std/Test.sol";
4+
import {MockFVMTest} from "@fvm-solidity/mocks/MockFVMTest.sol";
55
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
66
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77

88
import {ServiceProviderRegistry} from "../src/ServiceProviderRegistry.sol";
99
import {ServiceProviderRegistryStorage} from "../src/ServiceProviderRegistryStorage.sol";
1010

11-
contract ServiceProviderRegistryTest is Test {
11+
contract ServiceProviderRegistryTest is MockFVMTest {
1212
ServiceProviderRegistry public implementation;
1313
ServiceProviderRegistry public registry;
1414
address public owner;
1515
address public user1;
1616
address public user2;
1717

18-
function setUp() public {
18+
function setUp() public override {
19+
super.setUp();
1920
owner = address(this);
2021
user1 = address(0x1);
2122
user2 = address(0x2);

service_contracts/test/ServiceProviderRegistryFull.t.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import {Test} from "forge-std/Test.sol";
4+
import {BURN_ADDRESS} from "@fvm-solidity/FVMActors.sol";
5+
import {MockFVMTest} from "@fvm-solidity/mocks/MockFVMTest.sol";
56
import {ServiceProviderRegistry} from "../src/ServiceProviderRegistry.sol";
67
import {ServiceProviderRegistryStorage} from "../src/ServiceProviderRegistryStorage.sol";
78
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
89
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
910

10-
contract ServiceProviderRegistryFullTest is Test {
11+
contract ServiceProviderRegistryFullTest is MockFVMTest {
1112
ServiceProviderRegistry public implementation;
1213
ServiceProviderRegistry public registry;
1314

@@ -28,7 +29,8 @@ contract ServiceProviderRegistryFullTest is Test {
2829
bytes public encodedDefaultPDPData;
2930
bytes public encodedUpdatedPDPData;
3031

31-
function setUp() public {
32+
function setUp() public override {
33+
super.setUp();
3234
owner = address(this);
3335
provider1 = address(0x1);
3436
provider2 = address(0x2);
@@ -102,7 +104,7 @@ contract ServiceProviderRegistryFullTest is Test {
102104

103105
function testRegisterProvider() public {
104106
// Check burn actor balance before
105-
uint256 burnActorBalanceBefore = registry.BURN_ACTOR().balance;
107+
uint256 burnActorBalanceBefore = BURN_ADDRESS.balance;
106108

107109
vm.startPrank(provider1);
108110

@@ -214,7 +216,7 @@ contract ServiceProviderRegistryFullTest is Test {
214216
assertEq(datacenterValue, "EU-WEST", "Product first value should be EU-WEST");
215217

216218
// Verify fee was burned
217-
uint256 burnActorBalanceAfter = registry.BURN_ACTOR().balance;
219+
uint256 burnActorBalanceAfter = BURN_ADDRESS.balance;
218220
assertEq(burnActorBalanceAfter - burnActorBalanceBefore, REGISTRATION_FEE, "Fee should be burned");
219221
}
220222

service_contracts/test/ServiceProviderRegistryPagination.t.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22
pragma solidity ^0.8.20;
33

4-
import {Test} from "forge-std/Test.sol";
4+
import {MockFVMTest} from "@fvm-solidity/mocks/MockFVMTest.sol";
55
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
66
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77
import {ServiceProviderRegistry} from "../src/ServiceProviderRegistry.sol";
88
import {ServiceProviderRegistryStorage} from "../src/ServiceProviderRegistryStorage.sol";
99

10-
contract ServiceProviderRegistryPaginationTest is Test {
10+
contract ServiceProviderRegistryPaginationTest is MockFVMTest {
1111
ServiceProviderRegistry public registry;
1212

1313
address public owner = address(0x1);
@@ -24,7 +24,8 @@ contract ServiceProviderRegistryPaginationTest is Test {
2424
ServiceProviderRegistryStorage.PDPOffering public defaultPDPData;
2525
bytes public encodedDefaultPDPData;
2626

27-
function setUp() public {
27+
function setUp() public override {
28+
super.setUp();
2829
vm.startPrank(owner);
2930

3031
// Deploy implementation

0 commit comments

Comments
 (0)