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

hicommonwealth / commonwealth / 19146872917

06 Nov 2025 07:07PM UTC coverage: 37.507%. Remained the same
19146872917

push

github

web-flow
fix projection (#13184)

Co-authored-by: rotorsoft <rotorsoft@outlook.com>

2039 of 5832 branches covered (34.96%)

Branch coverage included in aggregate %.

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

3542 of 9048 relevant lines covered (39.15%)

44.34 hits per line

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

0.0
/libs/model/src/aggregates/token/ProjectLaunchpadTrade.command.ts
1
import { Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { UserTierMap } from '@hicommonwealth/shared';
4
import { Op } from 'sequelize';
5
import { z } from 'zod';
6
import { models } from '../../database';
7
import { chainNodeMustExist } from '../../policies/utils/utils';
8
import { setUserTier } from '../../utils/tiers';
9
import { handleCapReached } from './utils';
10

11
export function ProjectLaunchpadTrade(): Command<
12
  typeof schemas.ProjectLaunchpadTrade
13
> {
14
  return {
×
15
    ...schemas.ProjectLaunchpadTrade,
16
    auth: [],
17
    body: async ({ payload }) => {
18
      const {
19
        block_timestamp,
20
        transaction_hash,
21
        token_address: token_address_unformatted,
22
        trader_address,
23
        is_buy,
24
        eth_chain_id,
25
        eth_amount,
26
        community_token_amount,
27
        floating_supply,
28
      } = payload;
×
29

30
      const output: z.infer<(typeof schemas.ProjectLaunchpadTrade)['output']> =
31
        {};
×
32

33
      const token_address = token_address_unformatted.toLowerCase();
×
34
      const chainNode = await chainNodeMustExist(eth_chain_id);
×
35

36
      await models.sequelize.transaction(async (transaction) => {
×
37
        await models.LaunchpadTrade.findOrCreate({
×
38
          where: { eth_chain_id, transaction_hash },
39
          defaults: {
40
            eth_chain_id,
41
            transaction_hash,
42
            token_address,
43
            trader_address,
44
            is_buy,
45
            community_token_amount,
46
            price:
47
              Number((eth_amount * BigInt(1e18)) / community_token_amount) /
48
              1e18,
49
            floating_supply,
50
            timestamp: Number(block_timestamp),
51
          },
52
          transaction,
53
        });
54

55
        // auto-join community after trades
56
        const token = await models.LaunchpadToken.findOne({
×
57
          where: { token_address },
58
          attributes: ['namespace'],
59
        });
60
        if (token) {
×
61
          const community = await models.Community.findOne({
×
62
            where: { namespace: token.namespace },
63
            attributes: ['id'],
64
          });
65
          if (community) {
×
66
            output.community_id = community.id;
×
67
            // find user_id from address
NEW
68
            const user_addr = await models.Address.scope(
×
69
              'withPrivateData',
70
            ).findOne({
71
              where: {
72
                address: trader_address,
73
                user_id: { [Op.not]: null },
74
              },
75
              attributes: [
76
                'user_id',
77
                'role',
78
                'ghost_address',
79
                'is_banned',
80
                'verification_token',
81
              ],
82
            });
NEW
83
            if (user_addr) {
×
84
              await models.Address.findOrCreate({
×
85
                where: {
86
                  community_id: community.id,
87
                  address: trader_address,
88
                  user_id: user_addr.user_id,
89
                },
90
                defaults: {
91
                  community_id: community.id,
92
                  address: trader_address,
93
                  user_id: user_addr.user_id,
94
                  role: user_addr.role ?? 'member',
×
95
                  ghost_address: user_addr.ghost_address ?? false,
×
96
                  is_banned: user_addr.is_banned ?? false,
×
97
                  verification_token: user_addr.verification_token,
98
                },
99
                transaction,
100
              });
101
            }
102
          }
103
        }
104
        await setUserTier({
×
105
          userAddress: trader_address,
106
          newTier: UserTierMap.ChainVerified,
107
          transaction,
108
        });
109
      });
110

111
      // If cap reached, transfer to uniswap
112
      // TODO: what happens if something goes wrong here? Should this be a policy with a retry?
113
      await handleCapReached(
×
114
        token_address,
115
        floating_supply,
116
        trader_address,
117
        eth_chain_id,
118
        chainNode.private_url!,
119
        is_buy,
120
      );
121

122
      return output;
×
123
    },
124
  };
125
}
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