diff --git a/package.json b/package.json index 61cb9d3..34b64c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@compolabs/spark-orderbook-ts-sdk", - "version": "1.3.5", + "version": "1.3.6", "type": "module", "main": "./dist/index.сjs", "module": "./dist/index.js", diff --git a/src/ReadActions.ts b/src/ReadActions.ts index 1dc4a09..8462165 100644 --- a/src/ReadActions.ts +++ b/src/ReadActions.ts @@ -8,6 +8,7 @@ import { Options, OrderType, SpotOrderWithoutTimestamp, + UserMarketBalance, } from "./interface"; export class ReadActions { @@ -16,6 +17,40 @@ export class ReadActions { return BN.ZERO; }; + fetchUserMarketBalance = async ( + trader: Bech32Address, + options: Options, + ): Promise => { + const orderbookFactory = MarketContractAbi__factory.connect( + options.contractAddresses.market, + options.wallet, + ); + + const traderAddress = new Address(trader).toB256(); + + const address: AddressInput = { + bits: traderAddress, + }; + + const user: IdentityInput = { + Address: address, + }; + + const result = await orderbookFactory.functions.account(user).get(); + + const liquid = result.value + ? result.value.liquid.toString() + : BN.ZERO.toString(); + const locked = result.value + ? result.value.locked.toString() + : BN.ZERO.toString(); + + return { + liquid, + locked, + }; + }; + fetchOrderById = async ( orderId: string, options: Options, diff --git a/src/WriteActions.ts b/src/WriteActions.ts index 39969d0..c702150 100644 --- a/src/WriteActions.ts +++ b/src/WriteActions.ts @@ -58,16 +58,6 @@ export class WriteActions { assetId: depositAsset, }; - // console.log("deposit", depositAmount.toString(), depositAsset); - - // console.log( - // "open_order", - // amount.toString(), - // tokenType as unknown as AssetTypeInput, - // type as unknown as OrderTypeInput, - // price.toString(), - // ); - const tx = orderbookFactory .multiCall([ orderbookFactory.functions.deposit().callParams({ forward }), diff --git a/src/interface.ts b/src/interface.ts index 1d956ab..01379ab 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -49,6 +49,11 @@ export interface SpotOrderWithoutTimestamp { orderPrice: BN; } +export interface UserMarketBalance { + liquid: string; + locked: string; +} + export type MarketCreateEvent = { id: string; assetId: string;