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

Mintbase / mintbase-js / 4025061313

pending completion
4025061313

push

github

ruisantiago
Update batchMinters readme

483 of 648 branches covered (74.54%)

Branch coverage included in aggregate %.

721 of 780 relevant lines covered (92.44%)

4.23 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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