@huma-finance/soroban-sdk 0.0.15-beta.51 → 0.0.15-beta.53

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 (57) hide show
  1. package/API.md +2 -5
  2. package/dist/cjs/helpers/CreditContractHelper.d.ts +5 -5
  3. package/dist/cjs/helpers/CreditContractHelper.js +0 -2
  4. package/dist/cjs/helpers/Sep41ContractHelper.d.ts +1 -2
  5. package/dist/cjs/helpers/Sep41ContractHelper.js +2 -3
  6. package/dist/cjs/helpers/index.js +0 -1
  7. package/dist/cjs/index.js +0 -1
  8. package/dist/cjs/services/HumaContextStellar.js +16 -20
  9. package/dist/cjs/services/StellarWallet.js +5 -9
  10. package/dist/cjs/services/index.js +0 -1
  11. package/dist/cjs/utils/client.js +12 -16
  12. package/dist/cjs/utils/common.js +0 -1
  13. package/dist/cjs/utils/index.js +0 -1
  14. package/dist/cjs/utils/network.js +1 -2
  15. package/dist/cjs/utils/transaction.d.ts +2 -3
  16. package/dist/cjs/utils/transaction.js +0 -1
  17. package/dist/helpers/CreditContractHelper.d.ts +5 -5
  18. package/dist/helpers/CreditContractHelper.js +47 -38
  19. package/dist/helpers/CreditContractHelper.js.map +1 -1
  20. package/dist/helpers/Sep41ContractHelper.d.ts +1 -2
  21. package/dist/helpers/Sep41ContractHelper.js +19 -15
  22. package/dist/helpers/Sep41ContractHelper.js.map +1 -1
  23. package/dist/helpers/index.js +5 -2
  24. package/dist/helpers/index.js.map +1 -1
  25. package/dist/index.js +6 -3
  26. package/dist/index.js.map +1 -1
  27. package/dist/services/HumaContextStellar.js +21 -20
  28. package/dist/services/HumaContextStellar.js.map +1 -1
  29. package/dist/services/StellarWallet.js +12 -11
  30. package/dist/services/StellarWallet.js.map +1 -1
  31. package/dist/services/index.js +5 -2
  32. package/dist/services/index.js.map +1 -1
  33. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  34. package/dist/utils/client.js +69 -61
  35. package/dist/utils/client.js.map +1 -1
  36. package/dist/utils/common.js +25 -19
  37. package/dist/utils/common.js.map +1 -1
  38. package/dist/utils/index.js +7 -4
  39. package/dist/utils/index.js.map +1 -1
  40. package/dist/utils/network.js +15 -12
  41. package/dist/utils/network.js.map +1 -1
  42. package/dist/utils/transaction.d.ts +2 -3
  43. package/dist/utils/transaction.js +39 -31
  44. package/dist/utils/transaction.js.map +1 -1
  45. package/package.json +12 -11
  46. package/dist/cjs/helpers/CreditContractHelper.js.map +0 -1
  47. package/dist/cjs/helpers/Sep41ContractHelper.js.map +0 -1
  48. package/dist/cjs/helpers/index.js.map +0 -1
  49. package/dist/cjs/index.js.map +0 -1
  50. package/dist/cjs/services/HumaContextStellar.js.map +0 -1
  51. package/dist/cjs/services/StellarWallet.js.map +0 -1
  52. package/dist/cjs/services/index.js.map +0 -1
  53. package/dist/cjs/utils/client.js.map +0 -1
  54. package/dist/cjs/utils/common.js.map +0 -1
  55. package/dist/cjs/utils/index.js.map +0 -1
  56. package/dist/cjs/utils/network.js.map +0 -1
  57. package/dist/cjs/utils/transaction.js.map +0 -1
package/API.md CHANGED
@@ -12,7 +12,7 @@ getPoolBalance() to get the current available pool balance.</p></dd>
12
12
  <dt><a href="#getTotalDue">getTotalDue(poolName, network, wallet, borrower)</a> ⇒ <code>bigint</code> | <code>null</code></dt>
13
13
  <dd><p>Returns borrower's total due amount in bigint format
14
14
  associated with the given pool name on the current chain.</p></dd>
15
- <dt><a href="#approveAllowanceForSentinel">approveAllowanceForSentinel(poolName, network, wallet)</a> ⇒ <code>Promise.&lt;SentTransaction&gt;</code></dt>
15
+ <dt><a href="#approveAllowanceForSentinel">approveAllowanceForSentinel(poolName, network, wallet)</a></dt>
16
16
  <dd><p>Approve allowance for sentinel if not enough allowance is approved.</p></dd>
17
17
  <dt><a href="#drawdown">drawdown(poolName, network, wallet, drawdownAmount)</a> ⇒ <code>Promise.&lt;SentTransaction&gt;</code></dt>
18
18
  <dd><p>Draws down from a pool.</p></dd>
@@ -84,13 +84,10 @@ associated with the given pool name on the current chain.</p>
84
84
 
85
85
  <a name="approveAllowanceForSentinel"></a>
86
86
 
87
- ## approveAllowanceForSentinel(poolName, network, wallet) ⇒ <code>Promise.&lt;SentTransaction&gt;</code>
87
+ ## approveAllowanceForSentinel(poolName, network, wallet)
88
88
  <p>Approve allowance for sentinel if not enough allowance is approved.</p>
89
89
 
90
90
  **Kind**: global function
91
- **Returns**: <code>Promise.&lt;SentTransaction&gt;</code> - <ul>
92
- <li>A Promise of the SentTransaction.</li>
93
- </ul>
94
91
 
95
92
  | Param | Type | Description |
96
93
  | --- | --- | --- |
@@ -1,5 +1,4 @@
1
1
  import { CreditRecord } from '@huma-finance/soroban-pool-credit';
2
- import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
3
2
  import { StellarWallet } from '../services';
4
3
  import { POOL_NAME, StellarNetwork } from '../utils';
5
4
  /**
@@ -49,9 +48,8 @@ export declare function getTotalDue(poolName: POOL_NAME, network: StellarNetwork
49
48
  * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
50
49
  * @param {StellarNetwork} network - The stellar network.
51
50
  * @param {StellarWallet} wallet - The stellar wallet.
52
- * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
53
51
  */
54
- export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<SentTransaction<null> | null>;
52
+ export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<any>;
55
53
  /**
56
54
  * Draws down from a pool.
57
55
  *
@@ -63,7 +61,7 @@ export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network
63
61
  * @param {BigNumberish} drawdownAmount - The amount to drawdown.
64
62
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
65
63
  */
66
- export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, drawdownAmount: bigint): Promise<SentTransaction<null>>;
64
+ export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, drawdownAmount: bigint): Promise<any>;
67
65
  /**
68
66
  * Makes a payment.
69
67
  *
@@ -76,4 +74,6 @@ export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, w
76
74
  * @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
77
75
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
78
76
  */
79
- export declare function makePayment(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, paymentAmount: bigint, principalOnly: boolean): Promise<SentTransaction<readonly [bigint, boolean]>>;
77
+ export declare function makePayment(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, paymentAmount: bigint, principalOnly: boolean): Promise<{
78
+ result: readonly [bigint, boolean];
79
+ }>;
@@ -133,7 +133,6 @@ exports.getTotalDue = getTotalDue;
133
133
  * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
134
134
  * @param {StellarNetwork} network - The stellar network.
135
135
  * @param {StellarWallet} wallet - The stellar wallet.
136
- * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
137
136
  */
138
137
  async function approveAllowanceForSentinel(poolName, network, wallet) {
139
138
  const totalDue = await getTotalDue(poolName, network, wallet, wallet.userInfo.publicKey);
@@ -232,4 +231,3 @@ async function makePayment(poolName, network, wallet, paymentAmount, principalOn
232
231
  return result;
233
232
  }
234
233
  exports.makePayment = makePayment;
235
- //# sourceMappingURL=CreditContractHelper.js.map
@@ -1,4 +1,3 @@
1
- import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
2
1
  import { StellarWallet } from '../services';
3
2
  import { POOL_NAME, StellarNetwork } from '../utils';
4
3
  /**
@@ -14,4 +13,4 @@ import { POOL_NAME, StellarNetwork } from '../utils';
14
13
  * @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
15
14
  * @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
16
15
  */
17
- export declare function approveSep41AllowanceIfInsufficient(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, spenderAddress: string, allowanceAmount: bigint): Promise<SentTransaction<null> | null>;
16
+ export declare function approveSep41AllowanceIfInsufficient(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, spenderAddress: string, allowanceAmount: bigint): Promise<any>;
@@ -40,7 +40,7 @@ async function approveSep41AllowanceIfInsufficient(poolName, network, wallet, sp
40
40
  if (allowance < allowanceAmount) {
41
41
  const latestLedger = await (0, utils_1.getLatestLedger)(network);
42
42
  // @TODO find a better to advance the ledger number
43
- const advanceLedgerNum = 3000000;
43
+ const advanceLedgerNum = 3_000_000;
44
44
  const result = await (0, utils_1.sendTransaction)({
45
45
  context: underlyingTokenContext,
46
46
  method: 'approve',
@@ -58,7 +58,7 @@ async function approveSep41AllowanceIfInsufficient(poolName, network, wallet, sp
58
58
  {
59
59
  name: 'amount',
60
60
  type: utils_1.ScValType.i128,
61
- value: 1000000000 * Math.pow(10, Number(decimals)),
61
+ value: 1000_000_000 * Math.pow(10, Number(decimals)),
62
62
  },
63
63
  {
64
64
  name: 'expiration_ledger',
@@ -73,4 +73,3 @@ async function approveSep41AllowanceIfInsufficient(poolName, network, wallet, sp
73
73
  return null;
74
74
  }
75
75
  exports.approveSep41AllowanceIfInsufficient = approveSep41AllowanceIfInsufficient;
76
- //# sourceMappingURL=Sep41ContractHelper.js.map
@@ -3,4 +3,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./CreditContractHelper"), exports);
5
5
  tslib_1.__exportStar(require("./Sep41ContractHelper"), exports);
6
- //# sourceMappingURL=index.js.map
package/dist/cjs/index.js CHANGED
@@ -4,4 +4,3 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./helpers"), exports);
5
5
  tslib_1.__exportStar(require("./services"), exports);
6
6
  tslib_1.__exportStar(require("./utils"), exports);
7
- //# sourceMappingURL=index.js.map
@@ -1,47 +1,43 @@
1
1
  "use strict";
2
- var _HumaContextStellar_wallet, _HumaContextStellar_network, _HumaContextStellar_poolName, _HumaContextStellar_poolType;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.HumaContextStellar = void 0;
5
- const tslib_1 = require("tslib");
6
4
  class HumaContextStellar {
5
+ #wallet;
6
+ #network;
7
+ #poolName;
8
+ #poolType;
7
9
  constructor({ wallet, network, poolName, poolType, }) {
8
- _HumaContextStellar_wallet.set(this, void 0);
9
- _HumaContextStellar_network.set(this, void 0);
10
- _HumaContextStellar_poolName.set(this, void 0);
11
- _HumaContextStellar_poolType.set(this, void 0);
12
10
  if (!wallet || !network || !poolName || !poolType) {
13
11
  throw new Error('All parameters are required');
14
12
  }
15
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_wallet, wallet, "f");
16
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_network, network, "f");
17
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_poolName, poolName, "f");
18
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_poolType, poolType, "f");
13
+ this.#wallet = wallet;
14
+ this.#network = network;
15
+ this.#poolName = poolName;
16
+ this.#poolType = poolType;
19
17
  }
20
18
  get wallet() {
21
- return tslib_1.__classPrivateFieldGet(this, _HumaContextStellar_wallet, "f");
19
+ return this.#wallet;
22
20
  }
23
21
  set wallet(value) {
24
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_wallet, value, "f");
22
+ this.#wallet = value;
25
23
  }
26
24
  get network() {
27
- return tslib_1.__classPrivateFieldGet(this, _HumaContextStellar_network, "f");
25
+ return this.#network;
28
26
  }
29
27
  set network(value) {
30
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_network, value, "f");
28
+ this.#network = value;
31
29
  }
32
30
  get poolName() {
33
- return tslib_1.__classPrivateFieldGet(this, _HumaContextStellar_poolName, "f");
31
+ return this.#poolName;
34
32
  }
35
33
  set poolName(value) {
36
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_poolName, value, "f");
34
+ this.#poolName = value;
37
35
  }
38
36
  get poolType() {
39
- return tslib_1.__classPrivateFieldGet(this, _HumaContextStellar_poolType, "f");
37
+ return this.#poolType;
40
38
  }
41
39
  set poolType(value) {
42
- tslib_1.__classPrivateFieldSet(this, _HumaContextStellar_poolType, value, "f");
40
+ this.#poolType = value;
43
41
  }
44
42
  }
45
43
  exports.HumaContextStellar = HumaContextStellar;
46
- _HumaContextStellar_wallet = new WeakMap(), _HumaContextStellar_network = new WeakMap(), _HumaContextStellar_poolName = new WeakMap(), _HumaContextStellar_poolType = new WeakMap();
47
- //# sourceMappingURL=HumaContextStellar.js.map
@@ -1,29 +1,25 @@
1
1
  "use strict";
2
- var _StellarWallet_sourceKeypair;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.StellarWallet = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
7
5
  class StellarWallet {
6
+ #sourceKeypair;
8
7
  constructor(secretKey) {
9
- _StellarWallet_sourceKeypair.set(this, void 0);
10
- tslib_1.__classPrivateFieldSet(this, _StellarWallet_sourceKeypair, stellar_sdk_1.Keypair.fromSecret(secretKey), "f");
8
+ this.#sourceKeypair = stellar_sdk_1.Keypair.fromSecret(secretKey);
11
9
  }
12
10
  get keypair() {
13
- return tslib_1.__classPrivateFieldGet(this, _StellarWallet_sourceKeypair, "f");
11
+ return this.#sourceKeypair;
14
12
  }
15
13
  get userInfo() {
16
14
  return {
17
- publicKey: tslib_1.__classPrivateFieldGet(this, _StellarWallet_sourceKeypair, "f").publicKey(),
15
+ publicKey: this.#sourceKeypair.publicKey(),
18
16
  };
19
17
  }
20
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
19
  async signTransaction(tx, opts) {
22
20
  const txFromXDR = new stellar_sdk_1.Transaction(tx, opts.networkPassphrase);
23
- txFromXDR.sign(tslib_1.__classPrivateFieldGet(this, _StellarWallet_sourceKeypair, "f"));
21
+ txFromXDR.sign(this.#sourceKeypair);
24
22
  return txFromXDR.toXDR();
25
23
  }
26
24
  }
27
25
  exports.StellarWallet = StellarWallet;
28
- _StellarWallet_sourceKeypair = new WeakMap();
29
- //# sourceMappingURL=StellarWallet.js.map
@@ -3,4 +3,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./HumaContextStellar"), exports);
5
5
  tslib_1.__exportStar(require("./StellarWallet"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
- var _TransactionContext_client, _TransactionContext_wallet, _TransactionContext_network, _TransactionContext_contractId;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.TransactionContext = exports.getUnderlyingTokenClient = exports.getTrancheVaultClient = exports.getCreditManagerClient = exports.getCreditStorageClient = exports.getPoolCreditClient = exports.getPoolStorageClient = exports.getPoolClient = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const soroban_credit_manager_1 = require("@huma-finance/soroban-credit-manager");
7
5
  const soroban_credit_storage_1 = require("@huma-finance/soroban-credit-storage");
8
6
  const soroban_huma_config_1 = require("@huma-finance/soroban-huma-config");
@@ -109,11 +107,11 @@ const getUnderlyingTokenClient = (tokenAddress, network, wallet) => {
109
107
  };
110
108
  exports.getUnderlyingTokenClient = getUnderlyingTokenClient;
111
109
  class TransactionContext {
110
+ #client;
111
+ #wallet;
112
+ #network;
113
+ #contractId;
112
114
  constructor(poolName, network, wallet, contractType) {
113
- _TransactionContext_client.set(this, void 0);
114
- _TransactionContext_wallet.set(this, void 0);
115
- _TransactionContext_network.set(this, void 0);
116
- _TransactionContext_contractId.set(this, void 0);
117
115
  const poolMetadata = (0, common_1.findPoolMetadata)(network, poolName);
118
116
  if (!poolMetadata) {
119
117
  throw new Error(`Could not find pool metadata by pool name: ${poolName}`);
@@ -130,24 +128,22 @@ class TransactionContext {
130
128
  contractId: poolMetadata.contracts[contractType],
131
129
  ...getCommonProps(network, wallet),
132
130
  });
133
- tslib_1.__classPrivateFieldSet(this, _TransactionContext_client, client, "f");
134
- tslib_1.__classPrivateFieldSet(this, _TransactionContext_wallet, wallet, "f");
135
- tslib_1.__classPrivateFieldSet(this, _TransactionContext_network, network, "f");
136
- tslib_1.__classPrivateFieldSet(this, _TransactionContext_contractId, client.options.contractId, "f");
131
+ this.#client = client;
132
+ this.#wallet = wallet;
133
+ this.#network = network;
134
+ this.#contractId = client.options.contractId;
137
135
  }
138
136
  get client() {
139
- return tslib_1.__classPrivateFieldGet(this, _TransactionContext_client, "f");
137
+ return this.#client;
140
138
  }
141
139
  get wallet() {
142
- return tslib_1.__classPrivateFieldGet(this, _TransactionContext_wallet, "f");
140
+ return this.#wallet;
143
141
  }
144
142
  get network() {
145
- return tslib_1.__classPrivateFieldGet(this, _TransactionContext_network, "f");
143
+ return this.#network;
146
144
  }
147
145
  get contractId() {
148
- return tslib_1.__classPrivateFieldGet(this, _TransactionContext_contractId, "f");
146
+ return this.#contractId;
149
147
  }
150
148
  }
151
149
  exports.TransactionContext = TransactionContext;
152
- _TransactionContext_client = new WeakMap(), _TransactionContext_wallet = new WeakMap(), _TransactionContext_network = new WeakMap(), _TransactionContext_contractId = new WeakMap();
153
- //# sourceMappingURL=client.js.map
@@ -58,4 +58,3 @@ const getLatestLedger = async (network) => {
58
58
  return server.getLatestLedger();
59
59
  };
60
60
  exports.getLatestLedger = getLatestLedger;
61
- //# sourceMappingURL=common.js.map
@@ -5,4 +5,3 @@ tslib_1.__exportStar(require("./client"), exports);
5
5
  tslib_1.__exportStar(require("./common"), exports);
6
6
  tslib_1.__exportStar(require("./network"), exports);
7
7
  tslib_1.__exportStar(require("./transaction"), exports);
8
- //# sourceMappingURL=index.js.map
@@ -55,7 +55,7 @@ exports.NetworkMetadatas = [
55
55
  seniorTranche: 'CAEVE6BJIXQV54DGNFZ5GRIMIIITAHXSOWTGKTDZCQZA4FXK4ZNDZYFX',
56
56
  underlyingToken: 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75',
57
57
  },
58
- borrowers: ['GBQ4MIGKASCJG4GNEOQ3G6Z6YDUXCAKYARB3MNJ7QOF54MNMYW7HP62V'], // TODO: Replace with Arf
58
+ borrowers: ['GBQ4MIGKASCJG4GNEOQ3G6Z6YDUXCAKYARB3MNJ7QOF54MNMYW7HP62V'],
59
59
  },
60
60
  ],
61
61
  },
@@ -131,4 +131,3 @@ exports.NetworkMetadatas = [
131
131
  ],
132
132
  },
133
133
  ];
134
- //# sourceMappingURL=network.js.map
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { SorobanRpc, xdr } from '@stellar/stellar-sdk';
4
- import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
5
4
  import { StellarWallet } from 'services';
6
5
  import { TransactionContext } from './client';
7
6
  import { ScValType } from './common';
@@ -14,7 +13,7 @@ export declare const restoreAndExtendTTL: (network: StellarNetwork, wallet: Stel
14
13
  type: ScValType;
15
14
  value: string | number | bigint;
16
15
  }[]) => Promise<void>;
17
- export declare const sendTransaction: <T = null>({ context, method, params, shouldSignTransaction, }: {
16
+ export declare const sendTransaction: ({ context, method, params, shouldSignTransaction, }: {
18
17
  context: TransactionContext;
19
18
  method: string;
20
19
  params?: {
@@ -23,4 +22,4 @@ export declare const sendTransaction: <T = null>({ context, method, params, shou
23
22
  value: string | number | bigint | Buffer;
24
23
  }[] | undefined;
25
24
  shouldSignTransaction?: boolean | undefined;
26
- }) => Promise<SentTransaction<T>>;
25
+ }) => Promise<any>;
@@ -122,4 +122,3 @@ const sendTransaction = async ({ context, method, params = [], shouldSignTransac
122
122
  return tx.signAndSend();
123
123
  };
124
124
  exports.sendTransaction = sendTransaction;
125
- //# sourceMappingURL=transaction.js.map
@@ -1,5 +1,4 @@
1
1
  import { CreditRecord } from '@huma-finance/soroban-pool-credit';
2
- import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
3
2
  import { StellarWallet } from '../services';
4
3
  import { POOL_NAME, StellarNetwork } from '../utils';
5
4
  /**
@@ -49,9 +48,8 @@ export declare function getTotalDue(poolName: POOL_NAME, network: StellarNetwork
49
48
  * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
50
49
  * @param {StellarNetwork} network - The stellar network.
51
50
  * @param {StellarWallet} wallet - The stellar wallet.
52
- * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
53
51
  */
54
- export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<SentTransaction<null> | null>;
52
+ export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<any>;
55
53
  /**
56
54
  * Draws down from a pool.
57
55
  *
@@ -63,7 +61,7 @@ export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network
63
61
  * @param {BigNumberish} drawdownAmount - The amount to drawdown.
64
62
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
65
63
  */
66
- export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, drawdownAmount: bigint): Promise<SentTransaction<null>>;
64
+ export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, drawdownAmount: bigint): Promise<any>;
67
65
  /**
68
66
  * Makes a payment.
69
67
  *
@@ -76,4 +74,6 @@ export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, w
76
74
  * @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
77
75
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
78
76
  */
79
- export declare function makePayment(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, paymentAmount: bigint, principalOnly: boolean): Promise<SentTransaction<readonly [bigint, boolean]>>;
77
+ export declare function makePayment(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, paymentAmount: bigint, principalOnly: boolean): Promise<{
78
+ result: readonly [bigint, boolean];
79
+ }>;
@@ -1,5 +1,8 @@
1
- import { ScValType, sendTransaction, TransactionContext, } from '../utils';
2
- import { approveSep41AllowanceIfInsufficient } from './Sep41ContractHelper';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makePayment = exports.drawdown = exports.approveAllowanceForSentinel = exports.getTotalDue = exports.getAvailableCreditForPool = exports.getCreditRecordForPool = exports.getAvailableBalanceForPool = void 0;
4
+ const utils_1 = require("../utils");
5
+ const Sep41ContractHelper_1 = require("./Sep41ContractHelper");
3
6
  /**
4
7
  * Returns the current pool balance available for borrowing
5
8
  *
@@ -7,14 +10,15 @@ import { approveSep41AllowanceIfInsufficient } from './Sep41ContractHelper';
7
10
  * @param {StellarNetwork} network - The stellar network.
8
11
  * @param {StellarWallet} wallet - The stellar wallet.
9
12
  */
10
- export async function getAvailableBalanceForPool(poolName, network, wallet) {
11
- const poolStorageContext = new TransactionContext(poolName, network, wallet, 'poolStorage');
12
- const { result } = await sendTransaction({
13
+ async function getAvailableBalanceForPool(poolName, network, wallet) {
14
+ const poolStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolStorage');
15
+ const { result } = await (0, utils_1.sendTransaction)({
13
16
  context: poolStorageContext,
14
17
  method: 'get_available_balance',
15
18
  });
16
19
  return result;
17
20
  }
21
+ exports.getAvailableBalanceForPool = getAvailableBalanceForPool;
18
22
  /**
19
23
  * Returns the credit record of the borrower
20
24
  *
@@ -23,15 +27,15 @@ export async function getAvailableBalanceForPool(poolName, network, wallet) {
23
27
  * @param {StellarWallet} wallet - The stellar wallet.
24
28
  * @param {string} borrower - The address of the borrower to check the credit record for.
25
29
  */
26
- export async function getCreditRecordForPool(poolName, network, wallet, borrower) {
27
- const creditStorageContext = new TransactionContext(poolName, network, wallet, 'creditStorage');
28
- const { result: creditHash } = await sendTransaction({
30
+ async function getCreditRecordForPool(poolName, network, wallet, borrower) {
31
+ const creditStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'creditStorage');
32
+ const { result: creditHash } = await (0, utils_1.sendTransaction)({
29
33
  context: creditStorageContext,
30
34
  method: 'get_credit_hash',
31
35
  params: [
32
36
  {
33
37
  name: 'borrower',
34
- type: ScValType.address,
38
+ type: utils_1.ScValType.address,
35
39
  value: borrower,
36
40
  },
37
41
  ],
@@ -39,13 +43,13 @@ export async function getCreditRecordForPool(poolName, network, wallet, borrower
39
43
  if (!creditHash) {
40
44
  throw new Error('Could not find credit hash');
41
45
  }
42
- const { result: creditRecord } = await sendTransaction({
46
+ const { result: creditRecord } = await (0, utils_1.sendTransaction)({
43
47
  context: creditStorageContext,
44
48
  method: 'get_credit_record',
45
49
  params: [
46
50
  {
47
51
  name: 'credit_hash',
48
- type: ScValType.buffer,
52
+ type: utils_1.ScValType.buffer,
49
53
  value: creditHash,
50
54
  },
51
55
  ],
@@ -55,6 +59,7 @@ export async function getCreditRecordForPool(poolName, network, wallet, borrower
55
59
  }
56
60
  return creditRecord;
57
61
  }
62
+ exports.getCreditRecordForPool = getCreditRecordForPool;
58
63
  /**
59
64
  * Returns the borrower's remaining credit they can use for borrowing. Note that this might not be
60
65
  * currently available for borrowing as the credit limit might exceed the available pool balance. Use
@@ -65,15 +70,15 @@ export async function getCreditRecordForPool(poolName, network, wallet, borrower
65
70
  * @param {StellarWallet} wallet - The stellar wallet.
66
71
  * @param {string} borrower - The address of the borrower to check the available credit for.
67
72
  */
68
- export async function getAvailableCreditForPool(poolName, network, wallet, borrower) {
69
- const creditStorageContext = new TransactionContext(poolName, network, wallet, 'creditStorage');
70
- const { result: creditHash } = await sendTransaction({
73
+ async function getAvailableCreditForPool(poolName, network, wallet, borrower) {
74
+ const creditStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'creditStorage');
75
+ const { result: creditHash } = await (0, utils_1.sendTransaction)({
71
76
  context: creditStorageContext,
72
77
  method: 'get_credit_hash',
73
78
  params: [
74
79
  {
75
80
  name: 'borrower',
76
- type: ScValType.address,
81
+ type: utils_1.ScValType.address,
77
82
  value: borrower,
78
83
  },
79
84
  ],
@@ -83,15 +88,15 @@ export async function getAvailableCreditForPool(poolName, network, wallet, borro
83
88
  }
84
89
  const creditHashParam = {
85
90
  name: 'credit_hash',
86
- type: ScValType.buffer,
91
+ type: utils_1.ScValType.buffer,
87
92
  value: creditHash,
88
93
  };
89
- const { result: creditConfig } = await sendTransaction({
94
+ const { result: creditConfig } = await (0, utils_1.sendTransaction)({
90
95
  context: creditStorageContext,
91
96
  method: 'get_credit_config',
92
97
  params: [creditHashParam],
93
98
  });
94
- const { result: creditRecord } = await sendTransaction({
99
+ const { result: creditRecord } = await (0, utils_1.sendTransaction)({
95
100
  context: creditStorageContext,
96
101
  method: 'get_credit_record',
97
102
  params: [creditHashParam],
@@ -101,6 +106,7 @@ export async function getAvailableCreditForPool(poolName, network, wallet, borro
101
106
  }
102
107
  return (BigInt(creditConfig.credit_limit) - BigInt(creditRecord.unbilled_principal));
103
108
  }
109
+ exports.getAvailableCreditForPool = getAvailableCreditForPool;
104
110
  /**
105
111
  * Returns borrower's total due amount in bigint format
106
112
  * associated with the given pool name on the current chain.
@@ -111,13 +117,14 @@ export async function getAvailableCreditForPool(poolName, network, wallet, borro
111
117
  * @param {string} borrower - The address of the borrower to check the available credit for.
112
118
  * @returns {bigint | null} The account's total due amount in bigint format
113
119
  */
114
- export async function getTotalDue(poolName, network, wallet, borrower) {
120
+ async function getTotalDue(poolName, network, wallet, borrower) {
115
121
  const creditRecord = await getCreditRecordForPool(poolName, network, wallet, borrower);
116
122
  if (!creditRecord) {
117
123
  return null;
118
124
  }
119
125
  return creditRecord.next_due + creditRecord.total_past_due;
120
126
  }
127
+ exports.getTotalDue = getTotalDue;
121
128
  /**
122
129
  * Approve allowance for sentinel if not enough allowance is approved.
123
130
  *
@@ -126,21 +133,21 @@ export async function getTotalDue(poolName, network, wallet, borrower) {
126
133
  * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
127
134
  * @param {StellarNetwork} network - The stellar network.
128
135
  * @param {StellarWallet} wallet - The stellar wallet.
129
- * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
130
136
  */
131
- export async function approveAllowanceForSentinel(poolName, network, wallet) {
137
+ async function approveAllowanceForSentinel(poolName, network, wallet) {
132
138
  const totalDue = await getTotalDue(poolName, network, wallet, wallet.userInfo.publicKey);
133
139
  if (totalDue === null) {
134
140
  throw new Error('Could not find total due');
135
141
  }
136
- const poolStorageContext = new TransactionContext(poolName, network, wallet, 'poolStorage');
137
- const { result: sentinel } = await sendTransaction({
142
+ const poolStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolStorage');
143
+ const { result: sentinel } = await (0, utils_1.sendTransaction)({
138
144
  context: poolStorageContext,
139
145
  method: 'get_sentinel',
140
146
  });
141
- const tx = await approveSep41AllowanceIfInsufficient(poolName, network, wallet, sentinel, totalDue);
147
+ const tx = await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(poolName, network, wallet, sentinel, totalDue);
142
148
  return tx;
143
149
  }
150
+ exports.approveAllowanceForSentinel = approveAllowanceForSentinel;
144
151
  /**
145
152
  * Draws down from a pool.
146
153
  *
@@ -152,21 +159,21 @@ export async function approveAllowanceForSentinel(poolName, network, wallet) {
152
159
  * @param {BigNumberish} drawdownAmount - The amount to drawdown.
153
160
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
154
161
  */
155
- export async function drawdown(poolName, network, wallet, drawdownAmount) {
162
+ async function drawdown(poolName, network, wallet, drawdownAmount) {
156
163
  await approveAllowanceForSentinel(poolName, network, wallet);
157
- const poolCreditContext = new TransactionContext(poolName, network, wallet, 'poolCredit');
158
- const result = await sendTransaction({
164
+ const poolCreditContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolCredit');
165
+ const result = await (0, utils_1.sendTransaction)({
159
166
  context: poolCreditContext,
160
167
  method: 'drawdown',
161
168
  params: [
162
169
  {
163
170
  name: 'borrower',
164
- type: ScValType.address,
171
+ type: utils_1.ScValType.address,
165
172
  value: wallet.userInfo.publicKey,
166
173
  },
167
174
  {
168
175
  name: 'amount',
169
- type: ScValType.u128,
176
+ type: utils_1.ScValType.u128,
170
177
  value: drawdownAmount,
171
178
  },
172
179
  ],
@@ -174,6 +181,7 @@ export async function drawdown(poolName, network, wallet, drawdownAmount) {
174
181
  });
175
182
  return result;
176
183
  }
184
+ exports.drawdown = drawdown;
177
185
  /**
178
186
  * Makes a payment.
179
187
  *
@@ -186,35 +194,35 @@ export async function drawdown(poolName, network, wallet, drawdownAmount) {
186
194
  * @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
187
195
  * @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
188
196
  */
189
- export async function makePayment(poolName, network, wallet, paymentAmount, principalOnly) {
197
+ async function makePayment(poolName, network, wallet, paymentAmount, principalOnly) {
190
198
  await approveAllowanceForSentinel(poolName, network, wallet);
191
- const poolStorageContext = new TransactionContext(poolName, network, wallet, 'poolStorage');
192
- const { result: sentinel } = await sendTransaction({
199
+ const poolStorageContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolStorage');
200
+ const { result: sentinel } = await (0, utils_1.sendTransaction)({
193
201
  context: poolStorageContext,
194
202
  method: 'get_sentinel',
195
203
  });
196
- await approveSep41AllowanceIfInsufficient(poolName, network, wallet, sentinel, paymentAmount);
197
- const poolCreditContext = new TransactionContext(poolName, network, wallet, 'poolCredit');
204
+ await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(poolName, network, wallet, sentinel, paymentAmount);
205
+ const poolCreditContext = new utils_1.TransactionContext(poolName, network, wallet, 'poolCredit');
198
206
  const params = [
199
207
  {
200
208
  name: 'borrower',
201
- type: ScValType.address,
209
+ type: utils_1.ScValType.address,
202
210
  value: wallet.userInfo.publicKey,
203
211
  },
204
212
  {
205
213
  name: 'amount',
206
- type: ScValType.u128,
214
+ type: utils_1.ScValType.u128,
207
215
  value: paymentAmount,
208
216
  },
209
217
  ];
210
218
  if (!principalOnly) {
211
219
  params.unshift({
212
220
  name: 'caller',
213
- type: ScValType.address,
221
+ type: utils_1.ScValType.address,
214
222
  value: wallet.userInfo.publicKey,
215
223
  });
216
224
  }
217
- const result = await sendTransaction({
225
+ const result = await (0, utils_1.sendTransaction)({
218
226
  context: poolCreditContext,
219
227
  method: principalOnly ? 'make_principal_payment' : 'make_payment',
220
228
  params: params,
@@ -222,4 +230,5 @@ export async function makePayment(poolName, network, wallet, paymentAmount, prin
222
230
  });
223
231
  return result;
224
232
  }
233
+ exports.makePayment = makePayment;
225
234
  //# sourceMappingURL=CreditContractHelper.js.map