diff --git a/libs/model/src/comment/CreateComment.command.ts b/libs/model/src/comment/CreateComment.command.ts index a0422b3983b..cafd5c52226 100644 --- a/libs/model/src/comment/CreateComment.command.ts +++ b/libs/model/src/comment/CreateComment.command.ts @@ -71,7 +71,7 @@ export function CreateComment(): Command< text, address_id: address.id!, reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', created_by: '', search: getCommentSearchVector(text), content_url: contentUrl, diff --git a/libs/model/src/comment/CreateCommentReaction.command.ts b/libs/model/src/comment/CreateCommentReaction.command.ts index 412e87a0b3f..9bca7ad2c8c 100644 --- a/libs/model/src/comment/CreateCommentReaction.command.ts +++ b/libs/model/src/comment/CreateCommentReaction.command.ts @@ -38,7 +38,7 @@ export function CreateCommentReaction(): Command< address_id: address.id!, comment_id: comment.id, reaction: payload.reaction, - calculated_voting_weight, + calculated_voting_weight: calculated_voting_weight?.toString(), canvas_msg_id: payload.canvas_msg_id, canvas_signed_data: payload.canvas_signed_data, }, diff --git a/libs/model/src/community/CreateTopic.command.ts b/libs/model/src/community/CreateTopic.command.ts index 35f7aaf4cd4..65c17dab2f2 100644 --- a/libs/model/src/community/CreateTopic.command.ts +++ b/libs/model/src/community/CreateTopic.command.ts @@ -63,7 +63,6 @@ export function CreateTopic(): Command< options = { ...options, weighted_voting: payload.weighted_voting, - chain_node_id: payload.chain_node_id || undefined, token_address: payload.token_address || undefined, token_symbol: payload.token_symbol || undefined, vote_weight_multiplier: payload.vote_weight_multiplier || undefined, diff --git a/libs/model/src/models/associations.ts b/libs/model/src/models/associations.ts index 0ef84150c9f..6807b32f7d5 100644 --- a/libs/model/src/models/associations.ts +++ b/libs/model/src/models/associations.ts @@ -34,8 +34,7 @@ export const buildAssociations = (db: DB) => { db.ChainNode.withMany(db.Community) .withMany(db.EvmEventSource) - .withOne(db.LastProcessedEvmBlock) - .withMany(db.Topic); + .withOne(db.LastProcessedEvmBlock); db.ContractAbi.withMany(db.EvmEventSource, { foreignKey: 'abi_id' }); diff --git a/libs/model/src/models/comment.ts b/libs/model/src/models/comment.ts index 8d7f9ebc339..abd1a1aa24c 100644 --- a/libs/model/src/models/comment.ts +++ b/libs/model/src/models/comment.ts @@ -56,7 +56,7 @@ export default ( defaultValue: 0, }, reaction_weights_sum: { - type: Sequelize.INTEGER, + type: Sequelize.DECIMAL(78, 0), allowNull: false, defaultValue: 0, }, diff --git a/libs/model/src/models/reaction.ts b/libs/model/src/models/reaction.ts index 781d12d4367..554c5caedd5 100644 --- a/libs/model/src/models/reaction.ts +++ b/libs/model/src/models/reaction.ts @@ -20,7 +20,10 @@ export default ( comment_id: { type: Sequelize.INTEGER, allowNull: true }, address_id: { type: Sequelize.INTEGER, allowNull: false }, reaction: { type: Sequelize.ENUM('like'), allowNull: false }, - calculated_voting_weight: { type: Sequelize.INTEGER, allowNull: true }, + calculated_voting_weight: { + type: Sequelize.DECIMAL(78, 0), + allowNull: true, + }, // canvas-related columns canvas_signed_data: { type: Sequelize.JSONB, allowNull: true }, canvas_msg_id: { type: Sequelize.STRING, allowNull: true }, diff --git a/libs/model/src/models/thread.ts b/libs/model/src/models/thread.ts index 714720df1c3..ab7fa6174d9 100644 --- a/libs/model/src/models/thread.ts +++ b/libs/model/src/models/thread.ts @@ -77,7 +77,7 @@ export default ( defaultValue: 0, }, reaction_weights_sum: { - type: Sequelize.INTEGER, + type: Sequelize.DECIMAL(78, 0), allowNull: false, defaultValue: 0, }, diff --git a/libs/model/src/models/topic.ts b/libs/model/src/models/topic.ts index 0969f8988f1..fa2289b9b30 100644 --- a/libs/model/src/models/topic.ts +++ b/libs/model/src/models/topic.ts @@ -1,7 +1,6 @@ import { Topic } from '@hicommonwealth/schemas'; import Sequelize from 'sequelize'; import { z } from 'zod'; -import { ChainNodeAttributes } from './chain_node'; import type { CommunityAttributes } from './community'; import type { ThreadAttributes } from './thread'; import type { ModelInstance } from './types'; @@ -10,7 +9,6 @@ export type TopicAttributes = z.infer & { // associations community?: CommunityAttributes; threads?: ThreadAttributes[] | TopicAttributes['id'][]; - ChainNode?: ChainNodeAttributes; }; export type TopicInstance = ModelInstance; @@ -50,18 +48,9 @@ export default ( }, telegram: { type: Sequelize.STRING, allowNull: true }, weighted_voting: { type: Sequelize.STRING, allowNull: true }, - chain_node_id: { - type: Sequelize.INTEGER, - allowNull: true, - references: { - model: 'ChainNodes', - key: 'id', - }, - onUpdate: 'CASCADE', - }, token_address: { type: Sequelize.STRING, allowNull: true }, token_symbol: { type: Sequelize.STRING, allowNull: true }, - vote_weight_multiplier: { type: Sequelize.INTEGER, allowNull: true }, + vote_weight_multiplier: { type: Sequelize.FLOAT, allowNull: true }, }, { timestamps: true, diff --git a/libs/model/src/services/stakeHelper.ts b/libs/model/src/services/stakeHelper.ts index 313d979b789..40b35bf874d 100644 --- a/libs/model/src/services/stakeHelper.ts +++ b/libs/model/src/services/stakeHelper.ts @@ -17,9 +17,9 @@ import { contractHelpers } from '../services/commonProtocol'; export async function getVotingWeight( topic_id: number, address: string, -): Promise { +): Promise { if (config.STAKE.REACTION_WEIGHT_OVERRIDE) - return config.STAKE.REACTION_WEIGHT_OVERRIDE; + return BigNumber.from(config.STAKE.REACTION_WEIGHT_OVERRIDE); const topic = await models.Topic.findByPk(topic_id, { include: [ @@ -38,25 +38,21 @@ export async function getVotingWeight( }, ], }, - { - model: models.ChainNode, - required: false, - }, ], }); - mustExist('Topic', topic); const { community } = topic; - mustExist('Community', community); + const chain_node = community.ChainNode; + if (topic.weighted_voting === TopicWeightedVoting.Stake) { + mustExist('Chain Node Eth Chain Id', chain_node?.eth_chain_id); mustExist('Community Namespace Address', community.namespace_address); + const stake = topic.community?.CommunityStakes?.at(0); mustExist('Community Stake', stake); - const chain_node = community.ChainNode; - mustExist('Chain Node Eth Chain Id', chain_node?.eth_chain_id); const stakeBalances = await contractHelpers.getNamespaceBalance( community.namespace_address, @@ -70,24 +66,23 @@ export async function getVotingWeight( return commonProtocol.calculateVoteWeight(stakeBalance, stake.vote_weight); } else if (topic.weighted_voting === TopicWeightedVoting.ERC20) { - const { - ChainNode: chain_node, - token_address, - vote_weight_multiplier, - } = topic; - mustExist('Topic Chain Node Eth Chain Id', chain_node?.eth_chain_id); + mustExist('Chain Node Eth Chain Id', chain_node?.eth_chain_id); const balances = await tokenBalanceCache.getBalances({ balanceSourceType: BalanceSourceType.ERC20, addresses: [address], sourceOptions: { - evmChainId: chain_node?.eth_chain_id, - contractAddress: token_address!, + evmChainId: chain_node.eth_chain_id, + contractAddress: topic.token_address!, }, cacheRefresh: true, }); - const balance = balances[address]; - return commonProtocol.calculateVoteWeight(balance, vote_weight_multiplier!); + const result = commonProtocol.calculateVoteWeight( + balances[address], + topic.vote_weight_multiplier!, + ); + // only count full ERC20 tokens + return result?.div(BigNumber.from(10).pow(18)) || null; } // no weighted voting diff --git a/libs/model/src/tester/e2eSeeds.ts b/libs/model/src/tester/e2eSeeds.ts index cae953543d3..3d6c81d2309 100644 --- a/libs/model/src/tester/e2eSeeds.ts +++ b/libs/model/src/tester/e2eSeeds.ts @@ -201,7 +201,7 @@ export const e2eTestEntities = async function ( stage: 'discussion', view_count: 0, reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', comment_count: 0, search: getThreadSearchVector( `testThread Title ${-i - 1}`, @@ -233,7 +233,7 @@ export const e2eTestEntities = async function ( stage: 'discussion', view_count: 0, reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', comment_count: 0, search: getThreadSearchVector( `testThread Title ${-i - 1 - 2}`, @@ -276,6 +276,7 @@ export const e2eTestEntities = async function ( text: '', thread_id: -1, reaction_count: 0, + reaction_weights_sum: '0', search: getCommentSearchVector(''), }, }) @@ -298,6 +299,7 @@ export const e2eTestEntities = async function ( text: '', thread_id: -2, reaction_count: 0, + reaction_weights_sum: '0', search: getCommentSearchVector(''), }, }) diff --git a/libs/model/src/thread/CreateThread.command.ts b/libs/model/src/thread/CreateThread.command.ts index 579350acae6..7b8f77ee5d5 100644 --- a/libs/model/src/thread/CreateThread.command.ts +++ b/libs/model/src/thread/CreateThread.command.ts @@ -131,7 +131,7 @@ export function CreateThread(): Command< view_count: 0, comment_count: 0, reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', search: getThreadSearchVector(rest.title, body), content_url: contentUrl, }, diff --git a/libs/model/src/thread/CreateThreadReaction.command.ts b/libs/model/src/thread/CreateThreadReaction.command.ts index 935360ce7ae..351e57cc40e 100644 --- a/libs/model/src/thread/CreateThreadReaction.command.ts +++ b/libs/model/src/thread/CreateThreadReaction.command.ts @@ -46,7 +46,7 @@ export function CreateThreadReaction(): Command< address_id: address.id!, thread_id: thread.id, reaction: payload.reaction, - calculated_voting_weight, + calculated_voting_weight: calculated_voting_weight?.toString(), canvas_msg_id: payload.canvas_msg_id, canvas_signed_data: payload.canvas_signed_data, }, diff --git a/libs/model/test/community/community-lifecycle.spec.ts b/libs/model/test/community/community-lifecycle.spec.ts index 9adb0f9f583..fe52cd1695b 100644 --- a/libs/model/test/community/community-lifecycle.spec.ts +++ b/libs/model/test/community/community-lifecycle.spec.ts @@ -460,7 +460,6 @@ describe('Community lifecycle', () => { }); test('should create topic (stake weighted)', async () => { - // when community is staked, topic will automatically be staked await models.CommunityStake.create({ community_id: community.id, stake_id: 1, @@ -476,6 +475,7 @@ describe('Community lifecycle', () => { description: 'boohoo', featured_in_sidebar: false, featured_in_new_post: false, + weighted_voting: TopicWeightedVoting.Stake, }, }); const { topic } = result!; diff --git a/libs/model/test/contest-worker/contest-worker-policy.spec.ts b/libs/model/test/contest-worker/contest-worker-policy.spec.ts index 3b73b4d6437..47a3b759b2f 100644 --- a/libs/model/test/contest-worker/contest-worker-policy.spec.ts +++ b/libs/model/test/contest-worker/contest-worker-policy.spec.ts @@ -99,7 +99,7 @@ describe('Contest Worker Policy', () => { stage: '', view_count: 0, reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', comment_count: 0, deleted_at: undefined, pinned: false, diff --git a/libs/model/test/contest/contests-projection-lifecycle.spec.ts b/libs/model/test/contest/contests-projection-lifecycle.spec.ts index 057777a56fd..e8afe908dff 100644 --- a/libs/model/test/contest/contests-projection-lifecycle.spec.ts +++ b/libs/model/test/contest/contests-projection-lifecycle.spec.ts @@ -162,7 +162,7 @@ describe('Contests projection lifecycle', () => { topic_id: undefined, view_count: 1, reaction_count: 1, - reaction_weights_sum: 1, + reaction_weights_sum: '1', comment_count: 1, discord_meta: undefined, deleted_at: undefined, // so we can find it! diff --git a/libs/model/test/email/recap-email-lifecycle.spec.ts b/libs/model/test/email/recap-email-lifecycle.spec.ts index 9450116bc95..2654dbd2d79 100644 --- a/libs/model/test/email/recap-email-lifecycle.spec.ts +++ b/libs/model/test/email/recap-email-lifecycle.spec.ts @@ -72,11 +72,13 @@ describe('Recap email lifecycle', () => { topic_id: community?.topics?.at(0)?.id, pinned: false, read_only: false, + reaction_weights_sum: '0', }); [comment] = await seed('Comment', { address_id: community?.Addresses?.at(0)?.id, thread_id: thread!.id!, + reaction_weights_sum: '0', }); }); diff --git a/libs/model/test/email/util.ts b/libs/model/test/email/util.ts index e344c8fde25..6b3fef65efa 100644 --- a/libs/model/test/email/util.ts +++ b/libs/model/test/email/util.ts @@ -324,6 +324,7 @@ export async function generateThreads( topic_id: communityThree?.topics?.at(0)?.id, pinned: false, read_only: false, + reaction_weights_sum: '0', }); // 3 threads for communityOne and 1 thread for communityTwo @@ -334,6 +335,7 @@ export async function generateThreads( pinned: false, read_only: false, view_count: 10, + reaction_weights_sum: '0', }); const [threadTwo] = await seed('Thread', { address_id: communityOne?.Addresses?.at(0)?.id, @@ -342,6 +344,7 @@ export async function generateThreads( pinned: false, read_only: false, view_count: 5, + reaction_weights_sum: '0', }); const [threadThree] = await seed('Thread', { @@ -351,6 +354,7 @@ export async function generateThreads( pinned: false, read_only: false, view_count: 1, + reaction_weights_sum: '0', }); const [threadFour] = await seed('Thread', { @@ -360,6 +364,7 @@ export async function generateThreads( pinned: false, read_only: false, view_count: 10, + reaction_weights_sum: '0', }); return { diff --git a/libs/model/test/reaction/reaction-lifecycle.spec.ts b/libs/model/test/reaction/reaction-lifecycle.spec.ts index a2aee704848..f70d0837714 100644 --- a/libs/model/test/reaction/reaction-lifecycle.spec.ts +++ b/libs/model/test/reaction/reaction-lifecycle.spec.ts @@ -53,6 +53,7 @@ describe('Reactions lifecycle', () => { deleted_at: undefined, // so we can find it! pinned: false, read_only: false, + reaction_weights_sum: '0', }, //{ mock: true, log: true }, ); @@ -68,7 +69,7 @@ describe('Reactions lifecycle', () => { reaction: 'like', canvas_signed_data: '', canvas_msg_id: '', - calculated_voting_weight: 0, + calculated_voting_weight: '0', }); const lastOutboxEntry = await models.Outbox.findOne({ diff --git a/libs/model/test/subscription/comment-subscription-lifecycle.spec.ts b/libs/model/test/subscription/comment-subscription-lifecycle.spec.ts index 559c62f0183..62174ddc18c 100644 --- a/libs/model/test/subscription/comment-subscription-lifecycle.spec.ts +++ b/libs/model/test/subscription/comment-subscription-lifecycle.spec.ts @@ -46,15 +46,18 @@ describe('Comment subscription lifecycle', () => { topic_id: community?.topics?.at(0)?.id, pinned: false, read_only: false, + reaction_weights_sum: '0', }); [commentOne] = await seed('Comment', { address_id: community?.Addresses?.at(0)?.id, thread_id: thread!.id!, + reaction_weights_sum: '0', }); [commentTwo] = await seed('Comment', { address_id: community?.Addresses?.at(0)?.id, thread_id: thread!.id!, + reaction_weights_sum: '0', }); actor = { user: { id: user!.id!, email: user!.email! }, diff --git a/libs/model/test/subscription/thread-subscription-lifecycle.spec.ts b/libs/model/test/subscription/thread-subscription-lifecycle.spec.ts index ce23d43738d..c824e5cfa81 100644 --- a/libs/model/test/subscription/thread-subscription-lifecycle.spec.ts +++ b/libs/model/test/subscription/thread-subscription-lifecycle.spec.ts @@ -46,6 +46,7 @@ describe('Thread subscription lifecycle', () => { topic_id: community!.topics![0].id, pinned: false, read_only: false, + reaction_weights_sum: '0', }); [threadTwo] = await seed('Thread', { address_id: community!.Addresses![0].id!, @@ -53,6 +54,7 @@ describe('Thread subscription lifecycle', () => { topic_id: community!.topics![0].id, pinned: false, read_only: false, + reaction_weights_sum: '0', }); actor = { user: { id: user!.id!, email: user!.email! }, diff --git a/libs/model/test/thread/thread-lifecycle.spec.ts b/libs/model/test/thread/thread-lifecycle.spec.ts index 866dc4c2ff7..405cb8134fa 100644 --- a/libs/model/test/thread/thread-lifecycle.spec.ts +++ b/libs/model/test/thread/thread-lifecycle.spec.ts @@ -228,6 +228,7 @@ describe('Thread lifecycle', () => { archived_at: new Date(), pinned: false, read_only: false, + reaction_weights_sum: '0', }); archived = archived_thread; @@ -237,6 +238,7 @@ describe('Thread lifecycle', () => { topic_id: community?.topics?.at(0)?.id, pinned: false, read_only: true, + reaction_weights_sum: '0', }); read_only = read_only_thread; @@ -896,9 +898,11 @@ describe('Thread lifecycle', () => { }, }); const expectedWeight = 50 * vote_weight; - expect(reaction?.calculated_voting_weight).to.eq(expectedWeight); + expect(`${reaction?.calculated_voting_weight}`).to.eq( + `${expectedWeight}`, + ); const t = await models.Thread.findByPk(thread!.id); - expect(t!.reaction_weights_sum).to.eq(expectedWeight); + expect(`${t!.reaction_weights_sum}`).to.eq(`${expectedWeight}`); }); test('should delete a reaction', async () => { @@ -966,9 +970,11 @@ describe('Thread lifecycle', () => { }, }); const expectedWeight = 50 * vote_weight; - expect(reaction?.calculated_voting_weight).to.eq(expectedWeight); + expect(`${reaction?.calculated_voting_weight}`).to.eq( + `${expectedWeight}`, + ); const c = await models.Comment.findByPk(comment!.id); - expect(c!.reaction_weights_sum).to.eq(expectedWeight * 2); // *2 to account for first member reaction + expect(`${c!.reaction_weights_sum}`).to.eq(`${expectedWeight * 2}`); // *2 to account for first member reaction }); test('should throw error when comment not found', async () => { diff --git a/libs/model/test/user/new-content-lifecycle.spec.ts b/libs/model/test/user/new-content-lifecycle.spec.ts index e4b73ff5261..d4ad04cd84f 100644 --- a/libs/model/test/user/new-content-lifecycle.spec.ts +++ b/libs/model/test/user/new-content-lifecycle.spec.ts @@ -74,6 +74,7 @@ describe('New Content lifecycle', () => { pinned: false, read_only: false, body: 'Sample 1', + reaction_weights_sum: '0', }); await seed('Thread', { address_id: address1.id!, @@ -81,6 +82,7 @@ describe('New Content lifecycle', () => { pinned: false, read_only: false, body: 'Sample 2', + reaction_weights_sum: '0', }); // now actor 2 should only get 1 entry for that community in new content array diff --git a/libs/model/test/util-tests/getCommentDepth.spec.ts b/libs/model/test/util-tests/getCommentDepth.spec.ts index 99a02dca6c2..09c438b1938 100644 --- a/libs/model/test/util-tests/getCommentDepth.spec.ts +++ b/libs/model/test/util-tests/getCommentDepth.spec.ts @@ -28,6 +28,7 @@ describe('getCommentDepth', () => { title: 'Testing', kind: 'discussion', search: getThreadSearchVector('Testing', ''), + reaction_weights_sum: '0', }); let comment: CommentInstance; for (let i = 0; i < maxDepth; i++) { diff --git a/libs/schemas/src/commands/community.schemas.ts b/libs/schemas/src/commands/community.schemas.ts index 05953b63b97..48204383c89 100644 --- a/libs/schemas/src/commands/community.schemas.ts +++ b/libs/schemas/src/commands/community.schemas.ts @@ -170,7 +170,6 @@ export const CreateTopic = { featured_in_new_post: true, default_offchain_template: true, weighted_voting: true, - chain_node_id: true, token_address: true, token_symbol: true, vote_weight_multiplier: true, diff --git a/libs/schemas/src/entities/comment.schemas.ts b/libs/schemas/src/entities/comment.schemas.ts index 493e4624e24..37ab3e422a3 100644 --- a/libs/schemas/src/entities/comment.schemas.ts +++ b/libs/schemas/src/entities/comment.schemas.ts @@ -41,8 +41,12 @@ export const Comment = z.object({ .nullish(), reaction_count: PG_INT, - reaction_weights_sum: PG_INT.optional(), - + reaction_weights_sum: z + .string() + .refine((str) => { + return /^[0-9]+$/.test(str); // only numbers + }) + .nullish(), search: z.union([z.string(), z.record(z.any())]), Address: Address.nullish(), diff --git a/libs/schemas/src/entities/reaction.schemas.ts b/libs/schemas/src/entities/reaction.schemas.ts index 77ebf3cca5f..8539c940dc1 100644 --- a/libs/schemas/src/entities/reaction.schemas.ts +++ b/libs/schemas/src/entities/reaction.schemas.ts @@ -9,7 +9,7 @@ export const Reaction = z.object({ thread_id: PG_INT.nullish(), comment_id: PG_INT.nullish(), proposal_id: z.number().nullish(), - calculated_voting_weight: PG_INT.nullish(), + calculated_voting_weight: z.string().nullish(), canvas_signed_data: z.any().nullish(), canvas_msg_id: z.string().max(255).nullish(), created_at: z.coerce.date().optional(), diff --git a/libs/schemas/src/entities/thread.schemas.ts b/libs/schemas/src/entities/thread.schemas.ts index bc8cd1b8478..0787557ca9e 100644 --- a/libs/schemas/src/entities/thread.schemas.ts +++ b/libs/schemas/src/entities/thread.schemas.ts @@ -49,7 +49,12 @@ export const Thread = z.object({ //counts reaction_count: PG_INT.optional(), - reaction_weights_sum: PG_INT.optional(), + reaction_weights_sum: z + .string() + .refine((str) => { + return /^[0-9]+$/.test(str); // only numbers + }) + .nullish(), comment_count: PG_INT.optional().optional(), activity_rank_date: z.coerce.date().nullish(), diff --git a/libs/schemas/src/entities/topic.schemas.ts b/libs/schemas/src/entities/topic.schemas.ts index 3d6b9b0290d..75943cd5cb0 100644 --- a/libs/schemas/src/entities/topic.schemas.ts +++ b/libs/schemas/src/entities/topic.schemas.ts @@ -39,9 +39,6 @@ export const Topic = z.object({ group_ids: z.array(PG_INT).default([]), default_offchain_template_backup: z.string().nullish(), weighted_voting: z.nativeEnum(TopicWeightedVoting).nullish(), - chain_node_id: PG_INT.nullish().describe( - 'token chain node ID, used for ERC20 topics', - ), token_address: z .string() .nullish() @@ -50,9 +47,11 @@ export const Topic = z.object({ .string() .nullish() .describe('token symbol, used for ERC20 topics'), - vote_weight_multiplier: PG_INT.nullish().describe( - 'vote weight multiplier, used for ERC20 topics', - ), + vote_weight_multiplier: z + .number() + .gt(0) + .nullish() + .describe('vote weight multiplier, used for ERC20 topics'), created_at: z.coerce.date().optional(), updated_at: z.coerce.date().optional(), diff --git a/libs/shared/package.json b/libs/shared/package.json index 7c738da882e..dc40c06661b 100644 --- a/libs/shared/package.json +++ b/libs/shared/package.json @@ -31,9 +31,10 @@ "@canvas-js/interfaces": "^0.10.10", "@canvas-js/signatures": "^0.10.10", "@cosmjs/encoding": "0.32.3", + "@ethersproject/bignumber": "^5.7.0", "@ipld/dag-json": "^10.2.0", - "@polkadot/util": "12.6.2", "@libp2p/peer-id-factory": "^4.2.4", + "@polkadot/util": "12.6.2", "moment": "^2.23.0", "safe-stable-stringify": "^2.4.2" }, diff --git a/libs/shared/src/commonProtocol/utils.ts b/libs/shared/src/commonProtocol/utils.ts index 8a83ce19c58..61b090f5d9e 100644 --- a/libs/shared/src/commonProtocol/utils.ts +++ b/libs/shared/src/commonProtocol/utils.ts @@ -1,5 +1,15 @@ -export const calculateVoteWeight = (balance: string, voteWeight: number) => { - return parseInt(balance, 10) * voteWeight; +import { BigNumber } from '@ethersproject/bignumber'; + +export const calculateVoteWeight = ( + balance: string, // should be in wei + voteWeight: number, +): BigNumber | null => { + if (!balance || voteWeight <= 0) return null; + const bigBalance = BigNumber.from(balance); + const precision = 1e6; + const scaledVoteWeight = Math.floor(voteWeight * precision); + const result = bigBalance.mul(scaledVoteWeight).div(precision); + return result; }; export enum Denominations { diff --git a/libs/shared/test/commonProtocol.spec.ts b/libs/shared/test/commonProtocol.spec.ts new file mode 100644 index 00000000000..421ae3e5c90 --- /dev/null +++ b/libs/shared/test/commonProtocol.spec.ts @@ -0,0 +1,50 @@ +import { calculateVoteWeight } from 'shared/src/commonProtocol'; +import { describe, expect, it } from 'vitest'; + +describe('commonProtocol', () => { + describe('calculateVoteWeight', () => { + it('should calculate voting weight for balance with 1 multiplier', () => { + { + const result = calculateVoteWeight('1', 1); + expect(result!.toString()).eq('1'); + } + + { + const result = calculateVoteWeight('1000', 1); + expect(result!.toString()).eq('1000'); + } + }); + + it('should calculate voting weight for balance with > 1 multiplier', () => { + { + const result = calculateVoteWeight('1', 3); + expect(result!.toString()).eq('3'); + } + + { + const result = calculateVoteWeight('1000', 3); + expect(result!.toString()).eq('3000'); + } + + { + const result = calculateVoteWeight('1000000000000000000000000000', 7); + expect(result!.toString()).eq('7000000000000000000000000000'); + } + + { + const result = calculateVoteWeight('10', 1.5); + expect(result!.toString()).eq('15'); + } + + { + const result = calculateVoteWeight('1000', 1.234); + expect(result!.toString()).eq('1234'); + } + + { + const result = calculateVoteWeight('1000', 0.5); + expect(result!.toString()).eq('500'); + } + }); + }); +}); diff --git a/libs/sitemaps/test/integration/createSitemapGenerator.spec.ts b/libs/sitemaps/test/integration/createSitemapGenerator.spec.ts index 4e5e497c7f4..235688441f6 100644 --- a/libs/sitemaps/test/integration/createSitemapGenerator.spec.ts +++ b/libs/sitemaps/test/integration/createSitemapGenerator.spec.ts @@ -67,7 +67,7 @@ describe('createSitemapGenerator', { timeout: 10_000 }, function () { canvas_signed_data: '', canvas_msg_id: '', reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', comment_count: 0, profile_name: 'foobar', topic_id: topic.id, diff --git a/packages/commonwealth/client/scripts/models/Reaction.ts b/packages/commonwealth/client/scripts/models/Reaction.ts index 2943183422e..3745affc2e6 100644 --- a/packages/commonwealth/client/scripts/models/Reaction.ts +++ b/packages/commonwealth/client/scripts/models/Reaction.ts @@ -18,7 +18,7 @@ class Reaction { public readonly profile: UserProfile; - public calculatedVotingWeight: number; + public calculatedVotingWeight: string; // TODO: Do thread/comment/proposal ids ever appear as strings? constructor({ diff --git a/packages/commonwealth/client/scripts/models/Thread.ts b/packages/commonwealth/client/scripts/models/Thread.ts index 89f9fce5c3d..fb75903fbc2 100644 --- a/packages/commonwealth/client/scripts/models/Thread.ts +++ b/packages/commonwealth/client/scripts/models/Thread.ts @@ -263,7 +263,7 @@ export class Thread implements IUniqueId { public associatedReactions: AssociatedReaction[]; public associatedContests?: AssociatedContest[]; public recentComments?: Comment[]; - public reactionWeightsSum: number; + public reactionWeightsSum: string; public links: Link[]; public readonly discord_meta: any; public readonly latestActivity: Moment; @@ -353,7 +353,7 @@ export class Thread implements IUniqueId { reactionType?: any[]; // TODO: fix type reactionTimestamps?: string[]; reactionWeights?: number[]; - reaction_weights_sum: number; + reaction_weights_sum: string; ThreadVersionHistories: ThreadVersionHistory[]; Address: any; // TODO: fix type discord_meta?: any; @@ -457,7 +457,7 @@ export class Thread implements IUniqueId { parent_id: null, reactions: [], CommentVersionHistories: [], - reaction_weights_sum: 0, + reaction_weights_sum: '0', canvas_signed_data: null, canvas_msg_id: null, }), diff --git a/packages/commonwealth/client/scripts/models/Topic.ts b/packages/commonwealth/client/scripts/models/Topic.ts index b449b939e8a..44c349014d1 100644 --- a/packages/commonwealth/client/scripts/models/Topic.ts +++ b/packages/commonwealth/client/scripts/models/Topic.ts @@ -28,7 +28,6 @@ class Topic { public readonly defaultOffchainTemplate: TopicAttributes['default_offchain_template']; public totalThreads: TopicAttributes['total_threads']; public readonly activeContestManagers: TopicAttributes['active_contest_managers']; - public readonly chainNodeId: TopicAttributes['chain_node_id']; public readonly groupIds: TopicAttributes['group_ids']; public readonly defaultOffchainTemplateBackup: TopicAttributes['default_offchain_template_backup']; public readonly weightedVoting: TopicAttributes['weighted_voting']; @@ -49,7 +48,6 @@ class Topic { total_threads, channel_id, active_contest_managers, - chain_node_id, group_ids, default_offchain_template_backup, weighted_voting, @@ -69,7 +67,6 @@ class Topic { this.totalThreads = total_threads || 0; this.channelId = channel_id; this.activeContestManagers = active_contest_managers || []; - this.chainNodeId = chain_node_id; this.groupIds = group_ids; this.defaultOffchainTemplateBackup = default_offchain_template_backup; this.weightedVoting = weighted_voting; diff --git a/packages/commonwealth/client/scripts/state/api/feeds/util.ts b/packages/commonwealth/client/scripts/state/api/feeds/util.ts index b1f8470e7cf..f7a8eea5e67 100644 --- a/packages/commonwealth/client/scripts/state/api/feeds/util.ts +++ b/packages/commonwealth/client/scripts/state/api/feeds/util.ts @@ -67,7 +67,7 @@ export function formatActivityResponse(response: AxiosResponse) { version_history: null, last_commented_on: '', address_last_active: '', - reaction_weights_sum: 0, + reaction_weights_sum: '0', }), ); } diff --git a/packages/commonwealth/client/scripts/views/components/CommunityStake/VoteWeightModule/VoteWeightModule.tsx b/packages/commonwealth/client/scripts/views/components/CommunityStake/VoteWeightModule/VoteWeightModule.tsx index eb51017f5e9..432f638a5ed 100644 --- a/packages/commonwealth/client/scripts/views/components/CommunityStake/VoteWeightModule/VoteWeightModule.tsx +++ b/packages/commonwealth/client/scripts/views/components/CommunityStake/VoteWeightModule/VoteWeightModule.tsx @@ -17,7 +17,7 @@ import { CWTooltip } from '../../component_kit/new_designs/CWTooltip'; import './VoteWeightModule.scss'; type VoteWeightModuleProps = { - voteWeight: number; + voteWeight: string; stakeNumber: number; stakeValue: number; denomination: string; @@ -72,7 +72,7 @@ export const VoteWeightModule = ({ /> - {isNaN(voteWeight) ? 0 : voteWeight} + {voteWeight}
diff --git a/packages/commonwealth/client/scripts/views/components/ReactionButton/CommentReactionButton.tsx b/packages/commonwealth/client/scripts/views/components/ReactionButton/CommentReactionButton.tsx index e45d01c5259..0206da4c7a4 100644 --- a/packages/commonwealth/client/scripts/views/components/ReactionButton/CommentReactionButton.tsx +++ b/packages/commonwealth/client/scripts/views/components/ReactionButton/CommentReactionButton.tsx @@ -3,6 +3,7 @@ import { buildDeleteCommentReactionInput } from 'client/scripts/state/api/commen import { useAuthModalStore } from 'client/scripts/state/ui/modals'; import { notifyError } from 'controllers/app/notifications'; import { SessionKeyError } from 'controllers/server/sessions'; +import { BigNumber } from 'ethers'; import React, { useState } from 'react'; import app from 'state'; import useUserStore from 'state/ui/user'; @@ -52,8 +53,8 @@ export const CommentReactionButton = ({ (x) => x?.author === activeAddress, ); const reactionWeightsSum = comment.reactions.reduce( - (acc, curr) => acc + (curr.calculatedVotingWeight || 1), - 0, + (acc, reaction) => acc.add(reaction.calculatedVotingWeight || 1), + BigNumber.from(0), ); const handleVoteClick = async (e) => { @@ -117,7 +118,7 @@ export const CommentReactionButton = ({ isOpen={isAuthModalOpen} /> ) => void; @@ -41,13 +41,13 @@ const CWUpvoteSmall = ({ onMouseEnter={popoverProps.handleInteraction} onMouseLeave={popoverProps.handleInteraction} > - {voteCount > 0 && !disabled ? ( + {voteCount && !disabled ? ( <> @@ -58,7 +58,7 @@ const CWUpvoteSmall = ({ action="upvote" isThreadArchived={isThreadArchived} selected={selected} - label={String(voteCount)} + label={voteCount} disabled={disabled} tooltipText={tooltipText} onClick={handleClick} diff --git a/packages/commonwealth/client/scripts/views/components/component_kit/new_designs/cw_upvote.tsx b/packages/commonwealth/client/scripts/views/components/component_kit/new_designs/cw_upvote.tsx index 99594b9b119..516c5d197cc 100644 --- a/packages/commonwealth/client/scripts/views/components/component_kit/new_designs/cw_upvote.tsx +++ b/packages/commonwealth/client/scripts/views/components/component_kit/new_designs/cw_upvote.tsx @@ -1,16 +1,17 @@ import { ArrowFatUp } from '@phosphor-icons/react'; import React, { FC } from 'react'; -import { formatNumberShort } from 'adapters/currency'; +import { formatBigNumberShort } from 'adapters/currency'; import { CWText } from '../cw_text'; import { getClasses } from '../helpers'; import 'components/component_kit/new_designs/cw_upvote.scss'; +import { BigNumber } from 'ethers'; import { AnchorType } from 'views/components/component_kit/new_designs/CWPopover'; import { ComponentType } from '../types'; type CWUpvoteProps = { - voteCount: number; + voteCount: string; active?: boolean; disabled?: boolean; onClick?: (e) => void; @@ -47,7 +48,7 @@ export const CWUpvote: FC = ({ weight={active ? 'fill' : 'regular'} /> - {formatNumberShort(voteCount)} + {formatBigNumberShort(BigNumber.from(voteCount || 0))} ); diff --git a/packages/commonwealth/client/scripts/views/components/feed.tsx b/packages/commonwealth/client/scripts/views/components/feed.tsx index 3784fe063c3..b9cf9bca891 100644 --- a/packages/commonwealth/client/scripts/views/components/feed.tsx +++ b/packages/commonwealth/client/scripts/views/components/feed.tsx @@ -159,7 +159,7 @@ function mapThread(thread: z.infer): Thread { userId: thread.user_id, last_edited: thread.updated_at ?? '', last_commented_on: '', - reaction_weights_sum: 0, + reaction_weights_sum: '0', address_last_active: '', ContestActions: [], numberOfComments: thread.number_of_comments, diff --git a/packages/commonwealth/client/scripts/views/components/sidebar/CommunitySection/CommunitySection.tsx b/packages/commonwealth/client/scripts/views/components/sidebar/CommunitySection/CommunitySection.tsx index 704d3a0fa4e..f39ba061d60 100644 --- a/packages/commonwealth/client/scripts/views/components/sidebar/CommunitySection/CommunitySection.tsx +++ b/packages/commonwealth/client/scripts/views/components/sidebar/CommunitySection/CommunitySection.tsx @@ -81,7 +81,7 @@ export const CommunitySection = ({ showSkeleton }: CommunitySectionProps) => { {stakeEnabled && (
- Current vote weight {currentVoteWeight} + Current vote weight {currentVoteWeight?.toString()}
@@ -419,7 +419,7 @@ const StakeExchangeForm = ({ Total weight - {expectedVoteWeight} + {expectedVoteWeight?.toString()} diff --git a/packages/commonwealth/client/scripts/views/modals/confirm_snapshot_vote_modal.tsx b/packages/commonwealth/client/scripts/views/modals/confirm_snapshot_vote_modal.tsx index 7bd052d1d49..5b386ab88b7 100644 --- a/packages/commonwealth/client/scripts/views/modals/confirm_snapshot_vote_modal.tsx +++ b/packages/commonwealth/client/scripts/views/modals/confirm_snapshot_vote_modal.tsx @@ -1,7 +1,8 @@ import React from 'react'; -import { formatNumberShort } from 'adapters/currency'; +import { formatBigNumberShort } from 'adapters/currency'; import { MixpanelSnapshotEvents } from 'analytics/types'; +import { BigNumber } from 'ethers'; import type { SnapshotProposal, SnapshotSpace } from 'helpers/snapshot_utils'; import { useBrowserAnalyticsTrack } from 'hooks/useBrowserAnalyticsTrack'; import useUserStore from 'state/ui/user'; @@ -97,7 +98,7 @@ export const ConfirmSnapshotVoteModal = (
Your voting power - {`${formatNumberShort(totalScore)} ${space.symbol + {`${formatBigNumberShort(BigNumber.from(totalScore))} ${space.symbol .slice(0, 6) .trim()}...`} diff --git a/packages/commonwealth/client/scripts/views/pages/ComponentsShowcase/components/Upvotes.showcase.tsx b/packages/commonwealth/client/scripts/views/pages/ComponentsShowcase/components/Upvotes.showcase.tsx index 6b6f603e167..954ac4c87e1 100644 --- a/packages/commonwealth/client/scripts/views/pages/ComponentsShowcase/components/Upvotes.showcase.tsx +++ b/packages/commonwealth/client/scripts/views/pages/ComponentsShowcase/components/Upvotes.showcase.tsx @@ -8,15 +8,15 @@ const UpvotesShowcase = () => { <> Regular
- - - + + +
Small
@@ -24,7 +24,7 @@ const UpvotesShowcase = () => { popoverContent={
Upvoters List
} /> @@ -32,7 +32,7 @@ const UpvotesShowcase = () => { popoverContent={
Upvoters List
} /> diff --git a/packages/commonwealth/client/scripts/views/pages/discussions/ThreadCard/ThreadOptions/ReactionButton/ReactionButton.tsx b/packages/commonwealth/client/scripts/views/pages/discussions/ThreadCard/ThreadOptions/ReactionButton/ReactionButton.tsx index 1fdb5af1ca5..82171497502 100644 --- a/packages/commonwealth/client/scripts/views/pages/discussions/ThreadCard/ThreadOptions/ReactionButton/ReactionButton.tsx +++ b/packages/commonwealth/client/scripts/views/pages/discussions/ThreadCard/ThreadOptions/ReactionButton/ReactionButton.tsx @@ -3,6 +3,7 @@ import { buildDeleteThreadReactionInput } from 'client/scripts/state/api/threads import { useAuthModalStore } from 'client/scripts/state/ui/modals'; import { notifyError } from 'controllers/app/notifications'; import { SessionKeyError } from 'controllers/server/sessions'; +import { BigNumber } from 'ethers'; import type Thread from 'models/Thread'; import React, { useState } from 'react'; import app from 'state'; @@ -46,9 +47,10 @@ export const ReactionButton = ({ const reactionWeightsSum = thread?.associatedReactions?.reduce( - (acc, curr) => acc + (curr.voting_weight || 1), - 0, - ) || 0; + (acc, reaction) => acc.add(reaction.voting_weight || 1), + BigNumber.from(0), + ) || BigNumber.from(0); + const activeAddress = user.activeAccount?.address; const thisUserReaction = thread?.associatedReactions?.filter( (r) => r.address === activeAddress, @@ -129,7 +131,7 @@ export const ReactionButton = ({ <> {size === 'small' ? ( @@ -155,7 +157,7 @@ export const ReactionButton = ({ > diff --git a/packages/commonwealth/client/scripts/views/pages/discussions/helpers.ts b/packages/commonwealth/client/scripts/views/pages/discussions/helpers.ts index 9f693bc02a8..543715748e5 100644 --- a/packages/commonwealth/client/scripts/views/pages/discussions/helpers.ts +++ b/packages/commonwealth/client/scripts/views/pages/discussions/helpers.ts @@ -1,3 +1,4 @@ +import { BigNumber } from 'ethers'; import moment from 'moment'; import type Thread from '../../../models/Thread'; import { ThreadFeaturedFilterTypes } from '../../../models/types'; @@ -45,7 +46,18 @@ export const sortByFeaturedFilter = (t: Thread[], featuredFilter) => { } if (featuredFilter === ThreadFeaturedFilterTypes.MostLikes) { - return [...t].sort((a, b) => b.reactionWeightsSum - a.reactionWeightsSum); + return [...t].sort((a, b) => { + const aWeight = BigNumber.from(a.reactionWeightsSum); + const bWeight = BigNumber.from(b.reactionWeightsSum); + + if (aWeight.lt(bWeight)) { + return 1; + } else if (aWeight.gt(bWeight)) { + return -1; + } else { + return 0; + } + }); } if (featuredFilter === ThreadFeaturedFilterTypes.LatestActivity) { diff --git a/packages/commonwealth/server/migrations/20241016173039-remove-topic-chain-node.js b/packages/commonwealth/server/migrations/20241016173039-remove-topic-chain-node.js new file mode 100644 index 00000000000..89dfeeb1cb2 --- /dev/null +++ b/packages/commonwealth/server/migrations/20241016173039-remove-topic-chain-node.js @@ -0,0 +1,20 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.removeColumn('Topics', 'chain_node_id'); + }, + + async down(queryInterface, Sequelize) { + await queryInterface.addColumn('Topics', 'chain_node_id', { + type: Sequelize.INTEGER, + allowNull: true, + references: { + model: 'ChainNodes', + key: 'id', + }, + onUpdate: 'CASCADE', + }); + }, +}; diff --git a/packages/commonwealth/server/migrations/20241016192854-reaction-voting-weight-numeric.js b/packages/commonwealth/server/migrations/20241016192854-reaction-voting-weight-numeric.js new file mode 100644 index 00000000000..e75cda6901f --- /dev/null +++ b/packages/commonwealth/server/migrations/20241016192854-reaction-voting-weight-numeric.js @@ -0,0 +1,52 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.sequelize.transaction(async (transaction) => { + await queryInterface.changeColumn( + 'Reactions', + 'calculated_voting_weight', + { + type: Sequelize.NUMERIC(78, 0), // up to 78 digits with no decimal places + allowNull: true, + }, + { transaction }, + ); + await queryInterface.changeColumn( + 'Threads', + 'reaction_weights_sum', + { + type: Sequelize.NUMERIC(78, 0), // up to 78 digits with no decimal places + allowNull: false, + defaultValue: 0, + }, + { transaction }, + ); + await queryInterface.changeColumn( + 'Comments', + 'reaction_weights_sum', + { + type: Sequelize.NUMERIC(78, 0), // up to 78 digits with no decimal places + allowNull: false, + defaultValue: 0, + }, + { transaction }, + ); + await queryInterface.changeColumn( + 'Topics', + 'vote_weight_multiplier', + { + type: Sequelize.FLOAT, + allowNull: true, + }, + { transaction }, + ); + }); + }, + + async down(queryInterface, Sequelize) { + // irreversible because converting back to integer + // may result in overflow + }, +}; diff --git a/packages/commonwealth/shared/adapters/currency.ts b/packages/commonwealth/shared/adapters/currency.ts index f349894d8d3..b10534507aa 100644 --- a/packages/commonwealth/shared/adapters/currency.ts +++ b/packages/commonwealth/shared/adapters/currency.ts @@ -1,4 +1,5 @@ import BN from 'bn.js'; +import { BigNumber } from 'ethers'; // duplicated in helpers.ts export function formatNumberShort(num: number) { @@ -16,18 +17,45 @@ export function formatNumberShort(num: number) { return num > 1_000_000_000_000 ? `${round(num / 1_000_000_000_000)}t` : num > 1_000_000_000 - ? `${round(num / 1_000_000_000)}b` - : num > 1_000_000 - ? `${round(num / 1_000_000)}m` - : num > 1_000 - ? `${round(num / 1_000)}k` - : num > 0.1 - ? round(num) - : num > 0.01 - ? precise(num, 2) - : num > 0.001 - ? precise(num, 1) - : num.toString(); + ? `${round(num / 1_000_000_000)}b` + : num > 1_000_000 + ? `${round(num / 1_000_000)}m` + : num > 1_000 + ? `${round(num / 1_000)}k` + : num > 0.1 + ? round(num) + : num > 0.01 + ? precise(num, 2) + : num > 0.001 + ? precise(num, 1) + : num.toString(); +} + +export function formatBigNumberShort(num: BigNumber): string { + if (num.isZero()) { + return '0'; + } + const thousand = BigNumber.from(1_000); + const million = BigNumber.from(1_000_000); + const billion = BigNumber.from(1_000_000_000); + const trillion = BigNumber.from(1_000_000_000_000); + + const round = (n: BigNumber, divisor: BigNumber, digits = 2) => { + const divided = n.div(divisor); + const factor = BigNumber.from(10).pow(digits); + return divided.mul(factor).div(factor).toString(); + }; + + // Compare BigNumber values and format accordingly + return num.gt(trillion) + ? `${round(num, trillion)}t` + : num.gt(billion) + ? `${round(num, billion)}b` + : num.gt(million) + ? `${round(num, million)}m` + : num.gt(thousand) + ? `${round(num, thousand)}k` + : num.toString(); } const nf = new Intl.NumberFormat(); diff --git a/packages/commonwealth/test/integration/databaseCleaner.spec.ts b/packages/commonwealth/test/integration/databaseCleaner.spec.ts index 2b4e7897f5a..14bb2506f88 100644 --- a/packages/commonwealth/test/integration/databaseCleaner.spec.ts +++ b/packages/commonwealth/test/integration/databaseCleaner.spec.ts @@ -184,7 +184,7 @@ describe('DatabaseCleaner Tests', async () => { title: 'Testing', community_id: 'ethereum', reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', kind: 'discussion', stage: 'discussion', view_count: 0, @@ -197,7 +197,7 @@ describe('DatabaseCleaner Tests', async () => { address_id: address.id!, text: 'Testing', reaction_count: 0, - reaction_weights_sum: 0, + reaction_weights_sum: '0', search: getCommentSearchVector('Testing'), }); diff --git a/packages/commonwealth/test/integration/knock/commentCreated.spec.ts b/packages/commonwealth/test/integration/knock/commentCreated.spec.ts index 9ca71f9f34d..3d9e9cf680c 100644 --- a/packages/commonwealth/test/integration/knock/commentCreated.spec.ts +++ b/packages/commonwealth/test/integration/knock/commentCreated.spec.ts @@ -86,18 +86,21 @@ describe('CommentCreated Event Handler', () => { deleted_at: null, read_only: false, pinned: false, + reaction_weights_sum: '0', }); [rootComment] = await tester.seed('Comment', { parent_id: null, thread_id: thread!.id!, address_id: community!.Addresses![0].id, deleted_at: null, + reaction_weights_sum: '0', }); [replyComment] = await tester.seed('Comment', { parent_id: String(rootComment!.id), thread_id: thread!.id!, address_id: community!.Addresses![0].id, deleted_at: null, + reaction_weights_sum: '0', }); [mentionedComment] = await tester.seed('Comment', { text: `Hi [@${mentionedUser!.profile.name}](/profile/id/${ @@ -107,6 +110,7 @@ describe('CommentCreated Event Handler', () => { thread_id: thread!.id!, address_id: community!.Addresses![0].id, deleted_at: null, + reaction_weights_sum: '0', }); }); diff --git a/packages/commonwealth/test/integration/knock/userMentioned.spec.ts b/packages/commonwealth/test/integration/knock/userMentioned.spec.ts index c66bab304b7..ac8443c8495 100644 --- a/packages/commonwealth/test/integration/knock/userMentioned.spec.ts +++ b/packages/commonwealth/test/integration/knock/userMentioned.spec.ts @@ -67,6 +67,7 @@ describe('userMentioned Event Handler', () => { pinned: false, read_only: false, body: 'some body', + reaction_weights_sum: '0', }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79a7841919f..6ca563ae2e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -738,6 +738,9 @@ importers: '@cosmjs/encoding': specifier: 0.32.3 version: 0.32.3 + '@ethersproject/bignumber': + specifier: ^5.7.0 + version: 5.7.0 '@ipld/dag-json': specifier: ^10.2.0 version: 10.2.0 @@ -15583,8 +15586,8 @@ snapshots: '@aws-crypto/sha1-browser': 3.0.0 '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.577.0(@aws-sdk/client-sts@3.577.0) - '@aws-sdk/client-sts': 3.577.0 + '@aws-sdk/client-sso-oidc': 3.577.0 + '@aws-sdk/client-sts': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0) '@aws-sdk/core': 3.576.0 '@aws-sdk/credential-provider-node': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0)(@aws-sdk/client-sts@3.577.0) '@aws-sdk/middleware-bucket-endpoint': 3.577.0 @@ -15641,11 +15644,11 @@ snapshots: transitivePeerDependencies: - aws-crt - '@aws-sdk/client-sso-oidc@3.577.0(@aws-sdk/client-sts@3.577.0)': + '@aws-sdk/client-sso-oidc@3.577.0': dependencies: '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sts': 3.577.0 + '@aws-sdk/client-sts': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0) '@aws-sdk/core': 3.576.0 '@aws-sdk/credential-provider-node': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0)(@aws-sdk/client-sts@3.577.0) '@aws-sdk/middleware-host-header': 3.577.0 @@ -15684,7 +15687,6 @@ snapshots: '@smithy/util-utf8': 3.0.0 tslib: 2.6.2 transitivePeerDependencies: - - '@aws-sdk/client-sts' - aws-crt '@aws-sdk/client-sso@3.577.0': @@ -15730,11 +15732,11 @@ snapshots: transitivePeerDependencies: - aws-crt - '@aws-sdk/client-sts@3.577.0': + '@aws-sdk/client-sts@3.577.0(@aws-sdk/client-sso-oidc@3.577.0)': dependencies: '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.577.0(@aws-sdk/client-sts@3.577.0) + '@aws-sdk/client-sso-oidc': 3.577.0 '@aws-sdk/core': 3.576.0 '@aws-sdk/credential-provider-node': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0)(@aws-sdk/client-sts@3.577.0) '@aws-sdk/middleware-host-header': 3.577.0 @@ -15773,6 +15775,7 @@ snapshots: '@smithy/util-utf8': 3.0.0 tslib: 2.6.2 transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' - aws-crt '@aws-sdk/core@3.576.0': @@ -15806,7 +15809,7 @@ snapshots: '@aws-sdk/credential-provider-ini@3.577.0(@aws-sdk/client-sso-oidc@3.577.0)(@aws-sdk/client-sts@3.577.0)': dependencies: - '@aws-sdk/client-sts': 3.577.0 + '@aws-sdk/client-sts': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0) '@aws-sdk/credential-provider-env': 3.577.0 '@aws-sdk/credential-provider-process': 3.577.0 '@aws-sdk/credential-provider-sso': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0) @@ -15863,7 +15866,7 @@ snapshots: '@aws-sdk/credential-provider-web-identity@3.577.0(@aws-sdk/client-sts@3.577.0)': dependencies: - '@aws-sdk/client-sts': 3.577.0 + '@aws-sdk/client-sts': 3.577.0(@aws-sdk/client-sso-oidc@3.577.0) '@aws-sdk/types': 3.577.0 '@smithy/property-provider': 3.0.0 '@smithy/types': 3.0.0 @@ -16001,7 +16004,7 @@ snapshots: '@aws-sdk/token-providers@3.577.0(@aws-sdk/client-sso-oidc@3.577.0)': dependencies: - '@aws-sdk/client-sso-oidc': 3.577.0(@aws-sdk/client-sts@3.577.0) + '@aws-sdk/client-sso-oidc': 3.577.0 '@aws-sdk/types': 3.577.0 '@smithy/property-provider': 3.0.0 '@smithy/shared-ini-file-loader': 3.0.0