diff --git a/src/actions/open-markets.test.ts b/src/actions/open-markets.test.ts index 52c3788..7fa61db 100644 --- a/src/actions/open-markets.test.ts +++ b/src/actions/open-markets.test.ts @@ -1,31 +1,31 @@ -import { describe, expect, inject, it } from "vitest"; -import { getClient } from "~test/src/client.js"; -import { getOpenMarkets } from "./open-markets.js"; -import type { Token } from "~mgv/_types/index.js"; +import { describe, expect, inject, it } from 'vitest' +import type { Token } from '~mgv/_types/index.js' +import { getClient } from '~test/src/client.js' +import { getOpenMarkets } from './open-markets.js' -const params = inject("mangrove"); +const params = inject('mangrove') -describe("Getting the open markets", () => { - it("should get the open markets", async () => { - const client = getClient(); - const openMarkets = await getOpenMarkets(client, params); +describe('Getting the open markets', () => { + it('should get the open markets', async () => { + const client = getClient() + const openMarkets = await getOpenMarkets(client, params) - console.log(openMarkets.markets, "markets"); + console.log(openMarkets.markets, 'markets') - expect(openMarkets.markets[0]?.tkn0).toBeTypeOf("object"); - expect(openMarkets.markets[0]?.tkn1).toBeTypeOf("object"); - expect(openMarkets.markets[0]?.tickSpacing).toBeTypeOf("bigint"); + expect(openMarkets.markets[0]?.tkn0).toBeTypeOf('object') + expect(openMarkets.markets[0]?.tkn1).toBeTypeOf('object') + expect(openMarkets.markets[0]?.tickSpacing).toBeTypeOf('bigint') - expect(openMarkets.markets[1]?.tkn0).toBeTypeOf("object"); - expect(openMarkets.markets[1]?.tkn1).toBeTypeOf("object"); - expect(openMarkets.markets[1]?.tickSpacing).toBeTypeOf("bigint"); - }); + expect(openMarkets.markets[1]?.tkn0).toBeTypeOf('object') + expect(openMarkets.markets[1]?.tkn1).toBeTypeOf('object') + expect(openMarkets.markets[1]?.tickSpacing).toBeTypeOf('bigint') + }) - it("should get the open markets config", async () => { - const client = getClient(); - const openMarkets = await getOpenMarkets(client, params); - console.log(openMarkets.marketsConfig, "config"); + it('should get the open markets config', async () => { + const client = getClient() + const openMarkets = await getOpenMarkets(client, params) + console.log(openMarkets.marketsConfig, 'config') - expect(openMarkets.marketsConfig).toBeTypeOf("object"); - }); -}); + expect(openMarkets.marketsConfig).toBeTypeOf('object') + }) +}) diff --git a/src/actions/open-markets.ts b/src/actions/open-markets.ts index 30f6e05..9658b40 100644 --- a/src/actions/open-markets.ts +++ b/src/actions/open-markets.ts @@ -1,27 +1,27 @@ // import type { SimulationParams } from '~mgv/types/actions/simulation.js' // import type { openMarketsABI } from '../builder/open-markets.js' -import type { Client, ContractFunctionReturnType } from "viem"; -import { multicall } from "viem/actions"; +import type { Client, ContractFunctionReturnType } from 'viem' +import { multicall } from 'viem/actions' -import type { OpenMarketsResult } from "~mgv/types/actions/open-markets.js"; -import type { MangroveActionsDefaultParams } from "~mgv/types/index.js"; +import type { OpenMarketsResult } from '~mgv/types/actions/open-markets.js' +import type { MangroveActionsDefaultParams } from '~mgv/types/index.js' import { openMarketsABI, openMarketsParams, parseOpenMarketResult, -} from "../builder/open-markets.js"; -import { getAction } from "../utils/getAction.js"; +} from '../builder/open-markets.js' +import { getAction } from '../utils/getAction.js' export async function getOpenMarkets( client: Client, - actionParams: MangroveActionsDefaultParams + actionParams: MangroveActionsDefaultParams, ): Promise { - const { mgvReader } = actionParams; + const { mgvReader } = actionParams const result = await getAction( client, multicall, - "multicall" + 'multicall', )({ contracts: [ { @@ -30,12 +30,12 @@ export async function getOpenMarkets( }, ], allowFailure: false, - }); + }) const parsedOpenMarkets = await parseOpenMarketResult({ client, result: result[0], - }); + }) - return parsedOpenMarkets; + return parsedOpenMarkets } diff --git a/src/builder/open-markets.ts b/src/builder/open-markets.ts index 4ea8270..dc245f6 100644 --- a/src/builder/open-markets.ts +++ b/src/builder/open-markets.ts @@ -2,22 +2,22 @@ import { type ContractFunctionParameters, type ContractFunctionReturnType, parseAbi, -} from "viem"; -import type { Client } from "viem"; +} from 'viem' +import type { Client } from 'viem' -import { multicall } from "viem/actions"; -import type { Token } from "~mgv/_types/index.js"; -import { buildToken } from "~mgv/addresses/index.js"; -import type { OpenMarketsResult } from "~mgv/types/actions/open-markets.js"; -import type { LocalConfig } from "~mgv/types/lib.js"; -import { getAction } from "~mgv/utils/getAction.js"; +import { multicall } from 'viem/actions' +import type { Token } from '~mgv/_types/index.js' +import { buildToken } from '~mgv/addresses/index.js' +import type { OpenMarketsResult } from '~mgv/types/actions/open-markets.js' +import type { LocalConfig } from '~mgv/types/lib.js' +import { getAction } from '~mgv/utils/getAction.js' export const openMarketsABI = parseAbi([ - "struct Market { address tkn0; address tkn1; uint tickSpacing; }", - "struct LocalUnpacked { bool active; uint fee; uint rawDensity; uint binPosInLeaf; uint level3; uint level2; uint level1; uint root; uint kilo_offer_gasbase; bool lock; uint last;}", - "struct MarketConfig { LocalUnpacked config01; LocalUnpacked config10; }", - "function openMarkets() external view returns (Market[] memory, MarketConfig[] memory)", -]); + 'struct Market { address tkn0; address tkn1; uint tickSpacing; }', + 'struct LocalUnpacked { bool active; uint fee; uint rawDensity; uint binPosInLeaf; uint level3; uint level2; uint level1; uint root; uint kilo_offer_gasbase; bool lock; uint last;}', + 'struct MarketConfig { LocalUnpacked config01; LocalUnpacked config10; }', + 'function openMarkets() external view returns (Market[] memory, MarketConfig[] memory)', +]) /** * @@ -38,22 +38,22 @@ export const openMarketsABI = parseAbi([ export function openMarketsParams() { return { abi: openMarketsABI, - functionName: "openMarkets", + functionName: 'openMarkets', args: [], } satisfies Omit< - ContractFunctionParameters, - "address" - >; + ContractFunctionParameters, + 'address' + > } export type ParseOpenMarketsParams = { - client: Client; + client: Client result: ContractFunctionReturnType< typeof openMarketsABI, - "view", - "openMarkets" - >; -}; + 'view', + 'openMarkets' + > +} /** * @@ -64,86 +64,86 @@ export async function parseOpenMarketResult({ client, result, }: ParseOpenMarketsParams): Promise { - const [rawMarkets, rawMarketsConfigs] = result; + const [rawMarkets, rawMarketsConfigs] = result const markets = await Promise.all( rawMarkets.map(async (item) => { - const { tkn0, tkn1, tickSpacing } = item; + const { tkn0, tkn1, tickSpacing } = item // Fetch token information for both tokens (tkn0 and tkn1) const tokenInfos = await getAction( client, multicall, - "multicall" + 'multicall', )({ contracts: [ { - functionName: "decimals", + functionName: 'decimals', abi: [ { - name: "decimals", + name: 'decimals', outputs: [ { - type: "uint8", + type: 'uint8', }, ], - stateMutability: "view", - type: "function", + stateMutability: 'view', + type: 'function', }, ], address: tkn0, }, { - functionName: "symbol", + functionName: 'symbol', abi: [ { - name: "symbol", + name: 'symbol', outputs: [ { - type: "string", + type: 'string', }, ], - stateMutability: "view", - type: "function", + stateMutability: 'view', + type: 'function', }, ], address: tkn0, }, { - functionName: "decimals", + functionName: 'decimals', abi: [ { - name: "decimals", + name: 'decimals', outputs: [ { - type: "uint8", + type: 'uint8', }, ], - stateMutability: "view", - type: "function", + stateMutability: 'view', + type: 'function', }, ], address: tkn1, }, { - functionName: "symbol", + functionName: 'symbol', abi: [ { - name: "symbol", + name: 'symbol', outputs: [ { - type: "string", + type: 'string', }, ], - stateMutability: "view", - type: "function", + stateMutability: 'view', + type: 'function', }, ], address: tkn1, }, ], allowFailure: false, - }); + }) return { tkn0: buildToken({ @@ -161,12 +161,12 @@ export async function parseOpenMarketResult({ mgvTestToken: false, }) as Token, tickSpacing, - }; - }) - ); + } + }), + ) const marketsConfig = rawMarketsConfigs?.map((item) => { - const { config01, config10 } = item; + const { config01, config10 } = item return { config01: { @@ -179,8 +179,8 @@ export async function parseOpenMarketResult({ density: Number(config10.rawDensity), offer_gasbase: config10.kilo_offer_gasbase, } as LocalConfig, - }; - }); + } + }) - return { markets, marketsConfig }; + return { markets, marketsConfig } } diff --git a/src/types/actions/open-markets.ts b/src/types/actions/open-markets.ts index 2e423c3..37be8a1 100644 --- a/src/types/actions/open-markets.ts +++ b/src/types/actions/open-markets.ts @@ -1,16 +1,16 @@ -import type { SimulateContractReturnType } from "viem"; -import type { LocalConfig, Token } from "~mgv/_types/index.js"; -import type { openMarketsABI } from "~mgv/builder/open-markets.js"; +import type { SimulateContractReturnType } from 'viem' +import type { LocalConfig, Token } from '~mgv/_types/index.js' +import type { openMarketsABI } from '~mgv/builder/open-markets.js' export type OpenMarketsResult = { markets: { - tkn0: Token; - tkn1: Token; - tickSpacing: bigint; - }[]; - marketsConfig: { config01: LocalConfig; config10: LocalConfig }[]; + tkn0: Token + tkn1: Token + tickSpacing: bigint + }[] + marketsConfig: { config01: LocalConfig; config10: LocalConfig }[] // request: SimulateContractReturnType< // typeof openMarketsABI, // "openMarkets" // >["request"]; -}; +}