Jelajahi Sumber

Stake events added

singulart 2 tahun lalu
induk
melakukan
00e34e738a

+ 24 - 2
scripts/wg-bot/src/joystream/discord.ts

@@ -1,7 +1,20 @@
 import { EventRecord } from '@polkadot/types/interfaces'
-import { getWorker, getMember, getMint, getEvents, getBlockHash, getWorkerReward } from '../lib/api';
+import { getWorker, getMember, getMint, getEvents, getBlockHash, getWorkerReward, getStake } from '../lib/api';
 import { getApplication, getHiringApplication, getHiringOpening, getOpening } from './api_extension';
-import { getApplicationTerminatedEmbed, getApplicationWithdrawnEmbed, getAppliedOnOpeningEmbed, getLeaderSetEmbed, getLeaderUnsetEmbed, getMintCapacityChangedEmbed, getOpeningAddedEmbed, getOpeningFilledEmbed, getWorkerExitedEmbed, getWorkerRewardAmountUpdatedEmbed, getWorkerTerminatedEmbed } from './embeds';
+import { 
+    getApplicationTerminatedEmbed, 
+    getApplicationWithdrawnEmbed, 
+    getAppliedOnOpeningEmbed, 
+    getLeaderSetEmbed, 
+    getLeaderUnsetEmbed, 
+    getMintCapacityChangedEmbed, 
+    getOpeningAddedEmbed, 
+    getOpeningFilledEmbed, 
+    getStakeUpdatedEmbed, 
+    getWorkerExitedEmbed, 
+    getWorkerRewardAmountUpdatedEmbed, 
+    getWorkerTerminatedEmbed 
+} from './embeds';
 
 import { wgEvents, workingGroups } from '../config'
 import Discord from 'discord.js';
@@ -99,6 +112,15 @@ export const processBlock = async (api: ApiPromise, client: Discord.Client, bloc
                     case "LeaderUnset": 
                         channel.send({ embeds: [getLeaderUnsetEmbed(blockNumber, value)] });
                         break;
+                    case "StakeDecreased":
+                    case "StakeIncreased":
+                    case "StakeSlashed":
+                        const stakeWorkerId = data[0] as WorkerId;
+                        const stakeWorker = await getWorker(api, section, hash, stakeWorkerId.toNumber());
+                        const stakeMember = await getMember(api, stakeWorker.member_id);
+                        const stake = await getStake(api, stakeWorker.role_stake_profile.unwrap().stake_id)
+                        channel.send({ embeds: [getStakeUpdatedEmbed(stake, stakeMember, method.replace('Stake', ''), blockNumber, value)] });
+                        break;
                 }
             } else {
                 console.log(`Channel not configured for ${section}`);

+ 15 - 2
scripts/wg-bot/src/joystream/embeds.ts

@@ -3,7 +3,7 @@ import { formatBalance } from '@polkadot/util';
 import { u128 } from '@polkadot/types';
 import { EventRecord } from '@polkadot/types/interfaces';
 import Discord from 'discord.js';
-import { ApplicationId, ApplicationOf, Membership, OpeningOf, RewardRelationship } from '@joystream/types/augment-codec/all';
+import { ApplicationId, ApplicationOf, Membership, OpeningOf, RewardRelationship, Stake, WorkerOf } from '@joystream/types/augment-codec/all';
 
 
 export const getMintCapacityChangedEmbed = (minted: number, mint: u128, blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
@@ -155,4 +155,17 @@ export const getApplicationTerminatedOrWithdrawEmbed = (action: string, applicat
             { name: 'Tx', value: event.hash.toString(), inline: true },
         )
         .setTimestamp();
-}
+}
+
+export const getStakeUpdatedEmbed = (stake: Stake, member: Membership, action: string, blockNumber: number, event: EventRecord): Discord.MessageEmbed => {
+
+    return new Discord.MessageEmbed()
+        .setColor(joystreamBlue)
+        .setTitle(`💰💰💰 ${member.handle} stake has been ${action} `)
+        .addFields(
+            { name: 'Stake', value: formatBalance(stake.value.toString(), { withUnit: 'JOY' }), inline: true },
+            { name: 'Block', value: blockNumber + "", inline: true },
+            { name: 'Tx', value: event.hash.toString(), inline: true },
+        )
+        .setTimestamp();
+}