@huma-finance/soroban-sdk 0.0.11-beta.12 → 0.0.11-beta.17
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/getting-started.md +158 -0
- package/package.json +11 -11
- package/dist/cjs/helpers/CreditContractHelper.d.ts +0 -88
- package/dist/cjs/helpers/CreditContractHelper.js +0 -219
- package/dist/cjs/helpers/CreditContractHelper.js.map +0 -1
- package/dist/cjs/helpers/Sep41ContractHelper.d.ts +0 -17
- package/dist/cjs/helpers/Sep41ContractHelper.js +0 -45
- package/dist/cjs/helpers/Sep41ContractHelper.js.map +0 -1
- package/dist/cjs/helpers/index.d.ts +0 -1
- package/dist/cjs/helpers/index.js +0 -5
- package/dist/cjs/helpers/index.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/services/HumaContextStellar.d.ts +0 -19
- package/dist/cjs/services/HumaContextStellar.js +0 -47
- package/dist/cjs/services/HumaContextStellar.js.map +0 -1
- package/dist/cjs/services/StellarWallet.d.ts +0 -8
- package/dist/cjs/services/StellarWallet.js +0 -22
- package/dist/cjs/services/StellarWallet.js.map +0 -1
- package/dist/cjs/services/index.d.ts +0 -2
- package/dist/cjs/services/index.js +0 -6
- package/dist/cjs/services/index.js.map +0 -1
- package/dist/cjs/utils/client.d.ts +0 -12
- package/dist/cjs/utils/client.js +0 -71
- package/dist/cjs/utils/client.js.map +0 -1
- package/dist/cjs/utils/common.d.ts +0 -4
- package/dist/cjs/utils/common.js +0 -21
- package/dist/cjs/utils/common.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -3
- package/dist/cjs/utils/index.js +0 -7
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/network.d.ts +0 -49
- package/dist/cjs/utils/network.js +0 -104
- package/dist/cjs/utils/network.js.map +0 -1
- package/dist/helpers/CreditContractHelper.d.ts +0 -88
- package/dist/helpers/CreditContractHelper.js +0 -208
- package/dist/helpers/CreditContractHelper.js.map +0 -1
- package/dist/helpers/Sep41ContractHelper.d.ts +0 -17
- package/dist/helpers/Sep41ContractHelper.js +0 -41
- package/dist/helpers/Sep41ContractHelper.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.js +0 -2
- package/dist/helpers/index.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/services/HumaContextStellar.d.ts +0 -19
- package/dist/services/HumaContextStellar.js +0 -43
- package/dist/services/HumaContextStellar.js.map +0 -1
- package/dist/services/StellarWallet.d.ts +0 -8
- package/dist/services/StellarWallet.js +0 -18
- package/dist/services/StellarWallet.js.map +0 -1
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.js +0 -3
- package/dist/services/index.js.map +0 -1
- package/dist/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist/utils/client.d.ts +0 -12
- package/dist/utils/client.js +0 -63
- package/dist/utils/client.js.map +0 -1
- package/dist/utils/common.d.ts +0 -4
- package/dist/utils/common.js +0 -16
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -4
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/network.d.ts +0 -49
- package/dist/utils/network.js +0 -101
- package/dist/utils/network.js.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
In this guide we'll take a look at using Huma's Soroban SDK to call functions on our pool, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Huma's Soroban SDK can be installed using npm or yarn.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @huma-finance/soroban-sdk
|
|
11
|
+
yarn add @huma-finance/soroban-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Approve lender
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import {
|
|
18
|
+
getTrancheVaultClient,
|
|
19
|
+
POOL_NAME,
|
|
20
|
+
StellarNetwork,
|
|
21
|
+
StellarWallet,
|
|
22
|
+
} from '@huma-finance/soroban-sdk'
|
|
23
|
+
|
|
24
|
+
const poolName = POOL_NAME.Arf
|
|
25
|
+
const network = StellarNetwork.testnet
|
|
26
|
+
const poolOperator = new StellarWallet(process.env.POOL_OPERATOR_SECRET_KEY)
|
|
27
|
+
const lender = new StellarWallet(process.env.LENDER_SECRET_KEY)
|
|
28
|
+
|
|
29
|
+
const trancheVaultClient = getTrancheVaultClient(
|
|
30
|
+
poolName,
|
|
31
|
+
network,
|
|
32
|
+
poolOperator,
|
|
33
|
+
'junior',
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if (trancheVaultClient) {
|
|
37
|
+
const tx = await trancheVaultClient.add_approved_lender(
|
|
38
|
+
{
|
|
39
|
+
caller: poolOperator.userInfo.publicKey,
|
|
40
|
+
lender: lender.userInfo.publicKey,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
timeoutInSeconds: 30,
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
await tx.signAndSend()
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Deposit
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
import {
|
|
54
|
+
getTrancheVaultClient,
|
|
55
|
+
POOL_NAME,
|
|
56
|
+
StellarNetwork,
|
|
57
|
+
StellarWallet,
|
|
58
|
+
} from '@huma-finance/soroban-sdk'
|
|
59
|
+
|
|
60
|
+
const poolName = POOL_NAME.Arf
|
|
61
|
+
const network = StellarNetwork.testnet
|
|
62
|
+
const lender = new StellarWallet(process.env.LENDER_SECRET_KEY)
|
|
63
|
+
|
|
64
|
+
const trancheVaultClient = getTrancheVaultClient(
|
|
65
|
+
poolName,
|
|
66
|
+
network,
|
|
67
|
+
lender,
|
|
68
|
+
'junior',
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
if (trancheVaultClient) {
|
|
72
|
+
const depositAmount = 100000000n
|
|
73
|
+
const tx = await trancheVaultClient.deposit(
|
|
74
|
+
{
|
|
75
|
+
lender: lender.userInfo.publicKey,
|
|
76
|
+
assets: depositAmount,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
timeoutInSeconds: 30,
|
|
80
|
+
},
|
|
81
|
+
)
|
|
82
|
+
await tx.signAndSend()
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Approve borrower
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
import {
|
|
90
|
+
getCreditManagerClient,
|
|
91
|
+
POOL_NAME,
|
|
92
|
+
StellarNetwork,
|
|
93
|
+
StellarWallet,
|
|
94
|
+
} from '@huma-finance/soroban-sdk'
|
|
95
|
+
|
|
96
|
+
const poolName = POOL_NAME.Arf
|
|
97
|
+
const network = StellarNetwork.testnet
|
|
98
|
+
const ea = new StellarWallet(process.env.EA_SECRET_KEY)
|
|
99
|
+
const borrower = new StellarWallet(process.env.BORROWER_SECRET_KEY)
|
|
100
|
+
|
|
101
|
+
const creditManagerClient = getCreditManagerClient(poolName, network, ea)
|
|
102
|
+
|
|
103
|
+
if (creditManagerClient) {
|
|
104
|
+
const tx = await creditManagerClient.approve_borrower(
|
|
105
|
+
{
|
|
106
|
+
borrower: borrower.userInfo.publicKey,
|
|
107
|
+
credit_limit: 1000_0000000n,
|
|
108
|
+
num_periods: 5,
|
|
109
|
+
yield_bps: 1200,
|
|
110
|
+
committed_amount: 0n,
|
|
111
|
+
designated_start_date: 0n,
|
|
112
|
+
revolving: true,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
timeoutInSeconds: 30,
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
await tx.signAndSend()
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Borrower drawdown and makePayment
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
import {
|
|
126
|
+
drawdown,
|
|
127
|
+
makePayment,
|
|
128
|
+
POOL_NAME,
|
|
129
|
+
StellarNetwork,
|
|
130
|
+
StellarWallet,
|
|
131
|
+
} from '@huma-finance/soroban-sdk'
|
|
132
|
+
|
|
133
|
+
const poolName = POOL_NAME.Arf
|
|
134
|
+
const network = StellarNetwork.testnet
|
|
135
|
+
const borrower = new StellarWallet(process.env.BORROWER_SECRET_KEY)
|
|
136
|
+
|
|
137
|
+
const borrowAmount = 100_0000000n
|
|
138
|
+
const drawdownResult = await drawdown(poolName, network, borrower, borrowAmount)
|
|
139
|
+
console.log(
|
|
140
|
+
`Drawdown success. Tx hash: ${drawdownResult.sendTransactionResponse?.hash}`,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
const paymentAmount = 100_0000000n
|
|
144
|
+
const makePaymentResult = await makePayment(
|
|
145
|
+
poolName,
|
|
146
|
+
network,
|
|
147
|
+
borrower,
|
|
148
|
+
paymentAmount,
|
|
149
|
+
true,
|
|
150
|
+
)
|
|
151
|
+
console.log(
|
|
152
|
+
`Payment success. Tx hash: ${makePaymentResult.sendTransactionResponse?.hash}`,
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Next steps
|
|
157
|
+
|
|
158
|
+
If you want to learn more about the different functions and helpers available in the Huma SDK, please check out our [API documentation](API.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/soroban-sdk",
|
|
3
|
-
"version": "0.0.11-beta.
|
|
3
|
+
"version": "0.0.11-beta.17+b42c649",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"binding": "ts-node --project ./tsconfig.script.json scripts/bindings.ts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@huma-finance/soroban-credit-manager": "^0.0.
|
|
31
|
-
"@huma-finance/soroban-credit-storage": "^0.0.
|
|
32
|
-
"@huma-finance/soroban-huma-config": "^0.0.
|
|
33
|
-
"@huma-finance/soroban-pool": "^0.0.
|
|
34
|
-
"@huma-finance/soroban-pool-credit": "^0.0.
|
|
35
|
-
"@huma-finance/soroban-pool-manager": "^0.0.
|
|
36
|
-
"@huma-finance/soroban-pool-storage": "^0.0.
|
|
37
|
-
"@huma-finance/soroban-sep41": "^0.0.
|
|
38
|
-
"@huma-finance/soroban-tranche-vault": "^0.0.
|
|
30
|
+
"@huma-finance/soroban-credit-manager": "^0.0.11-beta.17+b42c649",
|
|
31
|
+
"@huma-finance/soroban-credit-storage": "^0.0.11-beta.17+b42c649",
|
|
32
|
+
"@huma-finance/soroban-huma-config": "^0.0.11-beta.17+b42c649",
|
|
33
|
+
"@huma-finance/soroban-pool": "^0.0.11-beta.17+b42c649",
|
|
34
|
+
"@huma-finance/soroban-pool-credit": "^0.0.11-beta.17+b42c649",
|
|
35
|
+
"@huma-finance/soroban-pool-manager": "^0.0.11-beta.17+b42c649",
|
|
36
|
+
"@huma-finance/soroban-pool-storage": "^0.0.11-beta.17+b42c649",
|
|
37
|
+
"@huma-finance/soroban-sep41": "^0.0.11-beta.17+b42c649",
|
|
38
|
+
"@huma-finance/soroban-tranche-vault": "^0.0.11-beta.17+b42c649",
|
|
39
39
|
"@stellar/stellar-sdk": "^12.0.0-rc.3",
|
|
40
40
|
"dotenv": "^16.0.3",
|
|
41
41
|
"ts-node": "^10.9.1",
|
|
@@ -105,5 +105,5 @@
|
|
|
105
105
|
"prettier": "^2.7.1",
|
|
106
106
|
"ts-jest": "^29.1.1"
|
|
107
107
|
},
|
|
108
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "b42c649f26b5207b2f5e12767d63cc9e5ead0faa"
|
|
109
109
|
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Client as PoolCreditClient, CreditRecord, SentTransaction } from '@huma-finance/soroban-pool-credit';
|
|
2
|
-
import { StellarWallet } from '../services/StellarWallet';
|
|
3
|
-
import { POOL_NAME, StellarNetwork } from '../utils/network';
|
|
4
|
-
/**
|
|
5
|
-
* Returns an soroban contract client instance for the credit line contract
|
|
6
|
-
* associated with the given pool name on the current chain.
|
|
7
|
-
*
|
|
8
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
9
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
10
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
11
|
-
* @returns {PoolCreditClient | undefined} A contract client instance for the CreditLine contract or undefined if it could not be found.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getCreditLineClient(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): PoolCreditClient | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Returns the current pool balance available for borrowing
|
|
16
|
-
*
|
|
17
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
18
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
19
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
20
|
-
*/
|
|
21
|
-
export declare function getAvailableBalanceForPool(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet): Promise<bigint>;
|
|
22
|
-
/**
|
|
23
|
-
* Returns the credit record of the borrower
|
|
24
|
-
*
|
|
25
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
26
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
27
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
28
|
-
* @param {string} borrower - The address of the borrower to check the credit record for.
|
|
29
|
-
*/
|
|
30
|
-
export declare function getCreditRecordForPool(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, borrower: string): Promise<CreditRecord>;
|
|
31
|
-
/**
|
|
32
|
-
* Returns the borrower's remaining credit they can use for borrowing. Note that this might not be
|
|
33
|
-
* currently available for borrowing as the credit limit might exceed the available pool balance. Use
|
|
34
|
-
* getPoolBalance() to get the current available pool balance.
|
|
35
|
-
*
|
|
36
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
37
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
38
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
39
|
-
* @param {string} borrower - The address of the borrower to check the available credit for.
|
|
40
|
-
*/
|
|
41
|
-
export declare function getAvailableCreditForPool(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, borrower: string): Promise<bigint>;
|
|
42
|
-
/**
|
|
43
|
-
* Returns borrower's total due amount in bigint format
|
|
44
|
-
* associated with the given pool name on the current chain.
|
|
45
|
-
*
|
|
46
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
47
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
48
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
49
|
-
* @param {string} borrower - The address of the borrower to check the available credit for.
|
|
50
|
-
* @returns {bigint | null} The account's total due amount in bigint format
|
|
51
|
-
*/
|
|
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>;
|
|
64
|
-
/**
|
|
65
|
-
* Draws down from a pool.
|
|
66
|
-
*
|
|
67
|
-
* @async
|
|
68
|
-
* @function
|
|
69
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
70
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
71
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
72
|
-
* @param {BigNumberish} drawdownAmount - The amount to drawdown.
|
|
73
|
-
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
74
|
-
*/
|
|
75
|
-
export declare function drawdown(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, drawdownAmount: bigint): Promise<SentTransaction<null>>;
|
|
76
|
-
/**
|
|
77
|
-
* Makes a payment.
|
|
78
|
-
*
|
|
79
|
-
* @async
|
|
80
|
-
* @function
|
|
81
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
82
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
83
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
84
|
-
* @param {bigint} paymentAmount - The amount to payback.
|
|
85
|
-
* @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
|
|
86
|
-
* @returns {Promise<AssembledTransaction>} - A Promise of the AssembledTransaction.
|
|
87
|
-
*/
|
|
88
|
-
export declare function makePayment(poolName: POOL_NAME, network: StellarNetwork, wallet: StellarWallet, paymentAmount: bigint, principalOnly: boolean): Promise<SentTransaction<readonly [bigint, boolean]>>;
|
|
@@ -1,219 +0,0 @@
|
|
|
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 = exports.getCreditLineClient = void 0;
|
|
4
|
-
const client_1 = require("../utils/client");
|
|
5
|
-
const Sep41ContractHelper_1 = require("./Sep41ContractHelper");
|
|
6
|
-
/**
|
|
7
|
-
* Returns an soroban contract client instance for the credit line contract
|
|
8
|
-
* associated with the given pool name on the current chain.
|
|
9
|
-
*
|
|
10
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
11
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
12
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
13
|
-
* @returns {PoolCreditClient | undefined} A contract client instance for the CreditLine contract or undefined if it could not be found.
|
|
14
|
-
*/
|
|
15
|
-
function getCreditLineClient(poolName, network, wallet) {
|
|
16
|
-
return (0, client_1.getPoolCreditClient)(poolName, network, wallet);
|
|
17
|
-
}
|
|
18
|
-
exports.getCreditLineClient = getCreditLineClient;
|
|
19
|
-
/**
|
|
20
|
-
* Returns the current pool balance available for borrowing
|
|
21
|
-
*
|
|
22
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
23
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
24
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
25
|
-
*/
|
|
26
|
-
async function getAvailableBalanceForPool(poolName, network, wallet) {
|
|
27
|
-
const poolStorageClient = (0, client_1.getPoolStorageClient)(poolName, network, wallet);
|
|
28
|
-
if (!poolStorageClient) {
|
|
29
|
-
throw new Error('Could not find credit contract for pool');
|
|
30
|
-
}
|
|
31
|
-
const { result } = await poolStorageClient.get_available_balance();
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
exports.getAvailableBalanceForPool = getAvailableBalanceForPool;
|
|
35
|
-
/**
|
|
36
|
-
* Returns the credit record of the borrower
|
|
37
|
-
*
|
|
38
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
39
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
40
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
41
|
-
* @param {string} borrower - The address of the borrower to check the credit record for.
|
|
42
|
-
*/
|
|
43
|
-
async function getCreditRecordForPool(poolName, network, wallet, borrower) {
|
|
44
|
-
const creditStorageClient = (0, client_1.getCreditStorageClient)(poolName, network, wallet);
|
|
45
|
-
if (!creditStorageClient) {
|
|
46
|
-
throw new Error('Could not find credit storage contract for pool');
|
|
47
|
-
}
|
|
48
|
-
const { result: creditHash } = await creditStorageClient.get_credit_hash({
|
|
49
|
-
borrower,
|
|
50
|
-
});
|
|
51
|
-
if (!creditHash) {
|
|
52
|
-
throw new Error('Could not find credit hash');
|
|
53
|
-
}
|
|
54
|
-
const { result: creditRecord } = await creditStorageClient.get_credit_record({
|
|
55
|
-
credit_hash: creditHash,
|
|
56
|
-
});
|
|
57
|
-
if (!creditRecord) {
|
|
58
|
-
throw new Error('Could not find credit record');
|
|
59
|
-
}
|
|
60
|
-
return creditRecord;
|
|
61
|
-
}
|
|
62
|
-
exports.getCreditRecordForPool = getCreditRecordForPool;
|
|
63
|
-
/**
|
|
64
|
-
* Returns the borrower's remaining credit they can use for borrowing. Note that this might not be
|
|
65
|
-
* currently available for borrowing as the credit limit might exceed the available pool balance. Use
|
|
66
|
-
* getPoolBalance() to get the current available pool balance.
|
|
67
|
-
*
|
|
68
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
69
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
70
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
71
|
-
* @param {string} borrower - The address of the borrower to check the available credit for.
|
|
72
|
-
*/
|
|
73
|
-
async function getAvailableCreditForPool(poolName, network, wallet, borrower) {
|
|
74
|
-
const creditStorageClient = (0, client_1.getCreditStorageClient)(poolName, network, wallet);
|
|
75
|
-
if (!creditStorageClient) {
|
|
76
|
-
throw new Error('Could not find credit storage contract for pool');
|
|
77
|
-
}
|
|
78
|
-
const { result: creditHash } = await creditStorageClient.get_credit_hash({
|
|
79
|
-
borrower,
|
|
80
|
-
});
|
|
81
|
-
if (!creditHash) {
|
|
82
|
-
throw new Error('Could not find credit hash');
|
|
83
|
-
}
|
|
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
|
-
]);
|
|
92
|
-
if (!creditConfig || !creditRecord) {
|
|
93
|
-
throw new Error('Could not find credit config or credit record');
|
|
94
|
-
}
|
|
95
|
-
return creditConfig.credit_limit - creditRecord.unbilled_principal;
|
|
96
|
-
}
|
|
97
|
-
exports.getAvailableCreditForPool = getAvailableCreditForPool;
|
|
98
|
-
/**
|
|
99
|
-
* Returns borrower's total due amount in bigint format
|
|
100
|
-
* associated with the given pool name on the current chain.
|
|
101
|
-
*
|
|
102
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
103
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
104
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
105
|
-
* @param {string} borrower - The address of the borrower to check the available credit for.
|
|
106
|
-
* @returns {bigint | null} The account's total due amount in bigint format
|
|
107
|
-
*/
|
|
108
|
-
async function getTotalDue(poolName, network, wallet, borrower) {
|
|
109
|
-
const creditRecord = await getCreditRecordForPool(poolName, network, wallet, borrower);
|
|
110
|
-
if (!creditRecord) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
return creditRecord.next_due + creditRecord.total_past_due;
|
|
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;
|
|
143
|
-
/**
|
|
144
|
-
* Draws down from a pool.
|
|
145
|
-
*
|
|
146
|
-
* @async
|
|
147
|
-
* @function
|
|
148
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
149
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
150
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
151
|
-
* @param {BigNumberish} drawdownAmount - The amount to drawdown.
|
|
152
|
-
* @returns {Promise<SentTransaction>} - A Promise of the SentTransaction.
|
|
153
|
-
*/
|
|
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
|
-
}
|
|
159
|
-
await approveAllowanceForSentinel(poolName, network, wallet);
|
|
160
|
-
const tx = await poolCreditClient.drawdown({
|
|
161
|
-
borrower: wallet.userInfo.publicKey,
|
|
162
|
-
amount: drawdownAmount,
|
|
163
|
-
}, {
|
|
164
|
-
timeoutInSeconds: 30,
|
|
165
|
-
});
|
|
166
|
-
const result = await tx.signAndSend();
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
exports.drawdown = drawdown;
|
|
170
|
-
/**
|
|
171
|
-
* Makes a payment.
|
|
172
|
-
*
|
|
173
|
-
* @async
|
|
174
|
-
* @function
|
|
175
|
-
* @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
|
|
176
|
-
* @param {StellarNetwork} network - The stellar network.
|
|
177
|
-
* @param {StellarWallet} wallet - The stellar wallet.
|
|
178
|
-
* @param {bigint} paymentAmount - The amount to payback.
|
|
179
|
-
* @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
|
|
180
|
-
* @returns {Promise<AssembledTransaction>} - A Promise of the AssembledTransaction.
|
|
181
|
-
*/
|
|
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
|
-
}
|
|
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
|
-
]);
|
|
196
|
-
let tx;
|
|
197
|
-
tx = await (0, Sep41ContractHelper_1.approveSep41AllowanceIfInsufficient)(network, wallet, underlyingToken, sentinel, paymentAmount);
|
|
198
|
-
if (principalOnly) {
|
|
199
|
-
tx = await poolCreditClient.make_principal_payment({
|
|
200
|
-
borrower: wallet.userInfo.publicKey,
|
|
201
|
-
amount: paymentAmount,
|
|
202
|
-
}, {
|
|
203
|
-
timeoutInSeconds: 30,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
tx = await poolCreditClient.make_payment({
|
|
208
|
-
caller: wallet.userInfo.publicKey,
|
|
209
|
-
borrower: wallet.userInfo.publicKey,
|
|
210
|
-
amount: paymentAmount,
|
|
211
|
-
}, {
|
|
212
|
-
timeoutInSeconds: 30,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
const result = await tx.signAndSend();
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
exports.makePayment = makePayment;
|
|
219
|
-
//# sourceMappingURL=CreditContractHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreditContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/CreditContractHelper.ts"],"names":[],"mappings":";;;AAOA,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,6BAAoB,EAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IACzE,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;KAC3D;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,iBAAiB,CAAC,qBAAqB,EAAE,CAAA;IAClE,OAAO,MAAM,CAAA;AACf,CAAC;AAZD,gEAYC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,sBAAsB,CAC1C,QAAmB,EACn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
|
|
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>;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sep41ContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/Sep41ContractHelper.ts"],"names":[],"mappings":";;;AAGA,oCAIiB;AAEjB;;;;;;;;;;;;GAYG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Root":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,iEAAsC"}
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./helpers"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./services"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./utils"), exports);
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,qDAA0B;AAC1B,kDAAuB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { StellarNetwork, POOL_NAME, POOL_TYPE } from '../utils/network';
|
|
2
|
-
import { StellarWallet } from './StellarWallet';
|
|
3
|
-
export declare class HumaContextStellar {
|
|
4
|
-
#private;
|
|
5
|
-
constructor({ wallet, network, poolName, poolType, }: {
|
|
6
|
-
wallet: StellarWallet;
|
|
7
|
-
network: StellarNetwork;
|
|
8
|
-
poolName: POOL_NAME;
|
|
9
|
-
poolType: POOL_TYPE;
|
|
10
|
-
});
|
|
11
|
-
get wallet(): StellarWallet;
|
|
12
|
-
set wallet(value: StellarWallet);
|
|
13
|
-
get network(): StellarNetwork;
|
|
14
|
-
set network(value: StellarNetwork);
|
|
15
|
-
get poolName(): POOL_NAME;
|
|
16
|
-
set poolName(value: POOL_NAME);
|
|
17
|
-
get poolType(): POOL_TYPE;
|
|
18
|
-
set poolType(value: POOL_TYPE);
|
|
19
|
-
}
|