@curvefi/llamalend-api 1.0.31 → 1.0.32

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.
package/README.md CHANGED
@@ -891,6 +891,45 @@ import llamalend from "@curvefi/llamalend-api";
891
891
  })()
892
892
  ```
893
893
 
894
+ ### Force Update User State for lendMarket
895
+
896
+ After executing certain transactions, it's recommended to force update the user's state in the cache to ensure data consistency:
897
+
898
+ ```ts
899
+ // Methods after which you should call forceUpdateUserState:
900
+ // - createLoan()
901
+ // - leverage.createLoan()
902
+ // - borrowMore()
903
+ // - partialSelfLiquidate()
904
+ // - repay()
905
+
906
+ // Basic usage (after successful transaction):
907
+ const txHash = await lendMarket.createLoan(0.5, 1000, 5);
908
+ // Wait for transaction to be mined and confirmed
909
+ await lendMarket.forceUpdateUserState(txHash);
910
+
911
+ // With specific user address:
912
+ await lendMarket.forceUpdateUserState(txHash, "0x123...");
913
+
914
+ // The method sends a request with new_tx parameter and clears the cache
915
+ // to get fresh user state data
916
+ // Important: Only call after successful transaction confirmation
917
+ ```
918
+
919
+ **Why use forceUpdateUserState?**
920
+ - Ensures data consistency after successful transactions
921
+ - Clears cached user state data
922
+ - Forces fresh API request with transaction hash
923
+ - Prevents stale data issues
924
+ - **Important**: Only call after transaction is successfully mined and confirmed
925
+
926
+ **When to use:**
927
+ - After `createLoan()` - when creating a new loan
928
+ - After `leverage.createLoan()` - when creating a leveraged position
929
+ - After `borrowMore()` - when increasing loan amount
930
+ - After `partialSelfLiquidate()` - when partially liquidating position
931
+ - After `repay()` - when repaying loan
932
+
894
933
  ### User loss for lendMarket
895
934
  ```ts
896
935
  (async () => {
@@ -2360,4 +2399,5 @@ import llamalend from "@curvefi/llamalend-api";
2360
2399
  //
2361
2400
  // '50': [ '759.898822708156242647', '1560.282492846180089068' ]
2362
2401
  // }
2363
- ```
2402
+ ```
2403
+
@@ -11,6 +11,7 @@ type UserCollateral = {
11
11
  total_deposit_from_user_usd_value: number;
12
12
  };
13
13
  export declare const _getUserCollateral: ((network: INetworkName, controller: string, user: string) => Promise<UserCollateral>) & memoize.Memoized<(network: INetworkName, controller: string, user: string) => Promise<UserCollateral>>;
14
+ export declare const _getUserCollateralForce: (network: INetworkName, controller: string, user: string, newTx: string) => Promise<void>;
14
15
  export declare const _getUserCollateralCrvUsd: ((network: INetworkName, controller: string, user: string) => Promise<string>) & memoize.Memoized<(network: INetworkName, controller: string, user: string) => Promise<string>>;
15
16
  export declare const _getMarketsData: ((network: INetworkName) => Promise<IMarketData>) & memoize.Memoized<(network: INetworkName) => Promise<IMarketData>>;
16
17
  export declare function _getQuoteOdos(this: Llamalend, fromToken: string, toToken: string, _amount: bigint, blacklist: string, pathVizImage: boolean, slippage?: number): Promise<IQuoteOdos>;
@@ -124,6 +124,10 @@ export const _getUserCollateral = memoize((network, controller, user) => __await
124
124
  promise: true,
125
125
  maxAge: 60 * 1000, // 1m
126
126
  });
127
+ export const _getUserCollateralForce = (network, controller, user, newTx) => __awaiter(void 0, void 0, void 0, function* () {
128
+ yield fetch(`https://prices.curve.finance/v1/lending/collateral_events/${network}/${controller}/${user}?new_tx=${newTx}`);
129
+ _getUserCollateral.delete(network, controller, user);
130
+ });
127
131
  export const _getUserCollateralCrvUsd = memoize((network, controller, user) => __awaiter(void 0, void 0, void 0, function* () {
128
132
  const url = `https://prices.curve.finance/v1/crvusd/collateral_events/${network}/${controller}/${user}`;
129
133
  const response = yield fetch(url);
@@ -519,4 +519,5 @@ export declare class LendMarketTemplate {
519
519
  currentLeverage(userAddress?: string): Promise<string>;
520
520
  currentPnL(userAddress?: string): Promise<Record<string, string>>;
521
521
  userBoost(address?: string): Promise<string>;
522
+ forceUpdateUserState(newTx: string, userAddress?: string): Promise<void>;
522
523
  }
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import memoize from "memoizee";
11
11
  import BigNumber from "bignumber.js";
12
12
  import { _getAddress, parseUnits, BN, toBN, fromBN, getBalances, _ensureAllowance, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, _cutZeros, formatUnits, formatNumber, MAX_ALLOWANCE, MAX_ACTIVE_BAND, _mulBy1_3, _getUsdRate, DIGas, smartNumber, } from "../utils.js";
13
- import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getMarketsData } from "../external-api.js";
13
+ import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getUserCollateralForce, _getMarketsData } from "../external-api.js";
14
14
  import ERC20Abi from '../constants/abis/ERC20.json' with { type: 'json' };
15
15
  import { cacheKey, cacheStats } from "../cache/index.js";
16
16
  const DAY = 86400;
@@ -2799,4 +2799,12 @@ export class LendMarketTemplate {
2799
2799
  return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
2800
2800
  });
2801
2801
  }
2802
+ forceUpdateUserState(newTx, userAddress) {
2803
+ return __awaiter(this, void 0, void 0, function* () {
2804
+ const address = userAddress || this.llamalend.signerAddress;
2805
+ if (!address)
2806
+ throw Error("Need to connect wallet or pass address into args");
2807
+ yield _getUserCollateralForce(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, address, newTx);
2808
+ });
2809
+ }
2802
2810
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -136,6 +136,17 @@ export const _getUserCollateral = memoize(
136
136
  }
137
137
  )
138
138
 
139
+ export const _getUserCollateralForce = async (
140
+ network: INetworkName,
141
+ controller: string,
142
+ user: string,
143
+ newTx: string
144
+ ): Promise<void> => {
145
+ await fetch(`https://prices.curve.finance/v1/lending/collateral_events/${network}/${controller}/${user}?new_tx=${newTx}`);
146
+
147
+ _getUserCollateral.delete(network, controller, user);
148
+ }
149
+
139
150
  export const _getUserCollateralCrvUsd = memoize(
140
151
  async (network: INetworkName, controller: string, user: string): Promise<string> => {
141
152
  const url = `https://prices.curve.finance/v1/crvusd/collateral_events/${network}/${controller}/${user}`;
@@ -23,7 +23,7 @@ import {
23
23
  smartNumber,
24
24
  } from "../utils.js";
25
25
  import {IDict, TGas, TAmount, IReward, IQuoteOdos, IOneWayMarket, IPartialFrac} from "../interfaces.js";
26
- import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getMarketsData } from "../external-api.js";
26
+ import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getUserCollateralForce, _getMarketsData } from "../external-api.js";
27
27
  import ERC20Abi from '../constants/abis/ERC20.json' with {type: 'json'};
28
28
  import {cacheKey, cacheStats} from "../cache/index.js";
29
29
 
@@ -3160,4 +3160,16 @@ export class LendMarketTemplate {
3160
3160
 
3161
3161
  return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
3162
3162
  }
3163
+
3164
+ public async forceUpdateUserState(newTx: string, userAddress?: string): Promise<void> {
3165
+ const address = userAddress || this.llamalend.signerAddress;
3166
+ if (!address) throw Error("Need to connect wallet or pass address into args");
3167
+
3168
+ await _getUserCollateralForce(
3169
+ this.llamalend.constants.NETWORK_NAME,
3170
+ this.addresses.controller,
3171
+ address,
3172
+ newTx
3173
+ );
3174
+ }
3163
3175
  }