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

hicommonwealth / commonwealth / 13186178888

06 Feb 2025 07:14PM UTC coverage: 46.438% (-0.06%) from 46.502%
13186178888

push

github

web-flow
Merge pull request #10877 from hicommonwealth/ka.externalLaunchToken

Added logic to gate premium APIs. Gated launchToken

1364 of 3277 branches covered (41.62%)

Branch coverage included in aggregate %.

1 of 13 new or added lines in 2 files covered. (7.69%)

2612 of 5285 relevant lines covered (49.42%)

36.72 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
  command,
6
  type Command,
7
} from '@hicommonwealth/core';
8
import {
9
  commonProtocol as cp,
10
  getErc20TokenInfo,
11
  getLaunchpadTokenCreatedTransaction,
12
  launchpadFactoryAbi,
13
} from '@hicommonwealth/evm-protocols';
14
import { config } from '@hicommonwealth/model';
15
import * as schemas from '@hicommonwealth/schemas';
16
import { TokenView } from '@hicommonwealth/schemas';
17
import { ChainBase, ChainType } from '@hicommonwealth/shared';
18
import _ from 'lodash';
19
import { z } from 'zod';
20
import { CreateCommunity } from '../community';
21
import { models } from '../database';
22
import { mustExist } from '../middleware/guards';
23

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

NEW
32
      if (!cp.isValidChain(eth_chain_id)) {
×
NEW
33
        throw new AppError('eth_chain_id is not supported');
×
34
      }
35

NEW
36
      if (!config.WEB3.CONTEST_BOT_PRIVATE_KEY)
×
NEW
37
        throw new ServerError('Contest bot private key not set!');
×
38

NEW
39
      const communityId = _.kebabCase(name.toLowerCase());
×
NEW
40
      const existingCommunity = await models.Community.findOne({
×
41
        where: { id: communityId },
42
      });
43

NEW
44
      if (existingCommunity) {
×
NEW
45
        throw new AppError('Token already exists, choose another name');
×
46
      }
47

48
      const chainNode = await models.ChainNode.findOne({
×
49
        where: { eth_chain_id },
50
        attributes: ['id', 'eth_chain_id', 'url', 'private_url'],
51
      });
52

53
      mustExist('Chain Node', chainNode);
×
54

55
      const web3 = cp.createPrivateEvmClient({
×
56
        rpc: chainNode.private_url!,
57
        privateKey: config.WEB3.CONTEST_BOT_PRIVATE_KEY,
58
      });
59
      const launchpadContract = new web3.eth.Contract(
×
60
        launchpadFactoryAbi,
61
        cp.factoryContracts[
62
          eth_chain_id as cp.ValidChains.SepoliaBase
63
        ].launchpad,
64
      );
65
      const receipt = await cp.launchToken(
×
66
        launchpadContract,
67
        name,
68
        symbol,
69
        [],
70
        [],
71
        web3.utils.toWei(totalSupply.toString(), 'ether') as string,
72
        web3.eth.defaultAccount as string,
73
        830000,
74
        cp.factoryContracts[eth_chain_id as cp.ValidChains.SepoliaBase]
75
          .tokenCommunityManager,
76
      );
77

78
      const tokenData = await getLaunchpadTokenCreatedTransaction({
×
79
        rpc: chainNode.private_url! || chainNode.url!,
×
80
        transactionHash: receipt.transactionHash,
81
      });
82

83
      if (!tokenData) {
×
84
        throw new InvalidState('Transaction not found');
×
85
      }
86

87
      let tokenInfo: { name: string; symbol: string; totalSupply: bigint };
88
      try {
×
89
        tokenInfo = await getErc20TokenInfo({
×
90
          rpc: chainNode.private_url || chainNode.url,
×
91
          tokenAddress: tokenData.parsedArgs.tokenAddress,
92
        });
93
      } catch (e) {
94
        throw new Error(
×
95
          `Failed to get erc20 token properties for token ${tokenData.parsedArgs.tokenAddress}`,
96
        );
97
      }
98

99
      const [token] = await models.LaunchpadToken.findOrCreate({
×
100
        where: {
101
          token_address: tokenData.parsedArgs.tokenAddress.toLowerCase(),
102
          namespace: tokenData.parsedArgs.namespace,
103
        },
104
        defaults: {
105
          token_address: tokenData.parsedArgs.tokenAddress.toLowerCase(),
106
          namespace: tokenData.parsedArgs.namespace,
107
          name: tokenInfo.name,
108
          symbol: tokenInfo.symbol,
109
          initial_supply: Number(tokenInfo.totalSupply / BigInt(1e18)),
110
          liquidity_transferred: false,
111
          launchpad_liquidity: tokenData.parsedArgs.launchpadLiquidity,
112
          eth_market_cap_target: cp.getTargetMarketCap(),
113
          description: description ?? null,
×
114
          icon_url: icon_url ?? null,
×
115
        },
116
      });
117

118
      // Create corresponding community for token
NEW
119
      await command(CreateCommunity(), {
×
120
        actor,
121
        payload: {
122
          id: communityId,
123
          name,
124
          default_symbol: symbol,
125
          icon_url,
126
          description,
127
          base: ChainBase.Ethereum,
128
          token_name: name,
129
          chain_node_id: chainNode!.id!,
130
          type: ChainType.Offchain,
131
          social_links: [],
132
          directory_page_enabled: false,
133
          tags: [],
134
        },
135
      });
136

NEW
137
      await models.Community.update(
×
138
        { namespace: name },
139
        { where: { id: communityId } },
140
      );
141

NEW
142
      const response = {
×
143
        community_url: `${config.SERVER_URL}/${communityId}`,
144
        ...token!.toJSON(),
145
      };
NEW
146
      return response as unknown as z.infer<typeof TokenView> & {
×
147
        community_url: string;
148
      };
149
    },
150
  };
151
}
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