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

Mintbase / mintbase-js / 4006682080

pending completion
4006682080

push

github

Sérgio
πŸ“ Storage tests and fixes

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