@huma-finance/sdk 0.0.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +9 -0
  4. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +21 -0
  5. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
  6. package/dist/cjs/helpers/index.d.ts +1 -0
  7. package/dist/cjs/helpers/index.js +5 -0
  8. package/dist/cjs/helpers/index.js.map +1 -0
  9. package/dist/cjs/hooks/index.d.ts +5 -0
  10. package/dist/cjs/hooks/index.js +9 -0
  11. package/dist/cjs/hooks/index.js.map +1 -0
  12. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +9 -0
  13. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +19 -0
  14. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
  15. package/dist/cjs/hooks/useContract.d.ts +11 -0
  16. package/dist/cjs/hooks/useContract.js +29 -0
  17. package/dist/cjs/hooks/useContract.js.map +1 -0
  18. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  19. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +24 -0
  20. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  21. package/dist/cjs/hooks/usePoolContract.d.ts +53 -0
  22. package/dist/cjs/hooks/usePoolContract.js +49 -0
  23. package/dist/cjs/hooks/usePoolContract.js.map +1 -0
  24. package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
  25. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +17 -0
  26. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +1 -0
  27. package/dist/cjs/index.d.ts +4 -0
  28. package/dist/cjs/index.js +8 -0
  29. package/dist/cjs/index.js.map +1 -0
  30. package/dist/cjs/services/ARWeaveService.d.ts +62 -0
  31. package/dist/cjs/services/ARWeaveService.js +141 -0
  32. package/dist/cjs/services/ARWeaveService.js.map +1 -0
  33. package/dist/cjs/services/EAService.d.ts +13 -0
  34. package/dist/cjs/services/EAService.js +17 -0
  35. package/dist/cjs/services/EAService.js.map +1 -0
  36. package/dist/cjs/services/ReceivableService.d.ts +76 -0
  37. package/dist/cjs/services/ReceivableService.js +156 -0
  38. package/dist/cjs/services/ReceivableService.js.map +1 -0
  39. package/dist/cjs/services/SubgraphService.d.ts +39 -0
  40. package/dist/cjs/services/SubgraphService.js +92 -0
  41. package/dist/cjs/services/SubgraphService.js.map +1 -0
  42. package/dist/cjs/services/index.d.ts +4 -0
  43. package/dist/cjs/services/index.js +8 -0
  44. package/dist/cjs/services/index.js.map +1 -0
  45. package/dist/cjs/utils/chain.d.ts +14 -0
  46. package/dist/cjs/utils/chain.js +34 -0
  47. package/dist/cjs/utils/chain.js.map +1 -0
  48. package/dist/cjs/utils/index.d.ts +3 -0
  49. package/dist/cjs/utils/index.js +7 -0
  50. package/dist/cjs/utils/index.js.map +1 -0
  51. package/dist/cjs/utils/poolInfo.d.ts +9 -0
  52. package/dist/cjs/utils/poolInfo.js +14 -0
  53. package/dist/cjs/utils/poolInfo.js.map +1 -0
  54. package/dist/cjs/utils/web3.d.ts +4 -0
  55. package/dist/cjs/utils/web3.js +29 -0
  56. package/dist/cjs/utils/web3.js.map +1 -0
  57. package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +9 -0
  58. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +17 -0
  59. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
  60. package/dist/helpers/index.d.ts +1 -0
  61. package/dist/helpers/index.js +2 -0
  62. package/dist/helpers/index.js.map +1 -0
  63. package/dist/hooks/index.d.ts +5 -0
  64. package/dist/hooks/index.js +6 -0
  65. package/dist/hooks/index.js.map +1 -0
  66. package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +9 -0
  67. package/dist/hooks/useBaseCreditPoolReceivableContract.js +15 -0
  68. package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
  69. package/dist/hooks/useContract.d.ts +11 -0
  70. package/dist/hooks/useContract.js +25 -0
  71. package/dist/hooks/useContract.js.map +1 -0
  72. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  73. package/dist/hooks/useERC20TransferableReceivableContract.js +20 -0
  74. package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  75. package/dist/hooks/usePool.d.ts +0 -0
  76. package/dist/hooks/usePool.js +2 -0
  77. package/dist/hooks/usePool.js.map +1 -0
  78. package/dist/hooks/usePoolContract.d.ts +53 -0
  79. package/dist/hooks/usePoolContract.js +44 -0
  80. package/dist/hooks/usePoolContract.js.map +1 -0
  81. package/dist/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
  82. package/dist/hooks/useReceivableFactoringPoolContract.js +13 -0
  83. package/dist/hooks/useReceivableFactoringPoolContract.js.map +1 -0
  84. package/dist/index.d.ts +4 -0
  85. package/dist/index.js +5 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/services/ARWeaveService.d.ts +62 -0
  88. package/dist/services/ARWeaveService.js +133 -0
  89. package/dist/services/ARWeaveService.js.map +1 -0
  90. package/dist/services/EAService.d.ts +13 -0
  91. package/dist/services/EAService.js +14 -0
  92. package/dist/services/EAService.js.map +1 -0
  93. package/dist/services/ReceivableService.d.ts +76 -0
  94. package/dist/services/ReceivableService.js +149 -0
  95. package/dist/services/ReceivableService.js.map +1 -0
  96. package/dist/services/SubgraphService.d.ts +39 -0
  97. package/dist/services/SubgraphService.js +86 -0
  98. package/dist/services/SubgraphService.js.map +1 -0
  99. package/dist/services/index.d.ts +4 -0
  100. package/dist/services/index.js +5 -0
  101. package/dist/services/index.js.map +1 -0
  102. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  103. package/dist/utils/chain.d.ts +14 -0
  104. package/dist/utils/chain.js +29 -0
  105. package/dist/utils/chain.js.map +1 -0
  106. package/dist/utils/index.d.ts +3 -0
  107. package/dist/utils/index.js +4 -0
  108. package/dist/utils/index.js.map +1 -0
  109. package/dist/utils/poolInfo.d.ts +9 -0
  110. package/dist/utils/poolInfo.js +10 -0
  111. package/dist/utils/poolInfo.js.map +1 -0
  112. package/dist/utils/web3.d.ts +4 -0
  113. package/dist/utils/web3.js +24 -0
  114. package/dist/utils/web3.js.map +1 -0
  115. package/package.json +86 -0
@@ -0,0 +1,149 @@
1
+ import { Web3Provider, } from '@ethersproject/providers';
2
+ import { BASE_CREDIT_POOL_RECEIVABLE_ABI, PoolContractMap, SupplementaryContracts, SupplementaryContractsMap, } from '@00labs/huma-shared';
3
+ import { getContract } from '../utils';
4
+ import { storeData, getBundlrNetworkConfig } from './ARWeaveService';
5
+ import { getChainIdFromSignerOrProvider } from '../utils/chain';
6
+ /**
7
+ * Enumeration of payment methods. Maps to the PaymentMethod enum in the BaseCreditPoolReceivable contract.
8
+ * Declarative payment methods are those that do not actually send ERC20 funds. Payable payment methods are those that
9
+ * do by calling makePayment on the BaseCreditPool contract.
10
+ * @enum {number}
11
+ */
12
+ export var PaymentMethod;
13
+ (function (PaymentMethod) {
14
+ PaymentMethod[PaymentMethod["Declarative"] = 0] = "Declarative";
15
+ PaymentMethod[PaymentMethod["Payable"] = 1] = "Payable";
16
+ })(PaymentMethod || (PaymentMethod = {}));
17
+ /**
18
+ * Pays a BaseCreditPoolReceivable using the specified payment method, given an internalId mapping to the receivable's metadata
19
+ *
20
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
21
+ * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
22
+ * @param {number} paymentAmount - The amount to pay the receivable.
23
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
24
+ * @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
25
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
26
+ */
27
+ export async function payReceivableByInternalId(
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ signer,
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ internalId,
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ paymentAmount,
34
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
35
+ paymentMethod) {
36
+ throw new Error('Not implemented');
37
+ }
38
+ /**
39
+ * Pays a BaseCreditPoolReceivable using the specified payment method, given a tokenID of the receivable.
40
+ *
41
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
42
+ * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
43
+ * @param {number} paymentAmount - The amount to pay the receivable.
44
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
45
+ * @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
46
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
47
+ */
48
+ export async function payReceivableByTokenId(signer, receivableTokenId, paymentAmount, paymentMethod) {
49
+ var _a;
50
+ const chainId = await getChainIdFromSignerOrProvider(signer);
51
+ const baseCreditPoolReceivable = chainId
52
+ ? (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.BaseCreditPoolReceivable]
53
+ : null;
54
+ if (!baseCreditPoolReceivable) {
55
+ throw new Error('BaseCreditPoolReceivable is not available on this network');
56
+ }
57
+ const contract = getContract(baseCreditPoolReceivable, BASE_CREDIT_POOL_RECEIVABLE_ABI, signer);
58
+ if (!contract) {
59
+ throw new Error('Could not find BaseCreditPoolReceivable contract');
60
+ }
61
+ let tx;
62
+ switch (paymentMethod) {
63
+ case PaymentMethod.Declarative:
64
+ tx = await contract.declarePayment(receivableTokenId, paymentAmount);
65
+ break;
66
+ case PaymentMethod.Payable:
67
+ tx = await contract.makePayment(receivableTokenId, paymentAmount);
68
+ break;
69
+ default:
70
+ throw new Error('Invalid payment method');
71
+ }
72
+ return tx.wait();
73
+ }
74
+ /**
75
+ * Mints a new BaseCreditPoolReceivable token on the given chain of the signer
76
+ *
77
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
78
+ * @param {string} recipient - The address of the recipient of the receivable token.
79
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
80
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
81
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
82
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
83
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
84
+ * @param {string} uri - The URI of the receivable token metadata.
85
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
86
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
87
+ */
88
+ export async function mintReceivable(signer, recipient, poolName, poolType, receivableAmount, maturityDate, paymentMethod, uri) {
89
+ var _a, _b, _c;
90
+ const chainId = await getChainIdFromSignerOrProvider(signer);
91
+ const baseCreditPoolReceivable = chainId
92
+ ? (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.BaseCreditPoolReceivable]
93
+ : null;
94
+ const poolInfo = chainId
95
+ ? (_c = (_b = PoolContractMap[chainId]) === null || _b === void 0 ? void 0 : _b[poolType]) === null || _c === void 0 ? void 0 : _c[poolName]
96
+ : undefined;
97
+ if (!baseCreditPoolReceivable || !poolInfo) {
98
+ throw new Error('BaseCreditPoolReceivable is not available on this network');
99
+ }
100
+ const contract = getContract(baseCreditPoolReceivable, BASE_CREDIT_POOL_RECEIVABLE_ABI, signer);
101
+ if (!contract) {
102
+ throw new Error('Could not find BaseCreditPoolReceivable contract');
103
+ }
104
+ return contract.safeMint(recipient, poolInfo.pool, poolInfo.poolUnderlyingToken.address, receivableAmount, maturityDate, paymentMethod, uri);
105
+ }
106
+ /**
107
+ * Mints a BaseCreditPoolReceivable token with metadata uploaded onto ARWeave
108
+ *
109
+ * @param {Web3Provider | ethers.Signer} wallet - If calling this function from a browser, this function expects a Web3Provider.
110
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
111
+ * from server calls.
112
+ * @param {string} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
113
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
114
+ * @param {string} recipient - The receivable token recipient.
115
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
116
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
117
+ * @param {number} receivableAmount - The receivable amount.
118
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
119
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
120
+ * @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
121
+ * @param {number} internalId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
122
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
123
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
124
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
125
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
126
+ * @returns {Promise<TransactionReceipt>} - The transaction receipt.
127
+ */
128
+ export async function mintReceivableWithMetadata(wallet, privateKey, chainId, recipient, poolName, poolType, receivableAmount, maturityDate, paymentMethod, metadata, internalId, extraTags, lazyFund = true) {
129
+ const config = getBundlrNetworkConfig(chainId);
130
+ try {
131
+ const tags = [
132
+ { name: 'Content-Type', value: 'application/json' },
133
+ { name: 'appName', value: 'HumaFinance' },
134
+ { name: 'poolName', value: poolName },
135
+ { name: 'poolType', value: poolType },
136
+ { name: 'internalId', value: internalId },
137
+ ...extraTags,
138
+ ];
139
+ const response = await storeData(config, wallet instanceof Web3Provider ? wallet : privateKey, metadata, tags, lazyFund);
140
+ console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
141
+ const tx = await mintReceivable(wallet instanceof Web3Provider ? wallet.getSigner() : wallet, recipient, poolName, poolType, receivableAmount, maturityDate, paymentMethod, `https://arweave.net/${response.id}`);
142
+ return await tx.wait();
143
+ }
144
+ catch (e) {
145
+ console.error(e);
146
+ throw e;
147
+ }
148
+ }
149
+ //# sourceMappingURL=ReceivableService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../src/services/ReceivableService.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,GACb,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EACL,+BAA+B,EAG/B,eAAe,EACf,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,+DAAe,CAAA;IACf,uDAAW,CAAA;AACb,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB;AAC7C,6DAA6D;AAC7D,MAAqB;AACrB,6DAA6D;AAC7D,UAAkB;AAClB,6DAA6D;AAC7D,aAAqB;AACrB,6DAA6D;AAC7D,aAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAqB,EACrB,iBA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U,EAAE,KAAK,EAAE,QAAQ,EAAE;YACrC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE;YACzC,GAAG,SAAS;SACb,CAAA;QAED,MAAM,QAAQ,GAAG,MAAM,SAAS,CAC9B,MAAM,EACN,MAAM,YAAY,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,EACpD,QAAQ,EACR,IAAI,EACJ,QAAQ,CACT,CAAA;QACD,OAAO,CAAC,GAAG,CAAC,yCAAyC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAA;QAEnE,MAAM,EAAE,GAAG,MAAM,cAAc,CAC7B,MAAM,YAAY,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,MAAM,EAC5D,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,uBAAuB,QAAQ,CAAC,EAAE,EAAE,CACrC,CAAA;QAED,OAAO,MAAM,EAAE,CAAC,IAAI,EAAE,CAAA;KACvB;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,MAAM,CAAC,CAAA;KACR;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { POOL_NAME, POOL_TYPE } from '@00labs/huma-shared';
2
+ /**
3
+ * Returns the subgraph URL for a given chain ID.
4
+ *
5
+ * @param {number} chainId - The ID of the chain.
6
+ * @returns {string} The subgraph URL for the given chain ID.
7
+ */
8
+ export declare function getSubgraphUrlForChainId(chainId: number): string;
9
+ /**
10
+ * Represents the payload of a credit event.
11
+ */
12
+ export type CreditEventPayload = {
13
+ amount?: string;
14
+ timestamp?: string;
15
+ owner?: string;
16
+ pool?: string;
17
+ event?: string;
18
+ };
19
+ /**
20
+ * Returns the credit events for a given user.
21
+ *
22
+ * @param {string} userAddress - The address of the user.
23
+ * @param {number} chainId - The ID of the chain.
24
+ * @param {POOL_NAME} poolName - The name of the pool.
25
+ * @param {POOL_TYPE} poolType - The type of the pool.
26
+ * @param {string[]} event - The event types to filter by.
27
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
28
+ */
29
+ export declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: string[]): Promise<CreditEventPayload[]>;
30
+ /**
31
+ * Returns the last factorized amount for a given user and pool.
32
+ *
33
+ * @param {string} userAddress - The address of the user.
34
+ * @param {number} chainId - The ID of the chain.
35
+ * @param {POOL_NAME} poolName - The name of the pool.
36
+ * @param {POOL_TYPE} poolType - The type of the pool.
37
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
38
+ */
39
+ export declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
@@ -0,0 +1,86 @@
1
+ import { CreditEvent, PoolContractMap, } from '@00labs/huma-shared';
2
+ /**
3
+ * Returns the subgraph URL for a given chain ID.
4
+ *
5
+ * @param {number} chainId - The ID of the chain.
6
+ * @returns {string} The subgraph URL for the given chain ID.
7
+ */
8
+ export function getSubgraphUrlForChainId(chainId) {
9
+ switch (chainId) {
10
+ case 5:
11
+ return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
12
+ case 137:
13
+ return 'https://api.thegraph.com/subgraphs/name/00labs/huma-polygon';
14
+ case 80001:
15
+ return 'https://api.thegraph.com/subgraphs/name/00labs/huma-mumbai';
16
+ default:
17
+ return '';
18
+ }
19
+ }
20
+ /**
21
+ * Returns the credit events for a given user.
22
+ *
23
+ * @param {string} userAddress - The address of the user.
24
+ * @param {number} chainId - The ID of the chain.
25
+ * @param {POOL_NAME} poolName - The name of the pool.
26
+ * @param {POOL_TYPE} poolType - The type of the pool.
27
+ * @param {string[]} event - The event types to filter by.
28
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
29
+ */
30
+ export function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
31
+ var _a, _b, _c;
32
+ const url = getSubgraphUrlForChainId(chainId);
33
+ if (!url) {
34
+ return Promise.resolve([]);
35
+ }
36
+ const poolAddress = (_c = (_b = (_a = 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;
37
+ const query = `
38
+ query {
39
+ creditEvents(
40
+ where: {
41
+ owner: "${userAddress}",
42
+ pool: "${poolAddress}",
43
+ event_in: "[${event.join('", "')}]"
44
+ }
45
+ orderBy: timestamp
46
+ orderDirection: desc
47
+ ) {
48
+ amount
49
+ timestamp
50
+ owner
51
+ pool
52
+ event
53
+ }
54
+ }
55
+ `;
56
+ return fetch(url, {
57
+ method: 'POST',
58
+ headers: {
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ body: JSON.stringify({ query }),
62
+ })
63
+ .then((res) => res.json())
64
+ .then((res) => {
65
+ if (res.errors) {
66
+ console.error(res.errors);
67
+ return [];
68
+ }
69
+ return res.data.creditEvents;
70
+ });
71
+ }
72
+ /**
73
+ * Returns the last factorized amount for a given user and pool.
74
+ *
75
+ * @param {string} userAddress - The address of the user.
76
+ * @param {number} chainId - The ID of the chain.
77
+ * @param {POOL_NAME} poolName - The name of the pool.
78
+ * @param {POOL_TYPE} poolType - The type of the pool.
79
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
80
+ */
81
+ export function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
82
+ return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
83
+ CreditEvent.DrawdownMadeWithReceivable.toString(),
84
+ ]).then((events) => Number(events[0].amount));
85
+ }
86
+ //# sourceMappingURL=SubgraphService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubgraphService.js","sourceRoot":"","sources":["../../src/services/SubgraphService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,GAGhB,MAAM,qBAAqB,CAAA;A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A;IAC9B,CAAC,CAAC,CAAA;AACN,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,+BAA+B,CAC7C,WAAmB,EACnB,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,OAAO,sBAAsB,CAAC,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;QACtE,WAAW,CAAC,0BAA0B,CAAC,QAAQ,EAAE;KAClD,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAC/C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './ARWeaveService';
2
+ export * from './EAService';
3
+ export * from './SubgraphService';
4
+ export * from './ReceivableService';
@@ -0,0 +1,5 @@
1
+ export * from './ARWeaveService';
2
+ export * from './EAService';
3
+ export * from './SubgraphService';
4
+ export * from './ReceivableService';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}