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

Mintbase / mintbase-js / 4053782737

pending completion
4053782737

push

github

Ruben Marcus
fix test

521 of 749 branches covered (69.56%)

Branch coverage included in aggregate %.

764 of 837 relevant lines covered (91.28%)

4.61 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 {  BatchChangeMinterArgsResponse, BurnArgsResponse, DeployContractArgsResponse, NearContractCall, NEAR_NETWORKS, OldTransferContractOwnershipArgs, TOKEN_METHOD_NAMES } from '../types';
1✔
5
import {
1✔
6
  DEFAULT_MB_LOGO,
7
  GAS_CONSTANTS,
8
  DEPOSIT_CONSTANTS,
9
} from '../constants';
10
import {
11
  BurnArgs,
12
  DeployTokenContractArgs,
13
  TransferTokenContractOwnership,
14
  MintArgs,
15
  AddRemoveMinterArgs,
16
  BatchChangeMinters,
17
  RevokeAccountArgs,
18
} from './token.types';
19

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

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

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

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

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

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

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

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

83
  return {
×
84
    contractAddress: nftContractId || mbjs.keys.contractAddress,
×
85
    args: {
86
      new_owner: nextOwner,
87
      keep_old_minters: keepMinters,
88
    },
89
    methodName: TOKEN_METHOD_NAMES.TRANSFER_TOKEN_CONTRACT_OWNERSHIP,
90
    gas: GAS_CONSTANTS.DEFAULT_GAS,
91
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
92
  };
93
};
94

95
export const mint = (
1✔
96
  args: MintArgs,
97
): NearContractCall<{}> => {
98
  const { nftContractId, options } = args;
×
99

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

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

114
export const addMinter = (
1✔
115
  args: AddRemoveMinterArgs,
116
): NearContractCall<{account_id: string}> => {
117
  const { minterId, nftContractId } = args;
×
118

119
  return {
×
120
    contractAddress: nftContractId || mbjs.keys.contractAddress,
×
121
    args: {
122
      account_id: minterId,
123
    },
124
    methodName: TOKEN_METHOD_NAMES.ADD_MINTER,
125
    gas: GAS_CONSTANTS.DEFAULT_GAS,
126
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
127
  };
128
};
129

130
export const removeMinter = (
1✔
131
  args: AddRemoveMinterArgs,
132
): NearContractCall<{account_id: string}> => {
133
  const { minterId, nftContractId } = args;
×
134

135
  return {
×
136
    contractAddress: nftContractId || mbjs.keys.contractAddress,
×
137
    args: {
138
      account_id: minterId,
139
    },
140
    methodName: TOKEN_METHOD_NAMES.REMOVE_MINTER,
141
    gas: GAS_CONSTANTS.DEFAULT_GAS,
142
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
143
  };
144
};
145

146
export const batchChangeMinters = (
1✔
147
  args: BatchChangeMinters,
148
): NearContractCall<BatchChangeMinterArgsResponse> => {
149
  const { addMinters, removeMinters, nftContractId } = args;
×
150

151
  return {
×
152
    contractAddress: nftContractId || mbjs.keys.contractAddress,
×
153
    args: {
154
      grant: addMinters.length > 0 ? addMinters : undefined,
×
155
      revoke: removeMinters.length > 0 ? removeMinters : undefined,
×
156
    },
157
    methodName: TOKEN_METHOD_NAMES.BATCH_CHANGE_MINTERS,
158
    gas: GAS_CONSTANTS.DEFAULT_GAS,
159
    deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
160
  };
161
};
162

163
export const revoke = (
1✔
164
  args: RevokeAccountArgs,
165
): NearContractCall<{token_id: string; account_id?: string}> => {
166
  const { nftContractId, tokenId, accountToRevokeId } = args;
2✔
167

168
  if (accountToRevokeId) {
2✔
169
    return {
1✔
170
      contractAddress: nftContractId || mbjs.keys.contractAddress,
1!
171
      args: {
172
        token_id: tokenId,
173
        account_id: accountToRevokeId,
174
      },
175
      methodName: TOKEN_METHOD_NAMES.TOKEN_ACCOUNT_REVOKE,
176
      gas: GAS_CONSTANTS.DEFAULT_GAS,
177
      deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
178
    };
179
  } else {
180
    return {
1✔
181
      contractAddress: nftContractId,
182
      args: {
183
        token_id: tokenId,
184
      },
185
      methodName: TOKEN_METHOD_NAMES.TOKEN_ACCOUNT_REVOKE_ALL,
186
      gas: GAS_CONSTANTS.DEFAULT_GAS,
187
      deposit: DEPOSIT_CONSTANTS.ONE_YOCTO,
188
    };
189
  }
190
};
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