@trustvc/trustvc 1.6.0-alpha.1 → 1.6.0-alpha.2
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.
- package/dist/cjs/core/endorsement-chain/useEndorsementChain.js +5 -6
- package/dist/cjs/token-registry-functions/index.js +28 -0
- package/dist/cjs/token-registry-functions/mint.js +86 -0
- package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
- package/dist/cjs/token-registry-functions/rejectTransfers.js +123 -0
- package/dist/cjs/token-registry-functions/returnToken.js +204 -0
- package/dist/cjs/token-registry-functions/transfer.js +16 -58
- package/dist/cjs/token-registry-functions/types.js +2 -0
- package/dist/cjs/token-registry-functions/utils.js +37 -0
- package/dist/esm/core/endorsement-chain/useEndorsementChain.js +5 -7
- package/dist/esm/token-registry-functions/index.js +4 -0
- package/dist/esm/token-registry-functions/mint.js +84 -0
- package/dist/esm/token-registry-functions/ownerOf.js +43 -0
- package/dist/esm/token-registry-functions/rejectTransfers.js +119 -0
- package/dist/esm/token-registry-functions/returnToken.js +200 -0
- package/dist/esm/token-registry-functions/transfer.js +16 -58
- package/dist/esm/token-registry-functions/types.js +1 -0
- package/dist/esm/token-registry-functions/utils.js +33 -0
- package/dist/types/core/endorsement-chain/index.d.ts +1 -1
- package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +2 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +6 -1
- package/dist/types/token-registry-functions/index.d.ts +6 -1
- package/dist/types/token-registry-functions/mint.d.ts +20 -0
- package/dist/types/token-registry-functions/ownerOf.d.ts +19 -0
- package/dist/types/token-registry-functions/rejectTransfers.d.ts +43 -0
- package/dist/types/token-registry-functions/returnToken.d.ts +44 -0
- package/dist/types/token-registry-functions/transfer.d.ts +79 -40
- package/dist/types/token-registry-functions/types.d.ts +80 -0
- package/dist/types/token-registry-functions/utils.d.ts +13 -0
- package/package.json +1 -1
|
@@ -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 } : void 0;
|
|
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 (
|
|
93
|
+
const checkSupportsInterface = /* @__PURE__ */ __name(async (contractAddress, interfaceId, provider) => {
|
|
94
94
|
try {
|
|
95
95
|
const Contract = getEthersContractFromProvider(provider);
|
|
96
|
-
const
|
|
97
|
-
|
|
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 };
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
const mint = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
9
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
10
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
11
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
12
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
13
|
+
const { beneficiaryAddress, holderAddress, tokenId, remarks } = params;
|
|
14
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
15
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
16
|
+
if (titleEscrowVersion === void 0) {
|
|
17
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
18
|
+
checkSupportsInterface(
|
|
19
|
+
tokenRegistryAddress,
|
|
20
|
+
v4SupportInterfaceIds.TradeTrustTokenMintable,
|
|
21
|
+
signer.provider
|
|
22
|
+
),
|
|
23
|
+
checkSupportsInterface(
|
|
24
|
+
tokenRegistryAddress,
|
|
25
|
+
v5SupportInterfaceIds.TradeTrustTokenMintable,
|
|
26
|
+
signer.provider
|
|
27
|
+
)
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
if (!isV4TT && !isV5TT) {
|
|
31
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
32
|
+
}
|
|
33
|
+
let tradeTrustTokenContract;
|
|
34
|
+
if (isV5TT) {
|
|
35
|
+
tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
|
|
36
|
+
tokenRegistryAddress,
|
|
37
|
+
signer
|
|
38
|
+
);
|
|
39
|
+
} else if (isV4TT) {
|
|
40
|
+
tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
|
|
41
|
+
tokenRegistryAddress,
|
|
42
|
+
signer
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
46
|
+
try {
|
|
47
|
+
if (isV5TT) {
|
|
48
|
+
await tradeTrustTokenContract.callStatic.mint(
|
|
49
|
+
beneficiaryAddress,
|
|
50
|
+
holderAddress,
|
|
51
|
+
tokenId,
|
|
52
|
+
encryptedRemarks
|
|
53
|
+
);
|
|
54
|
+
} else if (isV4TT) {
|
|
55
|
+
await tradeTrustTokenContract.callStatic.mint(
|
|
56
|
+
beneficiaryAddress,
|
|
57
|
+
holderAddress,
|
|
58
|
+
tokenId
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error("callStatic failed:", e);
|
|
63
|
+
throw new Error("Pre-check (callStatic) for mint failed");
|
|
64
|
+
}
|
|
65
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
66
|
+
if (isV5TT) {
|
|
67
|
+
return await tradeTrustTokenContract.mint(
|
|
68
|
+
beneficiaryAddress,
|
|
69
|
+
holderAddress,
|
|
70
|
+
tokenId,
|
|
71
|
+
encryptedRemarks,
|
|
72
|
+
txOptions
|
|
73
|
+
);
|
|
74
|
+
} else if (isV4TT) {
|
|
75
|
+
return await tradeTrustTokenContract.mint(
|
|
76
|
+
beneficiaryAddress,
|
|
77
|
+
holderAddress,
|
|
78
|
+
tokenId,
|
|
79
|
+
txOptions
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}, "mint");
|
|
83
|
+
|
|
84
|
+
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 };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { getTitleEscrowAddress, encrypt, isTitleEscrowVersion, TitleEscrowInterface } from '../core';
|
|
2
|
+
import { v5Contracts } from '../token-registry-v5';
|
|
3
|
+
import { getTxOptions } from './utils';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const rejectTransferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
8
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
9
|
+
let { titleEscrowAddress } = contractOptions;
|
|
10
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
11
|
+
if (!titleEscrowAddress) {
|
|
12
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
13
|
+
tokenRegistryAddress,
|
|
14
|
+
tokenId,
|
|
15
|
+
signer.provider,
|
|
16
|
+
{}
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
20
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
21
|
+
const { remarks } = params;
|
|
22
|
+
const titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
23
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
24
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
25
|
+
if (titleEscrowVersion === void 0) {
|
|
26
|
+
isV5TT = await isTitleEscrowVersion({
|
|
27
|
+
titleEscrowAddress,
|
|
28
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
29
|
+
provider: signer.provider
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!isV5TT) {
|
|
33
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
await titleEscrowContract.callStatic.rejectTransferHolder(encryptedRemarks);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error("callStatic failed:", e);
|
|
39
|
+
throw new Error("Pre-check (callStatic) for rejectTransferHolder failed");
|
|
40
|
+
}
|
|
41
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
42
|
+
return await titleEscrowContract.rejectTransferHolder(encryptedRemarks, txOptions);
|
|
43
|
+
}, "rejectTransferHolder");
|
|
44
|
+
const rejectTransferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
45
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
46
|
+
let { titleEscrowAddress } = contractOptions;
|
|
47
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
48
|
+
if (!titleEscrowAddress) {
|
|
49
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
50
|
+
tokenRegistryAddress,
|
|
51
|
+
tokenId,
|
|
52
|
+
signer.provider,
|
|
53
|
+
{}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
57
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
58
|
+
const { remarks } = params;
|
|
59
|
+
const titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
60
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
61
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
62
|
+
if (titleEscrowVersion === void 0) {
|
|
63
|
+
isV5TT = await isTitleEscrowVersion({
|
|
64
|
+
titleEscrowAddress,
|
|
65
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
66
|
+
provider: signer.provider
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (!isV5TT) {
|
|
70
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await titleEscrowContract.callStatic.rejectTransferBeneficiary(encryptedRemarks);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error("callStatic failed:", e);
|
|
76
|
+
throw new Error("Pre-check (callStatic) for rejectTransferBeneficiary failed");
|
|
77
|
+
}
|
|
78
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
79
|
+
return await titleEscrowContract.rejectTransferBeneficiary(encryptedRemarks, txOptions);
|
|
80
|
+
}, "rejectTransferBeneficiary");
|
|
81
|
+
const rejectTransferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
82
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
83
|
+
let { titleEscrowAddress } = contractOptions;
|
|
84
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
85
|
+
if (!titleEscrowAddress) {
|
|
86
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
87
|
+
tokenRegistryAddress,
|
|
88
|
+
tokenId,
|
|
89
|
+
signer.provider,
|
|
90
|
+
{}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
94
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
95
|
+
const { remarks } = params;
|
|
96
|
+
const titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
97
|
+
const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
98
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
99
|
+
if (titleEscrowVersion === void 0) {
|
|
100
|
+
isV5TT = await isTitleEscrowVersion({
|
|
101
|
+
titleEscrowAddress,
|
|
102
|
+
versionInterface: TitleEscrowInterface.V5,
|
|
103
|
+
provider: signer.provider
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (!isV5TT) {
|
|
107
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
await titleEscrowContract.callStatic.rejectTransferOwners(encryptedRemarks);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.error("callStatic failed:", e);
|
|
113
|
+
throw new Error("Pre-check (callStatic) for rejectTransferOwners failed");
|
|
114
|
+
}
|
|
115
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
116
|
+
return await titleEscrowContract.rejectTransferOwners(encryptedRemarks, txOptions);
|
|
117
|
+
}, "rejectTransferOwners");
|
|
118
|
+
|
|
119
|
+
export { rejectTransferBeneficiary, rejectTransferHolder, rejectTransferOwners };
|
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
const returnToIssuer = /* @__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
|
+
titleEscrowAddress = await getTitleEscrowAddress(
|
|
14
|
+
tokenRegistryAddress,
|
|
15
|
+
tokenId,
|
|
16
|
+
signer.provider,
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
if (!titleEscrowAddress) throw new Error("Title Escrow address is required");
|
|
21
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
22
|
+
const { remarks } = params;
|
|
23
|
+
let titleEscrowContract = v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer);
|
|
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
|
+
if (isV4TT) {
|
|
45
|
+
titleEscrowContract = v4Contracts.TitleEscrow__factory.connect(
|
|
46
|
+
titleEscrowAddress,
|
|
47
|
+
signer
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (isV5TT) {
|
|
52
|
+
await titleEscrowContract.callStatic.returnToIssuer(
|
|
53
|
+
encryptedRemarks
|
|
54
|
+
);
|
|
55
|
+
} else if (isV4TT) {
|
|
56
|
+
await titleEscrowContract.callStatic.surrender();
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error("callStatic failed:", e);
|
|
60
|
+
throw new Error("Pre-check (callStatic) for returnToIssuer failed");
|
|
61
|
+
}
|
|
62
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
63
|
+
if (isV5TT) {
|
|
64
|
+
return await titleEscrowContract.returnToIssuer(
|
|
65
|
+
encryptedRemarks,
|
|
66
|
+
txOptions
|
|
67
|
+
);
|
|
68
|
+
} else if (isV4TT) {
|
|
69
|
+
return await titleEscrowContract.surrender(txOptions);
|
|
70
|
+
}
|
|
71
|
+
}, "returnToIssuer");
|
|
72
|
+
const rejectReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
73
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
74
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
75
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
76
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
77
|
+
const { tokenId, remarks } = params;
|
|
78
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
79
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
80
|
+
if (titleEscrowVersion === void 0) {
|
|
81
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
82
|
+
checkSupportsInterface(
|
|
83
|
+
tokenRegistryAddress,
|
|
84
|
+
v4SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
85
|
+
signer.provider
|
|
86
|
+
),
|
|
87
|
+
checkSupportsInterface(
|
|
88
|
+
tokenRegistryAddress,
|
|
89
|
+
v5SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
90
|
+
signer.provider
|
|
91
|
+
)
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
if (!isV4TT && !isV5TT) {
|
|
95
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
96
|
+
}
|
|
97
|
+
let tradeTrustTokenContract;
|
|
98
|
+
if (isV5TT) {
|
|
99
|
+
tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
|
|
100
|
+
tokenRegistryAddress,
|
|
101
|
+
signer
|
|
102
|
+
);
|
|
103
|
+
} else if (isV4TT) {
|
|
104
|
+
tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
|
|
105
|
+
tokenRegistryAddress,
|
|
106
|
+
signer
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
110
|
+
try {
|
|
111
|
+
if (isV5TT) {
|
|
112
|
+
await tradeTrustTokenContract.callStatic.restore(
|
|
113
|
+
tokenId,
|
|
114
|
+
encryptedRemarks
|
|
115
|
+
);
|
|
116
|
+
} else if (isV4TT) {
|
|
117
|
+
await tradeTrustTokenContract.callStatic.restore(tokenId);
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error("callStatic failed:", e);
|
|
121
|
+
throw new Error("Pre-check (callStatic) for rejectReturned failed");
|
|
122
|
+
}
|
|
123
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
124
|
+
if (isV5TT) {
|
|
125
|
+
return await tradeTrustTokenContract.restore(
|
|
126
|
+
tokenId,
|
|
127
|
+
encryptedRemarks,
|
|
128
|
+
txOptions
|
|
129
|
+
);
|
|
130
|
+
} else if (isV4TT) {
|
|
131
|
+
return await tradeTrustTokenContract.restore(
|
|
132
|
+
tokenId,
|
|
133
|
+
txOptions
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}, "rejectReturned");
|
|
137
|
+
const acceptReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
138
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
139
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
140
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
141
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
142
|
+
const { tokenId, remarks } = params;
|
|
143
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
144
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
145
|
+
if (titleEscrowVersion === void 0) {
|
|
146
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
147
|
+
checkSupportsInterface(
|
|
148
|
+
tokenRegistryAddress,
|
|
149
|
+
v4SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
150
|
+
signer.provider
|
|
151
|
+
),
|
|
152
|
+
checkSupportsInterface(
|
|
153
|
+
tokenRegistryAddress,
|
|
154
|
+
v5SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
155
|
+
signer.provider
|
|
156
|
+
)
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
if (!isV4TT && !isV5TT) {
|
|
160
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
161
|
+
}
|
|
162
|
+
let tradeTrustTokenContract;
|
|
163
|
+
if (isV5TT) {
|
|
164
|
+
tradeTrustTokenContract = v5Contracts.TradeTrustToken__factory.connect(
|
|
165
|
+
tokenRegistryAddress,
|
|
166
|
+
signer
|
|
167
|
+
);
|
|
168
|
+
} else if (isV4TT) {
|
|
169
|
+
tradeTrustTokenContract = v4Contracts.TradeTrustToken__factory.connect(
|
|
170
|
+
tokenRegistryAddress,
|
|
171
|
+
signer
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id)}` : "0x";
|
|
175
|
+
try {
|
|
176
|
+
if (isV5TT) {
|
|
177
|
+
await tradeTrustTokenContract.callStatic.burn(
|
|
178
|
+
tokenId,
|
|
179
|
+
encryptedRemarks
|
|
180
|
+
);
|
|
181
|
+
} else if (isV4TT) {
|
|
182
|
+
await tradeTrustTokenContract.callStatic.burn(tokenId);
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.error("callStatic failed:", e);
|
|
186
|
+
throw new Error("Pre-check (callStatic) for acceptReturned failed");
|
|
187
|
+
}
|
|
188
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
189
|
+
if (isV5TT) {
|
|
190
|
+
return await tradeTrustTokenContract.burn(
|
|
191
|
+
tokenId,
|
|
192
|
+
encryptedRemarks,
|
|
193
|
+
txOptions
|
|
194
|
+
);
|
|
195
|
+
} else if (isV4TT) {
|
|
196
|
+
return await tradeTrustTokenContract.burn(tokenId, txOptions);
|
|
197
|
+
}
|
|
198
|
+
}, "acceptReturned");
|
|
199
|
+
|
|
200
|
+
export { acceptReturned, rejectReturned, returnToIssuer };
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { isV6EthersProvider } from 'src/utils/ethers';
|
|
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';
|
|
6
5
|
|
|
7
6
|
var __defProp = Object.defineProperty;
|
|
8
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
const getChainIdSafe = /* @__PURE__ */ __name(async (signer) => {
|
|
10
|
-
if (isV6EthersProvider(signer.provider)) {
|
|
11
|
-
const network = await signer.provider?.getNetwork();
|
|
12
|
-
if (!network?.chainId) throw new Error("Cannot determine chainId: provider is missing");
|
|
13
|
-
return network.chainId;
|
|
14
|
-
}
|
|
15
|
-
return await signer.getChainId();
|
|
16
|
-
}, "getChainIdSafe");
|
|
17
8
|
const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
18
9
|
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
19
10
|
const { titleEscrowVersion } = options;
|
|
20
11
|
let { titleEscrowAddress } = contractOptions;
|
|
21
|
-
|
|
12
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
22
13
|
let isV5TT = titleEscrowVersion === "v5";
|
|
23
14
|
let isV4TT = titleEscrowVersion === "v4";
|
|
24
15
|
if (!titleEscrowAddress) {
|
|
@@ -72,16 +63,7 @@ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
72
63
|
console.error("callStatic failed:", e);
|
|
73
64
|
throw new Error("Pre-check (callStatic) for transferHolder failed");
|
|
74
65
|
}
|
|
75
|
-
|
|
76
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
77
|
-
const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
78
|
-
if (gasStation) {
|
|
79
|
-
const gasFees = await gasStation();
|
|
80
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
81
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
66
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
85
67
|
if (isV5TT) {
|
|
86
68
|
return await titleEscrowContract.transferHolder(
|
|
87
69
|
holderAddress,
|
|
@@ -89,14 +71,17 @@ const transferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
89
71
|
txOptions
|
|
90
72
|
);
|
|
91
73
|
} else if (isV4TT) {
|
|
92
|
-
return await titleEscrowContract.transferHolder(
|
|
74
|
+
return await titleEscrowContract.transferHolder(
|
|
75
|
+
holderAddress,
|
|
76
|
+
txOptions
|
|
77
|
+
);
|
|
93
78
|
}
|
|
94
79
|
}, "transferHolder");
|
|
95
80
|
const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
96
81
|
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
97
82
|
const { titleEscrowVersion } = options;
|
|
98
83
|
let { titleEscrowAddress } = contractOptions;
|
|
99
|
-
|
|
84
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
100
85
|
let isV5TT = titleEscrowVersion === "v5";
|
|
101
86
|
let isV4TT = titleEscrowVersion === "v4";
|
|
102
87
|
if (!titleEscrowAddress) {
|
|
@@ -150,16 +135,7 @@ const transferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signe
|
|
|
150
135
|
console.error("callStatic failed:", e);
|
|
151
136
|
throw new Error("Pre-check (callStatic) for transferBeneficiary failed");
|
|
152
137
|
}
|
|
153
|
-
|
|
154
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
155
|
-
const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
156
|
-
if (gasStation) {
|
|
157
|
-
const gasFees = await gasStation();
|
|
158
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
159
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
138
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
163
139
|
if (isV5TT) {
|
|
164
140
|
const tx = await titleEscrowContract.transferBeneficiary(
|
|
165
141
|
newBeneficiaryAddress,
|
|
@@ -179,7 +155,7 @@ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
179
155
|
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
180
156
|
const { titleEscrowVersion } = options;
|
|
181
157
|
let { titleEscrowAddress } = contractOptions;
|
|
182
|
-
|
|
158
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
183
159
|
let isV5TT = titleEscrowVersion === "v5";
|
|
184
160
|
let isV4TT = titleEscrowVersion === "v4";
|
|
185
161
|
if (!titleEscrowAddress) {
|
|
@@ -235,16 +211,7 @@ const transferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, pa
|
|
|
235
211
|
console.error("callStatic failed:", e);
|
|
236
212
|
throw new Error("Pre-check (callStatic) for transferOwners failed");
|
|
237
213
|
}
|
|
238
|
-
|
|
239
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
240
|
-
const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
241
|
-
if (gasStation) {
|
|
242
|
-
const gasFees = await gasStation();
|
|
243
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
244
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
214
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
248
215
|
if (isV5TT) {
|
|
249
216
|
return await titleEscrowContract.transferOwners(
|
|
250
217
|
newBeneficiaryAddress,
|
|
@@ -264,7 +231,7 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
|
|
|
264
231
|
const { tokenId, tokenRegistryAddress } = contractOptions;
|
|
265
232
|
const { titleEscrowVersion } = options;
|
|
266
233
|
let { titleEscrowAddress } = contractOptions;
|
|
267
|
-
|
|
234
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
268
235
|
let isV5TT = titleEscrowVersion === "v5";
|
|
269
236
|
let isV4TT = titleEscrowVersion === "v4";
|
|
270
237
|
if (!titleEscrowAddress) {
|
|
@@ -315,16 +282,7 @@ const nominate = /* @__PURE__ */ __name(async (contractOptions, signer, params,
|
|
|
315
282
|
console.error("callStatic failed:", e);
|
|
316
283
|
throw new Error("Pre-check (callStatic) for nominate failed");
|
|
317
284
|
}
|
|
318
|
-
|
|
319
|
-
chainId = chainId ?? await getChainIdSafe(signer);
|
|
320
|
-
const gasStation = SUPPORTED_CHAINS[chainId]?.gasStation;
|
|
321
|
-
if (gasStation) {
|
|
322
|
-
const gasFees = await gasStation();
|
|
323
|
-
maxFeePerGas = gasFees?.maxFeePerGas ?? 0;
|
|
324
|
-
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
const txOptions = maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : void 0;
|
|
285
|
+
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
328
286
|
if (isV5TT) {
|
|
329
287
|
return await titleEscrowContract.nominate(
|
|
330
288
|
newBeneficiaryAddress,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|