Skip to content

Commit

Permalink
feat: add new func - withdraw all (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-rock authored Aug 26, 2024
1 parent bcfe4f0 commit 40674ae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@compolabs/spark-orderbook-ts-sdk",
"version": "1.6.2",
"version": "1.6.3",
"type": "module",
"main": "./dist/index.сjs",
"module": "./dist/index.js",
Expand Down
7 changes: 7 additions & 0 deletions src/SparkOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
TradeOrderEvent,
UserMarketBalance,
Volume,
WithdrawAllType,
WriteTransactionResponse,
} from "./interface";
import { ReadActions } from "./ReadActions";
Expand Down Expand Up @@ -125,6 +126,12 @@ export class SparkOrderbook {
return this.write.withdraw(amount, assetType, this.getApiOptions());
};

withdrawAll = async (
assets: WithdrawAllType[],
): Promise<WriteTransactionResponse> => {
return this.write.withdrawAll(assets, this.getApiOptions());
};

fetchMarkets = async (assetIdPairs: [string, string][]): Promise<Markets> => {
const options = await this.getFetchOptions();

Expand Down
24 changes: 24 additions & 0 deletions src/WriteActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CreateOrderParams,
FulfillOrderManyParams,
Options,
WithdrawAllType,
WriteTransactionResponse,
} from "./interface";

Expand Down Expand Up @@ -65,6 +66,29 @@ export class WriteActions {
return this.sendTransaction(tx, options);
};

withdrawAll = async (
assets: WithdrawAllType[],
options: Options,
): Promise<WriteTransactionResponse> => {
const marketFactory = new MarketContract(

Check failure on line 73 in src/WriteActions.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'MarketContract'.
options.contractAddresses.market,
options.wallet,
);

const assetCall = assets.map((el) =>
marketFactory.functions.withdraw(
el.amount,
el.assetType as unknown as AssetTypeInput,
),
);

const tx = marketFactory
.multiCall(assetCall)
.txParams({ gasLimit: options.gasPrice });

return this.sendMultiTransaction(tx, options);
};

createOrder = async (
{ amount, price, type, feeAssetId }: CreateOrderParams,
options: Options,
Expand Down
5 changes: 5 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export enum LimitType {

export type Status = "Active" | "Canceled" | "Closed";

export interface WithdrawAllType {
amount: string;
assetType: AssetType;
}

export interface SpotMarketCreateEvent {
id: number;
asset_id: string;
Expand Down

0 comments on commit 40674ae

Please sign in to comment.