@manifoldxyz/dropkit 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -4,7 +4,7 @@ import { ReactNode } from 'react';
4
4
 
5
5
  declare const UNSUPPORTED_REASONS: readonly ["UNKNOWN_EXTENSION", "AMBIGUOUS_EXTENSION", "CLAIM_NOT_FOUND", "SIGNATURE_CLAIM", "INVALID_CONFIG", "CONNECT_WIDGET_TOO_OLD"];
6
6
  declare const INELIGIBLE_REASONS: readonly ["NOT_ON_ALLOWLIST", "ALLOWLIST_USED", "WALLET_LIMIT", "SIMULATION_REVERTED"];
7
- declare const ERROR_REASONS: readonly ["USER_REJECTED", "TX_REVERTED", "RATE_LIMITED", "RPC_ERROR", "CHAIN_SWITCH_FAILED", "ALLOWLIST_UNAVAILABLE"];
7
+ declare const ERROR_REASONS: readonly ["USER_REJECTED", "TX_REVERTED", "RATE_LIMITED", "RPC_ERROR", "CHAIN_SWITCH_FAILED", "ALLOWLIST_UNAVAILABLE", "BRIDGE_UNAVAILABLE", "BRIDGE_REFUNDED", "BRIDGE_FAILED", "BRIDGE_TIMEOUT"];
8
8
  /** insufficient-funds carries this reason so data-reason is never empty in that state. */
9
9
  declare const FUNDS_REASONS: readonly ["INSUFFICIENT_FUNDS"];
10
10
  type UnsupportedReason = (typeof UNSUPPORTED_REASONS)[number];
@@ -21,9 +21,12 @@ declare class MintError extends Error {
21
21
  readonly reason: ReasonCode;
22
22
  /** INVALID_CONFIG only: dotted path of the bad field, e.g. "mint.args[1]" or "price". */
23
23
  readonly field?: string;
24
+ /** 'relay': the message is Relay's decoded destination revert, shown as-is. */
25
+ readonly domain?: 'relay';
24
26
  constructor(reason: ReasonCode, message: string, opts?: {
25
27
  field?: string;
26
28
  cause?: unknown;
29
+ domain?: 'relay';
27
30
  });
28
31
  }
29
32
  declare function isMintError(e: unknown): e is MintError;
@@ -123,6 +126,33 @@ type MintResult = {
123
126
  txHash: Hex;
124
127
  explorerUrl: string | null;
125
128
  tokens: MintedToken[];
129
+ /** Set when the mint went through Relay: the deposit on the pay chain and Relay's request id. */
130
+ relay?: {
131
+ requestId: Hex;
132
+ originTxHash: Hex;
133
+ originChainId: number;
134
+ };
135
+ };
136
+ /** How the mint is paid (spec relay-cross-chain-mint #public-api). */
137
+ type Route = {
138
+ kind: 'direct';
139
+ chainId: number;
140
+ } | {
141
+ kind: 'relay';
142
+ /** The chain the collector pays on. */
143
+ originChainId: number;
144
+ /** What leaves the wallet on the origin chain: mint + Relay fee. */
145
+ amountIn: Money;
146
+ /** Relay's fee (fees.relayer). */
147
+ relayFee: Money;
148
+ /** Origin-chain gas Relay estimates for the deposit (fees.gas). */
149
+ originGas: Money;
150
+ /** Unix seconds. */
151
+ quotedAt: number;
152
+ };
153
+ /** Cross-chain options on useMint / MintButton. */
154
+ type CrossChainOption = boolean | {
155
+ chains?: number[];
126
156
  };
127
157
  /** Immutable context frozen when mint is clicked (spec #state-management). */
128
158
  type Attempt = {
@@ -133,6 +163,8 @@ type Attempt = {
133
163
  quantity: number;
134
164
  chainId: number;
135
165
  tokenContract: Address;
166
+ /** Chain the collector pays on; equals chainId for a direct mint. */
167
+ originChainId: number;
136
168
  };
137
169
  type MintEventType = 'state' | 'attempt' | 'approve-submitted' | 'tx-submitted' | 'success' | 'error';
138
170
  /** onEvent payload. No wallet address is included. */
@@ -148,6 +180,16 @@ type MintEvent = {
148
180
  chainId: number;
149
181
  address: Address;
150
182
  };
183
+ /** 'relay' when the mint is (or would be) paid on another chain through Relay. */
184
+ route: 'direct' | 'relay';
185
+ /** Chain the collector pays on. chainId stays the drop chain. */
186
+ originChainId: number;
187
+ };
188
+
189
+ type TxRequest = {
190
+ to: Address;
191
+ data: Hex;
192
+ value: bigint;
151
193
  };
152
194
 
153
195
  declare const MINT_STATES: readonly ["loading", "unsupported", "upcoming", "ended", "sold-out", "disconnected", "connecting", "live", "ineligible", "insufficient-funds", "switching-chain", "approving", "minting", "confirming", "success", "error"];
@@ -171,6 +213,24 @@ type UseMintOptions = {
171
213
  walletConnectProjectId?: string;
172
214
  };
173
215
  onEvent?: (event: MintEvent) => void;
216
+ /**
217
+ * Relay cross-chain mint for Manifold claims. Default on: a wallet on another supported chain pays
218
+ * there and Relay mints on the drop chain. false turns it off; `chains` narrows the pay chains.
219
+ */
220
+ crossChain?: CrossChainOption;
221
+ /** Force the pay chain. The drop chain means a direct mint. Must be one of the pay chains. */
222
+ payChainId?: number;
223
+ };
224
+ /** What PayWithPicker needs to quote other chains (spec #public-api). */
225
+ type CrossChainInfo = {
226
+ dropChainId: number;
227
+ /** Chains the collector may pay from, the drop chain included. */
228
+ payChains: number[];
229
+ /** The destination call (plan.mint for the current quantity and recipient). */
230
+ tx: TxRequest;
231
+ payer: Address;
232
+ recipient: Address;
233
+ testnet: boolean;
174
234
  };
175
235
  /** Spec #data-models table 2. */
176
236
  type MintState = {
@@ -190,9 +250,48 @@ type MintState = {
190
250
  result: MintResult | null;
191
251
  refresh: () => Promise<void>;
192
252
  canAct: boolean;
253
+ /** How this wallet pays: direct on the drop chain, or Relay from its current chain. null before a wallet read. */
254
+ route: Route | null;
255
+ /** Inputs for PayWithPicker; null when Relay cannot mint this drop for this wallet. */
256
+ crossChain: CrossChainInfo | null;
193
257
  };
194
258
  declare function useMint(options: UseMintOptions): MintState;
195
259
 
260
+ type PayOption = {
261
+ chainId: number;
262
+ name: string;
263
+ /** The wallet's current chain. */
264
+ selected: boolean;
265
+ /** The drop's own chain: no bridge, no fee ("None"). */
266
+ isDropChain: boolean;
267
+ /** Relay's fee to pay from this chain; null on the drop chain or before the quote. */
268
+ relayFee: Money | null;
269
+ /** Total leaving the wallet on this chain; null on the drop chain or before the quote. */
270
+ amountIn: Money | null;
271
+ /** Balance through the wallet, for the selected chain only (spec D14). */
272
+ balance: Money | null;
273
+ loading: boolean;
274
+ /** Pick this chain: asks the wallet to switch to it. */
275
+ select: () => void;
276
+ };
277
+ type PayWithPickerProps = {
278
+ /** From useMint, or from MintButton's function child. */
279
+ mint: MintState;
280
+ className?: string;
281
+ /** Replaces the default row markup. */
282
+ renderRow?: (row: PayOption) => ReactNode;
283
+ /** Called after a pick, with the chain id, once the wallet switched (or failed to). */
284
+ onSelect?: (chainId: number, error: unknown) => void;
285
+ };
286
+ /** Rows for every pay chain; a chain whose quote failed is hidden, the drop chain never is. */
287
+ declare function usePayOptions(mint: MintState, onSelect?: (chainId: number, error: unknown) => void): PayOption[];
288
+ /**
289
+ * One button per pay chain, showing Relay's fee (the drop chain shows "None") and, for the wallet's
290
+ * current chain only, its balance. Picking a row switches the wallet; the button re-reads the route.
291
+ * Renders nothing when the drop cannot be minted cross-chain for this wallet.
292
+ */
293
+ declare function PayWithPicker(props: PayWithPickerProps): ReactNode;
294
+
196
295
  type MintButtonProps = UseMintOptions & {
197
296
  className?: string;
198
297
  /** Per-state text override, e.g. { live: 'Collect', 'sold-out': 'Gone' }. */
@@ -202,6 +301,6 @@ type MintButtonProps = UseMintOptions & {
202
301
  };
203
302
  declare function MintButton(props: MintButtonProps): ReactNode;
204
303
 
205
- declare const VERSION = "0.1.0";
304
+ declare const VERSION = "0.2.0";
206
305
 
207
- export { type ArgTemplate, type Attempt, CLICKABLE_STATES, type ContractConfig, type DropInfo, type Erc20Ref, type ErrorReason, type FieldSource, type IneligibleReason, MAX_QUANTITY, MINT_STATES, type ManifoldClaimConfig, MintButton, type MintButtonProps, type MintConfig, MintError, type MintEvent, type MintEventType, type MintResult, type MintState, type MintStateName, type MintedToken, type Money, REASON_CODES, type ReasonCode, type RpcUrls, type UnsupportedReason, type UseMintOptions, VERSION, type WalletInfo, isMintError, useMint };
306
+ export { type ArgTemplate, type Attempt, CLICKABLE_STATES, type ContractConfig, type CrossChainInfo, type CrossChainOption, type DropInfo, type Erc20Ref, type ErrorReason, type FieldSource, type IneligibleReason, MAX_QUANTITY, MINT_STATES, type ManifoldClaimConfig, MintButton, type MintButtonProps, type MintConfig, MintError, type MintEvent, type MintEventType, type MintResult, type MintState, type MintStateName, type MintedToken, type Money, type PayOption, PayWithPicker, type PayWithPickerProps, REASON_CODES, type ReasonCode, type Route, type RpcUrls, type UnsupportedReason, type UseMintOptions, VERSION, type WalletInfo, isMintError, useMint, usePayOptions };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { ReactNode } from 'react';
4
4
 
5
5
  declare const UNSUPPORTED_REASONS: readonly ["UNKNOWN_EXTENSION", "AMBIGUOUS_EXTENSION", "CLAIM_NOT_FOUND", "SIGNATURE_CLAIM", "INVALID_CONFIG", "CONNECT_WIDGET_TOO_OLD"];
6
6
  declare const INELIGIBLE_REASONS: readonly ["NOT_ON_ALLOWLIST", "ALLOWLIST_USED", "WALLET_LIMIT", "SIMULATION_REVERTED"];
7
- declare const ERROR_REASONS: readonly ["USER_REJECTED", "TX_REVERTED", "RATE_LIMITED", "RPC_ERROR", "CHAIN_SWITCH_FAILED", "ALLOWLIST_UNAVAILABLE"];
7
+ declare const ERROR_REASONS: readonly ["USER_REJECTED", "TX_REVERTED", "RATE_LIMITED", "RPC_ERROR", "CHAIN_SWITCH_FAILED", "ALLOWLIST_UNAVAILABLE", "BRIDGE_UNAVAILABLE", "BRIDGE_REFUNDED", "BRIDGE_FAILED", "BRIDGE_TIMEOUT"];
8
8
  /** insufficient-funds carries this reason so data-reason is never empty in that state. */
9
9
  declare const FUNDS_REASONS: readonly ["INSUFFICIENT_FUNDS"];
10
10
  type UnsupportedReason = (typeof UNSUPPORTED_REASONS)[number];
@@ -21,9 +21,12 @@ declare class MintError extends Error {
21
21
  readonly reason: ReasonCode;
22
22
  /** INVALID_CONFIG only: dotted path of the bad field, e.g. "mint.args[1]" or "price". */
23
23
  readonly field?: string;
24
+ /** 'relay': the message is Relay's decoded destination revert, shown as-is. */
25
+ readonly domain?: 'relay';
24
26
  constructor(reason: ReasonCode, message: string, opts?: {
25
27
  field?: string;
26
28
  cause?: unknown;
29
+ domain?: 'relay';
27
30
  });
28
31
  }
29
32
  declare function isMintError(e: unknown): e is MintError;
@@ -123,6 +126,33 @@ type MintResult = {
123
126
  txHash: Hex;
124
127
  explorerUrl: string | null;
125
128
  tokens: MintedToken[];
129
+ /** Set when the mint went through Relay: the deposit on the pay chain and Relay's request id. */
130
+ relay?: {
131
+ requestId: Hex;
132
+ originTxHash: Hex;
133
+ originChainId: number;
134
+ };
135
+ };
136
+ /** How the mint is paid (spec relay-cross-chain-mint #public-api). */
137
+ type Route = {
138
+ kind: 'direct';
139
+ chainId: number;
140
+ } | {
141
+ kind: 'relay';
142
+ /** The chain the collector pays on. */
143
+ originChainId: number;
144
+ /** What leaves the wallet on the origin chain: mint + Relay fee. */
145
+ amountIn: Money;
146
+ /** Relay's fee (fees.relayer). */
147
+ relayFee: Money;
148
+ /** Origin-chain gas Relay estimates for the deposit (fees.gas). */
149
+ originGas: Money;
150
+ /** Unix seconds. */
151
+ quotedAt: number;
152
+ };
153
+ /** Cross-chain options on useMint / MintButton. */
154
+ type CrossChainOption = boolean | {
155
+ chains?: number[];
126
156
  };
127
157
  /** Immutable context frozen when mint is clicked (spec #state-management). */
128
158
  type Attempt = {
@@ -133,6 +163,8 @@ type Attempt = {
133
163
  quantity: number;
134
164
  chainId: number;
135
165
  tokenContract: Address;
166
+ /** Chain the collector pays on; equals chainId for a direct mint. */
167
+ originChainId: number;
136
168
  };
137
169
  type MintEventType = 'state' | 'attempt' | 'approve-submitted' | 'tx-submitted' | 'success' | 'error';
138
170
  /** onEvent payload. No wallet address is included. */
@@ -148,6 +180,16 @@ type MintEvent = {
148
180
  chainId: number;
149
181
  address: Address;
150
182
  };
183
+ /** 'relay' when the mint is (or would be) paid on another chain through Relay. */
184
+ route: 'direct' | 'relay';
185
+ /** Chain the collector pays on. chainId stays the drop chain. */
186
+ originChainId: number;
187
+ };
188
+
189
+ type TxRequest = {
190
+ to: Address;
191
+ data: Hex;
192
+ value: bigint;
151
193
  };
152
194
 
153
195
  declare const MINT_STATES: readonly ["loading", "unsupported", "upcoming", "ended", "sold-out", "disconnected", "connecting", "live", "ineligible", "insufficient-funds", "switching-chain", "approving", "minting", "confirming", "success", "error"];
@@ -171,6 +213,24 @@ type UseMintOptions = {
171
213
  walletConnectProjectId?: string;
172
214
  };
173
215
  onEvent?: (event: MintEvent) => void;
216
+ /**
217
+ * Relay cross-chain mint for Manifold claims. Default on: a wallet on another supported chain pays
218
+ * there and Relay mints on the drop chain. false turns it off; `chains` narrows the pay chains.
219
+ */
220
+ crossChain?: CrossChainOption;
221
+ /** Force the pay chain. The drop chain means a direct mint. Must be one of the pay chains. */
222
+ payChainId?: number;
223
+ };
224
+ /** What PayWithPicker needs to quote other chains (spec #public-api). */
225
+ type CrossChainInfo = {
226
+ dropChainId: number;
227
+ /** Chains the collector may pay from, the drop chain included. */
228
+ payChains: number[];
229
+ /** The destination call (plan.mint for the current quantity and recipient). */
230
+ tx: TxRequest;
231
+ payer: Address;
232
+ recipient: Address;
233
+ testnet: boolean;
174
234
  };
175
235
  /** Spec #data-models table 2. */
176
236
  type MintState = {
@@ -190,9 +250,48 @@ type MintState = {
190
250
  result: MintResult | null;
191
251
  refresh: () => Promise<void>;
192
252
  canAct: boolean;
253
+ /** How this wallet pays: direct on the drop chain, or Relay from its current chain. null before a wallet read. */
254
+ route: Route | null;
255
+ /** Inputs for PayWithPicker; null when Relay cannot mint this drop for this wallet. */
256
+ crossChain: CrossChainInfo | null;
193
257
  };
194
258
  declare function useMint(options: UseMintOptions): MintState;
195
259
 
260
+ type PayOption = {
261
+ chainId: number;
262
+ name: string;
263
+ /** The wallet's current chain. */
264
+ selected: boolean;
265
+ /** The drop's own chain: no bridge, no fee ("None"). */
266
+ isDropChain: boolean;
267
+ /** Relay's fee to pay from this chain; null on the drop chain or before the quote. */
268
+ relayFee: Money | null;
269
+ /** Total leaving the wallet on this chain; null on the drop chain or before the quote. */
270
+ amountIn: Money | null;
271
+ /** Balance through the wallet, for the selected chain only (spec D14). */
272
+ balance: Money | null;
273
+ loading: boolean;
274
+ /** Pick this chain: asks the wallet to switch to it. */
275
+ select: () => void;
276
+ };
277
+ type PayWithPickerProps = {
278
+ /** From useMint, or from MintButton's function child. */
279
+ mint: MintState;
280
+ className?: string;
281
+ /** Replaces the default row markup. */
282
+ renderRow?: (row: PayOption) => ReactNode;
283
+ /** Called after a pick, with the chain id, once the wallet switched (or failed to). */
284
+ onSelect?: (chainId: number, error: unknown) => void;
285
+ };
286
+ /** Rows for every pay chain; a chain whose quote failed is hidden, the drop chain never is. */
287
+ declare function usePayOptions(mint: MintState, onSelect?: (chainId: number, error: unknown) => void): PayOption[];
288
+ /**
289
+ * One button per pay chain, showing Relay's fee (the drop chain shows "None") and, for the wallet's
290
+ * current chain only, its balance. Picking a row switches the wallet; the button re-reads the route.
291
+ * Renders nothing when the drop cannot be minted cross-chain for this wallet.
292
+ */
293
+ declare function PayWithPicker(props: PayWithPickerProps): ReactNode;
294
+
196
295
  type MintButtonProps = UseMintOptions & {
197
296
  className?: string;
198
297
  /** Per-state text override, e.g. { live: 'Collect', 'sold-out': 'Gone' }. */
@@ -202,6 +301,6 @@ type MintButtonProps = UseMintOptions & {
202
301
  };
203
302
  declare function MintButton(props: MintButtonProps): ReactNode;
204
303
 
205
- declare const VERSION = "0.1.0";
304
+ declare const VERSION = "0.2.0";
206
305
 
207
- export { type ArgTemplate, type Attempt, CLICKABLE_STATES, type ContractConfig, type DropInfo, type Erc20Ref, type ErrorReason, type FieldSource, type IneligibleReason, MAX_QUANTITY, MINT_STATES, type ManifoldClaimConfig, MintButton, type MintButtonProps, type MintConfig, MintError, type MintEvent, type MintEventType, type MintResult, type MintState, type MintStateName, type MintedToken, type Money, REASON_CODES, type ReasonCode, type RpcUrls, type UnsupportedReason, type UseMintOptions, VERSION, type WalletInfo, isMintError, useMint };
306
+ export { type ArgTemplate, type Attempt, CLICKABLE_STATES, type ContractConfig, type CrossChainInfo, type CrossChainOption, type DropInfo, type Erc20Ref, type ErrorReason, type FieldSource, type IneligibleReason, MAX_QUANTITY, MINT_STATES, type ManifoldClaimConfig, MintButton, type MintButtonProps, type MintConfig, MintError, type MintEvent, type MintEventType, type MintResult, type MintState, type MintStateName, type MintedToken, type Money, type PayOption, PayWithPicker, type PayWithPickerProps, REASON_CODES, type ReasonCode, type Route, type RpcUrls, type UnsupportedReason, type UseMintOptions, VERSION, type WalletInfo, isMintError, useMint, usePayOptions };