@gearbox-protocol/sdk 3.0.0-next.124 → 3.0.0-next.125

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.
@@ -0,0 +1,33 @@
1
+ export declare enum PoolSpecialization {
2
+ GeneralPool = 0,
3
+ MinimalSwapInfoPool = 1,
4
+ TwoTokenPool = 2
5
+ }
6
+ /**
7
+ * Splits a poolId into its components, i.e. pool address, pool specialization and its nonce
8
+ * @param poolId - a bytes32 string of the pool's ID
9
+ * @returns an object with the decomposed poolId
10
+ */
11
+ export declare const splitPoolId: (poolId: string) => {
12
+ address: string;
13
+ specialization: PoolSpecialization;
14
+ nonce: bigint;
15
+ };
16
+ /**
17
+ * Extracts a pool's address from its poolId
18
+ * @param poolId - a bytes32 string of the pool's ID
19
+ * @returns the pool's address
20
+ */
21
+ export declare const getPoolAddress: (poolId: string) => string;
22
+ /**
23
+ * Extracts a pool's specialization from its poolId
24
+ * @param poolId - a bytes32 string of the pool's ID
25
+ * @returns the pool's specialization
26
+ */
27
+ export declare const getPoolSpecialization: (poolId: string) => PoolSpecialization;
28
+ /**
29
+ * Extracts a pool's nonce from its poolId
30
+ * @param poolId - a bytes32 string of the pool's ID
31
+ * @returns the pool's nonce
32
+ */
33
+ export declare const getPoolNonce: (poolId: string) => bigint;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPoolNonce = exports.getPoolSpecialization = exports.getPoolAddress = exports.splitPoolId = exports.PoolSpecialization = void 0;
4
+ var PoolSpecialization;
5
+ (function (PoolSpecialization) {
6
+ PoolSpecialization[PoolSpecialization["GeneralPool"] = 0] = "GeneralPool";
7
+ PoolSpecialization[PoolSpecialization["MinimalSwapInfoPool"] = 1] = "MinimalSwapInfoPool";
8
+ PoolSpecialization[PoolSpecialization["TwoTokenPool"] = 2] = "TwoTokenPool";
9
+ })(PoolSpecialization = exports.PoolSpecialization || (exports.PoolSpecialization = {}));
10
+ /**
11
+ * Splits a poolId into its components, i.e. pool address, pool specialization and its nonce
12
+ * @param poolId - a bytes32 string of the pool's ID
13
+ * @returns an object with the decomposed poolId
14
+ */
15
+ const splitPoolId = (poolId) => {
16
+ return {
17
+ address: (0, exports.getPoolAddress)(poolId),
18
+ specialization: (0, exports.getPoolSpecialization)(poolId),
19
+ nonce: (0, exports.getPoolNonce)(poolId),
20
+ };
21
+ };
22
+ exports.splitPoolId = splitPoolId;
23
+ /**
24
+ * Extracts a pool's address from its poolId
25
+ * @param poolId - a bytes32 string of the pool's ID
26
+ * @returns the pool's address
27
+ */
28
+ const getPoolAddress = (poolId) => {
29
+ if (poolId.length !== 66)
30
+ throw new Error("Invalid poolId length");
31
+ return poolId.slice(0, 42);
32
+ };
33
+ exports.getPoolAddress = getPoolAddress;
34
+ /**
35
+ * Extracts a pool's specialization from its poolId
36
+ * @param poolId - a bytes32 string of the pool's ID
37
+ * @returns the pool's specialization
38
+ */
39
+ const getPoolSpecialization = (poolId) => {
40
+ if (poolId.length !== 66)
41
+ throw new Error("Invalid poolId length");
42
+ // Only have 3 pool specializations so we can just pull the relevant character
43
+ const specializationCode = parseInt(poolId[45], 10);
44
+ if (specializationCode >= 3)
45
+ throw new Error("Invalid pool specialization");
46
+ return specializationCode;
47
+ };
48
+ exports.getPoolSpecialization = getPoolSpecialization;
49
+ /**
50
+ * Extracts a pool's nonce from its poolId
51
+ * @param poolId - a bytes32 string of the pool's ID
52
+ * @returns the pool's nonce
53
+ */
54
+ const getPoolNonce = (poolId) => {
55
+ if (poolId.length !== 66)
56
+ throw new Error("Invalid poolId length");
57
+ return BigInt(`0x${poolId.slice(46)}`);
58
+ };
59
+ exports.getPoolNonce = getPoolNonce;
@@ -1,4 +1,5 @@
1
- import { providers, utils } from "ethers";
1
+ import { providers } from "ethers";
2
+ import { Interface } from "ethers/lib/utils";
2
3
  import { MultiCall } from "./core";
3
4
  export interface FeeInfo {
4
5
  type: KnownFeeTypes;
@@ -16,7 +17,7 @@ export declare const BALANCER_VAULT_ABI: {
16
17
  stateMutability: string;
17
18
  type: string;
18
19
  }[];
19
- export declare const BALANCER_VAULT_INTERFACE: utils.Interface;
20
+ export declare const BALANCER_VAULT_INTERFACE: Interface;
20
21
  interface FindPathFeesProps {
21
22
  calls: Array<MultiCall>;
22
23
  provider: providers.Provider;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PathFinderUtils = exports.BALANCER_VAULT_INTERFACE = exports.BALANCER_VAULT_ABI = void 0;
4
4
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
- const ethers_1 = require("ethers");
6
5
  const utils_1 = require("ethers/lib/utils");
7
6
  const balancerV2VaultParser_1 = require("../parsers/balancerV2VaultParser");
8
7
  const curveAdapterParser_1 = require("../parsers/curveAdapterParser");
@@ -11,6 +10,7 @@ const txParser_1 = require("../parsers/txParser");
11
10
  const uniV2AdapterParser_1 = require("../parsers/uniV2AdapterParser");
12
11
  const uniV3AdapterParser_1 = require("../parsers/uniV3AdapterParser");
13
12
  const types_1 = require("../types");
13
+ const balancerVault_1 = require("./balancerVault");
14
14
  const CURVE_FEE_DECIMALS = 100000000n;
15
15
  const BALANCER_FEE_DECIMALS = 10000000000000000n;
16
16
  exports.BALANCER_VAULT_ABI = [
@@ -151,11 +151,10 @@ class PathFinderUtils {
151
151
  case "swapDiff":
152
152
  case "swap": {
153
153
  const { poolId = "" } = callObject.args?.[0] || {};
154
- // !& implement address getting
155
- const [contract] = ethers_1.utils.defaultAbiCoder.decode(["address", "unit16"], poolId);
156
- return contract
154
+ const { address } = (0, balancerVault_1.splitPoolId)(poolId);
155
+ return address
157
156
  ? {
158
- address: contract,
157
+ address,
159
158
  interface: exports.BALANCER_VAULT_INTERFACE,
160
159
  method: "getSwapFeePercentage()",
161
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.124",
3
+ "version": "3.0.0-next.125",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",