@gearbox-protocol/sdk 15.1.0-next.11 → 15.1.0-next.12

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 (54) hide show
  1. package/dist/cjs/dev/mode-parity/compareOpportunities.js +105 -0
  2. package/dist/cjs/dev/{comparePositions.js → mode-parity/comparePositions.js} +23 -46
  3. package/dist/cjs/dev/mode-parity/compareRules.js +93 -0
  4. package/dist/cjs/dev/{fieldDiff.js → mode-parity/fieldDiff.js} +49 -2
  5. package/dist/cjs/dev/mode-parity/scriptUtils.js +131 -0
  6. package/dist/cjs/model/compare.schema.js +33 -0
  7. package/dist/cjs/model/curators.schema.js +2 -1
  8. package/dist/cjs/model/index.js +5 -0
  9. package/dist/cjs/model/opportunities.schema.js +13 -12
  10. package/dist/cjs/model/positions.schema.js +15 -14
  11. package/dist/cjs/model/primitives.schema.js +2 -1
  12. package/dist/esm/common-utils/index.js +3 -3
  13. package/dist/esm/common-utils/utils/index.js +1 -1
  14. package/dist/esm/dev/AccountOpener.js +1 -1
  15. package/dist/esm/dev/{compareOpportunities.js → mode-parity/compareOpportunities.js} +14 -46
  16. package/dist/esm/dev/{comparePositions.js → mode-parity/comparePositions.js} +16 -39
  17. package/dist/esm/dev/mode-parity/compareRules.js +91 -0
  18. package/dist/esm/dev/{fieldDiff.js → mode-parity/fieldDiff.js} +49 -3
  19. package/dist/esm/dev/mode-parity/scriptUtils.js +121 -0
  20. package/dist/esm/dev/withdrawalUtils.js +1 -1
  21. package/dist/esm/model/compare.schema.js +29 -0
  22. package/dist/esm/model/curators.schema.js +2 -1
  23. package/dist/esm/model/index.js +2 -1
  24. package/dist/esm/model/opportunities.schema.js +13 -12
  25. package/dist/esm/model/positions.schema.js +15 -14
  26. package/dist/esm/model/primitives.schema.js +2 -1
  27. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  28. package/dist/esm/plugins/apy/ApyPlugin.js +2 -2
  29. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  30. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  31. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  32. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  33. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  34. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  35. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  36. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  37. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  38. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  39. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  40. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  41. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  42. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  43. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  44. package/dist/esm/sdk/pools/PoolService.js +1 -1
  45. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  46. package/dist/types/dev/{compareOpportunities.d.ts → mode-parity/compareOpportunities.d.ts} +5 -5
  47. package/dist/types/dev/{comparePositions.d.ts → mode-parity/comparePositions.d.ts} +5 -5
  48. package/dist/types/dev/mode-parity/compareRules.d.ts +33 -0
  49. package/dist/types/dev/{fieldDiff.d.ts → mode-parity/fieldDiff.d.ts} +47 -5
  50. package/dist/types/dev/mode-parity/scriptUtils.d.ts +47 -0
  51. package/dist/types/model/compare.schema.d.ts +47 -0
  52. package/dist/types/model/index.d.ts +2 -1
  53. package/package.json +1 -1
  54. package/dist/cjs/dev/compareOpportunities.js +0 -137
@@ -1,137 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_model_opportunities = require("../model/opportunities.js");
3
- require("../model/index.js");
4
- const require_dev_fieldDiff = require("./fieldDiff.js");
5
- //#region src/dev/compareOpportunities.ts
6
- /**
7
- * Matches two opportunity listings by {@link opportunityId} and reports every
8
- * field the two sources disagree on.
9
- *
10
- * Nothing is filtered out. A field only the backend can fill, or a USD value
11
- * that drifted within snapshot-lag noise, is still reported — tagged
12
- * {@link FieldDiff.expected} so that {@link CompareCounts.clean} can ignore it
13
- * while {@link CompareCounts.identical} stays strict.
14
- **/
15
- function compareOpportunities(input) {
16
- const onchainRows = indexById(input.onchain.data);
17
- const offchainRows = indexById(input.offchain.data);
18
- const onlyOnchain = [];
19
- const onlyOffchain = [];
20
- const matched = [];
21
- for (const [id, row] of onchainRows) {
22
- const counterpart = offchainRows.get(id);
23
- if (!counterpart) {
24
- onlyOnchain.push(toRef(row));
25
- continue;
26
- }
27
- const diffs = diffOpportunity(row, counterpart);
28
- matched.push({
29
- id,
30
- kind: row.kind,
31
- chainId: row.chainId,
32
- onchainName: row.name,
33
- offchainName: counterpart.name,
34
- identical: diffs.length === 0,
35
- clean: diffs.every((diff) => diff.expected),
36
- diffs
37
- });
38
- }
39
- for (const [id, row] of offchainRows) if (!onchainRows.has(id)) onlyOffchain.push(toRef(row));
40
- byId(onlyOnchain);
41
- byId(onlyOffchain);
42
- matched.sort((a, b) => a.id.localeCompare(b.id));
43
- return {
44
- generatedAt: input.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
45
- backendUrl: input.backendUrl,
46
- networks: [...input.networks],
47
- onchainChains: input.onchain.meta.chains,
48
- offchainChains: input.offchain.meta.chains,
49
- summary: summarize(input.onchain.data, input.offchain.data, onlyOnchain, onlyOffchain, matched),
50
- onlyOnchain,
51
- onlyOffchain,
52
- matched
53
- };
54
- }
55
- function indexById(rows) {
56
- return new Map(rows.map((row) => [require_model_opportunities.opportunityId(row), row]));
57
- }
58
- function byId(refs) {
59
- refs.sort((a, b) => a.id.localeCompare(b.id));
60
- }
61
- function toRef(row) {
62
- const base = {
63
- id: require_model_opportunities.opportunityId(row),
64
- kind: row.kind,
65
- chainId: row.chainId,
66
- name: row.name
67
- };
68
- return row.kind === "pool" ? {
69
- ...base,
70
- pool: row.pool
71
- } : {
72
- ...base,
73
- creditManager: row.creditManager,
74
- targetCollateral: row.targetCollateral.address
75
- };
76
- }
77
- /**
78
- * Every field two versions of one opportunity disagree on.
79
- **/
80
- function diffOpportunity(onchain, offchain) {
81
- return require_dev_fieldDiff.diffObjects(onchain, offchain).map((diff) => tagDiff(diff, onchain.kind));
82
- }
83
- /**
84
- * Paths whose values are basis-point rates that routinely differ by ±1 from
85
- * truncation vs rounding, plus pool `utilization` for the same reason.
86
- **/
87
- const BPS_RATE_PATHS = /* @__PURE__ */ new Set([
88
- "borrowApy",
89
- "supplyApy.organicApy",
90
- "additionalBorrowApy",
91
- "utilization"
92
- ]);
93
- /**
94
- * Amount fields whose bigint `value` moves with expected-liquidity accrual
95
- * between the backend's last sync and the current block. Strategy
96
- * `totalBorrow.value` and `maxBorrowAmount.value` are not in this set: those
97
- * disagreements are formula bugs, not lag.
98
- **/
99
- const LAG_AMOUNT_PATHS = /* @__PURE__ */ new Set(["totalSupply.value", "availableLiquidity.value"]);
100
- /**
101
- * Fields documented `@mode offchain` in the model: the chain has nothing to
102
- * put there, so a presence (or nested) mismatch is expected. Strategy
103
- * `utilization` is in this set; pool `utilization` is not.
104
- **/
105
- function isModeScoped(path, kind) {
106
- if (path === "curator.url") return true;
107
- if (path === "totalApy" || path.endsWith(".totalApy")) return true;
108
- if (path === "rewards" || path.startsWith("rewards[") || path.includes(".rewards[") || path.endsWith(".rewards")) return true;
109
- if (kind !== "strategy") return false;
110
- return path === "utilization" || path === "collateralApy" || path.startsWith("collateralApy.") || path === "maxLeverageApy" || path.startsWith("maxLeverageApy.") || path === "totalValue" || path.startsWith("totalValue.");
111
- }
112
- function tagDiff(diff, kind) {
113
- if (isModeScoped(diff.path, kind)) return require_dev_fieldDiff.withExpected(diff, "mode-scoped");
114
- if (withinTolerance(diff)) return require_dev_fieldDiff.withExpected(diff, "tolerance");
115
- return diff;
116
- }
117
- function withinTolerance(diff) {
118
- if (diff.kind === "usd") return require_dev_fieldDiff.isUsdWithinTolerance(diff.onchain, diff.offchain);
119
- if (diff.kind !== "numeric") return false;
120
- if (BPS_RATE_PATHS.has(diff.path)) return require_dev_fieldDiff.isBpsWithinTolerance(diff.onchain, diff.offchain);
121
- if (LAG_AMOUNT_PATHS.has(diff.path)) return require_dev_fieldDiff.isAmountWithinTolerance(diff.onchain, diff.offchain);
122
- return false;
123
- }
124
- function summarize(onchain, offchain, onlyOnchain, onlyOffchain, matched) {
125
- const byChain = require_dev_fieldDiff.union(onchain.map((row) => String(row.chainId)), offchain.map((row) => String(row.chainId))).map((chainId) => ({
126
- chainId: Number(chainId),
127
- ...require_dev_fieldDiff.toCompareCounts(onchain.filter((row) => String(row.chainId) === chainId).length, offchain.filter((row) => String(row.chainId) === chainId).length, onlyOnchain.filter((ref) => String(ref.chainId) === chainId).length, onlyOffchain.filter((ref) => String(ref.chainId) === chainId).length, matched.filter((match) => String(match.chainId) === chainId))
128
- })).sort((a, b) => a.chainId - b.chainId);
129
- return {
130
- ...require_dev_fieldDiff.toCompareCounts(onchain.length, offchain.length, onlyOnchain.length, onlyOffchain.length, matched),
131
- byChain,
132
- diffsByPath: require_dev_fieldDiff.countPaths(matched.flatMap((match) => match.diffs))
133
- };
134
- }
135
- //#endregion
136
- exports.compareOpportunities = compareOpportunities;
137
- exports.diffOpportunity = diffOpportunity;