diff --git a/package-lock.json b/package-lock.json index 1f6e41c..27fe871 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@clober/v2-sdk", - "version": "0.0.96", + "version": "0.0.97", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@clober/v2-sdk", - "version": "0.0.96", + "version": "0.0.97", "license": "MIT", "dependencies": { "axios": "^1.7.7", diff --git a/package.json b/package.json index 4b6fa36..9dd21e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@clober/v2-sdk", - "version": "0.0.96", + "version": "0.0.97", "description": "🛠 An SDK for building applications on top of Clober V2", "files": [ "dist" diff --git a/src/abis/rebalancer/strategy-abi.ts b/src/abis/rebalancer/strategy-abi.ts index bdf0309..1e584cc 100644 --- a/src/abis/rebalancer/strategy-abi.ts +++ b/src/abis/rebalancer/strategy-abi.ts @@ -1,4 +1,28 @@ export const STRATEGY_ABI = [ + { + inputs: [ + { + internalType: 'bytes32', + name: 'key', + type: 'bytes32', + }, + ], + name: 'getLastAmount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, { inputs: [ { @@ -472,30 +496,6 @@ export const STRATEGY_ABI = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'bytes32', - name: 'key', - type: 'bytes32', - }, - ], - name: 'getLastRawAmount', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, { inputs: [ { diff --git a/src/apis/strategy.ts b/src/apis/strategy.ts index 6df45ac..4c66398 100644 --- a/src/apis/strategy.ts +++ b/src/apis/strategy.ts @@ -2,7 +2,7 @@ import { formatUnits, PublicClient } from 'viem' import { CHAIN_IDS } from '../constants/chain' import { CONTRACT_ADDRESSES } from '../constants/addresses' -import { LastRawAmounts, Market, StrategyPosition } from '../type' +import { LastAmounts, Market, StrategyPosition } from '../type' import { STRATEGY_ABI } from '../abis/rebalancer/strategy-abi' import { toPoolKey } from '../utils/pool-key' @@ -47,14 +47,14 @@ export async function fetchStrategyPosition( } } -export async function fetchLastRawAmounts( +export async function fetchLastAmounts( publicClient: PublicClient, chainId: CHAIN_IDS, tokenAddresses: `0x${string}`[], salt: `0x${string}`, useSubgraph: boolean, market?: Market, -): Promise { +): Promise { let poolKey: `0x${string}` | undefined = undefined if (market) { poolKey = toPoolKey( @@ -72,14 +72,14 @@ export async function fetchLastRawAmounts( ) poolKey = pool.key } - const getLastRawAmount = await publicClient.readContract({ + const getLastAmount = await publicClient.readContract({ address: CONTRACT_ADDRESSES[chainId]!.Strategy, abi: STRATEGY_ABI, - functionName: 'getLastRawAmount', + functionName: 'getLastAmount', args: [poolKey], }) return { - lastRawAmountA: BigInt(getLastRawAmount[0]), - lastRawAmountB: BigInt(getLastRawAmount[1]), + lastAmountA: BigInt(getLastAmount[0]), + lastAmountB: BigInt(getLastAmount[1]), } } diff --git a/src/type.ts b/src/type.ts index f8ca19b..8c95cba 100644 --- a/src/type.ts +++ b/src/type.ts @@ -21,9 +21,9 @@ export type Book = { isOpened: boolean } -export type LastRawAmounts = { - lastRawAmountA: bigint - lastRawAmountB: bigint +export type LastAmounts = { + lastAmountA: bigint + lastAmountB: bigint } export type StrategyPosition = { diff --git a/src/view.ts b/src/view.ts index ea7d655..9507692 100644 --- a/src/view.ts +++ b/src/view.ts @@ -16,7 +16,7 @@ import type { DefaultReadContractOptions, ElectionGovernorMetadata, ElectionRoundData, - LastRawAmounts, + LastAmounts, Market, Pool, PoolPerformanceData, @@ -37,7 +37,7 @@ import { CONTRACT_ADDRESSES } from './constants/addresses' import { invertTick, toPrice } from './utils/tick' import { MAX_TICK, MIN_TICK } from './constants/tick' import { fetchPool, fetchPoolPerformance } from './apis/pool' -import { fetchLastRawAmounts, fetchStrategyPosition } from './apis/strategy' +import { fetchLastAmounts, fetchStrategyPosition } from './apis/strategy' import { Subgraph } from './constants/subgraph' import { fillAndSortByTimestamp } from './utils/time-series' import { @@ -397,7 +397,7 @@ export const getStrategyPrice = async ({ ) } -export const getLastRawAmounts = async ({ +export const getLastAmounts = async ({ chainId, token0, token1, @@ -412,7 +412,7 @@ export const getLastRawAmounts = async ({ market?: Market useSubgraph?: boolean } -}): Promise => { +}): Promise => { if (isAddressEqual(token0, token1)) { throw new Error('Token0 and token1 must be different') } @@ -420,7 +420,7 @@ export const getLastRawAmounts = async ({ chain: CHAIN_MAP[chainId], transport: options?.rpcUrl ? http(options.rpcUrl) : http(), }) - return fetchLastRawAmounts( + return fetchLastAmounts( publicClient, chainId, [token0, token1],