-
Couldn't load subscription status.
- Fork 81
WalletRegistry.seize function implemented #2942
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
7 commits
Select commit
Hold shift + click to select a range
b704383
WalletRegistry.seize function implemented
pdyraga 77faca6
@threshold-network/solidity-contracts for ecdsa updated to >1.2.0-dev
pdyraga a5a83e7
Adjusted WalletRegistry authorization unit tests to changes in stakin…
pdyraga ebde333
seize function added to IWalletRegistry interface
pdyraga d3b42be
Make it clear in docs WalletRegistry.seize may revert
pdyraga 8d77f01
Merge branch 'main' into ecdsa-slashing
pdyraga 79272f7
Added a TODO for a unit test covering reverting seize call
pdyraga 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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /* eslint-disable no-await-in-loop */ | ||
| import { helpers } from "hardhat" | ||
| import { expect } from "chai" | ||
| import { to1e18 } from "@keep-network/hardhat-helpers/dist/src/number" | ||
|
|
||
| import ecdsaData from "./data/ecdsa" | ||
| import { constants, walletRegistryFixture } from "./fixtures" | ||
| import { createNewWallet } from "./utils/wallets" | ||
|
|
||
| import type { | ||
| WalletRegistry, | ||
| IWalletOwner, | ||
| TokenStaking, | ||
| T, | ||
| } from "../typechain" | ||
| import type { FakeContract } from "@defi-wonderland/smock" | ||
| import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers" | ||
| import type { Operator, OperatorID } from "./utils/operators" | ||
|
|
||
| const { createSnapshot, restoreSnapshot } = helpers.snapshot | ||
|
|
||
| describe("WalletRegistry - Slashing", () => { | ||
| let walletRegistry: WalletRegistry | ||
| let walletOwner: FakeContract<IWalletOwner> | ||
| let thirdParty: SignerWithAddress | ||
| let staking: TokenStaking | ||
| let tToken: T | ||
|
|
||
| let members: Operator[] | ||
| let membersIDs: OperatorID[] | ||
| let membersAddresses: string[] | ||
| let walletID: string | ||
|
|
||
| const walletPublicKey: string = ecdsaData.group1.publicKey | ||
| const amountToSlash = to1e18(1000) | ||
| const rewardMultiplier = 30 | ||
|
|
||
| before(async () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-extra-semi | ||
| ;({ walletRegistry, walletOwner, thirdParty, staking, tToken } = | ||
| await walletRegistryFixture()) | ||
| ;({ walletID, members } = await createNewWallet( | ||
| walletRegistry, | ||
| walletOwner.wallet, | ||
| walletPublicKey | ||
| )) | ||
|
|
||
| membersIDs = members.map((member) => member.id) | ||
| membersAddresses = members.map((member) => member.signer.address) | ||
| }) | ||
|
|
||
| describe("seize", () => { | ||
| context("when called not by the wallet owner", () => { | ||
| it("should revert", async () => { | ||
| await expect( | ||
| walletRegistry | ||
| .connect(thirdParty) | ||
| .seize( | ||
| amountToSlash, | ||
| rewardMultiplier, | ||
| thirdParty.address, | ||
| walletID, | ||
| membersIDs | ||
| ) | ||
| ).to.be.revertedWith("Caller is not the Wallet Owner") | ||
| }) | ||
| }) | ||
|
|
||
| context("when called by the wallet owner", () => { | ||
| context("when the passed wallet members identifiers are invalid", () => { | ||
| it("should revert", async () => { | ||
| const corruptedMembersIDs = membersIDs.slice().reverse() | ||
| await expect( | ||
| walletRegistry | ||
| .connect(walletOwner.wallet) | ||
| .seize( | ||
| amountToSlash, | ||
| rewardMultiplier, | ||
| thirdParty.address, | ||
| walletID, | ||
| corruptedMembersIDs | ||
| ) | ||
| ).to.be.revertedWith("Invalid wallet members identifiers") | ||
| }) | ||
| }) | ||
|
|
||
| context("when the passed wallet members identifiers are valid", () => { | ||
| let notifierBalanceBefore | ||
| let notifierBalanceAfter | ||
|
|
||
| before(async () => { | ||
| await createSnapshot() | ||
|
|
||
| notifierBalanceBefore = await tToken.balanceOf(thirdParty.address) | ||
| await walletRegistry | ||
| .connect(walletOwner.wallet) | ||
| .seize( | ||
| amountToSlash, | ||
| rewardMultiplier, | ||
| thirdParty.address, | ||
| walletID, | ||
| membersIDs | ||
| ) | ||
| notifierBalanceAfter = await tToken.balanceOf(thirdParty.address) | ||
| }) | ||
|
|
||
| after(async () => { | ||
| await restoreSnapshot() | ||
| }) | ||
|
|
||
| it("should slash all group members", async () => { | ||
| expect(await staking.getSlashingQueueLength()).to.equal( | ||
| constants.groupSize | ||
| ) | ||
| }) | ||
|
|
||
| it("should slash with correct amounts", async () => { | ||
| for (let i = 0; i < constants.groupSize; i++) { | ||
| const slashing = await staking.slashingQueue(i) | ||
| expect(slashing.amount).to.equal(amountToSlash) | ||
| } | ||
| }) | ||
|
|
||
| it("should slash correct staking providers", async () => { | ||
| for (let i = 0; i < constants.groupSize; i++) { | ||
| const slashing = await staking.slashingQueue(i) | ||
| const expectedStakingProvider = | ||
| await walletRegistry.operatorToStakingProvider( | ||
| membersAddresses[i] | ||
| ) | ||
|
|
||
| expect(slashing.stakingProvider).to.equal(expectedStakingProvider) | ||
| } | ||
| }) | ||
|
|
||
| it("should send correct reward to notifier", async () => { | ||
| // reward multiplier is in % so we first multiply and then divide by | ||
| // 100 to get the actual number | ||
| const perMemberReward = constants.tokenStakingNotificationReward | ||
| .mul(rewardMultiplier) | ||
| .div(100) | ||
|
|
||
| const receivedReward = notifierBalanceAfter.sub(notifierBalanceBefore) | ||
|
|
||
| expect(receivedReward).to.equal( | ||
| perMemberReward.mul(constants.groupSize) | ||
| ) | ||
| }) | ||
| }) | ||
nkuba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // TODO: Add a unit test ensuring `seize` call reverts if the staking | ||
| // contract `seize` call reverts. | ||
| // Currently blocked by https://github.com/defi-wonderland/smock/issues/101 | ||
| // See https://github.com/keep-network/keep-core/issues/2870 | ||
| }) | ||
| }) | ||
| }) | ||
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
Oops, something went wrong.
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.