Skip to content

Commit

Permalink
feat(ui): split closing position and open order
Browse files Browse the repository at this point in the history
  • Loading branch information
janfabian committed Nov 6, 2023
1 parent e529e6c commit b352286
Show file tree
Hide file tree
Showing 23 changed files with 1,984 additions and 19,135 deletions.
19,516 changes: 872 additions & 18,644 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
"chain-registry": "1.20.0",
"cosmjs-types": "0.9.0",
"decimal.js": "10.4.3",
"immutable": "4.3.4",
"joi": "17.11.0",
"ramda": "0.29.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-helmet": "6.1.0",
"react-router-dom": "6.18.0",
"recoil": "0.7.7",
"rollbar": "2.26.2",
"suspend-react": "^0.1.3"
"suspend-react": "0.1.3"
},
"devDependencies": {
"@bangjelkoski/vite-plugin-node-polyfills": "0.0.2",
"@types/ramda": "0.29.7",
"@types/react": "18.2.35",
"@types/react-dom": "18.2.14",
"@types/react-helmet": "6.1.8",
Expand Down
88 changes: 78 additions & 10 deletions package/ui/src/codegen/KogenMarkets.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ export interface KogenMarketsInterface extends KogenMarketsReadOnlyInterface {
) => Promise<ExecuteResult>;
askOrder: (
{
closingPosition,
price,
quantity,
}: {
closingPosition?: Uint128;
price: Uint128;
quantity: Uint128;
},
Expand All @@ -139,11 +137,9 @@ export interface KogenMarketsInterface extends KogenMarketsReadOnlyInterface {
) => Promise<ExecuteResult>;
bidOrder: (
{
closingPosition,
price,
quantity,
}: {
closingPosition?: Uint128;
price: Uint128;
quantity: Uint128;
},
Expand Down Expand Up @@ -175,6 +171,30 @@ export interface KogenMarketsInterface extends KogenMarketsReadOnlyInterface {
memo?: string,
_funds?: Coin[],
) => Promise<ExecuteResult>;
closeLongPositionOrder: (
{
price,
quantity,
}: {
price: Uint128;
quantity: Uint128;
},
fee?: number | StdFee | "auto",
memo?: string,
_funds?: Coin[],
) => Promise<ExecuteResult>;
closeShortPositionOrder: (
{
price,
quantity,
}: {
price: Uint128;
quantity: Uint128;
},
fee?: number | StdFee | "auto",
memo?: string,
_funds?: Coin[],
) => Promise<ExecuteResult>;
exercise: (
{
expiryPrice,
Expand Down Expand Up @@ -208,6 +228,8 @@ export class KogenMarketsClient
this.bidOrder = this.bidOrder.bind(this);
this.cancelBidOrder = this.cancelBidOrder.bind(this);
this.cancelAskOrder = this.cancelAskOrder.bind(this);
this.closeLongPositionOrder = this.closeLongPositionOrder.bind(this);
this.closeShortPositionOrder = this.closeShortPositionOrder.bind(this);
this.exercise = this.exercise.bind(this);
}

Expand All @@ -229,11 +251,9 @@ export class KogenMarketsClient
};
askOrder = async (
{
closingPosition,
price,
quantity,
}: {
closingPosition?: Uint128;
price: Uint128;
quantity: Uint128;
},
Expand All @@ -246,7 +266,6 @@ export class KogenMarketsClient
this.contractAddress,
{
ask_order: {
closing_position: closingPosition,
price,
quantity,
},
Expand All @@ -258,11 +277,9 @@ export class KogenMarketsClient
};
bidOrder = async (
{
closingPosition,
price,
quantity,
}: {
closingPosition?: Uint128;
price: Uint128;
quantity: Uint128;
},
Expand All @@ -275,7 +292,6 @@ export class KogenMarketsClient
this.contractAddress,
{
bid_order: {
closing_position: closingPosition,
price,
quantity,
},
Expand Down Expand Up @@ -337,6 +353,58 @@ export class KogenMarketsClient
_funds,
);
};
closeLongPositionOrder = async (
{
price,
quantity,
}: {
price: Uint128;
quantity: Uint128;
},
fee: number | StdFee | "auto" = "auto",
memo?: string,
_funds?: Coin[],
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
close_long_position_order: {
price,
quantity,
},
},
fee,
memo,
_funds,
);
};
closeShortPositionOrder = async (
{
price,
quantity,
}: {
price: Uint128;
quantity: Uint128;
},
fee: number | StdFee | "auto" = "auto",
memo?: string,
_funds?: Coin[],
): Promise<ExecuteResult> => {
return await this.client.execute(
this.sender,
this.contractAddress,
{
close_short_position_order: {
price,
quantity,
},
},
fee,
memo,
_funds,
);
};
exercise = async (
{
expiryPrice,
Expand Down
66 changes: 64 additions & 2 deletions package/ui/src/codegen/KogenMarkets.react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,70 @@ export function useKogenMarketsExerciseMutation(
options,
);
}
export interface KogenMarketsCloseShortPositionOrderMutation {
client: KogenMarketsClient;
msg: {
price: Uint128;
quantity: Uint128;
};
args?: {
fee?: number | StdFee | "auto";
memo?: string;
funds?: Coin[];
};
}
export function useKogenMarketsCloseShortPositionOrderMutation(
options?: Omit<
UseMutationOptions<
ExecuteResult,
Error,
KogenMarketsCloseShortPositionOrderMutation
>,
"mutationFn"
>,
) {
return useMutation<
ExecuteResult,
Error,
KogenMarketsCloseShortPositionOrderMutation
>(
({ client, msg, args: { fee, memo, funds } = {} }) =>
client.closeShortPositionOrder(msg, fee, memo, funds),
options,
);
}
export interface KogenMarketsCloseLongPositionOrderMutation {
client: KogenMarketsClient;
msg: {
price: Uint128;
quantity: Uint128;
};
args?: {
fee?: number | StdFee | "auto";
memo?: string;
funds?: Coin[];
};
}
export function useKogenMarketsCloseLongPositionOrderMutation(
options?: Omit<
UseMutationOptions<
ExecuteResult,
Error,
KogenMarketsCloseLongPositionOrderMutation
>,
"mutationFn"
>,
) {
return useMutation<
ExecuteResult,
Error,
KogenMarketsCloseLongPositionOrderMutation
>(
({ client, msg, args: { fee, memo, funds } = {} }) =>
client.closeLongPositionOrder(msg, fee, memo, funds),
options,
);
}
export interface KogenMarketsCancelAskOrderMutation {
client: KogenMarketsClient;
msg: {
Expand Down Expand Up @@ -410,7 +474,6 @@ export function useKogenMarketsCancelBidOrderMutation(
export interface KogenMarketsBidOrderMutation {
client: KogenMarketsClient;
msg: {
closingPosition?: Uint128;
price: Uint128;
quantity: Uint128;
};
Expand All @@ -435,7 +498,6 @@ export function useKogenMarketsBidOrderMutation(
export interface KogenMarketsAskOrderMutation {
client: KogenMarketsClient;
msg: {
closingPosition?: Uint128;
price: Uint128;
quantity: Uint128;
};
Expand Down
15 changes: 13 additions & 2 deletions package/ui/src/codegen/KogenMarkets.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ export type ExecuteMsg =
}
| {
ask_order: {
closing_position?: Uint128 | null;
price: Uint128;
quantity: Uint128;
};
}
| {
bid_order: {
closing_position?: Uint128 | null;
price: Uint128;
quantity: Uint128;
};
Expand All @@ -55,6 +53,18 @@ export type ExecuteMsg =
quantity: Uint128;
};
}
| {
close_long_position_order: {
price: Uint128;
quantity: Uint128;
};
}
| {
close_short_position_order: {
price: Uint128;
quantity: Uint128;
};
}
| {
exercise: {
expiry_price?: Uint128 | null;
Expand Down Expand Up @@ -92,6 +102,7 @@ export interface OrdersResponse {
price: Uint128;
}
export interface OrderBookItem {
is_closing: boolean;
owner: Addr;
quantity_in_base: Uint128;
}
Expand Down
15 changes: 15 additions & 0 deletions package/ui/src/components/with-value.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Fragment } from "react";

export default function WithValue({
children,
value,
}: {
children?: React.ReactNode;
value: unknown;
}) {
if (!value) {
return <Fragment />;
} else {
return <Fragment>{children}</Fragment>;
}
}
35 changes: 0 additions & 35 deletions package/ui/src/hooks/use-form-data.ts

This file was deleted.

Loading

0 comments on commit b352286

Please sign in to comment.