@trustvc/trustvc 1.7.3 → 1.8.0

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 (33) hide show
  1. package/dist/cjs/core/endorsement-chain/useEndorsementChain.js +5 -6
  2. package/dist/cjs/index.js +7 -0
  3. package/dist/cjs/token-registry-functions/index.js +40 -0
  4. package/dist/cjs/token-registry-functions/mint.js +90 -0
  5. package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
  6. package/dist/cjs/token-registry-functions/rejectTransfers.js +166 -0
  7. package/dist/cjs/token-registry-functions/returnToken.js +210 -0
  8. package/dist/cjs/token-registry-functions/transfer.js +315 -0
  9. package/dist/cjs/token-registry-functions/types.js +2 -0
  10. package/dist/cjs/token-registry-functions/utils.js +37 -0
  11. package/dist/esm/core/endorsement-chain/useEndorsementChain.js +5 -7
  12. package/dist/esm/index.js +1 -0
  13. package/dist/esm/token-registry-functions/index.js +5 -0
  14. package/dist/esm/token-registry-functions/mint.js +88 -0
  15. package/dist/esm/token-registry-functions/ownerOf.js +43 -0
  16. package/dist/esm/token-registry-functions/rejectTransfers.js +162 -0
  17. package/dist/esm/token-registry-functions/returnToken.js +206 -0
  18. package/dist/esm/token-registry-functions/transfer.js +310 -0
  19. package/dist/esm/token-registry-functions/types.js +1 -0
  20. package/dist/esm/token-registry-functions/utils.js +33 -0
  21. package/dist/types/core/endorsement-chain/index.d.ts +1 -1
  22. package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +2 -1
  23. package/dist/types/core/index.d.ts +1 -1
  24. package/dist/types/index.d.ts +7 -1
  25. package/dist/types/token-registry-functions/index.d.ts +9 -0
  26. package/dist/types/token-registry-functions/mint.d.ts +20 -0
  27. package/dist/types/token-registry-functions/ownerOf.d.ts +19 -0
  28. package/dist/types/token-registry-functions/rejectTransfers.d.ts +43 -0
  29. package/dist/types/token-registry-functions/returnToken.d.ts +44 -0
  30. package/dist/types/token-registry-functions/transfer.d.ts +82 -0
  31. package/dist/types/token-registry-functions/types.d.ts +80 -0
  32. package/dist/types/token-registry-functions/utils.d.ts +16 -0
  33. package/package.json +15 -3
@@ -0,0 +1,162 @@
1
+ import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface } from './../core';
2
+ import { v5Contracts } from './../token-registry-v5';
3
+ import { getTxOptions } from './utils';
4
+ import { getEthersContractFromProvider, isV6EthersProvider } from '../utils/ethers';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const rejectTransferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
9
+ const { tokenRegistryAddress, tokenId } = contractOptions;
10
+ let { titleEscrowAddress } = contractOptions;
11
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
12
+ if (!titleEscrowAddress) {
13
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
14
+ if (!tokenId) throw new Error("Token ID is required");
15
+ titleEscrowAddress = await getTitleEscrowAddress(
16
+ tokenRegistryAddress,
17
+ tokenId,
18
+ signer.provider,
19
+ {}
20
+ );
21
+ }
22
+ if (!titleEscrowAddress) throw new Error("Title escrow address is required");
23
+ if (!signer.provider) throw new Error("Provider is required");
24
+ const { remarks } = params;
25
+ const Contract = getEthersContractFromProvider(signer.provider);
26
+ const titleEscrowContract = new Contract(
27
+ titleEscrowAddress,
28
+ v5Contracts.TitleEscrow__factory.abi,
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ signer
31
+ );
32
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
33
+ let isV5TT = titleEscrowVersion === "v5";
34
+ if (titleEscrowVersion === void 0) {
35
+ isV5TT = await isTitleEscrowVersion({
36
+ titleEscrowAddress,
37
+ versionInterface: TitleEscrowInterface.V5,
38
+ provider: signer.provider
39
+ });
40
+ }
41
+ if (!isV5TT) {
42
+ throw new Error("Only Token Registry V5 is supported");
43
+ }
44
+ try {
45
+ const isV6 = isV6EthersProvider(signer.provider);
46
+ const args = isV5TT ? [encryptedRemarks] : [];
47
+ if (isV6) {
48
+ await titleEscrowContract.rejectTransferHolder.staticCall(...args);
49
+ } else {
50
+ await titleEscrowContract.callStatic.rejectTransferHolder(...args);
51
+ }
52
+ } catch (e) {
53
+ console.error("callStatic failed:", e);
54
+ throw new Error("Pre-check (callStatic) for rejectTransferHolder failed");
55
+ }
56
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
57
+ return await titleEscrowContract.rejectTransferHolder(encryptedRemarks, txOptions);
58
+ }, "rejectTransferHolder");
59
+ const rejectTransferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
60
+ const { tokenRegistryAddress, tokenId } = contractOptions;
61
+ let { titleEscrowAddress } = contractOptions;
62
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
63
+ if (!titleEscrowAddress) {
64
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
65
+ if (!tokenId) throw new Error("Token ID is required");
66
+ titleEscrowAddress = await getTitleEscrowAddress(
67
+ tokenRegistryAddress,
68
+ tokenId,
69
+ signer.provider,
70
+ {}
71
+ );
72
+ }
73
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
74
+ if (!signer.provider) throw new Error("Provider is required");
75
+ const { remarks } = params;
76
+ const Contract = getEthersContractFromProvider(signer.provider);
77
+ const titleEscrowContract = new Contract(
78
+ titleEscrowAddress,
79
+ v5Contracts.TitleEscrow__factory.abi,
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ signer
82
+ );
83
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
84
+ let isV5TT = titleEscrowVersion === "v5";
85
+ if (titleEscrowVersion === void 0) {
86
+ isV5TT = await isTitleEscrowVersion({
87
+ titleEscrowAddress,
88
+ versionInterface: TitleEscrowInterface.V5,
89
+ provider: signer.provider
90
+ });
91
+ }
92
+ if (!isV5TT) {
93
+ throw new Error("Only Token Registry V5 is supported");
94
+ }
95
+ try {
96
+ const isV6 = isV6EthersProvider(signer.provider);
97
+ const args = isV5TT ? [encryptedRemarks] : [];
98
+ if (isV6) {
99
+ await titleEscrowContract.rejectTransferBeneficiary.staticCall(...args);
100
+ } else {
101
+ await titleEscrowContract.callStatic.rejectTransferBeneficiary(...args);
102
+ }
103
+ } catch (e) {
104
+ console.error("callStatic failed:", e);
105
+ throw new Error("Pre-check (callStatic) for rejectTransferBeneficiary failed");
106
+ }
107
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
108
+ return await titleEscrowContract.rejectTransferBeneficiary(encryptedRemarks, txOptions);
109
+ }, "rejectTransferBeneficiary");
110
+ const rejectTransferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
111
+ const { tokenRegistryAddress, tokenId } = contractOptions;
112
+ let { titleEscrowAddress } = contractOptions;
113
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
114
+ if (!titleEscrowAddress) {
115
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
116
+ if (!tokenId) throw new Error("Token ID is required");
117
+ titleEscrowAddress = await getTitleEscrowAddress(
118
+ tokenRegistryAddress,
119
+ tokenId,
120
+ signer.provider,
121
+ {}
122
+ );
123
+ }
124
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
125
+ if (!signer.provider) throw new Error("Provider is required");
126
+ const { remarks } = params;
127
+ const Contract = getEthersContractFromProvider(signer.provider);
128
+ const titleEscrowContract = new Contract(
129
+ titleEscrowAddress,
130
+ v5Contracts.TitleEscrow__factory.abi,
131
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
+ signer
133
+ );
134
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
135
+ let isV5TT = titleEscrowVersion === "v5";
136
+ if (titleEscrowVersion === void 0) {
137
+ isV5TT = await isTitleEscrowVersion({
138
+ titleEscrowAddress,
139
+ versionInterface: TitleEscrowInterface.V5,
140
+ provider: signer.provider
141
+ });
142
+ }
143
+ if (!isV5TT) {
144
+ throw new Error("Only Token Registry V5 is supported");
145
+ }
146
+ try {
147
+ const isV6 = isV6EthersProvider(signer.provider);
148
+ const args = isV5TT ? [encryptedRemarks] : [];
149
+ if (isV6) {
150
+ await titleEscrowContract.rejectTransferOwners.staticCall(...args);
151
+ } else {
152
+ await titleEscrowContract.callStatic.rejectTransferOwners(...args);
153
+ }
154
+ } catch (e) {
155
+ console.error("callStatic failed:", e);
156
+ throw new Error("Pre-check (callStatic) for rejectTransferOwners failed");
157
+ }
158
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
159
+ return await titleEscrowContract.rejectTransferOwners(encryptedRemarks, txOptions);
160
+ }, "rejectTransferOwners");
161
+
162
+ export { rejectTransferBeneficiary, rejectTransferHolder, rejectTransferOwners };
@@ -0,0 +1,206 @@
1
+ import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface, checkSupportsInterface } from '../core';
2
+ import { v5Contracts, v5SupportInterfaceIds } from '../token-registry-v5';
3
+ import { v4Contracts, v4SupportInterfaceIds } 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 returnToIssuer = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
10
+ const { tokenRegistryAddress, tokenId } = contractOptions;
11
+ let { titleEscrowAddress } = contractOptions;
12
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
13
+ if (!titleEscrowAddress) {
14
+ titleEscrowAddress = await getTitleEscrowAddress(
15
+ tokenRegistryAddress,
16
+ tokenId,
17
+ signer.provider,
18
+ {}
19
+ );
20
+ }
21
+ if (!titleEscrowAddress) throw new Error("Title Escrow address is required");
22
+ if (!signer.provider) throw new Error("Provider is required");
23
+ const { remarks } = params;
24
+ const encryptedRemarks = remarks && options.id ? `0x${encrypt(remarks, options.id)}` : "0x";
25
+ let isV5TT = titleEscrowVersion === "v5";
26
+ let isV4TT = titleEscrowVersion === "v4";
27
+ if (titleEscrowVersion === void 0) {
28
+ [isV4TT, isV5TT] = await Promise.all([
29
+ await isTitleEscrowVersion({
30
+ titleEscrowAddress,
31
+ versionInterface: TitleEscrowInterface.V4,
32
+ provider: signer.provider
33
+ }),
34
+ await isTitleEscrowVersion({
35
+ titleEscrowAddress,
36
+ versionInterface: TitleEscrowInterface.V5,
37
+ provider: signer.provider
38
+ })
39
+ ]);
40
+ }
41
+ if (!isV5TT && !isV4TT) {
42
+ throw new Error("Only Token Registry V4/V5 is supported");
43
+ }
44
+ const Contract = getEthersContractFromProvider(signer.provider);
45
+ let titleEscrowContract;
46
+ if (isV5TT) {
47
+ titleEscrowContract = new Contract(
48
+ titleEscrowAddress,
49
+ v5Contracts.TitleEscrow__factory.abi,
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ signer
52
+ );
53
+ } else if (isV4TT) {
54
+ titleEscrowContract = new Contract(
55
+ titleEscrowAddress,
56
+ v4Contracts.TitleEscrow__factory.abi,
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+ signer
59
+ );
60
+ }
61
+ try {
62
+ const isV6 = isV6EthersProvider(signer.provider);
63
+ const args = isV5TT ? [encryptedRemarks] : [];
64
+ const staticCallFxn = isV5TT ? "returnToIssuer" : "surrender";
65
+ if (isV6) {
66
+ await titleEscrowContract[staticCallFxn].staticCall(...args);
67
+ } else {
68
+ await titleEscrowContract.callStatic[staticCallFxn](...args);
69
+ }
70
+ } catch (e) {
71
+ console.error("callStatic failed:", e);
72
+ throw new Error("Pre-check (callStatic) for returnToIssuer failed");
73
+ }
74
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
75
+ if (isV5TT) {
76
+ return await titleEscrowContract.returnToIssuer(encryptedRemarks, txOptions);
77
+ } else if (isV4TT) {
78
+ return await titleEscrowContract.surrender(txOptions);
79
+ }
80
+ }, "returnToIssuer");
81
+ const rejectReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
82
+ const { tokenRegistryAddress } = contractOptions;
83
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
84
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
85
+ if (!signer.provider) throw new Error("Provider is required");
86
+ const { tokenId, remarks } = params;
87
+ let isV5TT = titleEscrowVersion === "v5";
88
+ let isV4TT = titleEscrowVersion === "v4";
89
+ if (titleEscrowVersion === void 0) {
90
+ [isV4TT, isV5TT] = await Promise.all([
91
+ checkSupportsInterface(
92
+ tokenRegistryAddress,
93
+ v4SupportInterfaceIds.TradeTrustTokenRestorable,
94
+ signer.provider
95
+ ),
96
+ checkSupportsInterface(
97
+ tokenRegistryAddress,
98
+ v5SupportInterfaceIds.TradeTrustTokenRestorable,
99
+ signer.provider
100
+ )
101
+ ]);
102
+ }
103
+ if (!isV4TT && !isV5TT) {
104
+ throw new Error("Only Token Registry V4/V5 is supported");
105
+ }
106
+ const Contract = getEthersContractFromProvider(signer.provider);
107
+ let tradeTrustTokenContract;
108
+ if (isV5TT) {
109
+ tradeTrustTokenContract = new Contract(
110
+ tokenRegistryAddress,
111
+ v5Contracts.TradeTrustToken__factory.abi,
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ signer
114
+ );
115
+ } else if (isV4TT) {
116
+ tradeTrustTokenContract = new Contract(
117
+ tokenRegistryAddress,
118
+ v4Contracts.TradeTrustToken__factory.abi,
119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
+ signer
121
+ );
122
+ }
123
+ const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
124
+ try {
125
+ const isV6 = isV6EthersProvider(signer.provider);
126
+ const args = isV5TT ? [tokenId, encryptedRemarks] : [tokenId];
127
+ if (isV6) {
128
+ await tradeTrustTokenContract.restore.staticCall(...args);
129
+ } else {
130
+ await tradeTrustTokenContract.callStatic.restore(...args);
131
+ }
132
+ } catch (e) {
133
+ console.error("callStatic failed:", e);
134
+ throw new Error("Pre-check (callStatic) for rejectReturned failed");
135
+ }
136
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
137
+ if (isV5TT) {
138
+ return await tradeTrustTokenContract.restore(tokenId, encryptedRemarks, txOptions);
139
+ } else if (isV4TT) {
140
+ return await tradeTrustTokenContract.restore(tokenId, txOptions);
141
+ }
142
+ }, "rejectReturned");
143
+ const acceptReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
144
+ const { tokenRegistryAddress } = contractOptions;
145
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
146
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
147
+ if (!signer.provider) throw new Error("Provider is required");
148
+ const { tokenId, remarks } = params;
149
+ let isV5TT = titleEscrowVersion === "v5";
150
+ let isV4TT = titleEscrowVersion === "v4";
151
+ if (titleEscrowVersion === void 0) {
152
+ [isV4TT, isV5TT] = await Promise.all([
153
+ checkSupportsInterface(
154
+ tokenRegistryAddress,
155
+ v4SupportInterfaceIds.TradeTrustTokenBurnable,
156
+ signer.provider
157
+ ),
158
+ checkSupportsInterface(
159
+ tokenRegistryAddress,
160
+ v5SupportInterfaceIds.TradeTrustTokenBurnable,
161
+ signer.provider
162
+ )
163
+ ]);
164
+ }
165
+ if (!isV4TT && !isV5TT) {
166
+ throw new Error("Only Token Registry V4/V5 is supported");
167
+ }
168
+ const Contract = getEthersContractFromProvider(signer.provider);
169
+ let tradeTrustTokenContract;
170
+ if (isV5TT) {
171
+ tradeTrustTokenContract = new Contract(
172
+ tokenRegistryAddress,
173
+ v5Contracts.TradeTrustToken__factory.abi,
174
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
+ signer
176
+ );
177
+ } else if (isV4TT) {
178
+ tradeTrustTokenContract = new Contract(
179
+ tokenRegistryAddress,
180
+ v4Contracts.TradeTrustToken__factory.abi,
181
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
+ signer
183
+ );
184
+ }
185
+ const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
186
+ try {
187
+ const isV6 = isV6EthersProvider(signer.provider);
188
+ const args = isV5TT ? [encryptedRemarks] : [];
189
+ if (isV6) {
190
+ await tradeTrustTokenContract.burn.staticCall(...args);
191
+ } else {
192
+ await tradeTrustTokenContract.callStatic.burn(...args);
193
+ }
194
+ } catch (e) {
195
+ console.error("callStatic failed:", e);
196
+ throw new Error("Pre-check (callStatic) for acceptReturned failed");
197
+ }
198
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
199
+ if (isV5TT) {
200
+ return await tradeTrustTokenContract.burn(tokenId, encryptedRemarks, txOptions);
201
+ } else if (isV4TT) {
202
+ return await tradeTrustTokenContract.burn(tokenId, txOptions);
203
+ }
204
+ }, "acceptReturned");
205
+
206
+ export { acceptReturned, rejectReturned, returnToIssuer };
@@ -0,0 +1,310 @@
1
+ import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface } from '../core';
2
+ import { v4Contracts } from '../token-registry-v4';
3
+ import { v5Contracts } from '../token-registry-v5';
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 transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
10
+ const { tokenRegistryAddress, tokenId } = contractOptions;
11
+ const { titleEscrowVersion } = options;
12
+ let { titleEscrowAddress } = contractOptions;
13
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
14
+ let isV5TT = titleEscrowVersion === "v5";
15
+ let isV4TT = titleEscrowVersion === "v4";
16
+ if (!titleEscrowAddress) {
17
+ if (!tokenRegistryAddress) throw new Error("Token registry address is required");
18
+ if (!tokenId) throw new Error("Token ID is required");
19
+ titleEscrowAddress = await getTitleEscrowAddress(
20
+ tokenRegistryAddress,
21
+ tokenId,
22
+ signer.provider,
23
+ { titleEscrowVersion }
24
+ );
25
+ }
26
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
27
+ if (!signer.provider) throw new Error("Provider is required");
28
+ const { holderAddress, remarks } = params;
29
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
30
+ if (titleEscrowVersion === void 0) {
31
+ [isV4TT, isV5TT] = await Promise.all([
32
+ isTitleEscrowVersion({
33
+ titleEscrowAddress,
34
+ versionInterface: TitleEscrowInterface.V4,
35
+ provider: signer.provider
36
+ }),
37
+ isTitleEscrowVersion({
38
+ titleEscrowAddress,
39
+ versionInterface: TitleEscrowInterface.V5,
40
+ provider: signer.provider
41
+ })
42
+ ]);
43
+ }
44
+ if (!isV4TT && !isV5TT) {
45
+ throw new Error("Only Token Registry V4/V5 is supported");
46
+ }
47
+ const Contract = getEthersContractFromProvider(signer.provider);
48
+ let titleEscrowContract;
49
+ if (isV5TT) {
50
+ titleEscrowContract = new Contract(
51
+ titleEscrowAddress,
52
+ v5Contracts.TitleEscrow__factory.abi,
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ signer
55
+ );
56
+ } else if (isV4TT) {
57
+ titleEscrowContract = new Contract(
58
+ titleEscrowAddress,
59
+ v4Contracts.TitleEscrow__factory.abi,
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ signer
62
+ );
63
+ }
64
+ try {
65
+ const isV6 = isV6EthersProvider(signer.provider);
66
+ const args = isV5TT ? [holderAddress, encryptedRemarks] : [holderAddress];
67
+ if (isV6) {
68
+ await titleEscrowContract.transferHolder.staticCall(...args);
69
+ } else {
70
+ await titleEscrowContract.callStatic.transferHolder(...args);
71
+ }
72
+ } catch (e) {
73
+ console.error("callStatic failed:", e);
74
+ throw new Error("Pre-check (callStatic) for transferHolder failed");
75
+ }
76
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
77
+ if (isV5TT) {
78
+ return await titleEscrowContract.transferHolder(holderAddress, encryptedRemarks, txOptions);
79
+ } else if (isV4TT) {
80
+ return await titleEscrowContract.transferHolder(holderAddress, txOptions);
81
+ }
82
+ }, "transferHolder");
83
+ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
84
+ const { tokenId, tokenRegistryAddress } = contractOptions;
85
+ const { titleEscrowVersion } = options;
86
+ let { titleEscrowAddress } = contractOptions;
87
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
88
+ let isV5TT = titleEscrowVersion === "v5";
89
+ let isV4TT = titleEscrowVersion === "v4";
90
+ if (!titleEscrowAddress) {
91
+ titleEscrowAddress = await getTitleEscrowAddress(
92
+ tokenRegistryAddress,
93
+ tokenId,
94
+ signer.provider,
95
+ { titleEscrowVersion }
96
+ );
97
+ }
98
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
99
+ if (!signer.provider) throw new Error("Provider is required");
100
+ const { newBeneficiaryAddress, remarks } = params;
101
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
102
+ if (titleEscrowVersion === void 0) {
103
+ [isV4TT, isV5TT] = await Promise.all([
104
+ isTitleEscrowVersion({
105
+ titleEscrowAddress,
106
+ versionInterface: TitleEscrowInterface.V4,
107
+ provider: signer.provider
108
+ }),
109
+ isTitleEscrowVersion({
110
+ titleEscrowAddress,
111
+ versionInterface: TitleEscrowInterface.V5,
112
+ provider: signer.provider
113
+ })
114
+ ]);
115
+ }
116
+ if (!isV4TT && !isV5TT) {
117
+ throw new Error("Only Token Registry V4/V5 is supported");
118
+ }
119
+ const Contract = getEthersContractFromProvider(signer.provider);
120
+ let titleEscrowContract;
121
+ if (isV5TT) {
122
+ titleEscrowContract = new Contract(
123
+ titleEscrowAddress,
124
+ v5Contracts.TitleEscrow__factory.abi,
125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
+ signer
127
+ );
128
+ } else if (isV4TT) {
129
+ titleEscrowContract = new Contract(
130
+ titleEscrowAddress,
131
+ v4Contracts.TitleEscrow__factory.abi,
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ signer
134
+ );
135
+ }
136
+ try {
137
+ const isV6 = isV6EthersProvider(signer.provider);
138
+ const args = isV5TT ? [newBeneficiaryAddress, encryptedRemarks] : [newBeneficiaryAddress];
139
+ if (isV6) {
140
+ await titleEscrowContract.transferBeneficiary.staticCall(...args);
141
+ } else {
142
+ await titleEscrowContract.callStatic.transferBeneficiary(...args);
143
+ }
144
+ } catch (e) {
145
+ console.error("callStatic failed:", e);
146
+ throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
147
+ }
148
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
149
+ if (isV5TT) {
150
+ return await titleEscrowContract.transferBeneficiary(
151
+ newBeneficiaryAddress,
152
+ encryptedRemarks,
153
+ txOptions
154
+ );
155
+ } else if (isV4TT) {
156
+ return await titleEscrowContract.transferBeneficiary(newBeneficiaryAddress, txOptions);
157
+ }
158
+ }, "transferBeneficiary");
159
+ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
160
+ const { tokenId, tokenRegistryAddress } = contractOptions;
161
+ const { titleEscrowVersion } = options;
162
+ let { titleEscrowAddress } = contractOptions;
163
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
164
+ let isV5TT = titleEscrowVersion === "v5";
165
+ let isV4TT = titleEscrowVersion === "v4";
166
+ if (!titleEscrowAddress) {
167
+ titleEscrowAddress = await getTitleEscrowAddress(
168
+ tokenRegistryAddress,
169
+ tokenId,
170
+ signer.provider,
171
+ { titleEscrowVersion }
172
+ );
173
+ }
174
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
175
+ if (!signer.provider) throw new Error("Provider is required");
176
+ const { newBeneficiaryAddress, newHolderAddress, remarks } = params;
177
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
178
+ if (titleEscrowVersion === void 0) {
179
+ [isV4TT, isV5TT] = await Promise.all([
180
+ isTitleEscrowVersion({
181
+ titleEscrowAddress,
182
+ versionInterface: TitleEscrowInterface.V4,
183
+ provider: signer.provider
184
+ }),
185
+ isTitleEscrowVersion({
186
+ titleEscrowAddress,
187
+ versionInterface: TitleEscrowInterface.V5,
188
+ provider: signer.provider
189
+ })
190
+ ]);
191
+ }
192
+ if (!isV4TT && !isV5TT) {
193
+ throw new Error("Only Token Registry V4/V5 is supported");
194
+ }
195
+ const Contract = getEthersContractFromProvider(signer.provider);
196
+ let titleEscrowContract;
197
+ if (isV5TT) {
198
+ titleEscrowContract = new Contract(
199
+ titleEscrowAddress,
200
+ v5Contracts.TitleEscrow__factory.abi,
201
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
202
+ signer
203
+ );
204
+ } else if (isV4TT) {
205
+ titleEscrowContract = new Contract(
206
+ titleEscrowAddress,
207
+ v4Contracts.TitleEscrow__factory.abi,
208
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
209
+ signer
210
+ );
211
+ }
212
+ try {
213
+ const isV6 = isV6EthersProvider(signer.provider);
214
+ const args = isV5TT ? [newBeneficiaryAddress, newHolderAddress, encryptedRemarks] : [newBeneficiaryAddress, newHolderAddress];
215
+ if (isV6) {
216
+ await titleEscrowContract.transferOwners.staticCall(...args);
217
+ } else {
218
+ await titleEscrowContract.callStatic.transferOwners(...args);
219
+ }
220
+ } catch (e) {
221
+ console.error("callStatic failed:", e);
222
+ throw new Error("Pre-check (callStatic) for transferOwners failed");
223
+ }
224
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
225
+ if (isV5TT) {
226
+ return await titleEscrowContract.transferOwners(
227
+ newBeneficiaryAddress,
228
+ newHolderAddress,
229
+ encryptedRemarks,
230
+ txOptions
231
+ );
232
+ } else if (isV4TT) {
233
+ return await titleEscrowContract.transferOwners(
234
+ newBeneficiaryAddress,
235
+ newHolderAddress,
236
+ txOptions
237
+ );
238
+ }
239
+ }, "transferOwners");
240
+ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
241
+ const { tokenId, tokenRegistryAddress } = contractOptions;
242
+ const { titleEscrowVersion } = options;
243
+ let { titleEscrowAddress } = contractOptions;
244
+ const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
245
+ let isV5TT = titleEscrowVersion === "v5";
246
+ let isV4TT = titleEscrowVersion === "v4";
247
+ if (!titleEscrowAddress) {
248
+ titleEscrowAddress = await getTitleEscrowAddress(
249
+ tokenRegistryAddress,
250
+ tokenId,
251
+ signer.provider,
252
+ { titleEscrowVersion }
253
+ );
254
+ }
255
+ if (!titleEscrowAddress) throw new Error("Token registry address is required");
256
+ if (!signer.provider) throw new Error("Provider is required");
257
+ const { newBeneficiaryAddress, remarks } = params;
258
+ const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
259
+ if (titleEscrowVersion === void 0) {
260
+ [isV4TT, isV5TT] = await Promise.all([
261
+ isTitleEscrowVersion({
262
+ titleEscrowAddress,
263
+ versionInterface: TitleEscrowInterface.V4,
264
+ provider: signer.provider
265
+ }),
266
+ isTitleEscrowVersion({
267
+ titleEscrowAddress,
268
+ versionInterface: TitleEscrowInterface.V5,
269
+ provider: signer.provider
270
+ })
271
+ ]);
272
+ }
273
+ const Contract = getEthersContractFromProvider(signer.provider);
274
+ let titleEscrowContract;
275
+ if (isV5TT) {
276
+ titleEscrowContract = new Contract(
277
+ titleEscrowAddress,
278
+ v5Contracts.TitleEscrow__factory.abi,
279
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
+ signer
281
+ );
282
+ } else if (isV4TT) {
283
+ titleEscrowContract = new Contract(
284
+ titleEscrowAddress,
285
+ v4Contracts.TitleEscrow__factory.abi,
286
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
287
+ signer
288
+ );
289
+ }
290
+ try {
291
+ const isV6 = isV6EthersProvider(signer.provider);
292
+ const args = isV5TT ? [newBeneficiaryAddress, encryptedRemarks] : [newBeneficiaryAddress];
293
+ if (isV6) {
294
+ await titleEscrowContract.nominate.staticCall(...args);
295
+ } else {
296
+ await titleEscrowContract.callStatic.nominate(...args);
297
+ }
298
+ } catch (e) {
299
+ console.error("callStatic failed:", e);
300
+ throw new Error("Pre-check (callStatic) for nominate failed");
301
+ }
302
+ const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
303
+ if (isV5TT) {
304
+ return await titleEscrowContract.nominate(newBeneficiaryAddress, encryptedRemarks, txOptions);
305
+ } else if (isV4TT) {
306
+ return await titleEscrowContract.nominate(newBeneficiaryAddress, txOptions);
307
+ }
308
+ }, "nominate");
309
+
310
+ export { nominate, transferBeneficiary, transferHolder, transferOwners };