-
Notifications
You must be signed in to change notification settings - Fork 47
feat(node): support configurable staking collateral token #1130
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
Changes from 35 commits
49555f7
5697ee4
2e7761c
43ee469
d961819
05d1095
9f00973
7102a78
92a1dc4
2cec1a7
374a7df
6057dd8
e89c069
4c6000c
0bfa4ec
cccf84e
19d6158
07f7182
80db07b
4743a12
4fc0e73
3dcacd0
9388b24
ee3a9a5
6d2cc3a
4c7e013
8e6e1e8
c997cba
7f2cb84
d91dc44
5e7fc74
b868fd1
012fa69
6626ee3
b3b3516
6a0e65c
7cc73c3
ea5e69a
78443ea
71cae9f
c6820a4
587552f
bdbbc6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,8 @@ import {SubnetActorGetterFacet} from "../subnet/SubnetActorGetterFacet.sol"; | |
| import {BURNT_FUNDS_ACTOR} from "../constants/Constants.sol"; | ||
| import {IpcEnvelope} from "../structs/CrossNet.sol"; | ||
| import {FvmAddress} from "../structs/FvmAddress.sol"; | ||
| import {SubnetID, Subnet, SupplySource} from "../structs/Subnet.sol"; | ||
| import {Membership, SupplyKind} from "../structs/Subnet.sol"; | ||
| import {SubnetID, Subnet, Asset} from "../structs/Subnet.sol"; | ||
| import {Membership, AssetKind} from "../structs/Subnet.sol"; | ||
| import {AlreadyRegisteredSubnet, CannotReleaseZero, MethodNotAllowed, NotEnoughFunds, NotEnoughFundsToRelease, NotEnoughCollateral, NotEmptySubnetCircSupply, NotRegisteredSubnet, InvalidXnetMessage, InvalidXnetMessageReason} from "../errors/IPCErrors.sol"; | ||
| import {LibGateway} from "../lib/LibGateway.sol"; | ||
| import {SubnetIDHelper} from "../lib/SubnetIDHelper.sol"; | ||
|
|
@@ -16,31 +16,34 @@ import {FilAddress} from "fevmate/contracts/utils/FilAddress.sol"; | |
| import {ReentrancyGuard} from "../lib/LibReentrancyGuard.sol"; | ||
| import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
| import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
| import {SupplySourceHelper} from "../lib/SupplySourceHelper.sol"; | ||
| import {AssetHelper} from "../lib/AssetHelper.sol"; | ||
| import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
|
|
||
| string constant ERR_CHILD_SUBNET_NOT_ALLOWED = "Subnet does not allow child subnets"; | ||
|
|
||
| contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | ||
| using FilAddress for address payable; | ||
| using SubnetIDHelper for SubnetID; | ||
| using SupplySourceHelper for SupplySource; | ||
| using AssetHelper for Asset; | ||
| using EnumerableSet for EnumerableSet.Bytes32Set; | ||
|
|
||
| /// @notice register a subnet in the gateway. It is called by a subnet when it reaches the threshold stake | ||
| /// @dev The subnet can optionally pass a genesis circulating supply that would be pre-allocated in the | ||
| /// subnet from genesis (without having to wait for the subnet to be spawned to propagate the funds). | ||
| function register(uint256 genesisCircSupply) external payable { | ||
| function register(uint256 genesisCircSupply, uint256 collateral) external payable { | ||
| // If L2+ support is not enabled, only allow the registration of new | ||
| // subnets in the root | ||
| if (s.networkName.route.length + 1 >= s.maxTreeDepth) { | ||
| revert MethodNotAllowed(ERR_CHILD_SUBNET_NOT_ALLOWED); | ||
| } | ||
|
|
||
| if (msg.value < genesisCircSupply) { | ||
| revert NotEnoughFunds(); | ||
| if (genesisCircSupply > 0) { | ||
| SubnetActorGetterFacet(msg.sender).supplySource().lock(genesisCircSupply); | ||
| } | ||
| if (collateral > 0) { | ||
| SubnetActorGetterFacet(msg.sender).collateralSource().lock(collateral); | ||
|
Comment on lines
+40
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would support dropping this feature entirely: #1142 |
||
| } | ||
| uint256 collateral = msg.value - genesisCircSupply; | ||
cryptoAtwill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SubnetID memory subnetId = s.networkName.createSubnetId(msg.sender); | ||
|
|
||
| (bool registered, Subnet storage subnet) = LibGateway.getSubnet(subnetId); | ||
|
|
@@ -58,18 +61,20 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | |
| } | ||
|
|
||
| /// @notice addStake - add collateral for an existing subnet | ||
| function addStake() external payable { | ||
| if (msg.value == 0) { | ||
| function addStake(uint256 amount) external payable { | ||
| if (amount == 0) { | ||
| revert NotEnoughFunds(); | ||
| } | ||
|
|
||
| SubnetActorGetterFacet(msg.sender).collateralSource().lock(amount); | ||
|
|
||
| (bool registered, Subnet storage subnet) = LibGateway.getSubnet(msg.sender); | ||
|
|
||
| if (!registered) { | ||
| revert NotRegisteredSubnet(); | ||
| } | ||
|
|
||
| subnet.stake += msg.value; | ||
| subnet.stake += amount; | ||
| } | ||
|
|
||
| /// @notice release collateral for an existing subnet. | ||
|
|
@@ -90,8 +95,7 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | |
| } | ||
|
|
||
| subnet.stake -= amount; | ||
|
|
||
| payable(subnet.id.getActor()).sendValue(amount); | ||
| SubnetActorGetterFacet(msg.sender).collateralSource().transferFunds(payable(msg.sender), amount); | ||
cryptoAtwill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// @notice kill an existing subnet. | ||
|
|
@@ -114,8 +118,7 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | |
| delete s.subnets[id]; | ||
|
|
||
| s.subnetKeys.remove(id); | ||
|
|
||
| payable(msg.sender).sendValue(stake); | ||
| SubnetActorGetterFacet(msg.sender).collateralSource().transferFunds(payable(msg.sender), stake); | ||
| } | ||
|
|
||
| /// @notice credits the received value to the specified address in the specified child subnet. | ||
|
|
@@ -137,8 +140,8 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | |
| } | ||
|
|
||
| // Validate that the supply strategy is native. | ||
| SupplySource memory supplySource = SubnetActorGetterFacet(subnetId.getActor()).supplySource(); | ||
| supplySource.expect(SupplyKind.Native); | ||
| Asset memory supplySource = SubnetActorGetterFacet(subnetId.getActor()).supplySource(); | ||
| supplySource.expect(AssetKind.Native); | ||
|
|
||
| IpcEnvelope memory crossMsg = CrossMsgHelper.createFundMsg({ | ||
| subnet: subnetId, | ||
|
|
@@ -172,8 +175,8 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | |
| // Check that the supply strategy is ERC20. | ||
| // There is no need to check whether the subnet exists. If it doesn't exist, the call to getter will revert. | ||
| // LibGateway.commitTopDownMsg will also revert if the subnet doesn't exist. | ||
| SupplySource memory supplySource = SubnetActorGetterFacet(subnetId.getActor()).supplySource(); | ||
| supplySource.expect(SupplyKind.ERC20); | ||
| Asset memory supplySource = SubnetActorGetterFacet(subnetId.getActor()).supplySource(); | ||
| supplySource.expect(AssetKind.ERC20); | ||
|
|
||
| // Locks a specified amount into custody, adjusting for tokens with transfer fees. This operation | ||
| // accommodates inflationary tokens, potentially reflecting a higher effective locked amount. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error type is not needed as it doesn't provide more information than a revert with a string message.