@bgd-labs/toolbox 0.0.54 → 0.0.55

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/dist/node.mjs CHANGED
@@ -7,18 +7,27 @@ function bitmapToIndexes(bitmap) {
7
7
  }
8
8
  return indexes;
9
9
  }
10
- function getBits(uint256, startBit, _endBit) {
11
- let endBit = _endBit;
10
+ function getBits(uint256, startBit, endBit) {
11
+ if (uint256 < 0n) {
12
+ throw new Error("uint256 must be non-negative");
13
+ }
14
+ if (startBit < 0n || endBit < 0n) {
15
+ throw new Error("Bit positions must be non-negative");
16
+ }
12
17
  if (startBit > endBit) {
13
18
  throw new Error(
14
19
  "Invalid bit range: startBit must be less than or equal to endBit"
15
20
  );
16
21
  }
17
- const bitLength = BigInt(uint256.toString(2)).toString().length;
18
- if (endBit >= bitLength) {
19
- endBit = BigInt(bitLength - 1);
22
+ if (uint256 === 0n) {
23
+ return 0n;
24
+ }
25
+ const bitLength = uint256.toString(2).length;
26
+ if (startBit >= bitLength) {
27
+ return 0n;
20
28
  }
21
- const mask = (1n << endBit - startBit + 1n) - 1n;
29
+ const actualEndBit = endBit >= bitLength ? BigInt(bitLength - 1) : endBit;
30
+ const mask = (1n << actualEndBit - startBit + 1n) - 1n;
22
31
  return uint256 >> startBit & mask;
23
32
  }
24
33
  function setBits(input, startBit, endBit, replaceValue) {
@@ -46,10 +55,10 @@ function decodeUserConfiguration(userConfiguration) {
46
55
 
47
56
  // src/aave/reserve.ts
48
57
  function decodeReserveConfiguration(data) {
49
- const ltv = Number(getBits(data, 0n, 15n));
50
- const liquidationThreshold = Number(getBits(data, 16n, 31n));
51
- const liquidationBonus = Number(getBits(data, 32n, 47n));
52
- const decimals = Number(getBits(data, 48n, 55n));
58
+ const ltv = getBits(data, 0n, 15n);
59
+ const liquidationThreshold = getBits(data, 16n, 31n);
60
+ const liquidationBonus = getBits(data, 32n, 47n);
61
+ const decimals = getBits(data, 48n, 55n);
53
62
  const active = getBits(data, 56n, 56n);
54
63
  const frozen = getBits(data, 57n, 57n);
55
64
  const borrowingEnabled = getBits(data, 58n, 58n);
@@ -61,26 +70,25 @@ function decodeReserveConfiguration(data) {
61
70
  const borrowCap = getBits(data, 80n, 115n);
62
71
  const supplyCap = getBits(data, 116n, 151n);
63
72
  const liquidationProtocolFee = Number(getBits(data, 152n, 167n));
64
- const unbackedMintCap = getBits(data, 176n, 211n);
65
73
  const debtCeiling = getBits(data, 212n, 251n);
66
74
  const virtualAccountingEnabled = getBits(data, 252n, 252n);
67
75
  return {
68
- ltv,
69
- liquidationThreshold,
70
- liquidationBonus,
71
- decimals,
76
+ ltv: Number(ltv),
77
+ liquidationThreshold: Number(liquidationThreshold),
78
+ liquidationBonus: Number(liquidationBonus),
79
+ decimals: Number(decimals),
72
80
  active: !!active,
73
81
  frozen: !!frozen,
74
82
  borrowingEnabled: !!borrowingEnabled,
75
83
  // stableRateBorrowingEnabled: !!stableRateBorrowingEnabled,
76
84
  paused: !!paused,
77
85
  borrowingInIsolation: !!borrowingInIsolation,
78
- reserveFactor,
86
+ reserveFactor: Number(reserveFactor),
79
87
  borrowCap,
80
88
  supplyCap,
81
- liquidationProtocolFee,
89
+ liquidationProtocolFee: Number(liquidationProtocolFee),
82
90
  // eModeCategory,
83
- unbackedMintCap,
91
+ // unbackedMintCap,
84
92
  debtCeiling,
85
93
  siloedBorrowingEnabled: !!siloedBorrowingEnabled,
86
94
  flashloaningEnabled: !!flashloaningEnabled,
@@ -16214,7 +16222,84 @@ async function getReserveConfigurations(client, pool, reserves) {
16214
16222
  };
16215
16223
  }
16216
16224
 
16217
- // ../../node_modules/.pnpm/@bgd-labs+aave-address-book@4.31.0_viem@2.37.6_typescript@5.8.3_zod@3.24.2_/node_modules/@bgd-labs/aave-address-book/dist/abis/IPayloadsControllerCore.mjs
16225
+ // src/aave/pool/configurations.ts
16226
+ import { readContract as readContract2 } from "viem/actions";
16227
+ async function getCompleteReserveConfiguration(client, poolAddress, reserve) {
16228
+ const [
16229
+ reserveData,
16230
+ deficit,
16231
+ virtualUnderlyingBalance,
16232
+ liquidationGracePeriod
16233
+ ] = await Promise.all([
16234
+ readContract2(client, {
16235
+ address: poolAddress,
16236
+ abi: IPool_ABI,
16237
+ functionName: "getReserveData",
16238
+ args: [reserve]
16239
+ }),
16240
+ readContract2(client, {
16241
+ address: poolAddress,
16242
+ abi: IPool_ABI,
16243
+ functionName: "getReserveDeficit",
16244
+ args: [reserve]
16245
+ }),
16246
+ readContract2(client, {
16247
+ address: poolAddress,
16248
+ abi: IPool_ABI,
16249
+ functionName: "getVirtualUnderlyingBalance",
16250
+ args: [reserve]
16251
+ }),
16252
+ readContract2(client, {
16253
+ address: poolAddress,
16254
+ abi: IPool_ABI,
16255
+ functionName: "getLiquidationGracePeriod",
16256
+ args: [reserve]
16257
+ })
16258
+ ]);
16259
+ const [
16260
+ scaledATokenTotalSupply,
16261
+ scaledVTokenTotalSupply,
16262
+ availableLiquidity,
16263
+ irParams
16264
+ ] = await Promise.all([
16265
+ readContract2(client, {
16266
+ address: reserveData.aTokenAddress,
16267
+ abi: IAToken_ABI,
16268
+ functionName: "scaledTotalSupply"
16269
+ }),
16270
+ readContract2(client, {
16271
+ address: reserveData.variableDebtTokenAddress,
16272
+ abi: IAToken_ABI,
16273
+ functionName: "scaledTotalSupply"
16274
+ }),
16275
+ readContract2(client, {
16276
+ address: reserve,
16277
+ abi: IAToken_ABI,
16278
+ functionName: "balanceOf",
16279
+ args: [reserveData.aTokenAddress]
16280
+ }),
16281
+ readContract2(client, {
16282
+ address: reserveData.interestRateStrategyAddress,
16283
+ abi: IDefaultInterestRateStrategyV2_ABI,
16284
+ functionName: "getInterestRateDataBps",
16285
+ args: [reserve]
16286
+ })
16287
+ ]);
16288
+ const config = decodeReserveConfiguration(reserveData.configuration.data);
16289
+ return {
16290
+ ...reserveData,
16291
+ ...config,
16292
+ deficit,
16293
+ virtualUnderlyingBalance,
16294
+ liquidationGracePeriod,
16295
+ scaledATokenTotalSupply,
16296
+ scaledVTokenTotalSupply,
16297
+ availableLiquidity,
16298
+ ...irParams
16299
+ };
16300
+ }
16301
+
16302
+ // ../../node_modules/.pnpm/@bgd-labs+aave-address-book@4.31.0_viem@2.41.2_typescript@5.8.3_zod@3.24.2_/node_modules/@bgd-labs/aave-address-book/dist/abis/IPayloadsControllerCore.mjs
16218
16303
  var IPayloadsControllerCore_ABI = [
16219
16304
  {
16220
16305
  type: "function",
@@ -16719,7 +16804,7 @@ var IPayloadsControllerCore_ABI = [
16719
16804
  }
16720
16805
  ];
16721
16806
 
16722
- // ../../node_modules/.pnpm/@bgd-labs+aave-address-book@4.31.0_viem@2.37.6_typescript@5.8.3_zod@3.24.2_/node_modules/@bgd-labs/aave-address-book/dist/abis/IGovernanceCore.mjs
16807
+ // ../../node_modules/.pnpm/@bgd-labs+aave-address-book@4.31.0_viem@2.41.2_typescript@5.8.3_zod@3.24.2_/node_modules/@bgd-labs/aave-address-book/dist/abis/IGovernanceCore.mjs
16723
16808
  var IGovernanceCore_ABI = [
16724
16809
  {
16725
16810
  type: "function",
@@ -17752,7 +17837,7 @@ var IGovernanceCore_ABI = [
17752
17837
  }
17753
17838
  ];
17754
17839
 
17755
- // ../../node_modules/.pnpm/@bgd-labs+aave-address-book@4.31.0_viem@2.37.6_typescript@5.8.3_zod@3.24.2_/node_modules/@bgd-labs/aave-address-book/dist/abis/IPool.mjs
17840
+ // ../../node_modules/.pnpm/@bgd-labs+aave-address-book@4.31.0_viem@2.41.2_typescript@5.8.3_zod@3.24.2_/node_modules/@bgd-labs/aave-address-book/dist/abis/IPool.mjs
17756
17841
  var IPool_ABI2 = [
17757
17842
  {
17758
17843
  type: "function",
@@ -19795,6 +19880,17 @@ import {
19795
19880
  toHex,
19796
19881
  trim
19797
19882
  } from "viem";
19883
+ function getSolidityStorageSlotBytes(mappingSlot, key) {
19884
+ const slot = pad(mappingSlot, { size: 32 });
19885
+ return trim(
19886
+ keccak256(
19887
+ encodeAbiParameters(parseAbiParameters("bytes32, uint256"), [
19888
+ key,
19889
+ BigInt(slot)
19890
+ ])
19891
+ )
19892
+ );
19893
+ }
19798
19894
  function getSolidityStorageSlotUint(mappingSlot, key) {
19799
19895
  return keccak256(
19800
19896
  encodeAbiParameters(parseAbiParameters("uint256, uint256"), [
@@ -19803,6 +19899,39 @@ function getSolidityStorageSlotUint(mappingSlot, key) {
19803
19899
  ])
19804
19900
  );
19805
19901
  }
19902
+ function getSolidityStorageSlotAddress(mappingSlot, key) {
19903
+ return keccak256(
19904
+ encodeAbiParameters(parseAbiParameters("address, uint256"), [
19905
+ key,
19906
+ BigInt(mappingSlot)
19907
+ ])
19908
+ );
19909
+ }
19910
+ function getDynamicArraySlot(baseSlot, arrayIndex, itemSize) {
19911
+ return pad(
19912
+ toHex(
19913
+ fromHex(
19914
+ keccak256(
19915
+ encodeAbiParameters(parseAbiParameters("uint256"), [baseSlot])
19916
+ ),
19917
+ "bigint"
19918
+ ) + BigInt(arrayIndex * itemSize)
19919
+ ),
19920
+ { size: 32 }
19921
+ );
19922
+ }
19923
+ function getBytesValue(value) {
19924
+ const bytesString = toBytes(value);
19925
+ if (bytesString.length > 31)
19926
+ throw new Error("Error: strings > 31 bytes are not implemented");
19927
+ return concat([
19928
+ toHex(pad(bytesString, { size: 31, dir: "right" })),
19929
+ toHex(bytesString.length * 2, { size: 1 })
19930
+ ]);
19931
+ }
19932
+ function bytes32ToAddress(bytes32) {
19933
+ return getAddress(slice(bytes32, 12, 32));
19934
+ }
19806
19935
 
19807
19936
  // src/aave/governance/payloads-controller.ts
19808
19937
  import { getBlock } from "viem/actions";
@@ -20996,7 +21125,8 @@ async function getXLayerSourceCode(params) {
20996
21125
  import {
20997
21126
  createTestClient,
20998
21127
  createWalletClient,
20999
- http
21128
+ http,
21129
+ publicActions
21000
21130
  } from "viem";
21001
21131
 
21002
21132
  // src/ecosystem/chainIds.ts
@@ -21225,7 +21355,7 @@ async function tenderly_createVnet({
21225
21355
  },
21226
21356
  mode: "tenderly",
21227
21357
  transport: http(rpc.url, { timeout: 2e5 })
21228
- }),
21358
+ }).extend(publicActions),
21229
21359
  walletClient: createWalletClient({
21230
21360
  chain: {
21231
21361
  ...ChainList[baseChainId],
@@ -21361,7 +21491,7 @@ var EVENT_DB = [];
21361
21491
  // src/ecosystem/rpcs.ts
21362
21492
  import {
21363
21493
  http as http2,
21364
- createClient
21494
+ createPublicClient
21365
21495
  } from "viem";
21366
21496
 
21367
21497
  // src/ecosystem/generated/alchemyNetworkMap.ts
@@ -21902,7 +22032,7 @@ function getClient(chainId, {
21902
22032
  } = {}) {
21903
22033
  if (!clientCache[chainId] || forceRebuildClient) {
21904
22034
  const rpcURL = getRPCUrl(chainId, providerConfig);
21905
- clientCache[chainId] = createClient({
22035
+ clientCache[chainId] = createPublicClient({
21906
22036
  chain: ChainList[chainId],
21907
22037
  transport: http2(rpcURL, httpConfig),
21908
22038
  ...clientConfig
@@ -38842,7 +38972,7 @@ async function getVerificationStatus({
38842
38972
 
38843
38973
  // src/seatbelt/state.ts
38844
38974
  import { getAddress as getAddress3, zeroAddress as zeroAddress2 } from "viem";
38845
- import { readContract as readContract2 } from "viem/actions";
38975
+ import { readContract as readContract3 } from "viem/actions";
38846
38976
  function isChangeOfType(change, name) {
38847
38977
  return change.name === name;
38848
38978
  }
@@ -39051,7 +39181,7 @@ async function enhanceStateDiff(client, diff) {
39051
39181
  if (isChangeOfType(change, "_reserves")) {
39052
39182
  let method = decodeReserveConfigurationV2;
39053
39183
  try {
39054
- await readContract2(client, {
39184
+ await readContract3(client, {
39055
39185
  abi: IPool_ABI,
39056
39186
  functionName: "getUserEMode",
39057
39187
  args: [zeroAddress2],
@@ -39452,6 +39582,7 @@ export {
39452
39582
  assetToBase,
39453
39583
  bitmapToIndexes,
39454
39584
  blockscoutExplorers,
39585
+ bytes32ToAddress,
39455
39586
  calculateAvailableBorrowsMarketReferenceCurrency,
39456
39587
  calculateCompoundedInterest,
39457
39588
  calculateHealthFactor,
@@ -39482,10 +39613,13 @@ export {
39482
39613
  genericIndexer,
39483
39614
  getAlchemyRPC,
39484
39615
  getBits,
39616
+ getBytesValue,
39485
39617
  getClient,
39618
+ getCompleteReserveConfiguration,
39486
39619
  getContractDeploymentBlock,
39487
39620
  getCurrentDebtBalance,
39488
39621
  getCurrentLiquidityBalance,
39622
+ getDynamicArraySlot,
39489
39623
  getExplicitRPC,
39490
39624
  getExplorer,
39491
39625
  getGovernance,
@@ -39507,6 +39641,9 @@ export {
39507
39641
  getRPCUrl,
39508
39642
  getReserveConfigurations,
39509
39643
  getReserveTokens,
39644
+ getSolidityStorageSlotAddress,
39645
+ getSolidityStorageSlotBytes,
39646
+ getSolidityStorageSlotUint,
39510
39647
  getSourceCode,
39511
39648
  getTenderlyRpc,
39512
39649
  getVerificationStatus,