@gearbox-protocol/sdk 16.0.0-next.12 → 16.0.0-next.14

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 (51) hide show
  1. package/dist/cjs/model/charts.js +5 -1
  2. package/dist/cjs/model/index.js +3 -1
  3. package/dist/cjs/model/opportunities.schema.js +9 -0
  4. package/dist/cjs/model/positions.js +6 -0
  5. package/dist/cjs/model/positions.schema.js +2 -1
  6. package/dist/cjs/model/previews.js +4 -3
  7. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +9 -0
  8. package/dist/cjs/offchain/positions/OffchainPositions.js +9 -0
  9. package/dist/cjs/onchain/market/adapters/contracts/AbstractAdapter.js +14 -0
  10. package/dist/cjs/onchain/market/adapters/contracts/ERC4626AdapterContract.js +54 -0
  11. package/dist/cjs/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +13 -0
  12. package/dist/cjs/onchain/positions/PositionsService.js +20 -17
  13. package/dist/cjs/preview/preview/replayInnerOperations.js +10 -25
  14. package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +6 -0
  15. package/dist/cjs/sdk/positions/PositionsNamespace.js +6 -0
  16. package/dist/esm/model/charts.js +5 -1
  17. package/dist/esm/model/index.js +4 -4
  18. package/dist/esm/model/opportunities.schema.js +9 -1
  19. package/dist/esm/model/positions.js +6 -1
  20. package/dist/esm/model/positions.schema.js +2 -1
  21. package/dist/esm/model/previews.js +4 -3
  22. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +10 -1
  23. package/dist/esm/offchain/positions/OffchainPositions.js +10 -1
  24. package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +14 -0
  25. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +55 -1
  26. package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +14 -1
  27. package/dist/esm/onchain/positions/PositionsService.js +21 -18
  28. package/dist/esm/preview/preview/replayInnerOperations.js +11 -26
  29. package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +6 -0
  30. package/dist/esm/sdk/positions/PositionsNamespace.js +6 -0
  31. package/dist/types/model/charts.d.ts +4 -2
  32. package/dist/types/model/charts.schema.d.ts +8 -0
  33. package/dist/types/model/index.d.ts +5 -5
  34. package/dist/types/model/opportunities.d.ts +19 -1
  35. package/dist/types/model/opportunities.schema.d.ts +9 -1
  36. package/dist/types/model/positions.d.ts +13 -1
  37. package/dist/types/model/positions.schema.d.ts +2 -0
  38. package/dist/types/model/previews.d.ts +4 -3
  39. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +5 -1
  40. package/dist/types/offchain/positions/OffchainPositions.d.ts +6 -1
  41. package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +12 -0
  42. package/dist/types/onchain/market/adapters/contracts/ERC4626AdapterContract.d.ts +8 -1
  43. package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +7 -0
  44. package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
  45. package/dist/types/sdk/opportunities/types.d.ts +9 -1
  46. package/dist/types/sdk/positions/PositionsNamespace.d.ts +5 -1
  47. package/dist/types/sdk/positions/types.d.ts +9 -1
  48. package/package.json +1 -1
  49. package/dist/cjs/preview/preview/applyRWAWrapUnwrap.js +0 -67
  50. package/dist/esm/preview/preview/applyRWAWrapUnwrap.js +0 -66
  51. package/dist/types/preview/preview/applyRWAWrapUnwrap.d.ts +0 -17
@@ -649,6 +649,13 @@ declare class MidasGatewayAdapterContract extends AbstractAdapterContract<abi, p
649
649
  * redemption from a redeemer contract.
650
650
  */
651
651
  parseDelayedWithdrawalClaim(calldata: Hex): DelayedWithdrawalClaim | undefined;
652
+ /**
653
+ * `receiveGreenlist()` is prepended by `prependMidasReceiveGreenlist`
654
+ * before the balance bracket when the multicall mints a permissioned
655
+ * mToken: it only greenlists the credit account and is balance-neutral,
656
+ * so it is legal outside a bracket and leaves balances untouched.
657
+ */
658
+ replayOutOfBracketCall(_balances: AssetsMap, calldata: Hex): boolean;
652
659
  protected applyBalanceChanges(balances: AssetsMap, decoded: DecodeFunctionDataReturnType<abi>): Promise<void>;
653
660
  }
654
661
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { ChartBundle, ChartRange, PoolOpportunityChartMetric, StrategyOpportunityChartMetric } from "../../model/charts.js";
2
- import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
2
+ import { Opportunity, OpportunityFilter, OpportunityTotals, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
3
3
  import { DataResponse } from "../../model/response.js";
4
4
  import "../../model/index.js";
5
5
  import { MultichainSDK } from "../../onchain/MultichainSDK.js";
@@ -51,6 +51,10 @@ declare class OpportunitiesNamespace extends AbstractNamespace<MultichainSDK["op
51
51
  * {@inheritDoc OpportunitiesBase.filter}
52
52
  **/
53
53
  filter<R extends DataResponse<Opportunity[]> | undefined>(response: R, filter?: OpportunityFilter): FilterResult<R, Opportunity>;
54
+ /**
55
+ * {@inheritDoc OpportunitiesOffchainOnly.totals}
56
+ **/
57
+ totals(): Promise<DataResponse<OpportunityTotals>>;
54
58
  /**
55
59
  * {@inheritDoc OpportunitiesOffchainOnly.charts}
56
60
  **/
@@ -1,5 +1,5 @@
1
1
  import { ChartBundle, ChartRange, PoolOpportunityChartMetric, StrategyOpportunityChartMetric } from "../../model/charts.js";
2
- import { Opportunity, OpportunityFilter, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
2
+ import { Opportunity, OpportunityFilter, OpportunityTotals, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef } from "../../model/opportunities.js";
3
3
  import { DataResponse } from "../../model/response.js";
4
4
  import "../../model/index.js";
5
5
  import { MultichainOpportunitiesService } from "../../onchain/opportunities/MultichainOpportunitiesService.js";
@@ -58,6 +58,14 @@ interface OpportunitiesBase {
58
58
  * Reads only a backend can answer.
59
59
  **/
60
60
  interface OpportunitiesOffchainOnly {
61
+ /**
62
+ * Protocol-wide totals across every opportunity: the TVL, total borrowed and
63
+ * total supplied the landing page shows.
64
+ *
65
+ * Absent in `onchain` mode: it is served by the backend rather than summed
66
+ * from the chain.
67
+ **/
68
+ totals(): Promise<DataResponse<OpportunityTotals>>;
61
69
  /**
62
70
  * Historical charts of one opportunity, one series per metric on a shared
63
71
  * axis: `charts(key, ["depositApy", "depositApyAvg7d"], "1m")`.
@@ -1,5 +1,5 @@
1
1
  import { ChartBundle, ChartRange, PoolPositionChartMetric, StrategyPositionChartMetric } from "../../model/charts.js";
2
- import { PoolPositionRef, Position, PositionFilter, StrategyPositionRef } from "../../model/positions.js";
2
+ import { PoolPositionRef, Position, PositionFilter, PositionsTotals, StrategyPositionRef } from "../../model/positions.js";
3
3
  import { DataResponse } from "../../model/response.js";
4
4
  import "../../model/index.js";
5
5
  import { MultichainSDK } from "../../onchain/MultichainSDK.js";
@@ -31,6 +31,10 @@ declare class PositionsNamespace extends AbstractNamespace<MultichainSDK["positi
31
31
  * {@inheritDoc PositionsBase.filter}
32
32
  **/
33
33
  filter<R extends DataResponse<Position[]> | undefined>(response: R, filter?: PositionFilter): FilterResult<R, Position>;
34
+ /**
35
+ * {@inheritDoc PositionsOffchainOnly.totals}
36
+ **/
37
+ totals(wallet: Address): Promise<DataResponse<PositionsTotals>>;
34
38
  /**
35
39
  * {@inheritDoc PositionsOffchainOnly.charts}
36
40
  **/
@@ -1,5 +1,5 @@
1
1
  import { ChartBundle, ChartRange, PoolPositionChartMetric, StrategyPositionChartMetric } from "../../model/charts.js";
2
- import { PoolPositionRef, Position, PositionFilter, StrategyPositionRef } from "../../model/positions.js";
2
+ import { PoolPositionRef, Position, PositionFilter, PositionsTotals, StrategyPositionRef } from "../../model/positions.js";
3
3
  import { DataResponse } from "../../model/response.js";
4
4
  import "../../model/index.js";
5
5
  import { MultichainPositionsService } from "../../onchain/positions/MultichainPositionsService.js";
@@ -48,6 +48,14 @@ interface PositionsBase {
48
48
  * Reads only a backend can answer.
49
49
  **/
50
50
  interface PositionsOffchainOnly {
51
+ /**
52
+ * Aggregate over everything a wallet holds: the list screen's badges, see
53
+ * {@link PositionsTotals}.
54
+ *
55
+ * Absent in `onchain` mode: it is served by the backend rather than summed
56
+ * from the chain.
57
+ **/
58
+ totals(wallet: Address): Promise<DataResponse<PositionsTotals>>;
51
59
  /**
52
60
  * Historical charts of one position, one series per metric on a shared axis:
53
61
  * `charts(key, ["apy", "mwr"], "1m")`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.0.0-next.12",
3
+ "version": "16.0.0-next.14",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,67 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_abi_ierc4626Adapter = require("../../abi/ierc4626Adapter.js");
3
- let viem = require("viem");
4
- //#region src/preview/preview/applyRWAWrapUnwrap.ts
5
- /**
6
- * Maps the decoded adapter call to the conversion it performs. Diff variants
7
- * spend the running balance down to the calldata leftover, so their input
8
- * amount comes from `balances`. Returns `undefined` for functions we do not
9
- * handle (`mint`/`withdraw` are never emitted by the RWA flows).
10
- */
11
- function resolveWrapUnwrap(adapter, calldata, balances) {
12
- const decoded = (0, viem.decodeFunctionData)({
13
- abi: require_abi_ierc4626Adapter.ierc4626AdapterAbi,
14
- data: calldata
15
- });
16
- const { asset, share } = adapter;
17
- switch (decoded.functionName) {
18
- case "deposit": return {
19
- tokenIn: asset,
20
- tokenOut: share,
21
- amountIn: decoded.args[0]
22
- };
23
- case "depositDiff": {
24
- const [leftoverAmount] = decoded.args;
25
- const running = balances.getOrZero(asset);
26
- return {
27
- tokenIn: asset,
28
- tokenOut: share,
29
- amountIn: running > leftoverAmount ? running - leftoverAmount : 0n
30
- };
31
- }
32
- case "redeem": return {
33
- tokenIn: share,
34
- tokenOut: asset,
35
- amountIn: decoded.args[0]
36
- };
37
- case "redeemDiff": {
38
- const [leftoverAmount] = decoded.args;
39
- const running = balances.getOrZero(share);
40
- return {
41
- tokenIn: share,
42
- tokenOut: asset,
43
- amountIn: running > leftoverAmount ? running - leftoverAmount : 0n
44
- };
45
- }
46
- default: return;
47
- }
48
- }
49
- /**
50
- * Applies an RWA wrap/unwrap adapter call (ERC4626 `deposit`/`redeem` and
51
- * their diff variants, as emitted by `CreditAccountsServiceV310`) to the
52
- * running credit-account balances.
53
- *
54
- * RWA underlyings always convert 1-to-1 with their vault asset, so the
55
- * counterpart amount equals the input amount and no on-chain preview read is
56
- * needed.
57
- */
58
- function applyRWAWrapUnwrap(adapter, calldata, balances) {
59
- const resolved = resolveWrapUnwrap(adapter, calldata, balances);
60
- if (!resolved) return;
61
- const { tokenIn, tokenOut, amountIn } = resolved;
62
- if (amountIn === 0n) return;
63
- balances.dec(tokenIn, amountIn);
64
- balances.inc(tokenOut, amountIn);
65
- }
66
- //#endregion
67
- exports.applyRWAWrapUnwrap = applyRWAWrapUnwrap;
@@ -1,66 +0,0 @@
1
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
2
- import { decodeFunctionData } from "viem";
3
- //#region src/preview/preview/applyRWAWrapUnwrap.ts
4
- /**
5
- * Maps the decoded adapter call to the conversion it performs. Diff variants
6
- * spend the running balance down to the calldata leftover, so their input
7
- * amount comes from `balances`. Returns `undefined` for functions we do not
8
- * handle (`mint`/`withdraw` are never emitted by the RWA flows).
9
- */
10
- function resolveWrapUnwrap(adapter, calldata, balances) {
11
- const decoded = decodeFunctionData({
12
- abi: ierc4626AdapterAbi,
13
- data: calldata
14
- });
15
- const { asset, share } = adapter;
16
- switch (decoded.functionName) {
17
- case "deposit": return {
18
- tokenIn: asset,
19
- tokenOut: share,
20
- amountIn: decoded.args[0]
21
- };
22
- case "depositDiff": {
23
- const [leftoverAmount] = decoded.args;
24
- const running = balances.getOrZero(asset);
25
- return {
26
- tokenIn: asset,
27
- tokenOut: share,
28
- amountIn: running > leftoverAmount ? running - leftoverAmount : 0n
29
- };
30
- }
31
- case "redeem": return {
32
- tokenIn: share,
33
- tokenOut: asset,
34
- amountIn: decoded.args[0]
35
- };
36
- case "redeemDiff": {
37
- const [leftoverAmount] = decoded.args;
38
- const running = balances.getOrZero(share);
39
- return {
40
- tokenIn: share,
41
- tokenOut: asset,
42
- amountIn: running > leftoverAmount ? running - leftoverAmount : 0n
43
- };
44
- }
45
- default: return;
46
- }
47
- }
48
- /**
49
- * Applies an RWA wrap/unwrap adapter call (ERC4626 `deposit`/`redeem` and
50
- * their diff variants, as emitted by `CreditAccountsServiceV310`) to the
51
- * running credit-account balances.
52
- *
53
- * RWA underlyings always convert 1-to-1 with their vault asset, so the
54
- * counterpart amount equals the input amount and no on-chain preview read is
55
- * needed.
56
- */
57
- function applyRWAWrapUnwrap(adapter, calldata, balances) {
58
- const resolved = resolveWrapUnwrap(adapter, calldata, balances);
59
- if (!resolved) return;
60
- const { tokenIn, tokenOut, amountIn } = resolved;
61
- if (amountIn === 0n) return;
62
- balances.dec(tokenIn, amountIn);
63
- balances.inc(tokenOut, amountIn);
64
- }
65
- //#endregion
66
- export { applyRWAWrapUnwrap };
@@ -1,17 +0,0 @@
1
- import { AssetsMap } from "../../onchain/utils/AssetsMap.js";
2
- import { ERC4626AdapterContract } from "../../onchain/market/adapters/contracts/ERC4626AdapterContract.js";
3
- import "../../onchain/index.js";
4
- import { Hex } from "viem";
5
- //#region src/preview/preview/applyRWAWrapUnwrap.d.ts
6
- /**
7
- * Applies an RWA wrap/unwrap adapter call (ERC4626 `deposit`/`redeem` and
8
- * their diff variants, as emitted by `CreditAccountsServiceV310`) to the
9
- * running credit-account balances.
10
- *
11
- * RWA underlyings always convert 1-to-1 with their vault asset, so the
12
- * counterpart amount equals the input amount and no on-chain preview read is
13
- * needed.
14
- */
15
- declare function applyRWAWrapUnwrap(adapter: ERC4626AdapterContract, calldata: Hex, balances: AssetsMap): void;
16
- //#endregion
17
- export { applyRWAWrapUnwrap };