@huma-finance/sdk 0.0.30 → 0.0.32
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/API.md +443 -10
- package/dist/cjs/services/ARWeaveService.d.ts +13 -2
- package/dist/cjs/services/ARWeaveService.js +22 -1
- package/dist/cjs/services/ARWeaveService.js.map +1 -1
- package/dist/cjs/services/ReceivableService.d.ts +23 -7
- package/dist/cjs/services/ReceivableService.js +160 -43
- package/dist/cjs/services/ReceivableService.js.map +1 -1
- package/dist/services/ARWeaveService.d.ts +13 -2
- package/dist/services/ARWeaveService.js +22 -1
- package/dist/services/ARWeaveService.js.map +1 -1
- package/dist/services/ReceivableService.d.ts +23 -7
- package/dist/services/ReceivableService.js +161 -44
- package/dist/services/ReceivableService.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../../src/services/ARWeaveService.ts"],"names":[],"mappings":";;;;AAAA,4EAA2C;AAM3C,2EAA8C;AAkB9C;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IACpD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC,EAAE,SAAS;YACf,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,UAAU;gBACpB,WAAW,EACT,8DAA8D;aACjE,CAAA;QACH,KAAK,KAAK,EAAE,SAAS;YACnB,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,OAAO;gBACjB,WAAW,EAAE,qCAAqC;aACnD,CAAA;QACH,KAAK,GAAG,EAAE,QAAQ;YAChB,OAAO;gBACL,OAAO,EAAE,8BAA8B;gBACvC,QAAQ,EAAE,OAAO;aAClB,CAAA;QACH;YACE,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;aACb,CAAA;KACJ;AACH,CAAC;AA1BD,wDA0BC;AAED;;;;;;;;;GASG;AACH,KAAK,UAAU,iBAAiB,CAAC,MAAoB,EAAE,MAAc;IACnE,MAAM,MAAM,GAAG,IAAI,gBAAM,CACvB,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,MAAM,EACN,MAAM,CAAC,WAAW;QAChB,CAAC,CAAC;YACE,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC;QACH,CAAC,CAAC,SAAS,CACd,CAAA;IACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IAEpB,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,aAAa,CAC1B,MAAoB;AACpB,8DAA8D;AAC9D,MAAc,EACd,MAAc;IAEd,MAAM,MAAM,GAAG,IAAI,gBAAM,CACvB,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,MAAM,EACN,MAAM,CAAC,WAAW;QAChB,CAAC,CAAC;YACE,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC;QACH,CAAC,CAAC,SAAS,CACd,CAAA;IACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IAEpB,2DAA2D;IAC3D,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAElD,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,KAAK,UAAU,SAAS,CACtB,MAAoB,EACpB,kBAAyC,EACzC,
|
|
1
|
+
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../../src/services/ARWeaveService.ts"],"names":[],"mappings":";;;;AAAA,4EAA2C;AAM3C,0DAAyB;AACzB,2EAA8C;AAkB9C;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IACpD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC,EAAE,SAAS;YACf,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;;;;;;;;;;;;;GAgBhB,CAAA;IAED,8DAA8D;IAC9D,MAAM,IAAI,GAAQ,MAAM,IAAA,yBAAO,EAAC,GAAG,MAAM,CAAC,OAAO,UAAU,EAAE,KAAK,EAAE;QAClE,MAAM;QACN,WAAW;KACZ,CAAC,CAAA;IAEF,OAAO,MAAA,MAAA,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,0CAAE,KAAK,0CAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,EAAE,CAAA;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,oBAAoB,CAAC,GAAW;IAC7C,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACrC,OAAO,QAAQ,CAAC,IAAI,CAAA;KACrB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAA;QAC5C,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAED;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,gBAAgB;IAChB,SAAS;IACT,aAAa;IACb,sBAAsB;IACtB,iBAAiB;IACjB,oBAAoB;CACrB,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TransactionResponse, Web3Provider } from '@ethersproject/providers';
|
|
2
2
|
import { BigNumberish, ethers, Overrides } from 'ethers';
|
|
3
|
-
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
3
|
+
import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfo } from '@huma-finance/shared';
|
|
4
4
|
/**
|
|
5
|
-
* Declares a payment on a RealWorldReceivable given a reference
|
|
5
|
+
* Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
|
|
6
6
|
*
|
|
7
7
|
* @async
|
|
8
8
|
* @function
|
|
@@ -15,13 +15,13 @@ import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
|
15
15
|
*/
|
|
16
16
|
declare function declareReceivablePaymentByReferenceId(signer: ethers.Signer, referenceId: string, paymentAmount: number, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
17
17
|
/**
|
|
18
|
-
* Declares a payment on a RealWorldReceivable given a
|
|
18
|
+
* Declares a payment on a RealWorldReceivable given a tokenId of the receivable.
|
|
19
19
|
*
|
|
20
20
|
* @async
|
|
21
21
|
* @function
|
|
22
22
|
* @memberof ReceivableService
|
|
23
23
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
24
|
-
* @param {BigNumberish} receivableTokenId - The
|
|
24
|
+
* @param {BigNumberish} receivableTokenId - The Id of the receivable token to pay.
|
|
25
25
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
26
26
|
* @param {Overrides} [gasOpts] - The gas options to use for the transaction.
|
|
27
27
|
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
@@ -56,14 +56,14 @@ declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, po
|
|
|
56
56
|
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
57
57
|
* from server calls.
|
|
58
58
|
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
59
|
-
* @param {number} chainId - The chain
|
|
59
|
+
* @param {number} chainId - The chain Id to mint the receivable token on and pay ARWeave funds from.
|
|
60
60
|
* @param {string} recipient - The receivable token recipient.
|
|
61
61
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
62
62
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
63
63
|
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
64
64
|
* @param {number} receivableAmount - The receivable amount.
|
|
65
65
|
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
66
|
-
* @param {
|
|
66
|
+
* @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
67
67
|
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
68
68
|
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
69
69
|
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
@@ -72,10 +72,25 @@ declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, po
|
|
|
72
72
|
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
73
73
|
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
74
74
|
*/
|
|
75
|
-
declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, metadata:
|
|
75
|
+
declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, metadata: Record<string, unknown>, referenceId: string, extraTags: {
|
|
76
76
|
name: string;
|
|
77
77
|
value: string;
|
|
78
78
|
}[], lazyFund?: boolean, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
81
|
+
*
|
|
82
|
+
* @async
|
|
83
|
+
* @function
|
|
84
|
+
* @memberof ReceivableService
|
|
85
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
86
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
87
|
+
* from server calls.
|
|
88
|
+
* @param {string} owner - The receivable token owner to query from.
|
|
89
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
90
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
91
|
+
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
92
|
+
*/
|
|
93
|
+
declare function loadReceivablesOfOwnerWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<RealWorldReceivableInfo[]>;
|
|
79
94
|
/**
|
|
80
95
|
* An object that contains functions to interact with Huma's receivables.
|
|
81
96
|
* @namespace ReceivableService
|
|
@@ -85,5 +100,6 @@ export declare const ReceivableService: {
|
|
|
85
100
|
createReceivable: typeof createReceivable;
|
|
86
101
|
declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
|
|
87
102
|
declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
|
|
103
|
+
loadReceivablesOfOwnerWithMetadata: typeof loadReceivablesOfOwnerWithMetadata;
|
|
88
104
|
};
|
|
89
105
|
export {};
|
|
@@ -3,33 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReceivableService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const providers_1 = require("@ethersproject/providers");
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
6
7
|
const shared_1 = require("@huma-finance/shared");
|
|
7
8
|
const graphql_request_1 = tslib_1.__importStar(require("graphql-request"));
|
|
8
9
|
const ARWeaveService_1 = require("./ARWeaveService");
|
|
9
10
|
const helpers_1 = require("../helpers");
|
|
10
11
|
const utils_1 = require("../utils");
|
|
11
12
|
/**
|
|
12
|
-
* Declares a payment on a RealWorldReceivable given a reference
|
|
13
|
+
* Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
|
|
13
14
|
*
|
|
14
15
|
* @async
|
|
15
16
|
* @function
|
|
16
17
|
* @memberof ReceivableService
|
|
17
|
-
* @param {ethers.Signer} signer - The signer used to
|
|
18
|
-
* @param {string}
|
|
19
|
-
* @
|
|
20
|
-
* @param {Overrides} [gasOpts] - The gas options to use for the transaction.
|
|
21
|
-
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
18
|
+
* @param {ethers.Signer} signer - The signer used to lookup metadata uploads for
|
|
19
|
+
* @param {string} arweaveId - The internal ARWeave identifier to lookup a token by
|
|
20
|
+
* @returns {Promise<string | null | undefined>} - Either the token Id or null if no token was found.
|
|
22
21
|
*/
|
|
23
|
-
async function
|
|
22
|
+
async function getTokenIdByARWeaveId(signer, arweaveId) {
|
|
24
23
|
var _a, _b, _c;
|
|
24
|
+
if (arweaveId === null) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
25
27
|
const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
|
|
26
28
|
const signerAddress = await signer.getAddress();
|
|
27
29
|
if (!chainId) {
|
|
28
|
-
throw new Error('No Chain
|
|
30
|
+
throw new Error('No Chain Id found');
|
|
29
31
|
}
|
|
30
|
-
//
|
|
31
|
-
const dataID = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
|
|
32
|
-
// Fetch receivables with the same ARWeave ID
|
|
32
|
+
// Fetch receivables with the same ARWeave Id
|
|
33
33
|
const receivablesQuery = (0, graphql_request_1.gql) `
|
|
34
34
|
query ReceivablesByURIQuery($owner: String!, $uri: String!) {
|
|
35
35
|
receivables(where: { owner: $owner, uri: $uri }) {
|
|
@@ -41,40 +41,65 @@ async function declareReceivablePaymentByReferenceId(signer, referenceId, paymen
|
|
|
41
41
|
tokenId
|
|
42
42
|
}
|
|
43
43
|
`;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
receivableSubgraph = `https://api.thegraph.com/subgraphs/name/00labs/huma-receivables-goerli`;
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
throw new Error('No receivable subgraph exists for this chain');
|
|
44
|
+
const receivableSubgraph = shared_1.PoolSubgraphMap[chainId].receivablesSubgraph;
|
|
45
|
+
if (!receivableSubgraph) {
|
|
46
|
+
throw new Error('No receivable subgraph exists for this chain');
|
|
51
47
|
}
|
|
52
48
|
const receivablesData = await (0, graphql_request_1.default)(receivableSubgraph, receivablesQuery, {
|
|
53
49
|
owner: signerAddress,
|
|
54
|
-
uri: `https://arweave.net/${
|
|
50
|
+
uri: `https://arweave.net/${arweaveId}`,
|
|
55
51
|
});
|
|
56
|
-
if (!(
|
|
57
|
-
|
|
52
|
+
if (!((_a = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
53
|
+
console.log('No receivables found with this ARWeave Id.');
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length) > 1) {
|
|
57
|
+
console.log(`This owner has multiple receivables with the same ARWeave URI, so we don't know which to use. Please burn
|
|
58
|
+
unnecessary receivables or pay the correct token manually using declareReceivablePaymentByTokenId`);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return (_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _c === void 0 ? void 0 : _c.tokenId;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
|
|
65
|
+
*
|
|
66
|
+
* @async
|
|
67
|
+
* @function
|
|
68
|
+
* @memberof ReceivableService
|
|
69
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
70
|
+
* @param {string} referenceId - An internal identifier value added as a tag on ARWeave
|
|
71
|
+
* @param {number} paymentAmount - The amount to declare paid to the receivable.
|
|
72
|
+
* @param {Overrides} [gasOpts] - The gas options to use for the transaction.
|
|
73
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
74
|
+
*/
|
|
75
|
+
async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount, gasOpts = {}) {
|
|
76
|
+
const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
|
|
77
|
+
const signerAddress = await signer.getAddress();
|
|
78
|
+
if (!chainId) {
|
|
79
|
+
throw new Error('No Chain Id found');
|
|
58
80
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
// Get ARWeave Id
|
|
82
|
+
const dataId = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
|
|
83
|
+
// Fetch receivables with the same ARWeave Id
|
|
84
|
+
const tokenId = await getTokenIdByARWeaveId(signer, dataId);
|
|
85
|
+
if (tokenId == null) {
|
|
86
|
+
throw new Error('Could not find tokenId for this ARWeave Id. Please check your logs for more details.');
|
|
62
87
|
}
|
|
63
88
|
const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
|
|
64
89
|
if (!contract) {
|
|
65
90
|
throw new Error('Could not find RealWorldReceivable contract');
|
|
66
91
|
}
|
|
67
92
|
gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
|
|
68
|
-
return contract.declarePayment(
|
|
93
|
+
return contract.declarePayment(tokenId, paymentAmount, gasOpts);
|
|
69
94
|
}
|
|
70
95
|
/**
|
|
71
|
-
* Declares a payment on a RealWorldReceivable given a
|
|
96
|
+
* Declares a payment on a RealWorldReceivable given a tokenId of the receivable.
|
|
72
97
|
*
|
|
73
98
|
* @async
|
|
74
99
|
* @function
|
|
75
100
|
* @memberof ReceivableService
|
|
76
101
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
77
|
-
* @param {BigNumberish} receivableTokenId - The
|
|
102
|
+
* @param {BigNumberish} receivableTokenId - The Id of the receivable token to pay.
|
|
78
103
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
79
104
|
* @param {Overrides} [gasOpts] - The gas options to use for the transaction.
|
|
80
105
|
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
@@ -84,7 +109,7 @@ async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paym
|
|
|
84
109
|
var _a;
|
|
85
110
|
const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
|
|
86
111
|
if (!chainId) {
|
|
87
|
-
throw new Error('No Chain
|
|
112
|
+
throw new Error('No Chain Id found');
|
|
88
113
|
}
|
|
89
114
|
const realWorldReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable];
|
|
90
115
|
if (!realWorldReceivable) {
|
|
@@ -118,7 +143,7 @@ async function createReceivable(signer, poolName, poolType, currencyCode, receiv
|
|
|
118
143
|
var _a, _b;
|
|
119
144
|
const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
|
|
120
145
|
if (!chainId) {
|
|
121
|
-
throw new Error('No Chain
|
|
146
|
+
throw new Error('No Chain Id found');
|
|
122
147
|
}
|
|
123
148
|
const poolInfo = chainId
|
|
124
149
|
? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
|
|
@@ -143,14 +168,14 @@ async function createReceivable(signer, poolName, poolType, currencyCode, receiv
|
|
|
143
168
|
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
144
169
|
* from server calls.
|
|
145
170
|
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
146
|
-
* @param {number} chainId - The chain
|
|
171
|
+
* @param {number} chainId - The chain Id to mint the receivable token on and pay ARWeave funds from.
|
|
147
172
|
* @param {string} recipient - The receivable token recipient.
|
|
148
173
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
149
174
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
150
175
|
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
151
176
|
* @param {number} receivableAmount - The receivable amount.
|
|
152
177
|
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
153
|
-
* @param {
|
|
178
|
+
* @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
154
179
|
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
155
180
|
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
156
181
|
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
@@ -160,27 +185,118 @@ async function createReceivable(signer, poolName, poolType, currencyCode, receiv
|
|
|
160
185
|
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
161
186
|
*/
|
|
162
187
|
async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
|
|
188
|
+
if (typeof metadata !== 'object' || Array.isArray(metadata)) {
|
|
189
|
+
throw new Error('Input must be a JSON object.');
|
|
190
|
+
}
|
|
163
191
|
const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
|
|
164
192
|
try {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{ name: 'appName', value: 'HumaFinance' },
|
|
168
|
-
{ name: 'poolName', value: poolName },
|
|
169
|
-
{ name: 'poolType', value: poolType },
|
|
170
|
-
{ name: 'referenceId', value: referenceId },
|
|
171
|
-
...extraTags,
|
|
172
|
-
];
|
|
173
|
-
const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
|
|
174
|
-
console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
|
|
175
|
-
return await createReceivable(signerOrProvider instanceof providers_1.Web3Provider
|
|
193
|
+
// Check to see if metadata with referenceId has already been minted
|
|
194
|
+
const signer = signerOrProvider instanceof providers_1.Web3Provider
|
|
176
195
|
? signerOrProvider.getSigner()
|
|
177
|
-
: signerOrProvider
|
|
196
|
+
: signerOrProvider;
|
|
197
|
+
const signerAddress = await signer.getAddress();
|
|
198
|
+
const dataId = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
|
|
199
|
+
let arweaveId;
|
|
200
|
+
if (dataId != null) {
|
|
201
|
+
// If there already exists metadata with this reference Id, check if there exists
|
|
202
|
+
// a token with that ARWeave Id as metadata.
|
|
203
|
+
const tokenId = await getTokenIdByARWeaveId(signer, dataId);
|
|
204
|
+
if (tokenId == null) {
|
|
205
|
+
console.log(`Reusing existing metadata ${dataId} to mint new receivable`);
|
|
206
|
+
arweaveId = dataId;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
throw new Error('A token already exists with this reference Id, canceling mint');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const tags = [
|
|
214
|
+
{ name: 'Content-Type', value: 'application/json' },
|
|
215
|
+
{ name: 'appName', value: 'HumaFinance' },
|
|
216
|
+
{ name: 'poolName', value: poolName },
|
|
217
|
+
{ name: 'poolType', value: poolType },
|
|
218
|
+
{ name: 'referenceId', value: referenceId },
|
|
219
|
+
...extraTags,
|
|
220
|
+
];
|
|
221
|
+
// Append referenceId to metadata (if it's not already there)
|
|
222
|
+
if (!Object.prototype.hasOwnProperty.call(metadata, 'referenceId')) {
|
|
223
|
+
metadata.referenceId = referenceId;
|
|
224
|
+
}
|
|
225
|
+
const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider
|
|
226
|
+
? signerOrProvider
|
|
227
|
+
: privateKey, metadata, tags, lazyFund);
|
|
228
|
+
arweaveId = response.id;
|
|
229
|
+
console.log(`Data uploaded ==> https://arweave.net/${arweaveId}`);
|
|
230
|
+
}
|
|
231
|
+
return await createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${arweaveId}`, gasOpts);
|
|
178
232
|
}
|
|
179
233
|
catch (e) {
|
|
180
234
|
console.error(e);
|
|
181
235
|
throw e;
|
|
182
236
|
}
|
|
183
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
240
|
+
*
|
|
241
|
+
* @async
|
|
242
|
+
* @function
|
|
243
|
+
* @memberof ReceivableService
|
|
244
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
245
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
246
|
+
* from server calls.
|
|
247
|
+
* @param {string} owner - The receivable token owner to query from.
|
|
248
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
249
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
250
|
+
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
251
|
+
*/
|
|
252
|
+
async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType) {
|
|
253
|
+
var _a, _b;
|
|
254
|
+
if (!ethers_1.ethers.utils.isAddress(owner)) {
|
|
255
|
+
throw new Error('Invalid owner address');
|
|
256
|
+
}
|
|
257
|
+
const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signerOrProvider);
|
|
258
|
+
if (!chainId) {
|
|
259
|
+
throw new Error('No Chain Id found');
|
|
260
|
+
}
|
|
261
|
+
const poolInfo = chainId
|
|
262
|
+
? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
|
|
263
|
+
: undefined;
|
|
264
|
+
if (!poolInfo) {
|
|
265
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
266
|
+
}
|
|
267
|
+
const rwrContract = (0, helpers_1.getRealWorldReceivableContract)(signerOrProvider, chainId);
|
|
268
|
+
if (!rwrContract) {
|
|
269
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
270
|
+
}
|
|
271
|
+
// Load all receivables of owner
|
|
272
|
+
const balance = await rwrContract.balanceOf(owner);
|
|
273
|
+
// Create empty array with length of balance
|
|
274
|
+
const tokens = Array.from(Array(balance.toNumber()));
|
|
275
|
+
const fetchPromises = tokens.map(async (_, tokenIndex) => {
|
|
276
|
+
const tokenId = await rwrContract.tokenOfOwnerByIndex(owner, tokenIndex);
|
|
277
|
+
const rwrInfo = await rwrContract.rwrInfoMapping(tokenId);
|
|
278
|
+
// If a RWR uploaded by an owner is not for this specific pool, skip it
|
|
279
|
+
if (rwrInfo.poolAddress.toLowerCase() !== poolInfo.pool.toLowerCase()) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const tokenURI = await rwrContract.tokenURI(tokenId);
|
|
283
|
+
const metadata = await ARWeaveService_1.ARWeaveService.fetchMetadataFromUrl(tokenURI);
|
|
284
|
+
return {
|
|
285
|
+
tokenId,
|
|
286
|
+
poolAddress: rwrInfo.poolAddress,
|
|
287
|
+
receivableAmount: rwrInfo.receivableAmount,
|
|
288
|
+
paidAmount: rwrInfo.paidAmount,
|
|
289
|
+
creationDate: rwrInfo.creationDate,
|
|
290
|
+
maturityDate: rwrInfo.maturityDate,
|
|
291
|
+
currencyCode: rwrInfo.currencyCode,
|
|
292
|
+
tokenURI,
|
|
293
|
+
metadata,
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
const tokenData = await Promise.all(fetchPromises);
|
|
297
|
+
// Filter undefined
|
|
298
|
+
return tokenData.filter((token) => token !== undefined);
|
|
299
|
+
}
|
|
184
300
|
/**
|
|
185
301
|
* An object that contains functions to interact with Huma's receivables.
|
|
186
302
|
* @namespace ReceivableService
|
|
@@ -190,5 +306,6 @@ exports.ReceivableService = {
|
|
|
190
306
|
createReceivable,
|
|
191
307
|
declareReceivablePaymentByTokenId,
|
|
192
308
|
declareReceivablePaymentByReferenceId,
|
|
309
|
+
loadReceivablesOfOwnerWithMetadata,
|
|
193
310
|
};
|
|
194
311
|
//# sourceMappingURL=ReceivableService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;;AAAA,wDAA4E;
|
|
1
|
+
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;;AAAA,wDAA4E;AAC5E,mCAAwD;AACxD,iDAQ6B;AAC7B,2EAA8C;AAE9C,qDAAiD;AACjD,wCAA2D;AAC3D,oCAA+E;AAG/E;;;;;;;;;GASG;AACH,KAAK,UAAU,qBAAqB,CAClC,MAAqB,EACrB,SAAwB;;IAExB,IAAI,SAAS,KAAK,IAAI,EAAE;QACtB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;IAE/C,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,6CAA6C;IAC7C,MAAM,gBAAgB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;GAU3B,CAAA;IAED,MAAM,kBAAkB,GAAG,wBAAe,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAA;IACvE,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;IAED,MAAM,eAAe,GAAkC,MAAM,IAAA,yBAAO,EAClE,kBAAkB,EAClB,gBAAgB,EAChB;QACE,KAAK,EAAE,aAAa;QACpB,GAAG,EAAE,uBAAuB,SAAS,EAAE;KACxC,CACF,CAAA;IAED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AK,KAAK,SAAS,CACF,CAAA;AAChC,CAAC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG;IAC/B,4BAA4B;IAC5B,gBAAgB;IAChB,iCAAiC;IACjC,qCAAqC;IACrC,kCAAkC;CACnC,CAAA"}
|
|
@@ -59,13 +59,13 @@ declare function prefundBundlr(config: BundlrConfig, signer: string, amount: num
|
|
|
59
59
|
* @param {Web3Provider | string} signerOrPrivateKey - Wallet object used for interacting with the Bundlr instance.
|
|
60
60
|
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
61
61
|
* environment, this should be a private key string.
|
|
62
|
-
* @param {
|
|
62
|
+
* @param {Record<string, unknown>} data - The data to store in the Bundlr instance.
|
|
63
63
|
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
64
64
|
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
65
65
|
* Bundlr node should already be funded or else uploads will fail.
|
|
66
66
|
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
67
67
|
*/
|
|
68
|
-
declare function storeData(config: BundlrConfig, signerOrPrivateKey: Web3Provider | string, data:
|
|
68
|
+
declare function storeData(config: BundlrConfig, signerOrPrivateKey: Web3Provider | string, data: Record<string, unknown>, tags: {
|
|
69
69
|
name: string;
|
|
70
70
|
value: string;
|
|
71
71
|
}[], lazyFund?: boolean): Promise<UploadResponse>;
|
|
@@ -81,6 +81,16 @@ declare function storeData(config: BundlrConfig, signerOrPrivateKey: Web3Provide
|
|
|
81
81
|
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
82
82
|
*/
|
|
83
83
|
declare function queryForMetadata(chainId: number, sender: string, referenceId: string): Promise<string | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Helper method to fetch data from an ARWeave URL.
|
|
86
|
+
*
|
|
87
|
+
* @async
|
|
88
|
+
* @function
|
|
89
|
+
* @memberof ArweaveService
|
|
90
|
+
* @param {string} url - The ARWeave metadata URL to query.
|
|
91
|
+
* @returns {Promise<JSON>} Promise resolving with the queried data.
|
|
92
|
+
*/
|
|
93
|
+
declare function fetchMetadataFromUrl(url: string): Promise<JSON | null>;
|
|
84
94
|
/**
|
|
85
95
|
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
86
96
|
* @namespace ARWeaveService
|
|
@@ -91,5 +101,6 @@ export declare const ARWeaveService: {
|
|
|
91
101
|
prefundBundlr: typeof prefundBundlr;
|
|
92
102
|
getBundlrNetworkConfig: typeof getBundlrNetworkConfig;
|
|
93
103
|
getBundlrInstance: typeof getBundlrInstance;
|
|
104
|
+
fetchMetadataFromUrl: typeof fetchMetadataFromUrl;
|
|
94
105
|
};
|
|
95
106
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Bundlr from '@bundlr-network/client';
|
|
2
|
+
import axios from 'axios';
|
|
2
3
|
import request, { gql } from 'graphql-request';
|
|
3
4
|
/**
|
|
4
5
|
* Get the configuration for Bundlr network given a chain ID
|
|
@@ -89,7 +90,7 @@ signer, amount) {
|
|
|
89
90
|
* @param {Web3Provider | string} signerOrPrivateKey - Wallet object used for interacting with the Bundlr instance.
|
|
90
91
|
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
91
92
|
* environment, this should be a private key string.
|
|
92
|
-
* @param {
|
|
93
|
+
* @param {Record<string, unknown>} data - The data to store in the Bundlr instance.
|
|
93
94
|
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
94
95
|
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
95
96
|
* Bundlr node should already be funded or else uploads will fail.
|
|
@@ -151,6 +152,25 @@ async function queryForMetadata(chainId, sender, referenceId) {
|
|
|
151
152
|
});
|
|
152
153
|
return (_d = (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.transactions) === null || _a === void 0 ? void 0 : _a.edges) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.node) === null || _d === void 0 ? void 0 : _d.id;
|
|
153
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Helper method to fetch data from an ARWeave URL.
|
|
157
|
+
*
|
|
158
|
+
* @async
|
|
159
|
+
* @function
|
|
160
|
+
* @memberof ArweaveService
|
|
161
|
+
* @param {string} url - The ARWeave metadata URL to query.
|
|
162
|
+
* @returns {Promise<JSON>} Promise resolving with the queried data.
|
|
163
|
+
*/
|
|
164
|
+
async function fetchMetadataFromUrl(url) {
|
|
165
|
+
try {
|
|
166
|
+
const response = await axios.get(url);
|
|
167
|
+
return response.data;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error('Error fetching data:', error);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
154
174
|
/**
|
|
155
175
|
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
156
176
|
* @namespace ARWeaveService
|
|
@@ -161,5 +181,6 @@ export const ARWeaveService = {
|
|
|
161
181
|
prefundBundlr,
|
|
162
182
|
getBundlrNetworkConfig,
|
|
163
183
|
getBundlrInstance,
|
|
184
|
+
fetchMetadataFromUrl,
|
|
164
185
|
};
|
|
165
186
|
//# sourceMappingURL=ARWeaveService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../src/services/ARWeaveService.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAM3C,OAAO,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAkB9C;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC,EAAE,SAAS;YACf,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,UAAU;gBACpB,WAAW,EACT,8DAA8D;aACjE,CAAA;QACH,KAAK,KAA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U,SAAS,CACtB,MAAoB,EACpB,kBAAyC,EACzC,
|
|
1
|
+
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../src/services/ARWeaveService.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAM3C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAkB9C;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC,EAAE,SAAS;YACf,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,UAAU;gBACpB,WAAW,EACT,8DAA8D;aACjE,CAAA;QACH,KAAK,KAAK,EAAE,SAAS;YACnB,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,OAAO;gBACjB,WAAW,EAAE,qCAAqC;aACnD,CAAA;QACH,KAAK,GAAG,EAAE,QAAQ;YAChB,OAAO;gBACL,OAAO,EAAE,8BAA8B;gBACvC,QAAQ,EAAE,OAAO;aAClB,CAAA;QACH;YACE,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;aACb,CAAA;KACJ;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,KAAK,UAAU,iBAAiB,CAAC,MAAoB,EAAE,MAAc;IACnE,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,MAAM,EACN,MAAM,CAAC,WAAW;QAChB,CAAC,CAAC;YACE,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC;QACH,CAAC,CAAC,SAAS,CACd,CAAA;IACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IAEpB,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,aAAa,CAC1B,MAA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
2
|
import { BigNumberish, ethers, Overrides } from 'ethers';
|
|
3
|
-
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
3
|
+
import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfo } from '@huma-finance/shared';
|
|
4
4
|
/**
|
|
5
|
-
* Declares a payment on a RealWorldReceivable given a reference
|
|
5
|
+
* Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
|
|
6
6
|
*
|
|
7
7
|
* @async
|
|
8
8
|
* @function
|
|
@@ -15,13 +15,13 @@ import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
|
15
15
|
*/
|
|
16
16
|
declare function declareReceivablePaymentByReferenceId(signer: ethers.Signer, referenceId: string, paymentAmount: number, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
17
17
|
/**
|
|
18
|
-
* Declares a payment on a RealWorldReceivable given a
|
|
18
|
+
* Declares a payment on a RealWorldReceivable given a tokenId of the receivable.
|
|
19
19
|
*
|
|
20
20
|
* @async
|
|
21
21
|
* @function
|
|
22
22
|
* @memberof ReceivableService
|
|
23
23
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
24
|
-
* @param {BigNumberish} receivableTokenId - The
|
|
24
|
+
* @param {BigNumberish} receivableTokenId - The Id of the receivable token to pay.
|
|
25
25
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
26
26
|
* @param {Overrides} [gasOpts] - The gas options to use for the transaction.
|
|
27
27
|
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
@@ -56,14 +56,14 @@ declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, po
|
|
|
56
56
|
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
57
57
|
* from server calls.
|
|
58
58
|
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
59
|
-
* @param {number} chainId - The chain
|
|
59
|
+
* @param {number} chainId - The chain Id to mint the receivable token on and pay ARWeave funds from.
|
|
60
60
|
* @param {string} recipient - The receivable token recipient.
|
|
61
61
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
62
62
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
63
63
|
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
64
64
|
* @param {number} receivableAmount - The receivable amount.
|
|
65
65
|
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
66
|
-
* @param {
|
|
66
|
+
* @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
67
67
|
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
68
68
|
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
69
69
|
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
@@ -72,10 +72,25 @@ declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, po
|
|
|
72
72
|
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
73
73
|
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
74
74
|
*/
|
|
75
|
-
declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, metadata:
|
|
75
|
+
declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, metadata: Record<string, unknown>, referenceId: string, extraTags: {
|
|
76
76
|
name: string;
|
|
77
77
|
value: string;
|
|
78
78
|
}[], lazyFund?: boolean, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
81
|
+
*
|
|
82
|
+
* @async
|
|
83
|
+
* @function
|
|
84
|
+
* @memberof ReceivableService
|
|
85
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
86
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
87
|
+
* from server calls.
|
|
88
|
+
* @param {string} owner - The receivable token owner to query from.
|
|
89
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
90
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
91
|
+
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
92
|
+
*/
|
|
93
|
+
declare function loadReceivablesOfOwnerWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<RealWorldReceivableInfo[]>;
|
|
79
94
|
/**
|
|
80
95
|
* An object that contains functions to interact with Huma's receivables.
|
|
81
96
|
* @namespace ReceivableService
|
|
@@ -85,5 +100,6 @@ export declare const ReceivableService: {
|
|
|
85
100
|
createReceivable: typeof createReceivable;
|
|
86
101
|
declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
|
|
87
102
|
declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
|
|
103
|
+
loadReceivablesOfOwnerWithMetadata: typeof loadReceivablesOfOwnerWithMetadata;
|
|
88
104
|
};
|
|
89
105
|
export {};
|