@huma-finance/soroban-sdk 0.0.15-beta.33 → 0.0.15-beta.36

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 (51) hide show
  1. package/API.md +3 -21
  2. package/dist/cjs/helpers/CreditContractHelper.d.ts +3 -13
  3. package/dist/cjs/helpers/CreditContractHelper.js +107 -91
  4. package/dist/cjs/helpers/CreditContractHelper.js.map +1 -1
  5. package/dist/cjs/helpers/Sep41ContractHelper.d.ts +3 -3
  6. package/dist/cjs/helpers/Sep41ContractHelper.js +49 -18
  7. package/dist/cjs/helpers/Sep41ContractHelper.js.map +1 -1
  8. package/dist/cjs/services/StellarWallet.d.ts +3 -1
  9. package/dist/cjs/services/StellarWallet.js +10 -3
  10. package/dist/cjs/services/StellarWallet.js.map +1 -1
  11. package/dist/cjs/utils/client.d.ts +12 -3
  12. package/dist/cjs/utils/client.js +57 -3
  13. package/dist/cjs/utils/client.js.map +1 -1
  14. package/dist/cjs/utils/common.d.ts +14 -1
  15. package/dist/cjs/utils/common.js +41 -1
  16. package/dist/cjs/utils/common.js.map +1 -1
  17. package/dist/cjs/utils/index.d.ts +1 -0
  18. package/dist/cjs/utils/index.js +1 -0
  19. package/dist/cjs/utils/index.js.map +1 -1
  20. package/dist/cjs/utils/network.d.ts +4 -1
  21. package/dist/cjs/utils/network.js +18 -10
  22. package/dist/cjs/utils/network.js.map +1 -1
  23. package/dist/cjs/utils/transaction.d.ts +25 -0
  24. package/dist/cjs/utils/transaction.js +127 -0
  25. package/dist/cjs/utils/transaction.js.map +1 -0
  26. package/dist/helpers/CreditContractHelper.d.ts +3 -13
  27. package/dist/helpers/CreditContractHelper.js +106 -89
  28. package/dist/helpers/CreditContractHelper.js.map +1 -1
  29. package/dist/helpers/Sep41ContractHelper.d.ts +3 -3
  30. package/dist/helpers/Sep41ContractHelper.js +50 -19
  31. package/dist/helpers/Sep41ContractHelper.js.map +1 -1
  32. package/dist/services/StellarWallet.d.ts +3 -1
  33. package/dist/services/StellarWallet.js +10 -3
  34. package/dist/services/StellarWallet.js.map +1 -1
  35. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  36. package/dist/utils/client.d.ts +12 -3
  37. package/dist/utils/client.js +55 -2
  38. package/dist/utils/client.js.map +1 -1
  39. package/dist/utils/common.d.ts +14 -1
  40. package/dist/utils/common.js +40 -1
  41. package/dist/utils/common.js.map +1 -1
  42. package/dist/utils/index.d.ts +1 -0
  43. package/dist/utils/index.js +1 -0
  44. package/dist/utils/index.js.map +1 -1
  45. package/dist/utils/network.d.ts +4 -1
  46. package/dist/utils/network.js +18 -10
  47. package/dist/utils/network.js.map +1 -1
  48. package/dist/utils/transaction.d.ts +25 -0
  49. package/dist/utils/transaction.js +119 -0
  50. package/dist/utils/transaction.js.map +1 -0
  51. package/package.json +11 -11
package/API.md CHANGED
@@ -1,9 +1,6 @@
1
1
  ## Functions
2
2
 
3
3
  <dl>
4
- <dt><a href="#getCreditLineClient">getCreditLineClient(poolName, network, wallet)</a> ⇒ <code>PoolCreditClient</code> | <code>undefined</code></dt>
5
- <dd><p>Returns an soroban contract client instance for the credit line contract
6
- associated with the given pool name on the current chain.</p></dd>
7
4
  <dt><a href="#getAvailableBalanceForPool">getAvailableBalanceForPool(poolName, network, wallet)</a></dt>
8
5
  <dd><p>Returns the current pool balance available for borrowing</p></dd>
9
6
  <dt><a href="#getCreditRecordForPool">getCreditRecordForPool(poolName, network, wallet, borrower)</a></dt>
@@ -21,26 +18,11 @@ associated with the given pool name on the current chain.</p></dd>
21
18
  <dd><p>Draws down from a pool.</p></dd>
22
19
  <dt><a href="#makePayment">makePayment(poolName, network, wallet, paymentAmount, principalOnly)</a> ⇒ <code>Promise.&lt;SentTransaction&gt;</code></dt>
23
20
  <dd><p>Makes a payment.</p></dd>
24
- <dt><a href="#approveSep41AllowanceIfInsufficient">approveSep41AllowanceIfInsufficient(network, wallet, tokenAddress, spenderAddress, allowanceAmount)</a> ⇒ <code>Promise.&lt;(SentTransaction.&lt;null&gt;|null)&gt;</code></dt>
21
+ <dt><a href="#approveSep41AllowanceIfInsufficient">approveSep41AllowanceIfInsufficient(poolName, network, wallet, spenderAddress, allowanceAmount)</a> ⇒ <code>Promise.&lt;(SentTransaction.&lt;null&gt;|null)&gt;</code></dt>
25
22
  <dd><p>Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
26
23
  Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)</p></dd>
27
24
  </dl>
28
25
 
29
- <a name="getCreditLineClient"></a>
30
-
31
- ## getCreditLineClient(poolName, network, wallet) ⇒ <code>PoolCreditClient</code> \| <code>undefined</code>
32
- <p>Returns an soroban contract client instance for the credit line contract
33
- associated with the given pool name on the current chain.</p>
34
-
35
- **Kind**: global function
36
- **Returns**: <code>PoolCreditClient</code> \| <code>undefined</code> - <p>A contract client instance for the CreditLine contract or undefined if it could not be found.</p>
37
-
38
- | Param | Type | Description |
39
- | --- | --- | --- |
40
- | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to get the contract instance for.</p> |
41
- | network | <code>StellarNetwork</code> | <p>The stellar network.</p> |
42
- | wallet | <code>StellarWallet</code> | <p>The stellar wallet.</p> |
43
-
44
26
  <a name="getAvailableBalanceForPool"></a>
45
27
 
46
28
  ## getAvailableBalanceForPool(poolName, network, wallet)
@@ -153,7 +135,7 @@ associated with the given pool name on the current chain.</p>
153
135
 
154
136
  <a name="approveSep41AllowanceIfInsufficient"></a>
155
137
 
156
- ## approveSep41AllowanceIfInsufficient(network, wallet, tokenAddress, spenderAddress, allowanceAmount) ⇒ <code>Promise.&lt;(SentTransaction.&lt;null&gt;\|null)&gt;</code>
138
+ ## approveSep41AllowanceIfInsufficient(poolName, network, wallet, spenderAddress, allowanceAmount) ⇒ <code>Promise.&lt;(SentTransaction.&lt;null&gt;\|null)&gt;</code>
157
139
  <p>Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
158
140
  Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)</p>
159
141
 
@@ -164,9 +146,9 @@ Allowance is required to do certain actions on the Huma protocol (e.g. makePayme
164
146
 
165
147
  | Param | Type | Description |
166
148
  | --- | --- | --- |
149
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to get the contract instance for.</p> |
167
150
  | network | <code>StellarNetwork</code> | <p>The stellar network.</p> |
168
151
  | wallet | <code>StellarWallet</code> | <p>The wallet used to send the transaction.</p> |
169
- | tokenAddress | <code>string</code> | <p>The address of the Sep41 token to approve.</p> |
170
152
  | spenderAddress | <code>string</code> | <p>The address of the spender to approve an allowance for.</p> |
171
153
  | allowanceAmount | <code>bigint</code> | <p>The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.</p> |
172
154
 
@@ -1,17 +1,7 @@
1
- import { Client as PoolCreditClient, CreditRecord } from '@huma-finance/soroban-pool-credit';
1
+ import { CreditRecord } from '@huma-finance/soroban-pool-credit';
2
2
  import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
3
- import { StellarWallet } from '../services/StellarWallet';
4
- import { POOL_NAME, StellarNetwork } from '../utils/network';
5
- /**
6
- * Returns an soroban contract client instance for the credit line contract
7
- * associated with the given pool name on the current chain.
8
- *
9
- * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
10
- * @param {StellarNetwork} network - The stellar network.
11
- * @param {StellarWallet} wallet - The stellar wallet.
12
- * @returns {PoolCreditClient | undefined} A contract client instance for the CreditLine contract or undefined if it could not be found.
13
- */
14
- export declare function getCreditLineClient(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): PoolCreditClient | undefined;
3
+ import { StellarWallet } from '../services';
4
+ import { POOL_NAME, StellarNetwork } from '../utils';
15
5
  /**
16
6
  * Returns the current pool balance available for borrowing
17
7
  *
@@ -1,21 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makePayment = exports.drawdown = exports.approveAllowanceForSentinel = exports.getTotalDue = exports.getAvailableCreditForPool = exports.getCreditRecordForPool = exports.getAvailableBalanceForPool = exports.getCreditLineClient = void 0;
4
- const client_1 = require("../utils/client");
3
+ exports.makePayment = exports.drawdown = exports.approveAllowanceForSentinel = exports.getTotalDue = exports.getAvailableCreditForPool = exports.getCreditRecordForPool = exports.getAvailableBalanceForPool = void 0;
4
+ const utils_1 = require("../utils");
5
5
  const Sep41ContractHelper_1 = require("./Sep41ContractHelper");
6
- /**
7
- * Returns an soroban contract client instance for the credit line contract
8
- * associated with the given pool name on the current chain.
9
- *
10
- * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
11
- * @param {StellarNetwork} network - The stellar network.
12
- * @param {StellarWallet} wallet - The stellar wallet.
13
- * @returns {PoolCreditClient | undefined} A contract client instance for the CreditLine contract or undefined if it could not be found.
14
- */
15
- function getCreditLineClient(poolName, network, wallet) {
16
- return (0, client_1.getPoolCreditClient)(poolName, network, wallet);
17
- }
18
- exports.getCreditLineClient = getCreditLineClient;
19
6
  /**
20
7
  * Returns the current pool balance available for borrowing
21
8
  *
@@ -24,11 +11,11 @@ exports.getCreditLineClient = getCreditLineClient;
24
11
  * @param {StellarWallet} wallet - The stellar wallet.
25
12
  */
26
13
  async function getAvailableBalanceForPool(poolName, network, wallet) {
27
- const poolStorageClient = (0, client_1.getPoolStorageClient)(poolName, network, wallet);
28
- if (!poolStorageClient) {
29
- throw new Error('Could not find credit contract for pool');
30
- }
31
- const { result } = await poolStorageClient.get_available_balance();
14
+ const poolStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolStorage');
15
+ const { result } = await (0, utils_1.sendTransaction)({
16
+ context: poolStorageContext,
17
+ method: 'get_available_balance',
18
+ });
32
19
  return result;
33
20
  }
34
21
  exports.getAvailableBalanceForPool = getAvailableBalanceForPool;
@@ -41,18 +28,31 @@ exports.getAvailableBalanceForPool = getAvailableBalanceForPool;
41
28
  * @param {string} borrower - The address of the borrower to check the credit record for.
42
29
  */
43
30
  async function getCreditRecordForPool(poolName, network, wallet, borrower) {
44
- const creditStorageClient = (0, client_1.getCreditStorageClient)(poolName, network, wallet);
45
- if (!creditStorageClient) {
46
- throw new Error('Could not find credit storage contract for pool');
47
- }
48
- const { result: creditHash } = await creditStorageClient.get_credit_hash({
49
- borrower,
31
+ const creditStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'creditStorage');
32
+ const { result: creditHash } = await (0, utils_1.sendTransaction)({
33
+ context: creditStorageContext,
34
+ method: 'get_credit_hash',
35
+ params: [
36
+ {
37
+ name: 'borrower',
38
+ type: utils_1.ScValType.address,
39
+ value: borrower,
40
+ },
41
+ ],
50
42
  });
51
43
  if (!creditHash) {
52
44
  throw new Error('Could not find credit hash');
53
45
  }
54
- const { result: creditRecord } = await creditStorageClient.get_credit_record({
55
- credit_hash: creditHash,
46
+ const { result: creditRecord } = await (0, utils_1.sendTransaction)({
47
+ context: creditStorageContext,
48
+ method: 'get_credit_record',
49
+ params: [
50
+ {
51
+ name: 'credit_hash',
52
+ type: utils_1.ScValType.buffer,
53
+ value: creditHash,
54
+ },
55
+ ],
56
56
  });
57
57
  if (!creditRecord) {
58
58
  throw new Error('Could not find credit record');
@@ -71,24 +71,36 @@ exports.getCreditRecordForPool = getCreditRecordForPool;
71
71
  * @param {string} borrower - The address of the borrower to check the available credit for.
72
72
  */
73
73
  async function getAvailableCreditForPool(poolName, network, wallet, borrower) {
74
- const creditStorageClient = (0, client_1.getCreditStorageClient)(poolName, network, wallet);
75
- if (!creditStorageClient) {
76
- throw new Error('Could not find credit storage contract for pool');
77
- }
78
- const { result: creditHash } = await creditStorageClient.get_credit_hash({
79
- borrower,
74
+ const creditStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'creditStorage');
75
+ const { result: creditHash } = await (0, utils_1.sendTransaction)({
76
+ context: creditStorageContext,
77
+ method: 'get_credit_hash',
78
+ params: [
79
+ {
80
+ name: 'borrower',
81
+ type: utils_1.ScValType.address,
82
+ value: borrower,
83
+ },
84
+ ],
80
85
  });
81
86
  if (!creditHash) {
82
87
  throw new Error('Could not find credit hash');
83
88
  }
84
- const [{ result: creditConfig }, { result: creditRecord }] = await Promise.all([
85
- creditStorageClient.get_credit_config({
86
- credit_hash: creditHash,
87
- }),
88
- creditStorageClient.get_credit_record({
89
- credit_hash: creditHash,
90
- }),
91
- ]);
89
+ const creditHashParam = {
90
+ name: 'credit_hash',
91
+ type: utils_1.ScValType.buffer,
92
+ value: creditHash,
93
+ };
94
+ const { result: creditConfig } = await (0, utils_1.sendTransaction)({
95
+ context: creditStorageContext,
96
+ method: 'get_credit_config',
97
+ params: [creditHashParam],
98
+ });
99
+ const { result: creditRecord } = await (0, utils_1.sendTransaction)({
100
+ context: creditStorageContext,
101
+ method: 'get_credit_record',
102
+ params: [creditHashParam],
103
+ });
92
104
  if (!creditConfig || !creditRecord) {
93
105
  throw new Error('Could not find credit config or credit record');
94
106
  }
@@ -128,15 +140,12 @@ async function approveAllowanceForSentinel(poolName, network, wallet) {
128
140
  if (totalDue === null) {
129
141
  throw new Error('Could not find total due');
130
142
  }
131
- const poolStorageClient = (0, client_1.getPoolStorageClient)(poolName, network, wallet);
132
- if (!poolStorageClient) {
133
- throw new Error('Could not find pool storage contract for pool');
134
- }
135
- const [{ result: underlyingToken }, { result: sentinel }] = await Promise.all([
136
- poolStorageClient.get_underlying_token(),
137
- poolStorageClient.get_sentinel(),
138
- ]);
139
- const tx = await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(network, wallet, underlyingToken, sentinel, totalDue);
143
+ const poolStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolStorage');
144
+ const { result: sentinel } = await (0, utils_1.sendTransaction)({
145
+ context: poolStorageContext,
146
+ method: 'get_sentinel',
147
+ });
148
+ const tx = await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(poolName, network, wallet, sentinel, totalDue);
140
149
  return tx;
141
150
  }
142
151
  exports.approveAllowanceForSentinel = approveAllowanceForSentinel;
@@ -152,18 +161,25 @@ exports.approveAllowanceForSentinel = approveAllowanceForSentinel;
152
161
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
153
162
  */
154
163
  async function drawdown(poolName, network, wallet, drawdownAmount) {
155
- const poolCreditClient = (0, client_1.getPoolCreditClient)(poolName, network, wallet);
156
- if (!poolCreditClient) {
157
- throw new Error('Could not find credit contract for pool');
158
- }
159
164
  await approveAllowanceForSentinel(poolName, network, wallet);
160
- const tx = await poolCreditClient.drawdown({
161
- borrower: wallet.userInfo.publicKey,
162
- amount: drawdownAmount,
163
- }, {
164
- timeoutInSeconds: 30,
165
+ const poolCreditContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolCredit');
166
+ const result = await (0, utils_1.sendTransaction)({
167
+ context: poolCreditContext,
168
+ method: 'drawdown',
169
+ params: [
170
+ {
171
+ name: 'borrower',
172
+ type: utils_1.ScValType.address,
173
+ value: wallet.userInfo.publicKey,
174
+ },
175
+ {
176
+ name: 'amount',
177
+ type: utils_1.ScValType.u128,
178
+ value: drawdownAmount,
179
+ },
180
+ ],
181
+ shouldSignTransaction: true,
165
182
  });
166
- const result = await tx.signAndSend();
167
183
  return result;
168
184
  }
169
185
  exports.drawdown = drawdown;
@@ -180,39 +196,39 @@ exports.drawdown = drawdown;
180
196
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
181
197
  */
182
198
  async function makePayment(poolName, network, wallet, paymentAmount, principalOnly) {
183
- const poolCreditClient = (0, client_1.getPoolCreditClient)(poolName, network, wallet);
184
- if (!poolCreditClient) {
185
- throw new Error('Could not find credit contract for pool');
186
- }
187
- const poolStorageClient = (0, client_1.getPoolStorageClient)(poolName, network, wallet);
188
- if (!poolStorageClient) {
189
- throw new Error('Could not find pool storage contract for pool');
190
- }
191
199
  await approveAllowanceForSentinel(poolName, network, wallet);
192
- const [{ result: underlyingToken }, { result: sentinel }] = await Promise.all([
193
- poolStorageClient.get_underlying_token(),
194
- poolStorageClient.get_sentinel(),
195
- ]);
196
- let tx;
197
- tx = await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(network, wallet, underlyingToken, sentinel, paymentAmount);
198
- if (principalOnly) {
199
- tx = await poolCreditClient.make_principal_payment({
200
- borrower: wallet.userInfo.publicKey,
201
- amount: paymentAmount,
202
- }, {
203
- timeoutInSeconds: 30,
204
- });
205
- }
206
- else {
207
- tx = await poolCreditClient.make_payment({
208
- caller: wallet.userInfo.publicKey,
209
- borrower: wallet.userInfo.publicKey,
210
- amount: paymentAmount,
211
- }, {
212
- timeoutInSeconds: 30,
200
+ const poolStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolStorage');
201
+ const { result: sentinel } = await (0, utils_1.sendTransaction)({
202
+ context: poolStorageContext,
203
+ method: 'get_sentinel',
204
+ });
205
+ await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(poolName, network, wallet, sentinel, paymentAmount);
206
+ const poolCreditContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolCredit');
207
+ const params = [
208
+ {
209
+ name: 'borrower',
210
+ type: utils_1.ScValType.address,
211
+ value: wallet.userInfo.publicKey,
212
+ },
213
+ {
214
+ name: 'amount',
215
+ type: utils_1.ScValType.u128,
216
+ value: paymentAmount,
217
+ },
218
+ ];
219
+ if (!principalOnly) {
220
+ params.unshift({
221
+ name: 'caller',
222
+ type: utils_1.ScValType.address,
223
+ value: wallet.userInfo.publicKey,
213
224
  });
214
225
  }
215
- const result = await tx.signAndSend();
226
+ const result = await (0, utils_1.sendTransaction)({
227
+ context: poolCreditContext,
228
+ method: principalOnly ? 'make_principal_payment' : 'make_payment',
229
+ params: params,
230
+ shouldSignTransaction: true,
231
+ });
216
232
  return result;
217
233
  }
218
234
  exports.makePayment = makePayment;
@@ -1 +1 @@
1
- {"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;;AAMA,4CAIwB;AAExB,+DAA2E;AAE3E;;;;;;;;GAQG;AACH,SAAgB,mBAAmB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,EACP,MAAM,EACN,eAAe,EACf,QAAQ,EACR,aAAa,CACd,CAAA;IAED,IAAI,aAAa,EAAE;QACjB,EAAE,GAAG,MAAM,gBAAgB,CAAC,sBAAsB,CAChD;YACE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;YACnC,MAAM,EAAE,aAAa;SACtB,EACD;YACE,gBAAgB,EAAE,EAAE;SACrB,CACF,CAAA;KACF;SAAM;QACL,EAAE,GAAG,MAAM,gBAAgB,CAAC,YAAY,CACtC;YACE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;YACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;YACnC,MAAM,EAAE,aAAa;SACtB,EACD;YACE,gBAAgB,EAAE,EAAE;SACrB,CACF,CAAA;KACF;IAED,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,WAAW,EAAE,CAAA;IACrC,OAAO,MAAM,CAAA;AACf,CAAC;AA1DD,kCA0DC"}
1
+ {"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;;AAKA,oCAMiB;AACjB,+DAA2E;AAE3E;;;;;;GAMG;AACI,KAAK,UAAU,0BAA0B,CAC9C,QAAmB,EACnB,OAAuB,EACvB,MAAqB;IAErB,MAAM,kBAAkB,GAAG,IAAI,0BAAkB,CAC/C,QAAQ,EACR,OAAO,EACP,MAAM,EACN,aAAa,CACd,CAAA;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,uBAAe,EAAS;QAC/C,OAAO,EAAE,kBAAkB;QAC3B,MAAM,EAAE,uBAAuB;KAChC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAlBD,gEAkBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,sBAAsB,CAC1C,QAAmB,EACnB,OAAuB,EACvB,MAAqB,EACrB,QAAgB;IAEhB,MAAM,oBAAoB,GAAG,IAAI,0BAA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GAAG,MAAM,IAAA,uBAAe,EAA6B;QAC/D,OAAO,EAAE,iBAAiB;QAC1B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,cAAc;QACjE,MAAM,EAAE,MAAM;QACd,qBAAqB,EAAE,IAAI;KAC5B,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC;AA5DD,kCA4DC"}
@@ -1,17 +1,17 @@
1
1
  import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
2
2
  import { StellarWallet } from '../services';
3
- import { StellarNetwork } from '../utils';
3
+ import { POOL_NAME, StellarNetwork } from '../utils';
4
4
  /**
5
5
  * Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
6
6
  * Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
7
7
  *
8
8
  * @async
9
9
  * @function
10
+ * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
10
11
  * @param {StellarNetwork} network - The stellar network.
11
12
  * @param {StellarWallet} wallet - The wallet used to send the transaction.
12
- * @param {string} tokenAddress - The address of the Sep41 token to approve.
13
13
  * @param {string} spenderAddress - The address of the spender to approve an allowance for.
14
14
  * @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
15
15
  * @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
16
16
  */
17
- export declare function approveSep41AllowanceIfInsufficient(network: StellarNetwork, wallet: StellarWallet, tokenAddress: string, spenderAddress: string, allowanceAmount: bigint): Promise<SentTransaction<null> | null>;
17
+ export declare function approveSep41AllowanceIfInsufficient(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, spenderAddress: string, allowanceAmount: bigint): Promise<SentTransaction<null> | null>;
@@ -8,35 +8,66 @@ const utils_1 = require("../utils");
8
8
  *
9
9
  * @async
10
10
  * @function
11
+ * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
11
12
  * @param {StellarNetwork} network - The stellar network.
12
13
  * @param {StellarWallet} wallet - The wallet used to send the transaction.
13
- * @param {string} tokenAddress - The address of the Sep41 token to approve.
14
14
  * @param {string} spenderAddress - The address of the spender to approve an allowance for.
15
15
  * @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
16
16
  * @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
17
17
  */
18
- async function approveSep41AllowanceIfInsufficient(network, wallet, tokenAddress, spenderAddress, allowanceAmount) {
19
- const tokenClient = (0, utils_1.getUnderlyingTokenClient)(tokenAddress, network, wallet);
20
- const [{ result: allowance }, { result: decimals }] = await Promise.all([
21
- tokenClient.allowance({
22
- from: wallet.userInfo.publicKey,
23
- spender: spenderAddress,
24
- }),
25
- tokenClient.decimals(),
26
- ]);
18
+ async function approveSep41AllowanceIfInsufficient(poolName, network, wallet, spenderAddress, allowanceAmount) {
19
+ const underlyingTokenContext = new utils_1.TransactionContext(poolName, network, wallet, 'underlyingToken');
20
+ const { result: allowance } = await (0, utils_1.sendTransaction)({
21
+ context: underlyingTokenContext,
22
+ method: 'allowance',
23
+ params: [
24
+ {
25
+ name: 'from',
26
+ type: utils_1.ScValType.address,
27
+ value: wallet.userInfo.publicKey,
28
+ },
29
+ {
30
+ name: 'spender',
31
+ type: utils_1.ScValType.address,
32
+ value: spenderAddress,
33
+ },
34
+ ],
35
+ });
36
+ const { result: decimals } = await (0, utils_1.sendTransaction)({
37
+ context: underlyingTokenContext,
38
+ method: 'decimals',
39
+ });
27
40
  if (allowance < allowanceAmount) {
28
41
  const latestLedger = await (0, utils_1.getLatestLedger)(network);
29
42
  // @TODO find a better to advance the ledger number
30
43
  const advanceLedgerNum = 3000000;
31
- const tx = await tokenClient.approve({
32
- from: wallet.userInfo.publicKey,
33
- spender: spenderAddress,
34
- amount: BigInt(1000000000 * Math.pow(10, Number(decimals))),
35
- expiration_ledger: latestLedger.sequence + advanceLedgerNum,
36
- }, {
37
- timeoutInSeconds: 30,
44
+ const result = await (0, utils_1.sendTransaction)({
45
+ context: underlyingTokenContext,
46
+ method: 'approve',
47
+ params: [
48
+ {
49
+ name: 'from',
50
+ type: utils_1.ScValType.address,
51
+ value: wallet.userInfo.publicKey,
52
+ },
53
+ {
54
+ name: 'spender',
55
+ type: utils_1.ScValType.address,
56
+ value: spenderAddress,
57
+ },
58
+ {
59
+ name: 'amount',
60
+ type: utils_1.ScValType.i128,
61
+ value: 1000000000 * Math.pow(10, Number(decimals)),
62
+ },
63
+ {
64
+ name: 'expiration_ledger',
65
+ type: utils_1.ScValType.u32,
66
+ value: latestLedger.sequence + advanceLedgerNum,
67
+ },
68
+ ],
69
+ shouldSignTransaction: true,
38
70
  });
39
- const result = await tx.signAndSend();
40
71
  return result;
41
72
  }
42
73
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"Sep41ContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/Sep41ContractHelper.ts"],"names":[],"mappings":";;;AAGA,oCAIiB;AAEjB;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,mCAAmC,CACvD,OAAuB,EACvB,MAAqB,EACrB,YAAoB,EACpB,cAAsB,EACtB,eAAuB;IAEvB,MAAM,WAAW,GAAG,IAAA,gCAAwB,EAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IAE3E,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACtE,WAAW,CAAC,SAAS,CAAC;YACpB,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;YAC/B,OAAO,EAAE,cAAc;SACxB,CAAC;QACF,WAAW,CAAC,QAAQ,EAAE;KACvB,CAAC,CAAA;IAEF,IAAI,SAAS,GAAG,eAAe,EAAE;QAC/B,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,EAAC,OAAO,CAAC,CAAA;QACnD,mDAAmD;QACnD,MAAM,gBAAgB,GAAG,OAAS,CAAA;QAClC,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,OAAO,CAClC;YACE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;YAC/B,OAAO,EAAE,cAAc;YACvB,MAAM,EAAE,MAAM,CAAC,UAAY,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC7D,iBAAiB,EAAE,YAAY,CAAC,QAAQ,GAAG,gBAAgB;SAC5D,EACD;YACE,gBAAgB,EAAE,EAAE;SACrB,CACF,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,WAAW,EAAE,CAAA;QACrC,OAAO,MAAM,CAAA;KACd;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AArCD,kFAqCC"}
1
+ {"version":3,"file":"Sep41ContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/Sep41ContractHelper.ts"],"names":[],"mappings":";;;AAGA,oCAOiB;AAEjB;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,mCAAmC,CACvD,QAAmB,EACnB,OAAuB,EACvB,MAAqB,EACrB,cAAsB,EACtB,eAAuB;IAEvB,MAAM,sBAAsB,GAAG,IAAI,0BAAkB,CACnD,QAAQ,EACR,OAAO,EACP,MAAM,EACN,iBAAiB,CAClB,CAAA;IAED,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,uBAAe,EAAS;QAC1D,OAAO,EAAE,sBAAsB;QAC/B,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,iBAAS,CAAC,OAAO;gBACvB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;aACjC;YACD;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,iBAAS,CAAC,OAAO;gBACvB,KAAK,EAAE,cAAc;aACtB;SACF;KACF,CAAC,CAAA;IACF,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,uBAAe,EAAS;QACzD,OAAO,EAAE,sBAAsB;QAC/B,MAAM,EAAE,UAAU;KACnB,CAAC,CAAA;IAEF,IAAI,SAAS,GAAG,eAAe,EAAE;QAC/B,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,EAAC,OAAO,CAAC,CAAA;QACnD,mDAAmD;QACnD,MAAM,gBAAgB,GAAG,OAAS,CAAA;QAElC,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAe,EAAC;YACnC,OAAO,EAAE,sBAAsB;YAC/B,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE;gBACN;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAS,CAAC,OAAO;oBACvB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;iBACjC;gBACD;oBACE,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,iBAAS,CAAC,OAAO;oBACvB,KAAK,EAAE,cAAc;iBACtB;gBACD;oBACE,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,iBAAS,CAAC,IAAI;oBACpB,KAAK,EAAE,UAAY,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;iBACrD;gBACD;oBACE,IAAI,EAAE,mBAAmB;oBACzB,IAAI,EAAE,iBAAS,CAAC,GAAG;oBACnB,KAAK,EAAE,YAAY,CAAC,QAAQ,GAAG,gBAAgB;iBAChD;aACF;YACD,qBAAqB,EAAE,IAAI;SAC5B,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;KACd;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAxED,kFAwEC"}
@@ -1,6 +1,8 @@
1
+ import { Keypair } from '@stellar/stellar-sdk';
1
2
  export declare class StellarWallet {
2
- private sourceKeypair;
3
+ #private;
3
4
  constructor(secretKey: string);
5
+ get keypair(): Keypair;
4
6
  get userInfo(): {
5
7
  publicKey: string;
6
8
  };
@@ -1,22 +1,29 @@
1
1
  "use strict";
2
+ var _StellarWallet_sourceKeypair;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.StellarWallet = void 0;
5
+ const tslib_1 = require("tslib");
4
6
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
5
7
  class StellarWallet {
6
8
  constructor(secretKey) {
7
- this.sourceKeypair = stellar_sdk_1.Keypair.fromSecret(secretKey);
9
+ _StellarWallet_sourceKeypair.set(this, void 0);
10
+ tslib_1.__classPrivateFieldSet(this, _StellarWallet_sourceKeypair, stellar_sdk_1.Keypair.fromSecret(secretKey), "f");
11
+ }
12
+ get keypair() {
13
+ return tslib_1.__classPrivateFieldGet(this, _StellarWallet_sourceKeypair, "f");
8
14
  }
9
15
  get userInfo() {
10
16
  return {
11
- publicKey: this.sourceKeypair.publicKey(),
17
+ publicKey: tslib_1.__classPrivateFieldGet(this, _StellarWallet_sourceKeypair, "f").publicKey(),
12
18
  };
13
19
  }
14
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
21
  async signTransaction(tx, opts) {
16
22
  const txFromXDR = new stellar_sdk_1.Transaction(tx, opts.networkPassphrase);
17
- txFromXDR.sign(this.sourceKeypair);
23
+ txFromXDR.sign(tslib_1.__classPrivateFieldGet(this, _StellarWallet_sourceKeypair, "f"));
18
24
  return txFromXDR.toXDR();
19
25
  }
20
26
  }
21
27
  exports.StellarWallet = StellarWallet;
28
+ _StellarWallet_sourceKeypair = new WeakMap();
22
29
  //# sourceMappingURL=StellarWallet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StellarWallet.js","sourceRoot":"","sources":["../../../src/services/StellarWallet.ts"],"names":[],"mappings":";;;AAAA,sDAA2D;AAE3D,MAAa,aAAa;IAGxB,YAAY,SAAiB;QAC3B,IAAI,CAAC,aAAa,GAAG,qBAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;SAC1C,CAAA;IACH,CAAC;IAED,8DAA8D;IACvD,KAAK,CAAC,eAAe,CAAC,EAAU,EAAE,IAAS;QAChD,MAAM,SAAS,GAAG,IAAI,yBAAW,CAAC,EAAE,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAC7D,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAClC,OAAO,SAAS,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;CACF;AAnBD,sCAmBC"}
1
+ {"version":3,"file":"StellarWallet.js","sourceRoot":"","sources":["../../../src/services/StellarWallet.ts"],"names":[],"mappings":";;;;;AAAA,sDAA2D;AAE3D,MAAa,aAAa;IAGxB,YAAY,SAAiB;QAF7B,+CAAuB;QAGrB,+BAAA,IAAI,gCAAkB,qBAAO,CAAC,UAAU,CAAC,SAAS,CAAC,MAAA,CAAA;IACrD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,+BAAA,IAAI,oCAAe,CAAA;IAC5B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO;YACL,SAAS,EAAE,+BAAA,IAAI,oCAAe,CAAC,SAAS,EAAE;SAC3C,CAAA;IACH,CAAC;IAED,8DAA8D;IACvD,KAAK,CAAC,eAAe,CAAC,EAAU,EAAE,IAAS;QAChD,MAAM,SAAS,GAAG,IAAI,yBAAW,CAAC,EAAE,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAC7D,SAAS,CAAC,IAAI,CAAC,+BAAA,IAAI,oCAAe,CAAC,CAAA;QACnC,OAAO,SAAS,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;CACF;AAvBD,sCAuBC"}
@@ -1,12 +1,13 @@
1
- import { Client as CreditStorageClient } from '@huma-finance/soroban-credit-storage';
2
1
  import { Client as CreditManagerClient } from '@huma-finance/soroban-credit-manager';
2
+ import { Client as CreditStorageClient } from '@huma-finance/soroban-credit-storage';
3
3
  import { Client as PoolClient } from '@huma-finance/soroban-pool';
4
4
  import { Client as PoolCreditClient } from '@huma-finance/soroban-pool-credit';
5
5
  import { Client as PoolStorageClient } from '@huma-finance/soroban-pool-storage';
6
- import { Client as TrancheVaultClient } from '@huma-finance/soroban-tranche-vault';
7
6
  import { Client as Sep41Client } from '@huma-finance/soroban-sep41';
7
+ import { Client as TrancheVaultClient } from '@huma-finance/soroban-tranche-vault';
8
8
  import { StellarWallet } from '../services/StellarWallet';
9
- import { POOL_NAME, StellarNetwork } from './network';
9
+ import { ContractType, POOL_NAME, StellarNetwork } from './network';
10
+ export type Client = PoolCreditClient | CreditStorageClient | CreditManagerClient | PoolClient | PoolStorageClient | TrancheVaultClient | Sep41Client;
10
11
  export declare const getPoolClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolClient | undefined;
11
12
  export declare const getPoolStorageClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolStorageClient | undefined;
12
13
  export declare const getPoolCreditClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolCreditClient | undefined;
@@ -14,3 +15,11 @@ export declare const getCreditStorageClient: (poolName: POOL_NAME, network: Stel
14
15
  export declare const getCreditManagerClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => CreditManagerClient | undefined;
15
16
  export declare const getTrancheVaultClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, tranche: 'senior' | 'junior') => TrancheVaultClient | undefined;
16
17
  export declare const getUnderlyingTokenClient: (tokenAddress: string, network: StellarNetwork, wallet: StellarWallet) => Sep41Client;
18
+ export declare class TransactionContext {
19
+ #private;
20
+ constructor(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, contractType: ContractType);
21
+ get client(): Client;
22
+ get wallet(): StellarWallet;
23
+ get network(): StellarNetwork;
24
+ get contractId(): string;
25
+ }