@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.
- package/README.md +167 -4
- package/dist/bundle.cjs.js +1389 -257
- package/dist/bundle.esm.js +1375 -258
- package/dist/domain/index.d.ts +5 -2
- package/dist/domain/index.js +3 -2
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/requests.d.ts +42 -4
- package/dist/domain/requests.js +20 -4
- package/dist/domain/requests.js.map +1 -1
- package/dist/domain/revert-errors.d.ts +59 -0
- package/dist/domain/revert-errors.js +190 -0
- package/dist/domain/revert-errors.js.map +1 -0
- package/dist/domain/wallet-errors.d.ts +63 -8
- package/dist/domain/wallet-errors.js +115 -16
- package/dist/domain/wallet-errors.js.map +1 -1
- package/dist/facade/deposits.js +2 -1
- package/dist/facade/deposits.js.map +1 -1
- package/dist/facade/flows.d.ts +95 -0
- package/dist/facade/flows.js +116 -0
- package/dist/facade/flows.js.map +1 -0
- package/dist/facade/index.d.ts +3 -0
- package/dist/facade/index.js +3 -0
- package/dist/facade/index.js.map +1 -1
- package/dist/facade/kasu.d.ts +6 -2
- package/dist/facade/kasu.js +28 -3
- package/dist/facade/kasu.js.map +1 -1
- package/dist/facade/read-only.d.ts +12 -0
- package/dist/facade/read-only.js +13 -0
- package/dist/facade/read-only.js.map +1 -0
- package/dist/flows/deposit-flow.d.ts +332 -0
- package/dist/flows/deposit-flow.js +436 -0
- package/dist/flows/deposit-flow.js.map +1 -0
- package/dist/flows/flow.d.ts +72 -0
- package/dist/flows/flow.js +110 -0
- package/dist/flows/flow.js.map +1 -0
- package/dist/flows/index.d.ts +19 -0
- package/dist/flows/index.js +17 -0
- package/dist/flows/index.js.map +1 -0
- package/dist/flows/observable.d.ts +59 -0
- package/dist/flows/observable.js +81 -0
- package/dist/flows/observable.js.map +1 -0
- package/dist/flows/withdraw-flow.d.ts +99 -0
- package/dist/flows/withdraw-flow.js +83 -0
- package/dist/flows/withdraw-flow.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/services/DataService/data-service.js +0 -1
- package/dist/services/DataService/data-service.js.map +1 -1
- package/package.json +8 -2
- package/src/domain/index.ts +10 -1
- package/src/domain/requests.ts +57 -4
- package/src/domain/revert-errors.ts +248 -0
- package/src/domain/wallet-errors.ts +135 -18
- package/src/facade/deposits.ts +2 -3
- package/src/facade/flows.ts +172 -0
- package/src/facade/index.ts +8 -0
- package/src/facade/kasu.ts +43 -3
- package/src/facade/read-only.ts +13 -0
- package/src/flows/deposit-flow.ts +884 -0
- package/src/flows/flow.ts +108 -0
- package/src/flows/index.ts +47 -0
- package/src/flows/observable.ts +97 -0
- package/src/flows/withdraw-flow.ts +210 -0
- package/src/index.ts +7 -0
- package/src/services/DataService/data-service.ts +0 -1
- package/dist/domain/au-minimum.test.d.ts +0 -1
- package/dist/domain/au-minimum.test.js +0 -202
- package/dist/domain/au-minimum.test.js.map +0 -1
- package/dist/domain/deposit-bounds.test.d.ts +0 -1
- package/dist/domain/deposit-bounds.test.js +0 -135
- package/dist/domain/deposit-bounds.test.js.map +0 -1
- package/dist/domain/loan-contract.test.d.ts +0 -1
- package/dist/domain/loan-contract.test.js +0 -255
- package/dist/domain/loan-contract.test.js.map +0 -1
- package/dist/domain/partners.test.d.ts +0 -1
- package/dist/domain/partners.test.js +0 -53
- package/dist/domain/partners.test.js.map +0 -1
- package/dist/domain/pools.test.d.ts +0 -1
- package/dist/domain/pools.test.js +0 -184
- package/dist/domain/pools.test.js.map +0 -1
- package/dist/domain/rates.test.d.ts +0 -1
- package/dist/domain/rates.test.js +0 -181
- package/dist/domain/rates.test.js.map +0 -1
- package/dist/domain/requests.test.d.ts +0 -1
- package/dist/domain/requests.test.js +0 -470
- package/dist/domain/requests.test.js.map +0 -1
- package/dist/domain/settlement.test.d.ts +0 -1
- package/dist/domain/settlement.test.js +0 -152
- package/dist/domain/settlement.test.js.map +0 -1
- package/dist/domain/tranche-display-name.test.d.ts +0 -1
- package/dist/domain/tranche-display-name.test.js +0 -58
- package/dist/domain/tranche-display-name.test.js.map +0 -1
- package/dist/domain/tranches.test.d.ts +0 -1
- package/dist/domain/tranches.test.js +0 -206
- package/dist/domain/tranches.test.js.map +0 -1
- package/dist/domain/wallet-errors.test.d.ts +0 -1
- package/dist/domain/wallet-errors.test.js +0 -71
- package/dist/domain/wallet-errors.test.js.map +0 -1
- package/dist/facade/config.test.d.ts +0 -1
- package/dist/facade/config.test.js +0 -216
- package/dist/facade/config.test.js.map +0 -1
- package/dist/facade/facade.test.d.ts +0 -1
- package/dist/facade/facade.test.js +0 -278
- package/dist/facade/facade.test.js.map +0 -1
- package/dist/services/Locking/calculate-apy.test.d.ts +0 -1
- package/dist/services/Locking/calculate-apy.test.js +0 -41
- package/dist/services/Locking/calculate-apy.test.js.map +0 -1
- package/dist/tests/sample.test.d.ts +0 -1
- package/dist/tests/sample.test.js +0 -59
- package/dist/tests/sample.test.js.map +0 -1
- package/src/domain/au-minimum.test.ts +0 -371
- package/src/domain/deposit-bounds.test.ts +0 -200
- package/src/domain/loan-contract.test.ts +0 -343
- package/src/domain/partners.test.ts +0 -83
- package/src/domain/pools.test.ts +0 -260
- package/src/domain/rates.test.ts +0 -254
- package/src/domain/requests.test.ts +0 -653
- package/src/domain/settlement.test.ts +0 -198
- package/src/domain/tranche-display-name.test.ts +0 -96
- package/src/domain/tranches.test.ts +0 -300
- package/src/domain/wallet-errors.test.ts +0 -100
- package/src/facade/config.test.ts +0 -265
- package/src/facade/facade.test.ts +0 -374
- package/src/services/Locking/calculate-apy.test.ts +0 -52
- package/src/tests/sample.test.ts +0 -63
package/src/facade/kasu.ts
CHANGED
|
@@ -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
|
|
22
|
-
* exposes the underlying `KasuSdk` services via `.services` for
|
|
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
|
-
|
|
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';
|