lynx-client 0.0.26 → 0.0.28

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.
@@ -4,16 +4,16 @@ exports.RateModelLensService = void 0;
4
4
  const RateModelLens__factory_1 = require("../../typechain/factories/contracts/Peripheral/Lens/RateModelLens__factory");
5
5
  const ethersTypes_1 = require("../../utils/ethersTypes");
6
6
  const IRateModelLensService_1 = require("./IRateModelLensService");
7
- // Conversion scale constants
8
- const PRECISION_SCALE = 1e18;
7
+ const chipsCalculationsUtils_1 = require("../../lynxSystem/chipsCalculationsUtils");
8
+ const lynxScalesUtils_1 = require("../../lynxSystem/lynxScalesUtils");
9
9
  // Helper functions for converting raw values to human-readable
10
10
  function convertRateParamsToUnits(raw) {
11
11
  return {
12
- baseRateInUnits: Number(raw.baseRate) / PRECISION_SCALE,
13
- multiplierInUnits: Number(raw.multiplier) / PRECISION_SCALE,
14
- kink: Number(raw.kink) / PRECISION_SCALE,
15
- postKinkMultiplierInUnits: Number(raw.postKinkMultiplier) / PRECISION_SCALE,
16
- rateOnKinkInUnits: Number(raw.rateOnKink) / PRECISION_SCALE,
12
+ baseRateInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.baseRate),
13
+ multiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.multiplier),
14
+ kink: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.kink),
15
+ postKinkMultiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.postKinkMultiplier),
16
+ rateOnKinkInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.rateOnKink),
17
17
  raw: {
18
18
  baseRate: raw.baseRate,
19
19
  multiplier: raw.multiplier,
@@ -25,11 +25,11 @@ function convertRateParamsToUnits(raw) {
25
25
  }
26
26
  function convertIRMRateParamsToUnits(raw) {
27
27
  return {
28
- baseRateInUnits: Number(raw.baseRate) / PRECISION_SCALE,
29
- multiplierInUnits: Number(raw.multiplier) / PRECISION_SCALE,
30
- kink: Number(raw.kink) / PRECISION_SCALE,
31
- postKinkMultiplierInUnits: Number(raw.postKinkMultiplier) / PRECISION_SCALE,
32
- rateOnKinkInUnits: Number(raw.rateOnKink) / PRECISION_SCALE,
28
+ baseRateInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.baseRate),
29
+ multiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.multiplier),
30
+ kink: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.kink),
31
+ postKinkMultiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.postKinkMultiplier),
32
+ rateOnKinkInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.rateOnKink),
33
33
  raw: {
34
34
  baseRate: raw.baseRate,
35
35
  multiplier: raw.multiplier,
@@ -43,7 +43,7 @@ function convertAccountantConfig(raw) {
43
43
  return {
44
44
  accountant: raw.accountant,
45
45
  lexPool: raw.lexPool,
46
- minTotalOIForFundingInUnits: Number(raw.minTotalOIForFunding) / PRECISION_SCALE,
46
+ minTotalOIForFundingInUnits: (0, chipsCalculationsUtils_1.chipsBnToUnits)(raw.minTotalOIForFunding),
47
47
  };
48
48
  }
49
49
  function convertPairSpecificParams(raw) {
@@ -68,7 +68,9 @@ class RateModelLensService {
68
68
  const fundingRateModelGroupsRaw = (0, ethersTypes_1.ethersStructResponseToArray)(result.fundingRateModelGroups, IRateModelLensService_1.EMPTY_FUNDING_RATE_MODEL_GROUP_RAW, {
69
69
  accountantConfigs: IRateModelLensService_1.EMPTY_FRM_ACCOUNTANT_CONFIG_RAW,
70
70
  pairSpecificParams: IRateModelLensService_1.EMPTY_FRM_PAIR_SPECIFIC_PARAMS_RAW,
71
- });
71
+ }, {
72
+ baseRateParams: IRateModelLensService_1.EMPTY_FRM_BASE_RATE_PARAMS_RAW,
73
+ }, ['lexPools', 'accountants']);
72
74
  // Convert to human-readable
73
75
  const fundingRateModelGroups = fundingRateModelGroupsRaw.map((group) => ({
74
76
  fundingRateModel: group.fundingRateModel,
@@ -81,7 +83,9 @@ class RateModelLensService {
81
83
  pairSpecificParams: group.pairSpecificParams.map(convertPairSpecificParams),
82
84
  }));
83
85
  // Convert interest rate model groups (raw)
84
- const interestRateModelGroupsRaw = (0, ethersTypes_1.ethersStructResponseToArray)(result.interestRateModelGroups, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW);
86
+ const interestRateModelGroupsRaw = (0, ethersTypes_1.ethersStructResponseToArray)(result.interestRateModelGroups, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW, {}, {
87
+ baseRateParams: IRateModelLensService_1.EMPTY_IRM_BASE_RATE_PARAMS_RAW,
88
+ }, ['lexPools', 'accountants']);
85
89
  // Convert to human-readable
86
90
  const interestRateModelGroups = interestRateModelGroupsRaw.map((group) => ({
87
91
  interestRateModel: group.interestRateModel,
@@ -102,7 +106,9 @@ class RateModelLensService {
102
106
  const rawGroups = (0, ethersTypes_1.ethersStructResponseToArray)(result, IRateModelLensService_1.EMPTY_FUNDING_RATE_MODEL_GROUP_RAW, {
103
107
  accountantConfigs: IRateModelLensService_1.EMPTY_FRM_ACCOUNTANT_CONFIG_RAW,
104
108
  pairSpecificParams: IRateModelLensService_1.EMPTY_FRM_PAIR_SPECIFIC_PARAMS_RAW,
105
- });
109
+ }, {
110
+ baseRateParams: IRateModelLensService_1.EMPTY_FRM_BASE_RATE_PARAMS_RAW,
111
+ }, ['lexPools', 'accountants']);
106
112
  // Convert to human-readable
107
113
  return rawGroups.map((group) => ({
108
114
  fundingRateModel: group.fundingRateModel,
@@ -118,7 +124,9 @@ class RateModelLensService {
118
124
  async getInterestRateModelGroups(lexPools) {
119
125
  const result = await this.contract.getInterestRateModelGroups(lexPools);
120
126
  // Convert to raw first
121
- const rawGroups = (0, ethersTypes_1.ethersStructResponseToArray)(result, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW);
127
+ const rawGroups = (0, ethersTypes_1.ethersStructResponseToArray)(result, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW, {}, {
128
+ baseRateParams: IRateModelLensService_1.EMPTY_IRM_BASE_RATE_PARAMS_RAW,
129
+ }, ['lexPools', 'accountants']);
122
130
  // Convert to human-readable
123
131
  return rawGroups.map((group) => ({
124
132
  interestRateModel: group.interestRateModel,
@@ -9,13 +9,18 @@ function ethersStructResponseToObject(ethersStructResponse,
9
9
  // NOTE : This is needed due to changes in ethers 6 + typechain that returns weird proxy object for struct which
10
10
  // makes it hard/impossible to get the proper keys of the intended type.
11
11
  // TODO : Solve it if possible ?
12
- emptyConcreteObject,
12
+ emptyConcreteObject = undefined,
13
13
  // NOTE : This is needed because inner array's object's fields cannot be auto inferred (same as with the main object)
14
14
  // TODO : Improve type to allow only keys found in the original object
15
- innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
15
+ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {},
16
+ // Keys of arrays that contain primitive values (strings, numbers, etc.) rather than structs
17
+ primitiveArrayKeys = []) {
16
18
  const obj = {};
17
- // for (let key in ethersStructResponse) {
18
- for (const key of Object.keys(emptyConcreteObject)) {
19
+ // If no emptyConcreteObject provided, use keys from the response (filtering out numeric indices)
20
+ const keys = emptyConcreteObject
21
+ ? Object.keys(emptyConcreteObject)
22
+ : Object.keys(ethersStructResponse).filter(key => Number.isNaN(parseInt(key)));
23
+ for (const key of keys) {
19
24
  // DEV_NOTE : We assume that all numeric keys belongs to the array and ignore them
20
25
  if (Number.isNaN(parseInt(key))) {
21
26
  // @ts-ignore
@@ -33,17 +38,40 @@ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
33
38
  // @ts-ignore
34
39
  }
35
40
  else if (innerStructsConcreteObjectMap[key] !== undefined) {
41
+ // Extract nested configuration for this specific nested struct
36
42
  // @ts-ignore
37
- obj[key] = ethersStructResponseToObject(value,
43
+ const nestedTemplate = innerStructsConcreteObjectMap[key];
44
+ const nestedInnerArrays = {};
45
+ const nestedInnerStructs = {};
46
+ // Scan the nested template to find arrays and structs within it
47
+ for (const [nestedKey, nestedValue] of Object.entries(nestedTemplate)) {
48
+ if (nestedValue && typeof nestedValue === 'object') {
49
+ if (Array.isArray(nestedValue)) {
50
+ // This is an array in the nested struct
51
+ nestedInnerArrays[nestedKey] = nestedValue.length > 0 ? nestedValue[0] : {};
52
+ }
53
+ else {
54
+ // This is a further nested struct
55
+ nestedInnerStructs[nestedKey] = nestedValue;
56
+ }
57
+ }
58
+ }
38
59
  // @ts-ignore
39
- innerStructsConcreteObjectMap[key]);
60
+ obj[key] = ethersStructResponseToObject(value, nestedTemplate, nestedInnerArrays, nestedInnerStructs, primitiveArrayKeys);
40
61
  }
41
62
  else if (Array.isArray(value)) {
42
63
  if (value.length === 0) {
43
64
  // @ts-ignore
44
65
  obj[key] = [];
45
66
  }
67
+ else if (primitiveArrayKeys.includes(key)) {
68
+ // Handle primitive arrays (strings, addresses, numbers, etc.)
69
+ // Convert ethers Result array to plain array of strings
70
+ // @ts-ignore
71
+ obj[key] = Array.from(value).map(item => String(item));
72
+ }
46
73
  else {
74
+ // Handle struct arrays (existing behavior)
47
75
  const emptyObjectOfArray =
48
76
  // @ts-ignore
49
77
  innerArraysConcreteObjectMap[key] ?? {};
@@ -51,8 +79,26 @@ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
51
79
  // // @ts-ignore
52
80
  // `@@@@ innerArraysConcreteObjectMap[key] ${innerArraysConcreteObjectMap[key]}`,
53
81
  // );
82
+ // Detect nested structs and arrays within the array element template
83
+ // and pass them as innerStructsConcreteObjectMap and innerArraysConcreteObjectMap
84
+ const nestedStructs = {};
85
+ const nestedArrays = {};
86
+ if (emptyObjectOfArray && typeof emptyObjectOfArray === 'object') {
87
+ for (const [nestedKey, nestedValue] of Object.entries(emptyObjectOfArray)) {
88
+ if (nestedValue && typeof nestedValue === 'object') {
89
+ if (Array.isArray(nestedValue)) {
90
+ // This is a nested array
91
+ nestedArrays[nestedKey] = nestedValue.length > 0 ? nestedValue[0] : {};
92
+ }
93
+ else {
94
+ // This is a nested struct
95
+ nestedStructs[nestedKey] = nestedValue;
96
+ }
97
+ }
98
+ }
99
+ }
54
100
  // @ts-ignore
55
- obj[key] = ethersStructResponseToArray(value, emptyObjectOfArray);
101
+ obj[key] = ethersStructResponseToArray(value, emptyObjectOfArray, nestedArrays, nestedStructs, primitiveArrayKeys);
56
102
  }
57
103
  }
58
104
  else {
@@ -66,8 +112,8 @@ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
66
112
  }
67
113
  return obj;
68
114
  }
69
- function ethersStructResponseToArray(ethersStructResponseArray, emptyConcreteObject, innerArraysConcreteObjectMap = {}) {
70
- return ethersStructResponseArray.map((struct) => ethersStructResponseToObject(struct, emptyConcreteObject, innerArraysConcreteObjectMap));
115
+ function ethersStructResponseToArray(ethersStructResponseArray, emptyConcreteObject = undefined, innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}, primitiveArrayKeys = []) {
116
+ return ethersStructResponseArray.map((struct) => ethersStructResponseToObject(struct, emptyConcreteObject, innerArraysConcreteObjectMap, innerStructsConcreteObjectMap, primitiveArrayKeys));
71
117
  }
72
118
  function isFunction(functionToCheck) {
73
119
  return (functionToCheck && {}.toString.call(functionToCheck) === "[object Function]");
@@ -1 +1 @@
1
- {"version":3,"file":"RateModelLensService.d.ts","sourceRoot":"","sources":["../../../../../lib/contractsIntegration/RateModelLensService/RateModelLensService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,yDAAyD,CAAA;AAMvF,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,4BAA4B,EAC5B,6BAA6B,EAU9B,MAAM,yBAAyB,CAAA;AAwDhC,qBAAa,oBAAqB,YAAW,qBAAqB;IA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C,yBAAyB,CAC7B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,4BAA4B,EAAE,CAAC;IAgCpC,0BAA0B,CAC9B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,6BAA6B,EAAE,CAAC;IAyB3C,WAAW,IAAI,aAAa;CAG7B"}
@@ -4,16 +4,16 @@ exports.RateModelLensService = void 0;
4
4
  const RateModelLens__factory_1 = require("../../typechain/factories/contracts/Peripheral/Lens/RateModelLens__factory");
5
5
  const ethersTypes_1 = require("../../utils/ethersTypes");
6
6
  const IRateModelLensService_1 = require("./IRateModelLensService");
7
- // Conversion scale constants
8
- const PRECISION_SCALE = 1e18;
7
+ const chipsCalculationsUtils_1 = require("../../lynxSystem/chipsCalculationsUtils");
8
+ const lynxScalesUtils_1 = require("../../lynxSystem/lynxScalesUtils");
9
9
  // Helper functions for converting raw values to human-readable
10
10
  function convertRateParamsToUnits(raw) {
11
11
  return {
12
- baseRateInUnits: Number(raw.baseRate) / PRECISION_SCALE,
13
- multiplierInUnits: Number(raw.multiplier) / PRECISION_SCALE,
14
- kink: Number(raw.kink) / PRECISION_SCALE,
15
- postKinkMultiplierInUnits: Number(raw.postKinkMultiplier) / PRECISION_SCALE,
16
- rateOnKinkInUnits: Number(raw.rateOnKink) / PRECISION_SCALE,
12
+ baseRateInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.baseRate),
13
+ multiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.multiplier),
14
+ kink: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.kink),
15
+ postKinkMultiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.postKinkMultiplier),
16
+ rateOnKinkInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.rateOnKink),
17
17
  raw: {
18
18
  baseRate: raw.baseRate,
19
19
  multiplier: raw.multiplier,
@@ -25,11 +25,11 @@ function convertRateParamsToUnits(raw) {
25
25
  }
26
26
  function convertIRMRateParamsToUnits(raw) {
27
27
  return {
28
- baseRateInUnits: Number(raw.baseRate) / PRECISION_SCALE,
29
- multiplierInUnits: Number(raw.multiplier) / PRECISION_SCALE,
30
- kink: Number(raw.kink) / PRECISION_SCALE,
31
- postKinkMultiplierInUnits: Number(raw.postKinkMultiplier) / PRECISION_SCALE,
32
- rateOnKinkInUnits: Number(raw.rateOnKink) / PRECISION_SCALE,
28
+ baseRateInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.baseRate),
29
+ multiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.multiplier),
30
+ kink: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.kink),
31
+ postKinkMultiplierInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.postKinkMultiplier),
32
+ rateOnKinkInUnits: (0, lynxScalesUtils_1.precisionBnToFloat)(raw.rateOnKink),
33
33
  raw: {
34
34
  baseRate: raw.baseRate,
35
35
  multiplier: raw.multiplier,
@@ -43,7 +43,7 @@ function convertAccountantConfig(raw) {
43
43
  return {
44
44
  accountant: raw.accountant,
45
45
  lexPool: raw.lexPool,
46
- minTotalOIForFundingInUnits: Number(raw.minTotalOIForFunding) / PRECISION_SCALE,
46
+ minTotalOIForFundingInUnits: (0, chipsCalculationsUtils_1.chipsBnToUnits)(raw.minTotalOIForFunding),
47
47
  };
48
48
  }
49
49
  function convertPairSpecificParams(raw) {
@@ -68,7 +68,9 @@ class RateModelLensService {
68
68
  const fundingRateModelGroupsRaw = (0, ethersTypes_1.ethersStructResponseToArray)(result.fundingRateModelGroups, IRateModelLensService_1.EMPTY_FUNDING_RATE_MODEL_GROUP_RAW, {
69
69
  accountantConfigs: IRateModelLensService_1.EMPTY_FRM_ACCOUNTANT_CONFIG_RAW,
70
70
  pairSpecificParams: IRateModelLensService_1.EMPTY_FRM_PAIR_SPECIFIC_PARAMS_RAW,
71
- });
71
+ }, {
72
+ baseRateParams: IRateModelLensService_1.EMPTY_FRM_BASE_RATE_PARAMS_RAW,
73
+ }, ['lexPools', 'accountants']);
72
74
  // Convert to human-readable
73
75
  const fundingRateModelGroups = fundingRateModelGroupsRaw.map((group) => ({
74
76
  fundingRateModel: group.fundingRateModel,
@@ -81,7 +83,9 @@ class RateModelLensService {
81
83
  pairSpecificParams: group.pairSpecificParams.map(convertPairSpecificParams),
82
84
  }));
83
85
  // Convert interest rate model groups (raw)
84
- const interestRateModelGroupsRaw = (0, ethersTypes_1.ethersStructResponseToArray)(result.interestRateModelGroups, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW);
86
+ const interestRateModelGroupsRaw = (0, ethersTypes_1.ethersStructResponseToArray)(result.interestRateModelGroups, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW, {}, {
87
+ baseRateParams: IRateModelLensService_1.EMPTY_IRM_BASE_RATE_PARAMS_RAW,
88
+ }, ['lexPools', 'accountants']);
85
89
  // Convert to human-readable
86
90
  const interestRateModelGroups = interestRateModelGroupsRaw.map((group) => ({
87
91
  interestRateModel: group.interestRateModel,
@@ -102,7 +106,9 @@ class RateModelLensService {
102
106
  const rawGroups = (0, ethersTypes_1.ethersStructResponseToArray)(result, IRateModelLensService_1.EMPTY_FUNDING_RATE_MODEL_GROUP_RAW, {
103
107
  accountantConfigs: IRateModelLensService_1.EMPTY_FRM_ACCOUNTANT_CONFIG_RAW,
104
108
  pairSpecificParams: IRateModelLensService_1.EMPTY_FRM_PAIR_SPECIFIC_PARAMS_RAW,
105
- });
109
+ }, {
110
+ baseRateParams: IRateModelLensService_1.EMPTY_FRM_BASE_RATE_PARAMS_RAW,
111
+ }, ['lexPools', 'accountants']);
106
112
  // Convert to human-readable
107
113
  return rawGroups.map((group) => ({
108
114
  fundingRateModel: group.fundingRateModel,
@@ -118,7 +124,9 @@ class RateModelLensService {
118
124
  async getInterestRateModelGroups(lexPools) {
119
125
  const result = await this.contract.getInterestRateModelGroups(lexPools);
120
126
  // Convert to raw first
121
- const rawGroups = (0, ethersTypes_1.ethersStructResponseToArray)(result, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW);
127
+ const rawGroups = (0, ethersTypes_1.ethersStructResponseToArray)(result, IRateModelLensService_1.EMPTY_INTEREST_RATE_MODEL_GROUP_RAW, {}, {
128
+ baseRateParams: IRateModelLensService_1.EMPTY_IRM_BASE_RATE_PARAMS_RAW,
129
+ }, ['lexPools', 'accountants']);
122
130
  // Convert to human-readable
123
131
  return rawGroups.map((group) => ({
124
132
  interestRateModel: group.interestRateModel,
@@ -9,6 +9,6 @@ export type TSafeBigNumberStruct<T extends object> = {
9
9
  /**
10
10
  * This functions takes a tuple returned from an 'ethers' contract object and returns it in a pure object form.
11
11
  */
12
- export declare function ethersStructResponseToObject<T extends object>(ethersStructResponse: object, emptyConcreteObject: T, innerArraysConcreteObjectMap?: object, innerStructsConcreteObjectMap?: object): T;
13
- export declare function ethersStructResponseToArray<T extends object>(ethersStructResponseArray: object[], emptyConcreteObject: T, innerArraysConcreteObjectMap?: object): T[];
12
+ export declare function ethersStructResponseToObject<T extends object>(ethersStructResponse: object, emptyConcreteObject?: T | undefined, innerArraysConcreteObjectMap?: object, innerStructsConcreteObjectMap?: object, primitiveArrayKeys?: string[]): T;
13
+ export declare function ethersStructResponseToArray<T extends object>(ethersStructResponseArray: object[], emptyConcreteObject?: T | undefined, innerArraysConcreteObjectMap?: object, innerStructsConcreteObjectMap?: object, primitiveArrayKeys?: string[]): T[];
14
14
  //# sourceMappingURL=ethersTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ethersTypes.d.ts","sourceRoot":"","sources":["../../../../lib/utils/ethersTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MA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AgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GACtC,SAAS,GACT,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,GACzC,MAAM,GACN,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,WAAW,GACxC,MAAM,GACN,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACnC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC5C,OAAO;CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,MAAM,EAC3D,oBAAoB,EAAE,MAAM,EAI5B,mBAAmB,GAAE,CAAC,GAAG,SAAqB,EAG9C,4BAA4B,GAAE,MAAW,EACzC,6BAA6B,GAAE,MAAW,EAE1C,kBAAkB,GAAE,MAAM,EAAO,GAChC,CAAC,CAiHH;AAED,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,EAC1D,yBAAyB,EAAE,MAAM,EAAE,EACnC,mBAAmB,GAAE,CAAC,GAAG,SAAqB,EAC9C,4BAA4B,GAAE,MAAW,EACzC,6BAA6B,GAAE,MAAW,EAC1C,kBAAkB,GAAE,MAAM,EAAO,GAChC,CAAC,EAAE,CAUL"}
@@ -9,13 +9,18 @@ function ethersStructResponseToObject(ethersStructResponse,
9
9
  // NOTE : This is needed due to changes in ethers 6 + typechain that returns weird proxy object for struct which
10
10
  // makes it hard/impossible to get the proper keys of the intended type.
11
11
  // TODO : Solve it if possible ?
12
- emptyConcreteObject,
12
+ emptyConcreteObject = undefined,
13
13
  // NOTE : This is needed because inner array's object's fields cannot be auto inferred (same as with the main object)
14
14
  // TODO : Improve type to allow only keys found in the original object
15
- innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
15
+ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {},
16
+ // Keys of arrays that contain primitive values (strings, numbers, etc.) rather than structs
17
+ primitiveArrayKeys = []) {
16
18
  const obj = {};
17
- // for (let key in ethersStructResponse) {
18
- for (const key of Object.keys(emptyConcreteObject)) {
19
+ // If no emptyConcreteObject provided, use keys from the response (filtering out numeric indices)
20
+ const keys = emptyConcreteObject
21
+ ? Object.keys(emptyConcreteObject)
22
+ : Object.keys(ethersStructResponse).filter(key => Number.isNaN(parseInt(key)));
23
+ for (const key of keys) {
19
24
  // DEV_NOTE : We assume that all numeric keys belongs to the array and ignore them
20
25
  if (Number.isNaN(parseInt(key))) {
21
26
  // @ts-ignore
@@ -33,17 +38,40 @@ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
33
38
  // @ts-ignore
34
39
  }
35
40
  else if (innerStructsConcreteObjectMap[key] !== undefined) {
41
+ // Extract nested configuration for this specific nested struct
36
42
  // @ts-ignore
37
- obj[key] = ethersStructResponseToObject(value,
43
+ const nestedTemplate = innerStructsConcreteObjectMap[key];
44
+ const nestedInnerArrays = {};
45
+ const nestedInnerStructs = {};
46
+ // Scan the nested template to find arrays and structs within it
47
+ for (const [nestedKey, nestedValue] of Object.entries(nestedTemplate)) {
48
+ if (nestedValue && typeof nestedValue === 'object') {
49
+ if (Array.isArray(nestedValue)) {
50
+ // This is an array in the nested struct
51
+ nestedInnerArrays[nestedKey] = nestedValue.length > 0 ? nestedValue[0] : {};
52
+ }
53
+ else {
54
+ // This is a further nested struct
55
+ nestedInnerStructs[nestedKey] = nestedValue;
56
+ }
57
+ }
58
+ }
38
59
  // @ts-ignore
39
- innerStructsConcreteObjectMap[key]);
60
+ obj[key] = ethersStructResponseToObject(value, nestedTemplate, nestedInnerArrays, nestedInnerStructs, primitiveArrayKeys);
40
61
  }
41
62
  else if (Array.isArray(value)) {
42
63
  if (value.length === 0) {
43
64
  // @ts-ignore
44
65
  obj[key] = [];
45
66
  }
67
+ else if (primitiveArrayKeys.includes(key)) {
68
+ // Handle primitive arrays (strings, addresses, numbers, etc.)
69
+ // Convert ethers Result array to plain array of strings
70
+ // @ts-ignore
71
+ obj[key] = Array.from(value).map(item => String(item));
72
+ }
46
73
  else {
74
+ // Handle struct arrays (existing behavior)
47
75
  const emptyObjectOfArray =
48
76
  // @ts-ignore
49
77
  innerArraysConcreteObjectMap[key] ?? {};
@@ -51,8 +79,26 @@ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
51
79
  // // @ts-ignore
52
80
  // `@@@@ innerArraysConcreteObjectMap[key] ${innerArraysConcreteObjectMap[key]}`,
53
81
  // );
82
+ // Detect nested structs and arrays within the array element template
83
+ // and pass them as innerStructsConcreteObjectMap and innerArraysConcreteObjectMap
84
+ const nestedStructs = {};
85
+ const nestedArrays = {};
86
+ if (emptyObjectOfArray && typeof emptyObjectOfArray === 'object') {
87
+ for (const [nestedKey, nestedValue] of Object.entries(emptyObjectOfArray)) {
88
+ if (nestedValue && typeof nestedValue === 'object') {
89
+ if (Array.isArray(nestedValue)) {
90
+ // This is a nested array
91
+ nestedArrays[nestedKey] = nestedValue.length > 0 ? nestedValue[0] : {};
92
+ }
93
+ else {
94
+ // This is a nested struct
95
+ nestedStructs[nestedKey] = nestedValue;
96
+ }
97
+ }
98
+ }
99
+ }
54
100
  // @ts-ignore
55
- obj[key] = ethersStructResponseToArray(value, emptyObjectOfArray);
101
+ obj[key] = ethersStructResponseToArray(value, emptyObjectOfArray, nestedArrays, nestedStructs, primitiveArrayKeys);
56
102
  }
57
103
  }
58
104
  else {
@@ -66,8 +112,8 @@ innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}) {
66
112
  }
67
113
  return obj;
68
114
  }
69
- function ethersStructResponseToArray(ethersStructResponseArray, emptyConcreteObject, innerArraysConcreteObjectMap = {}) {
70
- return ethersStructResponseArray.map((struct) => ethersStructResponseToObject(struct, emptyConcreteObject, innerArraysConcreteObjectMap));
115
+ function ethersStructResponseToArray(ethersStructResponseArray, emptyConcreteObject = undefined, innerArraysConcreteObjectMap = {}, innerStructsConcreteObjectMap = {}, primitiveArrayKeys = []) {
116
+ return ethersStructResponseArray.map((struct) => ethersStructResponseToObject(struct, emptyConcreteObject, innerArraysConcreteObjectMap, innerStructsConcreteObjectMap, primitiveArrayKeys));
71
117
  }
72
118
  function isFunction(functionToCheck) {
73
119
  return (functionToCheck && {}.toString.call(functionToCheck) === "[object Function]");
@@ -1 +1 @@
1
- {"version":3,"file":"RateModelLensService.d.ts","sourceRoot":"","sources":["../../../../../lib/contractsIntegration/RateModelLensService/RateModelLensService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,yDAAyD,CAAA;AAMvF,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,4BAA4B,EAC5B,6BAA6B,EAU9B,MAAM,yBAAyB,CAAA;AAwDhC,qBAAa,oBAAqB,YAAW,qBAAqB;IAChE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,eAAe,EAAE,MAAM;IAOlE,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI5D,yBAAyB,CAC7B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,gCAAgC,CAAC;IAmDtC,yBAAyB,CAC7B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,4BAA4B,EAAE,CAAC;IA4BpC,0BAA0B,CAC9B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,6BAA6B,EAAE,CAAC;IAoB3C,WAAW,IAAI,aAAa;CAG7B"}
1
+ {"version":3,"file":"RateModelLensService.d.ts","sourceRoot":"","sources":["../../../../../lib/contractsIntegration/RateModelLensService/RateModelLensService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,yDAAyD,CAAA;AAMvF,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,4BAA4B,EAC5B,6BAA6B,EAY9B,MAAM,yBAAyB,CAAA;AAuDhC,qBAAa,oBAAqB,YAAW,qBAAqB;IAChE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,eAAe,EAAE,MAAM;IAOlE,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI5D,yBAAyB,CAC7B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,gCAAgC,CAAC;IA4DtC,yBAAyB,CAC7B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,4BAA4B,EAAE,CAAC;IAgCpC,0BAA0B,CAC9B,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,6BAA6B,EAAE,CAAC;IAyB3C,WAAW,IAAI,aAAa;CAG7B"}
@@ -9,6 +9,6 @@ export type TSafeBigNumberStruct<T extends object> = {
9
9
  /**
10
10
  * This functions takes a tuple returned from an 'ethers' contract object and returns it in a pure object form.
11
11
  */
12
- export declare function ethersStructResponseToObject<T extends object>(ethersStructResponse: object, emptyConcreteObject: T, innerArraysConcreteObjectMap?: object, innerStructsConcreteObjectMap?: object): T;
13
- export declare function ethersStructResponseToArray<T extends object>(ethersStructResponseArray: object[], emptyConcreteObject: T, innerArraysConcreteObjectMap?: object): T[];
12
+ export declare function ethersStructResponseToObject<T extends object>(ethersStructResponse: object, emptyConcreteObject?: T | undefined, innerArraysConcreteObjectMap?: object, innerStructsConcreteObjectMap?: object, primitiveArrayKeys?: string[]): T;
13
+ export declare function ethersStructResponseToArray<T extends object>(ethersStructResponseArray: object[], emptyConcreteObject?: T | undefined, innerArraysConcreteObjectMap?: object, innerStructsConcreteObjectMap?: object, primitiveArrayKeys?: string[]): T[];
14
14
  //# sourceMappingURL=ethersTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ethersTypes.d.ts","sourceRoot":"","sources":["../../../../lib/utils/ethersTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,IAAI;KAClD,CAAC,IAAI,MAAM,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACjD,MAAM,GACN,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GACtC,SAAS,GACT,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,GACzC,MAAM,GACN,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,WAAW,GACxC,MAAM,GACN,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACnC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC5C,OAAO;CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,MAAM,EAC3D,oBAAoB,EAAE,MAAM,EAI5B,mBAAmB,EAAE,CAAC,EAGtB,4BAA4B,GAAE,MAAW,EACzC,6BAA6B,GAAE,MAAW,GACzC,CAAC,CA8DH;AAED,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,EAC1D,yBAAyB,EAAE,MAAM,EAAE,EACnC,mBA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E,MAAW,EAC1C,kBAAkB,GAAE,MAAM,EAAO,GAChC,CAAC,EAAE,CAUL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lynx-client",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "Client library for interacting with Lynx publicly available services",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -23,7 +23,8 @@
23
23
  "build:cjs": "tsc -p tsconfig.cjs.json",
24
24
  "build": "npm run clean && npm run build:esm && npm run build:cjs",
25
25
  "prepublishOnly": "npm run build",
26
- "test": "jest"
26
+ "test": "jest",
27
+ "test:rate-model-lens": "tsx scripts/testRateModelLens.ts"
27
28
  },
28
29
  "repository": {
29
30
  "type": "git",
@@ -37,9 +38,12 @@
37
38
  "homepage": "https://github.com/lynx-protocol/lynx-client#readme",
38
39
  "devDependencies": {
39
40
  "@types/jest": "^30.0.0",
41
+ "@types/node": "^22.0.0",
42
+ "commander": "^14.0.1",
40
43
  "jest": "^30.1.3",
41
44
  "prettier": "^3.6.2",
42
45
  "ts-jest": "^29.4.1",
46
+ "tsx": "^4.19.2",
43
47
  "typescript": "^5.9.2"
44
48
  },
45
49
  "dependencies": {