From 0ea39e9b099ae669c186dca87b02e278cf5c32a7 Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Sun, 5 May 2024 16:15:13 +0200 Subject: [PATCH 1/3] feat: features --- .changeset/honest-books-develop.md | 5 + .changeset/metal-toes-ring.md | 5 + .changeset/tough-ads-roll.md | 5 + .zed/setting.json | 8 ++ src/actions/balances.ts | 137 ++++++++++++++++++++++++ src/actions/order/new.ts | 8 +- src/addresses/logics/chains/blast.ts | 6 ++ src/addresses/logics/chains/index.ts | 1 + src/addresses/logics/index.ts | 2 + src/addresses/logics/strategies/aave.ts | 2 +- src/addresses/logics/utils.ts | 4 +- src/bundle/index.ts | 2 +- src/bundle/public/general-actions.ts | 24 +++++ src/bundle/public/index.ts | 3 +- src/index.ts | 2 +- src/lib/human-readable.ts | 79 +++++++++++++- src/lib/tick.ts | 11 +- 17 files changed, 293 insertions(+), 11 deletions(-) create mode 100644 .changeset/honest-books-develop.md create mode 100644 .changeset/metal-toes-ring.md create mode 100644 .changeset/tough-ads-roll.md create mode 100644 .zed/setting.json create mode 100644 src/actions/balances.ts create mode 100644 src/bundle/public/general-actions.ts diff --git a/.changeset/honest-books-develop.md b/.changeset/honest-books-develop.md new file mode 100644 index 0000000..2745072 --- /dev/null +++ b/.changeset/honest-books-develop.md @@ -0,0 +1,5 @@ +--- +"@mangrovedao/mgv": minor +--- + +Added general actions for balances and logic diff --git a/.changeset/metal-toes-ring.md b/.changeset/metal-toes-ring.md new file mode 100644 index 0000000..7397f52 --- /dev/null +++ b/.changeset/metal-toes-ring.md @@ -0,0 +1,5 @@ +--- +"@mangrovedao/mgv": patch +--- + +Added tickSpacing to tick lib diff --git a/.changeset/tough-ads-roll.md b/.changeset/tough-ads-roll.md new file mode 100644 index 0000000..dea58cd --- /dev/null +++ b/.changeset/tough-ads-roll.md @@ -0,0 +1,5 @@ +--- +"@mangrovedao/mgv": minor +--- + +Add human readable prices conversions diff --git a/.zed/setting.json b/.zed/setting.json new file mode 100644 index 0000000..88e06ad --- /dev/null +++ b/.zed/setting.json @@ -0,0 +1,8 @@ +{ + "formatter": { + "external": { + "command": "bun", + "arguments": ["run", "format", "--stdin-file-path={buffer_path}"] + } + } +} diff --git a/src/actions/balances.ts b/src/actions/balances.ts new file mode 100644 index 0000000..b62a037 --- /dev/null +++ b/src/actions/balances.ts @@ -0,0 +1,137 @@ +import { + erc20Abi, + isAddressEqual, + zeroAddress, + type Address, + type Client, +} from "viem"; +import type { Logic, OverlyingResponse } from "../addresses/logics/utils.js"; +import type { MarketParams } from "../types/actions/index.js"; +import type { ContractFunctionParameters, MulticallParameters } from "viem"; +import { getAction } from "../utils/getAction.js"; +import { multicall } from "viem/actions"; +import type { Token } from "../addresses/tokens/utils.js"; +import type { Prettify } from "../types/lib.js"; + +/** + * Get the balances for a user + * @param logics the logics to get balances for + * @param markets the markets to get balances for + * @param user the user to get balances for + */ +export type GetBalancesParams = { + logics: TLogics; + markets: MarketParams[]; + user: Address; +}; + +export type GetBalancesArgs = + GetBalancesParams & + Omit; + +type ExtendedOverlyingResponse = Prettify; + +export type GetBalanceResult = { + tokens: { + token: Token; + balance: bigint; + }[]; + overlying: ExtendedOverlyingResponse[]; + logicBalances: { + token: Token; + logic: TLogics[number]; + balance: bigint; + }[]; +}; + +export async function getBalances( + client: Client, + args: GetBalancesArgs, +): Promise> { + const { logics, markets, ...multicallArgs } = args; + const tokens = markets.reduce((acc, market) => { + if (!acc.find((t) => isAddressEqual(t.address, market.base.address))) { + acc.push(market.base); + } + if (!acc.find((t) => isAddressEqual(t.address, market.quote.address))) { + acc.push(market.quote); + } + return acc; + }, [] as Token[]); + + const tokenBalanceCalls = tokens.map( + (token) => + ({ + address: token.address, + abi: erc20Abi, + functionName: "balanceOf", + args: [args.user], + }) as const, + ); + + const overlyingCalls = tokens.flatMap((token) => + logics.map((logic) => + logic.logicOverlying.getOverlyingContractParams({ + token: token.address, + logic: logic.logic, + name: logic.name, + }), + ), + ) as ContractFunctionParameters[]; + + const logicBalancesCalls = tokens.flatMap((token) => + logics.map((logic) => + logic.logicBalance.getRoutingLogicBalanceParams({ + token: token.address, + logic: logic.logic, + name: logic.name, + user: args.user, + }), + ), + ) as ContractFunctionParameters[]; + + const result = await getAction( + client, + multicall, + "multicall", + )({ + ...multicallArgs, + contracts: [...tokenBalanceCalls, ...overlyingCalls, ...logicBalancesCalls], + allowFailure: true, + }); + + const tokenBalances = tokens.map((token, i) => { + const res = result[i]; + const balance = res.status === "success" ? (res.result as bigint) : 0n; + return { token, balance }; + }); + + const overlying = tokens.flatMap((token, i) => + logics.map((logic, j) => { + const res = result[tokens.length * (i + 1) + j]; + const overlying: OverlyingResponse = + res.status === "success" + ? logic.logicOverlying.parseOverlyingContractResponse(res.result) + : { + type: "erc20", + overlying: zeroAddress, + available: false, + }; + return { token, ...overlying }; + }), + ); + + const logicBalances = tokens.flatMap((token, i) => + logics.map((logic, j) => { + const res = result[overlying.length + tokens.length * (i + 1) + j]; + const balance = res.status === "success" ? (res.result as bigint) : 0n; + return { token, logic, balance }; + }), + ); + + return { + tokens: tokenBalances, + overlying, + logicBalances, + }; +} diff --git a/src/actions/order/new.ts b/src/actions/order/new.ts index 5f463da..0d683f5 100644 --- a/src/actions/order/new.ts +++ b/src/actions/order/new.ts @@ -35,6 +35,7 @@ export type GetLimitOrderStepsParams = { userRouter: Address bs: BS sendAmount?: bigint + logicToken?: Address } export type GetLimitOrderStepsArgs = Prettify< @@ -48,8 +49,11 @@ export async function getLimitOrderSteps( args: GetLimitOrderStepsArgs, ): Promise { const { sendAmount: amount = maxUint256 } = args - const tokenToApprove = - args.bs === BS.buy ? market.quote.address : market.base.address + const tokenToApprove = args.logicToken + ? args.logicToken + : args.bs === BS.buy + ? market.quote.address + : market.base.address const allowance = await getAction( client, diff --git a/src/addresses/logics/chains/blast.ts b/src/addresses/logics/chains/blast.ts index 5942f84..53a8ee7 100644 --- a/src/addresses/logics/chains/blast.ts +++ b/src/addresses/logics/chains/blast.ts @@ -21,3 +21,9 @@ export const blastPacFinanceLogic = buildLogic( aaveOverLying, aaveBalance, ) + +export const blastLogics = [ + blastOrbitLogic, + blastZeroLendLogic, + blastPacFinanceLogic, +] as const \ No newline at end of file diff --git a/src/addresses/logics/chains/index.ts b/src/addresses/logics/chains/index.ts index 394f00b..2d040c8 100644 --- a/src/addresses/logics/chains/index.ts +++ b/src/addresses/logics/chains/index.ts @@ -2,4 +2,5 @@ export { blastOrbitLogic, blastZeroLendLogic, blastPacFinanceLogic, + blastLogics } from './blast.js' diff --git a/src/addresses/logics/index.ts b/src/addresses/logics/index.ts index e9a0c4a..c430734 100644 --- a/src/addresses/logics/index.ts +++ b/src/addresses/logics/index.ts @@ -2,6 +2,7 @@ export { blastOrbitLogic, blastZeroLendLogic, blastPacFinanceLogic, + blastLogics, } from './chains/index.js' export { @@ -19,6 +20,7 @@ export type { LogicBalanceParams, LogicBalanceResponse, RoutingLogicBalance, + Logic, } from './utils.js' export { buildLogic } from './utils.js' diff --git a/src/addresses/logics/strategies/aave.ts b/src/addresses/logics/strategies/aave.ts index 38dd9b8..0490a6a 100644 --- a/src/addresses/logics/strategies/aave.ts +++ b/src/addresses/logics/strategies/aave.ts @@ -22,7 +22,7 @@ export const aaveOverLying: RoutingLogicOverlying< parseOverlyingContractResponse(response) { return { type: 'erc20', - token: response, + overlying: response, available: !isAddressEqual(response, zeroAddress), } }, diff --git a/src/addresses/logics/utils.ts b/src/addresses/logics/utils.ts index 50af71a..9016fc4 100644 --- a/src/addresses/logics/utils.ts +++ b/src/addresses/logics/utils.ts @@ -15,7 +15,7 @@ export type OverlyingParams = { export type OverlyingResponse = { type: 'erc20' | 'erc721' - token: Address + overlying: Address available: boolean } @@ -96,3 +96,5 @@ export function buildLogic< logicBalance, } } + +export type Logic = ReturnType \ No newline at end of file diff --git a/src/bundle/index.ts b/src/bundle/index.ts index cf54a73..cd2d459 100644 --- a/src/bundle/index.ts +++ b/src/bundle/index.ts @@ -1 +1 @@ -export { publicMarketActions } from './public/index.js' +export { publicMarketActions, generalActions } from './public/index.js' diff --git a/src/bundle/public/general-actions.ts b/src/bundle/public/general-actions.ts new file mode 100644 index 0000000..4ffd9e2 --- /dev/null +++ b/src/bundle/public/general-actions.ts @@ -0,0 +1,24 @@ +import type { Client } from "viem"; +import { + getBalances, + type GetBalanceResult, + type GetBalancesArgs, +} from "../../actions/balances.js"; +import type { Logic } from "../../addresses/logics/utils.js"; + +export type GeneralActions = { + /** + * + * @param args.markets the markets to get balances for + * @param args.logics the logics to get balances for + * @param args.user the user to get balances for + * @returns balances of user for each token in markets, overlying tokens, and logic balances + */ + getBalances: ( + args: GetBalancesArgs, + ) => Promise>; +}; + +export const generalActions = (client: Client): GeneralActions => ({ + getBalances: (args) => getBalances(client, args), +}); diff --git a/src/bundle/public/index.ts b/src/bundle/public/index.ts index 1573e92..fa0acca 100644 --- a/src/bundle/public/index.ts +++ b/src/bundle/public/index.ts @@ -1 +1,2 @@ -export { publicMarketActions } from './market-actions.js' +export { publicMarketActions } from "./market-actions.js"; +export { generalActions } from "./general-actions.js"; diff --git a/src/index.ts b/src/index.ts index e6426ee..230d637 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,7 +61,7 @@ export type { // --- bundles --- -export { publicMarketActions } from './bundle/index.js' +export { publicMarketActions, generalActions } from './bundle/index.js' // --- addresses --- diff --git a/src/lib/human-readable.ts b/src/lib/human-readable.ts index 7b576a4..9a26ad8 100644 --- a/src/lib/human-readable.ts +++ b/src/lib/human-readable.ts @@ -1,6 +1,12 @@ import { formatUnits } from 'viem' import type { BA } from './enums.js' -import { inboundFromOutbound } from './tick.js' +import { + inboundFromOutbound, + outboundFromInbound, + tickFromPrice, + tickFromVolumes, +} from './tick.js' +import type { MarketParams } from '../types/index.js' // if ask, then outbound is the base, inbound is the quote // if bid, then outbound is the quote, inbound is the base @@ -43,3 +49,74 @@ export function rpcOfferToHumanOffer({ ba, } } + +export function rawPriceToHumanPrice( + price: number, + market: MarketParams, +): number { + // if market is WETH/USDC, and 1 WETH = 3000 USDC, WETH decimals = 18, USDC decimals = 6 + // this means raw price is (3000 * 1e6) / (1 * 1e18) = 3000 * 1e(-12) + // So if we want to convert this to human readable price, we need to multiply by 1e12 = 1e(18 - 6) = 1e(baseDecimals - quoteDecimals) + return price * 10 ** (market.base.decimals - market.quote.decimals) +} + +export function humanPriceToRawPrice( + price: number, + market: MarketParams, +): number { + return price * 10 ** (market.quote.decimals - market.base.decimals) +} + +export type AmountsToHumanPriceParams = { + baseAmount: bigint + quoteAmount: bigint +} + +export function amountsToHumanPrice( + params: AmountsToHumanPriceParams, + market: MarketParams, +): number { + const price = Number(params.quoteAmount) / Number(params.baseAmount) + return rawPriceToHumanPrice(price, market) +} + +export type AmountsParams = + | { + baseAmount: bigint + quoteAmount: bigint + } + | { + humanPrice: number + baseAmount: bigint + } + | { + humanPrice: number + quoteAmount: bigint + } + +export type AmountsOutput = { + baseAmount: bigint + quoteAmount: bigint + humanPrice: number +} + +export function amounts( + params: AmountsParams, + market: MarketParams, +): AmountsOutput { + // quote is inbound, base is outbound + const tick = + 'humanPrice' in params + ? tickFromPrice(humanPriceToRawPrice(params.humanPrice, market), market.tickSpacing) + : tickFromVolumes(params.quoteAmount, params.baseAmount, market.tickSpacing) + const baseAmount = + 'baseAmount' in params + ? params.baseAmount + : outboundFromInbound(tick, params.quoteAmount) + const quoteAmount = + 'quoteAmount' in params + ? params.quoteAmount + : inboundFromOutbound(tick, params.baseAmount) + const humanPrice = amountsToHumanPrice({ baseAmount, quoteAmount }, market) + return { baseAmount, quoteAmount, humanPrice } +} diff --git a/src/lib/tick.ts b/src/lib/tick.ts index ed5fda5..ff26484 100644 --- a/src/lib/tick.ts +++ b/src/lib/tick.ts @@ -30,16 +30,20 @@ export function tickInRange(tick: bigint): boolean { /** * Computes the tick value corresponding to the price of the asset. * @param price the price of the asset + * @param tickSpacing the tick spacing of the market @default 1n * @returns A Tick instance corresponding to the price of the asset. */ -export function tickFromPrice(price: number): bigint { - return BigInt(Math.floor(Math.log(price) / Math.log(1.0001))) +export function tickFromPrice(price: number, tickSpacing = 1n): bigint { + const rawTick = BigInt(Math.floor(Math.log(price) / Math.log(1.0001))) + const bin = rawTick / tickSpacing + (rawTick % tickSpacing > 0n ? 1n : 0n) + return bin * tickSpacing } /** * Computes the tick value corresponding to the price between two assets. * @param inboundAmt amount of inbound asset * @param outboundAmt amount of outbound asset + * @param tickSpacing the tick spacing of the market @default 1n * @returns A Tick instance corresponding to the price between the two assets. * @example * const inboundVolume = 100000000000000000000n @@ -50,10 +54,11 @@ export function tickFromPrice(price: number): bigint { export function tickFromVolumes( inboundAmt: bigint, outboundAmt: bigint, + tickSpacing = 1n, ): bigint { // This implementation is not exact const price = Number(inboundAmt) / Number(outboundAmt) - return tickFromPrice(price) + return tickFromPrice(price, tickSpacing) } /** From 95768de92b742e824318457890d515b8f2fa715d Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Sun, 5 May 2024 16:15:26 +0200 Subject: [PATCH 2/3] chore: format --- src/actions/balances.ts | 102 +++++++++++++-------------- src/addresses/logics/chains/blast.ts | 2 +- src/addresses/logics/chains/index.ts | 2 +- src/addresses/logics/utils.ts | 2 +- src/bundle/public/general-actions.ts | 14 ++-- src/bundle/public/index.ts | 4 +- src/lib/human-readable.ts | 13 +++- 7 files changed, 73 insertions(+), 66 deletions(-) diff --git a/src/actions/balances.ts b/src/actions/balances.ts index b62a037..500bbac 100644 --- a/src/actions/balances.ts +++ b/src/actions/balances.ts @@ -1,17 +1,17 @@ import { + type Address, + type Client, erc20Abi, isAddressEqual, zeroAddress, - type Address, - type Client, -} from "viem"; -import type { Logic, OverlyingResponse } from "../addresses/logics/utils.js"; -import type { MarketParams } from "../types/actions/index.js"; -import type { ContractFunctionParameters, MulticallParameters } from "viem"; -import { getAction } from "../utils/getAction.js"; -import { multicall } from "viem/actions"; -import type { Token } from "../addresses/tokens/utils.js"; -import type { Prettify } from "../types/lib.js"; +} from 'viem' +import type { ContractFunctionParameters, MulticallParameters } from 'viem' +import { multicall } from 'viem/actions' +import type { Logic, OverlyingResponse } from '../addresses/logics/utils.js' +import type { Token } from '../addresses/tokens/utils.js' +import type { MarketParams } from '../types/actions/index.js' +import type { Prettify } from '../types/lib.js' +import { getAction } from '../utils/getAction.js' /** * Get the balances for a user @@ -20,54 +20,54 @@ import type { Prettify } from "../types/lib.js"; * @param user the user to get balances for */ export type GetBalancesParams = { - logics: TLogics; - markets: MarketParams[]; - user: Address; -}; + logics: TLogics + markets: MarketParams[] + user: Address +} export type GetBalancesArgs = GetBalancesParams & - Omit; + Omit -type ExtendedOverlyingResponse = Prettify; +type ExtendedOverlyingResponse = Prettify export type GetBalanceResult = { tokens: { - token: Token; - balance: bigint; - }[]; - overlying: ExtendedOverlyingResponse[]; + token: Token + balance: bigint + }[] + overlying: ExtendedOverlyingResponse[] logicBalances: { - token: Token; - logic: TLogics[number]; - balance: bigint; - }[]; -}; + token: Token + logic: TLogics[number] + balance: bigint + }[] +} export async function getBalances( client: Client, args: GetBalancesArgs, ): Promise> { - const { logics, markets, ...multicallArgs } = args; + const { logics, markets, ...multicallArgs } = args const tokens = markets.reduce((acc, market) => { if (!acc.find((t) => isAddressEqual(t.address, market.base.address))) { - acc.push(market.base); + acc.push(market.base) } if (!acc.find((t) => isAddressEqual(t.address, market.quote.address))) { - acc.push(market.quote); + acc.push(market.quote) } - return acc; - }, [] as Token[]); + return acc + }, [] as Token[]) const tokenBalanceCalls = tokens.map( (token) => ({ address: token.address, abi: erc20Abi, - functionName: "balanceOf", + functionName: 'balanceOf', args: [args.user], }) as const, - ); + ) const overlyingCalls = tokens.flatMap((token) => logics.map((logic) => @@ -77,7 +77,7 @@ export async function getBalances( name: logic.name, }), ), - ) as ContractFunctionParameters[]; + ) as ContractFunctionParameters[] const logicBalancesCalls = tokens.flatMap((token) => logics.map((logic) => @@ -88,50 +88,50 @@ export async function getBalances( user: args.user, }), ), - ) as ContractFunctionParameters[]; + ) as ContractFunctionParameters[] const result = await getAction( client, multicall, - "multicall", + 'multicall', )({ ...multicallArgs, contracts: [...tokenBalanceCalls, ...overlyingCalls, ...logicBalancesCalls], allowFailure: true, - }); + }) const tokenBalances = tokens.map((token, i) => { - const res = result[i]; - const balance = res.status === "success" ? (res.result as bigint) : 0n; - return { token, balance }; - }); + const res = result[i] + const balance = res.status === 'success' ? (res.result as bigint) : 0n + return { token, balance } + }) const overlying = tokens.flatMap((token, i) => logics.map((logic, j) => { - const res = result[tokens.length * (i + 1) + j]; + const res = result[tokens.length * (i + 1) + j] const overlying: OverlyingResponse = - res.status === "success" + res.status === 'success' ? logic.logicOverlying.parseOverlyingContractResponse(res.result) : { - type: "erc20", + type: 'erc20', overlying: zeroAddress, available: false, - }; - return { token, ...overlying }; + } + return { token, ...overlying } }), - ); + ) const logicBalances = tokens.flatMap((token, i) => logics.map((logic, j) => { - const res = result[overlying.length + tokens.length * (i + 1) + j]; - const balance = res.status === "success" ? (res.result as bigint) : 0n; - return { token, logic, balance }; + const res = result[overlying.length + tokens.length * (i + 1) + j] + const balance = res.status === 'success' ? (res.result as bigint) : 0n + return { token, logic, balance } }), - ); + ) return { tokens: tokenBalances, overlying, logicBalances, - }; + } } diff --git a/src/addresses/logics/chains/blast.ts b/src/addresses/logics/chains/blast.ts index 53a8ee7..08ffb72 100644 --- a/src/addresses/logics/chains/blast.ts +++ b/src/addresses/logics/chains/blast.ts @@ -26,4 +26,4 @@ export const blastLogics = [ blastOrbitLogic, blastZeroLendLogic, blastPacFinanceLogic, -] as const \ No newline at end of file +] as const diff --git a/src/addresses/logics/chains/index.ts b/src/addresses/logics/chains/index.ts index 2d040c8..eb89e3f 100644 --- a/src/addresses/logics/chains/index.ts +++ b/src/addresses/logics/chains/index.ts @@ -2,5 +2,5 @@ export { blastOrbitLogic, blastZeroLendLogic, blastPacFinanceLogic, - blastLogics + blastLogics, } from './blast.js' diff --git a/src/addresses/logics/utils.ts b/src/addresses/logics/utils.ts index 9016fc4..ccb97fb 100644 --- a/src/addresses/logics/utils.ts +++ b/src/addresses/logics/utils.ts @@ -97,4 +97,4 @@ export function buildLogic< } } -export type Logic = ReturnType \ No newline at end of file +export type Logic = ReturnType diff --git a/src/bundle/public/general-actions.ts b/src/bundle/public/general-actions.ts index 4ffd9e2..418acf7 100644 --- a/src/bundle/public/general-actions.ts +++ b/src/bundle/public/general-actions.ts @@ -1,10 +1,10 @@ -import type { Client } from "viem"; +import type { Client } from 'viem' import { - getBalances, type GetBalanceResult, type GetBalancesArgs, -} from "../../actions/balances.js"; -import type { Logic } from "../../addresses/logics/utils.js"; + getBalances, +} from '../../actions/balances.js' +import type { Logic } from '../../addresses/logics/utils.js' export type GeneralActions = { /** @@ -16,9 +16,9 @@ export type GeneralActions = { */ getBalances: ( args: GetBalancesArgs, - ) => Promise>; -}; + ) => Promise> +} export const generalActions = (client: Client): GeneralActions => ({ getBalances: (args) => getBalances(client, args), -}); +}) diff --git a/src/bundle/public/index.ts b/src/bundle/public/index.ts index fa0acca..83dc9a9 100644 --- a/src/bundle/public/index.ts +++ b/src/bundle/public/index.ts @@ -1,2 +1,2 @@ -export { publicMarketActions } from "./market-actions.js"; -export { generalActions } from "./general-actions.js"; +export { publicMarketActions } from './market-actions.js' +export { generalActions } from './general-actions.js' diff --git a/src/lib/human-readable.ts b/src/lib/human-readable.ts index 9a26ad8..3cf7dab 100644 --- a/src/lib/human-readable.ts +++ b/src/lib/human-readable.ts @@ -1,4 +1,5 @@ import { formatUnits } from 'viem' +import type { MarketParams } from '../types/index.js' import type { BA } from './enums.js' import { inboundFromOutbound, @@ -6,7 +7,6 @@ import { tickFromPrice, tickFromVolumes, } from './tick.js' -import type { MarketParams } from '../types/index.js' // if ask, then outbound is the base, inbound is the quote // if bid, then outbound is the quote, inbound is the base @@ -107,8 +107,15 @@ export function amounts( // quote is inbound, base is outbound const tick = 'humanPrice' in params - ? tickFromPrice(humanPriceToRawPrice(params.humanPrice, market), market.tickSpacing) - : tickFromVolumes(params.quoteAmount, params.baseAmount, market.tickSpacing) + ? tickFromPrice( + humanPriceToRawPrice(params.humanPrice, market), + market.tickSpacing, + ) + : tickFromVolumes( + params.quoteAmount, + params.baseAmount, + market.tickSpacing, + ) const baseAmount = 'baseAmount' in params ? params.baseAmount From 57a436f3e886c17b02a5d874cb62b3ca934e10d6 Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Sun, 5 May 2024 16:21:02 +0200 Subject: [PATCH 3/3] chore: exports --- .zed/{setting.json => settings.json} | 0 src/index.ts | 3 +++ src/lib/index.ts | 14 +++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) rename .zed/{setting.json => settings.json} (100%) diff --git a/.zed/setting.json b/.zed/settings.json similarity index 100% rename from .zed/setting.json rename to .zed/settings.json diff --git a/src/index.ts b/src/index.ts index 230d637..1389360 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,9 @@ export type { MarketOrderResultFromLogsParams, LimitOrderResultFromLogsParams, LimitOrderResult, + AmountsToHumanPriceParams, + AmountsParams, + AmountsOutput, } from './lib/index.js' export { diff --git a/src/lib/index.ts b/src/lib/index.ts index 03e9a14..c9da9a6 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -17,7 +17,19 @@ export { unpackGlobalConfig } from './global.js' // human-readable -export { rpcOfferToHumanOffer } from './human-readable.js' +export type { + AmountsToHumanPriceParams, + AmountsParams, + AmountsOutput, +} from './human-readable.js' + +export { + rpcOfferToHumanOffer, + rawPriceToHumanPrice, + humanPriceToRawPrice, + amountsToHumanPrice, + amounts, +} from './human-readable.js' // limit-order