Skip to content

Commit

Permalink
Merge branch 'fix/moonbase-delegation-limits' into 'develop'
Browse files Browse the repository at this point in the history
Fix/moonbase delegation limits

See merge request papers/airgap/airgap-coin-lib!526
  • Loading branch information
godenzim committed Oct 26, 2021
2 parents 25be61f + b4a1d3b commit 37956d1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "0.12.1",
"version": "0.12.2",
"command": {
"publish": {
"ignoreChanges": ["*.sh", "*.md", "*.yml", ".*", "tsconfig.json", "tslint.json"]
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/coinlib-core",
"version": "0.12.1",
"version": "0.12.2",
"description": "The @airgap/coinlib-core is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.",
"keywords": [
"airgap",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,14 @@ export abstract class MoonbeamProtocol extends SubstrateDelegateProtocol<Substra
const results = await Promise.all([
this.options.accountController.getNominatorDetails(publicKey),
this.options.accountController.getCollatorDetails(collator),
this.options.nodeClient.getMaxNominatorsPerCollator(),
this.options.nodeClient.getMaxCollatorsPerNominator(),
this.getBalanceOfPublicKey(publicKey)
])

const nominatorDetails = results[0]
const collatorDetails = results[1]
const maxNominators = results[2]
const maxCollators = results[3]
const balance = results[4]

if (maxNominators?.lte(collatorDetails.nominators)) {
throw new ConditionViolationError(Domain.SUBSTRATE, 'This collator cannot have more nominators.')
}
const maxCollators = results[2]
const balance = results[3]

if (maxCollators?.lte(nominatorDetails.delegatees.length)) {
throw new ConditionViolationError(Domain.SUBSTRATE, 'This nominator cannot nominate more collators.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ export class MoonbeamAccountController extends SubstrateAccountController<Substr
status = 'Leaving'
}

// top nominators are already sorted (https://github.com/PureStake/moonbeam/blob/v0.13.2/pallets/parachain-staking/src/lib.rs#L152)
const topNominations = collatorState.topNominators.elements.map((bond) => bond.amount.value)

return {
address: address.getValue(),
status,
minEligibleBalance: topNominations[topNominations.length - 1].toString(),
ownStakingBalance: collatorState.bond.toString(),
totalStakingBalance: collatorState.totalBacking.toString(),
commission: commission.dividedBy(1_000_000_000).toString(), // commission is Perbill (parts per billion)
Expand Down Expand Up @@ -181,16 +185,10 @@ export class MoonbeamAccountController extends SubstrateAccountController<Substr
private async getStakingActions(nominations: MoonbeamBond[], collator?: MoonbeamCollatorDetails): Promise<DelegatorAction[]> {
const actions: DelegatorAction[] = []

const results = await Promise.all([this.nodeClient.getMaxNominatorsPerCollator(), this.nodeClient.getMaxCollatorsPerNominator()])

const maxNominators = results[0]
const maxCollators = results[1]
const maxCollators = await this.nodeClient.getMaxCollatorsPerNominator()

const canNominateCollator =
maxCollators?.gt(nominations.length) &&
maxNominators?.gt(collator?.nominators ?? 0) &&
collator &&
!nominations.some((bond) => bond.owner.compare(collator.address) === 0)
maxCollators?.gt(nominations.length) && collator && !nominations.some((bond) => bond.owner.compare(collator.address) === 0)

const isNominatingCollator = collator && nominations.some((bond) => bond.owner.compare(collator.address) === 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DelegateeDetails } from '../../../../ICoinDelegateProtocol'

export interface MoonbeamCollatorDetails extends DelegateeDetails {
status?: 'Active' | 'Idle' | 'Leaving'
minEligibleBalance: string
ownStakingBalance: string
totalStakingBalance: string
commission: string
Expand Down

0 comments on commit 37956d1

Please sign in to comment.