@trustvc/trustvc 1.6.0-alpha.1 → 1.6.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/cjs/core/endorsement-chain/useEndorsementChain.js +5 -6
  2. package/dist/cjs/token-registry-functions/index.js +28 -0
  3. package/dist/cjs/token-registry-functions/mint.js +90 -0
  4. package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
  5. package/dist/cjs/token-registry-functions/rejectTransfers.js +166 -0
  6. package/dist/cjs/token-registry-functions/returnToken.js +210 -0
  7. package/dist/cjs/token-registry-functions/transfer.js +96 -128
  8. package/dist/cjs/token-registry-functions/types.js +2 -0
  9. package/dist/cjs/token-registry-functions/utils.js +37 -0
  10. package/dist/esm/core/endorsement-chain/useEndorsementChain.js +5 -7
  11. package/dist/esm/token-registry-functions/index.js +4 -0
  12. package/dist/esm/token-registry-functions/mint.js +88 -0
  13. package/dist/esm/token-registry-functions/ownerOf.js +43 -0
  14. package/dist/esm/token-registry-functions/rejectTransfers.js +162 -0
  15. package/dist/esm/token-registry-functions/returnToken.js +206 -0
  16. package/dist/esm/token-registry-functions/transfer.js +96 -128
  17. package/dist/esm/token-registry-functions/types.js +1 -0
  18. package/dist/esm/token-registry-functions/utils.js +33 -0
  19. package/dist/types/core/endorsement-chain/index.d.ts +1 -1
  20. package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +2 -1
  21. package/dist/types/core/index.d.ts +1 -1
  22. package/dist/types/index.d.ts +6 -1
  23. package/dist/types/token-registry-functions/index.d.ts +6 -1
  24. package/dist/types/token-registry-functions/mint.d.ts +20 -0
  25. package/dist/types/token-registry-functions/ownerOf.d.ts +19 -0
  26. package/dist/types/token-registry-functions/rejectTransfers.d.ts +43 -0
  27. package/dist/types/token-registry-functions/returnToken.d.ts +44 -0
  28. package/dist/types/token-registry-functions/transfer.d.ts +79 -40
  29. package/dist/types/token-registry-functions/types.d.ts +80 -0
  30. package/dist/types/token-registry-functions/utils.d.ts +16 -0
  31. package/package.json +14 -2
@@ -1,29 +1,23 @@
1
1
  'use strict';
2
2
 
3
- var tradetrustUtils = require('@tradetrust-tt/tradetrust-utils');
4
- var core = require('src/core');
5
- var tokenRegistryV4 = require('src/token-registry-v4');
6
- var tokenRegistryV5 = require('src/token-registry-v5');
7
- var ethers = require('src/utils/ethers');
3
+ var core = require('../core');
4
+ var tokenRegistryV4 = require('../token-registry-v4');
5
+ var tokenRegistryV5 = require('../token-registry-v5');
6
+ var utils = require('./utils');
7
+ var ethers = require('../utils/ethers');
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
12
- if (ethers.isV6EthersProvider(signer.provider)) {
13
- const network = await signer.provider?.getNetwork();
14
- if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
15
- return network.chainId;
16
- }
17
- return await signer.getChainId();
18
- }, "getChainIdSafe");
19
11
  const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
20
12
  const { tokenRegistryAddress, tokenId } = contractOptions;
21
13
  const { titleEscrowVersion } = options;
22
14
  let { titleEscrowAddress } = contractOptions;
23
- let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
15
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
24
16
  let isV5TT = titleEscrowVersion === "v5";
25
17
  let isV4TT = titleEscrowVersion === "v4";
26
18
  if (!titleEscrowAddress) {
19
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
20
+ if (!tokenId) throw new Error("Token ID is required");
27
21
  titleEscrowAddress = await core.getTitleEscrowAddress(
28
22
  tokenRegistryAddress,
29
23
  tokenId,
@@ -34,7 +28,6 @@ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, pa
34
28
  if (!titleEscrowAddress) throw new Error("Token registry address is required");
35
29
  if (!signer.provider) throw new Error("Provider is required");
36
30
  const { holderAddress, remarks } = params;
37
- let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
38
31
  const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
39
32
  if (titleEscrowVersion === void 0) {
40
33
  [isV4TT, isV5TT] = await Promise.all([
@@ -53,43 +46,38 @@ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, pa
53
46
  if (!isV4TT && !isV5TT) {
54
47
  throw new Error("Only Token Registry V4/V5 is supported");
55
48
  }
56
- if (isV4TT) {
57
- titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
49
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
50
+ let titleEscrowContract;
51
+ if (isV5TT) {
52
+ titleEscrowContract = new Contract(
53
+ titleEscrowAddress,
54
+ tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ signer
57
+ );
58
+ } else if (isV4TT) {
59
+ titleEscrowContract = new Contract(
58
60
  titleEscrowAddress,
61
+ tokenRegistryV4.v4Contracts.TitleEscrow__factory.abi,
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
63
  signer
60
64
  );
61
65
  }
62
66
  try {
63
- if (isV5TT) {
64
- await titleEscrowContract.callStatic.transferHolder(
65
- holderAddress,
66
- encryptedRemarks
67
- );
68
- } else if (isV4TT) {
69
- await titleEscrowContract.callStatic.transferHolder(
70
- holderAddress
71
- );
67
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
68
+ const args = isV5TT ? [holderAddress, encryptedRemarks] : [holderAddress];
69
+ if (isV6) {
70
+ await titleEscrowContract.transferHolder.staticCall(...args);
71
+ } else {
72
+ await titleEscrowContract.callStatic.transferHolder(...args);
72
73
  }
73
74
  } catch (e) {
74
75
  console.error("callStatic failed:", e);
75
76
  throw new Error("Pre-check (callStatic) for transferHolder failed");
76
77
  }
77
- if (!maxFeePerGas || !maxPriorityFeePerGas) {
78
- chainId = chainId ?? await getChainIdSafe(signer);
79
- const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
80
- if (gasStation) {
81
- const gasFees = await gasStation();
82
- maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
83
- maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
84
- }
85
- }
86
- const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
78
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
87
79
  if (isV5TT) {
88
- return await titleEscrowContract.transferHolder(
89
- holderAddress,
90
- encryptedRemarks,
91
- txOptions
92
- );
80
+ return await titleEscrowContract.transferHolder(holderAddress, encryptedRemarks, txOptions);
93
81
  } else if (isV4TT) {
94
82
  return await titleEscrowContract.transferHolder(holderAddress, txOptions);
95
83
  }
@@ -98,7 +86,7 @@ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signe
98
86
  const { tokenId, tokenRegistryAddress } = contractOptions;
99
87
  const { titleEscrowVersion } = options;
100
88
  let { titleEscrowAddress } = contractOptions;
101
- let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
89
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
102
90
  let isV5TT = titleEscrowVersion === "v5";
103
91
  let isV4TT = titleEscrowVersion === "v4";
104
92
  if (!titleEscrowAddress) {
@@ -112,7 +100,6 @@ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signe
112
100
  if (!titleEscrowAddress) throw new Error("Token registry address is required");
113
101
  if (!signer.provider) throw new Error("Provider is required");
114
102
  const { newBeneficiaryAddress, remarks } = params;
115
- let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
116
103
  const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
117
104
  if (titleEscrowVersion === void 0) {
118
105
  [isV4TT, isV5TT] = await Promise.all([
@@ -131,57 +118,51 @@ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signe
131
118
  if (!isV4TT && !isV5TT) {
132
119
  throw new Error("Only Token Registry V4/V5 is supported");
133
120
  }
134
- if (!isV5TT) {
135
- titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
121
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
122
+ let titleEscrowContract;
123
+ if (isV5TT) {
124
+ titleEscrowContract = new Contract(
125
+ titleEscrowAddress,
126
+ tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
+ signer
129
+ );
130
+ } else if (isV4TT) {
131
+ titleEscrowContract = new Contract(
136
132
  titleEscrowAddress,
133
+ tokenRegistryV4.v4Contracts.TitleEscrow__factory.abi,
134
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
135
  signer
138
136
  );
139
137
  }
140
138
  try {
141
- if (isV5TT) {
142
- await titleEscrowContract.callStatic.transferBeneficiary(
143
- newBeneficiaryAddress,
144
- encryptedRemarks
145
- );
146
- } else if (isV4TT) {
147
- await titleEscrowContract.callStatic.transferBeneficiary(
148
- newBeneficiaryAddress
149
- );
139
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
140
+ const args = isV5TT ? [newBeneficiaryAddress, encryptedRemarks] : [newBeneficiaryAddress];
141
+ if (isV6) {
142
+ await titleEscrowContract.transferBeneficiary.staticCall(...args);
143
+ } else {
144
+ await titleEscrowContract.callStatic.transferBeneficiary(...args);
150
145
  }
151
146
  } catch (e) {
152
147
  console.error("callStatic failed:", e);
153
148
  throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
154
149
  }
155
- if (!maxFeePerGas || !maxPriorityFeePerGas) {
156
- chainId = chainId ?? await getChainIdSafe(signer);
157
- const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
158
- if (gasStation) {
159
- const gasFees = await gasStation();
160
- maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
161
- maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
162
- }
163
- }
164
- const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
150
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
165
151
  if (isV5TT) {
166
- const tx = await titleEscrowContract.transferBeneficiary(
152
+ return await titleEscrowContract.transferBeneficiary(
167
153
  newBeneficiaryAddress,
168
154
  encryptedRemarks,
169
155
  txOptions
170
156
  );
171
- return tx;
172
157
  } else if (isV4TT) {
173
- const tx = await titleEscrowContract.transferBeneficiary(
174
- newBeneficiaryAddress,
175
- txOptions
176
- );
177
- return tx;
158
+ return await titleEscrowContract.transferBeneficiary(newBeneficiaryAddress, txOptions);
178
159
  }
179
160
  }, "transferBeneficiary");
180
161
  const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
181
162
  const { tokenId, tokenRegistryAddress } = contractOptions;
182
163
  const { titleEscrowVersion } = options;
183
164
  let { titleEscrowAddress } = contractOptions;
184
- let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
165
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
185
166
  let isV5TT = titleEscrowVersion === "v5";
186
167
  let isV4TT = titleEscrowVersion === "v4";
187
168
  if (!titleEscrowAddress) {
@@ -195,7 +176,6 @@ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, pa
195
176
  if (!titleEscrowAddress) throw new Error("Token registry address is required");
196
177
  if (!signer.provider) throw new Error("Provider is required");
197
178
  const { newBeneficiaryAddress, newHolderAddress, remarks } = params;
198
- let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
199
179
  const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
200
180
  if (titleEscrowVersion === void 0) {
201
181
  [isV4TT, isV5TT] = await Promise.all([
@@ -214,39 +194,36 @@ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, pa
214
194
  if (!isV4TT && !isV5TT) {
215
195
  throw new Error("Only Token Registry V4/V5 is supported");
216
196
  }
217
- if (!isV5TT) {
218
- titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
197
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
198
+ let titleEscrowContract;
199
+ if (isV5TT) {
200
+ titleEscrowContract = new Contract(
201
+ titleEscrowAddress,
202
+ tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
203
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
204
+ signer
205
+ );
206
+ } else if (isV4TT) {
207
+ titleEscrowContract = new Contract(
219
208
  titleEscrowAddress,
209
+ tokenRegistryV4.v4Contracts.TitleEscrow__factory.abi,
210
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
220
211
  signer
221
212
  );
222
213
  }
223
214
  try {
224
- if (isV5TT) {
225
- await titleEscrowContract.callStatic.transferOwners(
226
- newBeneficiaryAddress,
227
- newHolderAddress,
228
- encryptedRemarks
229
- );
230
- } else if (isV4TT) {
231
- await titleEscrowContract.callStatic.transferOwners(
232
- newBeneficiaryAddress,
233
- newHolderAddress
234
- );
215
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
216
+ const args = isV5TT ? [newBeneficiaryAddress, newHolderAddress, encryptedRemarks] : [newBeneficiaryAddress, newHolderAddress];
217
+ if (isV6) {
218
+ await titleEscrowContract.transferOwners.staticCall(...args);
219
+ } else {
220
+ await titleEscrowContract.callStatic.transferOwners(...args);
235
221
  }
236
222
  } catch (e) {
237
223
  console.error("callStatic failed:", e);
238
224
  throw new Error("Pre-check (callStatic) for transferOwners failed");
239
225
  }
240
- if (!maxFeePerGas || !maxPriorityFeePerGas) {
241
- chainId = chainId ?? await getChainIdSafe(signer);
242
- const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
243
- if (gasStation) {
244
- const gasFees = await gasStation();
245
- maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
246
- maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
247
- }
248
- }
249
- const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
226
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
250
227
  if (isV5TT) {
251
228
  return await titleEscrowContract.transferOwners(
252
229
  newBeneficiaryAddress,
@@ -266,7 +243,7 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
266
243
  const { tokenId, tokenRegistryAddress } = contractOptions;
267
244
  const { titleEscrowVersion } = options;
268
245
  let { titleEscrowAddress } = contractOptions;
269
- let { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
246
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
270
247
  let isV5TT = titleEscrowVersion === "v5";
271
248
  let isV4TT = titleEscrowVersion === "v4";
272
249
  if (!titleEscrowAddress) {
@@ -280,7 +257,6 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
280
257
  if (!titleEscrowAddress) throw new Error("Token registry address is required");
281
258
  if (!signer.provider) throw new Error("Provider is required");
282
259
  const { newBeneficiaryAddress, remarks } = params;
283
- let titleEscrowContract = tokenRegistryV5.v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
284
260
  const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
285
261
  if (titleEscrowVersion === void 0) {
286
262
  [isV4TT, isV5TT] = await Promise.all([
@@ -296,48 +272,40 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
296
272
  })
297
273
  ]);
298
274
  }
299
- if (!isV5TT) {
300
- titleEscrowContract = tokenRegistryV4.v4Contracts.TitleEscrow__factory.connect(
275
+ const Contract = ethers.getEthersContractFromProvider(signer.provider);
276
+ let titleEscrowContract;
277
+ if (isV5TT) {
278
+ titleEscrowContract = new Contract(
301
279
  titleEscrowAddress,
280
+ tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
281
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
282
+ signer
283
+ );
284
+ } else if (isV4TT) {
285
+ titleEscrowContract = new Contract(
286
+ titleEscrowAddress,
287
+ tokenRegistryV4.v4Contracts.TitleEscrow__factory.abi,
288
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
302
289
  signer
303
290
  );
304
291
  }
305
292
  try {
306
- if (isV5TT) {
307
- await titleEscrowContract.callStatic.nominate(
308
- newBeneficiaryAddress,
309
- encryptedRemarks
310
- );
311
- } else if (isV4TT) {
312
- await titleEscrowContract.callStatic.nominate(
313
- newBeneficiaryAddress
314
- );
293
+ const isV6 = ethers.isV6EthersProvider(signer.provider);
294
+ const args = isV5TT ? [newBeneficiaryAddress, encryptedRemarks] : [newBeneficiaryAddress];
295
+ if (isV6) {
296
+ await titleEscrowContract.nominate.staticCall(...args);
297
+ } else {
298
+ await titleEscrowContract.callStatic.nominate(...args);
315
299
  }
316
300
  } catch (e) {
317
301
  console.error("callStatic failed:", e);
318
302
  throw new Error("Pre-check (callStatic) for nominate failed");
319
303
  }
320
- if (!maxFeePerGas || !maxPriorityFeePerGas) {
321
- chainId = chainId ?? await getChainIdSafe(signer);
322
- const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
323
- if (gasStation) {
324
- const gasFees = await gasStation();
325
- maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
326
- maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
327
- }
328
- }
329
- const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
304
+ const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
330
305
  if (isV5TT) {
331
- return await titleEscrowContract.nominate(
332
- newBeneficiaryAddress,
333
- encryptedRemarks,
334
- txOptions
335
- );
306
+ return await titleEscrowContract.nominate(newBeneficiaryAddress, encryptedRemarks, txOptions);
336
307
  } else if (isV4TT) {
337
- return await titleEscrowContract.nominate(
338
- newBeneficiaryAddress,
339
- txOptions
340
- );
308
+ return await titleEscrowContract.nominate(newBeneficiaryAddress, txOptions);
341
309
  }
342
310
  }, "nominate");
343
311
 
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var ethers = require('../utils/ethers');
4
+ var tradetrustUtils = require('@tradetrust-tt/tradetrust-utils');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const getTxOptions = /* @__PURE__ */ __name(async (signer, chainId, maxFeePerGas, maxPriorityFeePerGas) => {
9
+ if (!maxFeePerGas || !maxPriorityFeePerGas) {
10
+ chainId = chainId ?? await getChainIdSafe(signer);
11
+ const gasStation = tradetrustUtils.SUPPORTED_CHAINS[chainId]?.gasStation;
12
+ if (gasStation) {
13
+ const gasFees = await gasStation();
14
+ maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
15
+ maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
16
+ }
17
+ }
18
+ return maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : {};
19
+ }, "getTxOptions");
20
+ const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
21
+ if (ethers.isV6EthersProvider(signer.provider)) {
22
+ const network = await signer.provider?.getNetwork();
23
+ if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
24
+ return network.chainId;
25
+ }
26
+ return await signer.getChainId();
27
+ }, "getChainIdSafe");
28
+ const getSignerAddressSafe = /* @__PURE__ */ __name(async (signer) => {
29
+ if (ethers.isV6EthersProvider(signer.provider)) {
30
+ return await signer.getAddress();
31
+ }
32
+ return await signer.getAddress();
33
+ }, "getSignerAddressSafe");
34
+
35
+ exports.getChainIdSafe = getChainIdSafe;
36
+ exports.getSignerAddressSafe = getSignerAddressSafe;
37
+ exports.getTxOptions = getTxOptions;
@@ -90,14 +90,12 @@ const getDocumentOwner = /* @__PURE__ */ __name(async (tokenRegistryAddress, tok
90
90
  const tokenRegistry = new Contract(tokenRegistryAddress, tokenRegistryAbi, provider);
91
91
  return await tokenRegistry.ownerOf(tokenId);
92
92
  }, "getDocumentOwner");
93
- const checkSupportsInterface = /* @__PURE__ */ __name(async (titleEscrowAddress, interfaceId, provider) => {
93
+ const checkSupportsInterface = /* @__PURE__ */ __name(async (contractAddress, interfaceId, provider) => {
94
94
  try {
95
95
  const Contract = getEthersContractFromProvider(provider);
96
- const titleEscrowAbi = [
97
- "function supportsInterface(bytes4 interfaceId) external view returns (bool)"
98
- ];
99
- const titleEscrowContract = new Contract(titleEscrowAddress, titleEscrowAbi, provider);
100
- return await titleEscrowContract.supportsInterface(interfaceId);
96
+ const abi = ["function supportsInterface(bytes4 interfaceId) external view returns (bool)"];
97
+ const contract = new Contract(contractAddress, abi, provider);
98
+ return await contract.supportsInterface(interfaceId);
101
99
  } catch {
102
100
  return false;
103
101
  }
@@ -162,4 +160,4 @@ const fetchEndorsementChain = /* @__PURE__ */ __name(async (tokenRegistryAddress
162
160
  }));
163
161
  }, "fetchEndorsementChain");
164
162
 
165
- export { TitleEscrowInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion };
163
+ export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion };
@@ -1 +1,5 @@
1
1
  export * from './transfer';
2
+ export * from './rejectTransfers';
3
+ export * from './returnToken';
4
+ export * from './mint';
5
+ export * from './ownerOf';
@@ -0,0 +1,88 @@
1
+ import { checkSupportsInterface, encrypt } from '../core';
2
+ import { v5SupportInterfaceIds, v5Contracts } from '../token-registry-v5';
3
+ import { v4SupportInterfaceIds, v4Contracts } from '../token-registry-v4';
4
+ import { getTxOptions } from './utils';
5
+ import { getEthersContractFromProvider, isV6EthersProvider } from '../utils/ethers';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ const mint = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
10
+ const { tokenRegistryAddress } = contractOptions;
11
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
12
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
13
+ if (!signer.provider) throw new Error("Provider is required");
14
+ const { beneficiaryAddress, holderAddress, tokenId, remarks } = params;
15
+ let isV5TT = titleEscrowVersion === "v5";
16
+ let isV4TT = titleEscrowVersion === "v4";
17
+ if (titleEscrowVersion === void 0) {
18
+ [isV4TT, isV5TT] = await Promise.all([
19
+ checkSupportsInterface(
20
+ tokenRegistryAddress,
21
+ v4SupportInterfaceIds.TradeTrustTokenMintable,
22
+ signer.provider
23
+ ),
24
+ checkSupportsInterface(
25
+ tokenRegistryAddress,
26
+ v5SupportInterfaceIds.TradeTrustTokenMintable,
27
+ signer.provider
28
+ )
29
+ ]);
30
+ }
31
+ if (!isV4TT && !isV5TT) {
32
+ throw new Error("Only Token Registry V4/V5 is supported");
33
+ }
34
+ const Contract = getEthersContractFromProvider(signer.provider);
35
+ let tradeTrustTokenContract;
36
+ if (isV5TT) {
37
+ tradeTrustTokenContract = new Contract(
38
+ tokenRegistryAddress,
39
+ v5Contracts.TradeTrustToken__factory.abi,
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ signer
42
+ );
43
+ } else if (isV4TT) {
44
+ tradeTrustTokenContract = new Contract(
45
+ tokenRegistryAddress,
46
+ v4Contracts.TradeTrustToken__factory.abi,
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ signer
49
+ );
50
+ }
51
+ const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id ?? "")}` : "0x";
52
+ try {
53
+ const isV6 = isV6EthersProvider(signer.provider);
54
+ const args = isV5TT ? [beneficiaryAddress, holderAddress, tokenId, encryptedRemarks] : [beneficiaryAddress, holderAddress, tokenId];
55
+ if (isV6) {
56
+ await tradeTrustTokenContract.mint.staticCall(...args);
57
+ } else {
58
+ await tradeTrustTokenContract.callStatic.mint(...args);
59
+ }
60
+ } catch (e) {
61
+ console.error("callStatic failed:", e);
62
+ throw new Error("Pre-check (callStatic) for mint failed");
63
+ }
64
+ const txOptions = await getTxOptions(
65
+ signer,
66
+ chainId,
67
+ maxFeePerGas,
68
+ maxPriorityFeePerGas
69
+ );
70
+ if (isV5TT) {
71
+ return await tradeTrustTokenContract.mint(
72
+ beneficiaryAddress,
73
+ holderAddress,
74
+ tokenId,
75
+ encryptedRemarks,
76
+ txOptions
77
+ );
78
+ } else if (isV4TT) {
79
+ return await tradeTrustTokenContract.mint(
80
+ beneficiaryAddress,
81
+ holderAddress,
82
+ tokenId,
83
+ txOptions
84
+ );
85
+ }
86
+ }, "mint");
87
+
88
+ export { mint };
@@ -0,0 +1,43 @@
1
+ import { checkSupportsInterface } from '../core';
2
+ import { v5SupportInterfaceIds, v5Contracts } from '../token-registry-v5';
3
+ import { v4SupportInterfaceIds, v4Contracts } from '../token-registry-v4';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const ownerOf = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
8
+ const { tokenRegistryAddress } = contractOptions;
9
+ const { titleEscrowVersion } = options;
10
+ const { tokenId } = params;
11
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
12
+ if (!signer.provider) throw new Error("Provider is required");
13
+ let isV5TT = titleEscrowVersion === "v5";
14
+ let isV4TT = titleEscrowVersion === "v4";
15
+ if (titleEscrowVersion === void 0) {
16
+ [isV4TT, isV5TT] = await Promise.all([
17
+ checkSupportsInterface(tokenRegistryAddress, v4SupportInterfaceIds.SBT, signer.provider),
18
+ checkSupportsInterface(tokenRegistryAddress, v5SupportInterfaceIds.SBT, signer.provider)
19
+ ]);
20
+ }
21
+ if (!isV4TT && !isV5TT) {
22
+ throw new Error("Only Token Registry V4/V5 is supported");
23
+ }
24
+ let tradeTrustTokenContract;
25
+ if (isV5TT) {
26
+ tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
27
+ tokenRegistryAddress,
28
+ signer
29
+ );
30
+ } else if (isV4TT) {
31
+ tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
32
+ tokenRegistryAddress,
33
+ signer
34
+ );
35
+ }
36
+ if (isV5TT) {
37
+ return await tradeTrustTokenContract.ownerOf(tokenId);
38
+ } else if (isV4TT) {
39
+ return await tradeTrustTokenContract.ownerOf(tokenId);
40
+ }
41
+ }, "ownerOf");
42
+
43
+ export { ownerOf };