@gainsnetwork/sdk 1.4.5 → 1.5.0-rc2

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.
@@ -3715,6 +3715,21 @@ const _abi = [
3715
3715
  type: "function",
3716
3716
  signature: "0xfed8a190",
3717
3717
  },
3718
+ {
3719
+ inputs: [],
3720
+ name: "DepthBandsAboveMax",
3721
+ type: "error",
3722
+ },
3723
+ {
3724
+ inputs: [],
3725
+ name: "DepthBandsIncomplete",
3726
+ type: "error",
3727
+ },
3728
+ {
3729
+ inputs: [],
3730
+ name: "WrongDepthBandsOrder",
3731
+ type: "error",
3732
+ },
3718
3733
  {
3719
3734
  inputs: [],
3720
3735
  name: "WrongWindowsCount",
@@ -3745,6 +3760,26 @@ const _abi = [
3745
3760
  type: "event",
3746
3761
  signature: "0x2742ec28d0252b4477106a77a10b04e1c1ecd2b568c7168d56c3a3154d3a3122",
3747
3762
  },
3763
+ {
3764
+ anonymous: false,
3765
+ inputs: [
3766
+ {
3767
+ indexed: false,
3768
+ internalType: "uint256",
3769
+ name: "slot1",
3770
+ type: "uint256",
3771
+ },
3772
+ {
3773
+ indexed: false,
3774
+ internalType: "uint256",
3775
+ name: "slot2",
3776
+ type: "uint256",
3777
+ },
3778
+ ],
3779
+ name: "DepthBandsMappingUpdated",
3780
+ type: "event",
3781
+ signature: "0x22391293f5705268ac47df15d88a7704e1267eff228801ac480dbe5ecf5ea3ef",
3782
+ },
3748
3783
  {
3749
3784
  anonymous: false,
3750
3785
  inputs: [
@@ -3871,6 +3906,44 @@ const _abi = [
3871
3906
  type: "event",
3872
3907
  signature: "0xbe433d32d9112c2fcf91407f28314200753b05ef3e9c85b8a0e9d135e77a6c29",
3873
3908
  },
3909
+ {
3910
+ anonymous: false,
3911
+ inputs: [
3912
+ {
3913
+ indexed: true,
3914
+ internalType: "uint256",
3915
+ name: "pairIndex",
3916
+ type: "uint256",
3917
+ },
3918
+ {
3919
+ indexed: false,
3920
+ internalType: "uint256",
3921
+ name: "aboveSlot1",
3922
+ type: "uint256",
3923
+ },
3924
+ {
3925
+ indexed: false,
3926
+ internalType: "uint256",
3927
+ name: "aboveSlot2",
3928
+ type: "uint256",
3929
+ },
3930
+ {
3931
+ indexed: false,
3932
+ internalType: "uint256",
3933
+ name: "belowSlot1",
3934
+ type: "uint256",
3935
+ },
3936
+ {
3937
+ indexed: false,
3938
+ internalType: "uint256",
3939
+ name: "belowSlot2",
3940
+ type: "uint256",
3941
+ },
3942
+ ],
3943
+ name: "PairDepthBandsUpdated",
3944
+ type: "event",
3945
+ signature: "0x7a9ee81b0015d0b7824d14757416905ea9ace5b9ad54dc08cb426cd0ae3dff9f",
3946
+ },
3874
3947
  {
3875
3948
  anonymous: false,
3876
3949
  inputs: [
@@ -4230,6 +4303,39 @@ const _abi = [
4230
4303
  type: "function",
4231
4304
  signature: "0x81688f7b",
4232
4305
  },
4306
+ {
4307
+ inputs: [],
4308
+ name: "getDepthBandsMapping",
4309
+ outputs: [
4310
+ {
4311
+ internalType: "uint256",
4312
+ name: "slot1",
4313
+ type: "uint256",
4314
+ },
4315
+ {
4316
+ internalType: "uint256",
4317
+ name: "slot2",
4318
+ type: "uint256",
4319
+ },
4320
+ ],
4321
+ stateMutability: "view",
4322
+ type: "function",
4323
+ signature: "0xd40e0d20",
4324
+ },
4325
+ {
4326
+ inputs: [],
4327
+ name: "getDepthBandsMappingDecoded",
4328
+ outputs: [
4329
+ {
4330
+ internalType: "uint16[]",
4331
+ name: "bands",
4332
+ type: "uint16[]",
4333
+ },
4334
+ ],
4335
+ stateMutability: "view",
4336
+ type: "function",
4337
+ signature: "0x9615d82a",
4338
+ },
4233
4339
  {
4234
4340
  inputs: [],
4235
4341
  name: "getNegPnlCumulVolMultiplier",
@@ -4367,29 +4473,39 @@ const _abi = [
4367
4473
  type: "uint256",
4368
4474
  },
4369
4475
  ],
4370
- name: "getPairDepth",
4476
+ name: "getPairDepthBands",
4371
4477
  outputs: [
4372
4478
  {
4373
4479
  components: [
4374
4480
  {
4375
- internalType: "uint128",
4376
- name: "onePercentDepthAboveUsd",
4377
- type: "uint128",
4481
+ internalType: "uint256",
4482
+ name: "aboveSlot1",
4483
+ type: "uint256",
4378
4484
  },
4379
4485
  {
4380
- internalType: "uint128",
4381
- name: "onePercentDepthBelowUsd",
4382
- type: "uint128",
4486
+ internalType: "uint256",
4487
+ name: "aboveSlot2",
4488
+ type: "uint256",
4489
+ },
4490
+ {
4491
+ internalType: "uint256",
4492
+ name: "belowSlot1",
4493
+ type: "uint256",
4494
+ },
4495
+ {
4496
+ internalType: "uint256",
4497
+ name: "belowSlot2",
4498
+ type: "uint256",
4383
4499
  },
4384
4500
  ],
4385
- internalType: "struct IPriceImpact.PairDepth",
4501
+ internalType: "struct IPriceImpact.PairDepthBands",
4386
4502
  name: "",
4387
4503
  type: "tuple",
4388
4504
  },
4389
4505
  ],
4390
4506
  stateMutability: "view",
4391
4507
  type: "function",
4392
- signature: "0x375bb2bb",
4508
+ signature: "0xc693e1be",
4393
4509
  },
4394
4510
  {
4395
4511
  inputs: [
@@ -4399,29 +4515,109 @@ const _abi = [
4399
4515
  type: "uint256[]",
4400
4516
  },
4401
4517
  ],
4402
- name: "getPairDepths",
4518
+ name: "getPairDepthBandsArray",
4403
4519
  outputs: [
4404
4520
  {
4405
4521
  components: [
4406
4522
  {
4407
- internalType: "uint128",
4408
- name: "onePercentDepthAboveUsd",
4409
- type: "uint128",
4523
+ internalType: "uint256",
4524
+ name: "aboveSlot1",
4525
+ type: "uint256",
4410
4526
  },
4411
4527
  {
4412
- internalType: "uint128",
4413
- name: "onePercentDepthBelowUsd",
4414
- type: "uint128",
4528
+ internalType: "uint256",
4529
+ name: "aboveSlot2",
4530
+ type: "uint256",
4531
+ },
4532
+ {
4533
+ internalType: "uint256",
4534
+ name: "belowSlot1",
4535
+ type: "uint256",
4536
+ },
4537
+ {
4538
+ internalType: "uint256",
4539
+ name: "belowSlot2",
4540
+ type: "uint256",
4415
4541
  },
4416
4542
  ],
4417
- internalType: "struct IPriceImpact.PairDepth[]",
4543
+ internalType: "struct IPriceImpact.PairDepthBands[]",
4418
4544
  name: "",
4419
4545
  type: "tuple[]",
4420
4546
  },
4421
4547
  ],
4422
4548
  stateMutability: "view",
4423
4549
  type: "function",
4424
- signature: "0x0d569f27",
4550
+ signature: "0x35bf34e8",
4551
+ },
4552
+ {
4553
+ inputs: [
4554
+ {
4555
+ internalType: "uint256",
4556
+ name: "_pairIndex",
4557
+ type: "uint256",
4558
+ },
4559
+ ],
4560
+ name: "getPairDepthBandsDecoded",
4561
+ outputs: [
4562
+ {
4563
+ internalType: "uint256",
4564
+ name: "totalDepthAboveUsd",
4565
+ type: "uint256",
4566
+ },
4567
+ {
4568
+ internalType: "uint256",
4569
+ name: "totalDepthBelowUsd",
4570
+ type: "uint256",
4571
+ },
4572
+ {
4573
+ internalType: "uint16[]",
4574
+ name: "bandsAbove",
4575
+ type: "uint16[]",
4576
+ },
4577
+ {
4578
+ internalType: "uint16[]",
4579
+ name: "bandsBelow",
4580
+ type: "uint16[]",
4581
+ },
4582
+ ],
4583
+ stateMutability: "view",
4584
+ type: "function",
4585
+ signature: "0x2b363e71",
4586
+ },
4587
+ {
4588
+ inputs: [
4589
+ {
4590
+ internalType: "uint256[]",
4591
+ name: "_indices",
4592
+ type: "uint256[]",
4593
+ },
4594
+ ],
4595
+ name: "getPairDepthBandsDecodedArray",
4596
+ outputs: [
4597
+ {
4598
+ internalType: "uint256[]",
4599
+ name: "totalDepthAboveUsd",
4600
+ type: "uint256[]",
4601
+ },
4602
+ {
4603
+ internalType: "uint256[]",
4604
+ name: "totalDepthBelowUsd",
4605
+ type: "uint256[]",
4606
+ },
4607
+ {
4608
+ internalType: "uint16[][]",
4609
+ name: "bandsAbove",
4610
+ type: "uint16[][]",
4611
+ },
4612
+ {
4613
+ internalType: "uint16[][]",
4614
+ name: "bandsBelow",
4615
+ type: "uint16[][]",
4616
+ },
4617
+ ],
4618
+ stateMutability: "view",
4619
+ type: "function",
4620
+ signature: "0x299f621d",
4425
4621
  },
4426
4622
  {
4427
4623
  inputs: [
@@ -4850,6 +5046,25 @@ const _abi = [
4850
5046
  type: "function",
4851
5047
  signature: "0x5a1449ab",
4852
5048
  },
5049
+ {
5050
+ inputs: [
5051
+ {
5052
+ internalType: "uint256",
5053
+ name: "_slot1",
5054
+ type: "uint256",
5055
+ },
5056
+ {
5057
+ internalType: "uint256",
5058
+ name: "_slot2",
5059
+ type: "uint256",
5060
+ },
5061
+ ],
5062
+ name: "initializeDepthBandsMapping",
5063
+ outputs: [],
5064
+ stateMutability: "nonpayable",
5065
+ type: "function",
5066
+ signature: "0xbb8f07af",
5067
+ },
4853
5068
  {
4854
5069
  inputs: [
4855
5070
  {
@@ -4931,6 +5146,25 @@ const _abi = [
4931
5146
  type: "function",
4932
5147
  signature: "0xa7d518fc",
4933
5148
  },
5149
+ {
5150
+ inputs: [
5151
+ {
5152
+ internalType: "uint256",
5153
+ name: "_slot1",
5154
+ type: "uint256",
5155
+ },
5156
+ {
5157
+ internalType: "uint256",
5158
+ name: "_slot2",
5159
+ type: "uint256",
5160
+ },
5161
+ ],
5162
+ name: "setDepthBandsMapping",
5163
+ outputs: [],
5164
+ stateMutability: "nonpayable",
5165
+ type: "function",
5166
+ signature: "0x7e8462f7",
5167
+ },
4934
5168
  {
4935
5169
  inputs: [
4936
5170
  {
@@ -4991,21 +5225,38 @@ const _abi = [
4991
5225
  type: "uint256[]",
4992
5226
  },
4993
5227
  {
4994
- internalType: "uint128[]",
4995
- name: "_depthsAboveUsd",
4996
- type: "uint128[]",
4997
- },
4998
- {
4999
- internalType: "uint128[]",
5000
- name: "_depthsBelowUsd",
5001
- type: "uint128[]",
5228
+ components: [
5229
+ {
5230
+ internalType: "uint256",
5231
+ name: "aboveSlot1",
5232
+ type: "uint256",
5233
+ },
5234
+ {
5235
+ internalType: "uint256",
5236
+ name: "aboveSlot2",
5237
+ type: "uint256",
5238
+ },
5239
+ {
5240
+ internalType: "uint256",
5241
+ name: "belowSlot1",
5242
+ type: "uint256",
5243
+ },
5244
+ {
5245
+ internalType: "uint256",
5246
+ name: "belowSlot2",
5247
+ type: "uint256",
5248
+ },
5249
+ ],
5250
+ internalType: "struct IPriceImpact.PairDepthBands[]",
5251
+ name: "_depthBands",
5252
+ type: "tuple[]",
5002
5253
  },
5003
5254
  ],
5004
- name: "setPairDepths",
5255
+ name: "setPairDepthBands",
5005
5256
  outputs: [],
5006
5257
  stateMutability: "nonpayable",
5007
5258
  type: "function",
5008
- signature: "0x6474b399",
5259
+ signature: "0x88be5e4f",
5009
5260
  },
5010
5261
  {
5011
5262
  inputs: [
@@ -1,7 +1,18 @@
1
- import { Pair, Fee, OpenInterest, PairDepth, PairIndex } from "../../trade/types";
1
+ import { Fee, OpenInterest, Pair, PairIndex } from "../../trade/types";
2
2
  import { Contracts } from "../../contracts/types";
3
3
  export declare const fetchPairs: (contracts: Contracts, pairIxs: PairIndex[]) => Promise<Pair[]>;
4
- export declare const fetchPairDepths: (contracts: Contracts, pairIxs: number[]) => Promise<PairDepth[]>;
4
+ export declare const fetchPairDepthBands: (contracts: Contracts, pairIxs: number[]) => Promise<any[]>;
5
+ export declare const fetchPairDepthBandsDecoded: (contracts: Contracts, pairIxs: number[]) => Promise<{
6
+ totalDepthAboveUsd: number[];
7
+ totalDepthBelowUsd: number[];
8
+ bandsAbove: number[][];
9
+ bandsBelow: number[][];
10
+ }>;
11
+ export declare const fetchDepthBandsMapping: (contracts: Contracts) => Promise<{
12
+ slot1: string;
13
+ slot2: string;
14
+ }>;
15
+ export declare const fetchDepthBandsMappingDecoded: (contracts: Contracts) => Promise<number[]>;
5
16
  export declare const fetchFees: (contracts: Contracts, feeIxs: PairIndex[]) => Promise<Fee[]>;
6
17
  export declare const fetchOpenInterest: (contracts: Contracts, collateralIndex: number, pairIxs: number[]) => Promise<OpenInterest[]>;
7
18
  export declare const getPairDescription: (pairIndex: PairIndex) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.fetchPairDepths = exports.fetchPairs = void 0;
3
+ exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.fetchDepthBandsMappingDecoded = exports.fetchDepthBandsMapping = exports.fetchPairDepthBandsDecoded = exports.fetchPairDepthBands = exports.fetchPairs = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-unsafe-call */
5
5
  /* eslint-disable @typescript-eslint/no-unsafe-return */
6
6
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
@@ -31,26 +31,83 @@ const fetchPairs = async (contracts, pairIxs) => {
31
31
  }
32
32
  };
33
33
  exports.fetchPairs = fetchPairs;
34
- const fetchPairDepths = async (contracts, pairIxs) => {
34
+ const fetchPairDepthBands = async (contracts, pairIxs) => {
35
+ if (!contracts || pairIxs.length === 0) {
36
+ return [];
37
+ }
38
+ const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
39
+ try {
40
+ // Returns array of PairDepthBands structs (encoded slots)
41
+ return await multiCollatContract.getPairDepthBandsArray(pairIxs);
42
+ }
43
+ catch (error) {
44
+ console.error(`Unexpected error while fetching pair depth bands!`);
45
+ throw error;
46
+ }
47
+ };
48
+ exports.fetchPairDepthBands = fetchPairDepthBands;
49
+ const fetchPairDepthBandsDecoded = async (contracts, pairIxs) => {
50
+ if (!contracts || pairIxs.length === 0) {
51
+ return {
52
+ totalDepthAboveUsd: [],
53
+ totalDepthBelowUsd: [],
54
+ bandsAbove: [],
55
+ bandsBelow: [],
56
+ };
57
+ }
58
+ const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
59
+ try {
60
+ // Returns decoded values
61
+ // Using quoted signature for overloaded function
62
+ const [totalDepthAboveUsd, totalDepthBelowUsd, bandsAbove, bandsBelow] = await multiCollatContract.getPairDepthBandsDecodedArray(pairIxs);
63
+ return {
64
+ totalDepthAboveUsd: totalDepthAboveUsd.map((v) => parseFloat(v.toString())),
65
+ totalDepthBelowUsd: totalDepthBelowUsd.map((v) => parseFloat(v.toString())),
66
+ bandsAbove: bandsAbove.map((bands) => bands.map((b) => parseInt(b.toString()))),
67
+ bandsBelow: bandsBelow.map((bands) => bands.map((b) => parseInt(b.toString()))),
68
+ };
69
+ }
70
+ catch (error) {
71
+ console.error(`Unexpected error while fetching decoded pair depth bands!`);
72
+ throw error;
73
+ }
74
+ };
75
+ exports.fetchPairDepthBandsDecoded = fetchPairDepthBandsDecoded;
76
+ const fetchDepthBandsMapping = async (contracts) => {
77
+ if (!contracts) {
78
+ return { slot1: "0", slot2: "0" };
79
+ }
80
+ const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
81
+ try {
82
+ // Returns two uint256 slots
83
+ const [slot1, slot2] = await multiCollatContract.getDepthBandsMapping();
84
+ return {
85
+ slot1: slot1.toString(),
86
+ slot2: slot2.toString(),
87
+ };
88
+ }
89
+ catch (error) {
90
+ console.error(`Unexpected error while fetching depth bands mapping!`);
91
+ throw error;
92
+ }
93
+ };
94
+ exports.fetchDepthBandsMapping = fetchDepthBandsMapping;
95
+ const fetchDepthBandsMappingDecoded = async (contracts) => {
35
96
  if (!contracts) {
36
97
  return [];
37
98
  }
38
99
  const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
39
100
  try {
40
- const pairParams = await multiCollatContract.getPairDepths(pairIxs);
41
- return pairParams.map(pair => {
42
- return {
43
- onePercentDepthAboveUsd: parseFloat(pair.onePercentDepthAboveUsd.toString()),
44
- onePercentDepthBelowUsd: parseFloat(pair.onePercentDepthBelowUsd.toString()),
45
- };
46
- });
101
+ // Returns array of 30 uint16 values
102
+ const bands = await multiCollatContract.getDepthBandsMappingDecoded();
103
+ return bands.map((b) => parseInt(b.toString()));
47
104
  }
48
105
  catch (error) {
49
- console.error(`Unexpected error while fetching pairs!`);
106
+ console.error(`Unexpected error while fetching decoded depth bands mapping!`);
50
107
  throw error;
51
108
  }
52
109
  };
53
- exports.fetchPairDepths = fetchPairDepths;
110
+ exports.fetchDepthBandsMappingDecoded = fetchDepthBandsMappingDecoded;
54
111
  const fetchFees = async (contracts, feeIxs) => {
55
112
  if (!contracts) {
56
113
  return [];
package/lib/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export * from "./constants";
5
5
  export * from "./utils";
6
6
  export * from "./vault";
7
7
  export * from "./backend";
8
+ export * from "./pricing";
8
9
  export * from "./trade/fees/borrowing/index";
9
10
  export { ContractsVersion } from "./contracts/types";
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ __exportStar(require("./constants"), exports);
22
22
  __exportStar(require("./utils"), exports);
23
23
  __exportStar(require("./vault"), exports);
24
24
  __exportStar(require("./backend"), exports);
25
+ __exportStar(require("./pricing"), exports);
25
26
  // Not sure why this is needed, but it is. Barrel imports are not working.
26
27
  __exportStar(require("./trade/fees/borrowing/index"), exports);
27
28
  // Export ContractsVersion for frontend usage
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @dev Depth bands encoding/decoding functions
3
+ */
4
+ /**
5
+ * Encode depth bands data into two uint256 slots
6
+ * @param totalDepthUsd Total depth in USD (must fit in uint32)
7
+ * @param bandPercentagesBps Array of 30 band percentages in basis points
8
+ * @returns Two slots as bigints
9
+ */
10
+ export declare function encodeDepthBands(totalDepthUsd: number, bandPercentagesBps: number[]): {
11
+ slot1: bigint;
12
+ slot2: bigint;
13
+ };
14
+ /**
15
+ * Decode depth bands from two uint256 slots
16
+ * @param slot1 First slot containing totalDepthUsd and bands 0-13
17
+ * @param slot2 Second slot containing bands 14-29
18
+ * @returns Total depth and array of band percentages
19
+ */
20
+ export declare function decodeDepthBands(slot1: bigint, slot2: bigint): {
21
+ totalDepthUsd: number;
22
+ bands: number[];
23
+ };
24
+ /**
25
+ * Encode depth bands mapping (global offsets for all pairs)
26
+ * @param bands Array of 30 band offset values in ppm
27
+ * @returns Two slots as bigints
28
+ */
29
+ export declare function encodeDepthBandsMapping(bands: number[]): {
30
+ slot1: bigint;
31
+ slot2: bigint;
32
+ };
33
+ /**
34
+ * Decode depth bands mapping from two uint256 slots
35
+ * @param slot1 First slot containing bands 0-13 (starting at bit 32, first 32 bits unused)
36
+ * @param slot2 Second slot containing bands 14-29
37
+ * @returns Array of band offset values in ppm
38
+ */
39
+ export declare function decodeDepthBandsMapping(slot1: bigint, slot2: bigint): number[];
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Depth bands encoding/decoding functions
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.decodeDepthBandsMapping = exports.encodeDepthBandsMapping = exports.decodeDepthBands = exports.encodeDepthBands = void 0;
7
+ const DEPTH_BANDS_COUNT = 30;
8
+ const DEPTH_BANDS_PER_SLOT1 = 14;
9
+ /**
10
+ * Encode depth bands data into two uint256 slots
11
+ * @param totalDepthUsd Total depth in USD (must fit in uint32)
12
+ * @param bandPercentagesBps Array of 30 band percentages in basis points
13
+ * @returns Two slots as bigints
14
+ */
15
+ function encodeDepthBands(totalDepthUsd, bandPercentagesBps) {
16
+ // Pack slot1: totalDepthUsd (32 bits) + bands 0-13 (14 * 16 bits)
17
+ let slot1 = BigInt(totalDepthUsd);
18
+ for (let i = 0; i < DEPTH_BANDS_PER_SLOT1; i++) {
19
+ const shift = 32 + i * 16;
20
+ slot1 |= BigInt(bandPercentagesBps[i]) << BigInt(shift);
21
+ }
22
+ // Pack slot2: bands 14-29 (16 * 16 bits)
23
+ let slot2 = BigInt(0);
24
+ for (let i = DEPTH_BANDS_PER_SLOT1; i < DEPTH_BANDS_COUNT; i++) {
25
+ const shift = (i - DEPTH_BANDS_PER_SLOT1) * 16;
26
+ slot2 |= BigInt(bandPercentagesBps[i]) << BigInt(shift);
27
+ }
28
+ return { slot1, slot2 };
29
+ }
30
+ exports.encodeDepthBands = encodeDepthBands;
31
+ /**
32
+ * Decode depth bands from two uint256 slots
33
+ * @param slot1 First slot containing totalDepthUsd and bands 0-13
34
+ * @param slot2 Second slot containing bands 14-29
35
+ * @returns Total depth and array of band percentages
36
+ */
37
+ function decodeDepthBands(slot1, slot2) {
38
+ const totalDepthUsd = Number(slot1 & BigInt(0xffffffff));
39
+ const bands = [];
40
+ // Extract bands 0-13 from slot1
41
+ for (let i = 0; i < DEPTH_BANDS_PER_SLOT1; i++) {
42
+ const shift = 32 + i * 16;
43
+ bands.push(Number((slot1 >> BigInt(shift)) & BigInt(0xffff)));
44
+ }
45
+ // Extract bands 14-29 from slot2
46
+ for (let i = DEPTH_BANDS_PER_SLOT1; i < DEPTH_BANDS_COUNT; i++) {
47
+ const shift = (i - DEPTH_BANDS_PER_SLOT1) * 16;
48
+ bands.push(Number((slot2 >> BigInt(shift)) & BigInt(0xffff)));
49
+ }
50
+ return { totalDepthUsd, bands };
51
+ }
52
+ exports.decodeDepthBands = decodeDepthBands;
53
+ /**
54
+ * Encode depth bands mapping (global offsets for all pairs)
55
+ * @param bands Array of 30 band offset values in ppm
56
+ * @returns Two slots as bigints
57
+ */
58
+ function encodeDepthBandsMapping(bands) {
59
+ // Pack slot1: bands 0-13 (starting at bit 32, first 32 bits unused)
60
+ let slot1 = BigInt(0);
61
+ for (let i = 0; i < DEPTH_BANDS_PER_SLOT1; i++) {
62
+ const shift = 32 + i * 16; // Start at bit 32 to match contract
63
+ slot1 |= BigInt(bands[i]) << BigInt(shift);
64
+ }
65
+ // Pack slot2: bands 14-29 (16 * 16 bits)
66
+ let slot2 = BigInt(0);
67
+ for (let i = DEPTH_BANDS_PER_SLOT1; i < DEPTH_BANDS_COUNT; i++) {
68
+ const shift = (i - DEPTH_BANDS_PER_SLOT1) * 16;
69
+ slot2 |= BigInt(bands[i]) << BigInt(shift);
70
+ }
71
+ return { slot1, slot2 };
72
+ }
73
+ exports.encodeDepthBandsMapping = encodeDepthBandsMapping;
74
+ /**
75
+ * Decode depth bands mapping from two uint256 slots
76
+ * @param slot1 First slot containing bands 0-13 (starting at bit 32, first 32 bits unused)
77
+ * @param slot2 Second slot containing bands 14-29
78
+ * @returns Array of band offset values in ppm
79
+ */
80
+ function decodeDepthBandsMapping(slot1, slot2) {
81
+ const bands = [];
82
+ // Extract bands 0-13 from slot1 (skip first 32 bits which are unused for mappings)
83
+ for (let i = 0; i < DEPTH_BANDS_PER_SLOT1; i++) {
84
+ const shift = 32 + i * 16; // Start at bit 32, not bit 0
85
+ bands.push(Number((slot1 >> BigInt(shift)) & BigInt(0xffff)));
86
+ }
87
+ // Extract bands 14-29 from slot2
88
+ for (let i = DEPTH_BANDS_PER_SLOT1; i < DEPTH_BANDS_COUNT; i++) {
89
+ const shift = (i - DEPTH_BANDS_PER_SLOT1) * 16;
90
+ bands.push(Number((slot2 >> BigInt(shift)) & BigInt(0xffff)));
91
+ }
92
+ return bands;
93
+ }
94
+ exports.decodeDepthBandsMapping = decodeDepthBandsMapping;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @dev Pricing module exports
3
+ */
4
+ export * from "./depthBands";