Types.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import BN from 'bn.js'
  2. import { ElectionStage, Seat } from '@joystream/types/council'
  3. import { Option } from '@polkadot/types'
  4. import { Codec } from '@polkadot/types/types'
  5. import { BlockNumber, Balance, AccountId } from '@polkadot/types/interfaces'
  6. import { DeriveBalancesAll } from '@polkadot/api-derive/types'
  7. import { KeyringPair } from '@polkadot/keyring/types'
  8. import { WorkerId, OpeningType } from '@joystream/types/working-group'
  9. import { Membership, MemberId } from '@joystream/types/members'
  10. import { Opening, StakingPolicy, ApplicationStageKeys } from '@joystream/types/hiring'
  11. import { Validator } from 'inquirer'
  12. // KeyringPair type extended with mandatory "meta.name"
  13. // It's used for accounts/keys management within CLI.
  14. // If not provided in the account json file, the meta.name value is set to "Unnamed Account"
  15. export type NamedKeyringPair = KeyringPair & {
  16. meta: {
  17. name: string
  18. }
  19. }
  20. // Summary of the account information fetched from the api for "account:current" purposes (currently just balances)
  21. export type AccountSummary = {
  22. balances: DeriveBalancesAll
  23. }
  24. // This function allows us to easily transform the tuple into the object
  25. // and simplifies the creation of consitent Object and Tuple types (seen below).
  26. export function createCouncilInfoObj(
  27. activeCouncil: Seat[],
  28. termEndsAt: BlockNumber,
  29. autoStart: boolean,
  30. newTermDuration: BN,
  31. candidacyLimit: BN,
  32. councilSize: BN,
  33. minCouncilStake: Balance,
  34. minVotingStake: Balance,
  35. announcingPeriod: BlockNumber,
  36. votingPeriod: BlockNumber,
  37. revealingPeriod: BlockNumber,
  38. round: BN,
  39. stage: Option<ElectionStage>
  40. ) {
  41. return {
  42. activeCouncil,
  43. termEndsAt,
  44. autoStart,
  45. newTermDuration,
  46. candidacyLimit,
  47. councilSize,
  48. minCouncilStake,
  49. minVotingStake,
  50. announcingPeriod,
  51. votingPeriod,
  52. revealingPeriod,
  53. round,
  54. stage,
  55. }
  56. }
  57. // Object/Tuple containing council/councilElection information (council:info).
  58. // The tuple is useful, because that's how api.queryMulti returns the results.
  59. export type CouncilInfoTuple = Parameters<typeof createCouncilInfoObj>
  60. export type CouncilInfoObj = ReturnType<typeof createCouncilInfoObj>
  61. // Object with "name" and "value" properties, used for rendering simple CLI tables like:
  62. // Total balance: 100 JOY
  63. // Free calance: 50 JOY
  64. export type NameValueObj = { name: string; value: string }
  65. // Working groups related types
  66. export enum WorkingGroups {
  67. StorageProviders = 'storageProviders',
  68. Curators = 'curators',
  69. }
  70. // In contrast to Pioneer, currently only StorageProviders group is available in CLI
  71. export const AvailableGroups: readonly WorkingGroups[] = [
  72. WorkingGroups.StorageProviders,
  73. WorkingGroups.Curators,
  74. ] as const
  75. export type Reward = {
  76. totalRecieved: Balance
  77. value: Balance
  78. interval?: number
  79. nextPaymentBlock: number // 0 = no incoming payment
  80. }
  81. // Compound working group types
  82. export type GroupMember = {
  83. workerId: WorkerId
  84. memberId: MemberId
  85. roleAccount: AccountId
  86. profile: Membership
  87. stake?: Balance
  88. reward?: Reward
  89. }
  90. export type GroupApplication = {
  91. wgApplicationId: number
  92. applicationId: number
  93. wgOpeningId: number
  94. member: Membership | null
  95. roleAccout: AccountId
  96. stakes: {
  97. application: number
  98. role: number
  99. }
  100. humanReadableText: string
  101. stage: ApplicationStageKeys
  102. }
  103. export enum OpeningStatus {
  104. WaitingToBegin = 'WaitingToBegin',
  105. AcceptingApplications = 'AcceptingApplications',
  106. InReview = 'InReview',
  107. Complete = 'Complete',
  108. Cancelled = 'Cancelled',
  109. Unknown = 'Unknown',
  110. }
  111. export type GroupOpeningStage = {
  112. status: OpeningStatus
  113. block?: number
  114. date?: Date
  115. }
  116. export type GroupOpeningStakes = {
  117. application?: StakingPolicy
  118. role?: StakingPolicy
  119. }
  120. export const stakingPolicyUnstakingPeriodKeys = [
  121. 'crowded_out_unstaking_period_length',
  122. 'review_period_expired_unstaking_period_length',
  123. ] as const
  124. export type StakingPolicyUnstakingPeriodKey = typeof stakingPolicyUnstakingPeriodKeys[number]
  125. export const openingPolicyUnstakingPeriodsKeys = [
  126. 'fill_opening_failed_applicant_application_stake_unstaking_period',
  127. 'fill_opening_failed_applicant_role_stake_unstaking_period',
  128. 'fill_opening_successful_applicant_application_stake_unstaking_period',
  129. 'terminate_application_stake_unstaking_period',
  130. 'terminate_role_stake_unstaking_period',
  131. 'exit_role_application_stake_unstaking_period',
  132. 'exit_role_stake_unstaking_period',
  133. ] as const
  134. export type OpeningPolicyUnstakingPeriodsKey = typeof openingPolicyUnstakingPeriodsKeys[number]
  135. export type UnstakingPeriodsKey =
  136. | OpeningPolicyUnstakingPeriodsKey
  137. | 'crowded_out_application_stake_unstaking_period_length'
  138. | 'crowded_out_role_stake_unstaking_period_length'
  139. | 'review_period_expired_application_stake_unstaking_period_length'
  140. | 'review_period_expired_role_stake_unstaking_period_length'
  141. export type UnstakingPeriods = {
  142. [k in UnstakingPeriodsKey]: number
  143. }
  144. export type GroupOpening = {
  145. wgOpeningId: number
  146. openingId: number
  147. stage: GroupOpeningStage
  148. opening: Opening
  149. stakes: GroupOpeningStakes
  150. applications: GroupApplication[]
  151. type: OpeningType
  152. unstakingPeriods: UnstakingPeriods
  153. }
  154. // Api-related
  155. // Additional options that can be passed to ApiCommandBase.promptForParam in order to override
  156. // its default behaviour, change param name, add validation etc.
  157. export type ApiParamOptions<ParamType = Codec> = {
  158. forcedName?: string
  159. value?: {
  160. default: ParamType
  161. locked?: boolean
  162. }
  163. validator?: Validator
  164. nestedOptions?: ApiParamsOptions // For more complex params, like structs
  165. }
  166. export type ApiParamsOptions = {
  167. [paramName: string]: ApiParamOptions
  168. }
  169. export type ApiMethodArg = Codec
  170. export type ApiMethodNamedArg = {
  171. name: string
  172. value: ApiMethodArg
  173. }
  174. export type ApiMethodNamedArgs = ApiMethodNamedArg[]