@moonwell-fi/moonwell-sdk 0.20.0 → 0.20.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/actions/morpho/markets/common.js +25 -16
  3. package/_cjs/actions/morpho/markets/common.js.map +1 -1
  4. package/_cjs/actions/morpho/utils/graphql.js +4 -12
  5. package/_cjs/actions/morpho/utils/graphql.js.map +1 -1
  6. package/_cjs/actions/morpho/vaults/common.js +6 -24
  7. package/_cjs/actions/morpho/vaults/common.js.map +1 -1
  8. package/_cjs/environments/definitions/ethereum/contracts.js +1 -0
  9. package/_cjs/environments/definitions/ethereum/contracts.js.map +1 -1
  10. package/_cjs/errors/version.js +1 -1
  11. package/_esm/actions/morpho/markets/common.js +31 -19
  12. package/_esm/actions/morpho/markets/common.js.map +1 -1
  13. package/_esm/actions/morpho/utils/graphql.js +4 -12
  14. package/_esm/actions/morpho/utils/graphql.js.map +1 -1
  15. package/_esm/actions/morpho/vaults/common.js +9 -24
  16. package/_esm/actions/morpho/vaults/common.js.map +1 -1
  17. package/_esm/environments/definitions/ethereum/contracts.js +9 -0
  18. package/_esm/environments/definitions/ethereum/contracts.js.map +1 -1
  19. package/_esm/errors/version.js +1 -1
  20. package/_types/actions/morpho/utils/graphql.d.ts.map +1 -1
  21. package/_types/actions/morpho/vaults/common.d.ts.map +1 -1
  22. package/_types/client/createMoonwellClient.d.ts +2 -0
  23. package/_types/client/createMoonwellClient.d.ts.map +1 -1
  24. package/_types/environments/definitions/ethereum/contracts.d.ts +1 -0
  25. package/_types/environments/definitions/ethereum/contracts.d.ts.map +1 -1
  26. package/_types/environments/index.d.ts +1 -0
  27. package/_types/environments/index.d.ts.map +1 -1
  28. package/_types/errors/version.d.ts +1 -1
  29. package/actions/morpho/markets/common.ts +36 -28
  30. package/actions/morpho/utils/graphql.ts +10 -18
  31. package/actions/morpho/vaults/common.ts +11 -38
  32. package/environments/definitions/ethereum/contracts.ts +9 -0
  33. package/errors/version.ts +1 -1
  34. package/package.json +1 -1
@@ -603,13 +603,13 @@ async function getMorphoMarketRewards(
603
603
  maxIn
604
604
  maxOut
605
605
  market {
606
- uniqueKey
606
+ marketId
607
607
  }
608
608
  }
609
609
  }
610
610
  }
611
- allocationMarket {
612
- uniqueKey
611
+ allocationMarket: withdrawMarket {
612
+ marketId
613
613
  loanAsset {
614
614
  address
615
615
  }
@@ -640,11 +640,9 @@ async function getMorphoMarketRewards(
640
640
  }
641
641
  supplyApr
642
642
  borrowApr
643
- amountPerBorrowedToken
644
- amountPerSuppliedToken
645
643
  }
646
644
  }
647
- uniqueKey
645
+ marketId
648
646
  }
649
647
  }
650
648
  } `;
@@ -657,7 +655,7 @@ async function getMorphoMarketRewards(
657
655
  id: number;
658
656
  };
659
657
  };
660
- uniqueKey: string;
658
+ marketId: string;
661
659
  reallocatableLiquidityAssets: string;
662
660
  publicAllocatorSharedLiquidity: {
663
661
  assets: string;
@@ -668,7 +666,7 @@ async function getMorphoMarketRewards(
668
666
  fee: number;
669
667
  flowCaps: {
670
668
  market: {
671
- uniqueKey: string;
669
+ marketId: string;
672
670
  };
673
671
  maxIn: number;
674
672
  maxOut: number;
@@ -676,7 +674,7 @@ async function getMorphoMarketRewards(
676
674
  };
677
675
  };
678
676
  allocationMarket: {
679
- uniqueKey: string;
677
+ marketId: string;
680
678
  loanAsset: {
681
679
  address: string;
682
680
  };
@@ -706,9 +704,7 @@ async function getMorphoMarketRewards(
706
704
  name: string;
707
705
  };
708
706
  supplyApr: number;
709
- amountPerSuppliedToken: string;
710
707
  borrowApr: number;
711
- amountPerBorrowedToken: string;
712
708
  }[];
713
709
  };
714
710
  }[];
@@ -720,7 +716,7 @@ async function getMorphoMarketRewards(
720
716
  const loanAssetDecimals = item.loanAsset.decimals;
721
717
  const mapping: GetMorphoMarketsRewardsReturnType = {
722
718
  chainId: item.morphoBlue.chain.id,
723
- marketId: item.uniqueKey,
719
+ marketId: item.marketId,
724
720
  reallocatableLiquidityAssets: new Amount(
725
721
  BigInt(item.reallocatableLiquidityAssets),
726
722
  loanAssetDecimals,
@@ -742,31 +738,43 @@ async function getMorphoMarketRewards(
742
738
  vault: {
743
739
  address: item.vault.address,
744
740
  name: item.vault.name,
745
- publicAllocatorConfig: item.vault.publicAllocatorConfig,
741
+ // The Morpho API renamed Market.uniqueKey to marketId; map it
742
+ // back to keep the SDK's public types unchanged.
743
+ publicAllocatorConfig: {
744
+ fee: item.vault.publicAllocatorConfig.fee,
745
+ flowCaps: item.vault.publicAllocatorConfig.flowCaps.map(
746
+ (flowCap) => ({
747
+ market: { uniqueKey: flowCap.market.marketId },
748
+ maxIn: flowCap.maxIn,
749
+ maxOut: flowCap.maxOut,
750
+ }),
751
+ ),
752
+ },
753
+ },
754
+ allocationMarket: {
755
+ uniqueKey: item.allocationMarket.marketId,
756
+ loanAsset: item.allocationMarket.loanAsset,
757
+ ...(item.allocationMarket.collateralAsset
758
+ ? { collateralAsset: item.allocationMarket.collateralAsset }
759
+ : {}),
760
+ oracleAddress: item.allocationMarket.oracleAddress,
761
+ irmAddress: item.allocationMarket.irmAddress,
762
+ lltv: item.allocationMarket.lltv,
746
763
  },
747
- allocationMarket: item.allocationMarket,
748
764
  }),
749
765
  ),
750
766
  rewards: item.state?.rewards.map((reward) => {
751
- const tokenDecimals = 10 ** reward.asset.decimals;
752
-
753
767
  //Supply APR is used only for vaults, zeroing it for now to avoid confusion
754
- //const tokenAmountPer1000 = ((parseFloat(reward.amountPerSuppliedToken) / item.loanAsset.priceUsd) * 1000) || "0"
755
- //const amount = (Number(tokenAmountPer1000) / tokenDecimals)
756
-
757
- const borrowTokenAmountPer1000 =
758
- (Number.parseFloat(reward.amountPerBorrowedToken) /
759
- item.loanAsset.priceUsd) *
760
- 1000;
761
-
762
- const borrowAmount = borrowTokenAmountPer1000 / tokenDecimals;
768
+ // Morpho removed the per-token amount fields from the API
769
+ // (MarketStateReward.amountPerBorrowedToken et al.), so reward
770
+ // amounts can no longer be computed and are reported as 0.
763
771
  return {
764
- marketId: item.uniqueKey,
772
+ marketId: item.marketId,
765
773
  asset: reward.asset,
766
774
  supplyApr: 0, //(reward.supplyApr || 0) * 100,
767
- supplyAmount: 0, //amount,
775
+ supplyAmount: 0,
768
776
  borrowApr: (reward.borrowApr || 0) * 100 * -1,
769
- borrowAmount: borrowAmount,
777
+ borrowAmount: 0,
770
778
  };
771
779
  }),
772
780
  };
@@ -20,20 +20,16 @@ export async function getGraphQL<T>(
20
20
 
21
21
  const json = await response.json();
22
22
  if (response.status !== 200 || json.errors) {
23
- if (typeof window !== "undefined") {
24
- console.debug(
25
- `[Morpho GraphQL] Non-200 (${response.statusText}) or errors:`,
26
- json.errors,
27
- );
28
- }
23
+ console.error(
24
+ `[Morpho GraphQL] Non-200 (${response.statusText}) or errors:`,
25
+ JSON.stringify(json.errors),
26
+ );
29
27
  return undefined;
30
28
  }
31
29
 
32
30
  return json.data as T;
33
31
  } catch (error) {
34
- if (typeof window !== "undefined") {
35
- console.debug("[Morpho GraphQL] Error fetching data:", error);
36
- }
32
+ console.error("[Morpho GraphQL] Error fetching data:", error);
37
33
  return undefined;
38
34
  }
39
35
  }
@@ -94,20 +90,16 @@ export async function getVaultV2Apy(
94
90
 
95
91
  const json = await response.json();
96
92
  if (response.status !== 200 || json.errors) {
97
- if (typeof window !== "undefined") {
98
- console.debug(
99
- `[Morpho V2 APY] Non-200 (${response.statusText}) or errors:`,
100
- json.errors,
101
- );
102
- }
93
+ console.error(
94
+ `[Morpho V2 APY] Non-200 (${response.statusText}) or errors:`,
95
+ JSON.stringify(json.errors),
96
+ );
103
97
  return undefined;
104
98
  }
105
99
 
106
100
  return json.data?.vaultV2ByAddress as MorphoVaultV2ApyResponse | undefined;
107
101
  } catch (error) {
108
- if (typeof window !== "undefined") {
109
- console.debug("[Morpho V2 APY] Error fetching data:", error);
110
- }
102
+ console.error("[Morpho V2 APY] Error fetching data:", error);
111
103
  return undefined;
112
104
  }
113
105
  }
@@ -1372,11 +1372,8 @@ export async function getMorphoVaultsRewards(
1372
1372
  }
1373
1373
  id
1374
1374
  address
1375
- asset {
1376
- priceUsd
1377
- }
1378
1375
  state {
1379
- rewards {
1376
+ allRewards {
1380
1377
  asset {
1381
1378
  address
1382
1379
  symbol
@@ -1387,7 +1384,6 @@ export async function getMorphoVaultsRewards(
1387
1384
  }
1388
1385
  }
1389
1386
  supplyApr
1390
- amountPerSuppliedToken
1391
1387
  }
1392
1388
  }
1393
1389
  }
@@ -1405,10 +1401,7 @@ export async function getMorphoVaultsRewards(
1405
1401
  id
1406
1402
  }
1407
1403
  }
1408
- uniqueKey
1409
- loanAsset {
1410
- priceUsd
1411
- }
1404
+ marketId
1412
1405
  state {
1413
1406
  rewards {
1414
1407
  asset {
@@ -1421,7 +1414,6 @@ export async function getMorphoVaultsRewards(
1421
1414
  }
1422
1415
  }
1423
1416
  supplyApr
1424
- amountPerSuppliedToken
1425
1417
  }
1426
1418
  }
1427
1419
  }
@@ -1437,11 +1429,8 @@ export async function getMorphoVaultsRewards(
1437
1429
  };
1438
1430
  id: string;
1439
1431
  address: Address;
1440
- asset: {
1441
- priceUsd: number;
1442
- };
1443
1432
  state: {
1444
- rewards: {
1433
+ allRewards: {
1445
1434
  asset: {
1446
1435
  address: Address;
1447
1436
  symbol: string;
@@ -1452,7 +1441,6 @@ export async function getMorphoVaultsRewards(
1452
1441
  };
1453
1442
  };
1454
1443
  supplyApr: number;
1455
- amountPerSuppliedToken: string;
1456
1444
  }[];
1457
1445
  };
1458
1446
  }[];
@@ -1468,10 +1456,7 @@ export async function getMorphoVaultsRewards(
1468
1456
  id: number;
1469
1457
  };
1470
1458
  };
1471
- uniqueKey: string;
1472
- loanAsset: {
1473
- priceUsd: number;
1474
- };
1459
+ marketId: string;
1475
1460
  state: {
1476
1461
  rewards: {
1477
1462
  asset: {
@@ -1484,7 +1469,6 @@ export async function getMorphoVaultsRewards(
1484
1469
  };
1485
1470
  };
1486
1471
  supplyApr: number;
1487
- amountPerSuppliedToken: string;
1488
1472
  }[];
1489
1473
  };
1490
1474
  };
@@ -1494,22 +1478,18 @@ export async function getMorphoVaultsRewards(
1494
1478
 
1495
1479
  if (result) {
1496
1480
  try {
1481
+ // Morpho removed the per-supplied-token amount fields from the API
1482
+ // (VaultStateReward.amountPerSuppliedToken et al.), so reward amounts
1483
+ // can no longer be computed and are reported as 0.
1497
1484
  const marketsRewards = result.marketPositions.items.flatMap((item) => {
1498
1485
  const rewards = (item.market.state?.rewards || []).map((reward) => {
1499
- const tokenAmountPer1000 =
1500
- (Number.parseFloat(reward.amountPerSuppliedToken) /
1501
- item.market.loanAsset.priceUsd) *
1502
- 1000;
1503
- const tokenDecimals = 10 ** reward.asset.decimals;
1504
- const amount = Number(tokenAmountPer1000) / tokenDecimals;
1505
-
1506
1486
  return {
1507
1487
  chainId: reward.asset.chain.id,
1508
1488
  vaultId: item.user.address,
1509
- marketId: item.market.uniqueKey,
1489
+ marketId: item.market.marketId,
1510
1490
  asset: reward.asset,
1511
1491
  supplyApr: (reward.supplyApr || 0) * 100,
1512
- supplyAmount: amount,
1492
+ supplyAmount: 0,
1513
1493
  borrowApr: 0,
1514
1494
  borrowAmount: 0,
1515
1495
  };
@@ -1518,21 +1498,14 @@ export async function getMorphoVaultsRewards(
1518
1498
  });
1519
1499
 
1520
1500
  const vaultsRewards = result.vaults.items.flatMap((item) => {
1521
- return (item.state?.rewards || []).map((reward) => {
1522
- const tokenAmountPer1000 =
1523
- (Number.parseFloat(reward.amountPerSuppliedToken) /
1524
- item.asset.priceUsd) *
1525
- 1000;
1526
- const tokenDecimals = 10 ** reward.asset.decimals;
1527
- const amount = Number(tokenAmountPer1000) / tokenDecimals;
1528
-
1501
+ return (item.state?.allRewards || []).map((reward) => {
1529
1502
  return {
1530
1503
  chainId: reward.asset.chain.id,
1531
1504
  vaultId: item.address,
1532
1505
  marketId: undefined,
1533
1506
  asset: reward.asset,
1534
1507
  supplyApr: (reward.supplyApr || 0) * 100,
1535
- supplyAmount: amount,
1508
+ supplyAmount: 0,
1536
1509
  borrowApr: 0,
1537
1510
  borrowAmount: 0,
1538
1511
  };
@@ -14,6 +14,15 @@ export const contracts = createContractsConfig({
14
14
  // no-ops on confirm.
15
15
  comptroller: "0xdec80bb934397575594e91970b37baf65f5b21be",
16
16
  views: "0x2d85b9c48a8c582f0AA244e134e9C6f30Cf7786e",
17
+ // MultiRewardDistributor (MRD_PROXY, deployed with MIP-E00) — the
18
+ // comptroller's `rewardDistributor()`. Reward *APRs* come from the `views`
19
+ // contract / indexer, not this address; what needs it is the app's
20
+ // reward-claim flow (useUserRewardsData), which keys off its presence:
21
+ // defined ⇒ claim via the comptroller's `claimReward(holders, mTokens, …)`
22
+ // (the EVM path Base/Optimism use), absent ⇒ fall back to the Moonbeam
23
+ // `0x…0808` precompile `batchAll`, which reverts on Ethereum. Required so
24
+ // users can claim the WELL rewards MIP-X59 starts accruing on Core markets.
25
+ multiRewardDistributor: "0x60142B8d76FaC5b88cfB422Ba1aA905d2171851c",
17
26
  multichainGovernor: "0x8769B70ac7c93AF0e75de0D69877709B66d75838",
18
27
  // mWETHRouter — wraps native ETH to WETH on supply and unwraps WETH to
19
28
  // native ETH on withdraw, matching the mWETHRouter pattern used on Base
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '0.20.0'
1
+ export const version = '0.20.2'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonwell-fi/moonwell-sdk",
3
3
  "description": "TypeScript Interface for Moonwell",
4
- "version": "0.20.0",
4
+ "version": "0.20.2",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",