Skip to content

Commit d11ed98

Browse files
authored
Merge pull request #110 from threshold-network/permit-top-up
Allow anyone to top-up any staking provider with liquid T
2 parents d7f61f2 + 2a405be commit d11ed98

File tree

4 files changed

+13
-34
lines changed

4 files changed

+13
-34
lines changed

contracts/staking/IStaking.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ interface IStaking {
181181
//
182182

183183
/// @notice Increases the amount of the stake for the given staking provider.
184-
/// Can be called only by the owner or the staking provider.
185184
/// @dev The sender of this transaction needs to have the amount approved to
186185
/// transfer to the staking contract.
187186
function topUp(address stakingProvider, uint96 amount) external;

contracts/staking/TokenStaking.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,13 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
714714
//
715715

716716
/// @notice Increases the amount of the stake for the given staking provider.
717-
/// Can be called only by the owner or the staking provider.
718717
/// @dev The sender of this transaction needs to have the amount approved to
719718
/// transfer to the staking contract.
720-
function topUp(address stakingProvider, uint96 amount)
721-
external
722-
override
723-
onlyOwnerOrStakingProvider(stakingProvider)
724-
{
719+
function topUp(address stakingProvider, uint96 amount) external override {
720+
require(
721+
stakingProviders[stakingProvider].owner != address(0),
722+
"Nothing to top-up"
723+
);
725724
require(amount > 0, "Parameters must be specified");
726725
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
727726
stakingProvider

docs/rfc-1-staking-contract.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ protect against DoSing slashing queue. Can only be called by the governance.
389389

390390
=== Stake top-up
391391

392-
==== `topUp(address stakingProvider, uint96 amount) external onlyOwnerOrStakingProvider(stakingProvider)`
392+
==== `topUp(address stakingProvider, uint96 amount) external`
393393

394394
Increases the amount of the stake for the given staking provider. The sender of this
395395
transaction needs to have the amount approved to transfer to the staking
396-
contract. Can be called only by the owner or staking provider.
396+
contract.
397397

398398
==== `topUpKeep(address stakingProvider) external onlyOwnerOrStakingProvider(stakingProvider)`
399399

test/staking/TokenStaking.test.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,28 +2730,7 @@ describe("TokenStaking", () => {
27302730
tokenStaking
27312731
.connect(stakingProvider)
27322732
.topUp(stakingProvider.address, initialStakerBalance)
2733-
).to.be.revertedWith("Not owner or provider")
2734-
})
2735-
})
2736-
2737-
context("when caller is not owner or staking provider", () => {
2738-
it("should revert", async () => {
2739-
await tToken
2740-
.connect(staker)
2741-
.approve(tokenStaking.address, initialStakerBalance)
2742-
await tokenStaking
2743-
.connect(staker)
2744-
.stake(
2745-
stakingProvider.address,
2746-
staker.address,
2747-
staker.address,
2748-
initialStakerBalance
2749-
)
2750-
await expect(
2751-
tokenStaking
2752-
.connect(authorizer)
2753-
.topUp(stakingProvider.address, initialStakerBalance)
2754-
).to.be.revertedWith("Not owner or provider")
2733+
).to.be.revertedWith("Nothing to top-up")
27552734
})
27562735
})
27572736

@@ -2938,10 +2917,12 @@ describe("TokenStaking", () => {
29382917
await tokenStaking
29392918
.connect(staker)
29402919
.delegateVoting(stakingProvider.address, delegatee.address)
2941-
await tToken.connect(deployer).transfer(staker.address, topUpAmount)
2942-
await tToken.connect(staker).approve(tokenStaking.address, topUpAmount)
2920+
await tToken.connect(deployer).transfer(authorizer.address, topUpAmount)
2921+
await tToken
2922+
.connect(authorizer)
2923+
.approve(tokenStaking.address, topUpAmount)
29432924
tx = await tokenStaking
2944-
.connect(staker)
2925+
.connect(authorizer)
29452926
.topUp(stakingProvider.address, topUpAmount)
29462927
})
29472928

0 commit comments

Comments
 (0)