@trustvc/trustvc 1.7.4 → 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.
- package/dist/cjs/core/endorsement-chain/useEndorsementChain.js +5 -6
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/token-registry-functions/index.js +40 -0
- package/dist/cjs/token-registry-functions/mint.js +90 -0
- package/dist/cjs/token-registry-functions/ownerOf.js +45 -0
- package/dist/cjs/token-registry-functions/rejectTransfers.js +166 -0
- package/dist/cjs/token-registry-functions/returnToken.js +210 -0
- package/dist/cjs/token-registry-functions/transfer.js +315 -0
- 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/index.js +1 -0
- package/dist/esm/token-registry-functions/index.js +5 -0
- package/dist/esm/token-registry-functions/mint.js +88 -0
- package/dist/esm/token-registry-functions/ownerOf.js +43 -0
- package/dist/esm/token-registry-functions/rejectTransfers.js +162 -0
- package/dist/esm/token-registry-functions/returnToken.js +206 -0
- package/dist/esm/token-registry-functions/transfer.js +310 -0
- 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 +7 -1
- package/dist/types/token-registry-functions/index.d.ts +9 -0
- 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 +82 -0
- package/dist/types/token-registry-functions/types.d.ts +80 -0
- package/dist/types/token-registry-functions/utils.d.ts +16 -0
- package/package.json +14 -2
|
@@ -92,14 +92,12 @@ const getDocumentOwner = /* @__PURE__ */ __name(async (tokenRegistryAddress, tok
|
|
|
92
92
|
const tokenRegistry = new Contract(tokenRegistryAddress, tokenRegistryAbi, provider);
|
|
93
93
|
return await tokenRegistry.ownerOf(tokenId);
|
|
94
94
|
}, "getDocumentOwner");
|
|
95
|
-
const checkSupportsInterface = /* @__PURE__ */ __name(async (
|
|
95
|
+
const checkSupportsInterface = /* @__PURE__ */ __name(async (contractAddress, interfaceId, provider) => {
|
|
96
96
|
try {
|
|
97
97
|
const Contract = ethers.getEthersContractFromProvider(provider);
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const titleEscrowContract = new Contract(titleEscrowAddress, titleEscrowAbi, provider);
|
|
102
|
-
return await titleEscrowContract.supportsInterface(interfaceId);
|
|
98
|
+
const abi = ["function supportsInterface(bytes4 interfaceId) external view returns (bool)"];
|
|
99
|
+
const contract = new Contract(contractAddress, abi, provider);
|
|
100
|
+
return await contract.supportsInterface(interfaceId);
|
|
103
101
|
} catch {
|
|
104
102
|
return false;
|
|
105
103
|
}
|
|
@@ -165,6 +163,7 @@ const fetchEndorsementChain = /* @__PURE__ */ __name(async (tokenRegistryAddress
|
|
|
165
163
|
}, "fetchEndorsementChain");
|
|
166
164
|
|
|
167
165
|
exports.TitleEscrowInterface = TitleEscrowInterface;
|
|
166
|
+
exports.checkSupportsInterface = checkSupportsInterface;
|
|
168
167
|
exports.fetchEndorsementChain = fetchEndorsementChain;
|
|
169
168
|
exports.getDocumentOwner = getDocumentOwner;
|
|
170
169
|
exports.getTitleEscrowAddress = getTitleEscrowAddress;
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var tokenRegistryV4 = require('./token-registry-v4');
|
|
4
4
|
var tokenRegistryV5 = require('./token-registry-v5');
|
|
5
|
+
var tokenRegistryFunctions = require('./token-registry-functions');
|
|
5
6
|
var core = require('./core');
|
|
6
7
|
var openAttestation = require('./open-attestation');
|
|
7
8
|
var verify = require('./verify');
|
|
@@ -79,6 +80,12 @@ Object.defineProperty(exports, "v5Utils", {
|
|
|
79
80
|
enumerable: true,
|
|
80
81
|
get: function () { return tokenRegistryV5.v5Utils; }
|
|
81
82
|
});
|
|
83
|
+
Object.keys(tokenRegistryFunctions).forEach(function (k) {
|
|
84
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () { return tokenRegistryFunctions[k]; }
|
|
87
|
+
});
|
|
88
|
+
});
|
|
82
89
|
Object.keys(core).forEach(function (k) {
|
|
83
90
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
84
91
|
enumerable: true,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var transfer = require('./transfer');
|
|
4
|
+
var rejectTransfers = require('./rejectTransfers');
|
|
5
|
+
var returnToken = require('./returnToken');
|
|
6
|
+
var mint = require('./mint');
|
|
7
|
+
var ownerOf = require('./ownerOf');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.keys(transfer).forEach(function (k) {
|
|
12
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return transfer[k]; }
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
Object.keys(rejectTransfers).forEach(function (k) {
|
|
18
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return rejectTransfers[k]; }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
Object.keys(returnToken).forEach(function (k) {
|
|
24
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return returnToken[k]; }
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
Object.keys(mint).forEach(function (k) {
|
|
30
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return mint[k]; }
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
Object.keys(ownerOf).forEach(function (k) {
|
|
36
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return ownerOf[k]; }
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
6
|
+
var utils = require('./utils');
|
|
7
|
+
var ethers = require('../utils/ethers');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const mint = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
12
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
13
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
14
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
15
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
16
|
+
const { beneficiaryAddress, holderAddress, tokenId, remarks } = params;
|
|
17
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
18
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
19
|
+
if (titleEscrowVersion === void 0) {
|
|
20
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
21
|
+
core.checkSupportsInterface(
|
|
22
|
+
tokenRegistryAddress,
|
|
23
|
+
tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenMintable,
|
|
24
|
+
signer.provider
|
|
25
|
+
),
|
|
26
|
+
core.checkSupportsInterface(
|
|
27
|
+
tokenRegistryAddress,
|
|
28
|
+
tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenMintable,
|
|
29
|
+
signer.provider
|
|
30
|
+
)
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
if (!isV4TT && !isV5TT) {
|
|
34
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
35
|
+
}
|
|
36
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
37
|
+
let tradeTrustTokenContract;
|
|
38
|
+
if (isV5TT) {
|
|
39
|
+
tradeTrustTokenContract = new Contract(
|
|
40
|
+
tokenRegistryAddress,
|
|
41
|
+
tokenRegistryV5.v5Contracts.TradeTrustToken__factory.abi,
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
signer
|
|
44
|
+
);
|
|
45
|
+
} else if (isV4TT) {
|
|
46
|
+
tradeTrustTokenContract = new Contract(
|
|
47
|
+
tokenRegistryAddress,
|
|
48
|
+
tokenRegistryV4.v4Contracts.TradeTrustToken__factory.abi,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
signer
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id ?? "")}` : "0x";
|
|
54
|
+
try {
|
|
55
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
56
|
+
const args = isV5TT ? [beneficiaryAddress, holderAddress, tokenId, encryptedRemarks] : [beneficiaryAddress, holderAddress, tokenId];
|
|
57
|
+
if (isV6) {
|
|
58
|
+
await tradeTrustTokenContract.mint.staticCall(...args);
|
|
59
|
+
} else {
|
|
60
|
+
await tradeTrustTokenContract.callStatic.mint(...args);
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error("callStatic failed:", e);
|
|
64
|
+
throw new Error("Pre-check (callStatic) for mint failed");
|
|
65
|
+
}
|
|
66
|
+
const txOptions = await utils.getTxOptions(
|
|
67
|
+
signer,
|
|
68
|
+
chainId,
|
|
69
|
+
maxFeePerGas,
|
|
70
|
+
maxPriorityFeePerGas
|
|
71
|
+
);
|
|
72
|
+
if (isV5TT) {
|
|
73
|
+
return await tradeTrustTokenContract.mint(
|
|
74
|
+
beneficiaryAddress,
|
|
75
|
+
holderAddress,
|
|
76
|
+
tokenId,
|
|
77
|
+
encryptedRemarks,
|
|
78
|
+
txOptions
|
|
79
|
+
);
|
|
80
|
+
} else if (isV4TT) {
|
|
81
|
+
return await tradeTrustTokenContract.mint(
|
|
82
|
+
beneficiaryAddress,
|
|
83
|
+
holderAddress,
|
|
84
|
+
tokenId,
|
|
85
|
+
txOptions
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}, "mint");
|
|
89
|
+
|
|
90
|
+
exports.mint = mint;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const ownerOf = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
10
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
11
|
+
const { titleEscrowVersion } = options;
|
|
12
|
+
const { tokenId } = params;
|
|
13
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
16
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
17
|
+
if (titleEscrowVersion === void 0) {
|
|
18
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
19
|
+
core.checkSupportsInterface(tokenRegistryAddress, tokenRegistryV4.v4SupportInterfaceIds.SBT, signer.provider),
|
|
20
|
+
core.checkSupportsInterface(tokenRegistryAddress, tokenRegistryV5.v5SupportInterfaceIds.SBT, signer.provider)
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
if (!isV4TT && !isV5TT) {
|
|
24
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
25
|
+
}
|
|
26
|
+
let tradeTrustTokenContract;
|
|
27
|
+
if (isV5TT) {
|
|
28
|
+
tradeTrustTokenContract = tokenRegistryV5.v5Contracts.TradeTrustToken__factory.connect(
|
|
29
|
+
tokenRegistryAddress,
|
|
30
|
+
signer
|
|
31
|
+
);
|
|
32
|
+
} else if (isV4TT) {
|
|
33
|
+
tradeTrustTokenContract = tokenRegistryV4.v4Contracts.TradeTrustToken__factory.connect(
|
|
34
|
+
tokenRegistryAddress,
|
|
35
|
+
signer
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (isV5TT) {
|
|
39
|
+
return await tradeTrustTokenContract.ownerOf(tokenId);
|
|
40
|
+
} else if (isV4TT) {
|
|
41
|
+
return await tradeTrustTokenContract.ownerOf(tokenId);
|
|
42
|
+
}
|
|
43
|
+
}, "ownerOf");
|
|
44
|
+
|
|
45
|
+
exports.ownerOf = ownerOf;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('./../core');
|
|
4
|
+
var tokenRegistryV5 = require('./../token-registry-v5');
|
|
5
|
+
var utils = require('./utils');
|
|
6
|
+
var ethers = require('../utils/ethers');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const rejectTransferHolder = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
11
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
12
|
+
let { titleEscrowAddress } = contractOptions;
|
|
13
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
14
|
+
if (!titleEscrowAddress) {
|
|
15
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
16
|
+
if (!tokenId) throw new Error("Token ID is required");
|
|
17
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
18
|
+
tokenRegistryAddress,
|
|
19
|
+
tokenId,
|
|
20
|
+
signer.provider,
|
|
21
|
+
{}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (!titleEscrowAddress) throw new Error("Title escrow address is required");
|
|
25
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
26
|
+
const { remarks } = params;
|
|
27
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
28
|
+
const titleEscrowContract = new Contract(
|
|
29
|
+
titleEscrowAddress,
|
|
30
|
+
tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
signer
|
|
33
|
+
);
|
|
34
|
+
const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
35
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
36
|
+
if (titleEscrowVersion === void 0) {
|
|
37
|
+
isV5TT = await core.isTitleEscrowVersion({
|
|
38
|
+
titleEscrowAddress,
|
|
39
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
40
|
+
provider: signer.provider
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (!isV5TT) {
|
|
44
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
48
|
+
const args = isV5TT ? [encryptedRemarks] : [];
|
|
49
|
+
if (isV6) {
|
|
50
|
+
await titleEscrowContract.rejectTransferHolder.staticCall(...args);
|
|
51
|
+
} else {
|
|
52
|
+
await titleEscrowContract.callStatic.rejectTransferHolder(...args);
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error("callStatic failed:", e);
|
|
56
|
+
throw new Error("Pre-check (callStatic) for rejectTransferHolder failed");
|
|
57
|
+
}
|
|
58
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
59
|
+
return await titleEscrowContract.rejectTransferHolder(encryptedRemarks, txOptions);
|
|
60
|
+
}, "rejectTransferHolder");
|
|
61
|
+
const rejectTransferBeneficiary = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
62
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
63
|
+
let { titleEscrowAddress } = contractOptions;
|
|
64
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
65
|
+
if (!titleEscrowAddress) {
|
|
66
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
67
|
+
if (!tokenId) throw new Error("Token ID is required");
|
|
68
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
69
|
+
tokenRegistryAddress,
|
|
70
|
+
tokenId,
|
|
71
|
+
signer.provider,
|
|
72
|
+
{}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
76
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
77
|
+
const { remarks } = params;
|
|
78
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
79
|
+
const titleEscrowContract = new Contract(
|
|
80
|
+
titleEscrowAddress,
|
|
81
|
+
tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
signer
|
|
84
|
+
);
|
|
85
|
+
const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
86
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
87
|
+
if (titleEscrowVersion === void 0) {
|
|
88
|
+
isV5TT = await core.isTitleEscrowVersion({
|
|
89
|
+
titleEscrowAddress,
|
|
90
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
91
|
+
provider: signer.provider
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (!isV5TT) {
|
|
95
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
99
|
+
const args = isV5TT ? [encryptedRemarks] : [];
|
|
100
|
+
if (isV6) {
|
|
101
|
+
await titleEscrowContract.rejectTransferBeneficiary.staticCall(...args);
|
|
102
|
+
} else {
|
|
103
|
+
await titleEscrowContract.callStatic.rejectTransferBeneficiary(...args);
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.error("callStatic failed:", e);
|
|
107
|
+
throw new Error("Pre-check (callStatic) for rejectTransferBeneficiary failed");
|
|
108
|
+
}
|
|
109
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
110
|
+
return await titleEscrowContract.rejectTransferBeneficiary(encryptedRemarks, txOptions);
|
|
111
|
+
}, "rejectTransferBeneficiary");
|
|
112
|
+
const rejectTransferOwners = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
113
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
114
|
+
let { titleEscrowAddress } = contractOptions;
|
|
115
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
116
|
+
if (!titleEscrowAddress) {
|
|
117
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
118
|
+
if (!tokenId) throw new Error("Token ID is required");
|
|
119
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
120
|
+
tokenRegistryAddress,
|
|
121
|
+
tokenId,
|
|
122
|
+
signer.provider,
|
|
123
|
+
{}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (!titleEscrowAddress) throw new Error("Token registry address is required");
|
|
127
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
128
|
+
const { remarks } = params;
|
|
129
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
130
|
+
const titleEscrowContract = new Contract(
|
|
131
|
+
titleEscrowAddress,
|
|
132
|
+
tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
signer
|
|
135
|
+
);
|
|
136
|
+
const encryptedRemarks = remarks ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
137
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
138
|
+
if (titleEscrowVersion === void 0) {
|
|
139
|
+
isV5TT = await core.isTitleEscrowVersion({
|
|
140
|
+
titleEscrowAddress,
|
|
141
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
142
|
+
provider: signer.provider
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (!isV5TT) {
|
|
146
|
+
throw new Error("Only Token Registry V5 is supported");
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
150
|
+
const args = isV5TT ? [encryptedRemarks] : [];
|
|
151
|
+
if (isV6) {
|
|
152
|
+
await titleEscrowContract.rejectTransferOwners.staticCall(...args);
|
|
153
|
+
} else {
|
|
154
|
+
await titleEscrowContract.callStatic.rejectTransferOwners(...args);
|
|
155
|
+
}
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.error("callStatic failed:", e);
|
|
158
|
+
throw new Error("Pre-check (callStatic) for rejectTransferOwners failed");
|
|
159
|
+
}
|
|
160
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
161
|
+
return await titleEscrowContract.rejectTransferOwners(encryptedRemarks, txOptions);
|
|
162
|
+
}, "rejectTransferOwners");
|
|
163
|
+
|
|
164
|
+
exports.rejectTransferBeneficiary = rejectTransferBeneficiary;
|
|
165
|
+
exports.rejectTransferHolder = rejectTransferHolder;
|
|
166
|
+
exports.rejectTransferOwners = rejectTransferOwners;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var tokenRegistryV5 = require('../token-registry-v5');
|
|
5
|
+
var tokenRegistryV4 = require('../token-registry-v4');
|
|
6
|
+
var utils = require('./utils');
|
|
7
|
+
var ethers = require('../utils/ethers');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const returnToIssuer = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
12
|
+
const { tokenRegistryAddress, tokenId } = contractOptions;
|
|
13
|
+
let { titleEscrowAddress } = contractOptions;
|
|
14
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
15
|
+
if (!titleEscrowAddress) {
|
|
16
|
+
titleEscrowAddress = await core.getTitleEscrowAddress(
|
|
17
|
+
tokenRegistryAddress,
|
|
18
|
+
tokenId,
|
|
19
|
+
signer.provider,
|
|
20
|
+
{}
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (!titleEscrowAddress) throw new Error("Title Escrow address is required");
|
|
24
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
25
|
+
const { remarks } = params;
|
|
26
|
+
const encryptedRemarks = remarks && options.id ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
27
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
28
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
29
|
+
if (titleEscrowVersion === void 0) {
|
|
30
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
31
|
+
await core.isTitleEscrowVersion({
|
|
32
|
+
titleEscrowAddress,
|
|
33
|
+
versionInterface: core.TitleEscrowInterface.V4,
|
|
34
|
+
provider: signer.provider
|
|
35
|
+
}),
|
|
36
|
+
await core.isTitleEscrowVersion({
|
|
37
|
+
titleEscrowAddress,
|
|
38
|
+
versionInterface: core.TitleEscrowInterface.V5,
|
|
39
|
+
provider: signer.provider
|
|
40
|
+
})
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
if (!isV5TT && !isV4TT) {
|
|
44
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
45
|
+
}
|
|
46
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
47
|
+
let titleEscrowContract;
|
|
48
|
+
if (isV5TT) {
|
|
49
|
+
titleEscrowContract = new Contract(
|
|
50
|
+
titleEscrowAddress,
|
|
51
|
+
tokenRegistryV5.v5Contracts.TitleEscrow__factory.abi,
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
signer
|
|
54
|
+
);
|
|
55
|
+
} else if (isV4TT) {
|
|
56
|
+
titleEscrowContract = new Contract(
|
|
57
|
+
titleEscrowAddress,
|
|
58
|
+
tokenRegistryV4.v4Contracts.TitleEscrow__factory.abi,
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
signer
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
65
|
+
const args = isV5TT ? [encryptedRemarks] : [];
|
|
66
|
+
const staticCallFxn = isV5TT ? "returnToIssuer" : "surrender";
|
|
67
|
+
if (isV6) {
|
|
68
|
+
await titleEscrowContract[staticCallFxn].staticCall(...args);
|
|
69
|
+
} else {
|
|
70
|
+
await titleEscrowContract.callStatic[staticCallFxn](...args);
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error("callStatic failed:", e);
|
|
74
|
+
throw new Error("Pre-check (callStatic) for returnToIssuer failed");
|
|
75
|
+
}
|
|
76
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
77
|
+
if (isV5TT) {
|
|
78
|
+
return await titleEscrowContract.returnToIssuer(encryptedRemarks, txOptions);
|
|
79
|
+
} else if (isV4TT) {
|
|
80
|
+
return await titleEscrowContract.surrender(txOptions);
|
|
81
|
+
}
|
|
82
|
+
}, "returnToIssuer");
|
|
83
|
+
const rejectReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
84
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
85
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
86
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
87
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
88
|
+
const { tokenId, remarks } = params;
|
|
89
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
90
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
91
|
+
if (titleEscrowVersion === void 0) {
|
|
92
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
93
|
+
core.checkSupportsInterface(
|
|
94
|
+
tokenRegistryAddress,
|
|
95
|
+
tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
96
|
+
signer.provider
|
|
97
|
+
),
|
|
98
|
+
core.checkSupportsInterface(
|
|
99
|
+
tokenRegistryAddress,
|
|
100
|
+
tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenRestorable,
|
|
101
|
+
signer.provider
|
|
102
|
+
)
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
if (!isV4TT && !isV5TT) {
|
|
106
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
107
|
+
}
|
|
108
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
109
|
+
let tradeTrustTokenContract;
|
|
110
|
+
if (isV5TT) {
|
|
111
|
+
tradeTrustTokenContract = new Contract(
|
|
112
|
+
tokenRegistryAddress,
|
|
113
|
+
tokenRegistryV5.v5Contracts.TradeTrustToken__factory.abi,
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
|
+
signer
|
|
116
|
+
);
|
|
117
|
+
} else if (isV4TT) {
|
|
118
|
+
tradeTrustTokenContract = new Contract(
|
|
119
|
+
tokenRegistryAddress,
|
|
120
|
+
tokenRegistryV4.v4Contracts.TradeTrustToken__factory.abi,
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
+
signer
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
126
|
+
try {
|
|
127
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
128
|
+
const args = isV5TT ? [tokenId, encryptedRemarks] : [tokenId];
|
|
129
|
+
if (isV6) {
|
|
130
|
+
await tradeTrustTokenContract.restore.staticCall(...args);
|
|
131
|
+
} else {
|
|
132
|
+
await tradeTrustTokenContract.callStatic.restore(...args);
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error("callStatic failed:", e);
|
|
136
|
+
throw new Error("Pre-check (callStatic) for rejectReturned failed");
|
|
137
|
+
}
|
|
138
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
139
|
+
if (isV5TT) {
|
|
140
|
+
return await tradeTrustTokenContract.restore(tokenId, encryptedRemarks, txOptions);
|
|
141
|
+
} else if (isV4TT) {
|
|
142
|
+
return await tradeTrustTokenContract.restore(tokenId, txOptions);
|
|
143
|
+
}
|
|
144
|
+
}, "rejectReturned");
|
|
145
|
+
const acceptReturned = /* @__PURE__ */ __name(async (contractOptions, signer, params, options) => {
|
|
146
|
+
const { tokenRegistryAddress } = contractOptions;
|
|
147
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, titleEscrowVersion } = options;
|
|
148
|
+
if (!tokenRegistryAddress) throw new Error("Token registry address is required");
|
|
149
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
150
|
+
const { tokenId, remarks } = params;
|
|
151
|
+
let isV5TT = titleEscrowVersion === "v5";
|
|
152
|
+
let isV4TT = titleEscrowVersion === "v4";
|
|
153
|
+
if (titleEscrowVersion === void 0) {
|
|
154
|
+
[isV4TT, isV5TT] = await Promise.all([
|
|
155
|
+
core.checkSupportsInterface(
|
|
156
|
+
tokenRegistryAddress,
|
|
157
|
+
tokenRegistryV4.v4SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
158
|
+
signer.provider
|
|
159
|
+
),
|
|
160
|
+
core.checkSupportsInterface(
|
|
161
|
+
tokenRegistryAddress,
|
|
162
|
+
tokenRegistryV5.v5SupportInterfaceIds.TradeTrustTokenBurnable,
|
|
163
|
+
signer.provider
|
|
164
|
+
)
|
|
165
|
+
]);
|
|
166
|
+
}
|
|
167
|
+
if (!isV4TT && !isV5TT) {
|
|
168
|
+
throw new Error("Only Token Registry V4/V5 is supported");
|
|
169
|
+
}
|
|
170
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
171
|
+
let tradeTrustTokenContract;
|
|
172
|
+
if (isV5TT) {
|
|
173
|
+
tradeTrustTokenContract = new Contract(
|
|
174
|
+
tokenRegistryAddress,
|
|
175
|
+
tokenRegistryV5.v5Contracts.TradeTrustToken__factory.abi,
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
signer
|
|
178
|
+
);
|
|
179
|
+
} else if (isV4TT) {
|
|
180
|
+
tradeTrustTokenContract = new Contract(
|
|
181
|
+
tokenRegistryAddress,
|
|
182
|
+
tokenRegistryV4.v4Contracts.TradeTrustToken__factory.abi,
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
signer
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const encryptedRemarks = remarks && isV5TT ? `0x${core.encrypt(remarks, options.id)}` : "0x";
|
|
188
|
+
try {
|
|
189
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
190
|
+
const args = isV5TT ? [encryptedRemarks] : [];
|
|
191
|
+
if (isV6) {
|
|
192
|
+
await tradeTrustTokenContract.burn.staticCall(...args);
|
|
193
|
+
} else {
|
|
194
|
+
await tradeTrustTokenContract.callStatic.burn(...args);
|
|
195
|
+
}
|
|
196
|
+
} catch (e) {
|
|
197
|
+
console.error("callStatic failed:", e);
|
|
198
|
+
throw new Error("Pre-check (callStatic) for acceptReturned failed");
|
|
199
|
+
}
|
|
200
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
201
|
+
if (isV5TT) {
|
|
202
|
+
return await tradeTrustTokenContract.burn(tokenId, encryptedRemarks, txOptions);
|
|
203
|
+
} else if (isV4TT) {
|
|
204
|
+
return await tradeTrustTokenContract.burn(tokenId, txOptions);
|
|
205
|
+
}
|
|
206
|
+
}, "acceptReturned");
|
|
207
|
+
|
|
208
|
+
exports.acceptReturned = acceptReturned;
|
|
209
|
+
exports.rejectReturned = rejectReturned;
|
|
210
|
+
exports.returnToIssuer = returnToIssuer;
|