@pezkuwi/api-derive 16.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/README.md +30 -0
  2. package/build/accounts/accountId.d.ts +17 -0
  3. package/build/accounts/flags.d.ts +29 -0
  4. package/build/accounts/idAndIndex.d.ts +15 -0
  5. package/build/accounts/idToIndex.d.ts +16 -0
  6. package/build/accounts/identity.d.ts +48 -0
  7. package/build/accounts/index.d.ts +8 -0
  8. package/build/accounts/indexToId.d.ts +15 -0
  9. package/build/accounts/indexes.d.ts +16 -0
  10. package/build/accounts/info.d.ts +18 -0
  11. package/build/accounts/types.d.ts +39 -0
  12. package/build/alliance/index.d.ts +70 -0
  13. package/build/augment.d.ts +1 -0
  14. package/build/bagsList/get.d.ts +12 -0
  15. package/build/bagsList/getExpanded.d.ts +16 -0
  16. package/build/bagsList/index.d.ts +3 -0
  17. package/build/bagsList/listNodes.d.ts +9 -0
  18. package/build/bagsList/types.d.ts +13 -0
  19. package/build/bagsList/util.d.ts +2 -0
  20. package/build/balances/account.d.ts +17 -0
  21. package/build/balances/all.d.ts +20 -0
  22. package/build/balances/index.d.ts +20 -0
  23. package/build/balances/types.d.ts +69 -0
  24. package/build/balances/votingBalances.d.ts +15 -0
  25. package/build/bounties/bounties.d.ts +12 -0
  26. package/build/bounties/helpers/filterBountyProposals.d.ts +2 -0
  27. package/build/bounties/index.d.ts +1 -0
  28. package/build/bundle.d.ts +9 -0
  29. package/build/chain/bestNumber.d.ts +11 -0
  30. package/build/chain/bestNumberFinalized.d.ts +12 -0
  31. package/build/chain/bestNumberLag.d.ts +15 -0
  32. package/build/chain/getBlock.d.ts +15 -0
  33. package/build/chain/getBlockByNumber.d.ts +16 -0
  34. package/build/chain/getHeader.d.ts +16 -0
  35. package/build/chain/index.d.ts +10 -0
  36. package/build/chain/subscribeFinalizedBlocks.d.ts +14 -0
  37. package/build/chain/subscribeFinalizedHeads.d.ts +22 -0
  38. package/build/chain/subscribeNewBlocks.d.ts +14 -0
  39. package/build/chain/subscribeNewHeads.d.ts +15 -0
  40. package/build/chain/util.d.ts +9 -0
  41. package/build/collective/helpers.d.ts +6 -0
  42. package/build/collective/index.d.ts +3 -0
  43. package/build/collective/members.d.ts +2 -0
  44. package/build/collective/prime.d.ts +2 -0
  45. package/build/collective/proposals.d.ts +6 -0
  46. package/build/collective/types.d.ts +19 -0
  47. package/build/contracts/fees.d.ts +14 -0
  48. package/build/contracts/index.d.ts +1 -0
  49. package/build/council/index.d.ts +72 -0
  50. package/build/council/types.d.ts +6 -0
  51. package/build/council/votes.d.ts +11 -0
  52. package/build/council/votesOf.d.ts +16 -0
  53. package/build/crowdloan/childKey.d.ts +15 -0
  54. package/build/crowdloan/contributions.d.ts +14 -0
  55. package/build/crowdloan/index.d.ts +3 -0
  56. package/build/crowdloan/ownContributions.d.ts +15 -0
  57. package/build/crowdloan/types.d.ts +6 -0
  58. package/build/crowdloan/util.d.ts +10 -0
  59. package/build/democracy/dispatchQueue.d.ts +12 -0
  60. package/build/democracy/index.d.ts +11 -0
  61. package/build/democracy/locks.d.ts +14 -0
  62. package/build/democracy/nextExternal.d.ts +12 -0
  63. package/build/democracy/preimages.d.ts +24 -0
  64. package/build/democracy/proposals.d.ts +12 -0
  65. package/build/democracy/referendumIds.d.ts +12 -0
  66. package/build/democracy/referendums.d.ts +11 -0
  67. package/build/democracy/referendumsActive.d.ts +12 -0
  68. package/build/democracy/referendumsFinished.d.ts +15 -0
  69. package/build/democracy/referendumsInfo.d.ts +23 -0
  70. package/build/democracy/sqrtElectorate.d.ts +13 -0
  71. package/build/democracy/types.d.ts +70 -0
  72. package/build/democracy/util.d.ts +18 -0
  73. package/build/derive.d.ts +52 -0
  74. package/build/elections/index.d.ts +1 -0
  75. package/build/elections/info.d.ts +14 -0
  76. package/build/elections/types.d.ts +18 -0
  77. package/build/imOnline/index.d.ts +1 -0
  78. package/build/imOnline/receivedHeartbeats.d.ts +13 -0
  79. package/build/index.d.ts +2 -0
  80. package/build/membership/index.d.ts +70 -0
  81. package/build/packageDetect.d.ts +1 -0
  82. package/build/packageInfo.d.ts +6 -0
  83. package/build/parachains/index.d.ts +2 -0
  84. package/build/parachains/info.d.ts +19 -0
  85. package/build/parachains/overview.d.ts +15 -0
  86. package/build/parachains/types.d.ts +38 -0
  87. package/build/parachains/util.d.ts +3 -0
  88. package/build/session/index.d.ts +3 -0
  89. package/build/session/indexes.d.ts +15 -0
  90. package/build/session/info.d.ts +13 -0
  91. package/build/session/progress.d.ts +47 -0
  92. package/build/session/types.d.ts +19 -0
  93. package/build/society/candidates.d.ts +12 -0
  94. package/build/society/index.d.ts +4 -0
  95. package/build/society/info.d.ts +12 -0
  96. package/build/society/member.d.ts +14 -0
  97. package/build/society/members.d.ts +14 -0
  98. package/build/society/types.d.ts +27 -0
  99. package/build/staking/account.d.ts +31 -0
  100. package/build/staking/cache.d.ts +12 -0
  101. package/build/staking/currentPoints.d.ts +13 -0
  102. package/build/staking/electedInfo.d.ts +23 -0
  103. package/build/staking/erasExposure.d.ts +30 -0
  104. package/build/staking/erasHistoric.d.ts +8 -0
  105. package/build/staking/erasPoints.d.ts +18 -0
  106. package/build/staking/erasPrefs.d.ts +27 -0
  107. package/build/staking/erasRewards.d.ts +14 -0
  108. package/build/staking/erasSlashes.d.ts +26 -0
  109. package/build/staking/index.d.ts +22 -0
  110. package/build/staking/keys.d.ts +35 -0
  111. package/build/staking/overview.d.ts +19 -0
  112. package/build/staking/ownExposure.d.ts +37 -0
  113. package/build/staking/ownSlashes.d.ts +35 -0
  114. package/build/staking/query.d.ts +31 -0
  115. package/build/staking/stakerExposure.d.ts +33 -0
  116. package/build/staking/stakerPoints.d.ts +22 -0
  117. package/build/staking/stakerPrefs.d.ts +24 -0
  118. package/build/staking/stakerRewards.d.ts +49 -0
  119. package/build/staking/stakerSlashes.d.ts +22 -0
  120. package/build/staking/stashes.d.ts +16 -0
  121. package/build/staking/types.d.ts +139 -0
  122. package/build/staking/util.d.ts +14 -0
  123. package/build/staking/validators.d.ts +33 -0
  124. package/build/staking/waitingInfo.d.ts +16 -0
  125. package/build/technicalCommittee/index.d.ts +70 -0
  126. package/build/treasury/index.d.ts +1 -0
  127. package/build/treasury/proposals.d.ts +12 -0
  128. package/build/tx/constants.d.ts +5 -0
  129. package/build/tx/events.d.ts +22 -0
  130. package/build/tx/extrinsicInfo.d.ts +61 -0
  131. package/build/tx/index.d.ts +3 -0
  132. package/build/tx/signingInfo.d.ts +25 -0
  133. package/build/type/HeaderExtended.d.ts +4 -0
  134. package/build/type/SignedBlockExtended.d.ts +4 -0
  135. package/build/type/index.d.ts +2 -0
  136. package/build/type/types.d.ts +15 -0
  137. package/build/type/util.d.ts +2 -0
  138. package/build/types.d.ts +79 -0
  139. package/build/util/approvalFlagsToBools.d.ts +4 -0
  140. package/build/util/blockNumber.d.ts +7 -0
  141. package/build/util/cache.d.ts +4 -0
  142. package/build/util/cacheImpl.d.ts +3 -0
  143. package/build/util/first.d.ts +4 -0
  144. package/build/util/index.d.ts +7 -0
  145. package/build/util/lazy.d.ts +4 -0
  146. package/build/util/types.d.ts +6 -0
  147. package/package.json +42 -0
  148. package/src/accounts/accountId.ts +44 -0
  149. package/src/accounts/flags.ts +90 -0
  150. package/src/accounts/idAndIndex.ts +51 -0
  151. package/src/accounts/idToIndex.ts +31 -0
  152. package/src/accounts/identity.ts +235 -0
  153. package/src/accounts/index.ts +11 -0
  154. package/src/accounts/indexToId.ts +33 -0
  155. package/src/accounts/indexes.ts +56 -0
  156. package/src/accounts/info.ts +58 -0
  157. package/src/accounts/types.ts +48 -0
  158. package/src/alliance/index.ts +76 -0
  159. package/src/augment.ts +4 -0
  160. package/src/bagsList/get.ts +79 -0
  161. package/src/bagsList/getExpanded.ts +41 -0
  162. package/src/bagsList/index.ts +6 -0
  163. package/src/bagsList/listNodes.ts +50 -0
  164. package/src/bagsList/types.ts +18 -0
  165. package/src/bagsList/util.ts +14 -0
  166. package/src/balances/account.ts +210 -0
  167. package/src/balances/all.ts +246 -0
  168. package/src/balances/index.ts +26 -0
  169. package/src/balances/types.ts +79 -0
  170. package/src/balances/votingBalances.ts +33 -0
  171. package/src/bounties/bounties.spec.ts +162 -0
  172. package/src/bounties/bounties.ts +76 -0
  173. package/src/bounties/helpers/filterBountyProposals.ts +13 -0
  174. package/src/bounties/index.ts +4 -0
  175. package/src/bundle.ts +140 -0
  176. package/src/chain/bestNumber.ts +21 -0
  177. package/src/chain/bestNumberFinalized.ts +22 -0
  178. package/src/chain/bestNumberLag.ts +33 -0
  179. package/src/chain/getBlock.ts +43 -0
  180. package/src/chain/getBlockByNumber.ts +30 -0
  181. package/src/chain/getHeader.ts +37 -0
  182. package/src/chain/index.ts +13 -0
  183. package/src/chain/subscribeFinalizedBlocks.ts +30 -0
  184. package/src/chain/subscribeFinalizedHeads.ts +62 -0
  185. package/src/chain/subscribeNewBlocks.ts +30 -0
  186. package/src/chain/subscribeNewHeads.ts +38 -0
  187. package/src/chain/util.ts +112 -0
  188. package/src/checkTypes.manual.ts +8 -0
  189. package/src/collective/helpers.ts +36 -0
  190. package/src/collective/index.ts +6 -0
  191. package/src/collective/members.ts +8 -0
  192. package/src/collective/prime.ts +25 -0
  193. package/src/collective/proposals.ts +73 -0
  194. package/src/collective/types.ts +30 -0
  195. package/src/contracts/fees.ts +61 -0
  196. package/src/contracts/index.ts +4 -0
  197. package/src/council/index.ts +79 -0
  198. package/src/council/types.ts +11 -0
  199. package/src/council/votes.ts +97 -0
  200. package/src/council/votesOf.ts +35 -0
  201. package/src/crowdloan/childKey.ts +57 -0
  202. package/src/crowdloan/contributions.ts +142 -0
  203. package/src/crowdloan/index.ts +6 -0
  204. package/src/crowdloan/ownContributions.ts +81 -0
  205. package/src/crowdloan/types.ts +11 -0
  206. package/src/crowdloan/util.ts +33 -0
  207. package/src/democracy/dispatchQueue.ts +158 -0
  208. package/src/democracy/index.ts +14 -0
  209. package/src/democracy/locks.ts +114 -0
  210. package/src/democracy/nextExternal.ts +49 -0
  211. package/src/democracy/preimages.ts +171 -0
  212. package/src/democracy/proposals.ts +81 -0
  213. package/src/democracy/referendumIds.ts +37 -0
  214. package/src/democracy/referendums.ts +39 -0
  215. package/src/democracy/referendumsActive.ts +30 -0
  216. package/src/democracy/referendumsFinished.ts +37 -0
  217. package/src/democracy/referendumsInfo.ts +181 -0
  218. package/src/democracy/sqrtElectorate.ts +29 -0
  219. package/src/democracy/types.ts +84 -0
  220. package/src/democracy/util.ts +166 -0
  221. package/src/derive.ts +41 -0
  222. package/src/elections/index.ts +4 -0
  223. package/src/elections/info.ts +126 -0
  224. package/src/elections/types.ts +22 -0
  225. package/src/imOnline/index.ts +4 -0
  226. package/src/imOnline/receivedHeartbeats.ts +65 -0
  227. package/src/index.spec.ts +103 -0
  228. package/src/index.ts +6 -0
  229. package/src/membership/index.ts +76 -0
  230. package/src/mod.ts +4 -0
  231. package/src/packageDetect.ts +11 -0
  232. package/src/packageInfo.ts +6 -0
  233. package/src/parachains/index.ts +5 -0
  234. package/src/parachains/info.ts +111 -0
  235. package/src/parachains/overview.ts +63 -0
  236. package/src/parachains/types.ts +46 -0
  237. package/src/parachains/util.ts +11 -0
  238. package/src/session/index.ts +6 -0
  239. package/src/session/indexes.ts +90 -0
  240. package/src/session/info.ts +39 -0
  241. package/src/session/progress.ts +130 -0
  242. package/src/session/types.ts +25 -0
  243. package/src/society/candidates.ts +71 -0
  244. package/src/society/index.ts +7 -0
  245. package/src/society/info.ts +50 -0
  246. package/src/society/member.ts +28 -0
  247. package/src/society/members.ts +107 -0
  248. package/src/society/types.ts +33 -0
  249. package/src/staking/account.ts +112 -0
  250. package/src/staking/cache.ts +48 -0
  251. package/src/staking/currentPoints.ts +28 -0
  252. package/src/staking/electedInfo.ts +54 -0
  253. package/src/staking/erasExposure.ts +105 -0
  254. package/src/staking/erasHistoric.ts +47 -0
  255. package/src/staking/erasPoints.ts +67 -0
  256. package/src/staking/erasPrefs.ts +63 -0
  257. package/src/staking/erasRewards.ts +52 -0
  258. package/src/staking/erasSlashes.ts +69 -0
  259. package/src/staking/index.ts +25 -0
  260. package/src/staking/keys.ts +86 -0
  261. package/src/staking/overview.ts +42 -0
  262. package/src/staking/ownExposure.ts +83 -0
  263. package/src/staking/ownSlashes.ts +68 -0
  264. package/src/staking/query.ts +230 -0
  265. package/src/staking/stakerExposure.ts +78 -0
  266. package/src/staking/stakerPoints.ts +46 -0
  267. package/src/staking/stakerPrefs.ts +45 -0
  268. package/src/staking/stakerRewards.ts +298 -0
  269. package/src/staking/stakerSlashes.ts +45 -0
  270. package/src/staking/stashes.ts +55 -0
  271. package/src/staking/types.ts +174 -0
  272. package/src/staking/util.ts +94 -0
  273. package/src/staking/validators.ts +82 -0
  274. package/src/staking/waitingInfo.ts +45 -0
  275. package/src/technicalCommittee/index.ts +76 -0
  276. package/src/test/bountyFactory.ts +39 -0
  277. package/src/test/bytesFactory.ts +15 -0
  278. package/src/test/helpers.ts +23 -0
  279. package/src/test/proposalFactory.ts +25 -0
  280. package/src/treasury/index.ts +4 -0
  281. package/src/treasury/proposals.ts +109 -0
  282. package/src/tx/constants.ts +13 -0
  283. package/src/tx/events.ts +43 -0
  284. package/src/tx/extrinsicInfo.ts +123 -0
  285. package/src/tx/index.ts +6 -0
  286. package/src/tx/signingInfo.ts +129 -0
  287. package/src/type/HeaderExtended.ts +33 -0
  288. package/src/type/SignedBlockExtended.ts +75 -0
  289. package/src/type/index.ts +5 -0
  290. package/src/type/types.ts +21 -0
  291. package/src/type/util.ts +45 -0
  292. package/src/types.ts +97 -0
  293. package/src/util/approvalFlagToBools.spec.ts +37 -0
  294. package/src/util/approvalFlagsToBools.ts +26 -0
  295. package/src/util/blockNumber.ts +15 -0
  296. package/src/util/cache.ts +65 -0
  297. package/src/util/cacheImpl.ts +30 -0
  298. package/src/util/first.ts +20 -0
  299. package/src/util/index.ts +13 -0
  300. package/src/util/lazy.ts +16 -0
  301. package/src/util/types.ts +9 -0
  302. package/tsconfig.build.json +21 -0
  303. package/tsconfig.build.tsbuildinfo +1 -0
  304. package/tsconfig.spec.json +27 -0
@@ -0,0 +1,82 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { AccountId } from '@pezkuwi/types/interfaces';
6
+ import type { DeriveApi, DeriveStakingValidators } from '../types.js';
7
+
8
+ import { combineLatest, map, of, switchMap } from 'rxjs';
9
+
10
+ import { memo } from '../util/index.js';
11
+
12
+ /**
13
+ * @name nextElected
14
+ * @description Retrieves the list of accounts that are set to be the next elected validators in the staking system. It provides a preview of who will be validators in the next staking era.
15
+ * @example
16
+ * ```javascript
17
+ * const nextElected = await api.derive.staking.nextElected();
18
+ * console.log(
19
+ * "Next Elected Validators:",
20
+ * nextElected.map((acc) => acc.toString())
21
+ * );
22
+ * ```
23
+ */
24
+ export function nextElected (instanceId: string, api: DeriveApi): () => Observable<AccountId[]> {
25
+ return memo(instanceId, (): Observable<AccountId[]> =>
26
+ // Compatibility for future generation changes in staking.
27
+ api.query.staking.erasStakersOverview
28
+ ? api.derive.session.indexes().pipe(
29
+ // only populate for next era in the last session, so track both here - entries are not
30
+ // subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
31
+ switchMap(({ currentEra }) => api.query.staking.erasStakersOverview.keys(currentEra)),
32
+ // Dedupe any duplicates
33
+ map((keys) => [...new Set(keys.map(({ args: [, accountId] }) => accountId.toString()))].map((a) => api.registry.createType('AccountId', a)))
34
+ )
35
+ : api.query.staking.erasStakers
36
+ ? api.derive.session.indexes().pipe(
37
+ // only populate for next era in the last session, so track both here - entries are not
38
+ // subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
39
+ switchMap(({ currentEra }) => api.query.staking.erasStakers.keys(currentEra)),
40
+ // Dedupe any duplicates
41
+ map((keys) => [...new Set(keys.map(({ args: [, accountId] }) => accountId.toString()))].map((a) => api.registry.createType('AccountId', a)))
42
+ )
43
+ : api.query.staking['currentElected']<AccountId[]>()
44
+ );
45
+ }
46
+
47
+ /**
48
+ * @name validators
49
+ * @description Retrieve latest list of validators.
50
+ * @example
51
+ * ```javascript
52
+ * const { validators, nextElected } = await api.derive.staking.validators();
53
+ * console.log(
54
+ * "Current Validators:",
55
+ * validators.map((v) => v.toString())
56
+ * );
57
+ * console.log(
58
+ * "Next Elected Validators:",
59
+ * nextElected.map((v) => v.toString())
60
+ * );
61
+ * ```
62
+ */
63
+ export function validators (instanceId: string, api: DeriveApi): () => Observable<DeriveStakingValidators> {
64
+ return memo(instanceId, (): Observable<DeriveStakingValidators> =>
65
+ // Sadly the node-template is (for some obscure reason) not comprehensive, so while the derive works
66
+ // in all actual real-world deployed chains, it does create some confusion for limited template chains
67
+ combineLatest([
68
+ api.query.session
69
+ ? api.query.session.validators()
70
+ : of([]),
71
+ api.query.staking
72
+ ? api.derive.staking.nextElected()
73
+ : of([])
74
+ ]).pipe(
75
+ map(([validators, nextElected]): DeriveStakingValidators => ({
76
+ nextElected: nextElected.length
77
+ ? nextElected
78
+ : validators,
79
+ validators
80
+ }))
81
+ ));
82
+ }
@@ -0,0 +1,45 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { DeriveApi, DeriveStakingWaiting, StakingQueryFlags } from '../types.js';
6
+
7
+ import { combineLatest, map, switchMap } from 'rxjs';
8
+
9
+ import { memo } from '../util/index.js';
10
+
11
+ const DEFAULT_FLAGS = { withController: true, withPrefs: true };
12
+
13
+ /**
14
+ * @name waitingInfo
15
+ * @param {StakingQueryFlags} flags? (Optional) Query flags to filter the staking data.
16
+ * @description Staking candidates who are waiting to become validators.
17
+ * @example
18
+ * ```javascript
19
+ * const { waiting, info } = await api.derive.staking.waitingInfo();
20
+ * console.log(
21
+ * "Waiting Candidates:",
22
+ * waiting.map((acc) => acc.toString())
23
+ * );
24
+ * ```
25
+ */
26
+ export function waitingInfo (instanceId: string, api: DeriveApi): (flags?: StakingQueryFlags) => Observable<DeriveStakingWaiting> {
27
+ return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS): Observable<DeriveStakingWaiting> =>
28
+ combineLatest([
29
+ api.derive.staking.validators(),
30
+ api.derive.staking.stashes()
31
+ ]).pipe(
32
+ switchMap(([{ nextElected }, stashes]): Observable<DeriveStakingWaiting> => {
33
+ const elected = nextElected.map((a) => a.toString());
34
+ const waiting = stashes.filter((v) => !elected.includes(v.toString()));
35
+
36
+ return api.derive.staking.queryMulti(waiting, flags).pipe(
37
+ map((info): DeriveStakingWaiting => ({
38
+ info,
39
+ waiting
40
+ }))
41
+ );
42
+ })
43
+ )
44
+ );
45
+ }
@@ -0,0 +1,76 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
5
+
6
+ /**
7
+ * @name members
8
+ * @description Retrieves the list of members in the "technicalCommittee" collective.
9
+ * @example
10
+ * ```javascript
11
+ * const members = await api.derive.technicalCommittee.members();
12
+ * console.log(`Members: ${JSON.stringify(members)});
13
+ * ```
14
+ */
15
+ export const members = /*#__PURE__*/ collectiveMembers('technicalCommittee');
16
+
17
+ /**
18
+ * @name hasProposals
19
+ * @description Checks if there are any active proposals in the "technicalCommittee" collective.
20
+ * @example
21
+ * ```javascript
22
+ * const exists = await api.derive.technicalCommittee.hasProposals();
23
+ * console.log(exists);
24
+ * ```
25
+ */
26
+ export const hasProposals = /*#__PURE__*/ collectiveHasProposals('technicalCommittee');
27
+ /**
28
+ * @name proposal
29
+ * @description Retrieves details of a specific proposal in the "technicalCommitteeMotion" collective by its hash.
30
+ * @example
31
+ * ```javascript
32
+ * const proposalDetails = await api.derive.technicalCommittee.proposal(PROPOSAL_HASH);
33
+ * console.log(proposalDetails);
34
+ * ```
35
+ */
36
+ export const proposal = /*#__PURE__*/ collectiveProposal('technicalCommittee');
37
+ /**
38
+ * @name proposalCount
39
+ * @description Retrieves the total number of proposals in the "technicalCommittee" collective.
40
+ * @example
41
+ * ```javascript
42
+ * const count = await api.derive.technicalCommittee.proposalCount();
43
+ * console.log(`Amount of proposals: ${count}`);
44
+ * ```
45
+ */
46
+ export const proposalCount = /*#__PURE__*/ collectiveProposalCount('technicalCommittee');
47
+ /**
48
+ * @name proposalHashes
49
+ * @description Retrieves an array of hashes for all active proposals in the "technicalCommittee" collective.
50
+ * @example
51
+ * ```javascript
52
+ * const hashes = await api.derive.technicalCommittee.proposalHashes();
53
+ * console.log(`Proposals ${JSON.stringify(hashes)}`);
54
+ * ```
55
+ */
56
+ export const proposalHashes = /*#__PURE__*/ collectiveProposalHashes('technicalCommittee');
57
+ /**
58
+ * @name proposals
59
+ * @description Retrieves a list of all active proposals in the "technicalCommittee" collective.
60
+ * @example
61
+ * ```javascript
62
+ * const proposals = await api.derive.technicalCommittee.proposals();
63
+ * console.log(proposals);
64
+ * ```
65
+ */
66
+ export const proposals = /*#__PURE__*/ collectiveProposals('technicalCommittee');
67
+ /**
68
+ * @name prime
69
+ * @description Retrieves the prime member of the "technicalCommittee" collective, if one exists.
70
+ * @example
71
+ * ```javascript
72
+ * const primeMember = await api.derive.technicalCommittee.prime();
73
+ * console.log(primeMember);
74
+ * ```
75
+ */
76
+ export const prime = /*#__PURE__*/ collectivePrime('technicalCommittee');
@@ -0,0 +1,39 @@
1
+ // Copyright 2017-2025 @polkadot/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ApiPromise } from '@pezkuwi/api';
5
+ import type { Bounty, BountyIndex } from '@pezkuwi/types/interfaces';
6
+ import type { Codec, CodecClass, InterfaceTypes, Registry } from '@pezkuwi/types/types';
7
+
8
+ import { Option, StorageKey } from '@pezkuwi/types';
9
+
10
+ export class BountyFactory {
11
+ readonly #api: ApiPromise;
12
+ readonly #registry: Registry;
13
+
14
+ constructor (api: ApiPromise) {
15
+ this.#api = api;
16
+ this.#registry = this.#api.registry;
17
+ }
18
+
19
+ public storageKey = (index: number): StorageKey => {
20
+ const key = new StorageKey(this.#registry, this.#api.query.bounties.bounties.key(this.bountyIndex(index)));
21
+
22
+ return key.setMeta(this.#api.query.bounties.bounties.creator.meta);
23
+ };
24
+
25
+ public bountyIndex = (index: number): BountyIndex =>
26
+ this.#registry.createType('BountyIndex', index);
27
+
28
+ public defaultBounty = (): Bounty =>
29
+ this.#registry.createType('Bounty');
30
+
31
+ public optionOf = <T extends Codec>(value: T): Option<T> => {
32
+ const typeName = this.#registry.getClassName(value.constructor as CodecClass<T>);
33
+
34
+ return new Option<T>(this.#registry, typeName as keyof InterfaceTypes, value);
35
+ };
36
+
37
+ public emptyOption = <T extends Codec>(typeName: keyof InterfaceTypes): Option<T> =>
38
+ new Option<T>(this.#registry, typeName);
39
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright 2017-2025 @polkadot/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Bytes } from '@pezkuwi/types';
5
+ import type { Registry } from '@pezkuwi/types/types';
6
+
7
+ export class BytesFactory {
8
+ #registry: Registry;
9
+
10
+ constructor (registry: Registry) {
11
+ this.#registry = registry;
12
+ }
13
+
14
+ public bytes = (value: string): Bytes => this.#registry.createType('Bytes', value);
15
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright 2017-2025 @polkadot/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ApiPromise, WsProvider } from '@pezkuwi/api';
5
+ import { Metadata, TypeRegistry } from '@pezkuwi/types';
6
+ import metaStatic from '@pezkuwi/types-support/metadata/static-substrate';
7
+
8
+ export function createApiWithAugmentations (): ApiPromise {
9
+ const registry = new TypeRegistry();
10
+ const metadata = new Metadata(registry, metaStatic);
11
+
12
+ registry.setMetadata(metadata);
13
+
14
+ const api = new ApiPromise({
15
+ provider: new WsProvider('ws://', false),
16
+ registry
17
+ });
18
+
19
+ // eslint-disable-next-line deprecation/deprecation
20
+ api.injectMetadata(metadata, true, registry);
21
+
22
+ return api;
23
+ }
@@ -0,0 +1,25 @@
1
+ // Copyright 2017-2025 @polkadot/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ApiPromise } from '@pezkuwi/api';
5
+ import type { SubmittableExtrinsic } from '@pezkuwi/api-base/types';
6
+ import type { Proposal, ProposalIndex } from '@pezkuwi/types/interfaces';
7
+ import type { Registry } from '@pezkuwi/types/types';
8
+
9
+ export class ProposalFactory {
10
+ readonly #api: ApiPromise;
11
+ readonly #registry: Registry;
12
+
13
+ constructor (api: ApiPromise) {
14
+ this.#api = api;
15
+ this.#registry = this.#api.registry;
16
+ }
17
+
18
+ public createProposal = (method: SubmittableExtrinsic<'promise'>): Proposal => {
19
+ return this.#registry.createType('Proposal', method);
20
+ };
21
+
22
+ public proposalIndex = (index: number): ProposalIndex => {
23
+ return this.#registry.createType('ProposalIndex', index);
24
+ };
25
+ }
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './proposals.js';
@@ -0,0 +1,109 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { Option } from '@pezkuwi/types';
6
+ import type { ProposalIndex } from '@pezkuwi/types/interfaces';
7
+ import type { PalletTreasuryProposal } from '@pezkuwi/types/lookup';
8
+ import type { DeriveApi, DeriveCollectiveProposal, DeriveTreasuryProposal, DeriveTreasuryProposals } from '../types.js';
9
+
10
+ import { combineLatest, map, of, switchMap } from 'rxjs';
11
+
12
+ import { memo } from '../util/index.js';
13
+
14
+ interface Result {
15
+ allIds: ProposalIndex[];
16
+ allProposals: Option<PalletTreasuryProposal>[];
17
+ approvalIds: ProposalIndex[];
18
+ councilProposals: DeriveCollectiveProposal[];
19
+ proposalCount: ProposalIndex;
20
+ }
21
+
22
+ function parseResult (api: DeriveApi, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DeriveTreasuryProposals {
23
+ const approvals: DeriveTreasuryProposal[] = [];
24
+ const proposals: DeriveTreasuryProposal[] = [];
25
+ const councilTreasury = councilProposals.filter(({ proposal }) =>
26
+ // FIXME `approveProposal` and `rejectProposal` have been removed in substrate and released in 1.14
27
+ // in favor of `spend`. See: https://github.com/paritytech/polkadot-sdk/pull/3820
28
+ proposal && (
29
+ (api.tx.treasury['approveProposal'] && api.tx.treasury['approveProposal'].is(proposal)) ||
30
+ (api.tx.treasury['rejectProposal'] && api.tx.treasury['rejectProposal'].is(proposal))
31
+ )
32
+ );
33
+
34
+ allIds.forEach((id, index): void => {
35
+ if (allProposals[index].isSome) {
36
+ const council = councilTreasury
37
+ .filter(({ proposal }) => proposal && id.eq(proposal.args[0]))
38
+ .sort((a, b) =>
39
+ a.proposal && b.proposal
40
+ ? a.proposal.method.localeCompare(b.proposal.method)
41
+ : a.proposal
42
+ ? -1
43
+ : 1
44
+ );
45
+ const isApproval = approvalIds.some((approvalId) => approvalId.eq(id));
46
+ const derived = { council, id, proposal: allProposals[index].unwrap() };
47
+
48
+ if (isApproval) {
49
+ approvals.push(derived);
50
+ } else {
51
+ proposals.push(derived);
52
+ }
53
+ }
54
+ });
55
+
56
+ return { approvals, proposalCount, proposals };
57
+ }
58
+
59
+ function retrieveProposals (api: DeriveApi, proposalCount: ProposalIndex, approvalIds: ProposalIndex[]): Observable<DeriveTreasuryProposals> {
60
+ const proposalIds: ProposalIndex[] = [];
61
+ const count = proposalCount.toNumber();
62
+
63
+ for (let index = 0; index < count; index++) {
64
+ if (!approvalIds.some((id) => id.eqn(index))) {
65
+ proposalIds.push(api.registry.createType('ProposalIndex', index));
66
+ }
67
+ }
68
+
69
+ const allIds = [...proposalIds, ...approvalIds];
70
+
71
+ return combineLatest([
72
+ api.query.treasury.proposals.multi(allIds),
73
+ api.derive.council
74
+ ? api.derive.council.proposals()
75
+ : of([] as DeriveCollectiveProposal[])
76
+ ]).pipe(
77
+ map(([allProposals, councilProposals]): DeriveTreasuryProposals =>
78
+ parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount })
79
+ )
80
+ );
81
+ }
82
+
83
+ /**
84
+ * @name proposals
85
+ * @description Retrieve all active and approved treasury proposals, along with their info.
86
+ * @example
87
+ * ```javascript
88
+ * const treasuryProposals = await api.derive.treasury.proposals();
89
+ * console.log(treasuryProposals);
90
+ * ```
91
+ */
92
+ export function proposals (instanceId: string, api: DeriveApi): () => Observable<DeriveTreasuryProposals> {
93
+ return memo(instanceId, (): Observable<DeriveTreasuryProposals> =>
94
+ api.query.treasury
95
+ ? combineLatest([
96
+ api.query.treasury.proposalCount(),
97
+ api.query.treasury.approvals()
98
+ ]).pipe(
99
+ switchMap(([proposalCount, approvalIds]) =>
100
+ retrieveProposals(api, proposalCount, approvalIds)
101
+ )
102
+ )
103
+ : of({
104
+ approvals: [],
105
+ proposalCount: api.registry.createType('ProposalIndex'),
106
+ proposals: []
107
+ } as DeriveTreasuryProposals)
108
+ );
109
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BN } from '@pezkuwi/util';
5
+
6
+ export const FALLBACK_MAX_HASH_COUNT = 250;
7
+
8
+ // default here to 5 min eras, adjusted based on the actual blocktime
9
+ export const FALLBACK_PERIOD = new BN(6 * 1000);
10
+
11
+ export const MAX_FINALITY_LAG = new BN(5);
12
+
13
+ export const MORTAL_PERIOD = new BN(5 * 60 * 1000);
@@ -0,0 +1,43 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { EventRecord, Hash, SignedBlock } from '@pezkuwi/types/interfaces';
6
+ import type { DeriveApi } from '../types.js';
7
+
8
+ import { combineLatest, map, switchMap } from 'rxjs';
9
+
10
+ import { memo } from '../util/index.js';
11
+
12
+ interface Result {
13
+ block: SignedBlock;
14
+ events: EventRecord[];
15
+ }
16
+
17
+ /**
18
+ * @name events
19
+ * @param {Hash} at Block hash to query at.
20
+ * @description Retrieves the block information alongside its events at a given block hash
21
+ * @example
22
+ * ```javascript
23
+ * const blockHash = api.registry.createType(
24
+ * "Hash",
25
+ * "0xf1dc2efe8265be67deea5e91b05a98a7f9f81f66854e92825cf36f541beb7af6"
26
+ * );
27
+ * const { events, block } = await api.derive.tx.events(blockHash);
28
+ * ```
29
+ */
30
+ export function events (instanceId: string, api: DeriveApi): (at: Hash) => Observable<Result> {
31
+ return memo(instanceId, (blockHash: Hash) =>
32
+ combineLatest([
33
+ api.rpc.chain.getBlock(blockHash),
34
+ api.queryAt(blockHash).pipe(
35
+ switchMap((queryAt) =>
36
+ queryAt.system.events()
37
+ )
38
+ )
39
+ ]).pipe(
40
+ map(([block, events]) => ({ block, events }))
41
+ )
42
+ );
43
+ }
@@ -0,0 +1,123 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { GenericExtrinsic } from '@pezkuwi/types';
6
+ import type { EventRecord, Hash } from '@pezkuwi/types/interfaces';
7
+ import type { DeriveApi } from '../types.js';
8
+
9
+ import { map } from 'rxjs';
10
+
11
+ import { memo } from '../util/index.js';
12
+
13
+ interface ExtrinsicInfo {
14
+ blockHash: Hash | string,
15
+ blockNumber: number,
16
+ extrinsic: GenericExtrinsic,
17
+ events: EventRecord[]
18
+ success: boolean
19
+ }
20
+
21
+ interface ExtrinsicsInfo {
22
+ blockHash: Hash | string,
23
+ blockNumber: number,
24
+ extrinsics: {
25
+ events: EventRecord[]
26
+ extrinsic: GenericExtrinsic,
27
+ success: boolean
28
+ }[],
29
+ }
30
+
31
+ /**
32
+ * @name extrinsicInfo
33
+ * @param { Hash } at The block hash to query at.
34
+ * @param { Uint8Array | string } transactionHash A transaction hash as U8 array or string.
35
+ * @description Retrieves the extrinsic information and its events.
36
+ * @example
37
+ * ```javascript
38
+ * const blockHash = api.registry.createType(
39
+ * 'Hash',
40
+ * '0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
41
+ * );
42
+ * const extrinsicInfo = await api.derive.tx.extrinsicInfo(
43
+ * blockHash,
44
+ * '0xcd96520b05e0c4648ea365f3f063f27c5cdd8be10d41a1c44566428c91f37dcb'
45
+ * );
46
+ *
47
+ * console.log(extrinsicInfo.extrinsic.toHuman());
48
+ * ```
49
+ */
50
+ export function extrinsicInfo (instanceId: string, api: DeriveApi): (at: Hash, transactionHash: Uint8Array | string) => Observable<ExtrinsicInfo | null> {
51
+ return memo(instanceId, (at: Hash, transactionHash: Uint8Array | string): Observable<ExtrinsicInfo | null> => {
52
+ return api.derive.tx.events(at).pipe(map(({ block, events }) => {
53
+ const index = block.block.extrinsics.findIndex((ext) => ext.hash.toString() === transactionHash);
54
+
55
+ if (index === -1) {
56
+ return null;
57
+ }
58
+
59
+ const extEvents = events.filter(
60
+ ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index)
61
+ );
62
+
63
+ return {
64
+ blockHash: block.hash.toHex(),
65
+ blockNumber: block.block.header.number.toNumber(),
66
+ events: extEvents,
67
+ extrinsic: block.block.extrinsics[index],
68
+ success: (extEvents.findIndex((ev) => ev.event.method === 'ExtrinsicSuccess') !== -1)
69
+ };
70
+ }));
71
+ });
72
+ }
73
+
74
+ /**
75
+ * @name accountExtrinsics
76
+ * @description Retrieves information about every extrinsic submitted by an account at a given block.
77
+ * @param { Hash } at The block hash to query at.
78
+ * @param { Uint8Array | strings } accountId The account identifier to query.
79
+ * @example
80
+ * ```javascript
81
+ const blockHash = api.registry.createType(
82
+ 'Hash',
83
+ '0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
84
+ );
85
+ const extrinsicsInfo = await api.derive.tx.accountExtrinsics(
86
+ blockHash,
87
+ '0x21895DdfD4640b4e0aDCa2865b907f2CE6e6B777'
88
+ );
89
+
90
+ console.log(extrinsicsInfo.extrinsics[0]).extrinsic.toHuman();
91
+ * ```
92
+ */
93
+ export function accountExtrinsics (instanceId: string, api: DeriveApi): (at: Hash, accountId: Uint8Array | string) => Observable<ExtrinsicsInfo> {
94
+ return memo(instanceId, (at: Hash, accountId: Uint8Array | string): Observable<ExtrinsicsInfo> => {
95
+ return api.derive.tx.events(at).pipe(map(({ block, events }) => {
96
+ const indexes: number[] = [];
97
+
98
+ return {
99
+ blockHash: block.hash.toHex(),
100
+ blockNumber: block.block.header.number.toNumber(),
101
+ extrinsics: block.block.extrinsics.filter((ext, index) => {
102
+ if (ext.signer.toString() === accountId) {
103
+ indexes.push(index);
104
+
105
+ return true;
106
+ }
107
+
108
+ return false;
109
+ }).map((ext, i) => {
110
+ const extEvents = events.filter(
111
+ ({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(indexes[i])
112
+ );
113
+
114
+ return {
115
+ events: extEvents,
116
+ extrinsic: ext,
117
+ success: (extEvents.findIndex((ev) => ev.event.method === 'ExtrinsicSuccess') !== -1)
118
+ };
119
+ })
120
+ };
121
+ }));
122
+ });
123
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './events.js';
5
+ export * from './extrinsicInfo.js';
6
+ export * from './signingInfo.js';