@dimes-dot-fi/sdk 1.4.3 → 1.5.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.
- package/dist/{aliases-C2l_JZX_.d.cts → aliases-ByZ2DcA5.d.cts} +235 -1
- package/dist/{aliases-C2l_JZX_.d.ts → aliases-ByZ2DcA5.d.ts} +235 -1
- package/dist/{chunk-SGA6OZEU.mjs → chunk-3OPRSKCY.mjs} +18 -2
- package/dist/chunk-3OPRSKCY.mjs.map +1 -0
- package/dist/{chunk-DYPABUKC.cjs → chunk-72LTVPD2.cjs} +16 -1
- package/dist/chunk-72LTVPD2.cjs.map +1 -0
- package/dist/{chunk-BVILILIV.mjs → chunk-PZCBUVPD.mjs} +16 -1
- package/dist/chunk-PZCBUVPD.mjs.map +1 -0
- package/dist/{chunk-COSLZ5TM.cjs → chunk-Y5WQ3UWF.cjs} +21 -5
- package/dist/chunk-Y5WQ3UWF.cjs.map +1 -0
- package/dist/contract/index.cjs +13 -13
- package/dist/contract/index.d.cts +3 -3
- package/dist/contract/index.d.ts +3 -3
- package/dist/contract/index.mjs +1 -1
- package/dist/{dimes-client-u5wLYVfp.d.ts → dimes-client-B-thu7VQ.d.cts} +18 -3
- package/dist/{dimes-client-ty6xwk0b.d.cts → dimes-client-CerC9mTr.d.ts} +18 -3
- package/dist/{dimes-error-5ldDx2_G.d.cts → dimes-error-BY5qVGZC.d.cts} +1 -1
- package/dist/{dimes-error-D2RVknPr.d.ts → dimes-error-CrvPuFzB.d.ts} +1 -1
- package/dist/index.cjs +88 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -8
- package/dist/index.d.ts +138 -8
- package/dist/index.mjs +85 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{quote-GCNVcEoo.d.ts → quote-Czq3Selh.d.ts} +2 -2
- package/dist/{quote-DoRJUXld.d.cts → quote-quIOosIv.d.cts} +2 -2
- package/dist/react/index.cjs +4 -4
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.mjs +2 -2
- package/dist/{types-CM14Dx5b.d.cts → types-2bGyrtqd.d.cts} +1 -1
- package/dist/{types-CVcrVq0A.d.ts → types-CAuPxEwO.d.ts} +1 -1
- package/dist/ws/index.d.cts +3 -3
- package/dist/ws/index.d.ts +3 -3
- package/package.json +1 -1
- package/dist/chunk-BVILILIV.mjs.map +0 -1
- package/dist/chunk-COSLZ5TM.cjs.map +0 -1
- package/dist/chunk-DYPABUKC.cjs.map +0 -1
- package/dist/chunk-SGA6OZEU.mjs.map +0 -1
|
@@ -38,6 +38,185 @@ interface components {
|
|
|
38
38
|
*/
|
|
39
39
|
polygon_vault_contract_address: string;
|
|
40
40
|
};
|
|
41
|
+
CustomerOriginationFeeTier: {
|
|
42
|
+
/**
|
|
43
|
+
* @description Upper leverage bound (inclusive) in basis points for this tier. The last tier is the catch-all.
|
|
44
|
+
* @example 40000
|
|
45
|
+
*/
|
|
46
|
+
max_leverage_bps: number;
|
|
47
|
+
/**
|
|
48
|
+
* @description Protocol origination fee in basis points applied at or below this tier's leverage bound.
|
|
49
|
+
* @example 200
|
|
50
|
+
*/
|
|
51
|
+
fee_bps: number;
|
|
52
|
+
};
|
|
53
|
+
CustomerFeeRatesMarket: {
|
|
54
|
+
/**
|
|
55
|
+
* @description Market ticker
|
|
56
|
+
* @example TRUMP-2024-WIN
|
|
57
|
+
*/
|
|
58
|
+
ticker: string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Polymarket venue trading fee rate in basis points (`feeRateBps`).
|
|
61
|
+
* @example 0
|
|
62
|
+
*/
|
|
63
|
+
polymarket_trading_fee_bps: number;
|
|
64
|
+
/**
|
|
65
|
+
* @description Polymarket fee-curve exponent (`feeExponent`). `1` for the standard quadratic curve.
|
|
66
|
+
* @example 1
|
|
67
|
+
*/
|
|
68
|
+
polymarket_fee_exponent: number;
|
|
69
|
+
};
|
|
70
|
+
CustomerFeeRates: {
|
|
71
|
+
/** @description Per-market venue fee fields. Only present when the request includes a `ticker` query parameter. */
|
|
72
|
+
market?: components["schemas"]["CustomerFeeRatesMarket"];
|
|
73
|
+
/** @description Leverage-tiered protocol origination fee schedule. Resolve a leverage to its fee by picking the first tier whose `maxLeverageBps >= leverageBps` (the last tier is the catch-all). */
|
|
74
|
+
origination_fee_tiers: components["schemas"]["CustomerOriginationFeeTier"][];
|
|
75
|
+
/**
|
|
76
|
+
* @description Maximum combined (protocol + partner) origination fee in basis points enforced on-chain.
|
|
77
|
+
* @example 1000
|
|
78
|
+
*/
|
|
79
|
+
contract_max_origination_fee_bps: number;
|
|
80
|
+
/**
|
|
81
|
+
* @description Lifetime fee APR in basis points
|
|
82
|
+
* @example 2000
|
|
83
|
+
*/
|
|
84
|
+
lifetime_fee_apr_bps: number;
|
|
85
|
+
/**
|
|
86
|
+
* @description Liquidation fee in basis points
|
|
87
|
+
* @example 250
|
|
88
|
+
*/
|
|
89
|
+
liquidation_fee_bps: number;
|
|
90
|
+
/**
|
|
91
|
+
* @description This partner's origination fee component in basis points, added to the protocol tier fee. `0` by default.
|
|
92
|
+
* @example 0
|
|
93
|
+
*/
|
|
94
|
+
partner_origination_fee_bps: number;
|
|
95
|
+
/**
|
|
96
|
+
* @description This partner's Polymarket builder taker fee in basis points (flat percentage of notional). `0` by default.
|
|
97
|
+
* @example 0
|
|
98
|
+
*/
|
|
99
|
+
partner_trading_fee_bps: number;
|
|
100
|
+
};
|
|
101
|
+
FeeReportBody: {
|
|
102
|
+
/**
|
|
103
|
+
* @description Leverage in basis points (20000 = 2x, 100000 = 10x). Must be divisible by 2500. Maximum 10x.
|
|
104
|
+
* @example 50000
|
|
105
|
+
*/
|
|
106
|
+
leverage_bps: number;
|
|
107
|
+
/**
|
|
108
|
+
* @description Market ticker
|
|
109
|
+
* @example TRUMP-2024-WIN
|
|
110
|
+
*/
|
|
111
|
+
market_ticker: string;
|
|
112
|
+
/**
|
|
113
|
+
* @description Notional amount in USD pips (10,000 pips = $1.00)
|
|
114
|
+
* @example 50000
|
|
115
|
+
*/
|
|
116
|
+
notional_amount_usd_pips: string;
|
|
117
|
+
/**
|
|
118
|
+
* @description Market side (yes or no)
|
|
119
|
+
* @enum {string}
|
|
120
|
+
*/
|
|
121
|
+
effective_side: "yes" | "no";
|
|
122
|
+
/**
|
|
123
|
+
* @description Effective-side entry price in USD pips (10000 pips = $1) to compute against. When omitted, the market's current reference price is used. Provide it to compute deterministically against a known price.
|
|
124
|
+
* @example 5100
|
|
125
|
+
*/
|
|
126
|
+
entry_price_usd_pips?: string;
|
|
127
|
+
};
|
|
128
|
+
CustomerFeeReport: {
|
|
129
|
+
/**
|
|
130
|
+
* @description Market ticker
|
|
131
|
+
* @example TRUMP-2024-WIN
|
|
132
|
+
*/
|
|
133
|
+
market_ticker: string;
|
|
134
|
+
/**
|
|
135
|
+
* @description Market side
|
|
136
|
+
* @enum {string}
|
|
137
|
+
*/
|
|
138
|
+
effective_side: "yes" | "no";
|
|
139
|
+
/**
|
|
140
|
+
* @description Leverage in basis points (20000 = 2x)
|
|
141
|
+
* @example 20000
|
|
142
|
+
*/
|
|
143
|
+
leverage_bps: number;
|
|
144
|
+
/**
|
|
145
|
+
* @description Entry price used for the computation, in USD pips
|
|
146
|
+
* @example 5100
|
|
147
|
+
*/
|
|
148
|
+
entry_price_usd_pips: string;
|
|
149
|
+
/**
|
|
150
|
+
* @description Notional in USD pips (10000 pips = $1)
|
|
151
|
+
* @example 500000
|
|
152
|
+
*/
|
|
153
|
+
notional_amount_usd_pips: string;
|
|
154
|
+
/**
|
|
155
|
+
* @description Notional in USDC units (1,000,000 = 1 USDC)
|
|
156
|
+
* @example 50000000
|
|
157
|
+
*/
|
|
158
|
+
notional_usdc_units: string;
|
|
159
|
+
/**
|
|
160
|
+
* @description Collateral in USDC units
|
|
161
|
+
* @example 25000000
|
|
162
|
+
*/
|
|
163
|
+
collateral_usdc_units: string;
|
|
164
|
+
/**
|
|
165
|
+
* @description Combined origination fee in basis points
|
|
166
|
+
* @example 200
|
|
167
|
+
*/
|
|
168
|
+
origination_fee_bps: number;
|
|
169
|
+
/**
|
|
170
|
+
* @description Origination fee in USDC units
|
|
171
|
+
* @example 1000000
|
|
172
|
+
*/
|
|
173
|
+
origination_fee_usdc_units: string;
|
|
174
|
+
/**
|
|
175
|
+
* @description Protocol component of the origination fee in basis points
|
|
176
|
+
* @example 200
|
|
177
|
+
*/
|
|
178
|
+
protocol_origination_fee_bps: number;
|
|
179
|
+
/**
|
|
180
|
+
* @description Partner component of the origination fee in basis points
|
|
181
|
+
* @example 0
|
|
182
|
+
*/
|
|
183
|
+
partner_origination_fee_bps: number;
|
|
184
|
+
/**
|
|
185
|
+
* @description Polymarket venue trading fee rate in basis points (`feeRateBps`).
|
|
186
|
+
* @example 0
|
|
187
|
+
*/
|
|
188
|
+
polymarket_trading_fee_bps: number;
|
|
189
|
+
/**
|
|
190
|
+
* @description Partner Polymarket builder taker fee in basis points (flat percentage of notional).
|
|
191
|
+
* @example 0
|
|
192
|
+
*/
|
|
193
|
+
partner_trading_fee_bps: number;
|
|
194
|
+
/**
|
|
195
|
+
* @description Expected venue trading fee in USDC units charged to open the position (protocol venue fee + partner builder fee), computed from notional and entry price.
|
|
196
|
+
* @example 2204118
|
|
197
|
+
*/
|
|
198
|
+
expected_open_trading_fee_usdc_units: string;
|
|
199
|
+
/**
|
|
200
|
+
* @description Total amount the user must provide to open, in USDC units.
|
|
201
|
+
* @example 28204118
|
|
202
|
+
*/
|
|
203
|
+
total_user_amount_usdc_units: string;
|
|
204
|
+
/**
|
|
205
|
+
* @description Deterministic at-entry liquidation price ESTIMATE in USD pips (10000 pips = $1): `entry * (L-1)/L * (1 + liquidationFeeBps/10000)`. This is a closed-form estimate; the binding offer uses a TWAP/inference-based price that may differ.
|
|
206
|
+
* @example 2629
|
|
207
|
+
*/
|
|
208
|
+
estimated_liquidation_price_usd_pips: string;
|
|
209
|
+
/**
|
|
210
|
+
* @description Gross maximum gain in USDC units: full value on a win (settlement at $1) minus notional, before fees. Profit over principal; may be negative.
|
|
211
|
+
* @example 48039215
|
|
212
|
+
*/
|
|
213
|
+
gross_max_gain_usdc_units: string;
|
|
214
|
+
/**
|
|
215
|
+
* @description Net maximum gain in USDC units: grossMaxGain minus the open trading fee and the origination fee. Assumes a win via settlement (no exit trading fee) and excludes lifetime fees, so it is an upper bound. May be negative.
|
|
216
|
+
* @example 44835097
|
|
217
|
+
*/
|
|
218
|
+
net_max_gain_usdc_units: string;
|
|
219
|
+
};
|
|
41
220
|
CustomerLimit: {
|
|
42
221
|
/**
|
|
43
222
|
* @description Total limit formatted as USD
|
|
@@ -898,6 +1077,16 @@ interface components {
|
|
|
898
1077
|
* @example 0
|
|
899
1078
|
*/
|
|
900
1079
|
collected_liquidation_fee_usd_pips: string;
|
|
1080
|
+
/**
|
|
1081
|
+
* @description Volume-weighted notional realized across all unwinds and the final close, formatted as USD. Null for reverted or cancelled positions.
|
|
1082
|
+
* @example 5.25
|
|
1083
|
+
*/
|
|
1084
|
+
exit_notional_usd?: string | null;
|
|
1085
|
+
/**
|
|
1086
|
+
* @description Exit notional in USD pips. Null for reverted or cancelled positions.
|
|
1087
|
+
* @example 52500
|
|
1088
|
+
*/
|
|
1089
|
+
exit_notional_usd_pips?: string | null;
|
|
901
1090
|
/**
|
|
902
1091
|
* @description Realized PnL net of all fees (origination + lifetime + liquidation + venue) as return on equity in basis points
|
|
903
1092
|
* @example 1700
|
|
@@ -1078,6 +1267,38 @@ interface components {
|
|
|
1078
1267
|
*/
|
|
1079
1268
|
min_fill_bps?: number;
|
|
1080
1269
|
};
|
|
1270
|
+
CustomerOfferMaxGain: {
|
|
1271
|
+
/**
|
|
1272
|
+
* @description Gross max gain (profit before fees) formatted as USD
|
|
1273
|
+
* @example 1.90
|
|
1274
|
+
*/
|
|
1275
|
+
gross_max_gain_usd: string;
|
|
1276
|
+
/**
|
|
1277
|
+
* @description Gross max gain in USD pips (10000 pips = $1)
|
|
1278
|
+
* @example 19000
|
|
1279
|
+
*/
|
|
1280
|
+
gross_max_gain_usd_pips: string;
|
|
1281
|
+
/**
|
|
1282
|
+
* @description Gross max gain in USDC units (1,000,000 units = 1 USDC). May be negative.
|
|
1283
|
+
* @example 1900000
|
|
1284
|
+
*/
|
|
1285
|
+
gross_max_gain_usdc_units: string;
|
|
1286
|
+
/**
|
|
1287
|
+
* @description Net max gain (profit after fees) formatted as USD
|
|
1288
|
+
* @example 1.40
|
|
1289
|
+
*/
|
|
1290
|
+
net_max_gain_usd: string;
|
|
1291
|
+
/**
|
|
1292
|
+
* @description Net max gain in USD pips (10000 pips = $1)
|
|
1293
|
+
* @example 14000
|
|
1294
|
+
*/
|
|
1295
|
+
net_max_gain_usd_pips: string;
|
|
1296
|
+
/**
|
|
1297
|
+
* @description Net max gain in USDC units (1,000,000 units = 1 USDC). May be negative.
|
|
1298
|
+
* @example 1400000
|
|
1299
|
+
*/
|
|
1300
|
+
net_max_gain_usdc_units: string;
|
|
1301
|
+
};
|
|
1081
1302
|
CustomerOffer: {
|
|
1082
1303
|
/**
|
|
1083
1304
|
* @description Offer ID
|
|
@@ -1325,6 +1546,8 @@ interface components {
|
|
|
1325
1546
|
min_fill_bps?: number;
|
|
1326
1547
|
/** @description Base64-encoded Solana transaction (present for Solana markets only) */
|
|
1327
1548
|
swap_transaction?: string;
|
|
1549
|
+
/** @description Expected maximum gain on a win (profit over principal). Only present when the request includes `expand=max_gain`; omitted otherwise. Assumes settlement at $1.00 (no exit trading fee) and excludes time-based lifetime fees, so it is an upper bound. */
|
|
1550
|
+
max_gain?: components["schemas"]["CustomerOfferMaxGain"];
|
|
1328
1551
|
/**
|
|
1329
1552
|
* @description Total amount user must provide formatted as USD
|
|
1330
1553
|
* @example 2.73
|
|
@@ -1383,6 +1606,10 @@ type PositionTransactions = CamelizeKeys<Raw["PositionTransactions"]>;
|
|
|
1383
1606
|
type ContractInfo = CamelizeKeys<Raw["CustomerContractInfo"]>;
|
|
1384
1607
|
type CustomerLimit = CamelizeKeys<Raw["CustomerLimit"]>;
|
|
1385
1608
|
type CreateTokenResult = CamelizeKeys<Raw["CreateTokenResult"]>;
|
|
1609
|
+
type FeeRatesOriginationTier = CamelizeKeys<Raw["CustomerOriginationFeeTier"]>;
|
|
1610
|
+
type FeeRatesMarket = CamelizeKeys<Raw["CustomerFeeRatesMarket"]>;
|
|
1611
|
+
type FeeRates = CamelizeKeys<Raw["CustomerFeeRates"]>;
|
|
1612
|
+
type FeeReport = CamelizeKeys<Raw["CustomerFeeReport"]>;
|
|
1386
1613
|
interface CreateOfferParams {
|
|
1387
1614
|
marketTicker: string;
|
|
1388
1615
|
effectiveSide: "yes" | "no";
|
|
@@ -1391,8 +1618,15 @@ interface CreateOfferParams {
|
|
|
1391
1618
|
slippageBps: number;
|
|
1392
1619
|
pmProvider?: "polymarket" | "kalshi";
|
|
1393
1620
|
}
|
|
1621
|
+
interface FeeReportParams {
|
|
1622
|
+
marketTicker: string;
|
|
1623
|
+
effectiveSide: "yes" | "no";
|
|
1624
|
+
leverageBps: number;
|
|
1625
|
+
notionalAmountUsdPips: string;
|
|
1626
|
+
entryPriceUsdPips?: string;
|
|
1627
|
+
}
|
|
1394
1628
|
declare function isOpenPosition(p: Position): p is OpenPosition;
|
|
1395
1629
|
declare function isClosedPosition(p: Position): p is ClosedPosition;
|
|
1396
1630
|
declare function leverageMaxBps(lev: MarketLeverage, side: "yes" | "no"): number;
|
|
1397
1631
|
|
|
1398
|
-
export {
|
|
1632
|
+
export { type PositionUnwind as A, type PositionUnwindList as B, type CreateOfferParams as C, isClosedPosition as D, isOpenPosition as E, type FeeRates as F, leverageMaxBps as G, type PositionTransactions as H, type MarketPolymarket as I, type Market as M, type Offer as O, type Position as P, type CamelizeKeys as a, type CloseAttempt as b, type ClosedPosition as c, type ContractInfo as d, type CreateTokenResult as e, type CustomerLimit as f, type FeeRatesMarket as g, type FeeRatesOriginationTier as h, type FeeReport as i, type FeeReportParams as j, type MarketFees as k, type MarketLeverage as l, type MarketMaxLeveragePerNotional as m, type MarketPrices as n, type MarketSidedEligibility as o, type MarketSidedMaxLeveragePerNotional as p, type OpenPosition as q, type OriginationTier as r, type PositionClosedFees as s, type PositionCurrent as t, type PositionEntry as u, type PositionFailure as v, type PositionOpenFees as w, type PositionResult as x, type PositionRisk as y, type PositionTiming as z };
|
|
@@ -38,6 +38,185 @@ interface components {
|
|
|
38
38
|
*/
|
|
39
39
|
polygon_vault_contract_address: string;
|
|
40
40
|
};
|
|
41
|
+
CustomerOriginationFeeTier: {
|
|
42
|
+
/**
|
|
43
|
+
* @description Upper leverage bound (inclusive) in basis points for this tier. The last tier is the catch-all.
|
|
44
|
+
* @example 40000
|
|
45
|
+
*/
|
|
46
|
+
max_leverage_bps: number;
|
|
47
|
+
/**
|
|
48
|
+
* @description Protocol origination fee in basis points applied at or below this tier's leverage bound.
|
|
49
|
+
* @example 200
|
|
50
|
+
*/
|
|
51
|
+
fee_bps: number;
|
|
52
|
+
};
|
|
53
|
+
CustomerFeeRatesMarket: {
|
|
54
|
+
/**
|
|
55
|
+
* @description Market ticker
|
|
56
|
+
* @example TRUMP-2024-WIN
|
|
57
|
+
*/
|
|
58
|
+
ticker: string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Polymarket venue trading fee rate in basis points (`feeRateBps`).
|
|
61
|
+
* @example 0
|
|
62
|
+
*/
|
|
63
|
+
polymarket_trading_fee_bps: number;
|
|
64
|
+
/**
|
|
65
|
+
* @description Polymarket fee-curve exponent (`feeExponent`). `1` for the standard quadratic curve.
|
|
66
|
+
* @example 1
|
|
67
|
+
*/
|
|
68
|
+
polymarket_fee_exponent: number;
|
|
69
|
+
};
|
|
70
|
+
CustomerFeeRates: {
|
|
71
|
+
/** @description Per-market venue fee fields. Only present when the request includes a `ticker` query parameter. */
|
|
72
|
+
market?: components["schemas"]["CustomerFeeRatesMarket"];
|
|
73
|
+
/** @description Leverage-tiered protocol origination fee schedule. Resolve a leverage to its fee by picking the first tier whose `maxLeverageBps >= leverageBps` (the last tier is the catch-all). */
|
|
74
|
+
origination_fee_tiers: components["schemas"]["CustomerOriginationFeeTier"][];
|
|
75
|
+
/**
|
|
76
|
+
* @description Maximum combined (protocol + partner) origination fee in basis points enforced on-chain.
|
|
77
|
+
* @example 1000
|
|
78
|
+
*/
|
|
79
|
+
contract_max_origination_fee_bps: number;
|
|
80
|
+
/**
|
|
81
|
+
* @description Lifetime fee APR in basis points
|
|
82
|
+
* @example 2000
|
|
83
|
+
*/
|
|
84
|
+
lifetime_fee_apr_bps: number;
|
|
85
|
+
/**
|
|
86
|
+
* @description Liquidation fee in basis points
|
|
87
|
+
* @example 250
|
|
88
|
+
*/
|
|
89
|
+
liquidation_fee_bps: number;
|
|
90
|
+
/**
|
|
91
|
+
* @description This partner's origination fee component in basis points, added to the protocol tier fee. `0` by default.
|
|
92
|
+
* @example 0
|
|
93
|
+
*/
|
|
94
|
+
partner_origination_fee_bps: number;
|
|
95
|
+
/**
|
|
96
|
+
* @description This partner's Polymarket builder taker fee in basis points (flat percentage of notional). `0` by default.
|
|
97
|
+
* @example 0
|
|
98
|
+
*/
|
|
99
|
+
partner_trading_fee_bps: number;
|
|
100
|
+
};
|
|
101
|
+
FeeReportBody: {
|
|
102
|
+
/**
|
|
103
|
+
* @description Leverage in basis points (20000 = 2x, 100000 = 10x). Must be divisible by 2500. Maximum 10x.
|
|
104
|
+
* @example 50000
|
|
105
|
+
*/
|
|
106
|
+
leverage_bps: number;
|
|
107
|
+
/**
|
|
108
|
+
* @description Market ticker
|
|
109
|
+
* @example TRUMP-2024-WIN
|
|
110
|
+
*/
|
|
111
|
+
market_ticker: string;
|
|
112
|
+
/**
|
|
113
|
+
* @description Notional amount in USD pips (10,000 pips = $1.00)
|
|
114
|
+
* @example 50000
|
|
115
|
+
*/
|
|
116
|
+
notional_amount_usd_pips: string;
|
|
117
|
+
/**
|
|
118
|
+
* @description Market side (yes or no)
|
|
119
|
+
* @enum {string}
|
|
120
|
+
*/
|
|
121
|
+
effective_side: "yes" | "no";
|
|
122
|
+
/**
|
|
123
|
+
* @description Effective-side entry price in USD pips (10000 pips = $1) to compute against. When omitted, the market's current reference price is used. Provide it to compute deterministically against a known price.
|
|
124
|
+
* @example 5100
|
|
125
|
+
*/
|
|
126
|
+
entry_price_usd_pips?: string;
|
|
127
|
+
};
|
|
128
|
+
CustomerFeeReport: {
|
|
129
|
+
/**
|
|
130
|
+
* @description Market ticker
|
|
131
|
+
* @example TRUMP-2024-WIN
|
|
132
|
+
*/
|
|
133
|
+
market_ticker: string;
|
|
134
|
+
/**
|
|
135
|
+
* @description Market side
|
|
136
|
+
* @enum {string}
|
|
137
|
+
*/
|
|
138
|
+
effective_side: "yes" | "no";
|
|
139
|
+
/**
|
|
140
|
+
* @description Leverage in basis points (20000 = 2x)
|
|
141
|
+
* @example 20000
|
|
142
|
+
*/
|
|
143
|
+
leverage_bps: number;
|
|
144
|
+
/**
|
|
145
|
+
* @description Entry price used for the computation, in USD pips
|
|
146
|
+
* @example 5100
|
|
147
|
+
*/
|
|
148
|
+
entry_price_usd_pips: string;
|
|
149
|
+
/**
|
|
150
|
+
* @description Notional in USD pips (10000 pips = $1)
|
|
151
|
+
* @example 500000
|
|
152
|
+
*/
|
|
153
|
+
notional_amount_usd_pips: string;
|
|
154
|
+
/**
|
|
155
|
+
* @description Notional in USDC units (1,000,000 = 1 USDC)
|
|
156
|
+
* @example 50000000
|
|
157
|
+
*/
|
|
158
|
+
notional_usdc_units: string;
|
|
159
|
+
/**
|
|
160
|
+
* @description Collateral in USDC units
|
|
161
|
+
* @example 25000000
|
|
162
|
+
*/
|
|
163
|
+
collateral_usdc_units: string;
|
|
164
|
+
/**
|
|
165
|
+
* @description Combined origination fee in basis points
|
|
166
|
+
* @example 200
|
|
167
|
+
*/
|
|
168
|
+
origination_fee_bps: number;
|
|
169
|
+
/**
|
|
170
|
+
* @description Origination fee in USDC units
|
|
171
|
+
* @example 1000000
|
|
172
|
+
*/
|
|
173
|
+
origination_fee_usdc_units: string;
|
|
174
|
+
/**
|
|
175
|
+
* @description Protocol component of the origination fee in basis points
|
|
176
|
+
* @example 200
|
|
177
|
+
*/
|
|
178
|
+
protocol_origination_fee_bps: number;
|
|
179
|
+
/**
|
|
180
|
+
* @description Partner component of the origination fee in basis points
|
|
181
|
+
* @example 0
|
|
182
|
+
*/
|
|
183
|
+
partner_origination_fee_bps: number;
|
|
184
|
+
/**
|
|
185
|
+
* @description Polymarket venue trading fee rate in basis points (`feeRateBps`).
|
|
186
|
+
* @example 0
|
|
187
|
+
*/
|
|
188
|
+
polymarket_trading_fee_bps: number;
|
|
189
|
+
/**
|
|
190
|
+
* @description Partner Polymarket builder taker fee in basis points (flat percentage of notional).
|
|
191
|
+
* @example 0
|
|
192
|
+
*/
|
|
193
|
+
partner_trading_fee_bps: number;
|
|
194
|
+
/**
|
|
195
|
+
* @description Expected venue trading fee in USDC units charged to open the position (protocol venue fee + partner builder fee), computed from notional and entry price.
|
|
196
|
+
* @example 2204118
|
|
197
|
+
*/
|
|
198
|
+
expected_open_trading_fee_usdc_units: string;
|
|
199
|
+
/**
|
|
200
|
+
* @description Total amount the user must provide to open, in USDC units.
|
|
201
|
+
* @example 28204118
|
|
202
|
+
*/
|
|
203
|
+
total_user_amount_usdc_units: string;
|
|
204
|
+
/**
|
|
205
|
+
* @description Deterministic at-entry liquidation price ESTIMATE in USD pips (10000 pips = $1): `entry * (L-1)/L * (1 + liquidationFeeBps/10000)`. This is a closed-form estimate; the binding offer uses a TWAP/inference-based price that may differ.
|
|
206
|
+
* @example 2629
|
|
207
|
+
*/
|
|
208
|
+
estimated_liquidation_price_usd_pips: string;
|
|
209
|
+
/**
|
|
210
|
+
* @description Gross maximum gain in USDC units: full value on a win (settlement at $1) minus notional, before fees. Profit over principal; may be negative.
|
|
211
|
+
* @example 48039215
|
|
212
|
+
*/
|
|
213
|
+
gross_max_gain_usdc_units: string;
|
|
214
|
+
/**
|
|
215
|
+
* @description Net maximum gain in USDC units: grossMaxGain minus the open trading fee and the origination fee. Assumes a win via settlement (no exit trading fee) and excludes lifetime fees, so it is an upper bound. May be negative.
|
|
216
|
+
* @example 44835097
|
|
217
|
+
*/
|
|
218
|
+
net_max_gain_usdc_units: string;
|
|
219
|
+
};
|
|
41
220
|
CustomerLimit: {
|
|
42
221
|
/**
|
|
43
222
|
* @description Total limit formatted as USD
|
|
@@ -898,6 +1077,16 @@ interface components {
|
|
|
898
1077
|
* @example 0
|
|
899
1078
|
*/
|
|
900
1079
|
collected_liquidation_fee_usd_pips: string;
|
|
1080
|
+
/**
|
|
1081
|
+
* @description Volume-weighted notional realized across all unwinds and the final close, formatted as USD. Null for reverted or cancelled positions.
|
|
1082
|
+
* @example 5.25
|
|
1083
|
+
*/
|
|
1084
|
+
exit_notional_usd?: string | null;
|
|
1085
|
+
/**
|
|
1086
|
+
* @description Exit notional in USD pips. Null for reverted or cancelled positions.
|
|
1087
|
+
* @example 52500
|
|
1088
|
+
*/
|
|
1089
|
+
exit_notional_usd_pips?: string | null;
|
|
901
1090
|
/**
|
|
902
1091
|
* @description Realized PnL net of all fees (origination + lifetime + liquidation + venue) as return on equity in basis points
|
|
903
1092
|
* @example 1700
|
|
@@ -1078,6 +1267,38 @@ interface components {
|
|
|
1078
1267
|
*/
|
|
1079
1268
|
min_fill_bps?: number;
|
|
1080
1269
|
};
|
|
1270
|
+
CustomerOfferMaxGain: {
|
|
1271
|
+
/**
|
|
1272
|
+
* @description Gross max gain (profit before fees) formatted as USD
|
|
1273
|
+
* @example 1.90
|
|
1274
|
+
*/
|
|
1275
|
+
gross_max_gain_usd: string;
|
|
1276
|
+
/**
|
|
1277
|
+
* @description Gross max gain in USD pips (10000 pips = $1)
|
|
1278
|
+
* @example 19000
|
|
1279
|
+
*/
|
|
1280
|
+
gross_max_gain_usd_pips: string;
|
|
1281
|
+
/**
|
|
1282
|
+
* @description Gross max gain in USDC units (1,000,000 units = 1 USDC). May be negative.
|
|
1283
|
+
* @example 1900000
|
|
1284
|
+
*/
|
|
1285
|
+
gross_max_gain_usdc_units: string;
|
|
1286
|
+
/**
|
|
1287
|
+
* @description Net max gain (profit after fees) formatted as USD
|
|
1288
|
+
* @example 1.40
|
|
1289
|
+
*/
|
|
1290
|
+
net_max_gain_usd: string;
|
|
1291
|
+
/**
|
|
1292
|
+
* @description Net max gain in USD pips (10000 pips = $1)
|
|
1293
|
+
* @example 14000
|
|
1294
|
+
*/
|
|
1295
|
+
net_max_gain_usd_pips: string;
|
|
1296
|
+
/**
|
|
1297
|
+
* @description Net max gain in USDC units (1,000,000 units = 1 USDC). May be negative.
|
|
1298
|
+
* @example 1400000
|
|
1299
|
+
*/
|
|
1300
|
+
net_max_gain_usdc_units: string;
|
|
1301
|
+
};
|
|
1081
1302
|
CustomerOffer: {
|
|
1082
1303
|
/**
|
|
1083
1304
|
* @description Offer ID
|
|
@@ -1325,6 +1546,8 @@ interface components {
|
|
|
1325
1546
|
min_fill_bps?: number;
|
|
1326
1547
|
/** @description Base64-encoded Solana transaction (present for Solana markets only) */
|
|
1327
1548
|
swap_transaction?: string;
|
|
1549
|
+
/** @description Expected maximum gain on a win (profit over principal). Only present when the request includes `expand=max_gain`; omitted otherwise. Assumes settlement at $1.00 (no exit trading fee) and excludes time-based lifetime fees, so it is an upper bound. */
|
|
1550
|
+
max_gain?: components["schemas"]["CustomerOfferMaxGain"];
|
|
1328
1551
|
/**
|
|
1329
1552
|
* @description Total amount user must provide formatted as USD
|
|
1330
1553
|
* @example 2.73
|
|
@@ -1383,6 +1606,10 @@ type PositionTransactions = CamelizeKeys<Raw["PositionTransactions"]>;
|
|
|
1383
1606
|
type ContractInfo = CamelizeKeys<Raw["CustomerContractInfo"]>;
|
|
1384
1607
|
type CustomerLimit = CamelizeKeys<Raw["CustomerLimit"]>;
|
|
1385
1608
|
type CreateTokenResult = CamelizeKeys<Raw["CreateTokenResult"]>;
|
|
1609
|
+
type FeeRatesOriginationTier = CamelizeKeys<Raw["CustomerOriginationFeeTier"]>;
|
|
1610
|
+
type FeeRatesMarket = CamelizeKeys<Raw["CustomerFeeRatesMarket"]>;
|
|
1611
|
+
type FeeRates = CamelizeKeys<Raw["CustomerFeeRates"]>;
|
|
1612
|
+
type FeeReport = CamelizeKeys<Raw["CustomerFeeReport"]>;
|
|
1386
1613
|
interface CreateOfferParams {
|
|
1387
1614
|
marketTicker: string;
|
|
1388
1615
|
effectiveSide: "yes" | "no";
|
|
@@ -1391,8 +1618,15 @@ interface CreateOfferParams {
|
|
|
1391
1618
|
slippageBps: number;
|
|
1392
1619
|
pmProvider?: "polymarket" | "kalshi";
|
|
1393
1620
|
}
|
|
1621
|
+
interface FeeReportParams {
|
|
1622
|
+
marketTicker: string;
|
|
1623
|
+
effectiveSide: "yes" | "no";
|
|
1624
|
+
leverageBps: number;
|
|
1625
|
+
notionalAmountUsdPips: string;
|
|
1626
|
+
entryPriceUsdPips?: string;
|
|
1627
|
+
}
|
|
1394
1628
|
declare function isOpenPosition(p: Position): p is OpenPosition;
|
|
1395
1629
|
declare function isClosedPosition(p: Position): p is ClosedPosition;
|
|
1396
1630
|
declare function leverageMaxBps(lev: MarketLeverage, side: "yes" | "no"): number;
|
|
1397
1631
|
|
|
1398
|
-
export {
|
|
1632
|
+
export { type PositionUnwind as A, type PositionUnwindList as B, type CreateOfferParams as C, isClosedPosition as D, isOpenPosition as E, type FeeRates as F, leverageMaxBps as G, type PositionTransactions as H, type MarketPolymarket as I, type Market as M, type Offer as O, type Position as P, type CamelizeKeys as a, type CloseAttempt as b, type ClosedPosition as c, type ContractInfo as d, type CreateTokenResult as e, type CustomerLimit as f, type FeeRatesMarket as g, type FeeRatesOriginationTier as h, type FeeReport as i, type FeeReportParams as j, type MarketFees as k, type MarketLeverage as l, type MarketMaxLeveragePerNotional as m, type MarketPrices as n, type MarketSidedEligibility as o, type MarketSidedMaxLeveragePerNotional as p, type OpenPosition as q, type OriginationTier as r, type PositionClosedFees as s, type PositionCurrent as t, type PositionEntry as u, type PositionFailure as v, type PositionOpenFees as w, type PositionResult as x, type PositionRisk as y, type PositionTiming as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DimesApiError,
|
|
3
3
|
DimesError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PZCBUVPD.mjs";
|
|
5
5
|
|
|
6
6
|
// src/quote/build-quote-params.ts
|
|
7
7
|
var DEFAULT_LEVERAGE_STEP_BPS = 2500;
|
|
@@ -21,6 +21,7 @@ function buildQuoteParams(params, stepBps = DEFAULT_LEVERAGE_STEP_BPS) {
|
|
|
21
21
|
var pipsPerUsd = 1e4;
|
|
22
22
|
var bpsPerUnit = 1e4;
|
|
23
23
|
var bpsPerPct = 100;
|
|
24
|
+
var minFillBpsMax = 5e3;
|
|
24
25
|
var centsFactor = 100;
|
|
25
26
|
var decimalPlaces = 2;
|
|
26
27
|
var marketMovedCodes = /* @__PURE__ */ new Set([
|
|
@@ -118,6 +119,13 @@ function quoteErrorHint(code, params, context) {
|
|
|
118
119
|
}
|
|
119
120
|
return { kind: "raise-leverage", minLeverageBps };
|
|
120
121
|
}
|
|
122
|
+
case "quote_min_fill_bps_below_floor": {
|
|
123
|
+
const floorMinFillBps = num(params, "floorMinFillBps");
|
|
124
|
+
if (floorMinFillBps === null || floorMinFillBps > minFillBpsMax) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return { kind: "raise-min-fill", minFillBps: floorMinFillBps };
|
|
128
|
+
}
|
|
121
129
|
case "quote_slippage_too_high": {
|
|
122
130
|
const currentSlippageBps = num(params, "currentSlippageBps");
|
|
123
131
|
const maxSlippageBps = num(params, "maxSlippageBps");
|
|
@@ -200,6 +208,14 @@ function hintAdjustment(hint, current) {
|
|
|
200
208
|
toLabel: `${(hint.maxSlippageBps / bpsPerPct).toFixed(decimalPlaces).replace(/\.?0+$/, "")}%`,
|
|
201
209
|
reason: "raise-slippage"
|
|
202
210
|
};
|
|
211
|
+
case "raise-min-fill":
|
|
212
|
+
return {
|
|
213
|
+
field: "minFill",
|
|
214
|
+
fromValue: current.minFillBps ?? 0,
|
|
215
|
+
toValue: hint.minFillBps,
|
|
216
|
+
toLabel: `${(hint.minFillBps / bpsPerPct).toFixed(decimalPlaces).replace(/\.?0+$/, "")}%`,
|
|
217
|
+
reason: "raise-min-fill"
|
|
218
|
+
};
|
|
203
219
|
default:
|
|
204
220
|
return null;
|
|
205
221
|
}
|
|
@@ -305,4 +321,4 @@ export {
|
|
|
305
321
|
hintAdjustment,
|
|
306
322
|
executeQuote
|
|
307
323
|
};
|
|
308
|
-
//# sourceMappingURL=chunk-
|
|
324
|
+
//# sourceMappingURL=chunk-3OPRSKCY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/quote/build-quote-params.ts","../src/quote/quote-error-hints.ts","../src/quote/quote.ts"],"sourcesContent":["import type { CreateOfferParams } from \"../types\";\nimport type { QuoteParams } from \"../types/quote\";\n\nconst DEFAULT_LEVERAGE_STEP_BPS = 2500;\n\nexport function buildQuoteParams(params: QuoteParams, stepBps: number = DEFAULT_LEVERAGE_STEP_BPS): CreateOfferParams {\n const leverageBps = Math.round(params.leverageBps / stepBps) * stepBps;\n const notionalUsdPips = Math.round(params.collateralUsd * leverageBps);\n\n return {\n marketTicker: params.marketTicker,\n effectiveSide: params.side,\n leverageBps,\n notionalAmountUsdPips: notionalUsdPips.toString(),\n slippageBps: params.slippageBps,\n };\n}\n","const pipsPerUsd = 10_000;\nconst bpsPerUnit = 10_000;\nconst bpsPerPct = 100;\nconst minFillBpsMax = 5_000;\nconst centsFactor = 100;\nconst decimalPlaces = 2;\n\nexport const marketMovedCodes = new Set([\n \"quote_slippage_too_high\",\n \"quote_insufficient_liquidity\",\n \"quote_entry_price_out_of_range\",\n \"quote_entry_bid_depth_too_low\",\n \"quote_entry_depth_too_low\",\n \"quote_entry_spread_too_wide\",\n]);\n\nexport type QuoteHint =\n | { kind: \"use-max-collateral\"; maxCollateralUsd: number; minCollateralUsd: number }\n | { kind: \"raise-collateral\"; minCollateralUsd: number }\n | { kind: \"clamp-leverage\"; maxLeverageBps?: number }\n | { kind: \"raise-leverage\"; minLeverageBps: number }\n | { kind: \"raise-slippage\"; currentSlippageBps: number; maxSlippageBps: number }\n | { kind: \"raise-min-fill\"; minFillBps: number }\n | { kind: \"market-full\" }\n | { kind: \"insufficient-liquidity\"; maxCollateralUsd: number; minCollateralUsd: number }\n | null;\n\ntype Params = Record<string, unknown> | null | undefined;\n\nfunction num(params: Params, key: string): number | null {\n if (!params) {\n return null;\n }\n const raw = params[key];\n if (raw === null || raw === undefined) {\n return null;\n }\n // eslint-disable-next-line no-restricted-syntax\n const n = typeof raw === \"string\" ? Number(raw) : typeof raw === \"number\" ? raw : NaN;\n return Number.isFinite(n) ? n : null;\n}\n\nfunction pipsToUsd(pips: number): number {\n return pips / pipsPerUsd;\n}\n\nfunction notionalPipsToCollateralUsd(notionalPips: number, leverageBps: number): number | null {\n if (!Number.isFinite(leverageBps) || leverageBps <= 0) {\n return null;\n }\n return (notionalPips * bpsPerUnit) / leverageBps / pipsPerUsd;\n}\n\nfunction buildExhaustedHint(\n exhaustedKind: \"market-full\" | \"insufficient-liquidity\",\n maxCollateralUsd: number,\n minCollateralUsd: number,\n): QuoteHint {\n if (exhaustedKind === \"insufficient-liquidity\") {\n return { kind: \"insufficient-liquidity\", maxCollateralUsd, minCollateralUsd };\n }\n return { kind: \"market-full\" };\n}\n\nfunction resolveMaxCollateralHint(\n params: Params,\n context: { leverageBps: number },\n capacityKey: string,\n exhaustedKind: \"market-full\" | \"insufficient-liquidity\",\n): QuoteHint {\n const serverMaxCollateralPips = num(params, \"maxSupportedCollateralUsdPips\");\n const capacityPips = num(params, capacityKey);\n const minNotionalPips = num(params, \"minNotionalUsdPips\");\n\n const fromServer = serverMaxCollateralPips !== null ? pipsToUsd(serverMaxCollateralPips) : null;\n const fromCapacity = capacityPips !== null ? notionalPipsToCollateralUsd(capacityPips, context.leverageBps) : null;\n const maxCollateralUsd =\n fromServer !== null && fromCapacity !== null ? Math.min(fromServer, fromCapacity) : (fromServer ?? fromCapacity);\n\n const minCollateralUsd =\n minNotionalPips !== null ? notionalPipsToCollateralUsd(minNotionalPips, context.leverageBps) : null;\n\n if (maxCollateralUsd === null || minCollateralUsd === null) {\n return null;\n }\n if (maxCollateralUsd < minCollateralUsd) {\n return buildExhaustedHint(exhaustedKind, maxCollateralUsd, minCollateralUsd);\n }\n return { kind: \"use-max-collateral\", maxCollateralUsd, minCollateralUsd };\n}\n\n// eslint-disable-next-line complexity\nexport function quoteErrorHint(code: string | null, params: Params, context: { leverageBps: number }): QuoteHint {\n if (!code) {\n return null;\n }\n\n switch (code) {\n case \"quote_side_capacity_exceeded\":\n case \"quote_user_position_limit_exceeded\":\n case \"quote_market_position_limit_exceeded\":\n case \"quote_side_position_limit_exceeded\":\n case \"quote_global_position_limit_exceeded\":\n case \"quote_partner_position_limit_exceeded\":\n return resolveMaxCollateralHint(params, context, \"availableCapacityUsdPips\", \"market-full\");\n\n case \"quote_insufficient_liquidity\":\n return resolveMaxCollateralHint(params, context, \"slippageMaxUsdPips\", \"market-full\");\n\n case \"notional_selector_insufficient_liquidity\":\n return resolveMaxCollateralHint(params, context, \"slippageMaxUsdPips\", \"insufficient-liquidity\");\n\n case \"quote_leverage_exceeds_collateral_floor\": {\n const minCollateralPips = num(params, \"minCollateralUsdPips\");\n if (minCollateralPips === null) {\n return null;\n }\n return { kind: \"raise-collateral\", minCollateralUsd: pipsToUsd(minCollateralPips) };\n }\n\n case \"quote_leverage_exceeds_maximum\":\n case \"quote_leverage_exceeds_model_max\": {\n const maxLeverageBps = num(params, \"maxLeverageBps\");\n if (maxLeverageBps === null) {\n return null;\n }\n return { kind: \"clamp-leverage\", maxLeverageBps };\n }\n\n case \"quote_leverage_too_high_for_price\": {\n const maxLeverageBps = num(params, \"maxAcceptableLeverageBps\");\n if (maxLeverageBps === null) {\n return null;\n }\n return { kind: \"clamp-leverage\", maxLeverageBps };\n }\n\n case \"quote_leverage_below_minimum\": {\n const minLeverageBps = num(params, \"minLeverageBps\");\n if (minLeverageBps === null) {\n return null;\n }\n return { kind: \"raise-leverage\", minLeverageBps };\n }\n\n case \"quote_min_fill_bps_below_floor\": {\n const floorMinFillBps = num(params, \"floorMinFillBps\");\n if (floorMinFillBps === null || floorMinFillBps > minFillBpsMax) {\n return null;\n }\n return { kind: \"raise-min-fill\", minFillBps: floorMinFillBps };\n }\n\n case \"quote_slippage_too_high\": {\n const currentSlippageBps = num(params, \"currentSlippageBps\");\n const maxSlippageBps = num(params, \"maxSlippageBps\");\n if (currentSlippageBps === null || maxSlippageBps === null) {\n return null;\n }\n return { kind: \"raise-slippage\", currentSlippageBps, maxSlippageBps };\n }\n\n default:\n return null;\n }\n}\n\nexport type CorrectedField = \"collateral\" | \"leverage\" | \"slippage\" | \"minFill\";\n\nexport type HintAdjustment =\n | {\n field: \"collateral\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"max-collateral\" | \"min-collateral\";\n }\n | {\n field: \"leverage\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"clamp-max\" | \"raise-min\";\n }\n | {\n field: \"slippage\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"raise-slippage\";\n }\n | {\n field: \"minFill\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"raise-min-fill\";\n }\n | null;\n\nfunction formatUsd(value: number): string {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(value);\n}\n\nfunction bpsToMultiplier(bps: number): string {\n return `${(bps / bpsPerUnit).toFixed(1).replace(/\\.0$/, \"\")}x`;\n}\n\n// eslint-disable-next-line complexity\nexport function hintAdjustment(\n hint: QuoteHint,\n current: { collateralUsd: number; leverageBps: number; slippageBps: number; minFillBps?: number },\n): HintAdjustment {\n if (!hint) {\n return null;\n }\n\n switch (hint.kind) {\n case \"use-max-collateral\": {\n const to = Math.max(0, Math.floor(hint.maxCollateralUsd * centsFactor) / centsFactor);\n if (to <= 0) {\n return null;\n }\n return {\n field: \"collateral\",\n fromValue: current.collateralUsd,\n toValue: to,\n toLabel: formatUsd(to),\n reason: \"max-collateral\",\n };\n }\n case \"raise-collateral\": {\n const to = Math.ceil(hint.minCollateralUsd * centsFactor) / centsFactor;\n if (to <= 0) {\n return null;\n }\n return {\n field: \"collateral\",\n fromValue: current.collateralUsd,\n toValue: to,\n toLabel: formatUsd(to),\n reason: \"min-collateral\",\n };\n }\n case \"clamp-leverage\": {\n if (hint.maxLeverageBps === undefined) {\n return null;\n }\n return {\n field: \"leverage\",\n fromValue: current.leverageBps,\n toValue: hint.maxLeverageBps,\n toLabel: bpsToMultiplier(hint.maxLeverageBps),\n reason: \"clamp-max\",\n };\n }\n case \"raise-leverage\":\n return {\n field: \"leverage\",\n fromValue: current.leverageBps,\n toValue: hint.minLeverageBps,\n toLabel: bpsToMultiplier(hint.minLeverageBps),\n reason: \"raise-min\",\n };\n case \"raise-slippage\":\n return {\n field: \"slippage\",\n fromValue: hint.currentSlippageBps,\n toValue: hint.maxSlippageBps,\n toLabel: `${(hint.maxSlippageBps / bpsPerPct).toFixed(decimalPlaces).replace(/\\.?0+$/, \"\")}%`,\n reason: \"raise-slippage\",\n };\n case \"raise-min-fill\":\n return {\n field: \"minFill\",\n fromValue: current.minFillBps ?? 0,\n toValue: hint.minFillBps,\n toLabel: `${(hint.minFillBps / bpsPerPct).toFixed(decimalPlaces).replace(/\\.?0+$/, \"\")}%`,\n reason: \"raise-min-fill\",\n };\n default:\n return null;\n }\n}\n","import { DimesApiError, DimesError } from \"../errors/dimes-error\";\nimport type { CreateOfferParams, Offer } from \"../types\";\nimport type { QuoteOptions, QuoteParams, QuoteResult } from \"../types/quote\";\nimport { buildQuoteParams } from \"./build-quote-params\";\nimport { type HintAdjustment, hintAdjustment, marketMovedCodes, quoteErrorHint } from \"./quote-error-hints\";\n\nexport interface QuoteClient {\n createDraftQuote(params: CreateOfferParams): Promise<Offer>;\n promoteDraftQuote(draftId: string): Promise<Offer>;\n createQuote(params: CreateOfferParams): Promise<Offer>;\n}\n\nconst DEFAULT_MAX_RETRIES = 3;\n\nfunction isMarketMovedError(err: unknown): boolean {\n return err instanceof DimesApiError && marketMovedCodes.has(err.code);\n}\n\nfunction applyAdjustment(\n params: CreateOfferParams,\n adj: NonNullable<HintAdjustment>,\n currentParams: QuoteParams,\n): CreateOfferParams {\n switch (adj.field) {\n case \"collateral\": {\n const notionalUsdPips = Math.round(adj.toValue * params.leverageBps);\n return { ...params, notionalAmountUsdPips: notionalUsdPips.toString() };\n }\n case \"leverage\": {\n const notionalUsdPips = Math.round(currentParams.collateralUsd * adj.toValue);\n return {\n ...params,\n leverageBps: adj.toValue,\n notionalAmountUsdPips: notionalUsdPips.toString(),\n };\n }\n case \"slippage\":\n return { ...params, slippageBps: adj.toValue };\n default:\n return params;\n }\n}\n\nfunction handleMarketMoved(err: unknown, attempt: number, maxRetries: number): boolean {\n return isMarketMovedError(err) && attempt < maxRetries;\n}\n\nfunction handleCorrection(err: unknown, currentParams: QuoteParams): { adj: NonNullable<HintAdjustment> } | null {\n if (!(err instanceof DimesApiError)) {\n return null;\n }\n\n const hint = quoteErrorHint(err.code, err.params, {\n leverageBps: currentParams.leverageBps,\n });\n\n const adj = hintAdjustment(hint, {\n collateralUsd: currentParams.collateralUsd,\n leverageBps: currentParams.leverageBps,\n slippageBps: currentParams.slippageBps,\n });\n\n if (!adj) {\n return null;\n }\n\n return { adj };\n}\n\n// eslint-disable-next-line complexity\nexport async function executeQuote(\n client: QuoteClient,\n params: QuoteParams,\n options?: QuoteOptions,\n): Promise<QuoteResult> {\n const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;\n const autoCorrect = options?.autoCorrect ?? true;\n const corrections: NonNullable<HintAdjustment>[] = [];\n let retries = 0;\n\n let offerParams = buildQuoteParams(params);\n const currentParams = { ...params };\n\n const draft = await client.createDraftQuote(offerParams);\n options?.onDraftReady?.(draft);\n\n let currentDraft: Offer = draft;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const promotedOffer = await client.promoteDraftQuote(currentDraft.id);\n return { offer: promotedOffer, corrections, retries };\n } catch (err) {\n if (handleMarketMoved(err, attempt, maxRetries)) {\n const newDraft = await client.createDraftQuote(offerParams);\n retries++;\n\n const callbackResult = options?.onMarketMoved?.({\n originalDraft: currentDraft,\n newDraft,\n retryCount: retries,\n });\n\n if (callbackResult === false) {\n throw err;\n }\n\n currentDraft = newDraft;\n continue;\n }\n\n if (autoCorrect) {\n const correction = handleCorrection(err, currentParams);\n\n if (correction) {\n const callbackResult = options?.onCorrection?.(correction.adj);\n if (callbackResult === false) {\n throw err;\n }\n\n offerParams = applyAdjustment(offerParams, correction.adj, currentParams);\n corrections.push(correction.adj);\n\n const correctedOffer = await client.createQuote(offerParams);\n return { offer: correctedOffer, corrections, retries };\n }\n }\n\n throw err;\n }\n }\n\n throw new DimesError(\"market_moved_retries_exhausted\", \"Exhausted market-moved retries\");\n}\n"],"mappings":";;;;;;AAGA,IAAM,4BAA4B;AAE3B,SAAS,iBAAiB,QAAqB,UAAkB,2BAA8C;AACpH,QAAM,cAAc,KAAK,MAAM,OAAO,cAAc,OAAO,IAAI;AAC/D,QAAM,kBAAkB,KAAK,MAAM,OAAO,gBAAgB,WAAW;AAErE,SAAO;AAAA,IACL,cAAc,OAAO;AAAA,IACrB,eAAe,OAAO;AAAA,IACtB;AAAA,IACA,uBAAuB,gBAAgB,SAAS;AAAA,IAChD,aAAa,OAAO;AAAA,EACtB;AACF;;;AChBA,IAAM,aAAa;AACnB,IAAM,aAAa;AACnB,IAAM,YAAY;AAClB,IAAM,gBAAgB;AACtB,IAAM,cAAc;AACpB,IAAM,gBAAgB;AAEf,IAAM,mBAAmB,oBAAI,IAAI;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAeD,SAAS,IAAI,QAAgB,KAA4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