@manifoldxyz/dropkit 0.1.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.
@@ -0,0 +1,207 @@
1
+ import { Address, Abi, Hex } from 'viem';
2
+ export { Address, Hex } from 'viem';
3
+ import { ReactNode } from 'react';
4
+
5
+ declare const UNSUPPORTED_REASONS: readonly ["UNKNOWN_EXTENSION", "AMBIGUOUS_EXTENSION", "CLAIM_NOT_FOUND", "SIGNATURE_CLAIM", "INVALID_CONFIG", "CONNECT_WIDGET_TOO_OLD"];
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"];
8
+ /** insufficient-funds carries this reason so data-reason is never empty in that state. */
9
+ declare const FUNDS_REASONS: readonly ["INSUFFICIENT_FUNDS"];
10
+ type UnsupportedReason = (typeof UNSUPPORTED_REASONS)[number];
11
+ type IneligibleReason = (typeof INELIGIBLE_REASONS)[number];
12
+ type ErrorReason = (typeof ERROR_REASONS)[number];
13
+ type ReasonCode = UnsupportedReason | IneligibleReason | ErrorReason | (typeof FUNDS_REASONS)[number];
14
+ declare const REASON_CODES: readonly ReasonCode[];
15
+ /**
16
+ * Thrown by adapters, rpc and wallet code; the hook maps it to the matching state.
17
+ * `message` is plain English and, for INVALID_CONFIG, names the exact bad field
18
+ * (e.g. `mint.args[1] "{qty}" is not a known placeholder`).
19
+ */
20
+ declare class MintError extends Error {
21
+ readonly reason: ReasonCode;
22
+ /** INVALID_CONFIG only: dotted path of the bad field, e.g. "mint.args[1]" or "price". */
23
+ readonly field?: string;
24
+ constructor(reason: ReasonCode, message: string, opts?: {
25
+ field?: string;
26
+ cause?: unknown;
27
+ });
28
+ }
29
+ declare function isMintError(e: unknown): e is MintError;
30
+
31
+ /**
32
+ * Placeholders: {recipient} {payer} {quantity} {unitPrice} {totalPrice}. Integers beyond
33
+ * Number.MAX_SAFE_INTEGER must be bigint or a decimal string (an unsafe number is INVALID_CONFIG).
34
+ */
35
+ type ArgTemplate = string | number | bigint | boolean | ArgTemplate[];
36
+ type FieldSource = {
37
+ value: bigint;
38
+ } | {
39
+ value: string;
40
+ unit: 'display';
41
+ } | {
42
+ read: {
43
+ functionName: string;
44
+ args?: ArgTemplate[];
45
+ output?: number | string;
46
+ };
47
+ };
48
+ type Erc20Ref = {
49
+ address: Address;
50
+ };
51
+ type ManifoldClaimConfig = {
52
+ type: 'manifold-claim';
53
+ chainId: number;
54
+ creatorContract: Address;
55
+ /** Studio instance id == on-chain claim index (V6+ extensions). Decimal string. */
56
+ instanceId: string;
57
+ /** Optional; auto-discovered when omitted. */
58
+ extension?: Address;
59
+ };
60
+ type ContractConfig = {
61
+ type: 'contract';
62
+ chainId: number;
63
+ /** Mint call target. */
64
+ address: Address;
65
+ /** Where Transfer logs come from; defaults to address. */
66
+ tokenContract?: Address;
67
+ abi: Abi;
68
+ mint: {
69
+ functionName: string;
70
+ args: ArgTemplate[];
71
+ };
72
+ price: FieldSource & {
73
+ currency: 'native' | Erc20Ref;
74
+ per?: 'unit' | 'total';
75
+ };
76
+ totalMinted?: FieldSource;
77
+ /** 0 or absent = open edition. */
78
+ maxSupply?: FieldSource;
79
+ walletMinted?: FieldSource;
80
+ walletMax?: FieldSource;
81
+ startTime?: FieldSource;
82
+ endTime?: FieldSource;
83
+ };
84
+ type MintConfig = ManifoldClaimConfig | ContractConfig;
85
+ /** chainId -> JSON-RPC URL (agent's domain-restricted key). */
86
+ type RpcUrls = Record<number, string>;
87
+ type Money = {
88
+ value: bigint;
89
+ decimals: number;
90
+ symbol: string;
91
+ formatted: string;
92
+ };
93
+ type DropInfo = {
94
+ chainId: number;
95
+ unitPrice: Money;
96
+ /** Manifold MINT_FEE / MINT_FEE_MERKLE per unit (native). Zero Money for external contracts. */
97
+ unitFee: Money;
98
+ totalMinted: bigint;
99
+ /** null = open edition. */
100
+ maxSupply: bigint | null;
101
+ startTime: number | null;
102
+ endTime: number | null;
103
+ isAllowlist: boolean;
104
+ /** ERC20 the price is paid in; null = native. */
105
+ paymentToken: Address | null;
106
+ /** External price is per transaction ('total') rather than per unit. */
107
+ pricePer: 'unit' | 'total';
108
+ };
109
+ type WalletInfo = {
110
+ address: Address;
111
+ chainId: number;
112
+ recipient: Address;
113
+ walletMinted: bigint | null;
114
+ walletMax: bigint | null;
115
+ allowlistRemaining: number | null;
116
+ };
117
+ type MintedToken = {
118
+ contract: Address;
119
+ tokenId: bigint;
120
+ amount: bigint;
121
+ };
122
+ type MintResult = {
123
+ txHash: Hex;
124
+ explorerUrl: string | null;
125
+ tokens: MintedToken[];
126
+ };
127
+ /** Immutable context frozen when mint is clicked (spec #state-management). */
128
+ type Attempt = {
129
+ attemptId: number;
130
+ config: MintConfig;
131
+ payer: Address;
132
+ recipient: Address;
133
+ quantity: number;
134
+ chainId: number;
135
+ tokenContract: Address;
136
+ };
137
+ type MintEventType = 'state' | 'attempt' | 'approve-submitted' | 'tx-submitted' | 'success' | 'error';
138
+ /** onEvent payload. No wallet address is included. */
139
+ type MintEvent = {
140
+ type: MintEventType;
141
+ state: MintStateName;
142
+ reason: ReasonCode | null;
143
+ chainId: number;
144
+ txHash?: Hex;
145
+ quantity: number;
146
+ config: {
147
+ type: MintConfig['type'];
148
+ chainId: number;
149
+ address: Address;
150
+ };
151
+ };
152
+
153
+ declare const MINT_STATES: readonly ["loading", "unsupported", "upcoming", "ended", "sold-out", "disconnected", "connecting", "live", "ineligible", "insufficient-funds", "switching-chain", "approving", "minting", "confirming", "success", "error"];
154
+ type MintStateName = (typeof MINT_STATES)[number];
155
+ /** States where mint() does something (spec: Clickable column). */
156
+ declare const CLICKABLE_STATES: readonly MintStateName[];
157
+ /** uint16 mintCount cap on Manifold extensions; also the global quantity cap. */
158
+ declare const MAX_QUANTITY = 65535;
159
+
160
+ /** Options for useMint and the props MintButton forwards to it (spec #package-api). */
161
+ type UseMintOptions = {
162
+ config: MintConfig;
163
+ /** chainId -> JSON-RPC URL (agent's domain-restricted key). */
164
+ rpcUrls?: RpcUrls;
165
+ /** Defaults to the connected wallet. */
166
+ recipient?: Address;
167
+ /** Controlled when onQuantityChange is also supplied. */
168
+ quantity?: number;
169
+ onQuantityChange?: (quantity: number) => void;
170
+ connect?: {
171
+ walletConnectProjectId?: string;
172
+ };
173
+ onEvent?: (event: MintEvent) => void;
174
+ };
175
+ /** Spec #data-models table 2. */
176
+ type MintState = {
177
+ state: MintStateName;
178
+ reason: ReasonCode | null;
179
+ message: string | null;
180
+ drop: DropInfo | null;
181
+ wallet: WalletInfo | null;
182
+ quantity: number;
183
+ setQuantity: (quantity: number) => void;
184
+ maxQuantity: number | null;
185
+ total: {
186
+ native: Money;
187
+ erc20: Money | null;
188
+ } | null;
189
+ mint: () => void;
190
+ result: MintResult | null;
191
+ refresh: () => Promise<void>;
192
+ canAct: boolean;
193
+ };
194
+ declare function useMint(options: UseMintOptions): MintState;
195
+
196
+ type MintButtonProps = UseMintOptions & {
197
+ className?: string;
198
+ /** Per-state text override, e.g. { live: 'Collect', 'sold-out': 'Gone' }. */
199
+ labels?: Partial<Record<MintStateName, string>>;
200
+ /** A function child replaces the default markup entirely; m.mint still drives the flow. */
201
+ children?: ReactNode | ((m: MintState) => ReactNode);
202
+ };
203
+ declare function MintButton(props: MintButtonProps): ReactNode;
204
+
205
+ declare const VERSION = "0.1.0";
206
+
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 };
@@ -0,0 +1,207 @@
1
+ import { Address, Abi, Hex } from 'viem';
2
+ export { Address, Hex } from 'viem';
3
+ import { ReactNode } from 'react';
4
+
5
+ declare const UNSUPPORTED_REASONS: readonly ["UNKNOWN_EXTENSION", "AMBIGUOUS_EXTENSION", "CLAIM_NOT_FOUND", "SIGNATURE_CLAIM", "INVALID_CONFIG", "CONNECT_WIDGET_TOO_OLD"];
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"];
8
+ /** insufficient-funds carries this reason so data-reason is never empty in that state. */
9
+ declare const FUNDS_REASONS: readonly ["INSUFFICIENT_FUNDS"];
10
+ type UnsupportedReason = (typeof UNSUPPORTED_REASONS)[number];
11
+ type IneligibleReason = (typeof INELIGIBLE_REASONS)[number];
12
+ type ErrorReason = (typeof ERROR_REASONS)[number];
13
+ type ReasonCode = UnsupportedReason | IneligibleReason | ErrorReason | (typeof FUNDS_REASONS)[number];
14
+ declare const REASON_CODES: readonly ReasonCode[];
15
+ /**
16
+ * Thrown by adapters, rpc and wallet code; the hook maps it to the matching state.
17
+ * `message` is plain English and, for INVALID_CONFIG, names the exact bad field
18
+ * (e.g. `mint.args[1] "{qty}" is not a known placeholder`).
19
+ */
20
+ declare class MintError extends Error {
21
+ readonly reason: ReasonCode;
22
+ /** INVALID_CONFIG only: dotted path of the bad field, e.g. "mint.args[1]" or "price". */
23
+ readonly field?: string;
24
+ constructor(reason: ReasonCode, message: string, opts?: {
25
+ field?: string;
26
+ cause?: unknown;
27
+ });
28
+ }
29
+ declare function isMintError(e: unknown): e is MintError;
30
+
31
+ /**
32
+ * Placeholders: {recipient} {payer} {quantity} {unitPrice} {totalPrice}. Integers beyond
33
+ * Number.MAX_SAFE_INTEGER must be bigint or a decimal string (an unsafe number is INVALID_CONFIG).
34
+ */
35
+ type ArgTemplate = string | number | bigint | boolean | ArgTemplate[];
36
+ type FieldSource = {
37
+ value: bigint;
38
+ } | {
39
+ value: string;
40
+ unit: 'display';
41
+ } | {
42
+ read: {
43
+ functionName: string;
44
+ args?: ArgTemplate[];
45
+ output?: number | string;
46
+ };
47
+ };
48
+ type Erc20Ref = {
49
+ address: Address;
50
+ };
51
+ type ManifoldClaimConfig = {
52
+ type: 'manifold-claim';
53
+ chainId: number;
54
+ creatorContract: Address;
55
+ /** Studio instance id == on-chain claim index (V6+ extensions). Decimal string. */
56
+ instanceId: string;
57
+ /** Optional; auto-discovered when omitted. */
58
+ extension?: Address;
59
+ };
60
+ type ContractConfig = {
61
+ type: 'contract';
62
+ chainId: number;
63
+ /** Mint call target. */
64
+ address: Address;
65
+ /** Where Transfer logs come from; defaults to address. */
66
+ tokenContract?: Address;
67
+ abi: Abi;
68
+ mint: {
69
+ functionName: string;
70
+ args: ArgTemplate[];
71
+ };
72
+ price: FieldSource & {
73
+ currency: 'native' | Erc20Ref;
74
+ per?: 'unit' | 'total';
75
+ };
76
+ totalMinted?: FieldSource;
77
+ /** 0 or absent = open edition. */
78
+ maxSupply?: FieldSource;
79
+ walletMinted?: FieldSource;
80
+ walletMax?: FieldSource;
81
+ startTime?: FieldSource;
82
+ endTime?: FieldSource;
83
+ };
84
+ type MintConfig = ManifoldClaimConfig | ContractConfig;
85
+ /** chainId -> JSON-RPC URL (agent's domain-restricted key). */
86
+ type RpcUrls = Record<number, string>;
87
+ type Money = {
88
+ value: bigint;
89
+ decimals: number;
90
+ symbol: string;
91
+ formatted: string;
92
+ };
93
+ type DropInfo = {
94
+ chainId: number;
95
+ unitPrice: Money;
96
+ /** Manifold MINT_FEE / MINT_FEE_MERKLE per unit (native). Zero Money for external contracts. */
97
+ unitFee: Money;
98
+ totalMinted: bigint;
99
+ /** null = open edition. */
100
+ maxSupply: bigint | null;
101
+ startTime: number | null;
102
+ endTime: number | null;
103
+ isAllowlist: boolean;
104
+ /** ERC20 the price is paid in; null = native. */
105
+ paymentToken: Address | null;
106
+ /** External price is per transaction ('total') rather than per unit. */
107
+ pricePer: 'unit' | 'total';
108
+ };
109
+ type WalletInfo = {
110
+ address: Address;
111
+ chainId: number;
112
+ recipient: Address;
113
+ walletMinted: bigint | null;
114
+ walletMax: bigint | null;
115
+ allowlistRemaining: number | null;
116
+ };
117
+ type MintedToken = {
118
+ contract: Address;
119
+ tokenId: bigint;
120
+ amount: bigint;
121
+ };
122
+ type MintResult = {
123
+ txHash: Hex;
124
+ explorerUrl: string | null;
125
+ tokens: MintedToken[];
126
+ };
127
+ /** Immutable context frozen when mint is clicked (spec #state-management). */
128
+ type Attempt = {
129
+ attemptId: number;
130
+ config: MintConfig;
131
+ payer: Address;
132
+ recipient: Address;
133
+ quantity: number;
134
+ chainId: number;
135
+ tokenContract: Address;
136
+ };
137
+ type MintEventType = 'state' | 'attempt' | 'approve-submitted' | 'tx-submitted' | 'success' | 'error';
138
+ /** onEvent payload. No wallet address is included. */
139
+ type MintEvent = {
140
+ type: MintEventType;
141
+ state: MintStateName;
142
+ reason: ReasonCode | null;
143
+ chainId: number;
144
+ txHash?: Hex;
145
+ quantity: number;
146
+ config: {
147
+ type: MintConfig['type'];
148
+ chainId: number;
149
+ address: Address;
150
+ };
151
+ };
152
+
153
+ declare const MINT_STATES: readonly ["loading", "unsupported", "upcoming", "ended", "sold-out", "disconnected", "connecting", "live", "ineligible", "insufficient-funds", "switching-chain", "approving", "minting", "confirming", "success", "error"];
154
+ type MintStateName = (typeof MINT_STATES)[number];
155
+ /** States where mint() does something (spec: Clickable column). */
156
+ declare const CLICKABLE_STATES: readonly MintStateName[];
157
+ /** uint16 mintCount cap on Manifold extensions; also the global quantity cap. */
158
+ declare const MAX_QUANTITY = 65535;
159
+
160
+ /** Options for useMint and the props MintButton forwards to it (spec #package-api). */
161
+ type UseMintOptions = {
162
+ config: MintConfig;
163
+ /** chainId -> JSON-RPC URL (agent's domain-restricted key). */
164
+ rpcUrls?: RpcUrls;
165
+ /** Defaults to the connected wallet. */
166
+ recipient?: Address;
167
+ /** Controlled when onQuantityChange is also supplied. */
168
+ quantity?: number;
169
+ onQuantityChange?: (quantity: number) => void;
170
+ connect?: {
171
+ walletConnectProjectId?: string;
172
+ };
173
+ onEvent?: (event: MintEvent) => void;
174
+ };
175
+ /** Spec #data-models table 2. */
176
+ type MintState = {
177
+ state: MintStateName;
178
+ reason: ReasonCode | null;
179
+ message: string | null;
180
+ drop: DropInfo | null;
181
+ wallet: WalletInfo | null;
182
+ quantity: number;
183
+ setQuantity: (quantity: number) => void;
184
+ maxQuantity: number | null;
185
+ total: {
186
+ native: Money;
187
+ erc20: Money | null;
188
+ } | null;
189
+ mint: () => void;
190
+ result: MintResult | null;
191
+ refresh: () => Promise<void>;
192
+ canAct: boolean;
193
+ };
194
+ declare function useMint(options: UseMintOptions): MintState;
195
+
196
+ type MintButtonProps = UseMintOptions & {
197
+ className?: string;
198
+ /** Per-state text override, e.g. { live: 'Collect', 'sold-out': 'Gone' }. */
199
+ labels?: Partial<Record<MintStateName, string>>;
200
+ /** A function child replaces the default markup entirely; m.mint still drives the flow. */
201
+ children?: ReactNode | ((m: MintState) => ReactNode);
202
+ };
203
+ declare function MintButton(props: MintButtonProps): ReactNode;
204
+
205
+ declare const VERSION = "0.1.0";
206
+
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 };