@huma-finance/sdk 0.0.8 → 0.0.11
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/README.md +1 -1
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +2 -2
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +2 -2
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +22 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js.map +1 -0
- package/dist/cjs/helpers/index.d.ts +1 -1
- package/dist/cjs/helpers/index.js +1 -1
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/hooks/index.d.ts +1 -1
- package/dist/cjs/hooks/index.js +1 -1
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/usePoolContract.d.ts +1 -1
- package/dist/cjs/hooks/usePoolContract.js +1 -1
- package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.js +20 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.js.map +1 -0
- package/dist/cjs/services/ARWeaveService.d.ts +14 -0
- package/dist/cjs/services/ARWeaveService.js +46 -23
- package/dist/cjs/services/ARWeaveService.js.map +1 -1
- package/dist/cjs/services/EAService.d.ts +4 -22
- package/dist/cjs/services/EAService.js +0 -6
- package/dist/cjs/services/EAService.js.map +1 -1
- package/dist/cjs/services/ReceivableService.d.ts +25 -44
- package/dist/cjs/services/ReceivableService.js +41 -75
- package/dist/cjs/services/ReceivableService.js.map +1 -1
- package/dist/cjs/services/SubgraphService.js +18 -18
- package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
- package/dist/helpers/PoolContractHelper.d.ts +12 -12
- package/dist/helpers/PoolContractHelper.js +16 -16
- package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
- package/dist/helpers/RealWorldReceivableContractHelper.js +18 -0
- package/dist/helpers/RealWorldReceivableContractHelper.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -3
- package/dist/helpers/index.js +3 -3
- package/dist/helpers/index.js.map +1 -1
- package/dist/hooks/index.d.ts +4 -4
- package/dist/hooks/index.js +4 -4
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useContract.d.ts +13 -13
- package/dist/hooks/useContract.js +26 -26
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
- package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
- package/dist/hooks/usePoolContract.d.ts +60 -60
- package/dist/hooks/usePoolContract.js +48 -48
- package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -0
- package/dist/hooks/useRealWorldReceivableContract.js +16 -0
- package/dist/hooks/useRealWorldReceivableContract.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/services/ARWeaveService.d.ts +84 -84
- package/dist/services/ARWeaveService.js +144 -144
- package/dist/services/EAService.d.ts +18 -36
- package/dist/services/EAService.js +9 -15
- package/dist/services/EAService.js.map +1 -1
- package/dist/services/ReceivableService.d.ts +76 -95
- package/dist/services/ReceivableService.js +134 -168
- package/dist/services/ReceivableService.js.map +1 -1
- package/dist/services/SubgraphService.d.ts +53 -53
- package/dist/services/SubgraphService.js +95 -95
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +4 -4
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/chain.d.ts +14 -14
- package/dist/utils/chain.js +28 -28
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/poolInfo.d.ts +9 -9
- package/dist/utils/poolInfo.js +9 -9
- package/dist/utils/web3.d.ts +4 -4
- package/dist/utils/web3.js +23 -23
- package/package.json +3 -3
|
@@ -1,120 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReceivableService =
|
|
3
|
+
exports.ReceivableService = void 0;
|
|
4
4
|
const providers_1 = require("@ethersproject/providers");
|
|
5
5
|
const shared_1 = require("@huma-finance/shared");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const ARWeaveService_1 = require("./ARWeaveService");
|
|
8
8
|
const chain_1 = require("../utils/chain");
|
|
9
|
-
|
|
10
|
-
* Enumeration of payment methods. Maps to the PaymentMethod enum in the BaseCreditPoolReceivable contract.
|
|
11
|
-
* Declarative payment methods are those that do not actually send ERC20 funds. Payable payment methods are those that
|
|
12
|
-
* do by calling makePayment on the BaseCreditPool contract.
|
|
13
|
-
*
|
|
14
|
-
* @enum {number}
|
|
15
|
-
* @memberof ReceivableService
|
|
16
|
-
*/
|
|
17
|
-
var PaymentMethod;
|
|
18
|
-
(function (PaymentMethod) {
|
|
19
|
-
PaymentMethod[PaymentMethod["Declarative"] = 0] = "Declarative";
|
|
20
|
-
PaymentMethod[PaymentMethod["Payable"] = 1] = "Payable";
|
|
21
|
-
})(PaymentMethod = exports.PaymentMethod || (exports.PaymentMethod = {}));
|
|
22
|
-
/**
|
|
23
|
-
* Pays a BaseCreditPoolReceivable using the specified payment method, given an referenceId mapping to the receivable's metadata
|
|
24
|
-
*
|
|
25
|
-
* @memberof ReceivableService
|
|
26
|
-
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
27
|
-
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
28
|
-
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
29
|
-
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
30
|
-
* @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
|
|
31
|
-
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
32
|
-
*/
|
|
33
|
-
async function payReceivableByReferenceId(
|
|
9
|
+
async function declareReceivablePaymentByReferenceId(
|
|
34
10
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
11
|
signer,
|
|
36
12
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
37
13
|
referenceId,
|
|
38
14
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
-
paymentAmount
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
-
paymentMethod) {
|
|
15
|
+
paymentAmount) {
|
|
42
16
|
throw new Error('Not implemented');
|
|
43
17
|
}
|
|
44
18
|
/**
|
|
45
|
-
*
|
|
19
|
+
* Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
|
|
46
20
|
*
|
|
21
|
+
* @async
|
|
22
|
+
* @function
|
|
47
23
|
* @memberof ReceivableService
|
|
48
24
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
49
25
|
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
50
26
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
51
|
-
* @
|
|
52
|
-
* @
|
|
53
|
-
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
27
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
28
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
54
29
|
*/
|
|
55
|
-
async function
|
|
30
|
+
async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount) {
|
|
56
31
|
var _a;
|
|
57
32
|
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
58
|
-
const
|
|
59
|
-
? (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.
|
|
33
|
+
const realWorldReceivable = chainId
|
|
34
|
+
? (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable]
|
|
60
35
|
: null;
|
|
61
|
-
if (!
|
|
62
|
-
throw new Error('
|
|
36
|
+
if (!realWorldReceivable) {
|
|
37
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
63
38
|
}
|
|
64
|
-
const contract = (0, utils_1.getContract)(
|
|
39
|
+
const contract = (0, utils_1.getContract)(realWorldReceivable, shared_1.REAL_WORLD_RECEIVABLE_ABI, signer);
|
|
65
40
|
if (!contract) {
|
|
66
|
-
throw new Error('Could not find
|
|
67
|
-
}
|
|
68
|
-
let tx;
|
|
69
|
-
switch (paymentMethod) {
|
|
70
|
-
case PaymentMethod.Declarative:
|
|
71
|
-
tx = await contract.declarePayment(receivableTokenId, paymentAmount);
|
|
72
|
-
break;
|
|
73
|
-
case PaymentMethod.Payable:
|
|
74
|
-
tx = await contract.makePayment(receivableTokenId, paymentAmount);
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
throw new Error('Invalid payment method');
|
|
41
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
78
42
|
}
|
|
79
|
-
return
|
|
43
|
+
return contract.declarePayment(receivableTokenId, paymentAmount);
|
|
80
44
|
}
|
|
81
45
|
/**
|
|
82
|
-
*
|
|
46
|
+
* Creates a new RealWorldReceivable token on the given chain of the signer
|
|
83
47
|
*
|
|
48
|
+
* @async
|
|
49
|
+
* @function
|
|
84
50
|
* @memberof ReceivableService
|
|
85
51
|
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
86
|
-
* @param {string} recipient - The address of the recipient of the receivable token.
|
|
87
52
|
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
88
53
|
* @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
54
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
89
55
|
* @param {number} receivableAmount - The amount of the receivable token to mint.
|
|
90
56
|
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
91
|
-
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
92
57
|
* @param {string} uri - The URI of the receivable token metadata.
|
|
93
58
|
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
94
59
|
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
95
|
-
* @throws {Error} - Throws an error if the
|
|
60
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
96
61
|
*/
|
|
97
|
-
async function
|
|
62
|
+
async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
|
|
98
63
|
var _a, _b, _c;
|
|
99
64
|
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
100
|
-
const
|
|
101
|
-
? (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.
|
|
65
|
+
const realWorldReceivable = chainId
|
|
66
|
+
? (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable]
|
|
102
67
|
: null;
|
|
103
68
|
const poolInfo = chainId
|
|
104
69
|
? (_c = (_b = shared_1.PoolContractMap[chainId]) === null || _b === void 0 ? void 0 : _b[poolType]) === null || _c === void 0 ? void 0 : _c[poolName]
|
|
105
70
|
: undefined;
|
|
106
|
-
if (!
|
|
107
|
-
throw new Error('
|
|
71
|
+
if (!realWorldReceivable || !poolInfo) {
|
|
72
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
108
73
|
}
|
|
109
|
-
const contract = (0, utils_1.getContract)(
|
|
74
|
+
const contract = (0, utils_1.getContract)(realWorldReceivable, shared_1.REAL_WORLD_RECEIVABLE_ABI, signer);
|
|
110
75
|
if (!contract) {
|
|
111
|
-
throw new Error('Could not find
|
|
76
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
112
77
|
}
|
|
113
|
-
return contract.
|
|
78
|
+
return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
|
|
114
79
|
}
|
|
115
80
|
/**
|
|
116
|
-
*
|
|
81
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
117
82
|
*
|
|
83
|
+
* @async
|
|
84
|
+
* @function
|
|
118
85
|
* @memberof ReceivableService
|
|
119
86
|
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
120
87
|
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
@@ -124,9 +91,9 @@ async function mintReceivable(signer, poolName, poolType, receivableAmount, matu
|
|
|
124
91
|
* @param {string} recipient - The receivable token recipient.
|
|
125
92
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
126
93
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
94
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
127
95
|
* @param {number} receivableAmount - The receivable amount.
|
|
128
96
|
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
129
|
-
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
130
97
|
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
131
98
|
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
132
99
|
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
@@ -134,9 +101,9 @@ async function mintReceivable(signer, poolName, poolType, receivableAmount, matu
|
|
|
134
101
|
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
135
102
|
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
136
103
|
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
137
|
-
* @returns {Promise<
|
|
104
|
+
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
138
105
|
*/
|
|
139
|
-
async function
|
|
106
|
+
async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
|
|
140
107
|
const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
|
|
141
108
|
try {
|
|
142
109
|
const tags = [
|
|
@@ -149,10 +116,9 @@ async function mintReceivableWithMetadata(signerOrProvider, privateKey, chainId,
|
|
|
149
116
|
];
|
|
150
117
|
const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
|
|
151
118
|
console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
|
|
152
|
-
|
|
119
|
+
return await createReceivable(signerOrProvider instanceof providers_1.Web3Provider
|
|
153
120
|
? signerOrProvider.getSigner()
|
|
154
|
-
: signerOrProvider, poolName, poolType, receivableAmount, maturityDate,
|
|
155
|
-
return await tx.wait();
|
|
121
|
+
: signerOrProvider, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${response.id}`, gasOpts);
|
|
156
122
|
}
|
|
157
123
|
catch (e) {
|
|
158
124
|
console.error(e);
|
|
@@ -164,9 +130,9 @@ async function mintReceivableWithMetadata(signerOrProvider, privateKey, chainId,
|
|
|
164
130
|
* @namespace ReceivableService
|
|
165
131
|
*/
|
|
166
132
|
exports.ReceivableService = {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
133
|
+
createReceivableWithMetadata,
|
|
134
|
+
createReceivable,
|
|
135
|
+
declareReceivablePaymentByTokenId,
|
|
136
|
+
declareReceivablePaymentByReferenceId,
|
|
171
137
|
};
|
|
172
138
|
//# sourceMappingURL=ReceivableService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":"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"}
|
|
@@ -39,24 +39,24 @@ function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event)
|
|
|
39
39
|
return Promise.resolve([]);
|
|
40
40
|
}
|
|
41
41
|
const poolAddress = (_c = (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.pool;
|
|
42
|
-
const query = `
|
|
43
|
-
query {
|
|
44
|
-
creditEvents(
|
|
45
|
-
where: {
|
|
46
|
-
owner: "${userAddress}",
|
|
47
|
-
pool: "${poolAddress}",
|
|
48
|
-
event_in: "[${event.join('", "')}]"
|
|
49
|
-
}
|
|
50
|
-
orderBy: timestamp
|
|
51
|
-
orderDirection: desc
|
|
52
|
-
) {
|
|
53
|
-
amount
|
|
54
|
-
timestamp
|
|
55
|
-
owner
|
|
56
|
-
pool
|
|
57
|
-
event
|
|
58
|
-
}
|
|
59
|
-
}
|
|
42
|
+
const query = `
|
|
43
|
+
query {
|
|
44
|
+
creditEvents(
|
|
45
|
+
where: {
|
|
46
|
+
owner: "${userAddress}",
|
|
47
|
+
pool: "${poolAddress}",
|
|
48
|
+
event_in: "[${event.join('", "')}]"
|
|
49
|
+
}
|
|
50
|
+
orderBy: timestamp
|
|
51
|
+
orderDirection: desc
|
|
52
|
+
) {
|
|
53
|
+
amount
|
|
54
|
+
timestamp
|
|
55
|
+
owner
|
|
56
|
+
pool
|
|
57
|
+
event
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
60
|
`;
|
|
61
61
|
return fetch(url, {
|
|
62
62
|
method: 'POST',
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Contract, ethers } from 'ethers';
|
|
2
|
-
/**
|
|
3
|
-
* Returns an ethers contract instance for the
|
|
4
|
-
* associated with the given pool name on the current chain.
|
|
5
|
-
*
|
|
6
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
-
* @returns {Contract | null} A contract instance for the
|
|
9
|
-
*/
|
|
10
|
-
export declare function getERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
1
|
+
import { Contract, ethers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
4
|
+
* associated with the given pool name on the current chain.
|
|
5
|
+
*
|
|
6
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
+
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
|
|
2
|
-
import { getContract } from '../utils';
|
|
3
|
-
/**
|
|
4
|
-
* Returns an ethers contract instance for the
|
|
5
|
-
* associated with the given pool name on the current chain.
|
|
6
|
-
*
|
|
7
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
-
* @returns {Contract | null} A contract instance for the
|
|
10
|
-
*/
|
|
11
|
-
export function getERC20TransferableReceivableContract(signerOrProvider, chainId) {
|
|
12
|
-
var _a;
|
|
13
|
-
const erc20TransferableReceiable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.ERC20TransferableReceivable];
|
|
14
|
-
if (!erc20TransferableReceiable)
|
|
15
|
-
return null;
|
|
16
|
-
return getContract(erc20TransferableReceiable, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
|
|
17
|
-
}
|
|
1
|
+
import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
|
|
2
|
+
import { getContract } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
5
|
+
* associated with the given pool name on the current chain.
|
|
6
|
+
*
|
|
7
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
+
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
10
|
+
*/
|
|
11
|
+
export function getERC20TransferableReceivableContract(signerOrProvider, chainId) {
|
|
12
|
+
var _a;
|
|
13
|
+
const erc20TransferableReceiable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.ERC20TransferableReceivable];
|
|
14
|
+
if (!erc20TransferableReceiable)
|
|
15
|
+
return null;
|
|
16
|
+
return getContract(erc20TransferableReceiable, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=ERC20TransferableReceivableContractHelper.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Contract, ethers } from 'ethers';
|
|
2
|
-
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
3
|
-
/**
|
|
4
|
-
* Returns an ethers contract instance for a Huma pool contract
|
|
5
|
-
*
|
|
6
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
-
* @param {POOL_NAME} poolName The name of the pool contract to get.
|
|
9
|
-
* @param {POOL_TYPE} poolType The type of the pool contract to get.
|
|
10
|
-
* @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
|
|
11
|
-
*/
|
|
12
|
-
export declare function getPoolContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Contract | null;
|
|
1
|
+
import { Contract, ethers } from 'ethers';
|
|
2
|
+
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an ethers contract instance for a Huma pool contract
|
|
5
|
+
*
|
|
6
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
+
* @param {POOL_NAME} poolName The name of the pool contract to get.
|
|
9
|
+
* @param {POOL_TYPE} poolType The type of the pool contract to get.
|
|
10
|
+
* @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getPoolContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Contract | null;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { getContract, getPoolInfo } from '../utils';
|
|
2
|
-
/**
|
|
3
|
-
* Returns an ethers contract instance for a Huma pool contract
|
|
4
|
-
*
|
|
5
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
6
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
7
|
-
* @param {POOL_NAME} poolName The name of the pool contract to get.
|
|
8
|
-
* @param {POOL_TYPE} poolType The type of the pool contract to get.
|
|
9
|
-
* @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
|
|
10
|
-
*/
|
|
11
|
-
export function getPoolContract(signerOrProvider, chainId, poolName, poolType) {
|
|
12
|
-
const poolInfo = getPoolInfo(chainId, poolName, poolType);
|
|
13
|
-
if (!poolInfo)
|
|
14
|
-
return null;
|
|
15
|
-
return getContract(poolInfo.pool, poolInfo.poolAbi, signerOrProvider);
|
|
16
|
-
}
|
|
1
|
+
import { getContract, getPoolInfo } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an ethers contract instance for a Huma pool contract
|
|
4
|
+
*
|
|
5
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
6
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
7
|
+
* @param {POOL_NAME} poolName The name of the pool contract to get.
|
|
8
|
+
* @param {POOL_TYPE} poolType The type of the pool contract to get.
|
|
9
|
+
* @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
|
|
10
|
+
*/
|
|
11
|
+
export function getPoolContract(signerOrProvider, chainId, poolName, poolType) {
|
|
12
|
+
const poolInfo = getPoolInfo(chainId, poolName, poolType);
|
|
13
|
+
if (!poolInfo)
|
|
14
|
+
return null;
|
|
15
|
+
return getContract(poolInfo.pool, poolInfo.poolAbi, signerOrProvider);
|
|
16
|
+
}
|
|
17
17
|
//# sourceMappingURL=PoolContractHelper.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Contract, ethers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an ethers contract instance for the RealWorldReceivable contract
|
|
4
|
+
* associated with the given pool name on the current chain.
|
|
5
|
+
*
|
|
6
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
+
* @returns {Contract | null} A contract instance for the RealWorldReceivable contract or null if it could not be found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getRealWorldReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { REAL_WORLD_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
|
|
2
|
+
import { getContract } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an ethers contract instance for the RealWorldReceivable contract
|
|
5
|
+
* associated with the given pool name on the current chain.
|
|
6
|
+
*
|
|
7
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
+
* @returns {Contract | null} A contract instance for the RealWorldReceivable contract or null if it could not be found.
|
|
10
|
+
*/
|
|
11
|
+
export function getRealWorldReceivableContract(signerOrProvider, chainId) {
|
|
12
|
+
var _a;
|
|
13
|
+
const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
|
|
14
|
+
if (!realWorldReceivable)
|
|
15
|
+
return null;
|
|
16
|
+
return getContract(realWorldReceivable, REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=RealWorldReceivableContractHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealWorldReceivableContractHelper.js","sourceRoot":"","sources":["../../src/helpers/RealWorldReceivableContractHelper.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,mBAAmB,GACvB,MAAA,yBAAyB,CAAC,OAAO,CAAC,0CAChC,sBAAsB,CAAC,mBAAmB,CAC3C,CAAA;IAEH,IAAI,CAAC,mBAAmB;QAAE,OAAO,IAAI,CAAA;IAErC,OAAO,WAAW,CAChB,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,CACjB,CAAA;AACH,CAAC"}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './ERC20TransferableReceivableContractHelper';
|
|
3
|
-
export * from './PoolContractHelper';
|
|
1
|
+
export * from './RealWorldReceivableContractHelper';
|
|
2
|
+
export * from './ERC20TransferableReceivableContractHelper';
|
|
3
|
+
export * from './PoolContractHelper';
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './ERC20TransferableReceivableContractHelper';
|
|
3
|
-
export * from './PoolContractHelper';
|
|
1
|
+
export * from './RealWorldReceivableContractHelper';
|
|
2
|
+
export * from './ERC20TransferableReceivableContractHelper';
|
|
3
|
+
export * from './PoolContractHelper';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AACnD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,sBAAsB,CAAA"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './useContract';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './useERC20TransferableReceivableContract';
|
|
4
|
-
export * from './usePoolContract';
|
|
1
|
+
export * from './useContract';
|
|
2
|
+
export * from './useRealWorldReceivableContract';
|
|
3
|
+
export * from './useERC20TransferableReceivableContract';
|
|
4
|
+
export * from './usePoolContract';
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './useContract';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './useERC20TransferableReceivableContract';
|
|
4
|
-
export * from './usePoolContract';
|
|
1
|
+
export * from './useContract';
|
|
2
|
+
export * from './useRealWorldReceivableContract';
|
|
3
|
+
export * from './useERC20TransferableReceivableContract';
|
|
4
|
+
export * from './usePoolContract';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,kCAAkC,CAAA;AAChD,cAAc,0CAA0C,CAAA;AACxD,cAAc,mBAAmB,CAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Contract } from '@ethersproject/contracts';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook for creating an ethers instance of a smart contract.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the contract.
|
|
7
|
-
* @param {string | null | undefined} address - The address of the smart contract instance.
|
|
8
|
-
* @param {any} ABI - The ABI of the smart contract.
|
|
9
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
|
|
10
|
-
* Note that this signerOrProvider must be connected to the same network as the smart contract in question.
|
|
11
|
-
* @returns {T | null} An instance of the smart contract, or null if an error occurs.
|
|
12
|
-
*/
|
|
13
|
-
export declare function useContract<T extends Contract = Contract>(address: string | null | undefined, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): T | null;
|
|
1
|
+
import { Contract } from '@ethersproject/contracts';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook for creating an ethers instance of a smart contract.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the contract.
|
|
7
|
+
* @param {string | null | undefined} address - The address of the smart contract instance.
|
|
8
|
+
* @param {any} ABI - The ABI of the smart contract.
|
|
9
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
|
|
10
|
+
* Note that this signerOrProvider must be connected to the same network as the smart contract in question.
|
|
11
|
+
* @returns {T | null} An instance of the smart contract, or null if an error occurs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useContract<T extends Contract = Contract>(address: string | null | undefined, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): T | null;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { getContract } from '../utils/web3';
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook for creating an ethers instance of a smart contract.
|
|
5
|
-
*
|
|
6
|
-
* @template T - The type of the contract.
|
|
7
|
-
* @param {string | null | undefined} address - The address of the smart contract instance.
|
|
8
|
-
* @param {any} ABI - The ABI of the smart contract.
|
|
9
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
|
|
10
|
-
* Note that this signerOrProvider must be connected to the same network as the smart contract in question.
|
|
11
|
-
* @returns {T | null} An instance of the smart contract, or null if an error occurs.
|
|
12
|
-
*/
|
|
13
|
-
export function useContract(address,
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
ABI, signerOrProvider) {
|
|
16
|
-
return useMemo(() => {
|
|
17
|
-
if (!address || !ABI || !signerOrProvider)
|
|
18
|
-
return null;
|
|
19
|
-
try {
|
|
20
|
-
return getContract(address, ABI, signerOrProvider);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}, [address, ABI, signerOrProvider]);
|
|
26
|
-
}
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getContract } from '../utils/web3';
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook for creating an ethers instance of a smart contract.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the contract.
|
|
7
|
+
* @param {string | null | undefined} address - The address of the smart contract instance.
|
|
8
|
+
* @param {any} ABI - The ABI of the smart contract.
|
|
9
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
|
|
10
|
+
* Note that this signerOrProvider must be connected to the same network as the smart contract in question.
|
|
11
|
+
* @returns {T | null} An instance of the smart contract, or null if an error occurs.
|
|
12
|
+
*/
|
|
13
|
+
export function useContract(address,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
ABI, signerOrProvider) {
|
|
16
|
+
return useMemo(() => {
|
|
17
|
+
if (!address || !ABI || !signerOrProvider)
|
|
18
|
+
return null;
|
|
19
|
+
try {
|
|
20
|
+
return getContract(address, ABI, signerOrProvider);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}, [address, ABI, signerOrProvider]);
|
|
26
|
+
}
|
|
27
27
|
//# sourceMappingURL=useContract.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Contract, ethers } from 'ethers';
|
|
2
|
-
import { POOL_NAME } from '@huma-finance/shared';
|
|
3
|
-
/**
|
|
4
|
-
* A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
5
|
-
* associated with the given pool name on the current chain.
|
|
6
|
-
*
|
|
7
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
-
* @param {POOL_NAME} poolName The name of the pool to get the contract for.
|
|
10
|
-
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME): Contract | null;
|
|
1
|
+
import { Contract, ethers } from 'ethers';
|
|
2
|
+
import { POOL_NAME } from '@huma-finance/shared';
|
|
3
|
+
/**
|
|
4
|
+
* A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
5
|
+
* associated with the given pool name on the current chain.
|
|
6
|
+
*
|
|
7
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
+
* @param {POOL_NAME} poolName The name of the pool to get the contract for.
|
|
10
|
+
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME): Contract | null;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, POOL_TYPE, PoolContractMap, } from '@huma-finance/shared';
|
|
2
|
-
import { useContract } from './useContract';
|
|
3
|
-
/**
|
|
4
|
-
* A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
5
|
-
* associated with the given pool name on the current chain.
|
|
6
|
-
*
|
|
7
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
-
* @param {POOL_NAME} poolName The name of the pool to get the contract for.
|
|
10
|
-
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
11
|
-
*/
|
|
12
|
-
export function useERC20TransferableReceivableContract(signerOrProvider, chainId, poolName) {
|
|
13
|
-
var _a, _b, _c;
|
|
14
|
-
const TransferableReceivableAddress = (_c = (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[POOL_TYPE.Invoice]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.assetAddress;
|
|
15
|
-
return useContract(TransferableReceivableAddress, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
|
|
16
|
-
}
|
|
1
|
+
import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, POOL_TYPE, PoolContractMap, } from '@huma-finance/shared';
|
|
2
|
+
import { useContract } from './useContract';
|
|
3
|
+
/**
|
|
4
|
+
* A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
5
|
+
* associated with the given pool name on the current chain.
|
|
6
|
+
*
|
|
7
|
+
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
8
|
+
* @param {number} chainId The chain id where the contract instance exists
|
|
9
|
+
* @param {POOL_NAME} poolName The name of the pool to get the contract for.
|
|
10
|
+
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
11
|
+
*/
|
|
12
|
+
export function useERC20TransferableReceivableContract(signerOrProvider, chainId, poolName) {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const TransferableReceivableAddress = (_c = (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[POOL_TYPE.Invoice]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.assetAddress;
|
|
15
|
+
return useContract(TransferableReceivableAddress, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
|
|
16
|
+
}
|
|
17
17
|
//# sourceMappingURL=useERC20TransferableReceivableContract.js.map
|