@myx-trade/sdk 0.1.132 → 0.1.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { AddressLike, Signer, ethers } from 'ethers';
1
+ import * as ethers from 'ethers';
2
+ import { AddressLike, Signer, ethers as ethers$1 } from 'ethers';
2
3
  export { formatUnits, parseUnits } from 'ethers';
3
4
  import { Options, Event } from 'reconnecting-websocket';
4
5
  import { WalletClient } from 'viem';
@@ -48,49 +49,49 @@ interface CancelTpSLParams {
48
49
  orderId: string;
49
50
  }
50
51
 
51
- declare const createPool: ({ chainId, baseToken, marketId }: CreatePoolRequest) => Promise<any>;
52
+ declare const createPool: ({ chainId, baseToken, marketId }: CreatePoolRequest) => Promise<string | undefined>;
52
53
 
53
- declare const getMarketPoolId: ({ chainId, baseToken, marketId, }: CreatePoolRequest) => Promise<any>;
54
- declare const getMarketPools: (chainId: ChainId) => Promise<any>;
54
+ declare const getMarketPoolId: ({ chainId, baseToken, marketId, }: CreatePoolRequest) => Promise<string | undefined>;
55
+ declare const getMarketPools: (chainId: ChainId) => Promise<string[]>;
55
56
  declare const getPoolInfo$1: (chainId: ChainId, poolId: string, marketPrice?: bigint) => Promise<{
56
57
  quotePool: {
57
- poolToken: any;
58
- exchangeRate: any;
59
- poolTokenPrice: any;
60
- poolTokenSupply: any;
58
+ poolToken: string;
59
+ exchangeRate: bigint;
60
+ poolTokenPrice: bigint;
61
+ poolTokenSupply: bigint;
61
62
  };
62
63
  basePool: {
63
- poolToken: any;
64
- exchangeRate: any;
65
- poolTokenPrice: any;
66
- poolTokenSupply: any;
64
+ poolToken: string;
65
+ exchangeRate: bigint;
66
+ poolTokenPrice: bigint;
67
+ poolTokenSupply: bigint;
67
68
  };
68
69
  reserveInfo: {
69
- baseTotalAmount: any;
70
- baseReservedAmount: any;
71
- quoteTotalAmount: any;
72
- quoteReservedAmount: any;
70
+ baseTotalAmount: bigint;
71
+ baseReservedAmount: bigint;
72
+ quoteTotalAmount: bigint;
73
+ quoteReservedAmount: bigint;
73
74
  };
74
75
  fundingInfo: {
75
- nextFundingRate: any;
76
- lastFundingFeeTracker: any;
77
- nextEpochTime: any;
76
+ nextFundingRate: bigint;
77
+ lastFundingFeeTracker: bigint;
78
+ nextEpochTime: bigint;
78
79
  };
79
80
  ioTracker: {
80
- tracker: any;
81
- longSize: any;
82
- shortSize: any;
83
- poolEntryPrice: any;
81
+ tracker: bigint;
82
+ longSize: bigint;
83
+ shortSize: bigint;
84
+ poolEntryPrice: bigint;
84
85
  };
85
86
  }>;
86
87
 
87
- declare const getUserGenesisShare: (chainId: ChainId, tokenAddress: string, account: string) => Promise<any>;
88
+ declare const getUserGenesisShare: (chainId: ChainId, tokenAddress: string, account: string) => Promise<bigint>;
88
89
 
89
- declare const addTpSl: (params: AddTpSLParams) => Promise<any>;
90
+ declare const addTpSl: (params: AddTpSLParams) => Promise<ethers.ContractTransactionReceipt | null>;
90
91
 
91
- declare const cancelTpSl: (params: CancelTpSLParams) => Promise<any>;
92
+ declare const cancelTpSl: (params: CancelTpSLParams) => Promise<ethers.ContractTransactionReceipt | null>;
92
93
 
93
- declare const reprime: (chainId: ChainId, poolId: string, marketId: string) => Promise<any>;
94
+ declare const reprime: (chainId: ChainId, poolId: string, marketId: string) => Promise<ethers.ContractTransactionReceipt | null>;
94
95
 
95
96
  /**
96
97
  * Trading related types and enums
@@ -887,21 +888,21 @@ interface PreviewWithdrawDataParams {
887
888
  amount: string | number;
888
889
  }
889
890
 
890
- declare const claimBasePoolRebate: (params: ClaimParams) => Promise<any>;
891
- declare const claimBasePoolRebates: (params: ClaimRebatesParams) => Promise<any>;
891
+ declare const claimBasePoolRebate: (params: ClaimParams) => Promise<ethers.ContractTransactionResponse | undefined>;
892
+ declare const claimBasePoolRebates: (params: ClaimRebatesParams) => Promise<ethers.ContractTransactionResponse | undefined>;
892
893
 
893
- declare const deposit$1: (params: Deposit) => Promise<any>;
894
+ declare const deposit$1: (params: Deposit) => Promise<ethers.ContractTransactionResponse | undefined>;
894
895
 
895
- declare const withdraw$1: (params: WithdrawParams) => Promise<any>;
896
+ declare const withdraw$1: (params: WithdrawParams) => Promise<ethers.ContractTransactionReceipt | null | undefined>;
896
897
 
897
- declare const getRewards$1: (params: RewardsParams) => Promise<any>;
898
+ declare const getRewards$1: (params: RewardsParams) => Promise<bigint | undefined>;
898
899
 
899
900
  declare const previewUserWithdrawData: ({ chainId, account, poolId, amount }: PreviewWithdrawDataParams) => Promise<{
900
- baseAmountOut: any;
901
- rebateAmount: any;
901
+ baseAmountOut: bigint;
902
+ rebateAmount: bigint;
902
903
  } | undefined>;
903
904
 
904
- declare const getLpPrice$1: (chainId: ChainId, poolId: string) => Promise<any>;
905
+ declare const getLpPrice$1: (chainId: ChainId, poolId: string) => Promise<bigint | undefined>;
905
906
 
906
907
  declare const index$2_claimBasePoolRebate: typeof claimBasePoolRebate;
907
908
  declare const index$2_claimBasePoolRebates: typeof claimBasePoolRebates;
@@ -910,18 +911,18 @@ declare namespace index$2 {
910
911
  export { index$2_claimBasePoolRebate as claimBasePoolRebate, index$2_claimBasePoolRebates as claimBasePoolRebates, deposit$1 as deposit, getLpPrice$1 as getLpPrice, getRewards$1 as getRewards, index$2_previewUserWithdrawData as previewUserWithdrawData, withdraw$1 as withdraw };
911
912
  }
912
913
 
913
- declare const deposit: (params: Deposit) => Promise<any>;
914
+ declare const deposit: (params: Deposit) => Promise<ethers.ContractTransactionResponse | undefined>;
914
915
 
915
- declare const withdraw: (params: WithdrawParams) => Promise<any>;
916
+ declare const withdraw: (params: WithdrawParams) => Promise<ethers.ContractTransactionReceipt | null | undefined>;
916
917
 
917
- declare const transfer: (chainId: ChainId, fromPoolId: string, toPoolId: string, amount: number) => Promise<any>;
918
+ declare const transfer: (chainId: ChainId, fromPoolId: string, toPoolId: string, amount: number) => Promise<ethers.ContractTransactionResponse | null>;
918
919
 
919
- declare const getRewards: (params: RewardsParams) => Promise<any>;
920
+ declare const getRewards: (params: RewardsParams) => Promise<bigint | undefined>;
920
921
 
921
- declare const claimQuotePoolRebate: (params: ClaimParams) => Promise<any>;
922
- declare const claimQuotePoolRebates: (params: ClaimRebatesParams) => Promise<any>;
922
+ declare const claimQuotePoolRebate: (params: ClaimParams) => Promise<ethers.ContractTransactionResponse | undefined>;
923
+ declare const claimQuotePoolRebates: (params: ClaimRebatesParams) => Promise<ethers.ContractTransactionResponse | undefined>;
923
924
 
924
- declare const getLpPrice: (chainId: ChainId, poolId: string) => Promise<any>;
925
+ declare const getLpPrice: (chainId: ChainId, poolId: string) => Promise<bigint | undefined>;
925
926
 
926
927
  declare const index$1_claimQuotePoolRebate: typeof claimQuotePoolRebate;
927
928
  declare const index$1_claimQuotePoolRebates: typeof claimQuotePoolRebates;
@@ -934,9 +935,16 @@ declare namespace index$1 {
934
935
  export { index$1_claimQuotePoolRebate as claimQuotePoolRebate, index$1_claimQuotePoolRebates as claimQuotePoolRebates, index$1_deposit as deposit, index$1_getLpPrice as getLpPrice, index$1_getRewards as getRewards, index$1_transfer as transfer, index$1_withdraw as withdraw };
935
936
  }
936
937
 
937
- declare const getMarket: (chainId: ChainId, marketId: string) => Promise<any>;
938
+ declare const getMarket: (chainId: ChainId, marketId: string) => Promise<([string, bigint, bigint, bigint, bigint, bigint] & {
939
+ quoteToken: string;
940
+ baseReserveRatio: bigint;
941
+ quoteReserveRatio: bigint;
942
+ oracleFeeUsd: bigint;
943
+ oracleRefundFeeUsd: bigint;
944
+ poolPrimeThreshold: bigint;
945
+ }) | undefined>;
938
946
 
939
- declare const getOracleFee: (chainId: ChainId, marketId: string) => Promise<any>;
947
+ declare const getOracleFee: (chainId: ChainId, marketId: string) => Promise<bigint | undefined>;
940
948
 
941
949
  declare const index_getMarket: typeof getMarket;
942
950
  declare const index_getOracleFee: typeof getOracleFee;
@@ -979,9 +987,9 @@ declare const bigintAmountSlipperCalculator: (amount: bigint, slipper?: Number)
979
987
  declare const getTokenInfo: (chainId: number, tokenAddress: string, account?: string) => Promise<{
980
988
  balance?: number | undefined;
981
989
  address: string;
982
- name: any;
983
- symbol: any;
984
- decimals: any;
990
+ name: string;
991
+ symbol: string;
992
+ decimals: bigint;
985
993
  icon: string;
986
994
  totalSupply: number;
987
995
  }>;
@@ -1195,7 +1203,7 @@ interface MyxClientConfig {
1195
1203
  signer?: Signer;
1196
1204
  seamlessAccount?: {
1197
1205
  masterAddress: string;
1198
- wallet: ethers.Wallet | null;
1206
+ wallet: ethers$1.Wallet | null;
1199
1207
  authorized: boolean;
1200
1208
  };
1201
1209
  walletClient?: WalletClient;
@@ -1215,7 +1223,7 @@ declare class ConfigManager {
1215
1223
  clear(): void;
1216
1224
  startSeamlessMode(open: boolean): MyxClientConfig;
1217
1225
  updateSeamlessWallet({ wallet, authorized, masterAddress }: {
1218
- wallet?: ethers.Wallet;
1226
+ wallet?: ethers$1.Wallet;
1219
1227
  authorized?: boolean;
1220
1228
  masterAddress?: string;
1221
1229
  }): void;
@@ -1323,7 +1331,7 @@ declare class Utils {
1323
1331
  quoteAddress: string;
1324
1332
  amount?: string;
1325
1333
  spenderAddress?: string;
1326
- signer?: ethers.Signer;
1334
+ signer?: ethers$1.Signer;
1327
1335
  }): Promise<{
1328
1336
  code: number;
1329
1337
  message: any;
@@ -1430,8 +1438,10 @@ declare class Account {
1430
1438
  /**
1431
1439
  * get tradable amount
1432
1440
  */
1433
- getTradableAmount({ poolId }: {
1441
+ getTradableAmount({ poolId, chainId, address }: {
1434
1442
  poolId: string;
1443
+ chainId: number;
1444
+ address: string;
1435
1445
  }): Promise<{
1436
1446
  code: number;
1437
1447
  data: {
@@ -1443,6 +1453,11 @@ declare class Account {
1443
1453
  code: number;
1444
1454
  data?: undefined;
1445
1455
  }>;
1456
+ getAvailableMarginBalance({ poolId, chainId, address }: {
1457
+ poolId: string;
1458
+ chainId: number;
1459
+ address: string;
1460
+ }): Promise<bigint>;
1446
1461
  getTradeFlow(params: GetHistoryOrdersParams): Promise<{
1447
1462
  code: number;
1448
1463
  data: TradeFlowItem[];
@@ -1490,9 +1505,9 @@ declare class Seamless {
1490
1505
  private utils;
1491
1506
  private account;
1492
1507
  constructor(configManager: ConfigManager, logger: Logger, utils: Utils, account: Account);
1493
- onCheckRelayer(account: string, relayer: string): Promise<any>;
1508
+ onCheckRelayer(account: string, relayer: string): Promise<boolean>;
1494
1509
  getUSDPermitParams(deadline: number): Promise<{
1495
- token: string | ethers.Addressable;
1510
+ token: string | ethers$1.Addressable;
1496
1511
  owner: Promise<string> | undefined;
1497
1512
  spender: string;
1498
1513
  value: bigint;
@@ -1509,7 +1524,7 @@ declare class Seamless {
1509
1524
  deadline: number;
1510
1525
  data: string;
1511
1526
  nonce: string;
1512
- }, chainId: number, provider?: ethers.Signer): Promise<ApiResponse<any>>;
1527
+ }, chainId: number, provider?: ethers$1.Signer): Promise<ApiResponse<any>>;
1513
1528
  authorizeSeamlessAccount({ approve, seamlessAddress, chainId }: {
1514
1529
  approve: boolean;
1515
1530
  seamlessAddress: string;
@@ -1530,7 +1545,7 @@ declare class Seamless {
1530
1545
  data: {
1531
1546
  masterAddress: string;
1532
1547
  seamlessAccount: string;
1533
- authorized: any;
1548
+ authorized: boolean;
1534
1549
  };
1535
1550
  }>;
1536
1551
  exportSeamlessPrivateKey({ password, apiKey }: {
@@ -1548,9 +1563,9 @@ declare class Seamless {
1548
1563
  }): Promise<{
1549
1564
  code: number;
1550
1565
  data: {
1551
- masterAddress: any;
1566
+ masterAddress: string;
1552
1567
  seamlessAccount: string;
1553
- authorized: any;
1568
+ authorized: boolean;
1554
1569
  apiKey: string;
1555
1570
  };
1556
1571
  }>;
@@ -1570,7 +1585,7 @@ declare class Seamless {
1570
1585
  data: {
1571
1586
  masterAddress: string;
1572
1587
  seamlessAccount: string;
1573
- authorized: any;
1588
+ authorized: boolean;
1574
1589
  apiKey: string;
1575
1590
  };
1576
1591
  message?: undefined;
@@ -1647,7 +1662,7 @@ declare class Order {
1647
1662
  private seamless;
1648
1663
  private account;
1649
1664
  constructor(configManager: ConfigManager, logger: Logger, utils: Utils, seamless: Seamless, account: Account);
1650
- createIncreaseOrder(params: PlaceOrderParams): Promise<{
1665
+ createIncreaseOrder(params: PlaceOrderParams, tradingFee: string): Promise<{
1651
1666
  code: number;
1652
1667
  message: string;
1653
1668
  data: ApiResponse<any>;
@@ -1657,20 +1672,20 @@ declare class Order {
1657
1672
  data: {
1658
1673
  success: boolean;
1659
1674
  orderId: string | null;
1660
- transactionHash: any;
1661
- blockNumber: any;
1662
- gasUsed: any;
1675
+ transactionHash: string;
1676
+ blockNumber: number | undefined;
1677
+ gasUsed: string | undefined;
1663
1678
  status: string;
1664
1679
  confirmations: number;
1665
1680
  timestamp: number;
1666
- receipt: any;
1681
+ receipt: ethers$1.ContractTransactionReceipt | null;
1667
1682
  };
1668
1683
  } | {
1669
1684
  code: number;
1670
1685
  message: any;
1671
1686
  data?: undefined;
1672
1687
  }>;
1673
- closeAllPositions(chainId: number, params: PlaceOrderParams[]): Promise<{
1688
+ closeAllPositions(chainId: number, params: PlaceOrderParams[], tradingFee: string): Promise<{
1674
1689
  code: number;
1675
1690
  message: string;
1676
1691
  data: ApiResponse<any>;
@@ -1685,13 +1700,13 @@ declare class Order {
1685
1700
  code: number;
1686
1701
  message: string;
1687
1702
  data: string | null;
1688
- transactionHash: any;
1689
- blockNumber: any;
1690
- gasUsed: any;
1703
+ transactionHash: string;
1704
+ blockNumber: number | undefined;
1705
+ gasUsed: string | undefined;
1691
1706
  status: string;
1692
1707
  confirmations: number;
1693
1708
  timestamp: number;
1694
- receipt: any;
1709
+ receipt: ethers$1.ContractTransactionReceipt | null;
1695
1710
  } | {
1696
1711
  code: number;
1697
1712
  message: any;
@@ -1704,7 +1719,7 @@ declare class Order {
1704
1719
  timestamp?: undefined;
1705
1720
  receipt?: undefined;
1706
1721
  }>;
1707
- createDecreaseOrder(params: PlaceOrderParams): Promise<{
1722
+ createDecreaseOrder(params: PlaceOrderParams, tradingFee: string): Promise<{
1708
1723
  code: number;
1709
1724
  message: string;
1710
1725
  data: ApiResponse<any>;
@@ -1714,13 +1729,13 @@ declare class Order {
1714
1729
  data: {
1715
1730
  success: boolean;
1716
1731
  orderId: string | null;
1717
- transactionHash: any;
1718
- blockNumber: any;
1719
- gasUsed: any;
1732
+ transactionHash: string;
1733
+ blockNumber: number | undefined;
1734
+ gasUsed: string | undefined;
1720
1735
  status: string;
1721
1736
  confirmations: number;
1722
1737
  timestamp: number;
1723
- receipt: any;
1738
+ receipt: ethers$1.ContractTransactionReceipt | null;
1724
1739
  };
1725
1740
  } | {
1726
1741
  code: number;
@@ -1737,13 +1752,13 @@ declare class Order {
1737
1752
  data: {
1738
1753
  success: boolean;
1739
1754
  orderId: string | null;
1740
- transactionHash: any;
1741
- blockNumber: any;
1742
- gasUsed: any;
1755
+ transactionHash: string;
1756
+ blockNumber: number | undefined;
1757
+ gasUsed: string | undefined;
1743
1758
  status: string;
1744
1759
  confirmations: number;
1745
1760
  timestamp: number;
1746
- receipt: any;
1761
+ receipt: ethers$1.ContractTransactionReceipt | null;
1747
1762
  };
1748
1763
  } | {
1749
1764
  code: number;
@@ -1769,7 +1784,7 @@ declare class Order {
1769
1784
  }>;
1770
1785
  updateOrderTpSl(params: UpdateOrderParams, quoteAddress: string, chainId: number): Promise<{
1771
1786
  code: number;
1772
- data: any;
1787
+ data: ethers$1.ContractTransactionReceipt | null;
1773
1788
  message: string;
1774
1789
  } | {
1775
1790
  code: number;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { AddressLike, Signer, ethers } from 'ethers';
1
+ import * as ethers from 'ethers';
2
+ import { AddressLike, Signer, ethers as ethers$1 } from 'ethers';
2
3
  export { formatUnits, parseUnits } from 'ethers';
3
4
  import { Options, Event } from 'reconnecting-websocket';
4
5
  import { WalletClient } from 'viem';
@@ -48,49 +49,49 @@ interface CancelTpSLParams {
48
49
  orderId: string;
49
50
  }
50
51
 
51
- declare const createPool: ({ chainId, baseToken, marketId }: CreatePoolRequest) => Promise<any>;
52
+ declare const createPool: ({ chainId, baseToken, marketId }: CreatePoolRequest) => Promise<string | undefined>;
52
53
 
53
- declare const getMarketPoolId: ({ chainId, baseToken, marketId, }: CreatePoolRequest) => Promise<any>;
54
- declare const getMarketPools: (chainId: ChainId) => Promise<any>;
54
+ declare const getMarketPoolId: ({ chainId, baseToken, marketId, }: CreatePoolRequest) => Promise<string | undefined>;
55
+ declare const getMarketPools: (chainId: ChainId) => Promise<string[]>;
55
56
  declare const getPoolInfo$1: (chainId: ChainId, poolId: string, marketPrice?: bigint) => Promise<{
56
57
  quotePool: {
57
- poolToken: any;
58
- exchangeRate: any;
59
- poolTokenPrice: any;
60
- poolTokenSupply: any;
58
+ poolToken: string;
59
+ exchangeRate: bigint;
60
+ poolTokenPrice: bigint;
61
+ poolTokenSupply: bigint;
61
62
  };
62
63
  basePool: {
63
- poolToken: any;
64
- exchangeRate: any;
65
- poolTokenPrice: any;
66
- poolTokenSupply: any;
64
+ poolToken: string;
65
+ exchangeRate: bigint;
66
+ poolTokenPrice: bigint;
67
+ poolTokenSupply: bigint;
67
68
  };
68
69
  reserveInfo: {
69
- baseTotalAmount: any;
70
- baseReservedAmount: any;
71
- quoteTotalAmount: any;
72
- quoteReservedAmount: any;
70
+ baseTotalAmount: bigint;
71
+ baseReservedAmount: bigint;
72
+ quoteTotalAmount: bigint;
73
+ quoteReservedAmount: bigint;
73
74
  };
74
75
  fundingInfo: {
75
- nextFundingRate: any;
76
- lastFundingFeeTracker: any;
77
- nextEpochTime: any;
76
+ nextFundingRate: bigint;
77
+ lastFundingFeeTracker: bigint;
78
+ nextEpochTime: bigint;
78
79
  };
79
80
  ioTracker: {
80
- tracker: any;
81
- longSize: any;
82
- shortSize: any;
83
- poolEntryPrice: any;
81
+ tracker: bigint;
82
+ longSize: bigint;
83
+ shortSize: bigint;
84
+ poolEntryPrice: bigint;
84
85
  };
85
86
  }>;
86
87
 
87
- declare const getUserGenesisShare: (chainId: ChainId, tokenAddress: string, account: string) => Promise<any>;
88
+ declare const getUserGenesisShare: (chainId: ChainId, tokenAddress: string, account: string) => Promise<bigint>;
88
89
 
89
- declare const addTpSl: (params: AddTpSLParams) => Promise<any>;
90
+ declare const addTpSl: (params: AddTpSLParams) => Promise<ethers.ContractTransactionReceipt | null>;
90
91
 
91
- declare const cancelTpSl: (params: CancelTpSLParams) => Promise<any>;
92
+ declare const cancelTpSl: (params: CancelTpSLParams) => Promise<ethers.ContractTransactionReceipt | null>;
92
93
 
93
- declare const reprime: (chainId: ChainId, poolId: string, marketId: string) => Promise<any>;
94
+ declare const reprime: (chainId: ChainId, poolId: string, marketId: string) => Promise<ethers.ContractTransactionReceipt | null>;
94
95
 
95
96
  /**
96
97
  * Trading related types and enums
@@ -887,21 +888,21 @@ interface PreviewWithdrawDataParams {
887
888
  amount: string | number;
888
889
  }
889
890
 
890
- declare const claimBasePoolRebate: (params: ClaimParams) => Promise<any>;
891
- declare const claimBasePoolRebates: (params: ClaimRebatesParams) => Promise<any>;
891
+ declare const claimBasePoolRebate: (params: ClaimParams) => Promise<ethers.ContractTransactionResponse | undefined>;
892
+ declare const claimBasePoolRebates: (params: ClaimRebatesParams) => Promise<ethers.ContractTransactionResponse | undefined>;
892
893
 
893
- declare const deposit$1: (params: Deposit) => Promise<any>;
894
+ declare const deposit$1: (params: Deposit) => Promise<ethers.ContractTransactionResponse | undefined>;
894
895
 
895
- declare const withdraw$1: (params: WithdrawParams) => Promise<any>;
896
+ declare const withdraw$1: (params: WithdrawParams) => Promise<ethers.ContractTransactionReceipt | null | undefined>;
896
897
 
897
- declare const getRewards$1: (params: RewardsParams) => Promise<any>;
898
+ declare const getRewards$1: (params: RewardsParams) => Promise<bigint | undefined>;
898
899
 
899
900
  declare const previewUserWithdrawData: ({ chainId, account, poolId, amount }: PreviewWithdrawDataParams) => Promise<{
900
- baseAmountOut: any;
901
- rebateAmount: any;
901
+ baseAmountOut: bigint;
902
+ rebateAmount: bigint;
902
903
  } | undefined>;
903
904
 
904
- declare const getLpPrice$1: (chainId: ChainId, poolId: string) => Promise<any>;
905
+ declare const getLpPrice$1: (chainId: ChainId, poolId: string) => Promise<bigint | undefined>;
905
906
 
906
907
  declare const index$2_claimBasePoolRebate: typeof claimBasePoolRebate;
907
908
  declare const index$2_claimBasePoolRebates: typeof claimBasePoolRebates;
@@ -910,18 +911,18 @@ declare namespace index$2 {
910
911
  export { index$2_claimBasePoolRebate as claimBasePoolRebate, index$2_claimBasePoolRebates as claimBasePoolRebates, deposit$1 as deposit, getLpPrice$1 as getLpPrice, getRewards$1 as getRewards, index$2_previewUserWithdrawData as previewUserWithdrawData, withdraw$1 as withdraw };
911
912
  }
912
913
 
913
- declare const deposit: (params: Deposit) => Promise<any>;
914
+ declare const deposit: (params: Deposit) => Promise<ethers.ContractTransactionResponse | undefined>;
914
915
 
915
- declare const withdraw: (params: WithdrawParams) => Promise<any>;
916
+ declare const withdraw: (params: WithdrawParams) => Promise<ethers.ContractTransactionReceipt | null | undefined>;
916
917
 
917
- declare const transfer: (chainId: ChainId, fromPoolId: string, toPoolId: string, amount: number) => Promise<any>;
918
+ declare const transfer: (chainId: ChainId, fromPoolId: string, toPoolId: string, amount: number) => Promise<ethers.ContractTransactionResponse | null>;
918
919
 
919
- declare const getRewards: (params: RewardsParams) => Promise<any>;
920
+ declare const getRewards: (params: RewardsParams) => Promise<bigint | undefined>;
920
921
 
921
- declare const claimQuotePoolRebate: (params: ClaimParams) => Promise<any>;
922
- declare const claimQuotePoolRebates: (params: ClaimRebatesParams) => Promise<any>;
922
+ declare const claimQuotePoolRebate: (params: ClaimParams) => Promise<ethers.ContractTransactionResponse | undefined>;
923
+ declare const claimQuotePoolRebates: (params: ClaimRebatesParams) => Promise<ethers.ContractTransactionResponse | undefined>;
923
924
 
924
- declare const getLpPrice: (chainId: ChainId, poolId: string) => Promise<any>;
925
+ declare const getLpPrice: (chainId: ChainId, poolId: string) => Promise<bigint | undefined>;
925
926
 
926
927
  declare const index$1_claimQuotePoolRebate: typeof claimQuotePoolRebate;
927
928
  declare const index$1_claimQuotePoolRebates: typeof claimQuotePoolRebates;
@@ -934,9 +935,16 @@ declare namespace index$1 {
934
935
  export { index$1_claimQuotePoolRebate as claimQuotePoolRebate, index$1_claimQuotePoolRebates as claimQuotePoolRebates, index$1_deposit as deposit, index$1_getLpPrice as getLpPrice, index$1_getRewards as getRewards, index$1_transfer as transfer, index$1_withdraw as withdraw };
935
936
  }
936
937
 
937
- declare const getMarket: (chainId: ChainId, marketId: string) => Promise<any>;
938
+ declare const getMarket: (chainId: ChainId, marketId: string) => Promise<([string, bigint, bigint, bigint, bigint, bigint] & {
939
+ quoteToken: string;
940
+ baseReserveRatio: bigint;
941
+ quoteReserveRatio: bigint;
942
+ oracleFeeUsd: bigint;
943
+ oracleRefundFeeUsd: bigint;
944
+ poolPrimeThreshold: bigint;
945
+ }) | undefined>;
938
946
 
939
- declare const getOracleFee: (chainId: ChainId, marketId: string) => Promise<any>;
947
+ declare const getOracleFee: (chainId: ChainId, marketId: string) => Promise<bigint | undefined>;
940
948
 
941
949
  declare const index_getMarket: typeof getMarket;
942
950
  declare const index_getOracleFee: typeof getOracleFee;
@@ -979,9 +987,9 @@ declare const bigintAmountSlipperCalculator: (amount: bigint, slipper?: Number)
979
987
  declare const getTokenInfo: (chainId: number, tokenAddress: string, account?: string) => Promise<{
980
988
  balance?: number | undefined;
981
989
  address: string;
982
- name: any;
983
- symbol: any;
984
- decimals: any;
990
+ name: string;
991
+ symbol: string;
992
+ decimals: bigint;
985
993
  icon: string;
986
994
  totalSupply: number;
987
995
  }>;
@@ -1195,7 +1203,7 @@ interface MyxClientConfig {
1195
1203
  signer?: Signer;
1196
1204
  seamlessAccount?: {
1197
1205
  masterAddress: string;
1198
- wallet: ethers.Wallet | null;
1206
+ wallet: ethers$1.Wallet | null;
1199
1207
  authorized: boolean;
1200
1208
  };
1201
1209
  walletClient?: WalletClient;
@@ -1215,7 +1223,7 @@ declare class ConfigManager {
1215
1223
  clear(): void;
1216
1224
  startSeamlessMode(open: boolean): MyxClientConfig;
1217
1225
  updateSeamlessWallet({ wallet, authorized, masterAddress }: {
1218
- wallet?: ethers.Wallet;
1226
+ wallet?: ethers$1.Wallet;
1219
1227
  authorized?: boolean;
1220
1228
  masterAddress?: string;
1221
1229
  }): void;
@@ -1323,7 +1331,7 @@ declare class Utils {
1323
1331
  quoteAddress: string;
1324
1332
  amount?: string;
1325
1333
  spenderAddress?: string;
1326
- signer?: ethers.Signer;
1334
+ signer?: ethers$1.Signer;
1327
1335
  }): Promise<{
1328
1336
  code: number;
1329
1337
  message: any;
@@ -1430,8 +1438,10 @@ declare class Account {
1430
1438
  /**
1431
1439
  * get tradable amount
1432
1440
  */
1433
- getTradableAmount({ poolId }: {
1441
+ getTradableAmount({ poolId, chainId, address }: {
1434
1442
  poolId: string;
1443
+ chainId: number;
1444
+ address: string;
1435
1445
  }): Promise<{
1436
1446
  code: number;
1437
1447
  data: {
@@ -1443,6 +1453,11 @@ declare class Account {
1443
1453
  code: number;
1444
1454
  data?: undefined;
1445
1455
  }>;
1456
+ getAvailableMarginBalance({ poolId, chainId, address }: {
1457
+ poolId: string;
1458
+ chainId: number;
1459
+ address: string;
1460
+ }): Promise<bigint>;
1446
1461
  getTradeFlow(params: GetHistoryOrdersParams): Promise<{
1447
1462
  code: number;
1448
1463
  data: TradeFlowItem[];
@@ -1490,9 +1505,9 @@ declare class Seamless {
1490
1505
  private utils;
1491
1506
  private account;
1492
1507
  constructor(configManager: ConfigManager, logger: Logger, utils: Utils, account: Account);
1493
- onCheckRelayer(account: string, relayer: string): Promise<any>;
1508
+ onCheckRelayer(account: string, relayer: string): Promise<boolean>;
1494
1509
  getUSDPermitParams(deadline: number): Promise<{
1495
- token: string | ethers.Addressable;
1510
+ token: string | ethers$1.Addressable;
1496
1511
  owner: Promise<string> | undefined;
1497
1512
  spender: string;
1498
1513
  value: bigint;
@@ -1509,7 +1524,7 @@ declare class Seamless {
1509
1524
  deadline: number;
1510
1525
  data: string;
1511
1526
  nonce: string;
1512
- }, chainId: number, provider?: ethers.Signer): Promise<ApiResponse<any>>;
1527
+ }, chainId: number, provider?: ethers$1.Signer): Promise<ApiResponse<any>>;
1513
1528
  authorizeSeamlessAccount({ approve, seamlessAddress, chainId }: {
1514
1529
  approve: boolean;
1515
1530
  seamlessAddress: string;
@@ -1530,7 +1545,7 @@ declare class Seamless {
1530
1545
  data: {
1531
1546
  masterAddress: string;
1532
1547
  seamlessAccount: string;
1533
- authorized: any;
1548
+ authorized: boolean;
1534
1549
  };
1535
1550
  }>;
1536
1551
  exportSeamlessPrivateKey({ password, apiKey }: {
@@ -1548,9 +1563,9 @@ declare class Seamless {
1548
1563
  }): Promise<{
1549
1564
  code: number;
1550
1565
  data: {
1551
- masterAddress: any;
1566
+ masterAddress: string;
1552
1567
  seamlessAccount: string;
1553
- authorized: any;
1568
+ authorized: boolean;
1554
1569
  apiKey: string;
1555
1570
  };
1556
1571
  }>;
@@ -1570,7 +1585,7 @@ declare class Seamless {
1570
1585
  data: {
1571
1586
  masterAddress: string;
1572
1587
  seamlessAccount: string;
1573
- authorized: any;
1588
+ authorized: boolean;
1574
1589
  apiKey: string;
1575
1590
  };
1576
1591
  message?: undefined;
@@ -1647,7 +1662,7 @@ declare class Order {
1647
1662
  private seamless;
1648
1663
  private account;
1649
1664
  constructor(configManager: ConfigManager, logger: Logger, utils: Utils, seamless: Seamless, account: Account);
1650
- createIncreaseOrder(params: PlaceOrderParams): Promise<{
1665
+ createIncreaseOrder(params: PlaceOrderParams, tradingFee: string): Promise<{
1651
1666
  code: number;
1652
1667
  message: string;
1653
1668
  data: ApiResponse<any>;
@@ -1657,20 +1672,20 @@ declare class Order {
1657
1672
  data: {
1658
1673
  success: boolean;
1659
1674
  orderId: string | null;
1660
- transactionHash: any;
1661
- blockNumber: any;
1662
- gasUsed: any;
1675
+ transactionHash: string;
1676
+ blockNumber: number | undefined;
1677
+ gasUsed: string | undefined;
1663
1678
  status: string;
1664
1679
  confirmations: number;
1665
1680
  timestamp: number;
1666
- receipt: any;
1681
+ receipt: ethers$1.ContractTransactionReceipt | null;
1667
1682
  };
1668
1683
  } | {
1669
1684
  code: number;
1670
1685
  message: any;
1671
1686
  data?: undefined;
1672
1687
  }>;
1673
- closeAllPositions(chainId: number, params: PlaceOrderParams[]): Promise<{
1688
+ closeAllPositions(chainId: number, params: PlaceOrderParams[], tradingFee: string): Promise<{
1674
1689
  code: number;
1675
1690
  message: string;
1676
1691
  data: ApiResponse<any>;
@@ -1685,13 +1700,13 @@ declare class Order {
1685
1700
  code: number;
1686
1701
  message: string;
1687
1702
  data: string | null;
1688
- transactionHash: any;
1689
- blockNumber: any;
1690
- gasUsed: any;
1703
+ transactionHash: string;
1704
+ blockNumber: number | undefined;
1705
+ gasUsed: string | undefined;
1691
1706
  status: string;
1692
1707
  confirmations: number;
1693
1708
  timestamp: number;
1694
- receipt: any;
1709
+ receipt: ethers$1.ContractTransactionReceipt | null;
1695
1710
  } | {
1696
1711
  code: number;
1697
1712
  message: any;
@@ -1704,7 +1719,7 @@ declare class Order {
1704
1719
  timestamp?: undefined;
1705
1720
  receipt?: undefined;
1706
1721
  }>;
1707
- createDecreaseOrder(params: PlaceOrderParams): Promise<{
1722
+ createDecreaseOrder(params: PlaceOrderParams, tradingFee: string): Promise<{
1708
1723
  code: number;
1709
1724
  message: string;
1710
1725
  data: ApiResponse<any>;
@@ -1714,13 +1729,13 @@ declare class Order {
1714
1729
  data: {
1715
1730
  success: boolean;
1716
1731
  orderId: string | null;
1717
- transactionHash: any;
1718
- blockNumber: any;
1719
- gasUsed: any;
1732
+ transactionHash: string;
1733
+ blockNumber: number | undefined;
1734
+ gasUsed: string | undefined;
1720
1735
  status: string;
1721
1736
  confirmations: number;
1722
1737
  timestamp: number;
1723
- receipt: any;
1738
+ receipt: ethers$1.ContractTransactionReceipt | null;
1724
1739
  };
1725
1740
  } | {
1726
1741
  code: number;
@@ -1737,13 +1752,13 @@ declare class Order {
1737
1752
  data: {
1738
1753
  success: boolean;
1739
1754
  orderId: string | null;
1740
- transactionHash: any;
1741
- blockNumber: any;
1742
- gasUsed: any;
1755
+ transactionHash: string;
1756
+ blockNumber: number | undefined;
1757
+ gasUsed: string | undefined;
1743
1758
  status: string;
1744
1759
  confirmations: number;
1745
1760
  timestamp: number;
1746
- receipt: any;
1761
+ receipt: ethers$1.ContractTransactionReceipt | null;
1747
1762
  };
1748
1763
  } | {
1749
1764
  code: number;
@@ -1769,7 +1784,7 @@ declare class Order {
1769
1784
  }>;
1770
1785
  updateOrderTpSl(params: UpdateOrderParams, quoteAddress: string, chainId: number): Promise<{
1771
1786
  code: number;
1772
- data: any;
1787
+ data: ethers$1.ContractTransactionReceipt | null;
1773
1788
  message: string;
1774
1789
  } | {
1775
1790
  code: number;
package/dist/index.js CHANGED
@@ -1822,7 +1822,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1822
1822
  // package.json
1823
1823
  var package_default = {
1824
1824
  name: "@myx-trade/sdk",
1825
- version: "0.1.132",
1825
+ version: "0.1.134",
1826
1826
  private: false,
1827
1827
  publishConfig: {
1828
1828
  access: "public"
@@ -14292,34 +14292,35 @@ var Order = class {
14292
14292
  this.seamless = seamless;
14293
14293
  this.account = account;
14294
14294
  }
14295
- async createIncreaseOrder(params) {
14295
+ async createIncreaseOrder(params, tradingFee) {
14296
14296
  try {
14297
14297
  const config = this.configManager.getConfig();
14298
14298
  const networkFee = await this.utils.getNetworkFee(
14299
14299
  params.executionFeeToken,
14300
14300
  params.chainId
14301
14301
  );
14302
+ let totalNetWorkFee = BigInt(networkFee);
14303
+ if (params.tpSize) {
14304
+ totalNetWorkFee += BigInt(networkFee);
14305
+ }
14306
+ if (params.slSize) {
14307
+ totalNetWorkFee += BigInt(networkFee);
14308
+ }
14302
14309
  const needsApproval = await this.utils.needsApproval(
14303
14310
  params.chainId,
14304
14311
  params.executionFeeToken,
14305
14312
  params.collateralAmount
14306
14313
  );
14307
- const marginAccountBalanceRes = await this.account.getTradableAmount({ poolId: params.poolId });
14308
- const marginAccountBalance = marginAccountBalanceRes?.data;
14309
- if (marginAccountBalanceRes.code !== 0) {
14310
- return {
14311
- code: -1,
14312
- message: "Failed to get tradable amount or wallet balance"
14313
- };
14314
- }
14315
- const totalBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + (!marginAccountBalance?.tradeableProfit ? BigInt(marginAccountBalance?.tradeableProfit) : BigInt(0));
14316
- let depositAmount = BigInt(networkFee) + BigInt(params.collateralAmount);
14317
- if (totalBalance > 0) {
14318
- depositAmount = depositAmount - totalBalance;
14314
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
14315
+ const needAmount = BigInt(tradingFee) + BigInt(params.collateralAmount) + totalNetWorkFee;
14316
+ let depositAmount = BigInt(0);
14317
+ const diff = needAmount - availableAccountMarginBalance;
14318
+ if (diff > BigInt(0)) {
14319
+ depositAmount = diff;
14319
14320
  }
14320
14321
  const depositData = {
14321
14322
  token: params.executionFeeToken,
14322
- amount: depositAmount > BigInt(0) ? (depositAmount + BigInt(networkFee)).toString() : networkFee
14323
+ amount: depositAmount.toString()
14323
14324
  };
14324
14325
  const data = {
14325
14326
  user: params.address,
@@ -14483,17 +14484,20 @@ var Order = class {
14483
14484
  };
14484
14485
  }
14485
14486
  }
14486
- async closeAllPositions(chainId, params) {
14487
+ async closeAllPositions(chainId, params, tradingFee) {
14487
14488
  try {
14488
14489
  const config = this.configManager.getConfig();
14489
- if (!config.signer) {
14490
- throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14491
- }
14490
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params[0].poolId, chainId, address: params[0].address });
14492
14491
  const networkFee = await this.utils.getNetworkFee(
14493
14492
  params[0].executionFeeToken,
14494
14493
  chainId
14495
14494
  );
14496
- const depositAmount = BigInt(params.length) * BigInt(networkFee);
14495
+ const tradingFeeAmount = BigInt(tradingFee) * BigInt(params.length);
14496
+ const needAmount = tradingFeeAmount + BigInt(params.length) * BigInt(networkFee);
14497
+ let depositAmount = BigInt(0);
14498
+ if (availableAccountMarginBalance < needAmount) {
14499
+ depositAmount = needAmount - availableAccountMarginBalance;
14500
+ }
14497
14501
  const needsApproval = await this.utils.needsApproval(
14498
14502
  chainId,
14499
14503
  params[0].executionFeeToken,
@@ -14570,6 +14574,9 @@ var Order = class {
14570
14574
  data: rs
14571
14575
  };
14572
14576
  }
14577
+ if (!config.signer) {
14578
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14579
+ }
14573
14580
  const brokerContract = await getBrokerSingerContract(
14574
14581
  chainId,
14575
14582
  this.configManager.getConfig().brokerAddress
@@ -14614,17 +14621,19 @@ var Order = class {
14614
14621
  };
14615
14622
  }
14616
14623
  }
14617
- async createDecreaseOrder(params) {
14624
+ async createDecreaseOrder(params, tradingFee) {
14618
14625
  try {
14619
14626
  const config = this.configManager.getConfig();
14620
- const brokerContract = await getBrokerSingerContract(
14621
- params.chainId,
14622
- this.configManager.getConfig().brokerAddress
14623
- );
14624
14627
  const networkFee = await this.utils.getNetworkFee(
14625
14628
  params.executionFeeToken,
14626
14629
  params.chainId
14627
14630
  );
14631
+ let depositAmount = BigInt(0);
14632
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
14633
+ const needAmount = BigInt(tradingFee) + BigInt(networkFee);
14634
+ if (availableAccountMarginBalance < needAmount) {
14635
+ depositAmount = needAmount - availableAccountMarginBalance;
14636
+ }
14628
14637
  const data = {
14629
14638
  user: params.address,
14630
14639
  poolId: params.poolId,
@@ -14647,12 +14656,12 @@ var Order = class {
14647
14656
  };
14648
14657
  const depositData = {
14649
14658
  token: params.executionFeeToken,
14650
- amount: networkFee
14659
+ amount: depositAmount.toString()
14651
14660
  };
14652
14661
  const needsApproval = await this.utils.needsApproval(
14653
14662
  params.chainId,
14654
14663
  params.executionFeeToken,
14655
- networkFee.toString()
14664
+ depositAmount.toString()
14656
14665
  );
14657
14666
  const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14658
14667
  const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
@@ -14703,13 +14712,16 @@ var Order = class {
14703
14712
  };
14704
14713
  this.logger.info("create decrease order forward tx params --->", forwardTxParams);
14705
14714
  const rs = await this.seamless.forwarderTx(forwardTxParams, params.chainId, seamlessWallet);
14706
- console.log("rs-->", rs);
14707
14715
  return {
14708
14716
  code: 0,
14709
14717
  message: "create decrease order success",
14710
14718
  data: rs
14711
14719
  };
14712
14720
  }
14721
+ const brokerContract = await getBrokerSingerContract(
14722
+ params.chainId,
14723
+ this.configManager.getConfig().brokerAddress
14724
+ );
14713
14725
  if (!config.signer) {
14714
14726
  throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14715
14727
  }
@@ -14725,16 +14737,12 @@ var Order = class {
14725
14737
  }
14726
14738
  let transaction;
14727
14739
  if (!params.positionId) {
14728
- const depositData2 = {
14729
- token: params.executionFeeToken,
14730
- amount: networkFee
14731
- };
14732
14740
  const positionId = 1;
14733
14741
  this.logger.info("createDecreaseOrder salt position params--->", [positionId, { data }]);
14734
- const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData2, data);
14742
+ const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData, data);
14735
14743
  transaction = await brokerContract.placeOrderWithSalt(
14736
14744
  positionId.toString(),
14737
- depositData2,
14745
+ depositData,
14738
14746
  data,
14739
14747
  {
14740
14748
  gasLimit: gasLimit * 130n / 100n
@@ -21008,24 +21016,16 @@ var Account = class {
21008
21016
  /**
21009
21017
  * get tradable amount
21010
21018
  */
21011
- async getTradableAmount({ poolId }) {
21012
- const config = this.configManager.getConfig();
21013
- if (!config.signer) {
21014
- throw new MyxSDKError(
21015
- "INVALID_SIGNER" /* InvalidSigner */,
21016
- "Invalid signer"
21017
- );
21018
- }
21019
- const contractAddress = getContractAddressByChainId(config.chainId);
21020
- const provider = await getJSONProvider(config.chainId);
21019
+ async getTradableAmount({ poolId, chainId, address }) {
21020
+ const contractAddress = getContractAddressByChainId(chainId);
21021
+ const provider = await getJSONProvider(chainId);
21021
21022
  const accountContract = new import_ethers26.ethers.Contract(
21022
21023
  contractAddress.Account,
21023
21024
  Account_default,
21024
21025
  provider
21025
21026
  );
21026
21027
  try {
21027
- const targetAddress = config.seamlessMode ? config.seamlessAccount?.masterAddress : config.signer?.getAddress();
21028
- const assets = await accountContract.getTradableAmount(targetAddress, poolId);
21028
+ const assets = await accountContract.getTradableAmount(address, poolId);
21029
21029
  const data = {
21030
21030
  profitIsReleased: assets[0],
21031
21031
  freeAmount: assets[1],
@@ -21041,6 +21041,18 @@ var Account = class {
21041
21041
  };
21042
21042
  }
21043
21043
  }
21044
+ async getAvailableMarginBalance({ poolId, chainId, address }) {
21045
+ const marginAccountBalanceRes = await this.getTradableAmount({ poolId, chainId, address });
21046
+ const marginAccountBalance = marginAccountBalanceRes?.data;
21047
+ if (marginAccountBalanceRes.code !== 0) {
21048
+ throw new MyxSDKError(
21049
+ "INSUFFICIENT_MARGIN_BALANCE" /* InsufficientMarginBalance */,
21050
+ "Insufficient margin balance"
21051
+ );
21052
+ }
21053
+ const availableAccountMarginBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + (!marginAccountBalance?.tradeableProfit ? BigInt(marginAccountBalance?.tradeableProfit) : BigInt(0));
21054
+ return availableAccountMarginBalance;
21055
+ }
21044
21056
  async getTradeFlow(params) {
21045
21057
  const accessToken = await this.configManager.getAccessToken();
21046
21058
  if (!accessToken) {
package/dist/index.mjs CHANGED
@@ -1732,7 +1732,7 @@ var RotationProvider = class extends BaseProvider {
1732
1732
  // package.json
1733
1733
  var package_default = {
1734
1734
  name: "@myx-trade/sdk",
1735
- version: "0.1.132",
1735
+ version: "0.1.134",
1736
1736
  private: false,
1737
1737
  publishConfig: {
1738
1738
  access: "public"
@@ -14202,34 +14202,35 @@ var Order = class {
14202
14202
  this.seamless = seamless;
14203
14203
  this.account = account;
14204
14204
  }
14205
- async createIncreaseOrder(params) {
14205
+ async createIncreaseOrder(params, tradingFee) {
14206
14206
  try {
14207
14207
  const config = this.configManager.getConfig();
14208
14208
  const networkFee = await this.utils.getNetworkFee(
14209
14209
  params.executionFeeToken,
14210
14210
  params.chainId
14211
14211
  );
14212
+ let totalNetWorkFee = BigInt(networkFee);
14213
+ if (params.tpSize) {
14214
+ totalNetWorkFee += BigInt(networkFee);
14215
+ }
14216
+ if (params.slSize) {
14217
+ totalNetWorkFee += BigInt(networkFee);
14218
+ }
14212
14219
  const needsApproval = await this.utils.needsApproval(
14213
14220
  params.chainId,
14214
14221
  params.executionFeeToken,
14215
14222
  params.collateralAmount
14216
14223
  );
14217
- const marginAccountBalanceRes = await this.account.getTradableAmount({ poolId: params.poolId });
14218
- const marginAccountBalance = marginAccountBalanceRes?.data;
14219
- if (marginAccountBalanceRes.code !== 0) {
14220
- return {
14221
- code: -1,
14222
- message: "Failed to get tradable amount or wallet balance"
14223
- };
14224
- }
14225
- const totalBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + (!marginAccountBalance?.tradeableProfit ? BigInt(marginAccountBalance?.tradeableProfit) : BigInt(0));
14226
- let depositAmount = BigInt(networkFee) + BigInt(params.collateralAmount);
14227
- if (totalBalance > 0) {
14228
- depositAmount = depositAmount - totalBalance;
14224
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
14225
+ const needAmount = BigInt(tradingFee) + BigInt(params.collateralAmount) + totalNetWorkFee;
14226
+ let depositAmount = BigInt(0);
14227
+ const diff = needAmount - availableAccountMarginBalance;
14228
+ if (diff > BigInt(0)) {
14229
+ depositAmount = diff;
14229
14230
  }
14230
14231
  const depositData = {
14231
14232
  token: params.executionFeeToken,
14232
- amount: depositAmount > BigInt(0) ? (depositAmount + BigInt(networkFee)).toString() : networkFee
14233
+ amount: depositAmount.toString()
14233
14234
  };
14234
14235
  const data = {
14235
14236
  user: params.address,
@@ -14393,17 +14394,20 @@ var Order = class {
14393
14394
  };
14394
14395
  }
14395
14396
  }
14396
- async closeAllPositions(chainId, params) {
14397
+ async closeAllPositions(chainId, params, tradingFee) {
14397
14398
  try {
14398
14399
  const config = this.configManager.getConfig();
14399
- if (!config.signer) {
14400
- throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14401
- }
14400
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params[0].poolId, chainId, address: params[0].address });
14402
14401
  const networkFee = await this.utils.getNetworkFee(
14403
14402
  params[0].executionFeeToken,
14404
14403
  chainId
14405
14404
  );
14406
- const depositAmount = BigInt(params.length) * BigInt(networkFee);
14405
+ const tradingFeeAmount = BigInt(tradingFee) * BigInt(params.length);
14406
+ const needAmount = tradingFeeAmount + BigInt(params.length) * BigInt(networkFee);
14407
+ let depositAmount = BigInt(0);
14408
+ if (availableAccountMarginBalance < needAmount) {
14409
+ depositAmount = needAmount - availableAccountMarginBalance;
14410
+ }
14407
14411
  const needsApproval = await this.utils.needsApproval(
14408
14412
  chainId,
14409
14413
  params[0].executionFeeToken,
@@ -14480,6 +14484,9 @@ var Order = class {
14480
14484
  data: rs
14481
14485
  };
14482
14486
  }
14487
+ if (!config.signer) {
14488
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14489
+ }
14483
14490
  const brokerContract = await getBrokerSingerContract(
14484
14491
  chainId,
14485
14492
  this.configManager.getConfig().brokerAddress
@@ -14524,17 +14531,19 @@ var Order = class {
14524
14531
  };
14525
14532
  }
14526
14533
  }
14527
- async createDecreaseOrder(params) {
14534
+ async createDecreaseOrder(params, tradingFee) {
14528
14535
  try {
14529
14536
  const config = this.configManager.getConfig();
14530
- const brokerContract = await getBrokerSingerContract(
14531
- params.chainId,
14532
- this.configManager.getConfig().brokerAddress
14533
- );
14534
14537
  const networkFee = await this.utils.getNetworkFee(
14535
14538
  params.executionFeeToken,
14536
14539
  params.chainId
14537
14540
  );
14541
+ let depositAmount = BigInt(0);
14542
+ const availableAccountMarginBalance = await this.account.getAvailableMarginBalance({ poolId: params.poolId, chainId: params.chainId, address: params.address });
14543
+ const needAmount = BigInt(tradingFee) + BigInt(networkFee);
14544
+ if (availableAccountMarginBalance < needAmount) {
14545
+ depositAmount = needAmount - availableAccountMarginBalance;
14546
+ }
14538
14547
  const data = {
14539
14548
  user: params.address,
14540
14549
  poolId: params.poolId,
@@ -14557,12 +14566,12 @@ var Order = class {
14557
14566
  };
14558
14567
  const depositData = {
14559
14568
  token: params.executionFeeToken,
14560
- amount: networkFee
14569
+ amount: depositAmount.toString()
14561
14570
  };
14562
14571
  const needsApproval = await this.utils.needsApproval(
14563
14572
  params.chainId,
14564
14573
  params.executionFeeToken,
14565
- networkFee.toString()
14574
+ depositAmount.toString()
14566
14575
  );
14567
14576
  const authorized = this.configManager.getConfig().seamlessAccount?.authorized;
14568
14577
  const seamlessWallet = this.configManager.getConfig().seamlessAccount?.wallet;
@@ -14613,13 +14622,16 @@ var Order = class {
14613
14622
  };
14614
14623
  this.logger.info("create decrease order forward tx params --->", forwardTxParams);
14615
14624
  const rs = await this.seamless.forwarderTx(forwardTxParams, params.chainId, seamlessWallet);
14616
- console.log("rs-->", rs);
14617
14625
  return {
14618
14626
  code: 0,
14619
14627
  message: "create decrease order success",
14620
14628
  data: rs
14621
14629
  };
14622
14630
  }
14631
+ const brokerContract = await getBrokerSingerContract(
14632
+ params.chainId,
14633
+ this.configManager.getConfig().brokerAddress
14634
+ );
14623
14635
  if (!config.signer) {
14624
14636
  throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
14625
14637
  }
@@ -14635,16 +14647,12 @@ var Order = class {
14635
14647
  }
14636
14648
  let transaction;
14637
14649
  if (!params.positionId) {
14638
- const depositData2 = {
14639
- token: params.executionFeeToken,
14640
- amount: networkFee
14641
- };
14642
14650
  const positionId = 1;
14643
14651
  this.logger.info("createDecreaseOrder salt position params--->", [positionId, { data }]);
14644
- const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData2, data);
14652
+ const gasLimit = await brokerContract.placeOrderWithSalt.estimateGas(positionId.toString(), depositData, data);
14645
14653
  transaction = await brokerContract.placeOrderWithSalt(
14646
14654
  positionId.toString(),
14647
- depositData2,
14655
+ depositData,
14648
14656
  data,
14649
14657
  {
14650
14658
  gasLimit: gasLimit * 130n / 100n
@@ -20918,24 +20926,16 @@ var Account = class {
20918
20926
  /**
20919
20927
  * get tradable amount
20920
20928
  */
20921
- async getTradableAmount({ poolId }) {
20922
- const config = this.configManager.getConfig();
20923
- if (!config.signer) {
20924
- throw new MyxSDKError(
20925
- "INVALID_SIGNER" /* InvalidSigner */,
20926
- "Invalid signer"
20927
- );
20928
- }
20929
- const contractAddress = getContractAddressByChainId(config.chainId);
20930
- const provider = await getJSONProvider(config.chainId);
20929
+ async getTradableAmount({ poolId, chainId, address }) {
20930
+ const contractAddress = getContractAddressByChainId(chainId);
20931
+ const provider = await getJSONProvider(chainId);
20931
20932
  const accountContract = new ethers8.Contract(
20932
20933
  contractAddress.Account,
20933
20934
  Account_default,
20934
20935
  provider
20935
20936
  );
20936
20937
  try {
20937
- const targetAddress = config.seamlessMode ? config.seamlessAccount?.masterAddress : config.signer?.getAddress();
20938
- const assets = await accountContract.getTradableAmount(targetAddress, poolId);
20938
+ const assets = await accountContract.getTradableAmount(address, poolId);
20939
20939
  const data = {
20940
20940
  profitIsReleased: assets[0],
20941
20941
  freeAmount: assets[1],
@@ -20951,6 +20951,18 @@ var Account = class {
20951
20951
  };
20952
20952
  }
20953
20953
  }
20954
+ async getAvailableMarginBalance({ poolId, chainId, address }) {
20955
+ const marginAccountBalanceRes = await this.getTradableAmount({ poolId, chainId, address });
20956
+ const marginAccountBalance = marginAccountBalanceRes?.data;
20957
+ if (marginAccountBalanceRes.code !== 0) {
20958
+ throw new MyxSDKError(
20959
+ "INSUFFICIENT_MARGIN_BALANCE" /* InsufficientMarginBalance */,
20960
+ "Insufficient margin balance"
20961
+ );
20962
+ }
20963
+ const availableAccountMarginBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + (!marginAccountBalance?.tradeableProfit ? BigInt(marginAccountBalance?.tradeableProfit) : BigInt(0));
20964
+ return availableAccountMarginBalance;
20965
+ }
20954
20966
  async getTradeFlow(params) {
20955
20967
  const accessToken = await this.configManager.getAccessToken();
20956
20968
  if (!accessToken) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.132",
3
+ "version": "0.1.134",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"