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

hicommonwealth / commonwealth / 13182367366

06 Feb 2025 03:37PM UTC coverage: 46.489% (-0.02%) from 46.505%
13182367366

Pull #10877

github

web-flow
Merge 702221205 into b6dc06c62
Pull Request #10877: Added logic to gate premium APIs. Gated launchToken

1366 of 3279 branches covered (41.66%)

Branch coverage included in aggregate %.

1 of 5 new or added lines in 2 files covered. (20.0%)

1 existing line in 1 file now uncovered.

2613 of 5280 relevant lines covered (49.49%)

36.76 hits per line

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

0.0
/libs/model/src/bot/LaunchTokenBot.command.ts
1
import {
2
  AppError,
3
  InvalidState,
4
  ServerError,
5
  type Command,
6
} from '@hicommonwealth/core';
7
import {
8
  commonProtocol as cp,
9
  getErc20TokenInfo,
10
  getLaunchpadTokenCreatedTransaction,
11
  launchpadFactoryAbi,
12
} from '@hicommonwealth/evm-protocols';
13
import { config } from '@hicommonwealth/model';
14
import * as schemas from '@hicommonwealth/schemas';
15
import { TokenView } from '@hicommonwealth/schemas';
16
import { z } from 'zod';
17
import { models } from '../database';
18
import { mustExist } from '../middleware/guards';
19

20
export function LaunchTokenBot(): Command<typeof schemas.LaunchToken> {
21
  return {
×
22
    ...schemas.LaunchToken,
23
    auth: [],
24
    body: async ({ payload }) => {
25
      const { name, symbol, totalSupply, eth_chain_id, icon_url, description } =
26
        payload;
×
27

NEW
28
      if (!cp.isValidChain(eth_chain_id)) {
×
NEW
29
        throw new AppError('eth_chain_id is not supported');
×
30
      }
31

NEW
32
      if (!config.WEB3.CONTEST_BOT_PRIVATE_KEY)
×
NEW
33
        throw new ServerError('Contest bot private key not set!');
×
34

35
      const chainNode = await models.ChainNode.findOne({
×
36
        where: { eth_chain_id },
37
        attributes: ['eth_chain_id', 'url', 'private_url'],
38
      });
39

40
      mustExist('Chain Node', chainNode);
×
41

42
      const web3 = cp.createPrivateEvmClient({
×
43
        rpc: chainNode.private_url!,
44
        privateKey: config.WEB3.CONTEST_BOT_PRIVATE_KEY,
45
      });
46
      const launchpadContract = new web3.eth.Contract(
×
47
        launchpadFactoryAbi,
48
        cp.factoryContracts[
49
          eth_chain_id as cp.ValidChains.SepoliaBase
50
        ].launchpad,
51
      );
52
      const receipt = await cp.launchToken(
×
53
        launchpadContract,
54
        name,
55
        symbol,
56
        [],
57
        [],
58
        web3.utils.toWei(totalSupply.toString(), 'ether') as string,
59
        web3.eth.defaultAccount as string,
60
        830000,
61
        cp.factoryContracts[eth_chain_id as cp.ValidChains.SepoliaBase]
62
          .tokenCommunityManager,
63
      );
64

65
      const tokenData = await getLaunchpadTokenCreatedTransaction({
×
66
        rpc: chainNode.private_url! || chainNode.url!,
×
67
        transactionHash: receipt.transactionHash,
68
      });
69

70
      if (!tokenData) {
×
71
        throw new InvalidState('Transaction not found');
×
72
      }
73

74
      let tokenInfo: { name: string; symbol: string; totalSupply: bigint };
75
      try {
×
76
        tokenInfo = await getErc20TokenInfo({
×
77
          rpc: chainNode.private_url || chainNode.url,
×
78
          tokenAddress: tokenData.parsedArgs.tokenAddress,
79
        });
80
      } catch (e) {
81
        throw new Error(
×
82
          `Failed to get erc20 token properties for token ${tokenData.parsedArgs.tokenAddress}`,
83
        );
84
      }
85

86
      const [token] = await models.LaunchpadToken.findOrCreate({
×
87
        where: {
88
          token_address: tokenData.parsedArgs.tokenAddress.toLowerCase(),
89
          namespace: tokenData.parsedArgs.namespace,
90
        },
91
        defaults: {
92
          token_address: tokenData.parsedArgs.tokenAddress.toLowerCase(),
93
          namespace: tokenData.parsedArgs.namespace,
94
          name: tokenInfo.name,
95
          symbol: tokenInfo.symbol,
96
          initial_supply: Number(tokenInfo.totalSupply / BigInt(1e18)),
97
          liquidity_transferred: false,
98
          launchpad_liquidity: tokenData.parsedArgs.launchpadLiquidity,
99
          eth_market_cap_target: cp.getTargetMarketCap(),
100
          description: description ?? null,
×
101
          icon_url: icon_url ?? null,
×
102
        },
103
      });
104

105
      return token!.toJSON() as unknown as z.infer<typeof TokenView>;
×
106
    },
107
  };
108
}
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