@huma-finance/soroban-sdk 0.0.8-beta.2 → 0.0.11-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +40 -0
- package/dist/cjs/helpers/CreditContractHelper.d.ts +11 -0
- package/dist/cjs/helpers/CreditContractHelper.js +40 -1
- package/dist/cjs/helpers/CreditContractHelper.js.map +1 -1
- package/dist/cjs/helpers/Sep41ContractHelper.d.ts +17 -0
- package/dist/cjs/helpers/Sep41ContractHelper.js +45 -0
- package/dist/cjs/helpers/Sep41ContractHelper.js.map +1 -0
- package/dist/cjs/services/StellarWallet.d.ts +1 -2
- package/dist/cjs/utils/client.d.ts +2 -0
- package/dist/cjs/utils/client.js +9 -1
- package/dist/cjs/utils/client.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +2 -0
- package/dist/cjs/utils/common.js +9 -1
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/cjs/utils/network.d.ts +2 -1
- package/dist/cjs/utils/network.js +20 -17
- package/dist/cjs/utils/network.js.map +1 -1
- package/dist/helpers/CreditContractHelper.d.ts +11 -0
- package/dist/helpers/CreditContractHelper.js +38 -0
- package/dist/helpers/CreditContractHelper.js.map +1 -1
- package/dist/helpers/Sep41ContractHelper.d.ts +17 -0
- package/dist/helpers/Sep41ContractHelper.js +41 -0
- package/dist/helpers/Sep41ContractHelper.js.map +1 -0
- package/dist/services/StellarWallet.d.ts +1 -2
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/client.d.ts +2 -0
- package/dist/utils/client.js +7 -0
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/common.js +8 -1
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/network.d.ts +2 -1
- package/dist/utils/network.js +20 -17
- package/dist/utils/network.js.map +1 -1
- package/package.json +11 -9
package/API.md
CHANGED
|
@@ -15,10 +15,15 @@ getPoolBalance() to get the current available pool balance.</p></dd>
|
|
|
15
15
|
<dt><a href="#getTotalDue">getTotalDue(poolName, network, wallet, borrower)</a> ⇒ <code>bigint</code> | <code>null</code></dt>
|
|
16
16
|
<dd><p>Returns borrower's total due amount in bigint format
|
|
17
17
|
associated with the given pool name on the current chain.</p></dd>
|
|
18
|
+
<dt><a href="#approveAllowanceForSentinel">approveAllowanceForSentinel(poolName, network, wallet)</a> ⇒ <code>Promise.<SentTransaction></code></dt>
|
|
19
|
+
<dd><p>Approve allowance for sentinel if not enough allowance is approved.</p></dd>
|
|
18
20
|
<dt><a href="#drawdown">drawdown(poolName, network, wallet, drawdownAmount)</a> ⇒ <code>Promise.<SentTransaction></code></dt>
|
|
19
21
|
<dd><p>Draws down from a pool.</p></dd>
|
|
20
22
|
<dt><a href="#makePayment">makePayment(poolName, network, wallet, paymentAmount, principalOnly)</a> ⇒ <code>Promise.<AssembledTransaction></code></dt>
|
|
21
23
|
<dd><p>Makes a payment.</p></dd>
|
|
24
|
+
<dt><a href="#approveSep41AllowanceIfInsufficient">approveSep41AllowanceIfInsufficient(network, wallet, tokenAddress, spenderAddress, allowanceAmount)</a> ⇒ <code>Promise.<(SentTransaction.<null>|null)></code></dt>
|
|
25
|
+
<dd><p>Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
|
|
26
|
+
Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)</p></dd>
|
|
22
27
|
</dl>
|
|
23
28
|
|
|
24
29
|
<a name="getCreditLineClient"></a>
|
|
@@ -95,6 +100,22 @@ associated with the given pool name on the current chain.</p>
|
|
|
95
100
|
| wallet | <code>StellarWallet</code> | <p>The stellar wallet.</p> |
|
|
96
101
|
| borrower | <code>string</code> | <p>The address of the borrower to check the available credit for.</p> |
|
|
97
102
|
|
|
103
|
+
<a name="approveAllowanceForSentinel"></a>
|
|
104
|
+
|
|
105
|
+
## approveAllowanceForSentinel(poolName, network, wallet) ⇒ <code>Promise.<SentTransaction></code>
|
|
106
|
+
<p>Approve allowance for sentinel if not enough allowance is approved.</p>
|
|
107
|
+
|
|
108
|
+
**Kind**: global function
|
|
109
|
+
**Returns**: <code>Promise.<SentTransaction></code> - <ul>
|
|
110
|
+
<li>A Promise of the SentTransaction.</li>
|
|
111
|
+
</ul>
|
|
112
|
+
|
|
113
|
+
| Param | Type | Description |
|
|
114
|
+
| --- | --- | --- |
|
|
115
|
+
| poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to get the contract instance for.</p> |
|
|
116
|
+
| network | <code>StellarNetwork</code> | <p>The stellar network.</p> |
|
|
117
|
+
| wallet | <code>StellarWallet</code> | <p>The stellar wallet.</p> |
|
|
118
|
+
|
|
98
119
|
<a name="drawdown"></a>
|
|
99
120
|
|
|
100
121
|
## drawdown(poolName, network, wallet, drawdownAmount) ⇒ <code>Promise.<SentTransaction></code>
|
|
@@ -130,3 +151,22 @@ associated with the given pool name on the current chain.</p>
|
|
|
130
151
|
| paymentAmount | <code>bigint</code> | <p>The amount to payback.</p> |
|
|
131
152
|
| principalOnly | <code>boolean</code> | <p>Whether this payment should ONLY apply to the principal</p> |
|
|
132
153
|
|
|
154
|
+
<a name="approveSep41AllowanceIfInsufficient"></a>
|
|
155
|
+
|
|
156
|
+
## approveSep41AllowanceIfInsufficient(network, wallet, tokenAddress, spenderAddress, allowanceAmount) ⇒ <code>Promise.<(SentTransaction.<null>\|null)></code>
|
|
157
|
+
<p>Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
|
|
158
|
+
Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)</p>
|
|
159
|
+
|
|
160
|
+
**Kind**: global function
|
|
161
|
+
**Returns**: <code>Promise.<(SentTransaction.<null>\|null)></code> - <ul>
|
|
162
|
+
<li>A Promise of the transaction response, or null if the allowance was already sufficient.</li>
|
|
163
|
+
</ul>
|
|
164
|
+
|
|
165
|
+
| Param | Type | Description |
|
|
166
|
+
| --- | --- | --- |
|
|
167
|
+
| network | <code>StellarNetwork</code> | <p>The stellar network.</p> |
|
|
168
|
+
| 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
|
+
| spenderAddress | <code>string</code> | <p>The address of the spender to approve an allowance for.</p> |
|
|
171
|
+
| allowanceAmount | <code>bigint</code> | <p>The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.</p> |
|
|
172
|
+
|
|
@@ -50,6 +50,17 @@ export declare function getAvailableCreditForPool(poolName: POOL_NAME, network:
|
|
|
50
50
|
* @returns {bigint | null} The account's total due amount in bigint format
|
|
51
51
|
*/
|
|
52
52
|
export declare function getTotalDue(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, borrower: string): Promise<bigint | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Approve allowance for sentinel if not enough allowance is approved.
|
|
55
|
+
*
|
|
56
|
+
* @async
|
|
57
|
+
* @function
|
|
58
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
59
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
60
|
+
* @param {StellarWallet} wallet - The stellar wallet.
|
|
61
|
+
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
62
|
+
*/
|
|
63
|
+
export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<SentTransaction<null> | null>;
|
|
53
64
|
/**
|
|
54
65
|
* Draws down from a pool.
|
|
55
66
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makePayment = exports.drawdown = exports.getTotalDue = exports.getAvailableCreditForPool = exports.getCreditRecordForPool = exports.getAvailableBalanceForPool = exports.getCreditLineClient = void 0;
|
|
3
|
+
exports.makePayment = exports.drawdown = exports.approveAllowanceForSentinel = exports.getTotalDue = exports.getAvailableCreditForPool = exports.getCreditRecordForPool = exports.getAvailableBalanceForPool = exports.getCreditLineClient = void 0;
|
|
4
4
|
const client_1 = require("../utils/client");
|
|
5
|
+
const Sep41ContractHelper_1 = require("./Sep41ContractHelper");
|
|
5
6
|
/**
|
|
6
7
|
* Returns an soroban contract client instance for the credit line contract
|
|
7
8
|
* associated with the given pool name on the current chain.
|
|
@@ -112,6 +113,33 @@ async function getTotalDue(poolName, network, wallet, borrower) {
|
|
|
112
113
|
return creditRecord.next_due + creditRecord.total_past_due;
|
|
113
114
|
}
|
|
114
115
|
exports.getTotalDue = getTotalDue;
|
|
116
|
+
/**
|
|
117
|
+
* Approve allowance for sentinel if not enough allowance is approved.
|
|
118
|
+
*
|
|
119
|
+
* @async
|
|
120
|
+
* @function
|
|
121
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
122
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
123
|
+
* @param {StellarWallet} wallet - The stellar wallet.
|
|
124
|
+
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
125
|
+
*/
|
|
126
|
+
async function approveAllowanceForSentinel(poolName, network, wallet) {
|
|
127
|
+
const totalDue = await getTotalDue(poolName, network, wallet, wallet.userInfo.publicKey);
|
|
128
|
+
if (totalDue === null) {
|
|
129
|
+
throw new Error('Could not find total due');
|
|
130
|
+
}
|
|
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);
|
|
140
|
+
return tx;
|
|
141
|
+
}
|
|
142
|
+
exports.approveAllowanceForSentinel = approveAllowanceForSentinel;
|
|
115
143
|
/**
|
|
116
144
|
* Draws down from a pool.
|
|
117
145
|
*
|
|
@@ -128,6 +156,7 @@ async function drawdown(poolName, network, wallet, drawdownAmount) {
|
|
|
128
156
|
if (!poolCreditClient) {
|
|
129
157
|
throw new Error('Could not find credit contract for pool');
|
|
130
158
|
}
|
|
159
|
+
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
131
160
|
const tx = await poolCreditClient.drawdown({
|
|
132
161
|
borrower: wallet.userInfo.publicKey,
|
|
133
162
|
amount: drawdownAmount,
|
|
@@ -155,7 +184,17 @@ async function makePayment(poolName, network, wallet, paymentAmount, principalOn
|
|
|
155
184
|
if (!poolCreditClient) {
|
|
156
185
|
throw new Error('Could not find credit contract for pool');
|
|
157
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
|
+
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
192
|
+
const [{ result: underlyingToken }, { result: sentinel }] = await Promise.all([
|
|
193
|
+
poolStorageClient.get_underlying_token(),
|
|
194
|
+
poolStorageClient.get_sentinel(),
|
|
195
|
+
]);
|
|
158
196
|
let tx;
|
|
197
|
+
tx = await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(network, wallet, underlyingToken, sentinel, paymentAmount);
|
|
159
198
|
if (principalOnly) {
|
|
160
199
|
tx = await poolCreditClient.make_principal_payment({
|
|
161
200
|
borrower: wallet.userInfo.publicKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;;AAOA,4CAIwB;
|
|
1
|
+
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;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AA,yDAAmC,EAC5C,OAAO,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SentTransaction } from '@huma-finance/soroban-pool-credit';
|
|
2
|
+
import { StellarWallet } from '../services';
|
|
3
|
+
import { StellarNetwork } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
|
|
6
|
+
* Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
|
|
7
|
+
*
|
|
8
|
+
* @async
|
|
9
|
+
* @function
|
|
10
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
11
|
+
* @param {StellarWallet} wallet - The wallet used to send the transaction.
|
|
12
|
+
* @param {string} tokenAddress - The address of the Sep41 token to approve.
|
|
13
|
+
* @param {string} spenderAddress - The address of the spender to approve an allowance for.
|
|
14
|
+
* @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
|
|
15
|
+
* @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
|
|
16
|
+
*/
|
|
17
|
+
export declare function approveSep41AllowanceIfInsufficient(network: StellarNetwork, wallet: StellarWallet, tokenAddress: string, spenderAddress: string, allowanceAmount: bigint): Promise<SentTransaction<null> | null>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.approveSep41AllowanceIfInsufficient = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
/**
|
|
6
|
+
* Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
|
|
7
|
+
* Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
|
|
8
|
+
*
|
|
9
|
+
* @async
|
|
10
|
+
* @function
|
|
11
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
12
|
+
* @param {StellarWallet} wallet - The wallet used to send the transaction.
|
|
13
|
+
* @param {string} tokenAddress - The address of the Sep41 token to approve.
|
|
14
|
+
* @param {string} spenderAddress - The address of the spender to approve an allowance for.
|
|
15
|
+
* @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
|
|
16
|
+
* @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
|
|
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
|
+
]);
|
|
27
|
+
if (allowance < allowanceAmount) {
|
|
28
|
+
const latestLedger = await (0, utils_1.getLatestLedger)(network);
|
|
29
|
+
// @TODO find a better to advance the ledger number
|
|
30
|
+
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,
|
|
38
|
+
});
|
|
39
|
+
const result = await tx.signAndSend();
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
exports.approveSep41AllowanceIfInsufficient = approveSep41AllowanceIfInsufficient;
|
|
45
|
+
//# sourceMappingURL=Sep41ContractHelper.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -2,9 +2,11 @@ import { Client as CreditStorageClient } from '@huma-finance/soroban-credit-stor
|
|
|
2
2
|
import { Client as PoolClient } from '@huma-finance/soroban-pool';
|
|
3
3
|
import { Client as PoolCreditClient } from '@huma-finance/soroban-pool-credit';
|
|
4
4
|
import { Client as PoolStorageClient } from '@huma-finance/soroban-pool-storage';
|
|
5
|
+
import { Client as Sep41Client } from '@huma-finance/soroban-sep41';
|
|
5
6
|
import { StellarWallet } from '../services/StellarWallet';
|
|
6
7
|
import { POOL_NAME, StellarNetwork } from './network';
|
|
7
8
|
export declare const getPoolClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolClient | undefined;
|
|
8
9
|
export declare const getPoolStorageClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolStorageClient | undefined;
|
|
9
10
|
export declare const getPoolCreditClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolCreditClient | undefined;
|
|
10
11
|
export declare const getCreditStorageClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => CreditStorageClient | undefined;
|
|
12
|
+
export declare const getUnderlyingTokenClient: (tokenAddress: string, network: StellarNetwork, wallet: StellarWallet) => Sep41Client;
|
package/dist/cjs/utils/client.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCreditStorageClient = exports.getPoolCreditClient = exports.getPoolStorageClient = exports.getPoolClient = void 0;
|
|
3
|
+
exports.getUnderlyingTokenClient = exports.getCreditStorageClient = exports.getPoolCreditClient = exports.getPoolStorageClient = exports.getPoolClient = void 0;
|
|
4
4
|
const soroban_credit_storage_1 = require("@huma-finance/soroban-credit-storage");
|
|
5
5
|
const soroban_pool_1 = require("@huma-finance/soroban-pool");
|
|
6
6
|
const soroban_pool_credit_1 = require("@huma-finance/soroban-pool-credit");
|
|
7
7
|
const soroban_pool_storage_1 = require("@huma-finance/soroban-pool-storage");
|
|
8
|
+
const soroban_sep41_1 = require("@huma-finance/soroban-sep41");
|
|
8
9
|
const common_1 = require("./common");
|
|
9
10
|
const network_1 = require("./network");
|
|
10
11
|
const getCommonProps = (network, wallet) => {
|
|
@@ -60,4 +61,11 @@ const getCreditStorageClient = (poolName, network, wallet) => {
|
|
|
60
61
|
});
|
|
61
62
|
};
|
|
62
63
|
exports.getCreditStorageClient = getCreditStorageClient;
|
|
64
|
+
const getUnderlyingTokenClient = (tokenAddress, network, wallet) => {
|
|
65
|
+
return new soroban_sep41_1.Client({
|
|
66
|
+
contractId: tokenAddress,
|
|
67
|
+
...getCommonProps(network, wallet),
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.getUnderlyingTokenClient = getUnderlyingTokenClient;
|
|
63
71
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/utils/client.ts"],"names":[],"mappings":";;;AAAA,iFAAoF;AACpF,6DAAiE;AACjE,2EAA8E;AAC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 @@
|
|
|
1
|
+
import { SorobanRpc } from '@stellar/stellar-sdk';
|
|
1
2
|
import { StellarNetwork } from './network';
|
|
2
3
|
export declare const findPoolMetadata: (network: StellarNetwork, poolName: string) => import("./network").PoolMetadata | undefined;
|
|
4
|
+
export declare const getLatestLedger: (network: StellarNetwork) => Promise<SorobanRpc.Api.GetLatestLedgerResponse>;
|
package/dist/cjs/utils/common.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findPoolMetadata = void 0;
|
|
3
|
+
exports.getLatestLedger = exports.findPoolMetadata = void 0;
|
|
4
|
+
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
4
5
|
const network_1 = require("./network");
|
|
5
6
|
const findPoolMetadata = (network, poolName) => {
|
|
6
7
|
const selectedNetworkMetadata = network_1.NetworkMetadatas.find((metadata) => metadata.network === network);
|
|
@@ -10,4 +11,11 @@ const findPoolMetadata = (network, poolName) => {
|
|
|
10
11
|
return undefined;
|
|
11
12
|
};
|
|
12
13
|
exports.findPoolMetadata = findPoolMetadata;
|
|
14
|
+
const getLatestLedger = async (network) => {
|
|
15
|
+
const server = new stellar_sdk_1.SorobanRpc.Server(network_1.StellarPublicRpcUrl[network], {
|
|
16
|
+
allowHttp: true,
|
|
17
|
+
});
|
|
18
|
+
return server.getLatestLedger();
|
|
19
|
+
};
|
|
20
|
+
exports.getLatestLedger = getLatestLedger;
|
|
13
21
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AACjD,uCAIkB;AAEX,MAAM,gBAAgB,GAAG,CAAC,OAAuB,EAAE,QAAgB,EAAE,EAAE;IAC5E,MAAM,uBAAuB,GAAG,0BAAgB,CAAC,IAAI,CACnD,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,KAAK,OAAO,CAC3C,CAAA;IACD,IAAI,uBAAuB,EAAE;QAC3B,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,CACvC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CACrC,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAVY,QAAA,gBAAgB,oBAU5B;AAEM,MAAM,eAAe,GAAG,KAAK,EAAE,OAAuB,EAAE,EAAE;IAC/D,MAAM,MAAM,GAAG,IAAI,wBAAU,CAAC,MAAM,CAAC,6BAAmB,CAAC,OAAO,CAAC,EAAE;QACjE,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,eAAe,EAAE,CAAA;AACjC,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B"}
|
|
@@ -17,7 +17,7 @@ export declare enum StellarPublicRpcUrl {
|
|
|
17
17
|
testnet = "https://soroban-testnet.stellar.org",
|
|
18
18
|
futurenet = "https://rpc-futurenet.stellar.org",
|
|
19
19
|
localnet = "http://localhost:8000/soroban/rpc",
|
|
20
|
-
humanet = "
|
|
20
|
+
humanet = "https://dev.stellar.huma.finance/soroban/rpc"
|
|
21
21
|
}
|
|
22
22
|
export declare enum POOL_NAME {
|
|
23
23
|
Arf = "Arf"
|
|
@@ -34,6 +34,7 @@ export type PoolMetadata = {
|
|
|
34
34
|
pool: string;
|
|
35
35
|
poolManager: string;
|
|
36
36
|
poolCredit: string;
|
|
37
|
+
creditManager: string;
|
|
37
38
|
creditStorage: string;
|
|
38
39
|
seniorTranche: string;
|
|
39
40
|
juniorTranche: string;
|
|
@@ -23,7 +23,7 @@ var StellarPublicRpcUrl;
|
|
|
23
23
|
StellarPublicRpcUrl["testnet"] = "https://soroban-testnet.stellar.org";
|
|
24
24
|
StellarPublicRpcUrl["futurenet"] = "https://rpc-futurenet.stellar.org";
|
|
25
25
|
StellarPublicRpcUrl["localnet"] = "http://localhost:8000/soroban/rpc";
|
|
26
|
-
StellarPublicRpcUrl["humanet"] = "
|
|
26
|
+
StellarPublicRpcUrl["humanet"] = "https://dev.stellar.huma.finance/soroban/rpc";
|
|
27
27
|
})(StellarPublicRpcUrl = exports.StellarPublicRpcUrl || (exports.StellarPublicRpcUrl = {}));
|
|
28
28
|
var POOL_NAME;
|
|
29
29
|
(function (POOL_NAME) {
|
|
@@ -43,14 +43,15 @@ exports.NetworkMetadatas = [
|
|
|
43
43
|
poolName: POOL_NAME.Arf,
|
|
44
44
|
poolType: POOL_TYPE.Creditline,
|
|
45
45
|
contracts: {
|
|
46
|
-
humaConfig: '
|
|
47
|
-
poolStorage: '
|
|
48
|
-
pool: '
|
|
49
|
-
poolManager: '
|
|
50
|
-
poolCredit: '
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
humaConfig: 'CAHPEHOIZIIMMTFCZOYEXDKHXJZ2QDYLRD3SF2AZTXWAUV4OWKGHPDCL',
|
|
47
|
+
poolStorage: 'CDL3YWC2SMRK363QPS4AR5TGVFESE3FMIPOGHEQBMJJA3RTQQ2ALW73U',
|
|
48
|
+
pool: 'CCUM2YAJM3EY2RTFMX5P6PDBT7ZZWPNNQLMW4CGIGQJKLTLT7J2SMAMV',
|
|
49
|
+
poolManager: 'CDPNNXOD6LVIXD2VYAH6CKQ6TPQYDITGJ4END7LFLR7OIZNHLCWLF347',
|
|
50
|
+
poolCredit: 'CCRLVVJOUF5MHMKJ36YWRCKPK7YUVDHA7ZNEL6EDSU2LUDHIOMN65S5G',
|
|
51
|
+
creditManager: 'CASGH7RO7Q4H3JOMACIFKIVZDIL7AFHYELXB5JQ6VWTMQ7IMO6GEBRQ5',
|
|
52
|
+
creditStorage: 'CAWXNUPJVXSPZ4WSWURNYYPECL3GDPLLP7LSSBMRXMDGWZ4ZXNIHMITS',
|
|
53
|
+
juniorTranche: 'CAX7J3ZANVPKCW4YSTWUBOUNO667MLH2FQGDURE4RPPI5BWPAO6WCSKZ',
|
|
54
|
+
seniorTranche: 'CAX34UNMKDDDO7IFQO7VZ43UYYWLUILLMU52HDGBBDQFYGQQUCYASOWH',
|
|
54
55
|
},
|
|
55
56
|
},
|
|
56
57
|
],
|
|
@@ -69,6 +70,7 @@ exports.NetworkMetadatas = [
|
|
|
69
70
|
pool: 'CASFU6P33UERVBV7XSWJ6JHKTLZBAYL2UEWRSP77V4F27OHXS4O4OHML',
|
|
70
71
|
poolManager: 'CDBZYAXIHNGPRAHOQU53AILDMSUO5UENFSCNHNT2ABXGLC2MEJ6RPV33',
|
|
71
72
|
poolCredit: 'CAC6ZM2HT2JVNS3TZ2LYVJ6JDR724J2SOV63YIWMP2RSLYA64EB5C7JH',
|
|
73
|
+
creditManager: 'CAC6ZM2HT2JVNS3TZ2LYVJ6JDR724J2SOV63YIWMP2RSLYA64EB5C7JH',
|
|
72
74
|
creditStorage: 'CCPTCRU7FUVQLNR4GGUBWQDHJCQTW3MXDZQYQQGB4OC2PNME7HNIV3R3',
|
|
73
75
|
juniorTranche: 'CD4TNCKN7PDNOBS2JHEXRXPHOL327EX4Z7EURDG2XFWBZ67XG5XW5Q7O',
|
|
74
76
|
seniorTranche: 'CDOB4BPE2AKSZYW27QP4IYVIIGVQD3C7E7YL6XRZ2ANM7MYJT2TKOVPC',
|
|
@@ -85,14 +87,15 @@ exports.NetworkMetadatas = [
|
|
|
85
87
|
poolName: POOL_NAME.Arf,
|
|
86
88
|
poolType: POOL_TYPE.Creditline,
|
|
87
89
|
contracts: {
|
|
88
|
-
humaConfig: '
|
|
89
|
-
poolStorage: '
|
|
90
|
-
pool: '
|
|
91
|
-
poolManager: '
|
|
92
|
-
poolCredit: '
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
humaConfig: 'CD35X6V3O5BVFWYGETHIHRWPJIWYIA3MYHHULBUJLMD4INX6Y34DW3EG',
|
|
91
|
+
poolStorage: 'CARX3M7LZM4QPPR65OGGY36GKEVD2LNV6I7IMB5EHE77XUAQXZHTKX6S',
|
|
92
|
+
pool: 'CBB6RMWO2YBVSV66ZTBXZWEWKEFTFDP4K5YPV6KEMVZN26DNDXQI3JEO',
|
|
93
|
+
poolManager: 'CB6OOMIMGLDYYPI7QEJFKMNZEBMAZG5IF2SK7VTL5B4KE2KJVYKIIZOS',
|
|
94
|
+
poolCredit: 'CBB2X44GZCH2NMW7HQ53PAURLKQT2DOZVIQ3PWYY3YGQIOOUNAV5QACI',
|
|
95
|
+
creditManager: 'CBN6JIEPA4QQKANLMEUICLK24NBEWIG7TPIRGEXDT32WHYLBNHQU67CR',
|
|
96
|
+
creditStorage: 'CBXVWUFZU65MJZWFDMZSRSA6LPRVAUSOYCMVC3YJJXX32TH35MXUZJTN',
|
|
97
|
+
juniorTranche: 'CBWSIQMVG5VVUBTRFGAAXNZQ4AMRVYK2VN3346EP3JYPDZXT6VEOQEK2',
|
|
98
|
+
seniorTranche: 'CBSPGT3IW3PS2CIKVHZKPNA2KZP6EAXFZ3AH4LQ6HN252GGJKBNSIUAW',
|
|
96
99
|
},
|
|
97
100
|
},
|
|
98
101
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../src/utils/network.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;IACnB,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;AACrB,CAAC,EANW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAMzB;AAED,IAAY,wBAMX;AAND,WAAY,wBAAwB;IAClC,sFAA0D,CAAA;IAC1D,yEAA6C,CAAA;IAC7C,gFAAoD,CAAA;IACpD,2EAA+C,CAAA;IAC/C,0EAA8C,CAAA;AAChD,CAAC,EAN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oBAChE,WAAW,EACT,0DAA0D;oBAC5D,UAAU,EACR,0DAA0D;oBAC5D,aAAa,EACX,0DAA0D;oBAC5D,aAAa,EACX,0DAA0D;oBAC5D,aAAa,EACX,0DAA0D;oBAC5D,aAAa,EACX,0DAA0D;iBAC7D;aACF;SACF;KACF;CACF,CAAA"}
|
|
@@ -50,6 +50,17 @@ export declare function getAvailableCreditForPool(poolName: POOL_NAME, network:
|
|
|
50
50
|
* @returns {bigint | null} The account's total due amount in bigint format
|
|
51
51
|
*/
|
|
52
52
|
export declare function getTotalDue(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, borrower: string): Promise<bigint | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Approve allowance for sentinel if not enough allowance is approved.
|
|
55
|
+
*
|
|
56
|
+
* @async
|
|
57
|
+
* @function
|
|
58
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
59
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
60
|
+
* @param {StellarWallet} wallet - The stellar wallet.
|
|
61
|
+
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
62
|
+
*/
|
|
63
|
+
export declare function approveAllowanceForSentinel(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<SentTransaction<null> | null>;
|
|
53
64
|
/**
|
|
54
65
|
* Draws down from a pool.
|
|
55
66
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getCreditStorageClient, getPoolCreditClient, getPoolStorageClient, } from '../utils/client';
|
|
2
|
+
import { approveSep41AllowanceIfInsufficient } from './Sep41ContractHelper';
|
|
2
3
|
/**
|
|
3
4
|
* Returns an soroban contract client instance for the credit line contract
|
|
4
5
|
* associated with the given pool name on the current chain.
|
|
@@ -104,6 +105,32 @@ export async function getTotalDue(poolName, network, wallet, borrower) {
|
|
|
104
105
|
}
|
|
105
106
|
return creditRecord.next_due + creditRecord.total_past_due;
|
|
106
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Approve allowance for sentinel if not enough allowance is approved.
|
|
110
|
+
*
|
|
111
|
+
* @async
|
|
112
|
+
* @function
|
|
113
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
114
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
115
|
+
* @param {StellarWallet} wallet - The stellar wallet.
|
|
116
|
+
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
117
|
+
*/
|
|
118
|
+
export async function approveAllowanceForSentinel(poolName, network, wallet) {
|
|
119
|
+
const totalDue = await getTotalDue(poolName, network, wallet, wallet.userInfo.publicKey);
|
|
120
|
+
if (totalDue === null) {
|
|
121
|
+
throw new Error('Could not find total due');
|
|
122
|
+
}
|
|
123
|
+
const poolStorageClient = getPoolStorageClient(poolName, network, wallet);
|
|
124
|
+
if (!poolStorageClient) {
|
|
125
|
+
throw new Error('Could not find pool storage contract for pool');
|
|
126
|
+
}
|
|
127
|
+
const [{ result: underlyingToken }, { result: sentinel }] = await Promise.all([
|
|
128
|
+
poolStorageClient.get_underlying_token(),
|
|
129
|
+
poolStorageClient.get_sentinel(),
|
|
130
|
+
]);
|
|
131
|
+
const tx = await approveSep41AllowanceIfInsufficient(network, wallet, underlyingToken, sentinel, totalDue);
|
|
132
|
+
return tx;
|
|
133
|
+
}
|
|
107
134
|
/**
|
|
108
135
|
* Draws down from a pool.
|
|
109
136
|
*
|
|
@@ -120,6 +147,7 @@ export async function drawdown(poolName, network, wallet, drawdownAmount) {
|
|
|
120
147
|
if (!poolCreditClient) {
|
|
121
148
|
throw new Error('Could not find credit contract for pool');
|
|
122
149
|
}
|
|
150
|
+
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
123
151
|
const tx = await poolCreditClient.drawdown({
|
|
124
152
|
borrower: wallet.userInfo.publicKey,
|
|
125
153
|
amount: drawdownAmount,
|
|
@@ -146,7 +174,17 @@ export async function makePayment(poolName, network, wallet, paymentAmount, prin
|
|
|
146
174
|
if (!poolCreditClient) {
|
|
147
175
|
throw new Error('Could not find credit contract for pool');
|
|
148
176
|
}
|
|
177
|
+
const poolStorageClient = getPoolStorageClient(poolName, network, wallet);
|
|
178
|
+
if (!poolStorageClient) {
|
|
179
|
+
throw new Error('Could not find pool storage contract for pool');
|
|
180
|
+
}
|
|
181
|
+
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
182
|
+
const [{ result: underlyingToken }, { result: sentinel }] = await Promise.all([
|
|
183
|
+
poolStorageClient.get_underlying_token(),
|
|
184
|
+
poolStorageClient.get_sentinel(),
|
|
185
|
+
]);
|
|
149
186
|
let tx;
|
|
187
|
+
tx = await approveSep41AllowanceIfInsufficient(network, wallet, underlyingToken, sentinel, paymentAmount);
|
|
150
188
|
if (principalOnly) {
|
|
151
189
|
tx = await poolCreditClient.make_principal_payment({
|
|
152
190
|
borrower: wallet.userInfo.publicKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,mCAAmC,EAAE,MAAM,uBAAuB,CAAA;AAE3E;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAmB,EACnB,OAAuB,EACvB,MAAqB;IAErB,OAAO,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,QAAmB,EACnB,OAAuB,EACvB,MAAqB;IAErB,MAA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,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SentTransaction } from '@huma-finance/soroban-pool-credit';
|
|
2
|
+
import { StellarWallet } from '../services';
|
|
3
|
+
import { StellarNetwork } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
|
|
6
|
+
* Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
|
|
7
|
+
*
|
|
8
|
+
* @async
|
|
9
|
+
* @function
|
|
10
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
11
|
+
* @param {StellarWallet} wallet - The wallet used to send the transaction.
|
|
12
|
+
* @param {string} tokenAddress - The address of the Sep41 token to approve.
|
|
13
|
+
* @param {string} spenderAddress - The address of the spender to approve an allowance for.
|
|
14
|
+
* @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
|
|
15
|
+
* @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
|
|
16
|
+
*/
|
|
17
|
+
export declare function approveSep41AllowanceIfInsufficient(network: StellarNetwork, wallet: StellarWallet, tokenAddress: string, spenderAddress: string, allowanceAmount: bigint): Promise<SentTransaction<null> | null>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getLatestLedger, getUnderlyingTokenClient, } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Approves an Sep41 allowance for a spender address, if the current allowance is insufficient.
|
|
4
|
+
* Allowance is required to do certain actions on the Huma protocol (e.g. makePayment for Autopay)
|
|
5
|
+
*
|
|
6
|
+
* @async
|
|
7
|
+
* @function
|
|
8
|
+
* @param {StellarNetwork} network - The stellar network.
|
|
9
|
+
* @param {StellarWallet} wallet - The wallet used to send the transaction.
|
|
10
|
+
* @param {string} tokenAddress - The address of the Sep41 token to approve.
|
|
11
|
+
* @param {string} spenderAddress - The address of the spender to approve an allowance for.
|
|
12
|
+
* @param {bigint} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the Sep41 tokens.
|
|
13
|
+
* @returns {Promise<SentTransaction<null> | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
|
|
14
|
+
*/
|
|
15
|
+
export async function approveSep41AllowanceIfInsufficient(network, wallet, tokenAddress, spenderAddress, allowanceAmount) {
|
|
16
|
+
const tokenClient = getUnderlyingTokenClient(tokenAddress, network, wallet);
|
|
17
|
+
const [{ result: allowance }, { result: decimals }] = await Promise.all([
|
|
18
|
+
tokenClient.allowance({
|
|
19
|
+
from: wallet.userInfo.publicKey,
|
|
20
|
+
spender: spenderAddress,
|
|
21
|
+
}),
|
|
22
|
+
tokenClient.decimals(),
|
|
23
|
+
]);
|
|
24
|
+
if (allowance < allowanceAmount) {
|
|
25
|
+
const latestLedger = await getLatestLedger(network);
|
|
26
|
+
// @TODO find a better to advance the ledger number
|
|
27
|
+
const advanceLedgerNum = 3000000;
|
|
28
|
+
const tx = await tokenClient.approve({
|
|
29
|
+
from: wallet.userInfo.publicKey,
|
|
30
|
+
spender: spenderAddress,
|
|
31
|
+
amount: BigInt(1000000000 * Math.pow(10, Number(decimals))),
|
|
32
|
+
expiration_ledger: latestLedger.sequence + advanceLedgerNum,
|
|
33
|
+
}, {
|
|
34
|
+
timeoutInSeconds: 30,
|
|
35
|
+
});
|
|
36
|
+
const result = await tx.signAndSend();
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Sep41ContractHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sep41ContractHelper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