Skip to content

Commit

Permalink
Merge pull request #83 from Premian-Labs/issue/remove-cache
Browse files Browse the repository at this point in the history
Completely remove cache
  • Loading branch information
froggiedev committed Dec 11, 2023
2 parents e629718 + 28c571d commit 7e9fbb0
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 327 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@premia/v3-sdk",
"version": "1.3.3",
"version": "2.0.0",
"description": "The official SDK for building applications on Premia V3.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
6 changes: 0 additions & 6 deletions src/api/analyticsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { BaseAPI } from './baseAPI'
import { withCache } from '../cache'
import { CacheTTL } from '../constants'
import { VaultDayData } from '../entities'

/**
Expand All @@ -13,9 +11,6 @@ export class AnalyticsAPI extends BaseAPI {
/**
* Retrieves daily data for a specific vault using its address.
*
* This function is cached, meaning that if it is called multiple times within a one minute period,
* it will only perform the operation once and then return the cached result for subsequent calls.
*
* @param {string} vaultAddress - The address of the vault for which daily data should be retrieved.
* @param {number} [startTime=0] - The timestamp (in seconds) from when the data should start being retrieved (default is 0).
* @param {number} [first=1000] - The maximum number of data points to return (default is 1000).
Expand All @@ -24,7 +19,6 @@ export class AnalyticsAPI extends BaseAPI {
* @returns {Promise<VaultDayData[]>} A promise that resolves to an array of VaultDayData objects, containing
* daily information about the vault at the specified address.
*/
@withCache(CacheTTL.MINUTE)
async getVaultDayData(
vaultAddress: string,
startTime = 0,
Expand Down
9 changes: 1 addition & 8 deletions src/api/optionAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BigNumberish, toBigInt } from 'ethers'
import { get, isEqual } from 'lodash'

import { withCache } from '../cache'
import { CacheTTL, WAD_DECIMALS, ZERO_BI } from '../constants'
import { WAD_DECIMALS, ZERO_BI } from '../constants'
import { FillableQuote, PoolMinimal, Token } from '../entities'
import { BaseAPI } from './baseAPI'
import { TokenOrAddress } from './tokenAPI'
Expand Down Expand Up @@ -225,7 +224,6 @@ export class OptionAPI extends BaseAPI {

/**
* Provides the best quote available from different sources (RFQ, Pool, Vault) based on the provided options.
* The method is cached for a second to improve performance.
*
* @param {Object} options - Quote options object.
* @param {string} options.poolAddress - The pool's address.
Expand All @@ -241,7 +239,6 @@ export class OptionAPI extends BaseAPI {
* @param {boolean} [options.showVaultErrors] - Whether to show vault errors (optional).
* @returns {Promise<FillableQuote | null>} - A promise that resolves to the best quote.
*/
@withCache(CacheTTL.SECOND)
async quote(options: {
poolAddress: string
size: BigNumberish
Expand Down Expand Up @@ -323,7 +320,6 @@ export class OptionAPI extends BaseAPI {

/**
* Provides the best quotes available for each pool that matches the provided options.
* The method is cached for a second to improve performance.
*
* @param {Object} options - Multi-quote options object.
* @param {TokenOrAddress} options.token - The token object or address.
Expand All @@ -339,7 +335,6 @@ export class OptionAPI extends BaseAPI {
* @param {string} [options.taker] - The address of the taker (optional).
* @returns {Promise<(FillableQuote | null)[]>} - A promise that resolves to an array of the best quotes.
*/
@withCache(CacheTTL.SECOND)
async multiQuote(options: {
token: TokenOrAddress
strike: BigNumberish
Expand Down Expand Up @@ -385,7 +380,6 @@ export class OptionAPI extends BaseAPI {

/**
* Provides the best quotes available from each provider (RFQ, Pool, Vault) for each pool that matches the provided options.
* The method is cached for a second to improve performance.
*
* @param {Object} options - Quotes by provider options object.
* @param {TokenOrAddress} options.token - The token object or address.
Expand All @@ -401,7 +395,6 @@ export class OptionAPI extends BaseAPI {
* @param {string} [options.taker] - The address of the taker (optional).
* @returns {Promise<{ [provider: string]: (FillableQuote | null)[] }>} - A promise that resolves to an object where each key is a provider and the value is an array of the best quotes.
*/
@withCache(CacheTTL.SECOND)
async quotesByProvider(options: {
token: TokenOrAddress
strike: BigNumberish
Expand Down
4 changes: 1 addition & 3 deletions src/api/ordersAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import {
import { isEqual } from 'lodash'

import { BaseAPI } from './baseAPI'
import { withCache } from '../cache'
import { convertDecimals, signData } from '../utils'
import { Addresses, CacheTTL, WAD_BI, WAD_DECIMALS } from '../constants'
import { Addresses, WAD_BI, WAD_DECIMALS } from '../constants'
import {
EIP712Domain,
FillableQuote,
Expand Down Expand Up @@ -210,7 +209,6 @@ export class OrdersAPI extends BaseAPI {
* @param {string} [taker] - The address of the taker (optional).
* @returns {Promise<FillableQuote | null>} - The best fillable quote, or null if no quotes available.
*/
@withCache(CacheTTL.SECOND)
async quote(
poolAddress: string,
size: BigNumberish,
Expand Down
37 changes: 9 additions & 28 deletions src/api/poolAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ZeroAddress,
} from 'ethers'

import { withCache } from '../cache'
import {
AdapterType,
FillableQuote,
Expand All @@ -25,14 +24,7 @@ import {
Token,
TokenType,
} from '../entities'
import {
Addresses,
CacheTTL,
Fees,
WAD_BI,
WAD_DECIMALS,
ZERO_BI,
} from '../constants'
import { Addresses, Fees, WAD_BI, WAD_DECIMALS, ZERO_BI } from '../constants'
import { Position } from '@premia/v3-abi/typechain/IPool'
import { BaseAPI } from './baseAPI'
import { convertDecimals, formatTokenId, sendTransaction } from '../utils'
Expand Down Expand Up @@ -485,7 +477,6 @@ export class PoolAPI extends BaseAPI {
* @param {number} [maxSlippagePercent] - The maximum slippage percent.
* @returns {Promise<FillableQuote>} A promise that resolves to the fillable quote.
*/
@withCache(CacheTTL.SECOND)
async quote(
poolAddress: string,
size: BigNumberish,
Expand Down Expand Up @@ -653,7 +644,6 @@ export class PoolAPI extends BaseAPI {
* @param key {PoolKey} The relevant PoolKey.
* @returns {Promise<PoolMinimal>} Promise containing PoolMinimal.
*/
@withCache(CacheTTL.DAILY)
async getPoolMinimalFromKey(key: PoolKey): Promise<PoolMinimal> {
const address = await this.getPoolAddress(key)

Expand Down Expand Up @@ -714,53 +704,48 @@ export class PoolAPI extends BaseAPI {
* @param address {string} The relevant contract address.
* @returns {Promise<PoolMinimal>} Promise containing PoolMinimal.
*/
@withCache(CacheTTL.DAILY)
async getPoolMinimal(address: string): Promise<PoolMinimal> {
return this.premia.subgraph.getPoolMinimal(address)
}

/**
* Retrieves the pool information given its address. Cached daily.
* Retrieves the pool information given its address.
*
* @param {string} address - The address of the pool.
* @returns {Promise<Pool>} A promise that resolves to a `Pool` object.
*/
@withCache(CacheTTL.DAILY)
async getPool(address: string): Promise<Pool> {
return this.premia.subgraph.getPool(address)
}

/**
* Retrieves extended pool information given its address. Cached per minute.
* Retrieves extended pool information given its address.
*
* @param {string} address - The address of the Pool contract.
* @returns {Promise<PoolExtended>} A promise that resolves to a `PoolExtended` objects.
*/
@withCache(CacheTTL.MINUTE)
async getPoolExtended(address: string): Promise<PoolExtended> {
return this.premia.subgraph.getPoolExtended(address)
}

/**
* Retrieves pools based on the base address. Cached daily.
* Retrieves pools based on the base address.
*
* @param {string} baseAddress - The address of the base token.
* @param {boolean} isExpired - A filter for [non-] expired pools.
* @returns {Promise<Pool[]>} A promise that resolves to an array of `Pool` objects.
*/
@withCache(CacheTTL.DAILY)
async getPools(baseAddress: string, isExpired?: boolean): Promise<Pool[]> {
return this.premia.subgraph.getPools(baseAddress, isExpired)
}

/**
* Retrieves extended pools based on the base address. Cached daily.
* Retrieves extended pools based on the base address.
*
* @param {string} baseAddress - The address of the base token.
* @param {boolean} isExpired - A filter for [non-] expired pools.
* @returns {Promise<PoolExtended[]>} A promise that resolves to an array of `PoolExtended` objects.
*/
@withCache(CacheTTL.MINUTE)
async getPoolsExtended(
baseAddress: string,
isExpired?: boolean
Expand All @@ -769,13 +754,12 @@ export class PoolAPI extends BaseAPI {
}

/**
* Retrieves pools for a given token. Cached daily.
* Retrieves pools for a given token.
*
* @param {Token} token - The token information.
* @param {boolean} [isQuote=false] - A flag to indicate if the token is quote token.
* @returns {Promise<Pool[]>} A promise that resolves to an array of `Pool` objects.
*/
@withCache(CacheTTL.DAILY)
async getPoolsForToken(
token: Token,
isQuote: boolean = false
Expand All @@ -784,13 +768,12 @@ export class PoolAPI extends BaseAPI {
}

/**
* Retrieves extended pools for a given token. Cached per minute.
* Retrieves extended pools for a given token.
*
* @param {Token} token - The token information.
* @param {boolean} [isQuote=false] - A flag to indicate if the token is quote token.
* @returns {Promise<PoolExtended[]>} A promise that resolves to an array of `PoolExtended` objects.
*/
@withCache(CacheTTL.MINUTE)
async getPoolsExtendedForToken(
token: Token,
isQuote: boolean = false
Expand All @@ -799,13 +782,12 @@ export class PoolAPI extends BaseAPI {
}

/**
* Retrieves pools for a given token pair. Cached daily.
* Retrieves pools for a given token pair.
*
* @param {TokenPairOrId} pair - The token pair or pair id.
* @param {boolean} isExpired - A filter for [non-] expired pools.
* @returns {Promise<Pool[]>} A promise that resolves to an array of `Pool` objects.
*/
@withCache(CacheTTL.DAILY)
async getPoolsForPair(
pair: TokenPairOrId,
isExpired?: boolean
Expand All @@ -814,13 +796,12 @@ export class PoolAPI extends BaseAPI {
}

/**
* Retrieves extended pools for a given token pair. Cached per minute.
* Retrieves extended pools for a given token pair.
*
* @param {TokenPairOrId} pair - The token pair or pair id.
* @param {boolean} isExpired - A filter for [non-] expired pools.
* @returns {Promise<PoolExtended[]>} A promise that resolves to an array of `PoolExtended` objects.
*/
@withCache(CacheTTL.MINUTE)
async getPoolsExtendedForPair(
pair: TokenPairOrId,
isExpired?: boolean
Expand Down
12 changes: 1 addition & 11 deletions src/api/tokenAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TokenInfo } from '@premia/pair-lists/src/types'

import { withCache } from '../cache'
import { Token, TokenExtended, TokenMinimal } from '../entities'
import { Addresses, CacheTTL, WAD_DECIMALS } from '../constants'
import { Addresses, WAD_DECIMALS } from '../constants'
import { BaseAPI } from './baseAPI'
import { CoingeckoTokenId } from '../services'
import { parseBigInt } from '../utils'
Expand Down Expand Up @@ -42,15 +41,13 @@ export class TokenAPI extends BaseAPI {
*
* This function retrieves the spot price for a given token from the underlying data source.
* If the token's USD price is not available, an error is thrown.
* This function is cached for a minute to prevent frequent API calls.
*
* @param {string} address - The address of the token for which to fetch the spot price.
*
* @returns {Promise<bigint>} A promise that resolves to the spot price of the token in USD.
*
* @throws {Error} An error if the USD price for the token is not found.
*/
@withCache(CacheTTL.MINUTE)
async getSpotPrice(address: string): Promise<bigint> {
const token = await this.getToken(address)

Expand All @@ -70,7 +67,6 @@ export class TokenAPI extends BaseAPI {
*
* @returns {Promise<TokenMinimal>} A promise that resolves to an object containing the token's address, symbol, and decimals.
*/
@withCache()
async getTokenMinimal(address: string): Promise<TokenMinimal> {
const tokenContract = this.premia.contracts.getTokenContract(
address,
Expand Down Expand Up @@ -98,7 +94,6 @@ export class TokenAPI extends BaseAPI {
*
* @throws Will throw an error if the token information cannot be fetched from either the subgraph, coingecko, or token contract.
*/
@withCache(CacheTTL.HOURLY)
async getToken(address: string): Promise<Token> {
if (!this.premia.skipSubgraph) {
try {
Expand Down Expand Up @@ -215,7 +210,6 @@ export class TokenAPI extends BaseAPI {
*
* @returns {Promise<TokenExtended>} A promise that resolves to an object containing the extended information of the token.
*/
@withCache(CacheTTL.MINUTE)
async getTokenExtended(address: string): Promise<TokenExtended> {
return this.premia.subgraph.getTokenExtended(address)
}
Expand All @@ -231,7 +225,6 @@ export class TokenAPI extends BaseAPI {
*
* @returns {Promise<Token[]>} A promise that resolves to an array containing the information of the tokens.
*/
@withCache(CacheTTL.HOURLY)
async getTokens(tokens: string[]): Promise<Token[]> {
if (!this.premia.skipSubgraph) {
try {
Expand Down Expand Up @@ -261,7 +254,6 @@ export class TokenAPI extends BaseAPI {
* @returns {Promise<TokenExtended[]>} A promise that resolves to an array containing the extended
* information of the specified tokens.
*/
@withCache(CacheTTL.MINUTE)
async getTokensExtended(tokens: string[]): Promise<TokenExtended[]> {
return this.premia.subgraph.getTokensExtended(tokens)
}
Expand All @@ -279,7 +271,6 @@ export class TokenAPI extends BaseAPI {
*
* @throws Will throw an error if the subgraph fails to load.
*/
@withCache(CacheTTL.HOURLY)
async getTokenList(tokenList: TokenInfo[]): Promise<Token[]> {
if (!this.premia.skipSubgraph) {
try {
Expand Down Expand Up @@ -315,7 +306,6 @@ export class TokenAPI extends BaseAPI {
*
* @returns {Promise<TokenExtended[]>} A promise that resolves to an array containing the extended information of the specified tokens.
*/
@withCache(CacheTTL.MINUTE)
async getTokenListExtended(tokenList: TokenInfo[]): Promise<TokenExtended[]> {
return this.premia.subgraph.getTokenListExtended(tokenList)
}
Expand Down

0 comments on commit 7e9fbb0

Please sign in to comment.