@kasufinance/kasu-sdk 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +144 -7
  2. package/dist/bundle.cjs.js +1667 -21
  3. package/dist/bundle.esm.js +1630 -22
  4. package/dist/domain/au-minimum.d.ts +135 -0
  5. package/dist/domain/au-minimum.js +154 -0
  6. package/dist/domain/au-minimum.js.map +1 -0
  7. package/dist/domain/index.d.ts +18 -3
  8. package/dist/domain/index.js +13 -3
  9. package/dist/domain/index.js.map +1 -1
  10. package/dist/domain/loan-contract.d.ts +174 -0
  11. package/dist/domain/loan-contract.js +160 -0
  12. package/dist/domain/loan-contract.js.map +1 -0
  13. package/dist/domain/requests.d.ts +219 -0
  14. package/dist/domain/requests.js +218 -0
  15. package/dist/domain/requests.js.map +1 -0
  16. package/dist/domain/settlement.d.ts +97 -0
  17. package/dist/domain/settlement.js +117 -0
  18. package/dist/domain/settlement.js.map +1 -0
  19. package/dist/domain/wallet-errors.d.ts +92 -0
  20. package/dist/domain/wallet-errors.js +155 -0
  21. package/dist/domain/wallet-errors.js.map +1 -0
  22. package/dist/facade/chain-configs.js +7 -1
  23. package/dist/facade/chain-configs.js.map +1 -1
  24. package/dist/facade/deposits.js +2 -1
  25. package/dist/facade/deposits.js.map +1 -1
  26. package/dist/facade/flows.d.ts +95 -0
  27. package/dist/facade/flows.js +116 -0
  28. package/dist/facade/flows.js.map +1 -0
  29. package/dist/facade/index.d.ts +3 -0
  30. package/dist/facade/index.js +3 -0
  31. package/dist/facade/index.js.map +1 -1
  32. package/dist/facade/kasu.d.ts +6 -2
  33. package/dist/facade/kasu.js +28 -3
  34. package/dist/facade/kasu.js.map +1 -1
  35. package/dist/facade/read-only.d.ts +12 -0
  36. package/dist/facade/read-only.js +13 -0
  37. package/dist/facade/read-only.js.map +1 -0
  38. package/dist/facade/user-portfolio.d.ts +18 -0
  39. package/dist/facade/user-portfolio.js +23 -0
  40. package/dist/facade/user-portfolio.js.map +1 -1
  41. package/dist/flows/deposit-flow.d.ts +301 -0
  42. package/dist/flows/deposit-flow.js +358 -0
  43. package/dist/flows/deposit-flow.js.map +1 -0
  44. package/dist/flows/flow.d.ts +72 -0
  45. package/dist/flows/flow.js +110 -0
  46. package/dist/flows/flow.js.map +1 -0
  47. package/dist/flows/index.d.ts +19 -0
  48. package/dist/flows/index.js +17 -0
  49. package/dist/flows/index.js.map +1 -0
  50. package/dist/flows/observable.d.ts +59 -0
  51. package/dist/flows/observable.js +81 -0
  52. package/dist/flows/observable.js.map +1 -0
  53. package/dist/flows/withdraw-flow.d.ts +99 -0
  54. package/dist/flows/withdraw-flow.js +83 -0
  55. package/dist/flows/withdraw-flow.js.map +1 -0
  56. package/dist/index.d.ts +2 -0
  57. package/dist/index.js +7 -0
  58. package/dist/index.js.map +1 -1
  59. package/dist/services/DataService/data-service.js +3 -11
  60. package/dist/services/DataService/data-service.js.map +1 -1
  61. package/dist/services/DataService/directus-client.d.ts +26 -0
  62. package/dist/services/DataService/directus-client.js +38 -0
  63. package/dist/services/DataService/directus-client.js.map +1 -0
  64. package/dist/services/UserLending/user-lending.js +11 -7
  65. package/dist/services/UserLending/user-lending.js.map +1 -1
  66. package/package.json +8 -2
  67. package/src/domain/au-minimum.ts +192 -0
  68. package/src/domain/index.ts +73 -3
  69. package/src/domain/loan-contract.ts +275 -0
  70. package/src/domain/requests.ts +467 -0
  71. package/src/domain/settlement.ts +161 -0
  72. package/src/domain/wallet-errors.ts +173 -0
  73. package/src/facade/chain-configs.ts +7 -1
  74. package/src/facade/deposits.ts +2 -3
  75. package/src/facade/flows.ts +172 -0
  76. package/src/facade/index.ts +8 -0
  77. package/src/facade/kasu.ts +43 -3
  78. package/src/facade/read-only.ts +13 -0
  79. package/src/facade/user-portfolio.ts +24 -0
  80. package/src/flows/deposit-flow.ts +775 -0
  81. package/src/flows/flow.ts +108 -0
  82. package/src/flows/index.ts +45 -0
  83. package/src/flows/observable.ts +97 -0
  84. package/src/flows/withdraw-flow.ts +210 -0
  85. package/src/index.ts +9 -0
  86. package/src/services/DataService/data-service.ts +7 -25
  87. package/src/services/DataService/directus-client.ts +54 -0
  88. package/src/services/UserLending/user-lending.ts +17 -21
  89. package/dist/domain/deposit-bounds.test.d.ts +0 -1
  90. package/dist/domain/deposit-bounds.test.js +0 -135
  91. package/dist/domain/deposit-bounds.test.js.map +0 -1
  92. package/dist/domain/partners.test.d.ts +0 -1
  93. package/dist/domain/partners.test.js +0 -53
  94. package/dist/domain/partners.test.js.map +0 -1
  95. package/dist/domain/pools.test.d.ts +0 -1
  96. package/dist/domain/pools.test.js +0 -184
  97. package/dist/domain/pools.test.js.map +0 -1
  98. package/dist/domain/rates.test.d.ts +0 -1
  99. package/dist/domain/rates.test.js +0 -181
  100. package/dist/domain/rates.test.js.map +0 -1
  101. package/dist/domain/tranche-display-name.test.d.ts +0 -1
  102. package/dist/domain/tranche-display-name.test.js +0 -58
  103. package/dist/domain/tranche-display-name.test.js.map +0 -1
  104. package/dist/domain/tranches.test.d.ts +0 -1
  105. package/dist/domain/tranches.test.js +0 -206
  106. package/dist/domain/tranches.test.js.map +0 -1
  107. package/dist/facade/config.test.d.ts +0 -1
  108. package/dist/facade/config.test.js +0 -216
  109. package/dist/facade/config.test.js.map +0 -1
  110. package/dist/facade/facade.test.d.ts +0 -1
  111. package/dist/facade/facade.test.js +0 -201
  112. package/dist/facade/facade.test.js.map +0 -1
  113. package/dist/services/Locking/calculate-apy.test.d.ts +0 -1
  114. package/dist/services/Locking/calculate-apy.test.js +0 -41
  115. package/dist/services/Locking/calculate-apy.test.js.map +0 -1
  116. package/dist/tests/sample.test.d.ts +0 -1
  117. package/dist/tests/sample.test.js +0 -59
  118. package/dist/tests/sample.test.js.map +0 -1
  119. package/src/domain/deposit-bounds.test.ts +0 -200
  120. package/src/domain/partners.test.ts +0 -83
  121. package/src/domain/pools.test.ts +0 -260
  122. package/src/domain/rates.test.ts +0 -254
  123. package/src/domain/tranche-display-name.test.ts +0 -96
  124. package/src/domain/tranches.test.ts +0 -300
  125. package/src/facade/config.test.ts +0 -265
  126. package/src/facade/facade.test.ts +0 -250
  127. package/src/services/Locking/calculate-apy.test.ts +0 -52
  128. package/src/tests/sample.test.ts +0 -63
@@ -0,0 +1,72 @@
1
+ import { FlowStore } from './observable';
2
+ /**
3
+ * The run lifecycle both flows share: one run at a time, every transition
4
+ * published, and a `reset()` that is safe to call in the middle of one.
5
+ *
6
+ * `DepositFlow` and `WithdrawFlow` each carried their own copy of this — the
7
+ * re-entrancy guard, the `try/finally` around the run, `state`, `isRunning`,
8
+ * `subscribe`, `reset`. Two copies of a guard is two places for a guard to be
9
+ * wrong, on the money path, which is the same reason the pipelines themselves
10
+ * moved out of the applications.
11
+ *
12
+ * ## The guard and the run token are separate, and both matter
13
+ *
14
+ * `_runToken` is the re-entrancy guard: claimed synchronously, before the
15
+ * first `await`, so a double tap cannot launch two pipelines. The store's
16
+ * `generation` is the abandonment mechanism: an in-flight run holds the value
17
+ * it claimed, and every `patch` and `isCurrent` checkpoint it makes after
18
+ * `reset()` is dropped.
19
+ *
20
+ * `reset()` releases the guard IMMEDIATELY rather than waiting for the
21
+ * abandoned run to notice. It has to: a run parked on a wallet prompt that
22
+ * never answers is a promise that may never settle, and a consumer that has
23
+ * left that screen must be able to start a new run in the same tick. The
24
+ * abandoned run's `finally` therefore releases the guard only if it still
25
+ * holds it — by then a NEW run may own it, and clearing it there would let a
26
+ * third run start alongside the second.
27
+ */
28
+ export declare abstract class Flow<S, I> {
29
+ protected readonly _store: FlowStore<S>;
30
+ /**
31
+ * The token of the run currently holding the guard, or `null` when none
32
+ * does. Not a boolean: releasing the guard has to be attributable to the
33
+ * run that claimed it.
34
+ */
35
+ private _runToken;
36
+ protected constructor(initial: S);
37
+ /** The current state. Every transition is also published to `subscribe`. */
38
+ get state(): S;
39
+ /** True while a run is in flight, including while parked. */
40
+ get isRunning(): boolean;
41
+ /**
42
+ * Observe every transition. Returns the unsubscribe function.
43
+ *
44
+ * The listener is not called on subscribe; read `state` for the value it
45
+ * starts from.
46
+ */
47
+ subscribe(listener: (state: S) => void): () => void;
48
+ /**
49
+ * Run the pipeline. Resolves when it reaches a terminal phase — it does
50
+ * not reject, because every outcome a consumer can act on is in `state`.
51
+ *
52
+ * A second call while one is in flight is a no-op: one submission per
53
+ * intent, however many times the button is pressed.
54
+ */
55
+ start(input: I): Promise<void>;
56
+ /**
57
+ * Back to `idle`, abandoning any run in flight: its remaining transitions
58
+ * are dropped, whatever it is parked on is unparked, and the guard is
59
+ * released at once so `start()` is accepted in the SAME tick. Subscribers
60
+ * are kept — the consumer watching the last run is the one watching the
61
+ * next.
62
+ */
63
+ reset(): void;
64
+ /**
65
+ * Hook for a flow that parks: unpark it. Called by `reset()` after the
66
+ * generation has been bumped, so anything the abandoned run does with the
67
+ * result is dropped.
68
+ */
69
+ protected _onAbandon(): void;
70
+ /** The pipeline itself. `token` is this run's; check it after every await. */
71
+ protected abstract _run(input: I, token: number): Promise<void>;
72
+ }
@@ -0,0 +1,110 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { FlowStore } from './observable';
11
+ /**
12
+ * The run lifecycle both flows share: one run at a time, every transition
13
+ * published, and a `reset()` that is safe to call in the middle of one.
14
+ *
15
+ * `DepositFlow` and `WithdrawFlow` each carried their own copy of this — the
16
+ * re-entrancy guard, the `try/finally` around the run, `state`, `isRunning`,
17
+ * `subscribe`, `reset`. Two copies of a guard is two places for a guard to be
18
+ * wrong, on the money path, which is the same reason the pipelines themselves
19
+ * moved out of the applications.
20
+ *
21
+ * ## The guard and the run token are separate, and both matter
22
+ *
23
+ * `_runToken` is the re-entrancy guard: claimed synchronously, before the
24
+ * first `await`, so a double tap cannot launch two pipelines. The store's
25
+ * `generation` is the abandonment mechanism: an in-flight run holds the value
26
+ * it claimed, and every `patch` and `isCurrent` checkpoint it makes after
27
+ * `reset()` is dropped.
28
+ *
29
+ * `reset()` releases the guard IMMEDIATELY rather than waiting for the
30
+ * abandoned run to notice. It has to: a run parked on a wallet prompt that
31
+ * never answers is a promise that may never settle, and a consumer that has
32
+ * left that screen must be able to start a new run in the same tick. The
33
+ * abandoned run's `finally` therefore releases the guard only if it still
34
+ * holds it — by then a NEW run may own it, and clearing it there would let a
35
+ * third run start alongside the second.
36
+ */
37
+ export class Flow {
38
+ constructor(initial) {
39
+ /**
40
+ * The token of the run currently holding the guard, or `null` when none
41
+ * does. Not a boolean: releasing the guard has to be attributable to the
42
+ * run that claimed it.
43
+ */
44
+ this._runToken = null;
45
+ this._store = new FlowStore(initial);
46
+ }
47
+ /** The current state. Every transition is also published to `subscribe`. */
48
+ get state() {
49
+ return this._store.state;
50
+ }
51
+ /** True while a run is in flight, including while parked. */
52
+ get isRunning() {
53
+ return this._runToken !== null;
54
+ }
55
+ /**
56
+ * Observe every transition. Returns the unsubscribe function.
57
+ *
58
+ * The listener is not called on subscribe; read `state` for the value it
59
+ * starts from.
60
+ */
61
+ subscribe(listener) {
62
+ return this._store.subscribe(listener);
63
+ }
64
+ /**
65
+ * Run the pipeline. Resolves when it reaches a terminal phase — it does
66
+ * not reject, because every outcome a consumer can act on is in `state`.
67
+ *
68
+ * A second call while one is in flight is a no-op: one submission per
69
+ * intent, however many times the button is pressed.
70
+ */
71
+ start(input) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ if (this._runToken !== null)
74
+ return;
75
+ this._store.reset();
76
+ const token = this._store.beginRun();
77
+ this._runToken = token;
78
+ try {
79
+ yield this._run(input, token);
80
+ }
81
+ finally {
82
+ if (this._runToken === token)
83
+ this._runToken = null;
84
+ }
85
+ });
86
+ }
87
+ /**
88
+ * Back to `idle`, abandoning any run in flight: its remaining transitions
89
+ * are dropped, whatever it is parked on is unparked, and the guard is
90
+ * released at once so `start()` is accepted in the SAME tick. Subscribers
91
+ * are kept — the consumer watching the last run is the one watching the
92
+ * next.
93
+ */
94
+ reset() {
95
+ this._runToken = null;
96
+ // Bump the generation BEFORE unparking, so the abandoned run's next
97
+ // checkpoint already reads as superseded.
98
+ this._store.reset();
99
+ this._onAbandon();
100
+ }
101
+ /**
102
+ * Hook for a flow that parks: unpark it. Called by `reset()` after the
103
+ * generation has been bumped, so anything the abandoned run does with the
104
+ * result is dropped.
105
+ */
106
+ _onAbandon() {
107
+ // A flow with nothing parked has nothing to unpark.
108
+ }
109
+ }
110
+ //# sourceMappingURL=flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.js","sourceRoot":"","sources":["../../src/flows/flow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAgB,IAAI;IAUtB,YAAsB,OAAU;QAPhC;;;;WAIG;QACK,cAAS,GAAkB,IAAI,CAAC;QAGpC,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAI,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,4EAA4E;IAC5E,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,6DAA6D;IAC7D,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,QAA4B;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACG,KAAK,CAAC,KAAQ;;YAChB,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;gBAAE,OAAO;YACpC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC;gBACD,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;oBAAS,CAAC;gBACP,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK;oBAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACxD,CAAC;QACL,CAAC;KAAA;IAED;;;;;;OAMG;IACH,KAAK;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,oEAAoE;QACpE,0CAA0C;QAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACO,UAAU;QAChB,oDAAoD;IACxD,CAAC;CAIJ"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Flows: the headless money-path state machines.
3
+ *
4
+ * `domain/` holds rules that are pure functions. These are the same idea one
5
+ * level up — a rule that unfolds over time, with side effects the consumer
6
+ * injects as ports. They own the ORDER of a deposit and a withdrawal, the
7
+ * guards around them, and the codes that describe where a run got to. They own
8
+ * no UI, no framework, no network and no words.
9
+ *
10
+ * Every application drove its own copy of the deposit pipeline before this, and
11
+ * the copies had already started to differ.
12
+ */
13
+ export { Flow } from './flow';
14
+ export { FlowStore } from './observable';
15
+ export type { WaitableTransaction } from './observable';
16
+ export { CONTRACT_TTL_MS, DepositFlow, NO_SPENDER_MESSAGE, } from './deposit-flow';
17
+ export type { ContractMessageRequest, DepositFailure, DepositFlowInput, DepositFlowOptions, DepositPhase, DepositPorts, DepositState, DepositStep, GenerateContractRequest, KycSignature, LegacyContractRequest, LoanAgreementRequest, } from './deposit-flow';
18
+ export { NO_KYC_PARAMS_MESSAGE, WithdrawFlow } from './withdraw-flow';
19
+ export type { WithdrawFailure, WithdrawFlowInput, WithdrawPhase, WithdrawPorts, WithdrawState, WithdrawStep, } from './withdraw-flow';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Flows: the headless money-path state machines.
3
+ *
4
+ * `domain/` holds rules that are pure functions. These are the same idea one
5
+ * level up — a rule that unfolds over time, with side effects the consumer
6
+ * injects as ports. They own the ORDER of a deposit and a withdrawal, the
7
+ * guards around them, and the codes that describe where a run got to. They own
8
+ * no UI, no framework, no network and no words.
9
+ *
10
+ * Every application drove its own copy of the deposit pipeline before this, and
11
+ * the copies had already started to differ.
12
+ */
13
+ export { Flow } from './flow';
14
+ export { FlowStore } from './observable';
15
+ export { CONTRACT_TTL_MS, DepositFlow, NO_SPENDER_MESSAGE, } from './deposit-flow';
16
+ export { NO_KYC_PARAMS_MESSAGE, WithdrawFlow } from './withdraw-flow';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/flows/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EACH,eAAe,EACf,WAAW,EACX,kBAAkB,GACrB,MAAM,gBAAgB,CAAC;AAgBxB,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The tiny observable-state kernel both flows are built on.
3
+ *
4
+ * Deliberately not a framework store: no React, no signals, no dependency.
5
+ * A flow is a long asynchronous run that has to publish every transition to
6
+ * whatever is rendering it, and has to be able to abandon a run that the
7
+ * consumer walked away from. That is the whole requirement, and it is 60 lines.
8
+ *
9
+ * The `generation` counter is the abandonment mechanism. `reset()` bumps it;
10
+ * an in-flight run captured the previous value, so every later `patch` it
11
+ * attempts is dropped and every `isCurrent` checkpoint tells it to stop. It is
12
+ * what makes `reset()` safe to call mid-flight — the run cannot resurrect a
13
+ * dead state or, worse, drive the UI back into a phase the consumer has left.
14
+ */
15
+ export declare class FlowStore<S> {
16
+ private readonly _initial;
17
+ private _state;
18
+ private _generation;
19
+ private readonly _listeners;
20
+ constructor(_initial: S);
21
+ get state(): S;
22
+ /** The run token an in-flight pipeline captures at `start()`. */
23
+ get generation(): number;
24
+ /** False once `reset()` (or a later `start()`) has superseded `token`. */
25
+ isCurrent(token: number): boolean;
26
+ /**
27
+ * Subscribe to every transition. Returns the unsubscribe function; calling
28
+ * it twice is harmless.
29
+ *
30
+ * Listeners are NOT called on subscribe — read `state` for the current
31
+ * value. A listener that throws is not allowed to break the pipeline or
32
+ * starve the listeners registered after it, so throws are swallowed.
33
+ */
34
+ subscribe(listener: (state: S) => void): () => void;
35
+ /**
36
+ * Merge `next` into the state and notify, unless `token` names a
37
+ * superseded run.
38
+ */
39
+ patch(next: Partial<S>, token?: number): void;
40
+ /**
41
+ * Back to the initial state, abandoning any in-flight run.
42
+ *
43
+ * Subscribers are kept: the consumer that was watching the last run is the
44
+ * one that will watch the next.
45
+ */
46
+ reset(): void;
47
+ /** Claim the next run token. Any earlier run is abandoned. */
48
+ beginRun(): number;
49
+ }
50
+ /**
51
+ * Anything with a `wait()` — an ethers `ContractTransaction`, or a fake.
52
+ *
53
+ * Lives beside the store rather than in either flow: both submit transactions
54
+ * through their own ports, and neither of them should have to import the
55
+ * other's file to say so.
56
+ */
57
+ export interface WaitableTransaction {
58
+ wait(): Promise<unknown>;
59
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The tiny observable-state kernel both flows are built on.
3
+ *
4
+ * Deliberately not a framework store: no React, no signals, no dependency.
5
+ * A flow is a long asynchronous run that has to publish every transition to
6
+ * whatever is rendering it, and has to be able to abandon a run that the
7
+ * consumer walked away from. That is the whole requirement, and it is 60 lines.
8
+ *
9
+ * The `generation` counter is the abandonment mechanism. `reset()` bumps it;
10
+ * an in-flight run captured the previous value, so every later `patch` it
11
+ * attempts is dropped and every `isCurrent` checkpoint tells it to stop. It is
12
+ * what makes `reset()` safe to call mid-flight — the run cannot resurrect a
13
+ * dead state or, worse, drive the UI back into a phase the consumer has left.
14
+ */
15
+ export class FlowStore {
16
+ constructor(_initial) {
17
+ this._initial = _initial;
18
+ this._generation = 0;
19
+ this._listeners = new Set();
20
+ this._state = _initial;
21
+ }
22
+ get state() {
23
+ return this._state;
24
+ }
25
+ /** The run token an in-flight pipeline captures at `start()`. */
26
+ get generation() {
27
+ return this._generation;
28
+ }
29
+ /** False once `reset()` (or a later `start()`) has superseded `token`. */
30
+ isCurrent(token) {
31
+ return this._generation === token;
32
+ }
33
+ /**
34
+ * Subscribe to every transition. Returns the unsubscribe function; calling
35
+ * it twice is harmless.
36
+ *
37
+ * Listeners are NOT called on subscribe — read `state` for the current
38
+ * value. A listener that throws is not allowed to break the pipeline or
39
+ * starve the listeners registered after it, so throws are swallowed.
40
+ */
41
+ subscribe(listener) {
42
+ this._listeners.add(listener);
43
+ return () => {
44
+ this._listeners.delete(listener);
45
+ };
46
+ }
47
+ /**
48
+ * Merge `next` into the state and notify, unless `token` names a
49
+ * superseded run.
50
+ */
51
+ patch(next, token) {
52
+ if (token !== undefined && !this.isCurrent(token))
53
+ return;
54
+ this._state = Object.assign(Object.assign({}, this._state), next);
55
+ for (const listener of [...this._listeners]) {
56
+ try {
57
+ listener(this._state);
58
+ }
59
+ catch (_a) {
60
+ // A consumer's rendering fault is its own problem; the pipeline
61
+ // owns real money and keeps going.
62
+ }
63
+ }
64
+ }
65
+ /**
66
+ * Back to the initial state, abandoning any in-flight run.
67
+ *
68
+ * Subscribers are kept: the consumer that was watching the last run is the
69
+ * one that will watch the next.
70
+ */
71
+ reset() {
72
+ this._generation += 1;
73
+ this.patch(this._initial);
74
+ }
75
+ /** Claim the next run token. Any earlier run is abandoned. */
76
+ beginRun() {
77
+ this._generation += 1;
78
+ return this._generation;
79
+ }
80
+ }
81
+ //# sourceMappingURL=observable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../src/flows/observable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,SAAS;IAKlB,YAA6B,QAAW;QAAX,aAAQ,GAAR,QAAQ,CAAG;QAHhC,gBAAW,GAAG,CAAC,CAAC;QACP,eAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;QAGxD,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,iEAAiE;IACjE,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,0EAA0E;IAC1E,SAAS,CAAC,KAAa;QACnB,OAAO,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,QAA4B;QAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE;YACR,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAgB,EAAE,KAAc;QAClC,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO;QAC1D,IAAI,CAAC,MAAM,mCAAQ,IAAI,CAAC,MAAM,GAAK,IAAI,CAAE,CAAC;QAC1C,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,CAAC;YAAC,WAAM,CAAC;gBACL,gEAAgE;gBAChE,mCAAmC;YACvC,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACD,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,8DAA8D;IAC9D,QAAQ;QACJ,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;CACJ"}
@@ -0,0 +1,99 @@
1
+ import { BigNumber } from 'ethers';
2
+ import { KycParams } from '../facade/types';
3
+ import { Flow } from './flow';
4
+ import { WaitableTransaction } from './observable';
5
+ /**
6
+ * The withdrawal pipeline, headless — the small sibling of `DepositFlow`.
7
+ *
8
+ * Much less happens here, and that is the point of it being separate: no loan
9
+ * agreement, no approval (the lender is handing tranche shares back, not
10
+ * granting a spend), no on-chain KYC payload. What survives is the shape both
11
+ * applications need — an observable phase, one `'max'`-aware submission, and
12
+ * the same `cancelled` / `failed` split, so a lender who pressed Reject is
13
+ * never told something broke.
14
+ *
15
+ * The run lifecycle — the re-entrancy guard, `state`, `isRunning`,
16
+ * `subscribe`, `reset` — is `Flow`'s, shared with the deposit pipeline. It was
17
+ * a second copy here until 2.7.0, which is two places for one guard to be
18
+ * wrong.
19
+ *
20
+ * Same house rules as the deposit flow: no React, no copy, no I/O of its own.
21
+ * `state` carries codes; the consumer owns every word a lender reads.
22
+ *
23
+ * ```ts
24
+ * const flow = new WithdrawFlow(ports);
25
+ * flow.subscribe(render);
26
+ * await flow.start({ poolId, trancheId, amount: 'max', userAddress });
27
+ * ```
28
+ */
29
+ export type WithdrawPhase = 'idle' | 'checking-kyc' | 'request-sign' | 'request-confirm' | 'success' | 'error';
30
+ /**
31
+ * `kyc` only exists when the consumer supplies `getKycSignature`. kasu-mobile
32
+ * does, to fail early and legibly when a lender's KYC has lapsed rather than
33
+ * let the on-chain call revert; kasu-ui does not.
34
+ */
35
+ export type WithdrawStep = 'kyc' | 'request';
36
+ export type WithdrawFailure = {
37
+ step: WithdrawStep;
38
+ reason: 'cancelled';
39
+ } | {
40
+ step: WithdrawStep;
41
+ reason: 'failed';
42
+ error: unknown;
43
+ };
44
+ export interface WithdrawPorts {
45
+ /**
46
+ * Build the Nexera KYC params for the pre-check. Defaults to
47
+ * `kasu.deposits.buildKycParams`, exactly as the deposit flow's does.
48
+ */
49
+ buildKycParams?(userAddress: `0x${string}`): KycParams | Promise<KycParams>;
50
+ /**
51
+ * Exchange those params for a signature at the consumer's own backend, and
52
+ * so verify the lender's KYC BEFORE the wallet is opened — a lapsed one
53
+ * surfaces as `{ step: 'kyc' }` instead of an opaque revert. The
54
+ * withdrawal call itself does not carry the signature.
55
+ *
56
+ * Supplying this port is what turns the pre-check on; there is no default,
57
+ * because the SDK does not know the application's backend. This is the
58
+ * same pair the deposit flow uses, rather than the opaque `ensureKyc` of
59
+ * earlier drafts, so one KYC pre-check exists across both money paths.
60
+ */
61
+ getKycSignature?(params: KycParams): Promise<unknown>;
62
+ /** `requestWithdrawalInAsset`. Defaults to `kasu.deposits.withdraw`. */
63
+ withdraw(params: {
64
+ poolId: string;
65
+ trancheId: string;
66
+ amount: BigNumber;
67
+ }): Promise<WaitableTransaction>;
68
+ /** `requestWithdrawalMax`. Defaults to `kasu.deposits.withdrawMax`. */
69
+ withdrawMax(poolId: string, trancheId: string, userAddress: string): Promise<WaitableTransaction>;
70
+ }
71
+ export interface WithdrawFlowInput {
72
+ poolId: string;
73
+ trancheId: string;
74
+ /**
75
+ * The amount in BASE units, or the literal `'max'`.
76
+ *
77
+ * `'max'` is not "the balance as I last read it": it routes to the
78
+ * all-shares contract call, which resolves the balance on chain at
79
+ * execution. Deciding max-ness from a number the consumer read a moment ago
80
+ * is how dust gets stranded in a tranche, so the decision is a code, made
81
+ * by the consumer, and carried here intact.
82
+ */
83
+ amount: BigNumber | 'max';
84
+ userAddress: `0x${string}`;
85
+ }
86
+ export interface WithdrawState {
87
+ phase: WithdrawPhase;
88
+ step: WithdrawStep | null;
89
+ /** True when this run routed through the all-shares call. */
90
+ isMax: boolean;
91
+ failure: WithdrawFailure | null;
92
+ }
93
+ /** What a KYC pre-check with no `buildKycParams` to call fails with. */
94
+ export declare const NO_KYC_PARAMS_MESSAGE = "WithdrawFlow: getKycSignature was supplied without buildKycParams; build the flow with kasu.flows.withdraw() or pass both";
95
+ export declare class WithdrawFlow extends Flow<WithdrawState, WithdrawFlowInput> {
96
+ private readonly _ports;
97
+ constructor(_ports: WithdrawPorts);
98
+ protected _run(input: WithdrawFlowInput, token: number): Promise<void>;
99
+ }
@@ -0,0 +1,83 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { classifyWalletFailure } from '../domain/wallet-errors';
11
+ import { Flow } from './flow';
12
+ const INITIAL = {
13
+ phase: 'idle',
14
+ step: null,
15
+ isMax: false,
16
+ failure: null,
17
+ };
18
+ /** What a KYC pre-check with no `buildKycParams` to call fails with. */
19
+ export const NO_KYC_PARAMS_MESSAGE = 'WithdrawFlow: getKycSignature was supplied without buildKycParams; build the flow with kasu.flows.withdraw() or pass both';
20
+ // ---------------------------------------------------------------------------
21
+ // The flow
22
+ // ---------------------------------------------------------------------------
23
+ export class WithdrawFlow extends Flow {
24
+ constructor(_ports) {
25
+ super(INITIAL);
26
+ this._ports = _ports;
27
+ }
28
+ _run(input, token) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const ports = this._ports;
31
+ const isMax = input.amount === 'max';
32
+ // 1. The optional KYC pre-check: build the params, exchange them for a
33
+ // signature. Both ports reach the application's own backend, so a
34
+ // throw here is ALWAYS `failed` — running it through the wallet
35
+ // rejection classifier would let a backend's "Declined" be reported
36
+ // to a lender as something they did, with the real error dropped.
37
+ if (ports.getKycSignature) {
38
+ this._store.patch({ phase: 'checking-kyc', step: 'kyc', isMax }, token);
39
+ try {
40
+ if (!ports.buildKycParams) {
41
+ throw new Error(NO_KYC_PARAMS_MESSAGE);
42
+ }
43
+ const params = yield ports.buildKycParams(input.userAddress);
44
+ yield ports.getKycSignature(params);
45
+ }
46
+ catch (err) {
47
+ this._store.patch({
48
+ phase: 'error',
49
+ failure: { step: 'kyc', reason: 'failed', error: err },
50
+ }, token);
51
+ return;
52
+ }
53
+ if (!this._store.isCurrent(token))
54
+ return;
55
+ }
56
+ // 2. The submission. This one IS a wallet call, so it keeps the
57
+ // `cancelled` / `failed` split.
58
+ this._store.patch({ phase: 'request-sign', step: 'request', isMax }, token);
59
+ try {
60
+ const tx = input.amount === 'max'
61
+ ? yield ports.withdrawMax(input.poolId, input.trancheId, input.userAddress.toLowerCase())
62
+ : yield ports.withdraw({
63
+ poolId: input.poolId,
64
+ trancheId: input.trancheId,
65
+ amount: input.amount,
66
+ });
67
+ this._store.patch({ phase: 'request-confirm' }, token);
68
+ yield tx.wait();
69
+ }
70
+ catch (err) {
71
+ this._store.patch({
72
+ phase: 'error',
73
+ failure: classifyWalletFailure('request', err),
74
+ }, token);
75
+ return;
76
+ }
77
+ if (!this._store.isCurrent(token))
78
+ return;
79
+ this._store.patch({ phase: 'success' }, token);
80
+ });
81
+ }
82
+ }
83
+ //# sourceMappingURL=withdraw-flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdraw-flow.js","sourceRoot":"","sources":["../../src/flows/withdraw-flow.ts"],"names":[],"mappings":"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"}
package/dist/index.d.ts CHANGED
@@ -6,5 +6,7 @@ export type { UserRequest, UserRequestEvent, UserTrancheBalance, UserPoolBalance
6
6
  export type { PortfolioSummary, PortfolioLendingPool, PortfolioTranche, PortfolioRewards, PortfolioTrancheDepositDetails, } from './services/Portfolio/types';
7
7
  export type { UserLock, UserBonusData, LockPeriod, GQLGetLockingPeriods, SystemVariables, } from './services/Locking/types';
8
8
  export type { PoolOverviewDirectus, PlatformOverviewDirectus, } from './services/DataService/directus-types';
9
+ export { NO_DIRECTUS_URL_MESSAGE } from './services/DataService/directus-client';
9
10
  export * from './facade';
10
11
  export * from './domain';
12
+ export * from './flows';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  // ---------------------------------------------------------------------------
4
4
  export { KasuSdk } from './kasu-sdk';
5
5
  export { SdkConfig } from './sdk-config';
6
+ export { NO_DIRECTUS_URL_MESSAGE } from './services/DataService/directus-client';
6
7
  // ---------------------------------------------------------------------------
7
8
  // Re-export facade (high-level integrator API)
8
9
  // ---------------------------------------------------------------------------
@@ -12,4 +13,10 @@ export * from './facade';
12
13
  // only: no copy, no locale. See `src/domain/index.ts`.
13
14
  // ---------------------------------------------------------------------------
14
15
  export * from './domain';
16
+ // ---------------------------------------------------------------------------
17
+ // Flows — the headless deposit / withdraw state machines. No React, no copy,
18
+ // no I/O of their own: every side effect is an injected port and every
19
+ // observable state is a code. See `src/flows/index.ts`.
20
+ // ---------------------------------------------------------------------------
21
+ export * from './flows';
15
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAgDzC,8EAA8E;AAC9E,+CAA+C;AAC/C,8EAA8E;AAC9E,cAAc,UAAU,CAAC;AAEzB,8EAA8E;AAC9E,6EAA6E;AAC7E,uDAAuD;AACvD,8EAA8E;AAC9E,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAgDzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,8EAA8E;AAC9E,+CAA+C;AAC/C,8EAA8E;AAC9E,cAAc,UAAU,CAAC;AAEzB,8EAA8E;AAC9E,6EAA6E;AAC7E,uDAAuD;AACvD,8EAA8E;AAC9E,cAAc,UAAU,CAAC;AAEzB,8EAA8E;AAC9E,6EAA6E;AAC7E,uEAAuE;AACvE,wDAAwD;AACxD,8EAA8E;AAC9E,cAAc,SAAS,CAAC"}
@@ -18,28 +18,21 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import { authentication, createDirectus, readItems, readSingleton, rest, } from '@directus/sdk';
21
+ import { readItems, readSingleton } from '@directus/sdk';
22
22
  import { formatUnits } from 'ethers/lib/utils';
23
23
  import { GraphQLClient } from 'graphql-request';
24
24
  import { KasuPoolExternalTVLAbi__factory, } from '../../contracts';
25
25
  import { epochRateToApy } from '../../domain/rates';
26
26
  import { getSystemVariablesQuery } from '../Locking/queries';
27
27
  import { filterArray } from '../shared';
28
+ import { createDirectusClient, } from './directus-client';
28
29
  import { getAllTrancheConfigurationsQuery, getAllTranchesQuery, getLendingPoolWithdrawalAndDepositsQuery, getPoolNameQuery, getPoolOverviewQuery, } from './queries';
29
30
  export class DataService {
30
31
  constructor(_kasuConfig, signerOrProvider) {
31
32
  this._kasuConfig = _kasuConfig;
32
33
  this._externalTvlAbi = KasuPoolExternalTVLAbi__factory.connect(_kasuConfig.contracts.ExternalTVL, signerOrProvider);
33
34
  this._graph = new GraphQLClient(_kasuConfig.subgraphUrl);
34
- if (_kasuConfig.directusUrl) {
35
- this._directus = createDirectus(_kasuConfig.directusUrl)
36
- .with(authentication())
37
- .with(rest());
38
- }
39
- else {
40
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
41
- this._directus = null;
42
- }
35
+ this._directus = createDirectusClient(_kasuConfig.directusUrl);
43
36
  }
44
37
  getUrlFromFile(fileName) {
45
38
  return `${this._kasuConfig.directusUrl}assets/${fileName}`;
@@ -333,7 +326,6 @@ export class DataService {
333
326
  return __awaiter(this, void 0, void 0, function* () {
334
327
  var _a;
335
328
  const poolDelegateProfileAndHistoryDirectus = (yield this._directus.request(readItems('PoolDelegateProfileAndHistory', {
336
- // @ts-ignore Directus' deep-fields typing is fragile across versions
337
329
  fields: ['*', { otherPools: ['*'] }],
338
330
  })));
339
331
  const [poolNames, directusPoolNames] = yield Promise.all([