@rozoai/intent-common 0.0.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/LICENSE +26 -0
- package/dist/assert.d.ts +5 -0
- package/dist/assert.js +31 -0
- package/dist/assert.js.map +1 -0
- package/dist/chain.d.ts +40 -0
- package/dist/chain.js +168 -0
- package/dist/chain.js.map +1 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +17 -0
- package/dist/debug.js.map +1 -0
- package/dist/format.d.ts +13 -0
- package/dist/format.js +25 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/primitiveTypes.d.ts +8 -0
- package/dist/primitiveTypes.js +18 -0
- package/dist/primitiveTypes.js.map +1 -0
- package/dist/retryBackoff.d.ts +5 -0
- package/dist/retryBackoff.js +28 -0
- package/dist/retryBackoff.js.map +1 -0
- package/dist/rozoPay.d.ts +450 -0
- package/dist/rozoPay.js +250 -0
- package/dist/rozoPay.js.map +1 -0
- package/dist/token.d.ts +128 -0
- package/dist/token.js +852 -0
- package/dist/token.js.map +1 -0
- package/dist/try.d.ts +3 -0
- package/dist/try.js +31 -0
- package/dist/try.js.map +1 -0
- package/package.json +35 -0
- package/src/assert.ts +29 -0
- package/src/chain.ts +182 -0
- package/src/debug.ts +14 -0
- package/src/format.ts +21 -0
- package/src/index.ts +9 -0
- package/src/primitiveTypes.ts +25 -0
- package/src/retryBackoff.ts +30 -0
- package/src/rozoPay.ts +571 -0
- package/src/token.ts +1020 -0
- package/src/try.ts +25 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { Address, Hex } from "viem";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { Token } from "./token";
|
|
4
|
+
import { BigIntStr, SolanaPublicKey } from "./primitiveTypes";
|
|
5
|
+
export declare enum RozoPayOrderStatusSource {
|
|
6
|
+
WAITING_PAYMENT = "waiting_payment",
|
|
7
|
+
PENDING_PROCESSING = "pending_processing",
|
|
8
|
+
START_SUBMITTED = "start_submitted",
|
|
9
|
+
PROCESSED = "processed"
|
|
10
|
+
}
|
|
11
|
+
export declare enum RozoPayOrderStatusDest {
|
|
12
|
+
PENDING = "pending",
|
|
13
|
+
FAST_FINISH_SUBMITTED = "fast_finish_submitted",
|
|
14
|
+
FAST_FINISHED = "fast_finished",
|
|
15
|
+
CLAIM_SUCCESSFUL = "claimed"
|
|
16
|
+
}
|
|
17
|
+
export declare enum RozoPayOrderMode {
|
|
18
|
+
SALE = "sale",// product or item sale
|
|
19
|
+
CHOOSE_AMOUNT = "choose_amount",// let the user specify the amount to pay
|
|
20
|
+
HYDRATED = "hydrated"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Status values:
|
|
24
|
+
* - `payment_unpaid` - the user has not paid yet
|
|
25
|
+
* - `payment_started` - the user has paid & payment is in progress. This status
|
|
26
|
+
* typically lasts a few seconds.
|
|
27
|
+
* - `payment_completed` - the final call or transfer succeeded
|
|
28
|
+
* - `payment_bounced` - the final call or transfer reverted. Funds were sent
|
|
29
|
+
* to the payment's configured refund address on the destination chain.
|
|
30
|
+
*/
|
|
31
|
+
export declare enum RozoPayIntentStatus {
|
|
32
|
+
UNPAID = "payment_unpaid",
|
|
33
|
+
STARTED = "payment_started",
|
|
34
|
+
COMPLETED = "payment_completed",
|
|
35
|
+
BOUNCED = "payment_bounced"
|
|
36
|
+
}
|
|
37
|
+
export interface RozoPayOrderItem {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
image?: string;
|
|
41
|
+
}
|
|
42
|
+
export declare const zBridgeTokenOutOptions: z.ZodArray<z.ZodObject<{
|
|
43
|
+
token: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
44
|
+
amount: z.ZodEffects<z.ZodEffects<z.ZodString, `${bigint}`, string>, bigint, string>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
token: `0x${string}`;
|
|
47
|
+
amount: bigint;
|
|
48
|
+
}, {
|
|
49
|
+
token: string;
|
|
50
|
+
amount: string;
|
|
51
|
+
}>, "many">;
|
|
52
|
+
export type BridgeTokenOutOptions = z.infer<typeof zBridgeTokenOutOptions>;
|
|
53
|
+
export declare const zRozoPayOrderMetadata: z.ZodObject<{
|
|
54
|
+
style: z.ZodOptional<z.ZodObject<{
|
|
55
|
+
background: z.ZodOptional<z.ZodString>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
background?: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
background?: string | undefined;
|
|
60
|
+
}>>;
|
|
61
|
+
orgLogo: z.ZodOptional<z.ZodString>;
|
|
62
|
+
intent: z.ZodString;
|
|
63
|
+
items: z.ZodArray<z.ZodObject<{
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
description: z.ZodString;
|
|
66
|
+
image: z.ZodOptional<z.ZodString>;
|
|
67
|
+
price: z.ZodOptional<z.ZodString>;
|
|
68
|
+
priceDetails: z.ZodOptional<z.ZodString>;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
image?: string | undefined;
|
|
73
|
+
price?: string | undefined;
|
|
74
|
+
priceDetails?: string | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
name: string;
|
|
77
|
+
description: string;
|
|
78
|
+
image?: string | undefined;
|
|
79
|
+
price?: string | undefined;
|
|
80
|
+
priceDetails?: string | undefined;
|
|
81
|
+
}>, "many">;
|
|
82
|
+
payer: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
preferredChains: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
84
|
+
preferredTokens: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
85
|
+
chain: z.ZodNumber;
|
|
86
|
+
address: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
chain: number;
|
|
89
|
+
address: `0x${string}`;
|
|
90
|
+
}, {
|
|
91
|
+
chain: number;
|
|
92
|
+
address: string;
|
|
93
|
+
}>, "many">>;
|
|
94
|
+
evmChains: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
95
|
+
paymentOptions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
preferredChains?: number[] | undefined;
|
|
98
|
+
preferredTokens?: {
|
|
99
|
+
chain: number;
|
|
100
|
+
address: `0x${string}`;
|
|
101
|
+
}[] | undefined;
|
|
102
|
+
evmChains?: number[] | undefined;
|
|
103
|
+
paymentOptions?: string[] | undefined;
|
|
104
|
+
}, {
|
|
105
|
+
preferredChains?: number[] | undefined;
|
|
106
|
+
preferredTokens?: {
|
|
107
|
+
chain: number;
|
|
108
|
+
address: string;
|
|
109
|
+
}[] | undefined;
|
|
110
|
+
evmChains?: number[] | undefined;
|
|
111
|
+
paymentOptions?: string[] | undefined;
|
|
112
|
+
}>>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
intent: string;
|
|
115
|
+
items: {
|
|
116
|
+
name: string;
|
|
117
|
+
description: string;
|
|
118
|
+
image?: string | undefined;
|
|
119
|
+
price?: string | undefined;
|
|
120
|
+
priceDetails?: string | undefined;
|
|
121
|
+
}[];
|
|
122
|
+
style?: {
|
|
123
|
+
background?: string | undefined;
|
|
124
|
+
} | undefined;
|
|
125
|
+
orgLogo?: string | undefined;
|
|
126
|
+
payer?: {
|
|
127
|
+
preferredChains?: number[] | undefined;
|
|
128
|
+
preferredTokens?: {
|
|
129
|
+
chain: number;
|
|
130
|
+
address: `0x${string}`;
|
|
131
|
+
}[] | undefined;
|
|
132
|
+
evmChains?: number[] | undefined;
|
|
133
|
+
paymentOptions?: string[] | undefined;
|
|
134
|
+
} | undefined;
|
|
135
|
+
}, {
|
|
136
|
+
intent: string;
|
|
137
|
+
items: {
|
|
138
|
+
name: string;
|
|
139
|
+
description: string;
|
|
140
|
+
image?: string | undefined;
|
|
141
|
+
price?: string | undefined;
|
|
142
|
+
priceDetails?: string | undefined;
|
|
143
|
+
}[];
|
|
144
|
+
style?: {
|
|
145
|
+
background?: string | undefined;
|
|
146
|
+
} | undefined;
|
|
147
|
+
orgLogo?: string | undefined;
|
|
148
|
+
payer?: {
|
|
149
|
+
preferredChains?: number[] | undefined;
|
|
150
|
+
preferredTokens?: {
|
|
151
|
+
chain: number;
|
|
152
|
+
address: string;
|
|
153
|
+
}[] | undefined;
|
|
154
|
+
evmChains?: number[] | undefined;
|
|
155
|
+
paymentOptions?: string[] | undefined;
|
|
156
|
+
} | undefined;
|
|
157
|
+
}>;
|
|
158
|
+
export type RozoPayOrderMetadata = z.infer<typeof zRozoPayOrderMetadata>;
|
|
159
|
+
/**
|
|
160
|
+
* The user-passed metadata must meet these criteria:
|
|
161
|
+
* - All keys must be strings
|
|
162
|
+
* - All values must be strings
|
|
163
|
+
* - At most 50 key-value pairs
|
|
164
|
+
* - Maximum of 40 characters per key
|
|
165
|
+
* - Maximum of 500 characters per value
|
|
166
|
+
*/
|
|
167
|
+
export declare const zRozoPayUserMetadata: z.ZodEffects<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>, Record<string, string> | null, Record<string, string> | null>;
|
|
168
|
+
export type RozoPayUserMetadata = z.infer<typeof zRozoPayUserMetadata>;
|
|
169
|
+
export type RozoPayDehydratedOrder = {
|
|
170
|
+
mode: RozoPayOrderMode.SALE | RozoPayOrderMode.CHOOSE_AMOUNT;
|
|
171
|
+
id: bigint;
|
|
172
|
+
destFinalCallTokenAmount: RozoPayTokenAmount;
|
|
173
|
+
destFinalCall: OnChainCall;
|
|
174
|
+
nonce: bigint;
|
|
175
|
+
redirectUri: string | null;
|
|
176
|
+
orgId: string | null;
|
|
177
|
+
createdAt: number | null;
|
|
178
|
+
lastUpdatedAt: number | null;
|
|
179
|
+
intentStatus: RozoPayIntentStatus;
|
|
180
|
+
metadata: RozoPayOrderMetadata;
|
|
181
|
+
externalId: string | null;
|
|
182
|
+
userMetadata: RozoPayUserMetadata | null;
|
|
183
|
+
refundAddr: Address | null;
|
|
184
|
+
};
|
|
185
|
+
export type RozoPayHydratedOrder = {
|
|
186
|
+
mode: RozoPayOrderMode.HYDRATED;
|
|
187
|
+
id: bigint;
|
|
188
|
+
intentAddr: Address;
|
|
189
|
+
/** Nullable because old intents don't record escrow address. */
|
|
190
|
+
escrowContractAddress: Address | null;
|
|
191
|
+
/** Nullable because old intents don't record bridger address. */
|
|
192
|
+
bridgerContractAddress: Address | null;
|
|
193
|
+
/** @deprecated included for backcompat with old versions. Remove soon. */
|
|
194
|
+
handoffAddr: Address;
|
|
195
|
+
bridgeTokenOutOptions: RozoPayTokenAmount[];
|
|
196
|
+
selectedBridgeTokenOutAddr: Address | null;
|
|
197
|
+
selectedBridgeTokenOutAmount: bigint | null;
|
|
198
|
+
destFinalCallTokenAmount: RozoPayTokenAmount;
|
|
199
|
+
destFinalCall: OnChainCall;
|
|
200
|
+
usdValue: number;
|
|
201
|
+
refundAddr: Address;
|
|
202
|
+
nonce: bigint;
|
|
203
|
+
sourceFulfillerAddr: Address | SolanaPublicKey | null;
|
|
204
|
+
sourceTokenAmount: RozoPayTokenAmount | null;
|
|
205
|
+
sourceInitiateTxHash: Hex | null;
|
|
206
|
+
sourceStartTxHash: Hex | null;
|
|
207
|
+
sourceStatus: RozoPayOrderStatusSource;
|
|
208
|
+
destStatus: RozoPayOrderStatusDest;
|
|
209
|
+
destFastFinishTxHash: Hex | null;
|
|
210
|
+
destClaimTxHash: Hex | null;
|
|
211
|
+
redirectUri: string | null;
|
|
212
|
+
orgId: string | null;
|
|
213
|
+
createdAt: number | null;
|
|
214
|
+
lastUpdatedAt: number | null;
|
|
215
|
+
intentStatus: RozoPayIntentStatus;
|
|
216
|
+
metadata: RozoPayOrderMetadata;
|
|
217
|
+
externalId: string | null;
|
|
218
|
+
userMetadata: RozoPayUserMetadata | null;
|
|
219
|
+
/** Nullable because old intents don't have expiration time. */
|
|
220
|
+
expirationTs: bigint | null;
|
|
221
|
+
};
|
|
222
|
+
export type RozoPayOrderWithOrg = RozoPayOrder & {
|
|
223
|
+
org: RozoPayOrgPublicInfo;
|
|
224
|
+
};
|
|
225
|
+
export type RozoPayHydratedOrderWithOrg = RozoPayHydratedOrder & {
|
|
226
|
+
org: RozoPayOrgPublicInfo;
|
|
227
|
+
};
|
|
228
|
+
export type RozoPayOrgPublicInfo = {
|
|
229
|
+
orgId: string;
|
|
230
|
+
name: string;
|
|
231
|
+
logoURI?: string;
|
|
232
|
+
};
|
|
233
|
+
export type RozoPayHydratedOrderWithoutIntentAddr = Omit<RozoPayHydratedOrder, "intentAddr" | "handoffAddr">;
|
|
234
|
+
export type RozoPayOrder = RozoPayDehydratedOrder | RozoPayHydratedOrder;
|
|
235
|
+
export declare function isHydrated(order: RozoPayOrder): order is RozoPayHydratedOrder;
|
|
236
|
+
export type RozoPayOrderView = {
|
|
237
|
+
id: RozoPayOrderID;
|
|
238
|
+
status: RozoPayIntentStatus;
|
|
239
|
+
createdAt: string;
|
|
240
|
+
display: {
|
|
241
|
+
intent: string;
|
|
242
|
+
paymentValue: string;
|
|
243
|
+
currency: "USD";
|
|
244
|
+
};
|
|
245
|
+
source: {
|
|
246
|
+
payerAddress: Address | SolanaPublicKey | null;
|
|
247
|
+
txHash: Hex | string | null;
|
|
248
|
+
chainId: string;
|
|
249
|
+
amountUnits: string;
|
|
250
|
+
tokenSymbol: string;
|
|
251
|
+
tokenAddress: Address | string;
|
|
252
|
+
} | null;
|
|
253
|
+
destination: {
|
|
254
|
+
destinationAddress: Address;
|
|
255
|
+
txHash: Hex | null;
|
|
256
|
+
chainId: string;
|
|
257
|
+
amountUnits: string;
|
|
258
|
+
tokenSymbol: string;
|
|
259
|
+
tokenAddress: Address;
|
|
260
|
+
callData: Hex | null;
|
|
261
|
+
};
|
|
262
|
+
externalId: string | null;
|
|
263
|
+
metadata: RozoPayUserMetadata | null;
|
|
264
|
+
};
|
|
265
|
+
export declare function getOrderSourceChainId(order: RozoPayHydratedOrder): number | null;
|
|
266
|
+
export declare function getOrderDestChainId(order: RozoPayOrder | RozoPayHydratedOrderWithoutIntentAddr): number;
|
|
267
|
+
export declare function getRozoPayOrderView(order: RozoPayOrder): RozoPayOrderView;
|
|
268
|
+
export type WalletPaymentOption = {
|
|
269
|
+
balance: RozoPayTokenAmount;
|
|
270
|
+
required: RozoPayTokenAmount;
|
|
271
|
+
minimumRequired: RozoPayTokenAmount;
|
|
272
|
+
fees: RozoPayTokenAmount;
|
|
273
|
+
disabledReason?: string;
|
|
274
|
+
};
|
|
275
|
+
export type ExternalPaymentOptionMetadata = {
|
|
276
|
+
id: ExternalPaymentOptions;
|
|
277
|
+
optionType: "external" | "zkp2p";
|
|
278
|
+
cta: string;
|
|
279
|
+
logoURI: string;
|
|
280
|
+
logoShape: "circle" | "squircle";
|
|
281
|
+
paymentToken: RozoPayToken;
|
|
282
|
+
disabled: boolean;
|
|
283
|
+
message?: string;
|
|
284
|
+
minimumUsd?: number;
|
|
285
|
+
};
|
|
286
|
+
export declare enum ExternalPaymentOptions {
|
|
287
|
+
Rozo = "Rozo",
|
|
288
|
+
Coinbase = "Coinbase",
|
|
289
|
+
RampNetwork = "RampNetwork",
|
|
290
|
+
Binance = "Binance",
|
|
291
|
+
Solana = "Solana",
|
|
292
|
+
ExternalChains = "ExternalChains",
|
|
293
|
+
Lemon = "Lemon",
|
|
294
|
+
AllPaymentApps = "AllPaymentApps",
|
|
295
|
+
Venmo = "Venmo",
|
|
296
|
+
CashApp = "CashApp",
|
|
297
|
+
MercadoPago = "MercadoPago",
|
|
298
|
+
Revolut = "Revolut",
|
|
299
|
+
Wise = "Wise"
|
|
300
|
+
}
|
|
301
|
+
export type ExternalPaymentOptionsString = `${ExternalPaymentOptions}`;
|
|
302
|
+
export type ExternalPaymentOptionData = {
|
|
303
|
+
url: string;
|
|
304
|
+
waitingMessage: string;
|
|
305
|
+
};
|
|
306
|
+
export declare enum DepositAddressPaymentOptions {
|
|
307
|
+
TRON_USDT = "USDT on Tron",
|
|
308
|
+
BASE = "Base",
|
|
309
|
+
ARBITRUM = "Arbitrum",
|
|
310
|
+
OP_MAINNET = "Optimism",
|
|
311
|
+
POLYGON = "Polygon",
|
|
312
|
+
ETH_L1 = "Ethereum",
|
|
313
|
+
/** @deprecated */
|
|
314
|
+
BITCOIN = "Bitcoin",
|
|
315
|
+
/** @deprecated */
|
|
316
|
+
TON = "TON",
|
|
317
|
+
/** @deprecated */
|
|
318
|
+
MONERO = "Monero",
|
|
319
|
+
/** @deprecated */
|
|
320
|
+
DOGE = "Doge",
|
|
321
|
+
/** @deprecated */
|
|
322
|
+
LITECOIN = "Litecoin",
|
|
323
|
+
/** @deprecated */
|
|
324
|
+
ZCASH = "Zcash",
|
|
325
|
+
/** @deprecated */
|
|
326
|
+
DASH = "Dash"
|
|
327
|
+
}
|
|
328
|
+
export type DepositAddressPaymentOptionMetadata = {
|
|
329
|
+
id: DepositAddressPaymentOptions;
|
|
330
|
+
logoURI: string;
|
|
331
|
+
minimumUsd: number;
|
|
332
|
+
};
|
|
333
|
+
export type DepositAddressPaymentOptionData = {
|
|
334
|
+
address: string;
|
|
335
|
+
uri: string;
|
|
336
|
+
amount: string;
|
|
337
|
+
suffix: string;
|
|
338
|
+
expirationS: number;
|
|
339
|
+
};
|
|
340
|
+
export interface RozoPayToken extends Token {
|
|
341
|
+
token: Address | SolanaPublicKey;
|
|
342
|
+
/** Price to convert 1.0 of this token to a USD stablecoin. */
|
|
343
|
+
usd: number;
|
|
344
|
+
/** Price to convert $1 to this token T. If 2.00, then we receive 0.5 T. */
|
|
345
|
+
priceFromUsd: number;
|
|
346
|
+
/** Max payment accepted in this token, based on liquidity & mode. */
|
|
347
|
+
maxAcceptUsd: number;
|
|
348
|
+
/** Max payment we can send from this token, based on liquidity & mode. */
|
|
349
|
+
maxSendUsd: number;
|
|
350
|
+
/** Display decimals, separate from token decimals. Eg: 2 for USDC. */
|
|
351
|
+
displayDecimals: number;
|
|
352
|
+
/** Symbol for fiat currency, eg: "$" */
|
|
353
|
+
fiatSymbol?: string;
|
|
354
|
+
}
|
|
355
|
+
export interface RozoPayTokenAmount {
|
|
356
|
+
token: RozoPayToken;
|
|
357
|
+
amount: BigIntStr;
|
|
358
|
+
usd: number;
|
|
359
|
+
}
|
|
360
|
+
export type OnChainCall = {
|
|
361
|
+
to: Address;
|
|
362
|
+
data: Hex;
|
|
363
|
+
value: bigint;
|
|
364
|
+
};
|
|
365
|
+
export declare const emptyOnChainCall: OnChainCall;
|
|
366
|
+
declare const zRozoPayOrderID: z.ZodString;
|
|
367
|
+
export type RozoPayOrderID = z.infer<typeof zRozoPayOrderID>;
|
|
368
|
+
/**
|
|
369
|
+
* Read a base58-encoded id into a bigint.
|
|
370
|
+
*/
|
|
371
|
+
export declare function readRozoPayOrderID(id: string): bigint;
|
|
372
|
+
/**
|
|
373
|
+
* Write a bigint into a base58-encoded id.
|
|
374
|
+
*/
|
|
375
|
+
export declare function writeRozoPayOrderID(id: bigint): string;
|
|
376
|
+
export declare const zUUID: z.ZodString;
|
|
377
|
+
export type UUID = z.infer<typeof zUUID>;
|
|
378
|
+
export declare enum RozoPayEventType {
|
|
379
|
+
PaymentStarted = "payment_started",
|
|
380
|
+
PaymentCompleted = "payment_completed",
|
|
381
|
+
PaymentBounced = "payment_bounced",
|
|
382
|
+
PaymentRefunded = "payment_refunded"
|
|
383
|
+
}
|
|
384
|
+
export type PaymentStartedEvent = {
|
|
385
|
+
type: RozoPayEventType.PaymentStarted;
|
|
386
|
+
isTestEvent?: boolean;
|
|
387
|
+
paymentId: RozoPayOrderID;
|
|
388
|
+
chainId: number;
|
|
389
|
+
txHash: Hex | string | null;
|
|
390
|
+
payment: RozoPayOrderView;
|
|
391
|
+
};
|
|
392
|
+
export type PaymentCompletedEvent = {
|
|
393
|
+
type: RozoPayEventType.PaymentCompleted;
|
|
394
|
+
isTestEvent?: boolean;
|
|
395
|
+
paymentId: RozoPayOrderID;
|
|
396
|
+
chainId: number;
|
|
397
|
+
txHash: Hex;
|
|
398
|
+
payment: RozoPayOrderView;
|
|
399
|
+
};
|
|
400
|
+
export type PaymentBouncedEvent = {
|
|
401
|
+
type: RozoPayEventType.PaymentBounced;
|
|
402
|
+
isTestEvent?: boolean;
|
|
403
|
+
paymentId: RozoPayOrderID;
|
|
404
|
+
chainId: number;
|
|
405
|
+
txHash: Hex;
|
|
406
|
+
payment: RozoPayOrderView;
|
|
407
|
+
};
|
|
408
|
+
export type PaymentRefundedEvent = {
|
|
409
|
+
type: RozoPayEventType.PaymentRefunded;
|
|
410
|
+
isTestEvent?: boolean;
|
|
411
|
+
paymentId: RozoPayOrderID;
|
|
412
|
+
refundAddress: Address;
|
|
413
|
+
chainId: number;
|
|
414
|
+
tokenAddress: Address;
|
|
415
|
+
txHash: Hex;
|
|
416
|
+
amountUnits: string;
|
|
417
|
+
payment: RozoPayOrderView;
|
|
418
|
+
};
|
|
419
|
+
export type RozoPayEvent = PaymentStartedEvent | PaymentCompletedEvent | PaymentBouncedEvent | PaymentRefundedEvent;
|
|
420
|
+
export interface WebhookEndpoint {
|
|
421
|
+
id: UUID;
|
|
422
|
+
orgId: UUID;
|
|
423
|
+
url: string;
|
|
424
|
+
token: string;
|
|
425
|
+
createdAt: Date;
|
|
426
|
+
deletedAt: Date | null;
|
|
427
|
+
}
|
|
428
|
+
export declare enum WebhookEventStatus {
|
|
429
|
+
PENDING = "pending",// waiting to be delivered
|
|
430
|
+
RETRYING = "retrying",// currently in exponential backoff queue
|
|
431
|
+
SUCCESSFUL = "successful",// successfully delivered
|
|
432
|
+
FAILED = "failed"
|
|
433
|
+
}
|
|
434
|
+
export interface WebhookEvent {
|
|
435
|
+
id: UUID;
|
|
436
|
+
endpoint: WebhookEndpoint;
|
|
437
|
+
isTestEvent: boolean;
|
|
438
|
+
body: RozoPayEvent;
|
|
439
|
+
status: WebhookEventStatus;
|
|
440
|
+
deliveries: WebhookDelivery[];
|
|
441
|
+
createdAt: Date;
|
|
442
|
+
}
|
|
443
|
+
export interface WebhookDelivery {
|
|
444
|
+
id: UUID;
|
|
445
|
+
eventId: UUID;
|
|
446
|
+
httpStatus: number | null;
|
|
447
|
+
body: string | null;
|
|
448
|
+
createdAt: Date;
|
|
449
|
+
}
|
|
450
|
+
export {};
|
package/dist/rozoPay.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: this file defines types that shouldn't be exposed to the client.
|
|
3
|
+
// Clean this up to only expose the types that are needed by the client.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.WebhookEventStatus = exports.RozoPayEventType = exports.zUUID = exports.emptyOnChainCall = exports.DepositAddressPaymentOptions = exports.ExternalPaymentOptions = exports.zRozoPayUserMetadata = exports.zRozoPayOrderMetadata = exports.zBridgeTokenOutOptions = exports.RozoPayIntentStatus = exports.RozoPayOrderMode = exports.RozoPayOrderStatusDest = exports.RozoPayOrderStatusSource = void 0;
|
|
9
|
+
exports.isHydrated = isHydrated;
|
|
10
|
+
exports.getOrderSourceChainId = getOrderSourceChainId;
|
|
11
|
+
exports.getOrderDestChainId = getOrderDestChainId;
|
|
12
|
+
exports.getRozoPayOrderView = getRozoPayOrderView;
|
|
13
|
+
exports.readRozoPayOrderID = readRozoPayOrderID;
|
|
14
|
+
exports.writeRozoPayOrderID = writeRozoPayOrderID;
|
|
15
|
+
const base_1 = require("@scure/base");
|
|
16
|
+
const viem_1 = require("viem");
|
|
17
|
+
const zod_1 = __importDefault(require("zod"));
|
|
18
|
+
const assert_1 = require("./assert");
|
|
19
|
+
const primitiveTypes_1 = require("./primitiveTypes");
|
|
20
|
+
// lifecycle: waiting payment -> pending processing -> start submitted -> processed (onchain tx was successful)
|
|
21
|
+
var RozoPayOrderStatusSource;
|
|
22
|
+
(function (RozoPayOrderStatusSource) {
|
|
23
|
+
RozoPayOrderStatusSource["WAITING_PAYMENT"] = "waiting_payment";
|
|
24
|
+
RozoPayOrderStatusSource["PENDING_PROCESSING"] = "pending_processing";
|
|
25
|
+
RozoPayOrderStatusSource["START_SUBMITTED"] = "start_submitted";
|
|
26
|
+
/* Start transaction receipt confirmed. */
|
|
27
|
+
RozoPayOrderStatusSource["PROCESSED"] = "processed";
|
|
28
|
+
})(RozoPayOrderStatusSource || (exports.RozoPayOrderStatusSource = RozoPayOrderStatusSource = {}));
|
|
29
|
+
// lifecycle: pending -> fast-finish-submitted (onchain tx submitted) -> fast-finished (onchain tx was successful) -> claimed (onchain tx was successful)
|
|
30
|
+
var RozoPayOrderStatusDest;
|
|
31
|
+
(function (RozoPayOrderStatusDest) {
|
|
32
|
+
RozoPayOrderStatusDest["PENDING"] = "pending";
|
|
33
|
+
RozoPayOrderStatusDest["FAST_FINISH_SUBMITTED"] = "fast_finish_submitted";
|
|
34
|
+
/* Fast finish transaction receipt confirmed. */
|
|
35
|
+
RozoPayOrderStatusDest["FAST_FINISHED"] = "fast_finished";
|
|
36
|
+
RozoPayOrderStatusDest["CLAIM_SUCCESSFUL"] = "claimed";
|
|
37
|
+
})(RozoPayOrderStatusDest || (exports.RozoPayOrderStatusDest = RozoPayOrderStatusDest = {}));
|
|
38
|
+
var RozoPayOrderMode;
|
|
39
|
+
(function (RozoPayOrderMode) {
|
|
40
|
+
RozoPayOrderMode["SALE"] = "sale";
|
|
41
|
+
RozoPayOrderMode["CHOOSE_AMOUNT"] = "choose_amount";
|
|
42
|
+
RozoPayOrderMode["HYDRATED"] = "hydrated";
|
|
43
|
+
})(RozoPayOrderMode || (exports.RozoPayOrderMode = RozoPayOrderMode = {}));
|
|
44
|
+
/**
|
|
45
|
+
* Status values:
|
|
46
|
+
* - `payment_unpaid` - the user has not paid yet
|
|
47
|
+
* - `payment_started` - the user has paid & payment is in progress. This status
|
|
48
|
+
* typically lasts a few seconds.
|
|
49
|
+
* - `payment_completed` - the final call or transfer succeeded
|
|
50
|
+
* - `payment_bounced` - the final call or transfer reverted. Funds were sent
|
|
51
|
+
* to the payment's configured refund address on the destination chain.
|
|
52
|
+
*/
|
|
53
|
+
var RozoPayIntentStatus;
|
|
54
|
+
(function (RozoPayIntentStatus) {
|
|
55
|
+
RozoPayIntentStatus["UNPAID"] = "payment_unpaid";
|
|
56
|
+
RozoPayIntentStatus["STARTED"] = "payment_started";
|
|
57
|
+
RozoPayIntentStatus["COMPLETED"] = "payment_completed";
|
|
58
|
+
RozoPayIntentStatus["BOUNCED"] = "payment_bounced";
|
|
59
|
+
})(RozoPayIntentStatus || (exports.RozoPayIntentStatus = RozoPayIntentStatus = {}));
|
|
60
|
+
exports.zBridgeTokenOutOptions = zod_1.default.array(zod_1.default.object({
|
|
61
|
+
token: primitiveTypes_1.zAddress,
|
|
62
|
+
amount: primitiveTypes_1.zBigIntStr.transform((a) => BigInt(a)),
|
|
63
|
+
}));
|
|
64
|
+
// NOTE: be careful to modify this type only in backward-compatible ways.
|
|
65
|
+
// Add OPTIONAL fields, etc. Anything else requires a migration.
|
|
66
|
+
exports.zRozoPayOrderMetadata = zod_1.default.object({
|
|
67
|
+
style: zod_1.default
|
|
68
|
+
.object({
|
|
69
|
+
background: zod_1.default.string().optional().describe("Background color."),
|
|
70
|
+
})
|
|
71
|
+
.optional()
|
|
72
|
+
.describe("Style of the checkout page."),
|
|
73
|
+
orgLogo: zod_1.default.string().optional().describe("Logo of the organization."),
|
|
74
|
+
intent: zod_1.default
|
|
75
|
+
.string()
|
|
76
|
+
.describe("Title verb, eg 'Preorder', 'Check out', 'Deposit'."),
|
|
77
|
+
items: zod_1.default
|
|
78
|
+
.array(zod_1.default.object({
|
|
79
|
+
name: zod_1.default.string(),
|
|
80
|
+
description: zod_1.default.string(),
|
|
81
|
+
image: zod_1.default.string().optional(),
|
|
82
|
+
price: zod_1.default.string().optional(),
|
|
83
|
+
priceDetails: zod_1.default.string().optional(),
|
|
84
|
+
}))
|
|
85
|
+
.describe("Details about what's being ordered, donated, deposited, etc."),
|
|
86
|
+
payer: zod_1.default
|
|
87
|
+
.object({
|
|
88
|
+
preferredChains: zod_1.default
|
|
89
|
+
.array(zod_1.default.number())
|
|
90
|
+
.optional()
|
|
91
|
+
.describe("Preferred chain IDs, in descending order. Any assets the user owns on preferred chains will appear first. Defaults to destination chain."),
|
|
92
|
+
preferredTokens: zod_1.default
|
|
93
|
+
.array(zod_1.default.object({
|
|
94
|
+
chain: zod_1.default.number(),
|
|
95
|
+
address: primitiveTypes_1.zAddress.transform((a) => (0, viem_1.getAddress)(a)),
|
|
96
|
+
}))
|
|
97
|
+
.optional()
|
|
98
|
+
.describe("Preferred tokens, in descending order. Any preferred assets the user owns will appear first. Defaults to destination token."),
|
|
99
|
+
// Filter to only allow payments on these chains. Keep this
|
|
100
|
+
// parameter undocumented. Only for specific customers.
|
|
101
|
+
evmChains: zod_1.default
|
|
102
|
+
.array(zod_1.default.number())
|
|
103
|
+
.optional()
|
|
104
|
+
.describe("Filter to only allow payments on these EVM chains. Defaults to all chains."),
|
|
105
|
+
paymentOptions: zod_1.default
|
|
106
|
+
.array(zod_1.default.string())
|
|
107
|
+
.optional()
|
|
108
|
+
.describe("Payment options like Coinbase, Binance, etc. Defaults to all available options."),
|
|
109
|
+
})
|
|
110
|
+
.optional()
|
|
111
|
+
.describe(""),
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* The user-passed metadata must meet these criteria:
|
|
115
|
+
* - All keys must be strings
|
|
116
|
+
* - All values must be strings
|
|
117
|
+
* - At most 50 key-value pairs
|
|
118
|
+
* - Maximum of 40 characters per key
|
|
119
|
+
* - Maximum of 500 characters per value
|
|
120
|
+
*/
|
|
121
|
+
exports.zRozoPayUserMetadata = zod_1.default
|
|
122
|
+
.record(zod_1.default.string().max(40, "Metadata keys cannot be longer than 40 characters"), zod_1.default.string().max(500, "Metadata values cannot be longer than 500 characters"))
|
|
123
|
+
.nullable()
|
|
124
|
+
.refine((obj) => !obj || Object.keys(obj).length <= 50, "Metadata cannot have more than 50 key-value pairs");
|
|
125
|
+
function isHydrated(order) {
|
|
126
|
+
return order.mode === RozoPayOrderMode.HYDRATED;
|
|
127
|
+
}
|
|
128
|
+
function getOrderSourceChainId(order) {
|
|
129
|
+
if (order.sourceTokenAmount == null) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return order.sourceTokenAmount.token.chainId;
|
|
133
|
+
}
|
|
134
|
+
function getOrderDestChainId(order) {
|
|
135
|
+
return order.destFinalCallTokenAmount.token.chainId;
|
|
136
|
+
}
|
|
137
|
+
function getRozoPayOrderView(order) {
|
|
138
|
+
return {
|
|
139
|
+
id: writeRozoPayOrderID(order.id),
|
|
140
|
+
status: order.intentStatus,
|
|
141
|
+
createdAt: (0, assert_1.assertNotNull)(order.createdAt, `createdAt is null for order with id: ${order.id}`).toString(),
|
|
142
|
+
display: {
|
|
143
|
+
intent: order.metadata.intent,
|
|
144
|
+
// Show 2 decimal places for USD
|
|
145
|
+
paymentValue: order.destFinalCallTokenAmount.usd.toFixed(2),
|
|
146
|
+
currency: "USD",
|
|
147
|
+
},
|
|
148
|
+
source: order.mode === RozoPayOrderMode.HYDRATED &&
|
|
149
|
+
order.sourceTokenAmount != null
|
|
150
|
+
? {
|
|
151
|
+
payerAddress: order.sourceFulfillerAddr,
|
|
152
|
+
txHash: order.sourceInitiateTxHash,
|
|
153
|
+
chainId: (0, assert_1.assertNotNull)(getOrderSourceChainId(order), `source chain id is null for order with source token: ${order.id}`).toString(),
|
|
154
|
+
amountUnits: (0, viem_1.formatUnits)(BigInt(order.sourceTokenAmount.amount), order.sourceTokenAmount.token.decimals),
|
|
155
|
+
tokenSymbol: order.sourceTokenAmount.token.symbol,
|
|
156
|
+
tokenAddress: order.sourceTokenAmount.token.token,
|
|
157
|
+
}
|
|
158
|
+
: null,
|
|
159
|
+
destination: {
|
|
160
|
+
destinationAddress: order.destFinalCall.to,
|
|
161
|
+
txHash: order.mode === RozoPayOrderMode.HYDRATED
|
|
162
|
+
? order.destFastFinishTxHash ?? order.destClaimTxHash
|
|
163
|
+
: null,
|
|
164
|
+
chainId: getOrderDestChainId(order).toString(),
|
|
165
|
+
amountUnits: (0, viem_1.formatUnits)(BigInt(order.destFinalCallTokenAmount.amount), order.destFinalCallTokenAmount.token.decimals),
|
|
166
|
+
tokenSymbol: order.destFinalCallTokenAmount.token.symbol,
|
|
167
|
+
tokenAddress: (0, viem_1.getAddress)(order.destFinalCallTokenAmount.token.token),
|
|
168
|
+
callData: order.destFinalCall.data,
|
|
169
|
+
},
|
|
170
|
+
externalId: order.externalId,
|
|
171
|
+
metadata: order.userMetadata,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
var ExternalPaymentOptions;
|
|
175
|
+
(function (ExternalPaymentOptions) {
|
|
176
|
+
ExternalPaymentOptions["Rozo"] = "Rozo";
|
|
177
|
+
ExternalPaymentOptions["Coinbase"] = "Coinbase";
|
|
178
|
+
ExternalPaymentOptions["RampNetwork"] = "RampNetwork";
|
|
179
|
+
ExternalPaymentOptions["Binance"] = "Binance";
|
|
180
|
+
ExternalPaymentOptions["Solana"] = "Solana";
|
|
181
|
+
// ChangeNow chains. Bitcoin, Litecoin, Doge, Tron, etc.
|
|
182
|
+
ExternalPaymentOptions["ExternalChains"] = "ExternalChains";
|
|
183
|
+
ExternalPaymentOptions["Lemon"] = "Lemon";
|
|
184
|
+
// All available payment apps
|
|
185
|
+
ExternalPaymentOptions["AllPaymentApps"] = "AllPaymentApps";
|
|
186
|
+
ExternalPaymentOptions["Venmo"] = "Venmo";
|
|
187
|
+
ExternalPaymentOptions["CashApp"] = "CashApp";
|
|
188
|
+
ExternalPaymentOptions["MercadoPago"] = "MercadoPago";
|
|
189
|
+
ExternalPaymentOptions["Revolut"] = "Revolut";
|
|
190
|
+
ExternalPaymentOptions["Wise"] = "Wise";
|
|
191
|
+
})(ExternalPaymentOptions || (exports.ExternalPaymentOptions = ExternalPaymentOptions = {}));
|
|
192
|
+
var DepositAddressPaymentOptions;
|
|
193
|
+
(function (DepositAddressPaymentOptions) {
|
|
194
|
+
DepositAddressPaymentOptions["TRON_USDT"] = "USDT on Tron";
|
|
195
|
+
DepositAddressPaymentOptions["BASE"] = "Base";
|
|
196
|
+
DepositAddressPaymentOptions["ARBITRUM"] = "Arbitrum";
|
|
197
|
+
DepositAddressPaymentOptions["OP_MAINNET"] = "Optimism";
|
|
198
|
+
DepositAddressPaymentOptions["POLYGON"] = "Polygon";
|
|
199
|
+
DepositAddressPaymentOptions["ETH_L1"] = "Ethereum";
|
|
200
|
+
/** @deprecated */
|
|
201
|
+
DepositAddressPaymentOptions["BITCOIN"] = "Bitcoin";
|
|
202
|
+
/** @deprecated */
|
|
203
|
+
DepositAddressPaymentOptions["TON"] = "TON";
|
|
204
|
+
/** @deprecated */
|
|
205
|
+
DepositAddressPaymentOptions["MONERO"] = "Monero";
|
|
206
|
+
/** @deprecated */
|
|
207
|
+
DepositAddressPaymentOptions["DOGE"] = "Doge";
|
|
208
|
+
/** @deprecated */
|
|
209
|
+
DepositAddressPaymentOptions["LITECOIN"] = "Litecoin";
|
|
210
|
+
/** @deprecated */
|
|
211
|
+
DepositAddressPaymentOptions["ZCASH"] = "Zcash";
|
|
212
|
+
/** @deprecated */
|
|
213
|
+
DepositAddressPaymentOptions["DASH"] = "Dash";
|
|
214
|
+
})(DepositAddressPaymentOptions || (exports.DepositAddressPaymentOptions = DepositAddressPaymentOptions = {}));
|
|
215
|
+
exports.emptyOnChainCall = {
|
|
216
|
+
to: viem_1.zeroAddress,
|
|
217
|
+
data: "0x",
|
|
218
|
+
value: 0n,
|
|
219
|
+
};
|
|
220
|
+
// base58 encoded bigint
|
|
221
|
+
const zRozoPayOrderID = zod_1.default.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
222
|
+
/**
|
|
223
|
+
* Read a base58-encoded id into a bigint.
|
|
224
|
+
*/
|
|
225
|
+
function readRozoPayOrderID(id) {
|
|
226
|
+
return (0, viem_1.bytesToBigInt)(base_1.base58.decode(id));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Write a bigint into a base58-encoded id.
|
|
230
|
+
*/
|
|
231
|
+
function writeRozoPayOrderID(id) {
|
|
232
|
+
return base_1.base58.encode((0, viem_1.numberToBytes)(id));
|
|
233
|
+
}
|
|
234
|
+
exports.zUUID = zod_1.default.string().uuid();
|
|
235
|
+
var RozoPayEventType;
|
|
236
|
+
(function (RozoPayEventType) {
|
|
237
|
+
RozoPayEventType["PaymentStarted"] = "payment_started";
|
|
238
|
+
RozoPayEventType["PaymentCompleted"] = "payment_completed";
|
|
239
|
+
RozoPayEventType["PaymentBounced"] = "payment_bounced";
|
|
240
|
+
RozoPayEventType["PaymentRefunded"] = "payment_refunded";
|
|
241
|
+
})(RozoPayEventType || (exports.RozoPayEventType = RozoPayEventType = {}));
|
|
242
|
+
// Lifecycle: Pending (just created) -> (if failing) Retrying (exponential backoff) -> Successful or Failed
|
|
243
|
+
var WebhookEventStatus;
|
|
244
|
+
(function (WebhookEventStatus) {
|
|
245
|
+
WebhookEventStatus["PENDING"] = "pending";
|
|
246
|
+
WebhookEventStatus["RETRYING"] = "retrying";
|
|
247
|
+
WebhookEventStatus["SUCCESSFUL"] = "successful";
|
|
248
|
+
WebhookEventStatus["FAILED"] = "failed";
|
|
249
|
+
})(WebhookEventStatus || (exports.WebhookEventStatus = WebhookEventStatus = {}));
|
|
250
|
+
//# sourceMappingURL=rozoPay.js.map
|