@hypurrquant/defi-cli 1.0.6 → 1.0.8

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.
@@ -4189,6 +4189,79 @@ var init_dist2 = __esm({
4189
4189
  gas_estimate: 3e5
4190
4190
  };
4191
4191
  }
4192
+ /**
4193
+ * List every LB pair from the factory with basic pair info (no rewarder /
4194
+ * APR enrichment). Useful when the factory has pools but none have hooks
4195
+ * deployed yet (e.g. early-stage Monad TraderJoe).
4196
+ *
4197
+ * Three multicall batches: pair addresses, token addresses, token symbols.
4198
+ */
4199
+ async discoverAllPools() {
4200
+ const rpcUrl = this.requireRpc();
4201
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
4202
+ const pairCount = await client.readContract({
4203
+ address: this.lbFactory,
4204
+ abi: lbFactoryAbi,
4205
+ functionName: "getNumberOfLBPairs"
4206
+ });
4207
+ const count = Number(pairCount);
4208
+ if (count === 0) return [];
4209
+ const indexCalls = Array.from({ length: count }, (_, i) => [
4210
+ this.lbFactory,
4211
+ encodeFunctionData12({ abi: lbFactoryAbi, functionName: "getLBPairAtIndex", args: [BigInt(i)] })
4212
+ ]);
4213
+ const indexResults = await multicallRead(rpcUrl, indexCalls);
4214
+ const pairs = indexResults.map((r) => decodeAddressResult(r)).filter((a) => a !== null);
4215
+ if (pairs.length === 0) return [];
4216
+ const tokenCalls = [];
4217
+ for (const pool of pairs) {
4218
+ tokenCalls.push([pool, encodeFunctionData12({ abi: lbPairAbi, functionName: "getTokenX" })]);
4219
+ tokenCalls.push([pool, encodeFunctionData12({ abi: lbPairAbi, functionName: "getTokenY" })]);
4220
+ }
4221
+ const tokenResults = await multicallRead(rpcUrl, tokenCalls);
4222
+ const tokensX = [];
4223
+ const tokensY = [];
4224
+ for (let i = 0; i < pairs.length; i++) {
4225
+ tokensX.push(decodeAddressResult(tokenResults[i * 2] ?? null));
4226
+ tokensY.push(decodeAddressResult(tokenResults[i * 2 + 1] ?? null));
4227
+ }
4228
+ const uniqueTokens = Array.from(
4229
+ new Set([...tokensX, ...tokensY].filter((a) => a !== null))
4230
+ );
4231
+ const symbolCalls = uniqueTokens.map((t) => [
4232
+ t,
4233
+ encodeFunctionData12({ abi: erc20Abi2, functionName: "symbol" })
4234
+ ]);
4235
+ const symbolResults = await multicallRead(rpcUrl, symbolCalls);
4236
+ const symbolMap = /* @__PURE__ */ new Map();
4237
+ for (let i = 0; i < uniqueTokens.length; i++) {
4238
+ const raw = symbolResults[i];
4239
+ if (!raw) continue;
4240
+ try {
4241
+ const sym = decodeFunctionResult4({
4242
+ abi: parseAbi12(["function f() external view returns (string)"]),
4243
+ functionName: "f",
4244
+ data: raw
4245
+ });
4246
+ symbolMap.set(uniqueTokens[i].toLowerCase(), sym);
4247
+ } catch {
4248
+ }
4249
+ }
4250
+ const out = [];
4251
+ for (let i = 0; i < pairs.length; i++) {
4252
+ const tx = tokensX[i];
4253
+ const ty = tokensY[i];
4254
+ if (!tx || !ty) continue;
4255
+ out.push({
4256
+ pool: pairs[i],
4257
+ tokenX: tx,
4258
+ tokenY: ty,
4259
+ symbolX: symbolMap.get(tx.toLowerCase()) ?? "?",
4260
+ symbolY: symbolMap.get(ty.toLowerCase()) ?? "?"
4261
+ });
4262
+ }
4263
+ return out;
4264
+ }
4192
4265
  /**
4193
4266
  * Discover all active rewarded LB pools by iterating the factory.
4194
4267
  * Uses 7 multicall batches to minimise RPC round-trips and avoid 429s.
@@ -5734,6 +5807,7 @@ var init_dist2 = __esm({
5734
5807
  "function borrowBalanceStored(address account) external view returns (uint256)",
5735
5808
  "function mint(uint256 mintAmount) external returns (uint256)",
5736
5809
  "function redeem(uint256 redeemTokens) external returns (uint256)",
5810
+ "function redeemUnderlying(uint256 redeemAmount) external returns (uint256)",
5737
5811
  "function borrow(uint256 borrowAmount) external returns (uint256)",
5738
5812
  "function repayBorrow(uint256 repayAmount) external returns (uint256)"
5739
5813
  ]);
@@ -5776,57 +5850,55 @@ var init_dist2 = __esm({
5776
5850
  name() {
5777
5851
  return this.protocolName;
5778
5852
  }
5853
+ // Resolve the vToken whose underlying() matches params.asset. Compound V2 has
5854
+ // a separate vToken per asset, so all builders must dispatch on the request
5855
+ // asset. Returns the resolved vToken or throws if no candidate matches.
5856
+ async vtokenFor(asset) {
5857
+ const v = await this.resolveVtoken(asset);
5858
+ if (!v) throw DefiError.contractError(`[${this.protocolName}] no vToken for asset ${asset}`);
5859
+ return v;
5860
+ }
5779
5861
  async buildSupply(params) {
5780
- const data = encodeFunctionData16({
5781
- abi: CTOKEN_ABI,
5782
- functionName: "mint",
5783
- args: [params.amount]
5784
- });
5862
+ const vtoken = await this.vtokenFor(params.asset);
5863
+ const data = encodeFunctionData16({ abi: CTOKEN_ABI, functionName: "mint", args: [params.amount] });
5785
5864
  return {
5786
- description: `[${this.protocolName}] Supply ${params.amount} to Venus`,
5787
- to: this.defaultVtoken,
5865
+ description: `[${this.protocolName}] Supply ${params.amount} of ${params.asset} to Venus`,
5866
+ to: vtoken,
5788
5867
  data,
5789
5868
  value: 0n,
5790
- gas_estimate: 3e5
5869
+ gas_estimate: 3e5,
5870
+ approvals: [{ token: params.asset, spender: vtoken, amount: params.amount }]
5791
5871
  };
5792
5872
  }
5793
5873
  async buildBorrow(params) {
5794
- const data = encodeFunctionData16({
5795
- abi: CTOKEN_ABI,
5796
- functionName: "borrow",
5797
- args: [params.amount]
5798
- });
5874
+ const vtoken = await this.vtokenFor(params.asset);
5875
+ const data = encodeFunctionData16({ abi: CTOKEN_ABI, functionName: "borrow", args: [params.amount] });
5799
5876
  return {
5800
- description: `[${this.protocolName}] Borrow ${params.amount} from Venus`,
5801
- to: this.defaultVtoken,
5877
+ description: `[${this.protocolName}] Borrow ${params.amount} of ${params.asset} from Venus`,
5878
+ to: vtoken,
5802
5879
  data,
5803
5880
  value: 0n,
5804
5881
  gas_estimate: 35e4
5805
5882
  };
5806
5883
  }
5807
5884
  async buildRepay(params) {
5808
- const data = encodeFunctionData16({
5809
- abi: CTOKEN_ABI,
5810
- functionName: "repayBorrow",
5811
- args: [params.amount]
5812
- });
5885
+ const vtoken = await this.vtokenFor(params.asset);
5886
+ const data = encodeFunctionData16({ abi: CTOKEN_ABI, functionName: "repayBorrow", args: [params.amount] });
5813
5887
  return {
5814
- description: `[${this.protocolName}] Repay ${params.amount} to Venus`,
5815
- to: this.defaultVtoken,
5888
+ description: `[${this.protocolName}] Repay ${params.amount} of ${params.asset} to Venus`,
5889
+ to: vtoken,
5816
5890
  data,
5817
5891
  value: 0n,
5818
- gas_estimate: 3e5
5892
+ gas_estimate: 3e5,
5893
+ approvals: [{ token: params.asset, spender: vtoken, amount: params.amount }]
5819
5894
  };
5820
5895
  }
5821
5896
  async buildWithdraw(params) {
5822
- const data = encodeFunctionData16({
5823
- abi: CTOKEN_ABI,
5824
- functionName: "redeem",
5825
- args: [params.amount]
5826
- });
5897
+ const vtoken = await this.vtokenFor(params.asset);
5898
+ const data = encodeFunctionData16({ abi: CTOKEN_ABI, functionName: "redeemUnderlying", args: [params.amount] });
5827
5899
  return {
5828
- description: `[${this.protocolName}] Withdraw from Venus`,
5829
- to: this.defaultVtoken,
5900
+ description: `[${this.protocolName}] Withdraw ${params.amount} of ${params.asset} from Venus`,
5901
+ to: vtoken,
5830
5902
  data,
5831
5903
  value: 0n,
5832
5904
  gas_estimate: 25e4