Skip to content

Commit

Permalink
Merge pull request #154 from clober-dex/fix/remove-raw
Browse files Browse the repository at this point in the history
Fix/remove raw
  • Loading branch information
graykode authored Feb 3, 2025
2 parents d0d22a8 + 54a11b2 commit b9c2f2a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
48 changes: 24 additions & 24 deletions src/abis/rebalancer/strategy-abi.ts
Original file line number Diff line number Diff line change
@@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down
14 changes: 7 additions & 7 deletions src/apis/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<LastRawAmounts> {
): Promise<LastAmounts> {
let poolKey: `0x${string}` | undefined = undefined
if (market) {
poolKey = toPoolKey(
Expand All @@ -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]),
}
}
6 changes: 3 additions & 3 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 5 additions & 5 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
DefaultReadContractOptions,
ElectionGovernorMetadata,
ElectionRoundData,
LastRawAmounts,
LastAmounts,
Market,
Pool,
PoolPerformanceData,
Expand All @@ -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 {
Expand Down Expand Up @@ -397,7 +397,7 @@ export const getStrategyPrice = async ({
)
}

export const getLastRawAmounts = async ({
export const getLastAmounts = async ({
chainId,
token0,
token1,
Expand All @@ -412,15 +412,15 @@ export const getLastRawAmounts = async ({
market?: Market
useSubgraph?: boolean
}
}): Promise<LastRawAmounts> => {
}): Promise<LastAmounts> => {
if (isAddressEqual(token0, token1)) {
throw new Error('Token0 and token1 must be different')
}
const publicClient = createPublicClient({
chain: CHAIN_MAP[chainId],
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
})
return fetchLastRawAmounts(
return fetchLastAmounts(
publicClient,
chainId,
[token0, token1],
Expand Down

0 comments on commit b9c2f2a

Please sign in to comment.