-
Notifications
You must be signed in to change notification settings - Fork 34
Refactor burn native tokens method #123
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
67e94dd
Add Ownable package for contants manager
Mike-CZ 3742645
Add collection of failed treasury fees
Mike-CZ eeddd39
Add storage gaps into upgradeable contracts
Mike-CZ b3c273c
Apply Checks-Effects-Interactions pattern
Mike-CZ bf8fa72
Merge branch 'refs/heads/mike/retreive_collected_fees' into mike/stor…
Mike-CZ d1726a4
Add penalty into `Withdrawn` event
Mike-CZ 34f4108
Add option to issue tokens
Mike-CZ 56d591e
Update Withdrawn event in interface
Mike-CZ 57ecc32
Merge branch 'refs/heads/mike/withdraw_event' into mike/issue_tokens
Mike-CZ e36a4cd
Remove redundant `issueTokens` method on `NodeDriverAuth`
Mike-CZ 7c57e0e
Disable initializers to be called directly
Mike-CZ 4e77902
Refactor burn native tokens method
Mike-CZ de08380
Add revert into burn method
Mike-CZ 6227803
Lint fixes
Mike-CZ c35adbe
Merge branch 'refs/heads/main' into mike/burn_native_tokens
Mike-CZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -152,6 +152,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version { | |
| // values | ||
| error ZeroAmount(); | ||
| error ZeroRewards(); | ||
| error ValueTooLarge(); | ||
|
|
||
| // pubkeys | ||
| error PubkeyUsedByOtherValidator(); | ||
|
|
@@ -216,7 +217,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version { | |
| ); | ||
| event ClaimedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards); | ||
| event RestakedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards); | ||
| event BurntFTM(uint256 amount); | ||
| event BurntNativeTokens(uint256 amount); | ||
| event UpdatedSlashingRefundRatio(uint256 indexed validatorID, uint256 refundRatio); | ||
| event RefundedSlashedLegacyDelegation(address indexed delegator, uint256 indexed validatorID, uint256 amount); | ||
| event AnnouncedRedirection(address indexed from, address indexed to); | ||
|
|
@@ -459,9 +460,12 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version { | |
| emit TreasuryFeesResolved(fees); | ||
| } | ||
|
|
||
| /// burnFTM allows SFC to burn an arbitrary amount of FTM tokens. | ||
| function burnFTM(uint256 amount) external onlyOwner { | ||
| _burnFTM(amount); | ||
| /// Burn native tokens by sending them to the SFC contract. | ||
| function burnNativeTokens() external payable { | ||
| if (msg.value == 0) { | ||
| revert ZeroAmount(); | ||
| } | ||
| _burnNativeTokens(msg.value); | ||
| } | ||
|
|
||
| /// Issue tokens to the issued tokens recipient as a counterparty to the burnt FTM tokens. | ||
|
|
@@ -753,7 +757,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version { | |
| if (!sent) { | ||
| revert TransferFailed(); | ||
| } | ||
| _burnFTM(penalty); | ||
| _burnNativeTokens(penalty); | ||
|
|
||
| emit Withdrawn(delegator, toValidatorID, wrID, amount - penalty, penalty); | ||
| } | ||
|
|
@@ -817,12 +821,16 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version { | |
| return rewards; | ||
| } | ||
|
|
||
| /// Burn FTM tokens. | ||
| /// Burn native tokens. | ||
| /// The tokens are sent to the zero address. | ||
| function _burnFTM(uint256 amount) internal { | ||
| function _burnNativeTokens(uint256 amount) internal { | ||
| if (amount != 0) { | ||
| if (amount > totalSupply) { | ||
| revert ValueTooLarge(); | ||
| } | ||
| totalSupply -= amount; | ||
| payable(address(0)).transfer(amount); | ||
| emit BurntFTM(amount); | ||
| emit BurntNativeTokens(amount); | ||
|
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. you could also use call instead of transfer
Collaborator
Author
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. this is pending in #111 |
||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.