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

Mintbase / mintbase-js / 3855010255

pending completion
3855010255

push

github

mintbaseteam
🤖 npm prerelease alpha

319 of 399 branches covered (79.95%)

Branch coverage included in aggregate %.

508 of 556 relevant lines covered (91.37%)

3.16 hits per line

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

62.07
/packages/sdk/src/v1/token.ts
1
// Mintbase token contract JS implementation
2

3
import {
1✔
4
  DEFAULT_MB_LOGO,
5
  TOKEN_METHOD_NAMES,
6
  Network,
7
  MB_TOKEN_FACTORY_ADDRESS,
8
  GAS_CONSTANTS,
9
  DEPOSIT_CONSTANTS,
10
} from '../constants';
11
import { NearContractCall } from '../execute';
12
import {
13
  BurnArgs,
14
  DeployTokenContractArgs,
15
  TransferTokenContractOwnership,
16
  MintArgs,
17
  AddRemoveMinterArgs,
18
  BatchChangeMinters,
19
  RevokeAccountArgs,
20
} from './token.types';
21

22
// TODO: figure out a way to generate gas and deposit for each
23

24
export const burn = (
1✔
25
  args: BurnArgs,
26
): NearContractCall => {
27
  const { nftContractId, tokenIds } = args;
2✔
28

29
  return {
2✔
30
    contractAddress: nftContractId,
31
    methodName: TOKEN_METHOD_NAMES.BATCH_BURN,
32
    args: {
33
      // eslint-disable-next-line @typescript-eslint/camelcase
34
      token_ids: tokenIds,
35
    },
36
    gas: GAS_CONSTANTS.DEFAULT_GAS,
37
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
38
  };
39
};
40

41
export const deployContract = (
1✔
42
  args: DeployTokenContractArgs,
43
): NearContractCall => {
44
  const {
45
    name,
46
    factoryContractId,
47
    network = Network.TESTNET,
1✔
48
    ownerId,
49
    metadata,
50
  } = args;
1✔
51

52
  const { symbol, icon, baseUri, reference, referenceHash } = metadata;
1✔
53

54
  const data = {
1✔
55
    // eslint-disable-next-line @typescript-eslint/camelcase
56
    owner_id: ownerId,
57
    metadata: {
58
      spec: 'nft-1.0.0',
59
      name: name.replace(/[^a-z0-9]+/gim, '').toLowerCase(),
60
      symbol: symbol.replace(/[^a-z0-9]+/gim, '').toLowerCase(),
61
      icon: icon ?? DEFAULT_MB_LOGO,
3!
62
      // eslint-disable-next-line @typescript-eslint/camelcase
63
      base_uri: baseUri ?? null,
3!
64
      reference: reference ?? null,
3!
65
      // eslint-disable-next-line @typescript-eslint/camelcase
66
      reference_hash: referenceHash ?? null,
3!
67
    },
68
  };
69

70
  return {
1✔
71
    contractAddress: factoryContractId || MB_TOKEN_FACTORY_ADDRESS,
1!
72
    methodName: TOKEN_METHOD_NAMES.DEPLOY_TOKEN_CONTRACT,
73
    args: data,
74
    gas: GAS_CONSTANTS.DEFAULT_GAS,
75
    deposit: '6500000000000000000000000',
76
  };
77
};
78

79
export const transferContractOwnership = (
1✔
80
  args: TransferTokenContractOwnership,
81
): NearContractCall => {
82
  const { nftContractId, nextOwner, options } = args;
×
83
  const { keepMinters = true } = options;
×
84

85
  return {
×
86
    contractAddress: nftContractId,
87
    args: {
88
      // eslint-disable-next-line @typescript-eslint/camelcase
89
      new_owner: nextOwner,
90
      // eslint-disable-next-line @typescript-eslint/camelcase
91
      keep_old_minters: keepMinters,
92
    },
93
    methodName: TOKEN_METHOD_NAMES.TRANSFER_TOKEN_CONTRACT_OWNERSHIP,
94
    gas: GAS_CONSTANTS.DEFAULT_GAS,
95
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
96
  };
97
};
98

99
export const mint = (
1✔
100
  args: MintArgs,
101
): NearContractCall => {
102
  const { nftContractId, options } = args;
×
103

104
  return {
×
105
    contractAddress: nftContractId,
106
    args: {},
107
    methodName: TOKEN_METHOD_NAMES.MINT,
108
    gas: GAS_CONSTANTS.DEFAULT_GAS,
109
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
110
  };
111
};
112

113
// TODO: do we want this method? How can we reuse `mint` instead of having an extra method
114
export const mintMore = (): void => {
1✔
115
  return;
×
116
};
117

118
export const addMinter = (
1✔
119
  args: AddRemoveMinterArgs,
120
): NearContractCall => {
121
  const { minterId, nftContractId } = args;
×
122

123
  return {
×
124
    contractAddress: nftContractId,
125
    args: {
126
      // eslint-disable-next-line @typescript-eslint/camelcase
127
      account_id: minterId,
128
    },
129
    methodName: TOKEN_METHOD_NAMES.ADD_MINTER,
130
    gas: GAS_CONSTANTS.DEFAULT_GAS,
131
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
132
  };
133
};
134

135
export const removeMinter = (
1✔
136
  args: AddRemoveMinterArgs,
137
): NearContractCall => {
138
  const { minterId, nftContractId } = args;
×
139

140
  return {
×
141
    contractAddress: nftContractId,
142
    args: {
143
      // eslint-disable-next-line @typescript-eslint/camelcase
144
      account_id: minterId,
145
    },
146
    methodName: TOKEN_METHOD_NAMES.REMOVE_MINTER,
147
    gas: GAS_CONSTANTS.DEFAULT_GAS,
148
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
149
  };
150
};
151

152
export const batchChangeMinters = (
1✔
153
  args: BatchChangeMinters,
154
): NearContractCall => {
155
  const { addMinters, removeMinters, nftContractId } = args;
×
156

157
  return {
×
158
    contractAddress: nftContractId,
159
    args: {
160
      grant: addMinters.length > 0 ? addMinters : undefined,
×
161
      revoke: removeMinters.length > 0 ? removeMinters : undefined,
×
162
    },
163
    methodName: TOKEN_METHOD_NAMES.BATCH_CHANGE_MINTERS,
164
    gas: GAS_CONSTANTS.DEFAULT_GAS,
165
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
166
  };
167
};
168

169
export const revoke = (
1✔
170
  args: RevokeAccountArgs,
171
): NearContractCall => {
172
  const { nftContractId, tokenId, accountToRevokeId } = args;
2✔
173

174
  if (accountToRevokeId) {
2✔
175
    return {
1✔
176
      contractAddress: nftContractId,
177
      args: {
178
        // eslint-disable-next-line @typescript-eslint/camelcase
179
        token_id: tokenId,
180
        // eslint-disable-next-line @typescript-eslint/camelcase
181
        account_id: accountToRevokeId,
182
      },
183
      methodName: TOKEN_METHOD_NAMES.TOKEN_ACCOUNT_REVOKE,
184
      gas: GAS_CONSTANTS.DEFAULT_GAS,
185
      deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
186
    };
187
  } else {
188
    return {
1✔
189
      contractAddress: nftContractId,
190
      args: {
191
        // eslint-disable-next-line @typescript-eslint/camelcase
192
        token_id: tokenId,
193
      },
194
      methodName: TOKEN_METHOD_NAMES.TOKEN_ACCOUNT_REVOKE_ALL,
195
      gas: GAS_CONSTANTS.DEFAULT_GAS,
196
      deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
197
    };
198
  }
199
};
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

© 2025 Coveralls, Inc