@dimes-dot-fi/sdk 2.3.0 → 2.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.
Files changed (44) hide show
  1. package/README.md +10 -0
  2. package/dist/{aliases-Dne14KBa.d.cts → aliases-lNsFUKPA.d.cts} +147 -10
  3. package/dist/{aliases-Dne14KBa.d.ts → aliases-lNsFUKPA.d.ts} +147 -10
  4. package/dist/{chunk-E6YJDY4F.cjs → chunk-ERM4WP6D.cjs} +9 -4
  5. package/dist/chunk-ERM4WP6D.cjs.map +1 -0
  6. package/dist/{chunk-4OKYU5D7.mjs → chunk-GA7ZBK6W.mjs} +9 -4
  7. package/dist/chunk-GA7ZBK6W.mjs.map +1 -0
  8. package/dist/{chunk-IJO5E22G.mjs → chunk-HJ5EVO5A.mjs} +11 -6
  9. package/dist/chunk-HJ5EVO5A.mjs.map +1 -0
  10. package/dist/{chunk-GY6L2QGR.cjs → chunk-L273PAD4.cjs} +14 -9
  11. package/dist/chunk-L273PAD4.cjs.map +1 -0
  12. package/dist/contract/index.cjs +557 -67
  13. package/dist/contract/index.cjs.map +1 -1
  14. package/dist/contract/index.d.cts +69 -8
  15. package/dist/contract/index.d.ts +69 -8
  16. package/dist/contract/index.mjs +544 -54
  17. package/dist/contract/index.mjs.map +1 -1
  18. package/dist/{dimes-client-DJ1d_p31.d.ts → dimes-client-BUAeOsgL.d.cts} +48 -3
  19. package/dist/{dimes-client-D9tohawC.d.cts → dimes-client-DDF-f8yA.d.ts} +48 -3
  20. package/dist/{dimes-error-hSoOierP.d.ts → dimes-error-CkcjExUy.d.ts} +1 -1
  21. package/dist/{dimes-error-E9yPAZb-.d.cts → dimes-error-I7lEZ2V5.d.cts} +1 -1
  22. package/dist/index.cjs +78 -8
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +10 -9
  25. package/dist/index.d.ts +10 -9
  26. package/dist/index.mjs +74 -4
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/{quote-D4QunMtN.d.ts → quote-B_cMLw7P.d.cts} +7 -2
  29. package/dist/{quote-sWguOcoJ.d.cts → quote-Z88cryAN.d.ts} +7 -2
  30. package/dist/react/index.cjs +34 -33
  31. package/dist/react/index.cjs.map +1 -1
  32. package/dist/react/index.d.cts +12 -8
  33. package/dist/react/index.d.ts +12 -8
  34. package/dist/react/index.mjs +7 -6
  35. package/dist/react/index.mjs.map +1 -1
  36. package/dist/{types-BHU4Qq7e.d.ts → types-BvZf3uFL.d.ts} +1 -1
  37. package/dist/{types-Bvj_WDbX.d.cts → types-F2rHf2Qv.d.cts} +1 -1
  38. package/dist/ws/index.d.cts +3 -3
  39. package/dist/ws/index.d.ts +3 -3
  40. package/package.json +1 -1
  41. package/dist/chunk-4OKYU5D7.mjs.map +0 -1
  42. package/dist/chunk-E6YJDY4F.cjs.map +0 -1
  43. package/dist/chunk-GY6L2QGR.cjs.map +0 -1
  44. package/dist/chunk-IJO5E22G.mjs.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { Abi, Address, Hex } from 'viem';
2
2
  export { Address, Hex } from 'viem';
3
- import { Q as Quote, e as ContractInfo } from '../aliases-Dne14KBa.cjs';
4
- import { D as DimesClient } from '../dimes-client-D9tohawC.cjs';
5
- import { D as DimesContractError } from '../dimes-error-E9yPAZb-.cjs';
3
+ import { Q as Quote, f as ContractInfo } from '../aliases-lNsFUKPA.cjs';
4
+ import { D as DimesClient } from '../dimes-client-BUAeOsgL.cjs';
5
+ import { D as DimesContractError } from '../dimes-error-I7lEZ2V5.cjs';
6
6
 
7
7
  declare const vaultAbi: Abi;
8
8
  declare const erc20Abi: readonly [{
@@ -59,6 +59,31 @@ interface CreatePositionTxData {
59
59
  bigint
60
60
  ];
61
61
  }
62
+ interface CreatePositionWithMarginTxData {
63
+ address: `0x${string}`;
64
+ abi: Abi;
65
+ functionName: "createPositionWithMargin";
66
+ args: readonly [
67
+ `0x${string}`,
68
+ `0x${string}`,
69
+ bigint,
70
+ bigint,
71
+ number,
72
+ bigint,
73
+ number,
74
+ number,
75
+ number,
76
+ bigint,
77
+ bigint,
78
+ `0x${string}`,
79
+ bigint
80
+ ];
81
+ }
82
+ /**
83
+ * What {@link buildCreatePositionTx} returns: the plain call for an adaptive quote, the
84
+ * margin-bearing call for a committed one.
85
+ */
86
+ type OpenPositionTxData = CreatePositionTxData | CreatePositionWithMarginTxData;
62
87
  interface ApproveTxData {
63
88
  address: `0x${string}`;
64
89
  abi: typeof erc20Abi;
@@ -77,11 +102,34 @@ interface RequestPartialCloseTxData {
77
102
  functionName: "requestPartialClose";
78
103
  args: readonly [`0x${string}`, bigint];
79
104
  }
80
- declare function buildCreatePositionTx(quote: Quote): CreatePositionTxData;
105
+ /**
106
+ * Build the vault call that opens the position this quote was signed for.
107
+ *
108
+ * The quote names its own mode in `riskMode`: a committed-mode quote
109
+ * is signed over a different EIP-712 type and opens through `createPositionWithMargin`, which
110
+ * pulls `marginUsdcUnits` on top of collateral and fees. Submitting one quote's signature to
111
+ * the other entry point always reverts, so the mode is read off the quote rather than left to
112
+ * the caller.
113
+ *
114
+ * `quote.totalUserAmountUsdcUnits` already includes the margin — approve that amount.
115
+ */
116
+ declare function buildCreatePositionTx(quote: Quote): OpenPositionTxData;
81
117
  declare function buildApproveTx(usdcAddress: `0x${string}`, spender: `0x${string}`, amount: bigint): ApproveTxData;
82
118
  declare function buildRequestCloseTx(vaultAddress: `0x${string}`, positionKey: `0x${string}`): RequestCloseTxData;
83
119
  declare function buildRequestPartialCloseTx(vaultAddress: `0x${string}`, positionKey: `0x${string}`, closeTokenUnits: bigint): RequestPartialCloseTxData;
84
120
 
121
+ /**
122
+ * Whether this quote opens in committed mode — a fixed ladder of price-triggered unwinds,
123
+ * backed by extra margin locked in the vault.
124
+ *
125
+ * Read from `riskMode`, the quote's own statement of the mode it was issued in, so a quote
126
+ * issued before committed mode existed reads as adaptive. Asking for committed mode does not
127
+ * guarantee getting it: when the market, price or leverage rules it out the request is rejected
128
+ * with `quote_committed_risk_mode_unavailable`, and a partner without the beta feature enabled
129
+ * is rejected with `beta_feature_not_enabled`.
130
+ */
131
+ declare function isCommittedQuote(quote: Quote): boolean;
132
+
85
133
  /**
86
134
  * Helpers for opening and closing positions from a Polymarket **deposit wallet** (DW).
87
135
  *
@@ -142,7 +190,12 @@ declare const depositWalletBatchTypes: {
142
190
  * Build the three inner calls for a push-funded `createPosition`.
143
191
  *
144
192
  * The relayer submits these atomically; `quote.totalUserAmountUsdcUnits` is the
145
- * contract-ready amount (collateral + fees) used for both the reservation and the transfer.
193
+ * contract-ready amount (collateral + fees + committed-mode margin) used for both the
194
+ * reservation and the transfer. The vault checks the pushed amount for exact equality, so
195
+ * a committed quote whose margin was left out of the transfer reverts the whole batch.
196
+ *
197
+ * A committed quote is opened through `createPositionPushFundedWithMargin`, chosen from the
198
+ * quote itself — see {@link isCommittedQuote}.
146
199
  *
147
200
  * @param quote - the signed quote returned by the quote endpoint
148
201
  * @param pUsdAddress - the pUSD (USDC) token address (from `GET /contract-info`)
@@ -241,6 +294,13 @@ interface BuildRelayerHeadersParams {
241
294
  */
242
295
  declare function buildRelayerAuthHeaders(params: BuildRelayerHeadersParams): Promise<Record<string, string>>;
243
296
 
297
+ /**
298
+ * Recover the address that signed this quote.
299
+ *
300
+ * A committed-mode quote is signed over `CreatePositionWithMargin`, a separate EIP-712 type
301
+ * carrying `marginUsdcUnits`; recovering it against the adaptive type would yield a garbage
302
+ * address, so the type is chosen from the quote itself.
303
+ */
244
304
  declare function recoverCreatePositionSigner(quote: Quote, userAddress: `0x${string}`): Promise<`0x${string}`>;
245
305
  declare function resolveExpectedSigner(apiSigner: string | undefined): `0x${string}` | undefined;
246
306
  /**
@@ -264,7 +324,8 @@ declare const verifyOfferSignature: typeof verifyQuoteSignature;
264
324
 
265
325
  /**
266
326
  * Verify a quote's signature against the on-chain authority (using the client's
267
- * cached `/contract-info`) and then build the `createPosition` transaction.
327
+ * cached `/contract-info`) and then build the transaction that opens the position —
328
+ * `createPosition`, or `createPositionWithMargin` for a committed-mode quote.
268
329
  *
269
330
  * Prefer this over the raw {@link buildCreatePositionTx} so a tampered or stale
270
331
  * quote fails fast in the client instead of reverting on-chain. Throws
@@ -273,7 +334,7 @@ declare const verifyOfferSignature: typeof verifyQuoteSignature;
273
334
  * @param userAddress - the wallet that will submit the tx (the signed `user`,
274
335
  * bound to `msg.sender` by the contract).
275
336
  */
276
- declare function buildVerifiedCreatePositionTx(client: DimesClient, quote: Quote, userAddress: `0x${string}`): Promise<CreatePositionTxData>;
337
+ declare function buildVerifiedCreatePositionTx(client: DimesClient, quote: Quote, userAddress: `0x${string}`): Promise<OpenPositionTxData>;
277
338
  /**
278
339
  * Verify a quote's signature (see {@link buildVerifiedCreatePositionTx}) and then
279
340
  * build the push-funded deposit-wallet calls. Prefer this over the raw
@@ -290,4 +351,4 @@ declare function buildVerifiedPushFundedCreateCalls(client: DimesClient, quote:
290
351
 
291
352
  declare function formatContractError(err: unknown): DimesContractError;
292
353
 
293
- export { type ApproveTxData, type CreatePositionTxData, type DepositWalletBatch, type DepositWalletCall, type RequestCloseTxData, type RequestPartialCloseTxData, assertQuoteSigner, buildApproveTx, buildCreatePositionTx, buildDepositWalletBatch, buildPushFundedCreateCalls, buildRelayerAuthHeaders, buildRelayerSubmitPayload, buildRequestCloseCalls, buildRequestCloseTx, buildRequestPartialCloseCalls, buildRequestPartialCloseTx, buildVerifiedCreatePositionTx, buildVerifiedPushFundedCreateCalls, depositWalletBatchTypes, depositWalletFactoryAddress, erc20Abi, formatContractError, getCachedContractInfo, getDepositWalletBatchTypedData, polymarketRelayerBaseUrl, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature, verifyQuoteSignature };
354
+ export { type ApproveTxData, type CreatePositionTxData, type CreatePositionWithMarginTxData, type DepositWalletBatch, type DepositWalletCall, type OpenPositionTxData, type RequestCloseTxData, type RequestPartialCloseTxData, assertQuoteSigner, buildApproveTx, buildCreatePositionTx, buildDepositWalletBatch, buildPushFundedCreateCalls, buildRelayerAuthHeaders, buildRelayerSubmitPayload, buildRequestCloseCalls, buildRequestCloseTx, buildRequestPartialCloseCalls, buildRequestPartialCloseTx, buildVerifiedCreatePositionTx, buildVerifiedPushFundedCreateCalls, depositWalletBatchTypes, depositWalletFactoryAddress, erc20Abi, formatContractError, getCachedContractInfo, getDepositWalletBatchTypedData, isCommittedQuote, polymarketRelayerBaseUrl, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature, verifyQuoteSignature };
@@ -1,8 +1,8 @@
1
1
  import { Abi, Address, Hex } from 'viem';
2
2
  export { Address, Hex } from 'viem';
3
- import { Q as Quote, e as ContractInfo } from '../aliases-Dne14KBa.js';
4
- import { D as DimesClient } from '../dimes-client-DJ1d_p31.js';
5
- import { D as DimesContractError } from '../dimes-error-hSoOierP.js';
3
+ import { Q as Quote, f as ContractInfo } from '../aliases-lNsFUKPA.js';
4
+ import { D as DimesClient } from '../dimes-client-DDF-f8yA.js';
5
+ import { D as DimesContractError } from '../dimes-error-CkcjExUy.js';
6
6
 
7
7
  declare const vaultAbi: Abi;
8
8
  declare const erc20Abi: readonly [{
@@ -59,6 +59,31 @@ interface CreatePositionTxData {
59
59
  bigint
60
60
  ];
61
61
  }
62
+ interface CreatePositionWithMarginTxData {
63
+ address: `0x${string}`;
64
+ abi: Abi;
65
+ functionName: "createPositionWithMargin";
66
+ args: readonly [
67
+ `0x${string}`,
68
+ `0x${string}`,
69
+ bigint,
70
+ bigint,
71
+ number,
72
+ bigint,
73
+ number,
74
+ number,
75
+ number,
76
+ bigint,
77
+ bigint,
78
+ `0x${string}`,
79
+ bigint
80
+ ];
81
+ }
82
+ /**
83
+ * What {@link buildCreatePositionTx} returns: the plain call for an adaptive quote, the
84
+ * margin-bearing call for a committed one.
85
+ */
86
+ type OpenPositionTxData = CreatePositionTxData | CreatePositionWithMarginTxData;
62
87
  interface ApproveTxData {
63
88
  address: `0x${string}`;
64
89
  abi: typeof erc20Abi;
@@ -77,11 +102,34 @@ interface RequestPartialCloseTxData {
77
102
  functionName: "requestPartialClose";
78
103
  args: readonly [`0x${string}`, bigint];
79
104
  }
80
- declare function buildCreatePositionTx(quote: Quote): CreatePositionTxData;
105
+ /**
106
+ * Build the vault call that opens the position this quote was signed for.
107
+ *
108
+ * The quote names its own mode in `riskMode`: a committed-mode quote
109
+ * is signed over a different EIP-712 type and opens through `createPositionWithMargin`, which
110
+ * pulls `marginUsdcUnits` on top of collateral and fees. Submitting one quote's signature to
111
+ * the other entry point always reverts, so the mode is read off the quote rather than left to
112
+ * the caller.
113
+ *
114
+ * `quote.totalUserAmountUsdcUnits` already includes the margin — approve that amount.
115
+ */
116
+ declare function buildCreatePositionTx(quote: Quote): OpenPositionTxData;
81
117
  declare function buildApproveTx(usdcAddress: `0x${string}`, spender: `0x${string}`, amount: bigint): ApproveTxData;
82
118
  declare function buildRequestCloseTx(vaultAddress: `0x${string}`, positionKey: `0x${string}`): RequestCloseTxData;
83
119
  declare function buildRequestPartialCloseTx(vaultAddress: `0x${string}`, positionKey: `0x${string}`, closeTokenUnits: bigint): RequestPartialCloseTxData;
84
120
 
121
+ /**
122
+ * Whether this quote opens in committed mode — a fixed ladder of price-triggered unwinds,
123
+ * backed by extra margin locked in the vault.
124
+ *
125
+ * Read from `riskMode`, the quote's own statement of the mode it was issued in, so a quote
126
+ * issued before committed mode existed reads as adaptive. Asking for committed mode does not
127
+ * guarantee getting it: when the market, price or leverage rules it out the request is rejected
128
+ * with `quote_committed_risk_mode_unavailable`, and a partner without the beta feature enabled
129
+ * is rejected with `beta_feature_not_enabled`.
130
+ */
131
+ declare function isCommittedQuote(quote: Quote): boolean;
132
+
85
133
  /**
86
134
  * Helpers for opening and closing positions from a Polymarket **deposit wallet** (DW).
87
135
  *
@@ -142,7 +190,12 @@ declare const depositWalletBatchTypes: {
142
190
  * Build the three inner calls for a push-funded `createPosition`.
143
191
  *
144
192
  * The relayer submits these atomically; `quote.totalUserAmountUsdcUnits` is the
145
- * contract-ready amount (collateral + fees) used for both the reservation and the transfer.
193
+ * contract-ready amount (collateral + fees + committed-mode margin) used for both the
194
+ * reservation and the transfer. The vault checks the pushed amount for exact equality, so
195
+ * a committed quote whose margin was left out of the transfer reverts the whole batch.
196
+ *
197
+ * A committed quote is opened through `createPositionPushFundedWithMargin`, chosen from the
198
+ * quote itself — see {@link isCommittedQuote}.
146
199
  *
147
200
  * @param quote - the signed quote returned by the quote endpoint
148
201
  * @param pUsdAddress - the pUSD (USDC) token address (from `GET /contract-info`)
@@ -241,6 +294,13 @@ interface BuildRelayerHeadersParams {
241
294
  */
242
295
  declare function buildRelayerAuthHeaders(params: BuildRelayerHeadersParams): Promise<Record<string, string>>;
243
296
 
297
+ /**
298
+ * Recover the address that signed this quote.
299
+ *
300
+ * A committed-mode quote is signed over `CreatePositionWithMargin`, a separate EIP-712 type
301
+ * carrying `marginUsdcUnits`; recovering it against the adaptive type would yield a garbage
302
+ * address, so the type is chosen from the quote itself.
303
+ */
244
304
  declare function recoverCreatePositionSigner(quote: Quote, userAddress: `0x${string}`): Promise<`0x${string}`>;
245
305
  declare function resolveExpectedSigner(apiSigner: string | undefined): `0x${string}` | undefined;
246
306
  /**
@@ -264,7 +324,8 @@ declare const verifyOfferSignature: typeof verifyQuoteSignature;
264
324
 
265
325
  /**
266
326
  * Verify a quote's signature against the on-chain authority (using the client's
267
- * cached `/contract-info`) and then build the `createPosition` transaction.
327
+ * cached `/contract-info`) and then build the transaction that opens the position —
328
+ * `createPosition`, or `createPositionWithMargin` for a committed-mode quote.
268
329
  *
269
330
  * Prefer this over the raw {@link buildCreatePositionTx} so a tampered or stale
270
331
  * quote fails fast in the client instead of reverting on-chain. Throws
@@ -273,7 +334,7 @@ declare const verifyOfferSignature: typeof verifyQuoteSignature;
273
334
  * @param userAddress - the wallet that will submit the tx (the signed `user`,
274
335
  * bound to `msg.sender` by the contract).
275
336
  */
276
- declare function buildVerifiedCreatePositionTx(client: DimesClient, quote: Quote, userAddress: `0x${string}`): Promise<CreatePositionTxData>;
337
+ declare function buildVerifiedCreatePositionTx(client: DimesClient, quote: Quote, userAddress: `0x${string}`): Promise<OpenPositionTxData>;
277
338
  /**
278
339
  * Verify a quote's signature (see {@link buildVerifiedCreatePositionTx}) and then
279
340
  * build the push-funded deposit-wallet calls. Prefer this over the raw
@@ -290,4 +351,4 @@ declare function buildVerifiedPushFundedCreateCalls(client: DimesClient, quote:
290
351
 
291
352
  declare function formatContractError(err: unknown): DimesContractError;
292
353
 
293
- export { type ApproveTxData, type CreatePositionTxData, type DepositWalletBatch, type DepositWalletCall, type RequestCloseTxData, type RequestPartialCloseTxData, assertQuoteSigner, buildApproveTx, buildCreatePositionTx, buildDepositWalletBatch, buildPushFundedCreateCalls, buildRelayerAuthHeaders, buildRelayerSubmitPayload, buildRequestCloseCalls, buildRequestCloseTx, buildRequestPartialCloseCalls, buildRequestPartialCloseTx, buildVerifiedCreatePositionTx, buildVerifiedPushFundedCreateCalls, depositWalletBatchTypes, depositWalletFactoryAddress, erc20Abi, formatContractError, getCachedContractInfo, getDepositWalletBatchTypedData, polymarketRelayerBaseUrl, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature, verifyQuoteSignature };
354
+ export { type ApproveTxData, type CreatePositionTxData, type CreatePositionWithMarginTxData, type DepositWalletBatch, type DepositWalletCall, type OpenPositionTxData, type RequestCloseTxData, type RequestPartialCloseTxData, assertQuoteSigner, buildApproveTx, buildCreatePositionTx, buildDepositWalletBatch, buildPushFundedCreateCalls, buildRelayerAuthHeaders, buildRelayerSubmitPayload, buildRequestCloseCalls, buildRequestCloseTx, buildRequestPartialCloseCalls, buildRequestPartialCloseTx, buildVerifiedCreatePositionTx, buildVerifiedPushFundedCreateCalls, depositWalletBatchTypes, depositWalletFactoryAddress, erc20Abi, formatContractError, getCachedContractInfo, getDepositWalletBatchTypedData, isCommittedQuote, polymarketRelayerBaseUrl, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature, verifyQuoteSignature };