Skip to content

Commit 0bef9ad

Browse files
committed
TokenStaking: restricts topUp auto increase to only approved apps (not paused, not disabled)
1 parent c05d8d0 commit 0bef9ad

File tree

2 files changed

+116
-71
lines changed

2 files changed

+116
-71
lines changed

contracts/staking/TokenStaking.sol

+10-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
392392
/// application.
393393
/// @dev Calls `authorizationDecreaseRequested` callback
394394
/// for each authorized application. See `IApplication`.
395-
function requestAuthorizationDecrease(address stakingProvider) external {
395+
function requestAuthorizationDecrease(address stakingProvider)
396+
external
397+
override
398+
{
396399
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
397400
stakingProvider
398401
];
@@ -608,6 +611,12 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
608611
address application = stakingProviderStruct.authorizedApplications[
609612
i
610613
];
614+
require(
615+
applicationInfo[application].status ==
616+
ApplicationStatus.APPROVED,
617+
"Application is not approved"
618+
);
619+
611620
AppAuthorization storage authorization = stakingProviderStruct
612621
.authorizations[application];
613622
uint96 fromAmount = authorization.authorized;

test/staking/TokenStaking.test.js

+106-70
Original file line numberDiff line numberDiff line change
@@ -1984,89 +1984,125 @@ describe("TokenStaking", () => {
19841984
await tToken
19851985
.connect(stakingProvider)
19861986
.approve(tokenStaking.address, topUpAmount)
1987-
tx = await tokenStaking
1988-
.connect(stakingProvider)
1989-
.topUp(stakingProvider.address, topUpAmount)
19901987
})
19911988

1992-
it("should update T staked amount", async () => {
1993-
await assertStake(stakingProvider.address, expectedAmount)
1994-
})
1989+
context("when one of applications is paused", () => {
1990+
it("should revert", async () => {
1991+
await tokenStaking
1992+
.connect(deployer)
1993+
.setPanicButton(application1Mock.address, panicButton.address)
1994+
await tokenStaking
1995+
.connect(panicButton)
1996+
.pauseApplication(application1Mock.address)
19951997

1996-
it("should not increase available amount to authorize", async () => {
1997-
expect(
1998-
await tokenStaking.getAvailableToAuthorize(
1999-
stakingProvider.address,
2000-
application1Mock.address
2001-
)
2002-
).to.equal(0)
2003-
expect(
2004-
await tokenStaking.getAvailableToAuthorize(
2005-
stakingProvider.address,
2006-
application2Mock.address
2007-
)
2008-
).to.equal(amount.sub(authorized2))
1998+
await expect(
1999+
tokenStaking
2000+
.connect(stakingProvider)
2001+
.topUp(stakingProvider.address, topUpAmount)
2002+
).to.be.revertedWith("Application is not approved")
2003+
})
20092004
})
20102005

2011-
it("should increase authorized amount", async () => {
2012-
expect(
2013-
await tokenStaking.getMaxAuthorization(stakingProvider.address)
2014-
).to.equal(expectedAmount)
2015-
})
2006+
context("when one of applications is disabled", () => {
2007+
it("should revert", async () => {
2008+
await tokenStaking
2009+
.connect(deployer)
2010+
.disableApplication(application2Mock.address)
20162011

2017-
it("should emit ToppedUp event", async () => {
2018-
await expect(tx)
2019-
.to.emit(tokenStaking, "ToppedUp")
2020-
.withArgs(stakingProvider.address, topUpAmount)
2012+
await expect(
2013+
tokenStaking
2014+
.connect(stakingProvider)
2015+
.topUp(stakingProvider.address, topUpAmount)
2016+
).to.be.revertedWith("Application is not approved")
2017+
})
20212018
})
20222019

2023-
it("should increase authorized amounts", async () => {
2024-
expect(
2025-
await tokenStaking.authorizedStake(
2026-
stakingProvider.address,
2027-
application1Mock.address
2028-
)
2029-
).to.equal(expectedAmount)
2030-
expect(
2031-
await tokenStaking.authorizedStake(
2032-
stakingProvider.address,
2033-
application2Mock.address
2034-
)
2035-
).to.equal(authorized2.add(topUpAmount))
2036-
})
2020+
context("when all applications are approved", () => {
2021+
beforeEach(async () => {
2022+
tx = await tokenStaking
2023+
.connect(stakingProvider)
2024+
.topUp(stakingProvider.address, topUpAmount)
2025+
})
20372026

2038-
it("should inform application", async () => {
2039-
await assertApplicationStakingProviders(
2040-
application1Mock,
2041-
stakingProvider.address,
2042-
expectedAmount,
2043-
Zero
2044-
)
2045-
await assertApplicationStakingProviders(
2046-
application2Mock,
2047-
stakingProvider.address,
2048-
authorized2.add(topUpAmount),
2049-
Zero
2050-
)
2051-
})
2027+
it("should update T staked amount", async () => {
2028+
await assertStake(stakingProvider.address, expectedAmount)
2029+
})
20522030

2053-
it("should emit AuthorizationIncreased", async () => {
2054-
await expect(tx)
2055-
.to.emit(tokenStaking, "AuthorizationIncreased")
2056-
.withArgs(
2031+
it("should not increase available amount to authorize", async () => {
2032+
expect(
2033+
await tokenStaking.getAvailableToAuthorize(
2034+
stakingProvider.address,
2035+
application1Mock.address
2036+
)
2037+
).to.equal(0)
2038+
expect(
2039+
await tokenStaking.getAvailableToAuthorize(
2040+
stakingProvider.address,
2041+
application2Mock.address
2042+
)
2043+
).to.equal(amount.sub(authorized2))
2044+
})
2045+
2046+
it("should increase authorized amount", async () => {
2047+
expect(
2048+
await tokenStaking.getMaxAuthorization(stakingProvider.address)
2049+
).to.equal(expectedAmount)
2050+
})
2051+
2052+
it("should emit ToppedUp event", async () => {
2053+
await expect(tx)
2054+
.to.emit(tokenStaking, "ToppedUp")
2055+
.withArgs(stakingProvider.address, topUpAmount)
2056+
})
2057+
2058+
it("should increase authorized amounts", async () => {
2059+
expect(
2060+
await tokenStaking.authorizedStake(
2061+
stakingProvider.address,
2062+
application1Mock.address
2063+
)
2064+
).to.equal(expectedAmount)
2065+
expect(
2066+
await tokenStaking.authorizedStake(
2067+
stakingProvider.address,
2068+
application2Mock.address
2069+
)
2070+
).to.equal(authorized2.add(topUpAmount))
2071+
})
2072+
2073+
it("should inform application", async () => {
2074+
await assertApplicationStakingProviders(
2075+
application1Mock,
20572076
stakingProvider.address,
2058-
application1Mock.address,
2059-
authorized1,
2060-
expectedAmount
2077+
expectedAmount,
2078+
Zero
20612079
)
2062-
await expect(tx)
2063-
.to.emit(tokenStaking, "AuthorizationIncreased")
2064-
.withArgs(
2080+
await assertApplicationStakingProviders(
2081+
application2Mock,
20652082
stakingProvider.address,
2066-
application2Mock.address,
2067-
authorized2,
2068-
authorized2.add(topUpAmount)
2083+
authorized2.add(topUpAmount),
2084+
Zero
20692085
)
2086+
})
2087+
2088+
it("should emit AuthorizationIncreased", async () => {
2089+
await expect(tx)
2090+
.to.emit(tokenStaking, "AuthorizationIncreased")
2091+
.withArgs(
2092+
stakingProvider.address,
2093+
application1Mock.address,
2094+
authorized1,
2095+
expectedAmount
2096+
)
2097+
await expect(tx)
2098+
.to.emit(tokenStaking, "AuthorizationIncreased")
2099+
.withArgs(
2100+
stakingProvider.address,
2101+
application2Mock.address,
2102+
authorized2,
2103+
authorized2.add(topUpAmount)
2104+
)
2105+
})
20702106
})
20712107
})
20722108
})
@@ -2130,7 +2166,7 @@ describe("TokenStaking", () => {
21302166
.toggleAutoAuthorizationIncrease(stakingProvider.address)
21312167
})
21322168

2133-
it("should enable auto increase flag", async () => {
2169+
it("should disable auto increase flag", async () => {
21342170
expect(
21352171
await tokenStaking.getAutoIncreaseFlag(stakingProvider.address)
21362172
).to.equal(false)

0 commit comments

Comments
 (0)