@huma-finance/soroban-sdk 0.0.15-beta.39 → 0.0.15
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/dist/cjs/helpers/CreditContractHelper.d.ts +13 -3
- package/dist/cjs/helpers/CreditContractHelper.js +91 -107
- package/dist/cjs/helpers/CreditContractHelper.js.map +1 -1
- package/dist/cjs/helpers/Sep41ContractHelper.d.ts +3 -3
- package/dist/cjs/helpers/Sep41ContractHelper.js +18 -49
- package/dist/cjs/helpers/Sep41ContractHelper.js.map +1 -1
- package/dist/cjs/services/StellarWallet.d.ts +1 -3
- package/dist/cjs/services/StellarWallet.js +3 -10
- package/dist/cjs/services/StellarWallet.js.map +1 -1
- package/dist/cjs/utils/client.d.ts +3 -12
- package/dist/cjs/utils/client.js +4 -58
- package/dist/cjs/utils/client.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +1 -14
- package/dist/cjs/utils/common.js +1 -41
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +0 -1
- package/dist/cjs/utils/index.js +0 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/network.d.ts +2 -5
- package/dist/cjs/utils/network.js +19 -48
- package/dist/cjs/utils/network.js.map +1 -1
- package/dist/helpers/CreditContractHelper.d.ts +13 -3
- package/dist/helpers/CreditContractHelper.js +89 -106
- package/dist/helpers/CreditContractHelper.js.map +1 -1
- package/dist/helpers/Sep41ContractHelper.d.ts +3 -3
- package/dist/helpers/Sep41ContractHelper.js +19 -50
- package/dist/helpers/Sep41ContractHelper.js.map +1 -1
- package/dist/services/StellarWallet.d.ts +1 -3
- package/dist/services/StellarWallet.js +3 -10
- package/dist/services/StellarWallet.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/client.d.ts +3 -12
- package/dist/utils/client.js +3 -56
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/common.d.ts +1 -14
- package/dist/utils/common.js +1 -40
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/network.d.ts +2 -5
- package/dist/utils/network.js +19 -48
- package/dist/utils/network.js.map +1 -1
- package/package.json +11 -11
- package/dist/cjs/utils/transaction.d.ts +0 -25
- package/dist/cjs/utils/transaction.js +0 -125
- package/dist/cjs/utils/transaction.js.map +0 -1
- package/dist/utils/transaction.d.ts +0 -25
- package/dist/utils/transaction.js +0 -117
- package/dist/utils/transaction.js.map +0 -1
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { CreditRecord } from '@huma-finance/soroban-pool-credit';
|
|
1
|
+
import { Client as PoolCreditClient, CreditRecord } from '@huma-finance/soroban-pool-credit';
|
|
2
2
|
import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
|
|
3
|
-
import { StellarWallet } from '../services';
|
|
4
|
-
import { POOL_NAME, StellarNetwork } from '../utils';
|
|
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;
|
|
5
15
|
/**
|
|
6
16
|
* Returns the current pool balance available for borrowing
|
|
7
17
|
*
|
|
@@ -1,8 +1,21 @@
|
|
|
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 = void 0;
|
|
4
|
-
const
|
|
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");
|
|
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;
|
|
6
19
|
/**
|
|
7
20
|
* Returns the current pool balance available for borrowing
|
|
8
21
|
*
|
|
@@ -11,11 +24,11 @@ const Sep41ContractHelper_1 = require("./Sep41ContractHelper");
|
|
|
11
24
|
* @param {StellarWallet} wallet - The stellar wallet.
|
|
12
25
|
*/
|
|
13
26
|
async function getAvailableBalanceForPool(poolName, network, wallet) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
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();
|
|
19
32
|
return result;
|
|
20
33
|
}
|
|
21
34
|
exports.getAvailableBalanceForPool = getAvailableBalanceForPool;
|
|
@@ -28,31 +41,18 @@ exports.getAvailableBalanceForPool = getAvailableBalanceForPool;
|
|
|
28
41
|
* @param {string} borrower - The address of the borrower to check the credit record for.
|
|
29
42
|
*/
|
|
30
43
|
async function getCreditRecordForPool(poolName, network, wallet, borrower) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
name: 'borrower',
|
|
38
|
-
type: utils_1.ScValType.address,
|
|
39
|
-
value: borrower,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
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,
|
|
42
50
|
});
|
|
43
51
|
if (!creditHash) {
|
|
44
52
|
throw new Error('Could not find credit hash');
|
|
45
53
|
}
|
|
46
|
-
const { result: creditRecord } = await
|
|
47
|
-
|
|
48
|
-
method: 'get_credit_record',
|
|
49
|
-
params: [
|
|
50
|
-
{
|
|
51
|
-
name: 'credit_hash',
|
|
52
|
-
type: utils_1.ScValType.buffer,
|
|
53
|
-
value: creditHash,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
54
|
+
const { result: creditRecord } = await creditStorageClient.get_credit_record({
|
|
55
|
+
credit_hash: creditHash,
|
|
56
56
|
});
|
|
57
57
|
if (!creditRecord) {
|
|
58
58
|
throw new Error('Could not find credit record');
|
|
@@ -71,36 +71,24 @@ 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
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
name: 'borrower',
|
|
81
|
-
type: utils_1.ScValType.address,
|
|
82
|
-
value: borrower,
|
|
83
|
-
},
|
|
84
|
-
],
|
|
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,
|
|
85
80
|
});
|
|
86
81
|
if (!creditHash) {
|
|
87
82
|
throw new Error('Could not find credit hash');
|
|
88
83
|
}
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
});
|
|
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
|
+
]);
|
|
104
92
|
if (!creditConfig || !creditRecord) {
|
|
105
93
|
throw new Error('Could not find credit config or credit record');
|
|
106
94
|
}
|
|
@@ -140,12 +128,15 @@ async function approveAllowanceForSentinel(poolName, network, wallet) {
|
|
|
140
128
|
if (totalDue === null) {
|
|
141
129
|
throw new Error('Could not find total due');
|
|
142
130
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
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);
|
|
149
140
|
return tx;
|
|
150
141
|
}
|
|
151
142
|
exports.approveAllowanceForSentinel = approveAllowanceForSentinel;
|
|
@@ -161,25 +152,18 @@ exports.approveAllowanceForSentinel = approveAllowanceForSentinel;
|
|
|
161
152
|
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
162
153
|
*/
|
|
163
154
|
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
|
+
}
|
|
164
159
|
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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,
|
|
160
|
+
const tx = await poolCreditClient.drawdown({
|
|
161
|
+
borrower: wallet.userInfo.publicKey,
|
|
162
|
+
amount: drawdownAmount,
|
|
163
|
+
}, {
|
|
164
|
+
timeoutInSeconds: 30,
|
|
182
165
|
});
|
|
166
|
+
const result = await tx.signAndSend();
|
|
183
167
|
return result;
|
|
184
168
|
}
|
|
185
169
|
exports.drawdown = drawdown;
|
|
@@ -196,39 +180,39 @@ exports.drawdown = drawdown;
|
|
|
196
180
|
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
197
181
|
*/
|
|
198
182
|
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
|
+
}
|
|
199
191
|
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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,
|
|
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,
|
|
224
204
|
});
|
|
225
205
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const result = await tx.signAndSend();
|
|
232
216
|
return result;
|
|
233
217
|
}
|
|
234
218
|
exports.makePayment = makePayment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;;AAMA,4CAIwB;AAExB,+DAA2E;AAE3E;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CACjC,QAAmB,EACnB,OAAuB,EACvB,MAAqB;IAErB,OAAO,IAAA,4BAAmB,EAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AACvD,CAAC;AAND,kDAMC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,0BAA0B,CAC9C,QAAmB,EACnB,OAAuB,EACvB,MAAqB;IAErB,MAAM,iBAAiB,GAAG,IAAA,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A;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,17 +1,17 @@
|
|
|
1
1
|
import { SentTransaction } from '@stellar/stellar-sdk/lib/contract';
|
|
2
2
|
import { StellarWallet } from '../services';
|
|
3
|
-
import {
|
|
3
|
+
import { 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.
|
|
11
10
|
* @param {StellarNetwork} network - The stellar network.
|
|
12
11
|
* @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(
|
|
17
|
+
export declare function approveSep41AllowanceIfInsufficient(network: StellarNetwork, wallet: StellarWallet, tokenAddress: string, spenderAddress: string, allowanceAmount: bigint): Promise<SentTransaction<null> | null>;
|
|
@@ -8,66 +8,35 @@ 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.
|
|
12
11
|
* @param {StellarNetwork} network - The stellar network.
|
|
13
12
|
* @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(
|
|
19
|
-
const
|
|
20
|
-
const { result: allowance } = await
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
});
|
|
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
|
+
]);
|
|
40
27
|
if (allowance < allowanceAmount) {
|
|
41
28
|
const latestLedger = await (0, utils_1.getLatestLedger)(network);
|
|
42
29
|
// @TODO find a better to advance the ledger number
|
|
43
30
|
const advanceLedgerNum = 3000000;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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,
|
|
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,
|
|
70
38
|
});
|
|
39
|
+
const result = await tx.signAndSend();
|
|
71
40
|
return result;
|
|
72
41
|
}
|
|
73
42
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sep41ContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/Sep41ContractHelper.ts"],"names":[],"mappings":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"Sep41ContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/Sep41ContractHelper.ts"],"names":[],"mappings":";;;AAGA,o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;
|
|
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 {
|
|
8
6
|
constructor(secretKey) {
|
|
9
|
-
|
|
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");
|
|
7
|
+
this.sourceKeypair = stellar_sdk_1.Keypair.fromSecret(secretKey);
|
|
14
8
|
}
|
|
15
9
|
get userInfo() {
|
|
16
10
|
return {
|
|
17
|
-
publicKey:
|
|
11
|
+
publicKey: this.sourceKeypair.publicKey(),
|
|
18
12
|
};
|
|
19
13
|
}
|
|
20
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
15
|
async signTransaction(tx, opts) {
|
|
22
16
|
const txFromXDR = new stellar_sdk_1.Transaction(tx, opts.networkPassphrase);
|
|
23
|
-
txFromXDR.sign(
|
|
17
|
+
txFromXDR.sign(this.sourceKeypair);
|
|
24
18
|
return txFromXDR.toXDR();
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
exports.StellarWallet = StellarWallet;
|
|
28
|
-
_StellarWallet_sourceKeypair = new WeakMap();
|
|
29
22
|
//# sourceMappingURL=StellarWallet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarWallet.js","sourceRoot":"","sources":["../../../src/services/StellarWallet.ts"],"names":[],"mappings":"
|
|
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,13 +1,12 @@
|
|
|
1
|
-
import { Client as CreditManagerClient } from '@huma-finance/soroban-credit-manager';
|
|
2
1
|
import { Client as CreditStorageClient } from '@huma-finance/soroban-credit-storage';
|
|
2
|
+
import { Client as CreditManagerClient } from '@huma-finance/soroban-credit-manager';
|
|
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 Sep41Client } from '@huma-finance/soroban-sep41';
|
|
7
6
|
import { Client as TrancheVaultClient } from '@huma-finance/soroban-tranche-vault';
|
|
7
|
+
import { Client as Sep41Client } from '@huma-finance/soroban-sep41';
|
|
8
8
|
import { StellarWallet } from '../services/StellarWallet';
|
|
9
|
-
import {
|
|
10
|
-
export type Client = PoolCreditClient | CreditStorageClient | CreditManagerClient | PoolClient | PoolStorageClient | TrancheVaultClient | Sep41Client;
|
|
9
|
+
import { POOL_NAME, StellarNetwork } from './network';
|
|
11
10
|
export declare const getPoolClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolClient | undefined;
|
|
12
11
|
export declare const getPoolStorageClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolStorageClient | undefined;
|
|
13
12
|
export declare const getPoolCreditClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => PoolCreditClient | undefined;
|
|
@@ -15,11 +14,3 @@ export declare const getCreditStorageClient: (poolName: POOL_NAME, network: Stel
|
|
|
15
14
|
export declare const getCreditManagerClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet) => CreditManagerClient | undefined;
|
|
16
15
|
export declare const getTrancheVaultClient: (poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, tranche: 'senior' | 'junior') => TrancheVaultClient | undefined;
|
|
17
16
|
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
|
-
}
|
package/dist/cjs/utils/client.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _TransactionContext_client, _TransactionContext_wallet, _TransactionContext_network, _TransactionContext_contractId;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const soroban_credit_manager_1 = require("@huma-finance/soroban-credit-manager");
|
|
3
|
+
exports.getUnderlyingTokenClient = exports.getTrancheVaultClient = exports.getCreditManagerClient = exports.getCreditStorageClient = exports.getPoolCreditClient = exports.getPoolStorageClient = exports.getPoolClient = void 0;
|
|
7
4
|
const soroban_credit_storage_1 = require("@huma-finance/soroban-credit-storage");
|
|
5
|
+
const soroban_credit_manager_1 = require("@huma-finance/soroban-credit-manager");
|
|
8
6
|
const soroban_pool_1 = require("@huma-finance/soroban-pool");
|
|
9
7
|
const soroban_pool_credit_1 = require("@huma-finance/soroban-pool-credit");
|
|
10
8
|
const soroban_pool_storage_1 = require("@huma-finance/soroban-pool-storage");
|
|
11
|
-
const soroban_sep41_1 = require("@huma-finance/soroban-sep41");
|
|
12
9
|
const soroban_tranche_vault_1 = require("@huma-finance/soroban-tranche-vault");
|
|
10
|
+
const soroban_sep41_1 = require("@huma-finance/soroban-sep41");
|
|
13
11
|
const common_1 = require("./common");
|
|
14
12
|
const network_1 = require("./network");
|
|
15
|
-
const ClientMap = {
|
|
16
|
-
poolCredit: soroban_pool_credit_1.Client,
|
|
17
|
-
creditStorage: soroban_credit_storage_1.Client,
|
|
18
|
-
creditManager: soroban_credit_manager_1.Client,
|
|
19
|
-
pool: soroban_pool_1.Client,
|
|
20
|
-
poolStorage: soroban_pool_storage_1.Client,
|
|
21
|
-
juniorTranche: soroban_tranche_vault_1.Client,
|
|
22
|
-
seniorTranche: soroban_tranche_vault_1.Client,
|
|
23
|
-
underlyingToken: soroban_sep41_1.Client,
|
|
24
|
-
};
|
|
25
13
|
const getCommonProps = (network, wallet) => {
|
|
26
14
|
return {
|
|
27
15
|
publicKey: wallet.userInfo.publicKey,
|
|
@@ -88,7 +76,7 @@ const getCreditManagerClient = (poolName, network, wallet) => {
|
|
|
88
76
|
exports.getCreditManagerClient = getCreditManagerClient;
|
|
89
77
|
const getTrancheVaultClient = (poolName, network, wallet, tranche) => {
|
|
90
78
|
const poolMetadata = (0, common_1.findPoolMetadata)(network, poolName);
|
|
91
|
-
if (!poolMetadata
|
|
79
|
+
if (!poolMetadata) {
|
|
92
80
|
return undefined;
|
|
93
81
|
}
|
|
94
82
|
return new soroban_tranche_vault_1.Client({
|
|
@@ -104,46 +92,4 @@ const getUnderlyingTokenClient = (tokenAddress, network, wallet) => {
|
|
|
104
92
|
});
|
|
105
93
|
};
|
|
106
94
|
exports.getUnderlyingTokenClient = getUnderlyingTokenClient;
|
|
107
|
-
class TransactionContext {
|
|
108
|
-
constructor(poolName, network, wallet, contractType) {
|
|
109
|
-
_TransactionContext_client.set(this, void 0);
|
|
110
|
-
_TransactionContext_wallet.set(this, void 0);
|
|
111
|
-
_TransactionContext_network.set(this, void 0);
|
|
112
|
-
_TransactionContext_contractId.set(this, void 0);
|
|
113
|
-
const poolMetadata = (0, common_1.findPoolMetadata)(network, poolName);
|
|
114
|
-
if (!poolMetadata) {
|
|
115
|
-
throw new Error(`Could not find pool metadata by pool name: ${poolName}`);
|
|
116
|
-
}
|
|
117
|
-
if (!poolMetadata.contracts[contractType]) {
|
|
118
|
-
throw new Error(`Could not find contract by contract type: ${contractType}`);
|
|
119
|
-
}
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
const clientClass = ClientMap[contractType];
|
|
122
|
-
if (!clientClass) {
|
|
123
|
-
throw new Error(`Could not find client by contract type: ${contractType}`);
|
|
124
|
-
}
|
|
125
|
-
const client = new clientClass({
|
|
126
|
-
contractId: poolMetadata.contracts[contractType],
|
|
127
|
-
...getCommonProps(network, wallet),
|
|
128
|
-
});
|
|
129
|
-
tslib_1.__classPrivateFieldSet(this, _TransactionContext_client, client, "f");
|
|
130
|
-
tslib_1.__classPrivateFieldSet(this, _TransactionContext_wallet, wallet, "f");
|
|
131
|
-
tslib_1.__classPrivateFieldSet(this, _TransactionContext_network, network, "f");
|
|
132
|
-
tslib_1.__classPrivateFieldSet(this, _TransactionContext_contractId, client.options.contractId, "f");
|
|
133
|
-
}
|
|
134
|
-
get client() {
|
|
135
|
-
return tslib_1.__classPrivateFieldGet(this, _TransactionContext_client, "f");
|
|
136
|
-
}
|
|
137
|
-
get wallet() {
|
|
138
|
-
return tslib_1.__classPrivateFieldGet(this, _TransactionContext_wallet, "f");
|
|
139
|
-
}
|
|
140
|
-
get network() {
|
|
141
|
-
return tslib_1.__classPrivateFieldGet(this, _TransactionContext_network, "f");
|
|
142
|
-
}
|
|
143
|
-
get contractId() {
|
|
144
|
-
return tslib_1.__classPrivateFieldGet(this, _TransactionContext_contractId, "f");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.TransactionContext = TransactionContext;
|
|
148
|
-
_TransactionContext_client = new WeakMap(), _TransactionContext_wallet = new WeakMap(), _TransactionContext_network = new WeakMap(), _TransactionContext_contractId = new WeakMap();
|
|
149
95
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/utils/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/utils/client.ts"],"names":[],"mappings":";;;AAAA,iFAAoF;AACpF,iFAAoF;AACpF,6DAAiE;AACjE,2EAA8E;AAC9E,6EAAgF;AAChF,+EAAkF;AAClF,+DAAmE;AAGnE,qCAA2C;AAC3C,uCAKkB;AAElB,MAAM,cAAc,GAAG,CAAC,OAAuB,EAAE,MAAqB,EAAE,EAAE;IACxE,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;QACpC,iBAAiB,EAAE,kCAAwB,CAAC,OAAO,CAAC;QACpD,MAAM,EAAE,6BAAmB,CAAC,OAAO,CAAC;QACpC,SAAS,EAAE,6BAAmB,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;QAC7D,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;KACrD,CAAA;AACH,CAAC,CAAA;AAEM,MAAM,aAAa,GAAG,CAC3B,QAAmB,EACnB,OAAuB,EACvB,MAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,IAAA,yBAAgB,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACxD,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO,SAAS,CAAA;KACjB;IAED,OAAO,IAAI,qBAAU,CAAC;QACpB,UAAU,EAAE,YAAY,CAAC,SAAS,CAAC,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