Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1223] Improve address type for better readability #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/ReadActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Bech32Address } from "fuels";
import { B256Address } from "fuels";

import { MarketContractAbi__factory } from "./types/market";
import { AddressInput, IdentityInput } from "./types/market/MarketContractAbi";
Expand All @@ -18,18 +18,16 @@ export class ReadActions {
};

fetchUserMarketBalance = async (
trader: Bech32Address,
trader: B256Address,
options: Options,
): Promise<UserMarketBalance> => {
const orderbookFactory = MarketContractAbi__factory.connect(
options.contractAddresses.market,
options.wallet,
);

const traderAddress = new Address(trader).toB256();

const address: AddressInput = {
bits: traderAddress,
bits: trader,
};

const user: IdentityInput = {
Expand Down Expand Up @@ -81,18 +79,16 @@ export class ReadActions {
};

fetchOrderIdsByAddress = async (
trader: Bech32Address,
trader: B256Address,
options: Options,
): Promise<string[]> => {
const orderbookFactory = MarketContractAbi__factory.connect(
options.contractAddresses.market,
options.wallet,
);

const traderAddress = new Address(trader).toB256();

const address: AddressInput = {
bits: traderAddress,
bits: trader,
};

const user: IdentityInput = {
Expand Down
6 changes: 3 additions & 3 deletions src/SparkOrderbook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Bech32Address,
B256Address,
Provider,
Wallet,
WalletLocked,
Expand Down Expand Up @@ -158,14 +158,14 @@ export class SparkOrderbook {
return this.read.fetchWalletBalance(asset.address, this.getApiOptions());
};

fetchOrderIdsByAddress = async (trader: Bech32Address): Promise<string[]> => {
fetchOrderIdsByAddress = async (trader: B256Address): Promise<string[]> => {
const options = await this.getFetchOptions();

return this.read.fetchOrderIdsByAddress(trader, options);
};

fetchUserMarketBalance = async (
trader: Bech32Address,
trader: B256Address,
): Promise<UserMarketBalance> => {
const options = await this.getFetchOptions();

Expand Down
32 changes: 16 additions & 16 deletions src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { WalletLocked, WalletUnlocked } from "fuels";
import { B256Address, WalletLocked, WalletUnlocked } from "fuels";

import BN from "./utils/BN";

export type MarketStatusOutput = "Opened" | "Paused" | "Closed";

export interface OrderbookContracts {
market: string;
tokenFactory: string;
pyth: string;
market: B256Address;
tokenFactory: B256Address;
pyth: B256Address;
}

export interface Asset {
address: string;
address: B256Address;
symbol: string;
decimals: number;
}
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface SpotOrderWithoutTimestamp {
id: string;
assetType: AssetType;
orderType: OrderType;
trader: string;
trader: B256Address;
baseSize: BN;
orderPrice: BN;
}
Expand All @@ -62,7 +62,7 @@ export interface UserMarketBalance {

export type MarketCreateEvent = {
id: string;
assetId: string;
assetId: B256Address;
decimal: number;
};

Expand Down Expand Up @@ -90,7 +90,7 @@ export type Status = "Active" | "Canceled" | "Closed";

export interface SpotMarketCreateEvent {
id: number;
asset_id: string;
asset_id: B256Address;
asset_decimals: string;
timestamp: string;
createdAt: string;
Expand All @@ -101,13 +101,13 @@ export interface GetOrdersParams {
limit: number;
orderType?: OrderType;
status?: Status[];
user?: string;
asset?: string;
user?: B256Address;
asset?: B256Address;
}

export interface DepositParams {
amount: string;
asset: string;
asset: B256Address;
}

export interface CreateOrderParams {
Expand All @@ -124,14 +124,14 @@ export interface WithdrawParams {

export interface Order {
id: string;
asset: string;
asset: B256Address;
asset_type: AssetType;
amount: string;
initial_amount: string;
order_type: OrderType;
price: string;
status: Status;
user: string;
user: B256Address;
timestamp: string;
}

Expand All @@ -141,9 +141,9 @@ export interface GetTradeOrderEventsParams {

export interface MatchOrderEvent {
id: string;
owner: string;
counterparty: string;
asset: string;
owner: B256Address;
counterparty: B256Address;
asset: B256Address;
match_size: string;
match_price: string;
timestamp: string;
Expand Down