@huma-finance/soroban-pool-credit 0.0.8-beta.2

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.
@@ -0,0 +1,401 @@
1
+ /// <reference types="node" />
2
+ import { Buffer } from 'buffer';
3
+ import { AssembledTransaction, ContractClient, ContractClientOptions } from '@stellar/stellar-sdk/lib/contract_client/index.js';
4
+ import type { u32, u64, u128, Option } from '@stellar/stellar-sdk/lib/contract_client';
5
+ export * from '@stellar/stellar-sdk';
6
+ export * from '@stellar/stellar-sdk/lib/contract_client/index.js';
7
+ export * from '@stellar/stellar-sdk/lib/rust_types/index.js';
8
+ export declare const networks: {
9
+ readonly testnet: {
10
+ readonly networkPassphrase: "Test SDF Network ; September 2015";
11
+ readonly contractId: "CBI7LGEWCJFO2APREGBRTUXB5JMZHJOVD76MESEB7V6W4IJ4ZLQJILDB";
12
+ };
13
+ };
14
+ export type ClientDataKey = {
15
+ tag: 'Pool';
16
+ values: void;
17
+ } | {
18
+ tag: 'PoolStorage';
19
+ values: void;
20
+ } | {
21
+ tag: 'CreditStorage';
22
+ values: void;
23
+ } | {
24
+ tag: 'UnderlyingToken';
25
+ values: void;
26
+ };
27
+ export declare const Errors: {
28
+ 51: {
29
+ message: string;
30
+ };
31
+ 55: {
32
+ message: string;
33
+ };
34
+ 71: {
35
+ message: string;
36
+ };
37
+ 222: {
38
+ message: string;
39
+ };
40
+ 202: {
41
+ message: string;
42
+ };
43
+ 203: {
44
+ message: string;
45
+ };
46
+ 204: {
47
+ message: string;
48
+ };
49
+ 215: {
50
+ message: string;
51
+ };
52
+ 205: {
53
+ message: string;
54
+ };
55
+ 206: {
56
+ message: string;
57
+ };
58
+ 207: {
59
+ message: string;
60
+ };
61
+ 219: {
62
+ message: string;
63
+ };
64
+ 101: {
65
+ message: string;
66
+ };
67
+ };
68
+ /**
69
+ * Account billing info refreshed with the updated due amount and date.
70
+ * # Fields:
71
+ * * `credit_hash` - The hash of the credit.
72
+ * * `new_due_date` - The updated due date of the bill.
73
+ * * `next_due` - The amount of next due on the bill.
74
+ * * `total_past_due` - The total amount of past due on the bill.
75
+ */
76
+ export interface BillRefreshedEvent {
77
+ credit_hash: Buffer;
78
+ new_due_date: u64;
79
+ next_due: u128;
80
+ total_past_due: u128;
81
+ }
82
+ /**
83
+ * A credit has been borrowed from.
84
+ * # Fields:
85
+ * * `borrower` - The address of the borrower.
86
+ * * `borrow_amount` - The amount the user has borrowed.
87
+ * * `net_amount_to_borrower` - The borrowing amount minus the fees that are charged upfront.
88
+ */
89
+ export interface DrawdownMadeEvent {
90
+ borrow_amount: u128;
91
+ borrower: string;
92
+ net_amount_to_borrower: u128;
93
+ }
94
+ /**
95
+ * A payment has been made against the credit.
96
+ * # Fields:
97
+ * * `borrower` - The address of the borrower.
98
+ * * `amount` - The payback amount.
99
+ * * `next_due_date` - The due date of the next payment.
100
+ * * `yield_due` - The yield due on the credit after processing the payment.
101
+ * * `principal_due` - The principal due on the credit after processing the payment.
102
+ * * `yield_due_paid` - The amount of this payment applied to yield due in the current billing cycle.
103
+ * * `principal_due_paid` - The amount of this payment applied to principal due in the current billing cycle.
104
+ * * `unbilled_principal_paid` - The amount of this payment applied to unbilled principal.
105
+ * * `yield_past_due_paid` - The amount of this payment applied to yield past due.
106
+ * * `late_fee_paid` - The amount of this payment applied to late fee.
107
+ * * `principal_past_due_paid` - The amount of this payment applied to principal past due.
108
+ */
109
+ export interface PaymentMadeEvent {
110
+ amount: u128;
111
+ borrower: string;
112
+ late_fee_paid: u128;
113
+ next_due_date: u64;
114
+ principal_due: u128;
115
+ principal_due_paid: u128;
116
+ principal_past_due_paid: u128;
117
+ unbilled_principal_paid: u128;
118
+ yield_due: u128;
119
+ yield_due_paid: u128;
120
+ yield_past_due_paid: u128;
121
+ }
122
+ /**
123
+ * A principal payment has been made against the credit.
124
+ * # Fields:
125
+ * * `borrower` - The address of the borrower.
126
+ * * `payer` - The address from which the money is coming.
127
+ * * `amount` - The payback amount.
128
+ * * `next_due_date` - The due date of the next payment.
129
+ * * `principal_due` - The principal due on the credit after processing the payment.
130
+ * * `unbilled_principal` - The unbilled principal on the credit after processing the payment.
131
+ * * `principal_due_paid` - The amount of this payment applied to principal due.
132
+ * * `unbilled_principal_paid` - The amount of this payment applied to unbilled principal.
133
+ */
134
+ export interface PrincipalPaymentMadeEvent {
135
+ amount: u128;
136
+ borrower: string;
137
+ next_due_date: u64;
138
+ principal_due: u128;
139
+ principal_due_paid: u128;
140
+ unbilled_principal: u128;
141
+ unbilled_principal_paid: u128;
142
+ }
143
+ /**
144
+ * An existing credit has been closed.
145
+ * # Fields:
146
+ * * `credit_hash` - The credit hash.
147
+ */
148
+ export interface CreditClosedAfterPayOffEvent {
149
+ credit_hash: Buffer;
150
+ }
151
+ export type PayPeriodDuration = {
152
+ tag: 'Monthly';
153
+ values: void;
154
+ } | {
155
+ tag: 'Quarterly';
156
+ values: void;
157
+ } | {
158
+ tag: 'SemiAnnually';
159
+ values: void;
160
+ };
161
+ export type CreditState = {
162
+ tag: 'Deleted';
163
+ values: void;
164
+ } | {
165
+ tag: 'Approved';
166
+ values: void;
167
+ } | {
168
+ tag: 'GoodStanding';
169
+ values: void;
170
+ } | {
171
+ tag: 'Delayed';
172
+ values: void;
173
+ } | {
174
+ tag: 'Defaulted';
175
+ values: void;
176
+ };
177
+ /**
178
+ * `CreditConfig` keeps track of the static settings of a credit.
179
+ * A `CreditConfig` is created after the approval of each credit.
180
+ * # Fields:
181
+ * * `credit_limit` - The maximum amount that can be borrowed.
182
+ * * `committed_amount` - The amount that the borrower has committed to use. If the used credit
183
+ * is less than this amount, the borrower will be charged yield using this amount.
184
+ * * `pay_period_duration` - The duration of each pay period, e.g., monthly, quarterly, or semi-annually.
185
+ * * `num_of_periods` - The number of periods before the credit expires.
186
+ * * `yield_bps` - The expected yield expressed in basis points, where 1% is 100, and 100% is 10,000. It means different things
187
+ * for different credit types:
188
+ * 1. For credit line, it is APR.
189
+ * 2. For factoring, it is factoring fee for the given period.
190
+ * 3. For dynamic yield credit, it is the estimated APY.
191
+ * * `revolving` - A flag indicating if repeated borrowing is allowed.
192
+ */
193
+ export interface CreditConfig {
194
+ committed_amount: u128;
195
+ credit_limit: u128;
196
+ num_periods: u32;
197
+ pay_period_duration: PayPeriodDuration;
198
+ revolving: boolean;
199
+ yield_bps: u32;
200
+ }
201
+ export interface CreditRecord {
202
+ missed_periods: u32;
203
+ next_due: u128;
204
+ next_due_date: u64;
205
+ remaining_periods: u32;
206
+ state: CreditState;
207
+ total_past_due: u128;
208
+ unbilled_principal: u128;
209
+ yield_due: u128;
210
+ }
211
+ export interface DueDetail {
212
+ accrued: u128;
213
+ committed: u128;
214
+ late_fee: u128;
215
+ late_fee_updated_date: u64;
216
+ paid: u128;
217
+ principal_past_due: u128;
218
+ yield_past_due: u128;
219
+ }
220
+ export interface PoolSettings {
221
+ default_grace_period_days: u32;
222
+ late_payment_grace_period_days: u32;
223
+ max_credit_line: u128;
224
+ min_deposit_amount: u128;
225
+ pay_period_duration: PayPeriodDuration;
226
+ principal_only_payment_allowed: boolean;
227
+ }
228
+ export interface LPConfig {
229
+ fixed_senior_yield_bps: u32;
230
+ liquidity_cap: u128;
231
+ max_senior_junior_ratio: u32;
232
+ tranches_risk_adjustment_bps: u32;
233
+ withdrawal_lockout_period_days: u32;
234
+ }
235
+ export interface FeeStructure {
236
+ front_loading_fee_bps: u32;
237
+ front_loading_fee_flat: u128;
238
+ late_fee_bps: u32;
239
+ yield_bps: u32;
240
+ }
241
+ export type PoolStatus = {
242
+ tag: 'Off';
243
+ values: void;
244
+ } | {
245
+ tag: 'On';
246
+ values: void;
247
+ } | {
248
+ tag: 'Closed';
249
+ values: void;
250
+ };
251
+ export interface CurrentEpoch {
252
+ end_time: u64;
253
+ id: u64;
254
+ }
255
+ export interface AdminRnR {
256
+ liquidity_rate_bps_ea: u32;
257
+ liquidity_rate_bps_pool_owner: u32;
258
+ reward_rate_bps_ea: u32;
259
+ reward_rate_bps_pool_owner: u32;
260
+ }
261
+ export interface TrancheAddresses {
262
+ addrs: Array<Option<string>>;
263
+ }
264
+ export interface TrancheAssets {
265
+ assets: Array<u128>;
266
+ }
267
+ export interface Client {
268
+ /**
269
+ * Construct and simulate a initialize transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
270
+ */
271
+ initialize: ({ pool, pool_storage, credit_storage, underlying_token, }: {
272
+ pool: string;
273
+ pool_storage: string;
274
+ credit_storage: string;
275
+ underlying_token: string;
276
+ }, options?: {
277
+ /**
278
+ * The fee to pay for the transaction. Default: BASE_FEE
279
+ */
280
+ fee?: number;
281
+ /**
282
+ * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
283
+ */
284
+ timeoutInSeconds?: number;
285
+ /**
286
+ * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
287
+ */
288
+ simulate?: boolean;
289
+ }) => Promise<AssembledTransaction<null>>;
290
+ /**
291
+ * Construct and simulate a get_due_info transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
292
+ */
293
+ get_due_info: ({ borrower }: {
294
+ borrower: string;
295
+ }, options?: {
296
+ /**
297
+ * The fee to pay for the transaction. Default: BASE_FEE
298
+ */
299
+ fee?: number;
300
+ /**
301
+ * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
302
+ */
303
+ timeoutInSeconds?: number;
304
+ /**
305
+ * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
306
+ */
307
+ simulate?: boolean;
308
+ }) => Promise<AssembledTransaction<readonly [CreditRecord, DueDetail]>>;
309
+ /**
310
+ * Construct and simulate a get_next_bill_refresh_date transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
311
+ */
312
+ get_next_bill_refresh_date: ({ borrower }: {
313
+ borrower: string;
314
+ }, options?: {
315
+ /**
316
+ * The fee to pay for the transaction. Default: BASE_FEE
317
+ */
318
+ fee?: number;
319
+ /**
320
+ * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
321
+ */
322
+ timeoutInSeconds?: number;
323
+ /**
324
+ * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
325
+ */
326
+ simulate?: boolean;
327
+ }) => Promise<AssembledTransaction<u64>>;
328
+ /**
329
+ * Construct and simulate a drawdown transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
330
+ */
331
+ drawdown: ({ borrower, amount }: {
332
+ borrower: string;
333
+ amount: u128;
334
+ }, options?: {
335
+ /**
336
+ * The fee to pay for the transaction. Default: BASE_FEE
337
+ */
338
+ fee?: number;
339
+ /**
340
+ * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
341
+ */
342
+ timeoutInSeconds?: number;
343
+ /**
344
+ * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
345
+ */
346
+ simulate?: boolean;
347
+ }) => Promise<AssembledTransaction<null>>;
348
+ /**
349
+ * Construct and simulate a make_payment transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
350
+ */
351
+ make_payment: ({ caller, borrower, amount, }: {
352
+ caller: string;
353
+ borrower: string;
354
+ amount: u128;
355
+ }, options?: {
356
+ /**
357
+ * The fee to pay for the transaction. Default: BASE_FEE
358
+ */
359
+ fee?: number;
360
+ /**
361
+ * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
362
+ */
363
+ timeoutInSeconds?: number;
364
+ /**
365
+ * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
366
+ */
367
+ simulate?: boolean;
368
+ }) => Promise<AssembledTransaction<readonly [u128, boolean]>>;
369
+ /**
370
+ * Construct and simulate a make_principal_payment transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
371
+ */
372
+ make_principal_payment: ({ borrower, amount }: {
373
+ borrower: string;
374
+ amount: u128;
375
+ }, options?: {
376
+ /**
377
+ * The fee to pay for the transaction. Default: BASE_FEE
378
+ */
379
+ fee?: number;
380
+ /**
381
+ * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
382
+ */
383
+ timeoutInSeconds?: number;
384
+ /**
385
+ * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
386
+ */
387
+ simulate?: boolean;
388
+ }) => Promise<AssembledTransaction<readonly [u128, boolean]>>;
389
+ }
390
+ export declare class Client extends ContractClient {
391
+ readonly options: ContractClientOptions;
392
+ constructor(options: ContractClientOptions);
393
+ readonly fromJSON: {
394
+ initialize: (json: string) => AssembledTransaction<null>;
395
+ get_due_info: (json: string) => AssembledTransaction<readonly [CreditRecord, DueDetail]>;
396
+ get_next_bill_refresh_date: (json: string) => AssembledTransaction<bigint>;
397
+ drawdown: (json: string) => AssembledTransaction<null>;
398
+ make_payment: (json: string) => AssembledTransaction<readonly [bigint, boolean]>;
399
+ make_principal_payment: (json: string) => AssembledTransaction<readonly [bigint, boolean]>;
400
+ };
401
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "version": "0.0.8-beta.2+79432b6",
3
+ "name": "@huma-finance/soroban-pool-credit",
4
+ "dependencies": {
5
+ "@stellar/freighter-api": "2.0.0",
6
+ "@stellar/stellar-sdk": "11.3.0",
7
+ "buffer": "6.0.3"
8
+ },
9
+ "scripts": {
10
+ "build": "node ./scripts/build.mjs"
11
+ },
12
+ "exports": {
13
+ "require": "./dist/cjs/index.js",
14
+ "import": "./dist/esm/index.js"
15
+ },
16
+ "typings": "dist/types/index.d.ts",
17
+ "devDependencies": {
18
+ "typescript": "5.3.3"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "registry": "https://registry.npmjs.org/"
23
+ },
24
+ "gitHead": "79432b60d3d0c755634737e635699aab90be53f0"
25
+ }
@@ -0,0 +1,37 @@
1
+ import { spawnSync } from "node:child_process"
2
+ import fs from "node:fs"
3
+ import path from "node:path"
4
+
5
+ const buildDir = "./dist"
6
+
7
+ const { error, stderr } = spawnSync("tsc", ["-b", "./scripts/tsconfig.cjs.json", "./scripts/tsconfig.esm.json", "./scripts/tsconfig.types.json"], { stdio: "inherit" })
8
+
9
+ if (error) {
10
+ console.error(stderr)
11
+ console.error(error)
12
+ throw error
13
+ }
14
+
15
+ function createEsmModulePackageJson() {
16
+ fs.readdir(buildDir, function (err, dirs) {
17
+ if (err) {
18
+ throw err
19
+ }
20
+ dirs.forEach(function (dir) {
21
+ if (dir === "esm") {
22
+ // 1. add package.json file with "type": "module"
23
+ var packageJsonFile = path.join(buildDir, dir, "/package.json")
24
+ if (!fs.existsSync(packageJsonFile)) {
25
+ fs.writeFileSync(
26
+ packageJsonFile,
27
+ '{"type": "module"}',
28
+ 'utf8',
29
+ err => { if (err) throw err }
30
+ )
31
+ }
32
+ }
33
+ })
34
+ })
35
+ }
36
+
37
+ createEsmModulePackageJson()
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../dist/cjs",
5
+ "module": "commonjs"
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../dist/esm",
5
+ "module": "esnext"
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../dist/types",
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true
7
+ }
8
+ }