@symmio/trading-core 3.1.0 → 3.2.0

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.
Files changed (126) hide show
  1. package/dist/index.d.ts +4 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +304 -298
  4. package/dist/quotes/get-quote-history/solver-fees.d.ts +39 -0
  5. package/dist/quotes/get-quote-history/solver-fees.d.ts.map +1 -0
  6. package/dist/quotes/get-quote-history/solver-fees.js +36 -0
  7. package/dist/quotes/get-quote-history/solver-fees.js.map +1 -0
  8. package/dist/quotes/get-quote-history/to-history-row.d.ts.map +1 -1
  9. package/dist/quotes/get-quote-history/to-history-row.js +34 -30
  10. package/dist/quotes/get-quote-history/to-history-row.js.map +1 -1
  11. package/dist/quotes/get-quote-history/types.d.ts +20 -0
  12. package/dist/quotes/get-quote-history/types.d.ts.map +1 -1
  13. package/dist/quotes/get-quote-history/types.js.map +1 -1
  14. package/dist/solvers/get-solver-info/get-solver-info.d.ts +36 -0
  15. package/dist/solvers/get-solver-info/get-solver-info.d.ts.map +1 -0
  16. package/dist/solvers/get-solver-info/get-solver-info.js +28 -0
  17. package/dist/solvers/get-solver-info/get-solver-info.js.map +1 -0
  18. package/dist/solvers/get-solver-info/index.d.ts +3 -0
  19. package/dist/solvers/get-solver-info/index.d.ts.map +1 -0
  20. package/dist/solvers/get-solver-info/query.d.ts +29 -0
  21. package/dist/solvers/get-solver-info/query.d.ts.map +1 -0
  22. package/dist/solvers/get-solver-info/query.js +24 -0
  23. package/dist/solvers/get-solver-info/query.js.map +1 -0
  24. package/dist/solvers/instant-close/get-instant-close-fees/get-instant-close-fees.d.ts +152 -0
  25. package/dist/solvers/instant-close/get-instant-close-fees/get-instant-close-fees.d.ts.map +1 -0
  26. package/dist/solvers/instant-close/get-instant-close-fees/get-instant-close-fees.js +82 -0
  27. package/dist/solvers/instant-close/get-instant-close-fees/get-instant-close-fees.js.map +1 -0
  28. package/dist/solvers/instant-close/get-instant-close-fees/index.d.ts +3 -0
  29. package/dist/solvers/instant-close/get-instant-close-fees/index.d.ts.map +1 -0
  30. package/dist/solvers/instant-close/get-instant-close-fees/query.d.ts +37 -0
  31. package/dist/solvers/instant-close/get-instant-close-fees/query.d.ts.map +1 -0
  32. package/dist/solvers/instant-close/get-instant-close-fees/query.js +32 -0
  33. package/dist/solvers/instant-close/get-instant-close-fees/query.js.map +1 -0
  34. package/dist/solvers/instant-close/index.d.ts +1 -0
  35. package/dist/solvers/instant-close/index.d.ts.map +1 -1
  36. package/dist/solvers/instant-close/instant-close/instant-close.d.ts +4 -3
  37. package/dist/solvers/instant-close/instant-close/instant-close.d.ts.map +1 -1
  38. package/dist/solvers/instant-close/instant-close/instant-close.js +26 -22
  39. package/dist/solvers/instant-close/instant-close/instant-close.js.map +1 -1
  40. package/dist/solvers/instant-close/instant-close-bulk/instant-close-bulk.d.ts +2 -0
  41. package/dist/solvers/instant-close/instant-close-bulk/instant-close-bulk.d.ts.map +1 -1
  42. package/dist/solvers/instant-close/instant-close-bulk/instant-close-bulk.js +26 -22
  43. package/dist/solvers/instant-close/instant-close-bulk/instant-close-bulk.js.map +1 -1
  44. package/dist/solvers/instant-close/shared/calldata.d.ts +1 -1
  45. package/dist/solvers/instant-close/shared/calldata.d.ts.map +1 -1
  46. package/dist/solvers/instant-close/shared/calldata.js.map +1 -1
  47. package/dist/solvers/instant-close/shared/resolve-close-order-type.d.ts +13 -0
  48. package/dist/solvers/instant-close/shared/resolve-close-order-type.d.ts.map +1 -0
  49. package/dist/solvers/instant-close/shared/resolve-close-order-type.js +9 -0
  50. package/dist/solvers/instant-close/shared/resolve-close-order-type.js.map +1 -0
  51. package/dist/solvers/instant-close/shared/types.d.ts +3 -3
  52. package/dist/solvers/instant-open/get-instant-open-fees/get-instant-open-fees.d.ts +111 -35
  53. package/dist/solvers/instant-open/get-instant-open-fees/get-instant-open-fees.d.ts.map +1 -1
  54. package/dist/solvers/instant-open/get-instant-open-fees/get-instant-open-fees.js +168 -91
  55. package/dist/solvers/instant-open/get-instant-open-fees/get-instant-open-fees.js.map +1 -1
  56. package/dist/solvers/instant-open/get-instant-open-fees/query.d.ts +3 -2
  57. package/dist/solvers/instant-open/get-instant-open-fees/query.d.ts.map +1 -1
  58. package/dist/solvers/instant-open/get-instant-open-fees/query.js +4 -15
  59. package/dist/solvers/instant-open/get-instant-open-fees/query.js.map +1 -1
  60. package/dist/solvers/instant-open/prepare-instant-open-params/index.d.ts +1 -0
  61. package/dist/solvers/instant-open/prepare-instant-open-params/index.d.ts.map +1 -1
  62. package/dist/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.d.ts +108 -12
  63. package/dist/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.d.ts.map +1 -1
  64. package/dist/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.js +169 -149
  65. package/dist/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.js.map +1 -1
  66. package/dist/solvers/instant-open/prepare-instant-open-params/query.d.ts +49 -0
  67. package/dist/solvers/instant-open/prepare-instant-open-params/query.d.ts.map +1 -0
  68. package/dist/solvers/instant-open/prepare-instant-open-params/query.js +24 -0
  69. package/dist/solvers/instant-open/prepare-instant-open-params/query.js.map +1 -0
  70. package/dist/solvers/instant-open/prepare-instant-open-params/resolvers/index.d.ts +0 -1
  71. package/dist/solvers/instant-open/prepare-instant-open-params/resolvers/index.d.ts.map +1 -1
  72. package/dist/solvers/instant-open/shared/full-balance-sizing.d.ts +164 -0
  73. package/dist/solvers/instant-open/shared/full-balance-sizing.d.ts.map +1 -0
  74. package/dist/solvers/instant-open/shared/full-balance-sizing.js +138 -0
  75. package/dist/solvers/instant-open/shared/full-balance-sizing.js.map +1 -0
  76. package/dist/solvers/instant-open/shared/index.d.ts +1 -0
  77. package/dist/solvers/instant-open/shared/index.d.ts.map +1 -1
  78. package/dist/solvers/instant-open/shared/resolve-instant-open-sizing.d.ts +46 -0
  79. package/dist/solvers/instant-open/shared/resolve-instant-open-sizing.d.ts.map +1 -0
  80. package/dist/solvers/instant-open/shared/resolve-instant-open-sizing.js +50 -0
  81. package/dist/solvers/instant-open/shared/resolve-instant-open-sizing.js.map +1 -0
  82. package/dist/solvers/instant-open/shared/trade-math.d.ts +73 -26
  83. package/dist/solvers/instant-open/shared/trade-math.d.ts.map +1 -1
  84. package/dist/solvers/instant-open/shared/trade-math.js +18 -13
  85. package/dist/solvers/instant-open/shared/trade-math.js.map +1 -1
  86. package/dist/solvers/instant-open/shared/types.d.ts +18 -1
  87. package/dist/solvers/instant-open/shared/types.d.ts.map +1 -1
  88. package/dist/solvers/instant-open/shared/types.js.map +1 -1
  89. package/dist/solvers/limit-open/prepare-limit-open-params.d.ts +3 -1
  90. package/dist/solvers/limit-open/prepare-limit-open-params.d.ts.map +1 -1
  91. package/dist/solvers/limit-open/prepare-limit-open-params.js.map +1 -1
  92. package/dist/solvers/shared/resolvers/index.d.ts +2 -0
  93. package/dist/solvers/shared/resolvers/index.d.ts.map +1 -1
  94. package/dist/solvers/{instant-open/prepare-instant-open-params → shared}/resolvers/resolve-fee-rates.d.ts +3 -3
  95. package/dist/solvers/shared/resolvers/resolve-fee-rates.d.ts.map +1 -0
  96. package/dist/solvers/{instant-open/prepare-instant-open-params → shared}/resolvers/resolve-fee-rates.js +2 -2
  97. package/dist/solvers/shared/resolvers/resolve-fee-rates.js.map +1 -0
  98. package/dist/solvers/shared/resolvers/resolve-market.d.ts +21 -0
  99. package/dist/solvers/shared/resolvers/resolve-market.d.ts.map +1 -1
  100. package/dist/solvers/shared/resolvers/resolve-market.js +34 -18
  101. package/dist/solvers/shared/resolvers/resolve-market.js.map +1 -1
  102. package/dist/solvers/shared/resolvers/resolve-solver-info.d.ts +29 -0
  103. package/dist/solvers/shared/resolvers/resolve-solver-info.d.ts.map +1 -0
  104. package/dist/solvers/shared/resolvers/resolve-solver-info.js +21 -0
  105. package/dist/solvers/shared/resolvers/resolve-solver-info.js.map +1 -0
  106. package/dist/solvers/shared/resolvers/types.d.ts +12 -0
  107. package/dist/solvers/shared/resolvers/types.d.ts.map +1 -1
  108. package/dist/solvers/types/generated/enigma-solver.d.ts +43 -82
  109. package/dist/solvers/types/generated/enigma-solver.d.ts.map +1 -1
  110. package/dist/solvers/types/generated/enigma-solver.js +6 -6
  111. package/dist/solvers/types/generated/enigma-solver.js.map +1 -1
  112. package/dist/symmio-contracts/abi/v0.8.6/account-layer.d.ts +696 -85
  113. package/dist/symmio-contracts/abi/v0.8.6/account-layer.d.ts.map +1 -1
  114. package/dist/symmio-contracts/abi/v0.8.6/account-layer.js +815 -116
  115. package/dist/symmio-contracts/abi/v0.8.6/account-layer.js.map +1 -1
  116. package/dist/symmio-contracts/abi/v0.8.6/symmio.d.ts +1044 -467
  117. package/dist/symmio-contracts/abi/v0.8.6/symmio.d.ts.map +1 -1
  118. package/dist/symmio-contracts/abi/v0.8.6/symmio.js +1183 -496
  119. package/dist/symmio-contracts/abi/v0.8.6/symmio.js.map +1 -1
  120. package/dist/symmio-contracts/symmio/types.d.ts +3 -1
  121. package/dist/symmio-contracts/symmio/types.d.ts.map +1 -1
  122. package/dist/symmio-contracts/symmio/types.js +1 -1
  123. package/dist/symmio-contracts/symmio/types.js.map +1 -1
  124. package/package.json +3 -3
  125. package/dist/solvers/instant-open/prepare-instant-open-params/resolvers/resolve-fee-rates.d.ts.map +0 -1
  126. package/dist/solvers/instant-open/prepare-instant-open-params/resolvers/resolve-fee-rates.js.map +0 -1
@@ -5,26 +5,15 @@ function n(t) {
5
5
  return ["getInstantOpenFees", e(t)];
6
6
  }
7
7
  function r(e, r) {
8
+ let { query: i, ...a } = r, o = r.fund === void 0 ? (r.initialMargin?.length ?? 0) > 0 : r.fund.balance.length > 0;
8
9
  return {
9
- ...r.query,
10
+ ...i,
10
11
  queryKey: n({
11
12
  ...r,
12
13
  configKey: e.getChainConfigKey(r.chainId)
13
14
  }),
14
- enabled: (r.query?.enabled ?? !0) && r.initialMargin.length > 0,
15
- queryFn: () => t(e, {
16
- chainId: r.chainId,
17
- solverId: r.solverId,
18
- subAccountAddress: r.subAccountAddress,
19
- market: r.market,
20
- positionType: r.positionType,
21
- initialMargin: r.initialMargin,
22
- leverage: r.leverage,
23
- slippage: r.slippage,
24
- markPrice: r.markPrice,
25
- feeRates: r.feeRates,
26
- estimatedOpenPrice: r.estimatedOpenPrice
27
- })
15
+ enabled: (r.query?.enabled ?? !0) && o,
16
+ queryFn: () => t(e, a)
28
17
  };
29
18
  }
30
19
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","names":[],"sources":["../../../../src/solvers/instant-open/get-instant-open-fees/query.ts"],"sourcesContent":["import type { Config } from \"../../../core/config\";\nimport type { Compute, ConfigKeyParameter } from \"../../../shared/types/properties\";\nimport type { QueryParameter, SymmioQueryOptions } from \"../../../shared/types/query\";\nimport { filterQueryOptions } from \"../../../shared/utils/query\";\nimport {\n getInstantOpenFees,\n type GetInstantOpenFeesParameters,\n type GetInstantOpenFeesReturnType,\n} from \"./get-instant-open-fees\";\n\n/** Data resolved by the {@link getInstantOpenFeesQueryOptions} query. */\nexport type GetInstantOpenFeesData = GetInstantOpenFeesReturnType;\n\n/** Build the TanStack Query key for {@link getInstantOpenFeesQueryOptions}. */\nexport function getInstantOpenFeesQueryKey(options: Compute<GetInstantOpenFeesParameters & ConfigKeyParameter>) {\n return [\"getInstantOpenFees\", filterQueryOptions(options)] as const;\n}\n\n/** Query-key type produced by {@link getInstantOpenFeesQueryKey}. */\nexport type GetInstantOpenFeesQueryKey = ReturnType<typeof getInstantOpenFeesQueryKey>;\n\n/** Options accepted by {@link getInstantOpenFeesQueryOptions}. */\nexport type GetInstantOpenFeesOptions = Compute<\n GetInstantOpenFeesParameters &\n QueryParameter<GetInstantOpenFeesData, Error, GetInstantOpenFeesData, GetInstantOpenFeesQueryKey>\n>;\n\n/** TanStack Query options returned by {@link getInstantOpenFeesQueryOptions}. */\nexport type GetInstantOpenFeesQueryOptions = SymmioQueryOptions<\n GetInstantOpenFeesData,\n Error,\n GetInstantOpenFeesData,\n GetInstantOpenFeesQueryKey\n>;\n\n/**\n * Build TanStack Query options for {@link getInstantOpenFees}. Disabled until\n * `initialMargin` is non-empty, so the fee preview does not fire on an empty\n * amount input.\n *\n * @example\n * ```ts\n * useQuery(\n * getInstantOpenFeesQueryOptions(config, {\n * subAccountAddress,\n * market: { id: 1 },\n * positionType,\n * initialMargin,\n * leverage: 5,\n * }),\n * );\n * ```\n */\nexport function getInstantOpenFeesQueryOptions(\n config: Config,\n options: GetInstantOpenFeesOptions,\n): GetInstantOpenFeesQueryOptions {\n return {\n ...options.query,\n queryKey: getInstantOpenFeesQueryKey({\n ...options,\n configKey: config.getChainConfigKey(options.chainId),\n }),\n enabled: (options.query?.enabled ?? true) && options.initialMargin.length > 0,\n queryFn: () =>\n getInstantOpenFees(config, {\n chainId: options.chainId,\n solverId: options.solverId,\n subAccountAddress: options.subAccountAddress,\n market: options.market,\n positionType: options.positionType,\n initialMargin: options.initialMargin,\n leverage: options.leverage,\n slippage: options.slippage,\n markPrice: options.markPrice,\n feeRates: options.feeRates,\n estimatedOpenPrice: options.estimatedOpenPrice,\n }),\n };\n}\n"],"mappings":";;;AAcA,SAAgB,EAA2B,GAAqE;CAC9G,OAAO,CAAC,sBAAsB,EAAmB,CAAO,CAAC;AAC3D;AAqCA,SAAgB,EACd,GACA,GACgC;CAChC,OAAO;EACL,GAAG,EAAQ;EACX,UAAU,EAA2B;GACnC,GAAG;GACH,WAAW,EAAO,kBAAkB,EAAQ,OAAO;EACrD,CAAC;EACD,UAAU,EAAQ,OAAO,WAAW,OAAS,EAAQ,cAAc,SAAS;EAC5E,eACE,EAAmB,GAAQ;GACzB,SAAS,EAAQ;GACjB,UAAU,EAAQ;GAClB,mBAAmB,EAAQ;GAC3B,QAAQ,EAAQ;GAChB,cAAc,EAAQ;GACtB,eAAe,EAAQ;GACvB,UAAU,EAAQ;GAClB,UAAU,EAAQ;GAClB,WAAW,EAAQ;GACnB,UAAU,EAAQ;GAClB,oBAAoB,EAAQ;EAC9B,CAAC;CACL;AACF"}
1
+ {"version":3,"file":"query.js","names":[],"sources":["../../../../src/solvers/instant-open/get-instant-open-fees/query.ts"],"sourcesContent":["import type { Config } from \"../../../core/config\";\nimport type { Compute, ConfigKeyParameter } from \"../../../shared/types/properties\";\nimport type { QueryParameter, SymmioQueryOptions } from \"../../../shared/types/query\";\nimport { filterQueryOptions } from \"../../../shared/utils/query\";\nimport {\n getInstantOpenFees,\n type GetInstantOpenFeesParameters,\n type GetInstantOpenFeesReturnType,\n} from \"./get-instant-open-fees\";\n\n/** Data resolved by the {@link getInstantOpenFeesQueryOptions} query. */\nexport type GetInstantOpenFeesData = GetInstantOpenFeesReturnType;\n\n/** Build the TanStack Query key for {@link getInstantOpenFeesQueryOptions}. */\nexport function getInstantOpenFeesQueryKey(options: Compute<GetInstantOpenFeesParameters & ConfigKeyParameter>) {\n return [\"getInstantOpenFees\", filterQueryOptions(options)] as const;\n}\n\n/** Query-key type produced by {@link getInstantOpenFeesQueryKey}. */\nexport type GetInstantOpenFeesQueryKey = ReturnType<typeof getInstantOpenFeesQueryKey>;\n\n/** Options accepted by {@link getInstantOpenFeesQueryOptions}. */\nexport type GetInstantOpenFeesOptions = Compute<\n GetInstantOpenFeesParameters &\n QueryParameter<GetInstantOpenFeesData, Error, GetInstantOpenFeesData, GetInstantOpenFeesQueryKey>\n>;\n\n/** TanStack Query options returned by {@link getInstantOpenFeesQueryOptions}. */\nexport type GetInstantOpenFeesQueryOptions = SymmioQueryOptions<\n GetInstantOpenFeesData,\n Error,\n GetInstantOpenFeesData,\n GetInstantOpenFeesQueryKey\n>;\n\n/**\n * Build TanStack Query options for {@link getInstantOpenFees}. Disabled until\n * a funding source exists — a non-empty `initialMargin`, or `fund` with a\n * non-empty balance — so the fee preview does not fire on an empty amount\n * input.\n *\n * @example\n * ```ts\n * useQuery(\n * getInstantOpenFeesQueryOptions(config, {\n * subAccountAddress,\n * market: { id: 1 },\n * positionType,\n * initialMargin,\n * leverage: 5,\n * }),\n * );\n * ```\n */\nexport function getInstantOpenFeesQueryOptions(\n config: Config,\n options: GetInstantOpenFeesOptions,\n): GetInstantOpenFeesQueryOptions {\n const { query, ...parameters } = options;\n const hasFunding =\n options.fund !== undefined ? options.fund.balance.length > 0 : (options.initialMargin?.length ?? 0) > 0;\n return {\n ...query,\n queryKey: getInstantOpenFeesQueryKey({\n ...options,\n configKey: config.getChainConfigKey(options.chainId),\n }),\n enabled: (options.query?.enabled ?? true) && hasFunding,\n queryFn: () => getInstantOpenFees(config, parameters),\n };\n}\n"],"mappings":";;;AAcA,SAAgB,EAA2B,GAAqE;CAC9G,OAAO,CAAC,sBAAsB,EAAmB,CAAO,CAAC;AAC3D;AAsCA,SAAgB,EACd,GACA,GACgC;CAChC,IAAM,EAAE,UAAO,GAAG,MAAe,GAC3B,IACJ,EAAQ,SAAS,KAAA,KAA+C,EAAQ,eAAe,UAAU,KAAK,IAAzE,EAAQ,KAAK,QAAQ,SAAS;CAC7D,OAAO;EACL,GAAG;EACH,UAAU,EAA2B;GACnC,GAAG;GACH,WAAW,EAAO,kBAAkB,EAAQ,OAAO;EACrD,CAAC;EACD,UAAU,EAAQ,OAAO,WAAW,OAAS;EAC7C,eAAe,EAAmB,GAAQ,CAAU;CACtD;AACF"}
@@ -1,3 +1,4 @@
1
1
  export * from './prepare-instant-open-params.js';
2
+ export * from './query.js';
2
3
  export * from './resolvers/index.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/solvers/instant-open/prepare-instant-open-params/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/solvers/instant-open/prepare-instant-open-params/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -2,6 +2,7 @@ import { Address, Hex } from 'viem';
2
2
  import { Config } from '../../../core/config/index.js';
3
3
  import { Compute, WriteSolverParameter } from '../../../shared/types/properties.js';
4
4
  import { FeeForUser } from '../../../symmio-contracts/symmio/actions/get-fee-for-user.js';
5
+ import { EnigmaSolverInfo } from '../../get-solver-info/index.js';
5
6
  import { ApiLockedParamsBySymbolIdResponse } from '../../types/generated/enigma-solver.js';
6
7
  import { InstantOpenParameters } from '../instant-open/types.js';
7
8
  import { InstantOpenMarketData, PositionType } from '../shared/types.js';
@@ -12,15 +13,38 @@ import { InstantOpenMarketData, PositionType } from '../shared/types.js';
12
13
  * intent). Optional = anything derivable from solver / price-service / on-chain
13
14
  * reads. Pre-fill an optional field to skip its fetch.
14
15
  */
15
- export type PrepareInstantOpenParameters = Compute<WriteSolverParameter & {
16
+ /**
17
+ * Full-balance funding for a lowcap (Enigma) open — deploy the **entire**
18
+ * selected collateral into the position's Virtual Account instead of typing an
19
+ * initial margin.
20
+ *
21
+ * With a typed `initialMargin` the SubAccount keeps back whatever the position
22
+ * did not need (locks + open fees + settlement), so a user who deposited `$100`
23
+ * and hit "Max" saw a smaller spendable figure and left dust behind. In this
24
+ * mode the whole balance moves to the VA and the SDK sizes the quantity **down**
25
+ * so its locks + open fees + worst-case settlement fit inside it — nothing is
26
+ * stranded and the figure the user deployed is the figure they picked. (Close
27
+ * fees are charged at close from the position, so they are not sized in here.)
28
+ *
29
+ * Lowcap (Enigma) only: it relies on the per-position VA and the solver-fee /
30
+ * settlement legs a majors (cross-margin) open does not have.
31
+ */
32
+ export interface FullBalanceFunding {
33
+ /** Discriminant selecting the full-balance sizing path. */
34
+ mode: "full-balance";
35
+ /** The entire collateral to move into the VA, as a USD decimal string. */
36
+ balance: string;
37
+ }
38
+ /**
39
+ * Fields shared by every {@link PrepareInstantOpenParameters} funding mode.
40
+ */
41
+ type PrepareInstantOpenBaseParameters = WriteSolverParameter & {
16
42
  /** Sub-account / partyA address. */
17
43
  subAccountAddress: Address;
18
44
  /** Market identification + optional pre-fetched precision metadata. */
19
45
  market: InstantOpenMarketData;
20
46
  /** Trade side. */
21
47
  positionType: PositionType;
22
- /** Collateral (USD) the user enters as initial margin. Decimal string. */
23
- initialMargin: string;
24
48
  /** Position leverage (integer ≥ 1). */
25
49
  leverage: number;
26
50
  /**
@@ -36,11 +60,12 @@ export type PrepareInstantOpenParameters = Compute<WriteSolverParameter & {
36
60
  /**
37
61
  * Pre-fetched solver estimated open (fill) price as decimal string —
38
62
  * **lowcap/Enigma only**; ignored on any other solver kind. When omitted
39
- * on a lowcap solver, fetched via `GET /estimated-price`. Feeds the
40
- * settlement-loss provision, the slippage gate, and (when `slippage` is
63
+ * on a lowcap solver, fetched via `GET /estimated-price`. Pass `null` when
64
+ * an estimate was attempted but unavailable to skip fetching and use the fallback.
65
+ * Feeds the settlement-loss provision, the slippage gate, and (when `slippage` is
41
66
  * omitted) the auto-slippage derivation.
42
67
  */
43
- estimatedOpenPrice?: string;
68
+ estimatedOpenPrice?: string | null;
44
69
  /**
45
70
  * Pre-fetched solver locked params (matches `getLockedParams` return —
46
71
  * `ApiLockedParamsBySymbolIdResponse`). When supplied with all four
@@ -52,6 +77,14 @@ export type PrepareInstantOpenParameters = Compute<WriteSolverParameter & {
52
77
  * `FeeForUser`). When omitted, fetched via `getFeeForUser`.
53
78
  */
54
79
  feeRates?: FeeForUser;
80
+ /**
81
+ * Pre-fetched solver static fees (matches `getSolverInfo` return) —
82
+ * **lowcap/Enigma only**; ignored on any other solver kind. When omitted on
83
+ * a lowcap solver, fetched via `getSolverInfo` (fail-soft: an unreachable
84
+ * `/info` prices both static legs at `"0"`). The flat USD legs ride the
85
+ * `addMargin` transfer like the rate-based solver fees.
86
+ */
87
+ solverInfo?: EnigmaSolverInfo;
55
88
  /** Forwarded to {@link InstantOpenParameters}. */
56
89
  uuid?: string;
57
90
  /** Forwarded to {@link InstantOpenParameters}. */
@@ -60,7 +93,38 @@ export type PrepareInstantOpenParameters = Compute<WriteSolverParameter & {
60
93
  sendQuoteSalt?: Hex;
61
94
  /** Forwarded to {@link InstantOpenParameters}. */
62
95
  deadline?: bigint;
96
+ };
97
+ /**
98
+ * Parameters for {@link prepareInstantOpenParams} and `instantOpenAuto`.
99
+ *
100
+ * The funding source is a choice: pass a typed `initialMargin` (the classic
101
+ * path, works on every solver), **or** `fund` with {@link FullBalanceFunding} to
102
+ * deploy the whole balance on a lowcap (Enigma) solver. Provide **exactly one** —
103
+ * passing both, or neither, throws. (Both are typed optional so the params
104
+ * spread cleanly through wrapper flows; the one-of rule is enforced at runtime.)
105
+ */
106
+ export type PrepareInstantOpenParameters = Compute<PrepareInstantOpenBaseParameters & {
107
+ /** Collateral (USD) the user enters as initial margin. Decimal string. Provide this **or** `fund`. */
108
+ initialMargin?: string;
109
+ /**
110
+ * Raw available collateral (USD decimal string). With initialMargin, automatically
111
+ * use full-balance sizing when required funding exceeds this amount. Lowcap only;
112
+ * must be positive and finite. initialMargin above this balance throws.
113
+ * Omit to preserve typed sizing. Cannot accompany fund.
114
+ */
115
+ availableBalance?: string;
116
+ /**
117
+ * Deploy the entire collateral and size the quantity to fit it — lowcap
118
+ * (Enigma) only. Provide this **or** `initialMargin`. See
119
+ * {@link FullBalanceFunding}.
120
+ */
121
+ fund?: FullBalanceFunding;
63
122
  }>;
123
+ /** Prepared order parameters plus the effective funding mode. Pass directly to instantOpen. */
124
+ export type PrepareInstantOpenParamsReturnType = InstantOpenParameters & {
125
+ /** Effective sizing mode, including automatic fallback from a typed initial margin. */
126
+ fundingMode: "initial-margin" | "full-balance";
127
+ };
64
128
  /**
65
129
  * Resolve every input the {@link InstantOpenParameters} primitive needs from a
66
130
  * minimal parameter set.
@@ -70,6 +134,29 @@ export type PrepareInstantOpenParameters = Compute<WriteSolverParameter & {
70
134
  * unchanged: `slippage` required, no estimate fetch, margin = locks +
71
135
  * platform fee.
72
136
  *
137
+ * Funding is a discriminated choice (see {@link PrepareInstantOpenParameters}):
138
+ * a typed `initialMargin`, or `fund` ({@link FullBalanceFunding}, lowcap only)
139
+ * to deploy the whole balance. In full-balance mode the balance is used as a
140
+ * sizing probe: since the addMargin amount is linear in the sizing input at a
141
+ * fixed fill price, one probe gives the exact factor that shrinks the quantity
142
+ * so its locks + fees + settlement fit the balance, and the transfer then funds
143
+ * the whole balance (any remainder rides as free VA margin). The sized
144
+ * quantity is snapped down to the market's lot grid, re-checked so its costs
145
+ * never exceed the balance (precision rounding can overshoot the linear
146
+ * factor), and validated against the market's published quote constraints;
147
+ * when no fill estimate is available the settlement leg is provisioned at the
148
+ * slippage bound instead of zero — a full-balance open leaves nothing behind
149
+ * to absorb an optimistic estimate.
150
+ *
151
+ * Pass `availableBalance` with `initialMargin` to automatically select full-balance
152
+ * sizing when the typed position's required funding exceeds the raw balance.
153
+ * An initialMargin above availableBalance throws before sizing. Otherwise, funding
154
+ * equality preserves typed sizing. The returned `fundingMode` reports the choice.
155
+ *
156
+ * @param config - SDK configuration used to resolve market and account inputs.
157
+ * @param parameters - Trade intent, optional balance budget, and prefetched inputs.
158
+ * @returns Prepared order parameters and the effective funding mode.
159
+ *
73
160
  * Steps:
74
161
  * 1. Validate the user's `slippage` ({@link assertValidSlippage}). On a
75
162
  * lowcap solver it may be omitted and is auto-derived: dry-run the
@@ -87,18 +174,27 @@ export type PrepareInstantOpenParameters = Compute<WriteSolverParameter & {
87
174
  * auto-slippage estimate when one exists).
88
175
  * 5. Run {@link computePlatformFee}, {@link calculateSolverFees}, and
89
176
  * {@link calculateExpectedSettlementLoss}, then {@link calculateMargin} to
90
- * derive the `addMargin` amount — the solver charges its fees and the
91
- * open-price settlement from the VA, so the transfer funds
92
- * `locks + platformFee + openSolverFee + closeSolverFee +
93
- * expectedSettlementLoss`.
177
+ * derive the `addMargin` amount. The open funds only the **open-side** legs
178
+ * plus the open-price settlement from the VA, so the transfer funds
179
+ * `locks + platformOpenFee + openSolverFee + staticSolverFeeOpen +
180
+ * expectedSettlementLoss` (the static open leg is a flat USD amount from the
181
+ * solver's `/info` config). The close-side legs (platform close, solver
182
+ * close, static close) are **charged at close** from the position — the
183
+ * contract collects them at close execution — so they are not pre-funded
184
+ * here; pre-funding them would strand collateral in the VA. In full-balance
185
+ * mode the quantity is rescaled to fit the balance — the static open leg is
186
+ * carved off the budget before the linear solve — and the `addMargin` amount
187
+ * is the whole balance instead.
94
188
  * 6. Convert all final values to 18-decimal-wei `bigint`.
95
189
  *
96
190
  * @throws {SymmError} `INVALID_SLIPPAGE` / `SLIPPAGE_REQUIRED` /
97
- * `SLIPPAGE_EXCEEDED` /
191
+ * `SLIPPAGE_EXCEEDED` / `AMBIGUOUS_FUNDING` / `FULL_BALANCE_UNSUPPORTED` /
192
+ * `INITIAL_MARGIN_REQUIRED` / `QUOTE_CONSTRAINT_VIOLATED` /
98
193
  * `RESOLVE_MARKET_NOT_FOUND` /
99
194
  * `RESOLVE_MARKET_METADATA_INCOMPLETE` /
100
195
  * `RESOLVE_MARK_PRICE_NOT_FOUND` / `INVALID_TRADE_PARAMETERS` /
101
196
  * `INVALID_SOLVER_FEE_CAP` for invalid inputs or an out-of-tolerance fill.
102
197
  */
103
- export declare function prepareInstantOpenParams(config: Config, parameters: PrepareInstantOpenParameters): Promise<InstantOpenParameters>;
198
+ export declare function prepareInstantOpenParams(config: Config, parameters: PrepareInstantOpenParameters): Promise<PrepareInstantOpenParamsReturnType>;
199
+ export {};
104
200
  //# sourceMappingURL=prepare-instant-open-params.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepare-instant-open-params.d.ts","sourceRoot":"","sources":["../../../../src/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAEtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2DAA2D,CAAC;AAC5F,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAgBnE,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA+BhF;;;;;;GAMG;AACH,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAChD,oBAAoB,GAAG;IACrB,oCAAoC;IACpC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,uEAAuE;IACvE,MAAM,EAAE,qBAAqB,CAAC;IAC9B,kBAAkB;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,0EAA0E;IAC1E,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,iCAAiC,CAAC;IACvD;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,kDAAkD;IAClD,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,4BAA4B,GACvC,OAAO,CAAC,qBAAqB,CAAC,CAiOhC"}
1
+ {"version":3,"file":"prepare-instant-open-params.d.ts","sourceRoot":"","sources":["../../../../src/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAEtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2DAA2D,CAAC;AAC5F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AASnE,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA+BhF;;;;;;GAMG;AACH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,IAAI,EAAE,cAAc,CAAC;IACrB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,KAAK,gCAAgC,GAAG,oBAAoB,GAAG;IAC7D,oCAAoC;IACpC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,uEAAuE;IACvE,MAAM,EAAE,qBAAqB,CAAC;IAC9B,kBAAkB;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,iCAAiC,CAAC;IACvD;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,kDAAkD;IAClD,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAChD,gCAAgC,GAAG;IACjC,sGAAsG;IACtG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;CAC3B,CACF,CAAC;AAEF,+FAA+F;AAC/F,MAAM,MAAM,kCAAkC,GAAG,qBAAqB,GAAG;IACvE,uFAAuF;IACvF,WAAW,EAAE,gBAAgB,GAAG,cAAc,CAAC;CAChD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,4BAA4B,GACvC,OAAO,CAAC,kCAAkC,CAAC,CA+Q7C"}
@@ -1,175 +1,195 @@
1
1
  import { SymmError as e } from "../../../shared/errors/symm-error.js";
2
- import { calculateExpectedSettlementLoss as t, calculateMargin as n, calculateSolverFees as r, calculateTradeParams as i, computePlatformFee as a, toWeiBigInt as o } from "../shared/trade-math.js";
3
- import { decimalPriceToWei as s } from "../../../shared/utils/price.js";
4
- import { assertOpenEstimateWithinSlippage as c, assertValidSlippage as l, deriveAutoSlippage as u, fetchOpenEstimatePrice as d } from "../shared/open-estimate-guard.js";
5
- import { resolveMarkPrice as f } from "../../shared/resolvers/resolve-mark-price.js";
6
- import { resolveMarket as p } from "../../shared/resolvers/resolve-market.js";
7
- import { resolveFeeRates as m } from "./resolvers/resolve-fee-rates.js";
8
- import { resolveLockedParams as h } from "./resolvers/resolve-locked-params.js";
2
+ import { calculateTradeParams as t, toWeiBigInt as n } from "../shared/trade-math.js";
3
+ import { decimalPriceToWei as r } from "../../../shared/utils/price.js";
4
+ import { assertOpenEstimateWithinSlippage as i, assertValidSlippage as a, deriveAutoSlippage as o, fetchOpenEstimatePrice as s } from "../shared/open-estimate-guard.js";
5
+ import { resolveInstantOpenSizing as c, validateInstantOpenBalanceFunding as l } from "../shared/resolve-instant-open-sizing.js";
6
+ import { resolveFeeRates as u } from "../../shared/resolvers/resolve-fee-rates.js";
7
+ import { resolveMarkPrice as d } from "../../shared/resolvers/resolve-mark-price.js";
8
+ import { resolveMarket as f } from "../../shared/resolvers/resolve-market.js";
9
+ import { resolveSolverInfo as p } from "../../shared/resolvers/resolve-solver-info.js";
10
+ import { resolveLockedParams as m } from "./resolvers/resolve-locked-params.js";
11
+ import { parseUnits as h } from "viem";
12
+ import { RoundingMode as g, toDecimal as _ } from "@symmio/utils/decimal";
9
13
  //#region src/solvers/instant-open/prepare-instant-open-params/prepare-instant-open-params.ts
10
- var g = "0.01";
11
- function _(t, n) {
12
- let r = s(n ?? g);
13
- if (r === void 0) throw new e("validation", "INVALID_SOLVER_FEE_CAP", `prepareInstantOpenParams: market ${t} "${n}" is not a valid decimal ratio.`);
14
- return r;
14
+ var v = "0.01";
15
+ function y(t, n) {
16
+ let i = r(n ?? v);
17
+ if (i === void 0) throw new e("validation", "INVALID_SOLVER_FEE_CAP", `prepareInstantOpenParams: market ${t} "${n}" is not a valid decimal ratio.`);
18
+ return i;
15
19
  }
16
- async function v(s, g) {
17
- g.slippage !== void 0 && l(g.slippage);
18
- let v = s.getSolver({
19
- chainId: g.chainId,
20
- solverId: g.solverId
20
+ async function b(r, v) {
21
+ v.slippage !== void 0 && a(v.slippage);
22
+ let b = r.getSolver({
23
+ chainId: v.chainId,
24
+ solverId: v.solverId
21
25
  }).id === "enigma";
22
- if (g.slippage === void 0 && !v) throw new e("validation", "SLIPPAGE_REQUIRED", "prepareInstantOpenParams: slippage is required on this solver — auto-derived slippage is lowcap-only.");
23
- let y = s.getChainConfig(g.chainId).contractsVersion === "0.8.6", b = await p(s, {
24
- chainId: g.chainId,
25
- solverId: g.solverId,
26
- marketId: g.market.id,
27
- marketName: g.market.name,
28
- pricePrecision: g.market.pricePrecision,
29
- quantityPrecision: g.market.quantityPrecision,
30
- minOpenSolverFeeCap: g.market.minOpenSolverFeeCap,
31
- minCloseSolverFeeCap: g.market.minCloseSolverFeeCap,
32
- includeSolverFeeCaps: y,
33
- hedgerFeeOpen: g.market.hedgerFeeOpen,
34
- hedgerFeeClose: g.market.hedgerFeeClose,
35
- hedgerFeeCloseEarlyRate: g.market.hedgerFeeCloseEarlyRate,
36
- hedgerFeeCloseEarlyThreshold: g.market.hedgerFeeCloseEarlyThreshold,
37
- hedgerFeeCloseStandardThreshold: g.market.hedgerFeeCloseStandardThreshold,
38
- includeHedgerFees: v
39
- }), [x, S, C] = await Promise.all([
40
- f(s, {
41
- chainId: g.chainId,
42
- solverId: g.solverId,
43
- marketName: b.name,
44
- markPrice: g.markPrice
26
+ if (v.slippage === void 0 && !b) throw new e("validation", "SLIPPAGE_REQUIRED", "prepareInstantOpenParams: slippage is required on this solver — auto-derived slippage is lowcap-only.");
27
+ let x = v.fund !== void 0;
28
+ l({
29
+ ...v,
30
+ isLowcap: b
31
+ });
32
+ let S = x || v.availableBalance !== void 0;
33
+ if (x && v.initialMargin !== void 0) throw new e("validation", "AMBIGUOUS_FUNDING", "prepareInstantOpenParams: pass exactly one of initialMargin or fund, not both.");
34
+ if (x && !b) throw new e("validation", "FULL_BALANCE_UNSUPPORTED", "prepareInstantOpenParams: full-balance funding is lowcap (Enigma) only — pass initialMargin on this solver.");
35
+ if (!x && v.initialMargin === void 0) throw new e("validation", "INITIAL_MARGIN_REQUIRED", "prepareInstantOpenParams: pass initialMargin, or fund: { mode: 'full-balance', balance } on a lowcap solver.");
36
+ let C = x ? v.fund.balance : v.initialMargin, w = r.getChainConfig(v.chainId).contractsVersion === "0.8.6", T = await f(r, {
37
+ chainId: v.chainId,
38
+ solverId: v.solverId,
39
+ marketId: v.market.id,
40
+ marketName: v.market.name,
41
+ pricePrecision: v.market.pricePrecision,
42
+ quantityPrecision: v.market.quantityPrecision,
43
+ minOpenSolverFeeCap: v.market.minOpenSolverFeeCap,
44
+ minCloseSolverFeeCap: v.market.minCloseSolverFeeCap,
45
+ includeSolverFeeCaps: w,
46
+ hedgerFeeOpen: v.market.hedgerFeeOpen,
47
+ hedgerFeeClose: v.market.hedgerFeeClose,
48
+ hedgerFeeCloseEarlyRate: v.market.hedgerFeeCloseEarlyRate,
49
+ hedgerFeeCloseEarlyThreshold: v.market.hedgerFeeCloseEarlyThreshold,
50
+ hedgerFeeCloseStandardThreshold: v.market.hedgerFeeCloseStandardThreshold,
51
+ includeHedgerFees: b,
52
+ includeQuoteConstraints: S,
53
+ minAcceptablePortionLf: v.market.minAcceptablePortionLf,
54
+ minAcceptableQuoteValue: v.market.minAcceptableQuoteValue,
55
+ maxNotionalValue: v.market.maxNotionalValue,
56
+ minNotionalValue: v.market.minNotionalValue,
57
+ maxQuantity: v.market.maxQuantity,
58
+ lotSize: v.market.lotSize
59
+ }), [E, D, O, k] = await Promise.all([
60
+ d(r, {
61
+ chainId: v.chainId,
62
+ solverId: v.solverId,
63
+ marketName: T.name,
64
+ markPrice: v.markPrice
65
+ }),
66
+ m(r, {
67
+ chainId: v.chainId,
68
+ solverId: v.solverId,
69
+ marketName: T.name,
70
+ leverage: v.leverage,
71
+ lockedParamPercent: v.lockedParamPercent
45
72
  }),
46
- h(s, {
47
- chainId: g.chainId,
48
- solverId: g.solverId,
49
- marketName: b.name,
50
- leverage: g.leverage,
51
- lockedParamPercent: g.lockedParamPercent
73
+ u(r, {
74
+ chainId: v.chainId,
75
+ subAccountAddress: v.subAccountAddress,
76
+ marketId: v.market.id,
77
+ feeRates: v.feeRates
52
78
  }),
53
- m(s, {
54
- chainId: g.chainId,
55
- subAccountAddress: g.subAccountAddress,
56
- marketId: g.market.id,
57
- feeRates: g.feeRates
79
+ b ? p(r, {
80
+ chainId: v.chainId,
81
+ solverId: v.solverId,
82
+ solverInfo: v.solverInfo
83
+ }) : Promise.resolve({
84
+ staticSolverFeeOpen: "0",
85
+ staticSolverFeeClose: "0"
58
86
  })
59
- ]), w = {
60
- markPrice: x,
61
- positionType: g.positionType,
62
- userInput: g.initialMargin,
87
+ ]), A = {
88
+ markPrice: E,
89
+ positionType: v.positionType,
90
+ userInput: C,
63
91
  inputField: "PRICE",
64
- leverage: g.leverage,
65
- pricePrecision: b.pricePrecision,
66
- quantityPrecision: b.quantityPrecision,
67
- cvaPercent: S.cva,
68
- lfPercent: S.lf,
69
- partyAmmPercent: S.partyAmm,
70
- partyBmmPercent: S.partyBmm
71
- }, T = g.slippage, E = v ? g.estimatedOpenPrice : void 0;
72
- if (T === void 0) {
73
- let t = i({
74
- ...w,
92
+ leverage: v.leverage,
93
+ pricePrecision: T.pricePrecision,
94
+ quantityPrecision: T.quantityPrecision,
95
+ cvaPercent: D.cva,
96
+ lfPercent: D.lf,
97
+ partyAmmPercent: D.partyAmm,
98
+ partyBmmPercent: D.partyBmm
99
+ }, j = v.slippage, M = b ? v.estimatedOpenPrice ?? void 0 : void 0, N = b && v.estimatedOpenPrice === void 0;
100
+ if (j === void 0) {
101
+ let n = t({
102
+ ...A,
75
103
  slippage: 0
76
104
  });
77
- if (!t) throw new e("validation", "INVALID_TRADE_PARAMETERS", "Invalid trade parameters: markPrice or initialMargin is zero/NaN.");
78
- v && E === void 0 && (E = await d(s, {
79
- chainId: g.chainId,
80
- solverId: g.solverId,
81
- symbolId: g.market.id,
82
- positionType: g.positionType,
83
- quantity: t.quantity,
84
- markPrice: x
85
- })), T = u({
86
- markPrice: x,
87
- expectedFillPrice: E,
88
- positionType: g.positionType
105
+ if (!n) throw new e("validation", "INVALID_TRADE_PARAMETERS", "Invalid trade parameters: markPrice or initialMargin is zero/NaN.");
106
+ N && (N = !1, M = await s(r, {
107
+ chainId: v.chainId,
108
+ solverId: v.solverId,
109
+ symbolId: v.market.id,
110
+ positionType: v.positionType,
111
+ quantity: n.quantity,
112
+ markPrice: E
113
+ })), j = o({
114
+ markPrice: E,
115
+ expectedFillPrice: M,
116
+ positionType: v.positionType
89
117
  });
90
118
  }
91
- let D = i({
92
- ...w,
93
- slippage: T
119
+ let P = t({
120
+ ...A,
121
+ slippage: j
94
122
  });
95
- if (!D) throw new e("validation", "INVALID_TRADE_PARAMETERS", "Invalid trade parameters: markPrice or initialMargin is zero/NaN.");
96
- v && E === void 0 && (E = await d(s, {
97
- chainId: g.chainId,
98
- solverId: g.solverId,
99
- symbolId: g.market.id,
100
- positionType: g.positionType,
101
- quantity: D.quantity,
102
- markPrice: x
103
- })), E !== void 0 && await c(s, {
104
- chainId: g.chainId,
105
- solverId: g.solverId,
106
- symbolId: g.market.id,
107
- positionType: g.positionType,
108
- quantity: D.quantity,
109
- markPrice: x,
110
- slippage: T,
111
- expectedFillPrice: E
123
+ if (!P) throw new e("validation", "INVALID_TRADE_PARAMETERS", "Invalid trade parameters: markPrice or initialMargin is zero/NaN.");
124
+ N && (M = await s(r, {
125
+ chainId: v.chainId,
126
+ solverId: v.solverId,
127
+ symbolId: v.market.id,
128
+ positionType: v.positionType,
129
+ quantity: P.quantity,
130
+ markPrice: E
131
+ })), M !== void 0 && await i(r, {
132
+ chainId: v.chainId,
133
+ solverId: v.solverId,
134
+ symbolId: v.market.id,
135
+ positionType: v.positionType,
136
+ quantity: P.quantity,
137
+ markPrice: E,
138
+ slippage: j,
139
+ expectedFillPrice: M
112
140
  });
113
- let O = a(C, D.notional, D.notional), { openSolverFee: k, closeSolverFee: A } = v ? r({
114
- notional: D.notional,
115
- hedgerFeeOpen: b.hedgerFeeOpen,
116
- hedgerFeeClose: b.hedgerFeeClose,
117
- hedgerFeeCloseEarlyRate: b.hedgerFeeCloseEarlyRate,
118
- hedgerFeeCloseEarlyThreshold: b.hedgerFeeCloseEarlyThreshold,
119
- hedgerFeeCloseStandardThreshold: b.hedgerFeeCloseStandardThreshold
120
- }) : {
121
- openSolverFee: "0",
122
- closeSolverFee: "0"
123
- }, j = t({
124
- positionType: g.positionType,
125
- markPrice: x,
126
- expectedFillPrice: E,
127
- quantity: D.quantity
128
- }), M = n({
129
- positionType: g.positionType,
130
- markPrice: x,
131
- quantityBasic: D.quantityBasic,
132
- cva: D.cva,
133
- lf: D.lf,
134
- partyAmm: D.partyAmm,
135
- openSolverFee: k,
136
- closeSolverFee: A,
137
- expectedSettlementLoss: j,
138
- shortFundingBufferPercent: +!!v,
139
- cvaPercent: S.cva,
140
- lfPercent: S.lf,
141
- partyAmmPercent: S.partyAmm,
142
- platformFee: O
141
+ let { trade: F, marginAmount: I, fundingMode: L } = c({
142
+ trade: P,
143
+ calculationInput: {
144
+ ...A,
145
+ slippage: j
146
+ },
147
+ isLowcap: b,
148
+ fund: v.fund,
149
+ availableBalance: v.availableBalance,
150
+ expectedFillPrice: M,
151
+ feeRates: O,
152
+ hedgerFeeOpen: T.hedgerFeeOpen,
153
+ staticSolverFeeOpen: k.staticSolverFeeOpen,
154
+ constraints: {
155
+ minAcceptablePortionLf: T.minAcceptablePortionLf,
156
+ minAcceptableQuoteValue: T.minAcceptableQuoteValue,
157
+ maxNotionalValue: T.maxNotionalValue,
158
+ minNotionalValue: T.minNotionalValue,
159
+ maxQuantity: T.maxQuantity,
160
+ lotSize: T.lotSize
161
+ }
143
162
  });
144
163
  return {
145
- chainId: g.chainId,
146
- solverId: g.solverId,
147
- from: g.from,
148
- subAccountAddress: g.subAccountAddress,
149
- marketId: g.market.id,
150
- positionType: g.positionType,
164
+ fundingMode: L,
165
+ chainId: v.chainId,
166
+ solverId: v.solverId,
167
+ from: v.from,
168
+ subAccountAddress: v.subAccountAddress,
169
+ marketId: v.market.id,
170
+ positionType: v.positionType,
151
171
  order: {
152
- price: o(D.requestedOpenPrice),
153
- quantity: o(D.quantity)
172
+ price: n(F.requestedOpenPrice),
173
+ quantity: n(F.quantity)
154
174
  },
155
175
  lockedParam: {
156
- cva: o(D.cva),
157
- lf: o(D.lf),
158
- partyAmm: o(D.partyAmm),
159
- partyBmm: o(D.partyBmm)
176
+ cva: n(F.cva),
177
+ lf: n(F.lf),
178
+ partyAmm: n(F.partyAmm),
179
+ partyBmm: n(F.partyBmm)
160
180
  },
161
- margin: { amount: o(M) },
162
- ...y ? { solverFeeCaps: {
163
- openRateCap: _("minOpenSolverFeeCap", b.minOpenSolverFeeCap),
164
- closeRateCap: _("minCloseSolverFeeCap", b.minCloseSolverFeeCap)
181
+ margin: { amount: h(_(I).toFixed(18, g.ROUND_DOWN), 18) },
182
+ ...w ? { solverFeeCaps: {
183
+ openRateCap: y("minOpenSolverFeeCap", T.minOpenSolverFeeCap),
184
+ closeRateCap: y("minCloseSolverFeeCap", T.minCloseSolverFeeCap)
165
185
  } } : {},
166
- uuid: g.uuid,
167
- addMarginSalt: g.addMarginSalt,
168
- sendQuoteSalt: g.sendQuoteSalt,
169
- deadline: g.deadline
186
+ uuid: v.uuid,
187
+ addMarginSalt: v.addMarginSalt,
188
+ sendQuoteSalt: v.sendQuoteSalt,
189
+ deadline: v.deadline
170
190
  };
171
191
  }
172
192
  //#endregion
173
- export { v as prepareInstantOpenParams };
193
+ export { b as prepareInstantOpenParams };
174
194
 
175
195
  //# sourceMappingURL=prepare-instant-open-params.js.map