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

hicommonwealth / commonwealth / 13337343755

14 Feb 2025 08:56PM UTC coverage: 45.957% (-0.1%) from 46.098%
13337343755

push

github

web-flow
Merge pull request #10987 from hicommonwealth/rotorsoft/10919-xp-chain-projection

Maps chain events to XP projection

1360 of 3312 branches covered (41.06%)

Branch coverage included in aggregate %.

14 of 61 new or added lines in 3 files covered. (22.95%)

1 existing line in 1 file now uncovered.

2647 of 5407 relevant lines covered (48.96%)

36.03 hits per line

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

6.45
/libs/model/src/token/ProjectLaunchpadTrade.command.ts
1
import { Command, logger } from '@hicommonwealth/core';
2
import {
3
  commonProtocol as cp,
4
  getLaunchpadToken,
5
  transferLaunchpadLiquidityToUniswap,
6
} from '@hicommonwealth/evm-protocols';
7
import { events } from '@hicommonwealth/schemas';
8
import { BigNumber } from 'ethers';
9
import { z } from 'zod';
10
import { config } from '../config';
11
import { models } from '../database';
12
import { chainNodeMustExist } from '../policies/utils/utils'; // TODO: place in utils
13

14
const log = logger(import.meta);
28✔
15

16
const schema = {
28✔
17
  input: events.TokenTraded,
18
  output: z.object({}),
19
};
20

21
export function ProjectLaunchpadTrade(): Command<typeof schema> {
NEW
22
  return {
×
23
    ...schema,
24
    auth: [],
25
    body: async ({ payload }) => {
26
      const {
27
        block_timestamp,
28
        transaction_hash,
29
        token_address,
30
        trader_address,
31
        is_buy,
32
        eth_chain_id,
33
        eth_amount,
34
        community_token_amount,
35
        floating_supply,
NEW
36
      } = payload;
×
37

NEW
38
      const token = await models.LaunchpadToken.findOne({
×
39
        where: { token_address },
40
      });
NEW
41
      if (!token) throw new Error('Token not found');
×
42

NEW
43
      const chainNode = await chainNodeMustExist(eth_chain_id);
×
44

NEW
45
      await models.LaunchpadTrade.findOrCreate({
×
46
        where: { eth_chain_id, transaction_hash },
47
        defaults: {
48
          eth_chain_id,
49
          transaction_hash,
50
          token_address,
51
          trader_address,
52
          is_buy,
53
          community_token_amount: BigNumber.from(
54
            community_token_amount,
55
          ).toBigInt(),
56
          price:
57
            Number(
58
              (BigNumber.from(eth_amount).toBigInt() * BigInt(1e18)) /
59
                BigNumber.from(community_token_amount).toBigInt(),
60
            ) / 1e18,
61
          floating_supply: BigNumber.from(floating_supply).toBigInt(),
62
          timestamp: block_timestamp,
63
        },
64
      });
65

NEW
66
      const contracts = cp.factoryContracts[eth_chain_id as cp.ValidChains];
×
67
      let lpBondingCurveAddress: string;
NEW
68
      if (contracts && 'lpBondingCurve' in contracts) {
×
NEW
69
        lpBondingCurveAddress = contracts.lpBondingCurve;
×
70
      } else {
NEW
71
        log.error('No lpBondingCurve address found for chain', undefined, {
×
72
          eth_chain_id,
73
        });
NEW
74
        return;
×
75
      }
76

NEW
77
      if (
×
78
        !token.liquidity_transferred &&
×
79
        BigNumber.from(floating_supply).toBigInt() ===
80
          BigInt(token.launchpad_liquidity)
81
      ) {
NEW
82
        const onChainTokenData = await getLaunchpadToken({
×
83
          rpc: chainNode.private_url!,
84
          tokenAddress: token_address,
85
          lpBondingCurveAddress,
86
        });
87

NEW
88
        if (!onChainTokenData.funded) {
×
NEW
89
          await transferLaunchpadLiquidityToUniswap({
×
90
            rpc: chainNode.private_url!,
91
            tokenAddress: token_address,
92
            lpBondingCurveAddress,
93
            privateKey: config.WEB3.PRIVATE_KEY,
94
          });
95
        }
96

NEW
97
        token.liquidity_transferred = true;
×
NEW
98
        await token.save();
×
99
      }
100
    },
101
  };
102
}
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