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

hicommonwealth / commonwealth / 19151223489

06 Nov 2025 10:04PM UTC coverage: 37.739% (+0.003%) from 37.736%
19151223489

push

github

web-flow
fix model upserts (#13185)

2063 of 5854 branches covered (35.24%)

Branch coverage included in aggregate %.

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

2 existing lines in 1 file now uncovered.

3571 of 9075 relevant lines covered (39.35%)

45.43 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
        {};
×
UNCOV
32
      const token_address = token_address_unformatted.toLowerCase();
×
33
      const chainNode = await chainNodeMustExist(eth_chain_id);
×
34

NEW
35
      const token = await models.LaunchpadToken.findOne({
×
36
        where: { token_address },
37
        attributes: ['namespace'],
38
      });
NEW
39
      if (!token) return output; // ignore if token not found
×
40

NEW
41
      const community = await models.Community.findOne({
×
42
        where: { namespace: token.namespace },
43
        attributes: ['id'],
44
      });
NEW
45
      const user_addr = await models.Address.scope('withPrivateData').findOne({
×
46
        where: {
47
          address: trader_address,
48
          user_id: { [Op.not]: null },
49
        },
50
        attributes: [
51
          'user_id',
52
          'role',
53
          'ghost_address',
54
          'is_banned',
55
          'verification_token',
56
        ],
57
      });
58

59
      await models.sequelize.transaction(async (transaction) => {
×
60
        await models.LaunchpadTrade.findOrCreate({
×
61
          where: { eth_chain_id, transaction_hash },
62
          defaults: {
63
            eth_chain_id,
64
            transaction_hash,
65
            token_address,
66
            trader_address,
67
            is_buy,
68
            community_token_amount,
69
            price:
70
              Number((eth_amount * BigInt(1e18)) / community_token_amount) /
71
              1e18,
72
            floating_supply,
73
            timestamp: Number(block_timestamp),
74
          },
75
          transaction,
76
        });
77

78
        // auto-join community after trades
NEW
79
        if (community && user_addr) {
×
NEW
80
          output.community_id = community.id;
×
NEW
81
          await models.Address.findOrCreate({
×
82
            where: {
83
              community_id: community.id,
84
              address: trader_address,
85
            },
86
            defaults: {
87
              community_id: community.id,
88
              address: trader_address,
89
              user_id: user_addr.user_id,
90
              role: user_addr.role ?? 'member',
×
91
              ghost_address: user_addr.ghost_address ?? false,
×
92
              is_banned: user_addr.is_banned ?? false,
×
93
              verification_token: user_addr.verification_token,
94
            },
95
            transaction,
96
          });
97
        }
98

UNCOV
99
        await setUserTier({
×
100
          userAddress: trader_address,
101
          newTier: UserTierMap.ChainVerified,
102
          transaction,
103
        });
104
      });
105

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

117
      return output;
×
118
    },
119
  };
120
}
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