• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 17243471050

26 Aug 2025 03:51PM UTC coverage: 37.803%. Remained the same
17243471050

push

github

web-flow
Merge pull request #12760 from hicommonwealth/salman/issue#12757/thread-token-refactor-widget-and-modal

Thread Token Refactor Widget & Modal

1923 of 5479 branches covered (35.1%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

3402 of 8607 relevant lines covered (39.53%)

44.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/aggregates/thread/CreateThreadToken.command.ts
1
import {
2
  TokenBondingCurveAbi,
3
  TokenLaunchpadAbi,
4
} from '@commonxyz/common-protocol-abis';
5
import { type Command, InvalidState } from '@hicommonwealth/core';
6
import * as protocols from '@hicommonwealth/evm-protocols';
7
import { withRetries } from '@hicommonwealth/evm-protocols';
8
import * as schemas from '@hicommonwealth/schemas';
9
import { createPublicClient, Hash, http, parseEventLogs } from 'viem';
10
import { models } from '../../database';
11
import { mustExist } from '../../middleware';
12

13
export function CreateThreadToken(): Command<typeof schemas.CreateThreadToken> {
14
  return {
×
15
    ...schemas.CreateThreadToken,
16
    auth: [],
17
    body: async ({ payload }) => {
18
      const { eth_chain_id, transaction_hash } = payload;
×
19

20
      const chainNode = await models.ChainNode.findOne({
×
21
        where: { eth_chain_id },
22
        attributes: ['url', 'private_url'],
23
      });
24
      mustExist('ChainNode', chainNode);
×
25

26
      const rpc = chainNode.private_url! || chainNode.url!;
×
27
      const client = createPublicClient({
×
28
        transport: http(rpc),
29
      });
30

NEW
31
      const receipt = await withRetries(
×
32
        () =>
NEW
33
          client.getTransactionReceipt({
×
34
            hash: transaction_hash as Hash,
35
          }),
36
        15000,
37
      );
38

39
      const parsedLogs = parseEventLogs({
×
40
        abi: TokenBondingCurveAbi,
41
        eventName: 'TokenRegistered',
42
        logs: receipt.logs,
43
      });
44

45
      if (parsedLogs.length === 0) {
×
46
        throw new InvalidState(
×
47
          'TokenRegistered event could not be processed from txReceipt',
48
        );
49
      }
50

51
      const {
52
        token: tokenAddress,
53
        totalSupply,
54
        launchpadLiquidity,
55
      } = parsedLogs[0].args;
×
56

57
      const tokenCreatedParsedLogs = parseEventLogs({
×
58
        abi: TokenLaunchpadAbi,
59
        eventName: 'NewTokenCreated',
60
        logs: receipt.logs,
61
      });
62

63
      if (tokenCreatedParsedLogs.length === 0) {
×
64
        throw new InvalidState(
×
65
          'NewTokenCreated event could not be processed from txReceipt',
66
        );
67
      }
68

69
      const { name, symbol, threadId } = tokenCreatedParsedLogs[0].args;
×
70

71
      const block = await client.getBlock({ blockHash: receipt.blockHash });
×
72
      const date = new Date(Number(block.timestamp) * 1000);
×
73

74
      return await models.sequelize.transaction(async (transaction) => {
×
75
        const [token] = await models.ThreadToken.findOrCreate({
×
76
          where: { token_address: tokenAddress.toLowerCase() },
77
          defaults: {
78
            token_address: tokenAddress.toLowerCase(),
79
            name,
80
            symbol,
81
            initial_supply: Number(BigInt(totalSupply) / BigInt(1e18)),
82
            liquidity_transferred: false,
83
            launchpad_liquidity: BigInt(launchpadLiquidity).toString(),
84
            eth_market_cap_target: protocols.getTargetMarketCap(),
85
            creator_address: receipt.from,
86
            thread_id: Number(threadId),
87
            created_at: date,
88
            updated_at: date,
89
          },
90
          transaction,
91
        });
92

93
        return token!.toJSON();
×
94
      });
95
    },
96
  };
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc