@kasufinance/kasu-sdk 2.6.0 → 2.7.1

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 (126) hide show
  1. package/README.md +167 -4
  2. package/dist/bundle.cjs.js +1389 -257
  3. package/dist/bundle.esm.js +1375 -258
  4. package/dist/domain/index.d.ts +5 -2
  5. package/dist/domain/index.js +3 -2
  6. package/dist/domain/index.js.map +1 -1
  7. package/dist/domain/requests.d.ts +42 -4
  8. package/dist/domain/requests.js +20 -4
  9. package/dist/domain/requests.js.map +1 -1
  10. package/dist/domain/revert-errors.d.ts +59 -0
  11. package/dist/domain/revert-errors.js +190 -0
  12. package/dist/domain/revert-errors.js.map +1 -0
  13. package/dist/domain/wallet-errors.d.ts +63 -8
  14. package/dist/domain/wallet-errors.js +115 -16
  15. package/dist/domain/wallet-errors.js.map +1 -1
  16. package/dist/facade/deposits.js +2 -1
  17. package/dist/facade/deposits.js.map +1 -1
  18. package/dist/facade/flows.d.ts +95 -0
  19. package/dist/facade/flows.js +116 -0
  20. package/dist/facade/flows.js.map +1 -0
  21. package/dist/facade/index.d.ts +3 -0
  22. package/dist/facade/index.js +3 -0
  23. package/dist/facade/index.js.map +1 -1
  24. package/dist/facade/kasu.d.ts +6 -2
  25. package/dist/facade/kasu.js +28 -3
  26. package/dist/facade/kasu.js.map +1 -1
  27. package/dist/facade/read-only.d.ts +12 -0
  28. package/dist/facade/read-only.js +13 -0
  29. package/dist/facade/read-only.js.map +1 -0
  30. package/dist/flows/deposit-flow.d.ts +332 -0
  31. package/dist/flows/deposit-flow.js +436 -0
  32. package/dist/flows/deposit-flow.js.map +1 -0
  33. package/dist/flows/flow.d.ts +72 -0
  34. package/dist/flows/flow.js +110 -0
  35. package/dist/flows/flow.js.map +1 -0
  36. package/dist/flows/index.d.ts +19 -0
  37. package/dist/flows/index.js +17 -0
  38. package/dist/flows/index.js.map +1 -0
  39. package/dist/flows/observable.d.ts +59 -0
  40. package/dist/flows/observable.js +81 -0
  41. package/dist/flows/observable.js.map +1 -0
  42. package/dist/flows/withdraw-flow.d.ts +99 -0
  43. package/dist/flows/withdraw-flow.js +83 -0
  44. package/dist/flows/withdraw-flow.js.map +1 -0
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.js +6 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/services/DataService/data-service.js +0 -1
  49. package/dist/services/DataService/data-service.js.map +1 -1
  50. package/package.json +8 -2
  51. package/src/domain/index.ts +10 -1
  52. package/src/domain/requests.ts +57 -4
  53. package/src/domain/revert-errors.ts +248 -0
  54. package/src/domain/wallet-errors.ts +135 -18
  55. package/src/facade/deposits.ts +2 -3
  56. package/src/facade/flows.ts +172 -0
  57. package/src/facade/index.ts +8 -0
  58. package/src/facade/kasu.ts +43 -3
  59. package/src/facade/read-only.ts +13 -0
  60. package/src/flows/deposit-flow.ts +884 -0
  61. package/src/flows/flow.ts +108 -0
  62. package/src/flows/index.ts +47 -0
  63. package/src/flows/observable.ts +97 -0
  64. package/src/flows/withdraw-flow.ts +210 -0
  65. package/src/index.ts +7 -0
  66. package/src/services/DataService/data-service.ts +0 -1
  67. package/dist/domain/au-minimum.test.d.ts +0 -1
  68. package/dist/domain/au-minimum.test.js +0 -202
  69. package/dist/domain/au-minimum.test.js.map +0 -1
  70. package/dist/domain/deposit-bounds.test.d.ts +0 -1
  71. package/dist/domain/deposit-bounds.test.js +0 -135
  72. package/dist/domain/deposit-bounds.test.js.map +0 -1
  73. package/dist/domain/loan-contract.test.d.ts +0 -1
  74. package/dist/domain/loan-contract.test.js +0 -255
  75. package/dist/domain/loan-contract.test.js.map +0 -1
  76. package/dist/domain/partners.test.d.ts +0 -1
  77. package/dist/domain/partners.test.js +0 -53
  78. package/dist/domain/partners.test.js.map +0 -1
  79. package/dist/domain/pools.test.d.ts +0 -1
  80. package/dist/domain/pools.test.js +0 -184
  81. package/dist/domain/pools.test.js.map +0 -1
  82. package/dist/domain/rates.test.d.ts +0 -1
  83. package/dist/domain/rates.test.js +0 -181
  84. package/dist/domain/rates.test.js.map +0 -1
  85. package/dist/domain/requests.test.d.ts +0 -1
  86. package/dist/domain/requests.test.js +0 -470
  87. package/dist/domain/requests.test.js.map +0 -1
  88. package/dist/domain/settlement.test.d.ts +0 -1
  89. package/dist/domain/settlement.test.js +0 -152
  90. package/dist/domain/settlement.test.js.map +0 -1
  91. package/dist/domain/tranche-display-name.test.d.ts +0 -1
  92. package/dist/domain/tranche-display-name.test.js +0 -58
  93. package/dist/domain/tranche-display-name.test.js.map +0 -1
  94. package/dist/domain/tranches.test.d.ts +0 -1
  95. package/dist/domain/tranches.test.js +0 -206
  96. package/dist/domain/tranches.test.js.map +0 -1
  97. package/dist/domain/wallet-errors.test.d.ts +0 -1
  98. package/dist/domain/wallet-errors.test.js +0 -71
  99. package/dist/domain/wallet-errors.test.js.map +0 -1
  100. package/dist/facade/config.test.d.ts +0 -1
  101. package/dist/facade/config.test.js +0 -216
  102. package/dist/facade/config.test.js.map +0 -1
  103. package/dist/facade/facade.test.d.ts +0 -1
  104. package/dist/facade/facade.test.js +0 -278
  105. package/dist/facade/facade.test.js.map +0 -1
  106. package/dist/services/Locking/calculate-apy.test.d.ts +0 -1
  107. package/dist/services/Locking/calculate-apy.test.js +0 -41
  108. package/dist/services/Locking/calculate-apy.test.js.map +0 -1
  109. package/dist/tests/sample.test.d.ts +0 -1
  110. package/dist/tests/sample.test.js +0 -59
  111. package/dist/tests/sample.test.js.map +0 -1
  112. package/src/domain/au-minimum.test.ts +0 -371
  113. package/src/domain/deposit-bounds.test.ts +0 -200
  114. package/src/domain/loan-contract.test.ts +0 -343
  115. package/src/domain/partners.test.ts +0 -83
  116. package/src/domain/pools.test.ts +0 -260
  117. package/src/domain/rates.test.ts +0 -254
  118. package/src/domain/requests.test.ts +0 -653
  119. package/src/domain/settlement.test.ts +0 -198
  120. package/src/domain/tranche-display-name.test.ts +0 -96
  121. package/src/domain/tranches.test.ts +0 -300
  122. package/src/domain/wallet-errors.test.ts +0 -100
  123. package/src/facade/config.test.ts +0 -265
  124. package/src/facade/facade.test.ts +0 -374
  125. package/src/services/Locking/calculate-apy.test.ts +0 -52
  126. package/src/tests/sample.test.ts +0 -63
@@ -1,11 +1,14 @@
1
1
  import { Provider } from '@ethersproject/providers';
2
2
  import { providers, Signer } from 'ethers';
3
3
 
4
+ import { IERC20MetadataAbi__factory } from '../contracts';
5
+ import type { IERC20MetadataAbi } from '../contracts';
4
6
  import { KasuSdk } from '../kasu-sdk';
5
7
  import { SdkConfig, SdkConfigOptions } from '../sdk-config';
6
8
 
7
9
  import { CHAIN_CONFIGS } from './chain-configs';
8
10
  import { DepositsFacade } from './deposits';
11
+ import { FlowsFacade } from './flows';
9
12
  import { StrategiesFacade } from './strategies';
10
13
  import {
11
14
  ChainConfigEntry,
@@ -18,8 +21,9 @@ import { PortfolioFacade } from './user-portfolio';
18
21
  /**
19
22
  * High-level entry point for external integrators.
20
23
  *
21
- * Provides three domain facades — `strategies`, `deposits`, `portfolio` — and
22
- * exposes the underlying `KasuSdk` services via `.services` for power-users.
24
+ * Provides four domain facades — `strategies`, `deposits`, `portfolio`,
25
+ * `flows` — and exposes the underlying `KasuSdk` services via `.services` for
26
+ * power-users.
23
27
  *
24
28
  * ```ts
25
29
  * import { Kasu } from '@kasufinance/kasu-sdk';
@@ -43,6 +47,8 @@ export class Kasu {
43
47
  public readonly deposits: DepositsFacade;
44
48
  /** User positions, yields, transaction history. */
45
49
  public readonly portfolio: PortfolioFacade;
50
+ /** Headless deposit / withdraw state machines. */
51
+ public readonly flows: FlowsFacade;
46
52
 
47
53
  private readonly _sdk: KasuSdk;
48
54
  private readonly _chainConfig: ChainConfigEntry;
@@ -70,10 +76,15 @@ export class Kasu {
70
76
  sdk.UserLending,
71
77
  );
72
78
 
79
+ // Derived ONCE and handed to every facade that needs it. Each of them
80
+ // re-deriving `Signer.isSigner` is how two facades come to disagree
81
+ // about whether the same instance can write.
82
+ const isReadOnly = !Signer.isSigner(signerOrProvider);
83
+
73
84
  this.deposits = new DepositsFacade(
74
85
  sdk.UserLending,
75
86
  chainConfig.chainId.toString(),
76
- !Signer.isSigner(signerOrProvider),
87
+ isReadOnly,
77
88
  );
78
89
 
79
90
  this.portfolio = new PortfolioFacade(
@@ -81,6 +92,13 @@ export class Kasu {
81
92
  sdk.UserLending,
82
93
  sdk.Portfolio,
83
94
  );
95
+
96
+ this.flows = new FlowsFacade(
97
+ this.deposits,
98
+ () => erc20Of(chainConfig, signerOrProvider),
99
+ isReadOnly,
100
+ chainConfig.contracts.LendingPoolManager,
101
+ );
84
102
  }
85
103
 
86
104
  /**
@@ -241,6 +259,28 @@ function rpcUrlsOf(chainConfig: ChainConfigEntry): string[] {
241
259
  return (chainConfig as { rpcUrls?: string[] }).rpcUrls ?? [];
242
260
  }
243
261
 
262
+ /**
263
+ * The chain's stable token, bound to whatever this instance holds.
264
+ *
265
+ * Built per call rather than cached: it is one `new Contract`, and a cached
266
+ * binding would outlive the signer a `connect()` replaced. A config with no
267
+ * `stableAsset` (a hand-written entry from before 2.5.0) throws here rather
268
+ * than inside ethers, naming the two ports that make the flow work without
269
+ * one.
270
+ */
271
+ function erc20Of(
272
+ chainConfig: ChainConfigEntry,
273
+ signerOrProvider: Provider | Signer,
274
+ ): IERC20MetadataAbi {
275
+ const address = stableAssetOf(chainConfig)?.address;
276
+ if (!address) {
277
+ throw new Error(
278
+ 'Kasu: this chain config has no stableAsset; pass readAllowance and approve ports explicitly',
279
+ );
280
+ }
281
+ return IERC20MetadataAbi__factory.connect(address, signerOrProvider);
282
+ }
283
+
244
284
  /**
245
285
  * The read-only provider used when the caller passes no `signerOrProvider`.
246
286
  *
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The refusal every write path shares when the instance holds a Provider
3
+ * rather than a Signer.
4
+ *
5
+ * One constant, because the message's job is to name the fix — `kasu.connect`
6
+ * — and three near-identical wordings across the facades would be three
7
+ * different pieces of advice for one problem. ethers' own
8
+ * "sending a transaction requires a signer" arrives several frames deeper,
9
+ * after the params have been encoded, and says nothing about how to get a
10
+ * signer onto THIS object.
11
+ */
12
+ export const READ_ONLY_MESSAGE =
13
+ 'Kasu: this instance is read-only; call kasu.connect(signer) first';