@dimes-dot-fi/sdk 1.2.0 → 1.3.1
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-DzVxkXtK.d.cts → aliases-BGqwpyE-.d.cts} +39 -1
- package/dist/{aliases-DzVxkXtK.d.ts → aliases-BGqwpyE-.d.ts} +39 -1
- package/dist/{chunk-YUCGNELT.mjs → chunk-4MO3HKMS.mjs} +7 -1
- package/dist/chunk-4MO3HKMS.mjs.map +1 -0
- package/dist/{chunk-S65RABUT.mjs → chunk-BVILILIV.mjs} +13 -1
- package/dist/chunk-BVILILIV.mjs.map +1 -0
- package/dist/{chunk-JWAPH4GD.cjs → chunk-COSLZ5TM.cjs} +36 -11
- package/dist/chunk-COSLZ5TM.cjs.map +1 -0
- package/dist/{chunk-UUE4HG2H.cjs → chunk-DYPABUKC.cjs} +13 -1
- package/dist/chunk-DYPABUKC.cjs.map +1 -0
- package/dist/{chunk-EI5V5Z6G.mjs → chunk-SGA6OZEU.mjs} +33 -8
- package/dist/chunk-SGA6OZEU.mjs.map +1 -0
- package/dist/{chunk-ZK56XS4X.cjs → chunk-UHQZSMUD.cjs} +8 -2
- package/dist/chunk-UHQZSMUD.cjs.map +1 -0
- package/dist/contract/index.cjs +206 -14
- package/dist/contract/index.cjs.map +1 -1
- package/dist/contract/index.d.cts +155 -4
- package/dist/contract/index.d.ts +155 -4
- package/dist/contract/index.mjs +193 -1
- package/dist/contract/index.mjs.map +1 -1
- package/dist/{dimes-client-D88pW-Lm.d.ts → dimes-client-C2hT6mZ8.d.cts} +10 -2
- package/dist/{dimes-client-Bs6eTIvn.d.cts → dimes-client-DFAKtIeI.d.ts} +10 -2
- package/dist/{dimes-error-DxIoHQzj.d.cts → dimes-error-BW0wd1ib.d.cts} +1 -1
- package/dist/{dimes-error-BHVY6vDv.d.ts → dimes-error-IBJ5eff6.d.ts} +1 -1
- package/dist/index.cjs +12 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.mjs +8 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{quote-Cy7ie8yT.d.ts → quote-BVMZb0T8.d.ts} +2 -2
- package/dist/{quote-CZqCqt8R.d.cts → quote-BcVJ0U0l.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-BcUKsoEs.d.ts → types-BwPF-kCK.d.cts} +20 -2
- package/dist/{types--ysRe5Os.d.cts → types-C7nWOxO-.d.ts} +20 -2
- package/dist/ws/index.cjs +114 -4
- package/dist/ws/index.cjs.map +1 -1
- package/dist/ws/index.d.cts +36 -9
- package/dist/ws/index.d.ts +36 -9
- package/dist/ws/index.mjs +111 -1
- package/dist/ws/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-EI5V5Z6G.mjs.map +0 -1
- package/dist/chunk-JWAPH4GD.cjs.map +0 -1
- package/dist/chunk-S65RABUT.mjs.map +0 -1
- package/dist/chunk-UUE4HG2H.cjs.map +0 -1
- package/dist/chunk-YUCGNELT.mjs.map +0 -1
- package/dist/chunk-ZK56XS4X.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Abi, Address, Hex } from 'viem';
|
|
2
2
|
export { Address, Hex } from 'viem';
|
|
3
|
-
import { O as Offer } from '../aliases-
|
|
4
|
-
import { D as DimesClient } from '../dimes-client-
|
|
5
|
-
import { a as DimesContractError } from '../dimes-error-
|
|
3
|
+
import { O as Offer } from '../aliases-BGqwpyE-.cjs';
|
|
4
|
+
import { D as DimesClient } from '../dimes-client-C2hT6mZ8.cjs';
|
|
5
|
+
import { a as DimesContractError } from '../dimes-error-BW0wd1ib.cjs';
|
|
6
6
|
|
|
7
7
|
declare const vaultAbi: Abi;
|
|
8
8
|
declare const erc20Abi: readonly [{
|
|
@@ -75,10 +75,161 @@ declare function buildCreatePositionTx(offer: Offer): CreatePositionTxData;
|
|
|
75
75
|
declare function buildApproveTx(usdcAddress: `0x${string}`, spender: `0x${string}`, amount: bigint): ApproveTxData;
|
|
76
76
|
declare function buildRequestCloseTx(vaultAddress: `0x${string}`, positionKey: `0x${string}`): RequestCloseTxData;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Helpers for opening and closing positions from a Polymarket **deposit wallet** (DW).
|
|
80
|
+
*
|
|
81
|
+
* Deposit wallets cannot use the legacy `approve` + `createPosition` path: the Polymarket
|
|
82
|
+
* relayer blocks `approve` to non-whitelisted spenders. Instead the DW submits an atomic
|
|
83
|
+
* batch through Polymarket's deposit-wallet factory:
|
|
84
|
+
*
|
|
85
|
+
* 1. `vault.reserveDeposit(totalUserAmount)` — snapshot the vault pUSD balance
|
|
86
|
+
* 2. `pUSD.transfer(vault, totalUserAmount)` — push the funds directly
|
|
87
|
+
* 3. `vault.createPositionPushFunded(...)` — verify the balance delta + create
|
|
88
|
+
*
|
|
89
|
+
* Closing follows the same batch mechanics with a single inner call, `requestClose`.
|
|
90
|
+
*/
|
|
91
|
+
/** Polymarket deposit-wallet factory (the `proxy` entrypoint), Polygon mainnet. */
|
|
92
|
+
declare const depositWalletFactoryAddress: Address;
|
|
93
|
+
/** Base URL of Polymarket's v2 relayer. */
|
|
94
|
+
declare const polymarketRelayerBaseUrl = "https://relayer-v2.polymarket.com";
|
|
95
|
+
/** A single inner call inside a deposit-wallet batch. */
|
|
96
|
+
interface DepositWalletCall {
|
|
97
|
+
target: Address;
|
|
98
|
+
value: bigint;
|
|
99
|
+
data: Hex;
|
|
100
|
+
}
|
|
101
|
+
/** The EIP-712 `Batch` struct signed by the deposit-wallet owner. */
|
|
102
|
+
interface DepositWalletBatch {
|
|
103
|
+
wallet: Address;
|
|
104
|
+
nonce: bigint;
|
|
105
|
+
deadline: bigint;
|
|
106
|
+
calls: DepositWalletCall[];
|
|
107
|
+
}
|
|
108
|
+
/** EIP-712 type definitions for the deposit-wallet `Batch` signature. */
|
|
109
|
+
declare const depositWalletBatchTypes: {
|
|
110
|
+
readonly Batch: readonly [{
|
|
111
|
+
readonly name: "wallet";
|
|
112
|
+
readonly type: "address";
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: "nonce";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "deadline";
|
|
118
|
+
readonly type: "uint256";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "calls";
|
|
121
|
+
readonly type: "Call[]";
|
|
122
|
+
}];
|
|
123
|
+
readonly Call: readonly [{
|
|
124
|
+
readonly name: "target";
|
|
125
|
+
readonly type: "address";
|
|
126
|
+
}, {
|
|
127
|
+
readonly name: "value";
|
|
128
|
+
readonly type: "uint256";
|
|
129
|
+
}, {
|
|
130
|
+
readonly name: "data";
|
|
131
|
+
readonly type: "bytes";
|
|
132
|
+
}];
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Build the three inner calls for a push-funded `createPosition`.
|
|
136
|
+
*
|
|
137
|
+
* The relayer submits these atomically; `offer.totalUserAmountUsdcUnits` is the
|
|
138
|
+
* contract-ready amount (collateral + fees) used for both the reservation and the transfer.
|
|
139
|
+
*
|
|
140
|
+
* @param offer - the signed offer returned by the quote endpoint
|
|
141
|
+
* @param pUsdAddress - the pUSD (USDC) token address (from `GET /contract-info`)
|
|
142
|
+
*/
|
|
143
|
+
declare function buildPushFundedCreateCalls(offer: Offer, pUsdAddress: string): DepositWalletCall[];
|
|
144
|
+
/**
|
|
145
|
+
* Build the single inner call for a deposit-wallet `requestClose`.
|
|
146
|
+
*
|
|
147
|
+
* @param vaultAddress - the vault contract address
|
|
148
|
+
* @param positionKey - the `on_chain_position_key` field from `GET /positions`
|
|
149
|
+
*/
|
|
150
|
+
declare function buildRequestCloseCalls(vaultAddress: string, positionKey: string): DepositWalletCall[];
|
|
151
|
+
interface BuildBatchParams {
|
|
152
|
+
depositWalletAddress: string;
|
|
153
|
+
/** Current `nonce()` read from the deposit wallet. */
|
|
154
|
+
nonce: bigint;
|
|
155
|
+
/** Unix-seconds deadline after which the relayer may no longer submit the batch. */
|
|
156
|
+
deadline: bigint;
|
|
157
|
+
calls: DepositWalletCall[];
|
|
158
|
+
}
|
|
159
|
+
/** Assemble a `DepositWalletBatch` ready for EIP-712 signing. */
|
|
160
|
+
declare function buildDepositWalletBatch(params: BuildBatchParams): DepositWalletBatch;
|
|
161
|
+
/** EIP-712 typed-data payload for a deposit-wallet `Batch` signature. */
|
|
162
|
+
interface DepositWalletBatchTypedData {
|
|
163
|
+
domain: {
|
|
164
|
+
name: string;
|
|
165
|
+
version: string;
|
|
166
|
+
chainId: number;
|
|
167
|
+
verifyingContract: Address;
|
|
168
|
+
};
|
|
169
|
+
types: typeof depositWalletBatchTypes;
|
|
170
|
+
primaryType: "Batch";
|
|
171
|
+
message: DepositWalletBatch;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Produce the EIP-712 typed-data object for a batch, ready to pass to a signer
|
|
175
|
+
* (viem `signTypedData`, ethers `signTypedData`, etc.). The owner of the deposit
|
|
176
|
+
* wallet must sign this.
|
|
177
|
+
*/
|
|
178
|
+
declare function getDepositWalletBatchTypedData(batch: DepositWalletBatch): DepositWalletBatchTypedData;
|
|
179
|
+
interface RelayerSubmitPayload {
|
|
180
|
+
type: "WALLET";
|
|
181
|
+
from: Address;
|
|
182
|
+
to: Address;
|
|
183
|
+
nonce: string;
|
|
184
|
+
signature: Hex;
|
|
185
|
+
depositWalletParams: {
|
|
186
|
+
depositWallet: Address;
|
|
187
|
+
deadline: string;
|
|
188
|
+
calls: {
|
|
189
|
+
target: Address;
|
|
190
|
+
value: string;
|
|
191
|
+
data: Hex;
|
|
192
|
+
}[];
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
interface BuildRelayerPayloadParams {
|
|
196
|
+
/** The deposit-wallet owner EOA that produced `signature`. */
|
|
197
|
+
ownerAddress: string;
|
|
198
|
+
batch: DepositWalletBatch;
|
|
199
|
+
/** The EIP-712 signature over `getDepositWalletBatchTypedData(batch)`. */
|
|
200
|
+
signature: Hex;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Build the JSON body for `POST {polymarketRelayerBaseUrl}/submit`.
|
|
204
|
+
*
|
|
205
|
+
* Stringify the result and send it with headers from {@link buildRelayerAuthHeaders}.
|
|
206
|
+
*/
|
|
207
|
+
declare function buildRelayerSubmitPayload(params: BuildRelayerPayloadParams): RelayerSubmitPayload;
|
|
208
|
+
interface BuildRelayerHeadersParams {
|
|
209
|
+
/** Polymarket builder API key. */
|
|
210
|
+
apiKey: string;
|
|
211
|
+
/** Polymarket builder API secret (base64). */
|
|
212
|
+
apiSecret: string;
|
|
213
|
+
/** Polymarket builder API passphrase. */
|
|
214
|
+
apiPassphrase: string;
|
|
215
|
+
/** The exact request body string sent to `/submit` (the value passed to `fetch`). */
|
|
216
|
+
body: string;
|
|
217
|
+
/** Unix-seconds timestamp; defaults to now. Must match the request time. */
|
|
218
|
+
timestamp?: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Compute the HMAC-signed headers for a relayer `/submit` request.
|
|
222
|
+
*
|
|
223
|
+
* The relayer authenticates each call with an HMAC-SHA256 over
|
|
224
|
+
* `timestamp + "POST" + "/submit" + body`, keyed by the base64-decoded API secret,
|
|
225
|
+
* encoded as base64url. Uses the Web Crypto API (works in Node 20+ and browsers).
|
|
226
|
+
*/
|
|
227
|
+
declare function buildRelayerAuthHeaders(params: BuildRelayerHeadersParams): Promise<Record<string, string>>;
|
|
228
|
+
|
|
78
229
|
declare function recoverCreatePositionSigner(offer: Offer, userAddress: `0x${string}`): Promise<`0x${string}`>;
|
|
79
230
|
declare function resolveExpectedSigner(apiSigner: string | undefined): `0x${string}` | undefined;
|
|
80
231
|
declare function verifyOfferSignature(client: DimesClient, offer: Offer, userAddress: `0x${string}`): Promise<void>;
|
|
81
232
|
|
|
82
233
|
declare function formatContractError(err: unknown): DimesContractError;
|
|
83
234
|
|
|
84
|
-
export { type ApproveTxData, type CreatePositionTxData, type RequestCloseTxData, buildApproveTx, buildCreatePositionTx, buildRequestCloseTx, erc20Abi, formatContractError, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature };
|
|
235
|
+
export { type ApproveTxData, type CreatePositionTxData, type DepositWalletBatch, type DepositWalletCall, type RequestCloseTxData, buildApproveTx, buildCreatePositionTx, buildDepositWalletBatch, buildPushFundedCreateCalls, buildRelayerAuthHeaders, buildRelayerSubmitPayload, buildRequestCloseCalls, buildRequestCloseTx, depositWalletBatchTypes, depositWalletFactoryAddress, erc20Abi, formatContractError, getDepositWalletBatchTypedData, polymarketRelayerBaseUrl, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature };
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Abi, Address, Hex } from 'viem';
|
|
2
2
|
export { Address, Hex } from 'viem';
|
|
3
|
-
import { O as Offer } from '../aliases-
|
|
4
|
-
import { D as DimesClient } from '../dimes-client-
|
|
5
|
-
import { a as DimesContractError } from '../dimes-error-
|
|
3
|
+
import { O as Offer } from '../aliases-BGqwpyE-.js';
|
|
4
|
+
import { D as DimesClient } from '../dimes-client-DFAKtIeI.js';
|
|
5
|
+
import { a as DimesContractError } from '../dimes-error-IBJ5eff6.js';
|
|
6
6
|
|
|
7
7
|
declare const vaultAbi: Abi;
|
|
8
8
|
declare const erc20Abi: readonly [{
|
|
@@ -75,10 +75,161 @@ declare function buildCreatePositionTx(offer: Offer): CreatePositionTxData;
|
|
|
75
75
|
declare function buildApproveTx(usdcAddress: `0x${string}`, spender: `0x${string}`, amount: bigint): ApproveTxData;
|
|
76
76
|
declare function buildRequestCloseTx(vaultAddress: `0x${string}`, positionKey: `0x${string}`): RequestCloseTxData;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Helpers for opening and closing positions from a Polymarket **deposit wallet** (DW).
|
|
80
|
+
*
|
|
81
|
+
* Deposit wallets cannot use the legacy `approve` + `createPosition` path: the Polymarket
|
|
82
|
+
* relayer blocks `approve` to non-whitelisted spenders. Instead the DW submits an atomic
|
|
83
|
+
* batch through Polymarket's deposit-wallet factory:
|
|
84
|
+
*
|
|
85
|
+
* 1. `vault.reserveDeposit(totalUserAmount)` — snapshot the vault pUSD balance
|
|
86
|
+
* 2. `pUSD.transfer(vault, totalUserAmount)` — push the funds directly
|
|
87
|
+
* 3. `vault.createPositionPushFunded(...)` — verify the balance delta + create
|
|
88
|
+
*
|
|
89
|
+
* Closing follows the same batch mechanics with a single inner call, `requestClose`.
|
|
90
|
+
*/
|
|
91
|
+
/** Polymarket deposit-wallet factory (the `proxy` entrypoint), Polygon mainnet. */
|
|
92
|
+
declare const depositWalletFactoryAddress: Address;
|
|
93
|
+
/** Base URL of Polymarket's v2 relayer. */
|
|
94
|
+
declare const polymarketRelayerBaseUrl = "https://relayer-v2.polymarket.com";
|
|
95
|
+
/** A single inner call inside a deposit-wallet batch. */
|
|
96
|
+
interface DepositWalletCall {
|
|
97
|
+
target: Address;
|
|
98
|
+
value: bigint;
|
|
99
|
+
data: Hex;
|
|
100
|
+
}
|
|
101
|
+
/** The EIP-712 `Batch` struct signed by the deposit-wallet owner. */
|
|
102
|
+
interface DepositWalletBatch {
|
|
103
|
+
wallet: Address;
|
|
104
|
+
nonce: bigint;
|
|
105
|
+
deadline: bigint;
|
|
106
|
+
calls: DepositWalletCall[];
|
|
107
|
+
}
|
|
108
|
+
/** EIP-712 type definitions for the deposit-wallet `Batch` signature. */
|
|
109
|
+
declare const depositWalletBatchTypes: {
|
|
110
|
+
readonly Batch: readonly [{
|
|
111
|
+
readonly name: "wallet";
|
|
112
|
+
readonly type: "address";
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: "nonce";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "deadline";
|
|
118
|
+
readonly type: "uint256";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "calls";
|
|
121
|
+
readonly type: "Call[]";
|
|
122
|
+
}];
|
|
123
|
+
readonly Call: readonly [{
|
|
124
|
+
readonly name: "target";
|
|
125
|
+
readonly type: "address";
|
|
126
|
+
}, {
|
|
127
|
+
readonly name: "value";
|
|
128
|
+
readonly type: "uint256";
|
|
129
|
+
}, {
|
|
130
|
+
readonly name: "data";
|
|
131
|
+
readonly type: "bytes";
|
|
132
|
+
}];
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Build the three inner calls for a push-funded `createPosition`.
|
|
136
|
+
*
|
|
137
|
+
* The relayer submits these atomically; `offer.totalUserAmountUsdcUnits` is the
|
|
138
|
+
* contract-ready amount (collateral + fees) used for both the reservation and the transfer.
|
|
139
|
+
*
|
|
140
|
+
* @param offer - the signed offer returned by the quote endpoint
|
|
141
|
+
* @param pUsdAddress - the pUSD (USDC) token address (from `GET /contract-info`)
|
|
142
|
+
*/
|
|
143
|
+
declare function buildPushFundedCreateCalls(offer: Offer, pUsdAddress: string): DepositWalletCall[];
|
|
144
|
+
/**
|
|
145
|
+
* Build the single inner call for a deposit-wallet `requestClose`.
|
|
146
|
+
*
|
|
147
|
+
* @param vaultAddress - the vault contract address
|
|
148
|
+
* @param positionKey - the `on_chain_position_key` field from `GET /positions`
|
|
149
|
+
*/
|
|
150
|
+
declare function buildRequestCloseCalls(vaultAddress: string, positionKey: string): DepositWalletCall[];
|
|
151
|
+
interface BuildBatchParams {
|
|
152
|
+
depositWalletAddress: string;
|
|
153
|
+
/** Current `nonce()` read from the deposit wallet. */
|
|
154
|
+
nonce: bigint;
|
|
155
|
+
/** Unix-seconds deadline after which the relayer may no longer submit the batch. */
|
|
156
|
+
deadline: bigint;
|
|
157
|
+
calls: DepositWalletCall[];
|
|
158
|
+
}
|
|
159
|
+
/** Assemble a `DepositWalletBatch` ready for EIP-712 signing. */
|
|
160
|
+
declare function buildDepositWalletBatch(params: BuildBatchParams): DepositWalletBatch;
|
|
161
|
+
/** EIP-712 typed-data payload for a deposit-wallet `Batch` signature. */
|
|
162
|
+
interface DepositWalletBatchTypedData {
|
|
163
|
+
domain: {
|
|
164
|
+
name: string;
|
|
165
|
+
version: string;
|
|
166
|
+
chainId: number;
|
|
167
|
+
verifyingContract: Address;
|
|
168
|
+
};
|
|
169
|
+
types: typeof depositWalletBatchTypes;
|
|
170
|
+
primaryType: "Batch";
|
|
171
|
+
message: DepositWalletBatch;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Produce the EIP-712 typed-data object for a batch, ready to pass to a signer
|
|
175
|
+
* (viem `signTypedData`, ethers `signTypedData`, etc.). The owner of the deposit
|
|
176
|
+
* wallet must sign this.
|
|
177
|
+
*/
|
|
178
|
+
declare function getDepositWalletBatchTypedData(batch: DepositWalletBatch): DepositWalletBatchTypedData;
|
|
179
|
+
interface RelayerSubmitPayload {
|
|
180
|
+
type: "WALLET";
|
|
181
|
+
from: Address;
|
|
182
|
+
to: Address;
|
|
183
|
+
nonce: string;
|
|
184
|
+
signature: Hex;
|
|
185
|
+
depositWalletParams: {
|
|
186
|
+
depositWallet: Address;
|
|
187
|
+
deadline: string;
|
|
188
|
+
calls: {
|
|
189
|
+
target: Address;
|
|
190
|
+
value: string;
|
|
191
|
+
data: Hex;
|
|
192
|
+
}[];
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
interface BuildRelayerPayloadParams {
|
|
196
|
+
/** The deposit-wallet owner EOA that produced `signature`. */
|
|
197
|
+
ownerAddress: string;
|
|
198
|
+
batch: DepositWalletBatch;
|
|
199
|
+
/** The EIP-712 signature over `getDepositWalletBatchTypedData(batch)`. */
|
|
200
|
+
signature: Hex;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Build the JSON body for `POST {polymarketRelayerBaseUrl}/submit`.
|
|
204
|
+
*
|
|
205
|
+
* Stringify the result and send it with headers from {@link buildRelayerAuthHeaders}.
|
|
206
|
+
*/
|
|
207
|
+
declare function buildRelayerSubmitPayload(params: BuildRelayerPayloadParams): RelayerSubmitPayload;
|
|
208
|
+
interface BuildRelayerHeadersParams {
|
|
209
|
+
/** Polymarket builder API key. */
|
|
210
|
+
apiKey: string;
|
|
211
|
+
/** Polymarket builder API secret (base64). */
|
|
212
|
+
apiSecret: string;
|
|
213
|
+
/** Polymarket builder API passphrase. */
|
|
214
|
+
apiPassphrase: string;
|
|
215
|
+
/** The exact request body string sent to `/submit` (the value passed to `fetch`). */
|
|
216
|
+
body: string;
|
|
217
|
+
/** Unix-seconds timestamp; defaults to now. Must match the request time. */
|
|
218
|
+
timestamp?: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Compute the HMAC-signed headers for a relayer `/submit` request.
|
|
222
|
+
*
|
|
223
|
+
* The relayer authenticates each call with an HMAC-SHA256 over
|
|
224
|
+
* `timestamp + "POST" + "/submit" + body`, keyed by the base64-decoded API secret,
|
|
225
|
+
* encoded as base64url. Uses the Web Crypto API (works in Node 20+ and browsers).
|
|
226
|
+
*/
|
|
227
|
+
declare function buildRelayerAuthHeaders(params: BuildRelayerHeadersParams): Promise<Record<string, string>>;
|
|
228
|
+
|
|
78
229
|
declare function recoverCreatePositionSigner(offer: Offer, userAddress: `0x${string}`): Promise<`0x${string}`>;
|
|
79
230
|
declare function resolveExpectedSigner(apiSigner: string | undefined): `0x${string}` | undefined;
|
|
80
231
|
declare function verifyOfferSignature(client: DimesClient, offer: Offer, userAddress: `0x${string}`): Promise<void>;
|
|
81
232
|
|
|
82
233
|
declare function formatContractError(err: unknown): DimesContractError;
|
|
83
234
|
|
|
84
|
-
export { type ApproveTxData, type CreatePositionTxData, type RequestCloseTxData, buildApproveTx, buildCreatePositionTx, buildRequestCloseTx, erc20Abi, formatContractError, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature };
|
|
235
|
+
export { type ApproveTxData, type CreatePositionTxData, type DepositWalletBatch, type DepositWalletCall, type RequestCloseTxData, buildApproveTx, buildCreatePositionTx, buildDepositWalletBatch, buildPushFundedCreateCalls, buildRelayerAuthHeaders, buildRelayerSubmitPayload, buildRequestCloseCalls, buildRequestCloseTx, depositWalletBatchTypes, depositWalletFactoryAddress, erc20Abi, formatContractError, getDepositWalletBatchTypedData, polymarketRelayerBaseUrl, recoverCreatePositionSigner, resolveExpectedSigner, toAddress, toHex, vaultAbi, verifyOfferSignature };
|
package/dist/contract/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DimesContractError,
|
|
3
3
|
DimesError
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-BVILILIV.mjs";
|
|
5
5
|
|
|
6
6
|
// src/contract/vault-abi.json
|
|
7
7
|
var vault_abi_default = {
|
|
@@ -464,6 +464,189 @@ function buildRequestCloseTx(vaultAddress, positionKey) {
|
|
|
464
464
|
};
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
+
// src/contract/deposit-wallet.ts
|
|
468
|
+
import { encodeFunctionData } from "viem";
|
|
469
|
+
var depositWalletFactoryAddress = "0x00000000000Fb5C9ADea0298D729A0CB3823Cc07";
|
|
470
|
+
var polymarketRelayerBaseUrl = "https://relayer-v2.polymarket.com";
|
|
471
|
+
var depositWalletBatchTypes = {
|
|
472
|
+
Batch: [
|
|
473
|
+
{ name: "wallet", type: "address" },
|
|
474
|
+
{ name: "nonce", type: "uint256" },
|
|
475
|
+
{ name: "deadline", type: "uint256" },
|
|
476
|
+
{ name: "calls", type: "Call[]" }
|
|
477
|
+
],
|
|
478
|
+
Call: [
|
|
479
|
+
{ name: "target", type: "address" },
|
|
480
|
+
{ name: "value", type: "uint256" },
|
|
481
|
+
{ name: "data", type: "bytes" }
|
|
482
|
+
]
|
|
483
|
+
};
|
|
484
|
+
var reserveDepositAbi = [
|
|
485
|
+
{
|
|
486
|
+
type: "function",
|
|
487
|
+
name: "reserveDeposit",
|
|
488
|
+
stateMutability: "nonpayable",
|
|
489
|
+
inputs: [{ name: "expectedAmountUsdcUnits", type: "uint256" }],
|
|
490
|
+
outputs: []
|
|
491
|
+
}
|
|
492
|
+
];
|
|
493
|
+
var createPositionPushFundedAbi = [
|
|
494
|
+
{
|
|
495
|
+
type: "function",
|
|
496
|
+
name: "createPositionPushFunded",
|
|
497
|
+
stateMutability: "nonpayable",
|
|
498
|
+
inputs: [
|
|
499
|
+
{ name: "positionSeed", type: "bytes16" },
|
|
500
|
+
{ name: "marketId", type: "bytes32" },
|
|
501
|
+
{ name: "tokenId", type: "uint256" },
|
|
502
|
+
{ name: "collateralUsdcUnits", type: "uint256" },
|
|
503
|
+
{ name: "leverageBps", type: "uint32" },
|
|
504
|
+
{ name: "notionalUsdcUnits", type: "uint256" },
|
|
505
|
+
{ name: "originationFeeBps", type: "uint16" },
|
|
506
|
+
{ name: "lifetimeFeeAprBps", type: "uint16" },
|
|
507
|
+
{ name: "liquidationFeeBps", type: "uint16" },
|
|
508
|
+
{ name: "venueFeeUsdcUnits", type: "uint256" },
|
|
509
|
+
{ name: "signature", type: "bytes" },
|
|
510
|
+
{ name: "signatureExpiry", type: "uint256" }
|
|
511
|
+
],
|
|
512
|
+
outputs: []
|
|
513
|
+
}
|
|
514
|
+
];
|
|
515
|
+
var erc20TransferAbi = [
|
|
516
|
+
{
|
|
517
|
+
type: "function",
|
|
518
|
+
name: "transfer",
|
|
519
|
+
stateMutability: "nonpayable",
|
|
520
|
+
inputs: [
|
|
521
|
+
{ name: "to", type: "address" },
|
|
522
|
+
{ name: "amount", type: "uint256" }
|
|
523
|
+
],
|
|
524
|
+
outputs: [{ name: "", type: "bool" }]
|
|
525
|
+
}
|
|
526
|
+
];
|
|
527
|
+
function buildPushFundedCreateCalls(offer, pUsdAddress) {
|
|
528
|
+
const vaultAddress = toAddress(offer.polygonVaultContractAddress);
|
|
529
|
+
const totalUserAmountUsdcUnits = BigInt(offer.totalUserAmountUsdcUnits);
|
|
530
|
+
const reserveDepositData = encodeFunctionData({
|
|
531
|
+
abi: reserveDepositAbi,
|
|
532
|
+
functionName: "reserveDeposit",
|
|
533
|
+
args: [totalUserAmountUsdcUnits]
|
|
534
|
+
});
|
|
535
|
+
const transferData = encodeFunctionData({
|
|
536
|
+
abi: erc20TransferAbi,
|
|
537
|
+
functionName: "transfer",
|
|
538
|
+
args: [vaultAddress, totalUserAmountUsdcUnits]
|
|
539
|
+
});
|
|
540
|
+
const createPositionData = encodeFunctionData({
|
|
541
|
+
abi: createPositionPushFundedAbi,
|
|
542
|
+
functionName: "createPositionPushFunded",
|
|
543
|
+
args: [
|
|
544
|
+
toHex(offer.positionSeedHex),
|
|
545
|
+
toHex(offer.polymarketMarketId),
|
|
546
|
+
BigInt(offer.polymarketTokenId),
|
|
547
|
+
BigInt(offer.collateralUsdcUnits),
|
|
548
|
+
offer.leverageBps,
|
|
549
|
+
BigInt(offer.notionalUsdcUnits),
|
|
550
|
+
offer.originationFeeBps,
|
|
551
|
+
offer.lifetimeFeeAprBps,
|
|
552
|
+
offer.liquidationFeeBps,
|
|
553
|
+
BigInt(offer.expectedOpenTradingFeeUsdcUnits),
|
|
554
|
+
toHex(offer.contractSignature),
|
|
555
|
+
BigInt(offer.signatureExpiry)
|
|
556
|
+
]
|
|
557
|
+
});
|
|
558
|
+
return [
|
|
559
|
+
{ target: vaultAddress, value: 0n, data: reserveDepositData },
|
|
560
|
+
{ target: toAddress(pUsdAddress), value: 0n, data: transferData },
|
|
561
|
+
{ target: vaultAddress, value: 0n, data: createPositionData }
|
|
562
|
+
];
|
|
563
|
+
}
|
|
564
|
+
function buildRequestCloseCalls(vaultAddress, positionKey) {
|
|
565
|
+
const closeData = encodeFunctionData({
|
|
566
|
+
abi: vaultAbi,
|
|
567
|
+
functionName: "requestClose",
|
|
568
|
+
args: [toHex(positionKey)]
|
|
569
|
+
});
|
|
570
|
+
return [{ target: toAddress(vaultAddress), value: 0n, data: closeData }];
|
|
571
|
+
}
|
|
572
|
+
function buildDepositWalletBatch(params) {
|
|
573
|
+
return {
|
|
574
|
+
wallet: toAddress(params.depositWalletAddress),
|
|
575
|
+
nonce: params.nonce,
|
|
576
|
+
deadline: params.deadline,
|
|
577
|
+
calls: params.calls
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
function getDepositWalletBatchTypedData(batch) {
|
|
581
|
+
return {
|
|
582
|
+
domain: {
|
|
583
|
+
name: "DepositWallet",
|
|
584
|
+
version: "1",
|
|
585
|
+
chainId: 137,
|
|
586
|
+
verifyingContract: batch.wallet
|
|
587
|
+
},
|
|
588
|
+
types: depositWalletBatchTypes,
|
|
589
|
+
primaryType: "Batch",
|
|
590
|
+
message: batch
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function buildRelayerSubmitPayload(params) {
|
|
594
|
+
return {
|
|
595
|
+
type: "WALLET",
|
|
596
|
+
from: toAddress(params.ownerAddress),
|
|
597
|
+
to: depositWalletFactoryAddress,
|
|
598
|
+
nonce: params.batch.nonce.toString(),
|
|
599
|
+
signature: params.signature,
|
|
600
|
+
depositWalletParams: {
|
|
601
|
+
depositWallet: params.batch.wallet,
|
|
602
|
+
deadline: params.batch.deadline.toString(),
|
|
603
|
+
calls: params.batch.calls.map((call) => ({
|
|
604
|
+
target: call.target,
|
|
605
|
+
value: call.value.toString(),
|
|
606
|
+
data: call.data
|
|
607
|
+
}))
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function base64ToBytes(value) {
|
|
612
|
+
const binary = atob(value);
|
|
613
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
614
|
+
const bytes = new Uint8Array(buffer);
|
|
615
|
+
for (let i = 0; i < binary.length; i++) {
|
|
616
|
+
bytes[i] = binary.charCodeAt(i);
|
|
617
|
+
}
|
|
618
|
+
return buffer;
|
|
619
|
+
}
|
|
620
|
+
function bytesToBase64Url(bytes) {
|
|
621
|
+
let binary = "";
|
|
622
|
+
const view = new Uint8Array(bytes);
|
|
623
|
+
for (const byte of view) {
|
|
624
|
+
binary += String.fromCharCode(byte);
|
|
625
|
+
}
|
|
626
|
+
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_");
|
|
627
|
+
}
|
|
628
|
+
async function buildRelayerAuthHeaders(params) {
|
|
629
|
+
const msPerSecond = 1e3;
|
|
630
|
+
const timestamp = params.timestamp ?? Math.floor(Date.now() / msPerSecond).toString();
|
|
631
|
+
const key = await crypto.subtle.importKey(
|
|
632
|
+
"raw",
|
|
633
|
+
base64ToBytes(params.apiSecret),
|
|
634
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
635
|
+
false,
|
|
636
|
+
["sign"]
|
|
637
|
+
);
|
|
638
|
+
const encoded = new TextEncoder().encode(`${timestamp}POST/submit${params.body}`);
|
|
639
|
+
const message = new Uint8Array(encoded).buffer;
|
|
640
|
+
const signature = await crypto.subtle.sign("HMAC", key, message);
|
|
641
|
+
return {
|
|
642
|
+
"Content-Type": "application/json",
|
|
643
|
+
POLY_BUILDER_API_KEY: params.apiKey,
|
|
644
|
+
POLY_BUILDER_TIMESTAMP: timestamp,
|
|
645
|
+
POLY_BUILDER_PASSPHRASE: params.apiPassphrase,
|
|
646
|
+
POLY_BUILDER_SIGNATURE: bytesToBase64Url(signature)
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
467
650
|
// src/contract/verify-signature.ts
|
|
468
651
|
import { recoverTypedDataAddress, getAddress as getAddress2 } from "viem";
|
|
469
652
|
var createPositionTypes = {
|
|
@@ -657,9 +840,18 @@ function formatContractError(err) {
|
|
|
657
840
|
export {
|
|
658
841
|
buildApproveTx,
|
|
659
842
|
buildCreatePositionTx,
|
|
843
|
+
buildDepositWalletBatch,
|
|
844
|
+
buildPushFundedCreateCalls,
|
|
845
|
+
buildRelayerAuthHeaders,
|
|
846
|
+
buildRelayerSubmitPayload,
|
|
847
|
+
buildRequestCloseCalls,
|
|
660
848
|
buildRequestCloseTx,
|
|
849
|
+
depositWalletBatchTypes,
|
|
850
|
+
depositWalletFactoryAddress,
|
|
661
851
|
erc20Abi,
|
|
662
852
|
formatContractError,
|
|
853
|
+
getDepositWalletBatchTypedData,
|
|
854
|
+
polymarketRelayerBaseUrl,
|
|
663
855
|
recoverCreatePositionSigner,
|
|
664
856
|
resolveExpectedSigner,
|
|
665
857
|
toAddress,
|