|
@@ -1,11 +1,17 @@
|
|
import { ApiPromise } from "@polkadot/api";
|
|
import { ApiPromise } from "@polkadot/api";
|
|
|
|
|
|
// types
|
|
// types
|
|
-import { Bounty, CacheEvent, WorkerReward } from "./types";
|
|
|
|
|
|
+import { Bounty, CacheEvent, WorkerReward, SpendingProposal } from "./types";
|
|
import { AccountId, Balance } from "@polkadot/types/interfaces";
|
|
import { AccountId, Balance } from "@polkadot/types/interfaces";
|
|
import { Hash } from "@polkadot/types/interfaces";
|
|
import { Hash } from "@polkadot/types/interfaces";
|
|
import { Membership } from "@joystream/types/members";
|
|
import { Membership } from "@joystream/types/members";
|
|
import { Mint, MintId } from "@joystream/types/mint";
|
|
import { Mint, MintId } from "@joystream/types/mint";
|
|
|
|
+import {
|
|
|
|
+ Proposal,
|
|
|
|
+ ProposalId,
|
|
|
|
+ SpendingParams,
|
|
|
|
+} from "@joystream/types/proposals";
|
|
|
|
+import { ProposalDetails, ProposalOf } from "@joystream/types/augment/types";
|
|
import { Stake } from "@joystream/types/stake";
|
|
import { Stake } from "@joystream/types/stake";
|
|
import {
|
|
import {
|
|
RewardRelationship,
|
|
RewardRelationship,
|
|
@@ -22,17 +28,22 @@ import {
|
|
getMember,
|
|
getMember,
|
|
getWorker,
|
|
getWorker,
|
|
getWorkerReward,
|
|
getWorkerReward,
|
|
|
|
+ getProposalInfo,
|
|
|
|
+ getProposalDetails,
|
|
getStake,
|
|
getStake,
|
|
getValidators,
|
|
getValidators,
|
|
getValidatorCount,
|
|
getValidatorCount,
|
|
} from "./api";
|
|
} from "./api";
|
|
-import {WorkerOf} from "@joystream/types/augment-codec/all";
|
|
|
|
|
|
+import { WorkerOf } from "@joystream/types/augment-codec/all";
|
|
|
|
+import { ProposalDetailsOf } from "@joystream/types/augment/types";
|
|
|
|
|
|
export const filterMethods = {
|
|
export const filterMethods = {
|
|
getBurnedTokens: ({ section, method }: CacheEvent) =>
|
|
getBurnedTokens: ({ section, method }: CacheEvent) =>
|
|
section === "balances" && method === "Transfer",
|
|
section === "balances" && method === "Transfer",
|
|
newValidatorsRewards: ({ section, method }: CacheEvent) =>
|
|
newValidatorsRewards: ({ section, method }: CacheEvent) =>
|
|
section === "staking" && method === "Reward",
|
|
section === "staking" && method === "Reward",
|
|
|
|
+ finalizedSpendingProposals: ({ section, method }: CacheEvent) =>
|
|
|
|
+ section === "proposalsEngine" && method === "ProposalStatusUpdated",
|
|
};
|
|
};
|
|
|
|
|
|
export const getWorkerRewards = async (
|
|
export const getWorkerRewards = async (
|
|
@@ -60,7 +71,8 @@ export const getWorkerRewards = async (
|
|
|
|
|
|
if (worker.reward_relationship.isSome) {
|
|
if (worker.reward_relationship.isSome) {
|
|
// TODO changing salaries are not reflected
|
|
// TODO changing salaries are not reflected
|
|
- const rewardId: RewardRelationshipId = worker.reward_relationship.unwrap();
|
|
|
|
|
|
+ const rewardId: RewardRelationshipId =
|
|
|
|
+ worker.reward_relationship.unwrap();
|
|
reward = await getWorkerReward(api, hash, rewardId);
|
|
reward = await getWorkerReward(api, hash, rewardId);
|
|
}
|
|
}
|
|
workers.push({ id, stake, reward, status, handle, account, memberId });
|
|
workers.push({ id, stake, reward, status, handle, account, memberId });
|
|
@@ -95,12 +107,45 @@ export const getBurnedTokens = (
|
|
transfers.forEach((transfer) => {
|
|
transfers.forEach((transfer) => {
|
|
let receiver = transfer.data[1] as AccountId;
|
|
let receiver = transfer.data[1] as AccountId;
|
|
let amount = transfer.data[2] as Balance;
|
|
let amount = transfer.data[2] as Balance;
|
|
- if (receiver.toString() === burnAddress) tokensBurned = Number(amount);
|
|
|
|
|
|
+ if (receiver.toString() === burnAddress) tokensBurned += Number(amount);
|
|
})
|
|
})
|
|
);
|
|
);
|
|
return tokensBurned;
|
|
return tokensBurned;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+export const getFinalizedSpendingProposals = async (
|
|
|
|
+ api: ApiPromise,
|
|
|
|
+ blocks: [number, CacheEvent[]][]
|
|
|
|
+): Promise<SpendingProposal[]> => {
|
|
|
|
+ let spendingProposals: SpendingProposal[] = [];
|
|
|
|
+ await blocks.forEach(([key, proposals]) =>
|
|
|
|
+ proposals.forEach(async (proposalEvent) => {
|
|
|
|
+ let statusUpdateData = proposalEvent.data[1] as any;
|
|
|
|
+ const finalizedAt = statusUpdateData.finalized.finalizedAt;
|
|
|
|
+ if (!(statusUpdateData.finalized && finalizedAt)) return;
|
|
|
|
+
|
|
|
|
+ const proposalId = proposalEvent.data[0] as ProposalId;
|
|
|
|
+ const id = +proposalId;
|
|
|
|
+ const proposalInfo: ProposalOf = await getProposalInfo(api, proposalId);
|
|
|
|
+ const finalizedData = proposalInfo.status.asFinalized;
|
|
|
|
+ const details: ProposalDetailsOf = await getProposalDetails(
|
|
|
|
+ api,
|
|
|
|
+ proposalId
|
|
|
|
+ );
|
|
|
|
+ if (!finalizedData.proposalStatus.isApproved || !details.isSpending)
|
|
|
|
+ return;
|
|
|
|
+ let approvedData = finalizedData.proposalStatus.asApproved;
|
|
|
|
+ if (!approvedData.isExecuted) return;
|
|
|
|
+ if (!spendingProposals.some((proposal) => proposal.id === id)) {
|
|
|
|
+ const title = proposalInfo.title.toString();
|
|
|
|
+ const amount = +details.asSpending[0];
|
|
|
|
+ spendingProposals.push({ id, title, amount });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+ return spendingProposals;
|
|
|
|
+};
|
|
|
|
+
|
|
export const getValidatorsRewards = (
|
|
export const getValidatorsRewards = (
|
|
blocks: [number, CacheEvent[]][]
|
|
blocks: [number, CacheEvent[]][]
|
|
): number => {
|
|
): number => {
|