@helium/blockchain-api 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.
Files changed (48) hide show
  1. package/README.md +25 -0
  2. package/package.json +142 -0
  3. package/src/server/api/errors.ts +152 -0
  4. package/src/server/api/index.ts +40 -0
  5. package/src/server/api/procedures.ts +144 -0
  6. package/src/server/api/routers/fiat/router.ts +709 -0
  7. package/src/server/api/routers/fiat/schemas.ts +157 -0
  8. package/src/server/api/routers/health/router.ts +41 -0
  9. package/src/server/api/routers/hotspots/procedures/claimRewards.ts +258 -0
  10. package/src/server/api/routers/hotspots/procedures/createSplit.ts +253 -0
  11. package/src/server/api/routers/hotspots/procedures/deleteSplit.ts +156 -0
  12. package/src/server/api/routers/hotspots/procedures/getHotspots.ts +31 -0
  13. package/src/server/api/routers/hotspots/procedures/getPendingRewards.ts +44 -0
  14. package/src/server/api/routers/hotspots/procedures/getSplit.ts +88 -0
  15. package/src/server/api/routers/hotspots/procedures/transferHotspot.ts +204 -0
  16. package/src/server/api/routers/hotspots/procedures/updateRewardsDestination.ts +201 -0
  17. package/src/server/api/routers/hotspots/router.ts +30 -0
  18. package/src/server/api/routers/hotspots/schemas.ts +182 -0
  19. package/src/server/api/routers/swap/procedures/getInstructions.ts +152 -0
  20. package/src/server/api/routers/swap/procedures/getQuote.ts +53 -0
  21. package/src/server/api/routers/swap/procedures/getTokens.ts +88 -0
  22. package/src/server/api/routers/swap/router.ts +15 -0
  23. package/src/server/api/routers/swap/schemas.ts +96 -0
  24. package/src/server/api/routers/tokens/procedures/createHntAccount.ts +87 -0
  25. package/src/server/api/routers/tokens/procedures/getBalances.ts +27 -0
  26. package/src/server/api/routers/tokens/procedures/transfer.ts +159 -0
  27. package/src/server/api/routers/tokens/router.ts +15 -0
  28. package/src/server/api/routers/tokens/schemas.ts +80 -0
  29. package/src/server/api/routers/transactions/procedures/get.ts +46 -0
  30. package/src/server/api/routers/transactions/procedures/getByPayer.ts +111 -0
  31. package/src/server/api/routers/transactions/procedures/getByPayerAndTag.ts +119 -0
  32. package/src/server/api/routers/transactions/procedures/resubmit.ts +68 -0
  33. package/src/server/api/routers/transactions/procedures/submit.ts +216 -0
  34. package/src/server/api/routers/transactions/router.ts +21 -0
  35. package/src/server/api/routers/transactions/schemas.ts +119 -0
  36. package/src/server/api/routers/webhooks/router.ts +75 -0
  37. package/src/server/api/routers/welcomePacks/procedures/claim.ts +157 -0
  38. package/src/server/api/routers/welcomePacks/procedures/create.ts +247 -0
  39. package/src/server/api/routers/welcomePacks/procedures/deletePack.ts +118 -0
  40. package/src/server/api/routers/welcomePacks/procedures/get.ts +36 -0
  41. package/src/server/api/routers/welcomePacks/procedures/getByAddress.ts +26 -0
  42. package/src/server/api/routers/welcomePacks/procedures/invite.ts +44 -0
  43. package/src/server/api/routers/welcomePacks/procedures/list.ts +27 -0
  44. package/src/server/api/routers/welcomePacks/router.ts +27 -0
  45. package/src/server/api/routers/welcomePacks/schemas.ts +135 -0
  46. package/src/server/api/schemas.ts +281 -0
  47. package/tsconfig.json +45 -0
  48. package/types/index.ts +27 -0
@@ -0,0 +1,135 @@
1
+ import { z } from "zod";
2
+ import { HotspotSchema } from "@/server/api/schemas";
3
+
4
+ // ============================================================================
5
+ // Input Schemas
6
+ // ============================================================================
7
+
8
+ export const ListInputSchema = z.object({
9
+ walletAddress: z.string().min(32),
10
+ });
11
+
12
+ export const RewardSplitInputSchema = z.object({
13
+ address: z.string(),
14
+ type: z.enum(["percentage", "fixed"]),
15
+ amount: z.number(),
16
+ });
17
+
18
+ export const ScheduleInputSchema = z.object({
19
+ frequency: z.enum(["daily", "weekly", "monthly"]),
20
+ time: z.string(),
21
+ timezone: z.string(),
22
+ dayOfWeek: z.string().optional(),
23
+ dayOfMonth: z.string().optional(),
24
+ });
25
+
26
+ export const CreateInputSchema = z.object({
27
+ walletAddress: z.string().min(32),
28
+ assetId: z.string(),
29
+ solAmount: z.number(),
30
+ rentRefund: z.string(),
31
+ assetReturnAddress: z.string(),
32
+ rewardsSplit: z.array(RewardSplitInputSchema),
33
+ schedule: ScheduleInputSchema,
34
+ lazyDistributor: z.string(),
35
+ });
36
+
37
+ export const GetInputSchema = z.object({
38
+ walletAddress: z.string().min(32),
39
+ packId: z.number(),
40
+ });
41
+
42
+ export const DeleteInputSchema = z.object({
43
+ walletAddress: z.string().min(32),
44
+ packId: z.number(),
45
+ });
46
+
47
+ export const GetByAddressInputSchema = z.object({
48
+ packAddress: z.string().min(32),
49
+ });
50
+
51
+ export const ClaimInputSchema = z.object({
52
+ packAddress: z.string().min(32),
53
+ walletAddress: z.string().min(32),
54
+ signature: z.string(),
55
+ expirationTs: z.string(),
56
+ });
57
+
58
+ export const InviteInputSchema = z.object({
59
+ packAddress: z.string().min(32),
60
+ walletAddress: z.string().min(32),
61
+ expirationDays: z.number().int().positive().max(365).default(7),
62
+ });
63
+
64
+ // ============================================================================
65
+ // Output Schemas
66
+ // ============================================================================
67
+
68
+ export const WelcomePackSchema = z.object({
69
+ address: z.string(),
70
+ id: z.number(),
71
+ owner: z.string(),
72
+ asset: z.string(),
73
+ lazyDistributor: z.string(),
74
+ rewardsMint: z.string(),
75
+ rentRefund: z.string(),
76
+ solAmount: z.string(),
77
+ rewardsSplit: z.array(RewardSplitInputSchema),
78
+ rewardsSchedule: z.string(),
79
+ assetReturnAddress: z.string(),
80
+ bumpSeed: z.number(),
81
+ uniqueId: z.string(),
82
+ loading: z.boolean().optional(),
83
+ hotspot: HotspotSchema.nullable(),
84
+ });
85
+
86
+ export const ListOutputSchema = z.array(WelcomePackSchema);
87
+
88
+ export const TransactionMetadataSchema = z
89
+ .object({
90
+ type: z.string(),
91
+ description: z.string(),
92
+ })
93
+ .catchall(z.unknown());
94
+
95
+ export const TransactionItemSchema = z.object({
96
+ serializedTransaction: z.string(),
97
+ metadata: TransactionMetadataSchema.optional(),
98
+ });
99
+
100
+ export const TransactionDataSchema = z.object({
101
+ transactions: z.array(TransactionItemSchema),
102
+ parallel: z.boolean(),
103
+ tag: z.string().optional(),
104
+ });
105
+
106
+ export const CreateOutputSchema = z.object({
107
+ welcomePack: WelcomePackSchema,
108
+ transactionData: TransactionDataSchema,
109
+ });
110
+
111
+ export const DeleteOutputSchema = z.object({
112
+ transactionData: TransactionDataSchema,
113
+ });
114
+
115
+ export const ClaimOutputSchema = z.object({
116
+ transactionData: TransactionDataSchema,
117
+ });
118
+
119
+ export const InviteOutputSchema = z.object({
120
+ message: z.string(),
121
+ expirationTs: z.number(),
122
+ });
123
+
124
+ // ============================================================================
125
+ // Type Exports
126
+ // ============================================================================
127
+
128
+ export type ListInput = z.infer<typeof ListInputSchema>;
129
+ export type CreateInput = z.infer<typeof CreateInputSchema>;
130
+ export type GetInput = z.infer<typeof GetInputSchema>;
131
+ export type DeleteInput = z.infer<typeof DeleteInputSchema>;
132
+ export type GetByAddressInput = z.infer<typeof GetByAddressInputSchema>;
133
+ export type ClaimInput = z.infer<typeof ClaimInputSchema>;
134
+ export type InviteInput = z.infer<typeof InviteInputSchema>;
135
+ export type WelcomePack = z.infer<typeof WelcomePackSchema>;
@@ -0,0 +1,281 @@
1
+ import { z } from "zod";
2
+
3
+ // ============================================================================
4
+ // Common Transaction Schemas
5
+ // ============================================================================
6
+
7
+ /**
8
+ * Metadata associated with a transaction for tracking and display purposes.
9
+ */
10
+ export const TransactionMetadataSchema = z
11
+ .object({
12
+ type: z.string(),
13
+ description: z.string(),
14
+ })
15
+ .catchall(z.unknown());
16
+
17
+ /**
18
+ * A single transaction item with serialized data and optional metadata.
19
+ */
20
+ export const TransactionItemSchema = z.object({
21
+ serializedTransaction: z.string(),
22
+ metadata: TransactionMetadataSchema.optional(),
23
+ });
24
+
25
+ /**
26
+ * Transaction data returned by procedures that create transactions.
27
+ * Contains serialized transactions ready for signing and submission.
28
+ */
29
+ export const TransactionDataSchema = z.object({
30
+ transactions: z.array(TransactionItemSchema),
31
+ parallel: z.boolean(),
32
+ tag: z.string().optional(),
33
+ });
34
+
35
+ /**
36
+ * Request schema for submitting a batch of transactions.
37
+ */
38
+ export const TransactionBatchRequestSchema = z.object({
39
+ transactions: z.array(TransactionItemSchema),
40
+ parallel: z.boolean(),
41
+ tag: z.string().optional(),
42
+ });
43
+
44
+ /**
45
+ * Response schema for transaction batch submission.
46
+ */
47
+ export const TransactionBatchResponseSchema = z.object({
48
+ batchId: z.string(),
49
+ message: z.string().optional(),
50
+ });
51
+
52
+ // ============================================================================
53
+ // Common Response Schemas
54
+ // ============================================================================
55
+
56
+ /**
57
+ * Standard error response schema.
58
+ */
59
+ export const ErrorResponseSchema = z.object({
60
+ error: z.string(),
61
+ details: z.array(z.string()).optional(),
62
+ });
63
+
64
+ // ============================================================================
65
+ // Wallet Address Schema
66
+ // ============================================================================
67
+
68
+ /**
69
+ * Solana wallet address validation.
70
+ */
71
+ export const WalletAddressSchema = z.string().min(32).max(44);
72
+
73
+ /**
74
+ * Solana public key validation (base58 encoded).
75
+ */
76
+ export const PublicKeySchema = z.string().min(32).max(44);
77
+
78
+ // ============================================================================
79
+ // Pagination Schemas
80
+ // ============================================================================
81
+
82
+ /**
83
+ * Standard pagination input schema.
84
+ */
85
+ export const PaginationInputSchema = z.object({
86
+ page: z.coerce.number().int().min(1).default(1),
87
+ limit: z.coerce.number().int().min(1).max(100).default(10),
88
+ });
89
+
90
+ /**
91
+ * Standard pagination output schema.
92
+ */
93
+ export const PaginationOutputSchema = z.object({
94
+ total: z.number(),
95
+ page: z.number(),
96
+ totalPages: z.number(),
97
+ });
98
+
99
+ // ============================================================================
100
+ // Hotspot Schemas
101
+ // ============================================================================
102
+
103
+ /**
104
+ * Hotspot type enumeration.
105
+ */
106
+ export const HotspotTypeSchema = z.enum(["iot", "mobile", "all"]);
107
+
108
+ /**
109
+ * Hotspot device type enumeration.
110
+ */
111
+ export const DeviceTypeSchema = z.enum([
112
+ "iot-gateway",
113
+ "wifiIndoor",
114
+ "wifiOutdoor",
115
+ "wifiDataOnly",
116
+ "cbrs",
117
+ ]);
118
+
119
+ /**
120
+ * Hotspot ownership type enumeration.
121
+ */
122
+ export const OwnershipTypeSchema = z.enum(["owner", "direct", "fanout", "all"]);
123
+
124
+ /**
125
+ * Hotspot share configuration.
126
+ */
127
+ export const HotspotSharesSchema = z.object({
128
+ fixed: z.string().optional(),
129
+ percentage: z.number().optional(),
130
+ });
131
+
132
+ /**
133
+ * Complete hotspot data schema.
134
+ */
135
+ export const HotspotSchema = z.object({
136
+ address: z.string(),
137
+ entityKey: z.string(),
138
+ name: z.string(),
139
+ type: HotspotTypeSchema,
140
+ deviceType: DeviceTypeSchema,
141
+ city: z.string().optional(),
142
+ state: z.string().optional(),
143
+ country: z.string().optional(),
144
+ asset: z.string(),
145
+ isOnline: z.boolean().optional(),
146
+ owner: z.string().optional(),
147
+ shares: HotspotSharesSchema.optional(),
148
+ ownershipType: z.string(),
149
+ });
150
+
151
+ /**
152
+ * Paginated hotspots response schema.
153
+ */
154
+ export const HotspotsDataSchema = z.object({
155
+ hotspots: z.array(HotspotSchema),
156
+ total: z.number(),
157
+ page: z.number(),
158
+ totalPages: z.number(),
159
+ });
160
+
161
+ // ============================================================================
162
+ // Token Schemas
163
+ // ============================================================================
164
+
165
+ /**
166
+ * Token account data schema.
167
+ */
168
+ export const TokenAccountSchema = z.object({
169
+ mint: z.string(),
170
+ address: z.string(),
171
+ balance: z.string(),
172
+ decimals: z.number(),
173
+ uiAmount: z.number(),
174
+ symbol: z.string().optional(),
175
+ name: z.string().optional(),
176
+ logoURI: z.string().optional(),
177
+ priceUsd: z.number().optional(),
178
+ balanceUsd: z.number().optional(),
179
+ });
180
+
181
+ /**
182
+ * Token balance data response schema.
183
+ */
184
+ export const TokenBalanceDataSchema = z.object({
185
+ totalBalanceUsd: z.number(),
186
+ solBalance: z.number(),
187
+ solBalanceUsd: z.number(),
188
+ tokens: z.array(TokenAccountSchema),
189
+ });
190
+
191
+ // ============================================================================
192
+ // Welcome Pack Schemas
193
+ // ============================================================================
194
+
195
+ /**
196
+ * Reward split recipient schema.
197
+ */
198
+ export const RewardSplitSchema = z.object({
199
+ address: z.string(),
200
+ type: z.enum(["percentage", "fixed"]),
201
+ amount: z.number(),
202
+ });
203
+
204
+ /**
205
+ * Schedule configuration schema.
206
+ */
207
+ export const ScheduleSchema = z.object({
208
+ frequency: z.enum(["daily", "weekly", "monthly"]),
209
+ time: z.string(),
210
+ timezone: z.string(),
211
+ dayOfWeek: z.string().optional(),
212
+ dayOfMonth: z.string().optional(),
213
+ });
214
+
215
+ /**
216
+ * Welcome pack with status schema.
217
+ */
218
+ export const WelcomePackWithStatusSchema = z.object({
219
+ address: z.string(),
220
+ id: z.number(),
221
+ owner: z.string(),
222
+ asset: z.string(),
223
+ lazyDistributor: z.string(),
224
+ rewardsMint: z.string(),
225
+ rentRefund: z.string(),
226
+ solAmount: z.string(),
227
+ rewardsSplit: z.array(RewardSplitSchema),
228
+ rewardsSchedule: z.string(),
229
+ assetReturnAddress: z.string(),
230
+ bumpSeed: z.number(),
231
+ uniqueId: z.string(),
232
+ loading: z.boolean().optional(),
233
+ });
234
+
235
+ // ============================================================================
236
+ // Split Schemas
237
+ // ============================================================================
238
+
239
+ /**
240
+ * Split share schema.
241
+ */
242
+ export const SplitShareSchema = z.object({
243
+ wallet: z.string(),
244
+ delegate: z.string(),
245
+ fixed: z.number(),
246
+ shares: z.number(),
247
+ });
248
+
249
+ /**
250
+ * Split response schema.
251
+ */
252
+ export const SplitResponseSchema = z.object({
253
+ walletAddress: z.string(),
254
+ hotspotPubkey: z.string(),
255
+ splitAddress: z.string(),
256
+ shares: z.array(SplitShareSchema),
257
+ });
258
+
259
+ // ============================================================================
260
+ // Type Exports
261
+ // ============================================================================
262
+
263
+ export type TransactionMetadata = z.infer<typeof TransactionMetadataSchema>;
264
+ export type TransactionItem = z.infer<typeof TransactionItemSchema>;
265
+ export type TransactionData = z.infer<typeof TransactionDataSchema>;
266
+ export type TransactionBatchRequest = z.infer<
267
+ typeof TransactionBatchRequestSchema
268
+ >;
269
+ export type TransactionBatchResponse = z.infer<
270
+ typeof TransactionBatchResponseSchema
271
+ >;
272
+ export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
273
+ export type Hotspot = z.infer<typeof HotspotSchema>;
274
+ export type HotspotsData = z.infer<typeof HotspotsDataSchema>;
275
+ export type TokenAccount = z.infer<typeof TokenAccountSchema>;
276
+ export type TokenBalanceData = z.infer<typeof TokenBalanceDataSchema>;
277
+ export type RewardSplit = z.infer<typeof RewardSplitSchema>;
278
+ export type Schedule = z.infer<typeof ScheduleSchema>;
279
+ export type WelcomePackWithStatus = z.infer<typeof WelcomePackWithStatusSchema>;
280
+ export type SplitShare = z.infer<typeof SplitShareSchema>;
281
+ export type SplitResponse = z.infer<typeof SplitResponseSchema>;
package/tsconfig.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": [
5
+ "dom",
6
+ "dom.iterable",
7
+ "esnext"
8
+ ],
9
+ "allowJs": true,
10
+ "skipLibCheck": true,
11
+ "strict": true,
12
+ "noEmit": true,
13
+ "esModuleInterop": true,
14
+ "module": "esnext",
15
+ "moduleResolution": "bundler",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "jsx": "react-jsx",
19
+ "incremental": true,
20
+ "sourceMap": true,
21
+ "inlineSourceMap": false,
22
+ "inlineSources": true,
23
+ "plugins": [
24
+ {
25
+ "name": "next"
26
+ }
27
+ ],
28
+ "paths": {
29
+ "@/*": [
30
+ "./src/*"
31
+ ]
32
+ }
33
+ },
34
+ "include": [
35
+ "next-env.d.ts",
36
+ "**/*.ts",
37
+ "**/*.tsx",
38
+ ".next/types/**/*.ts",
39
+ ".next/dev/types/**/*.ts",
40
+ ".next/dev/dev/types/**/*.ts"
41
+ ],
42
+ "exclude": [
43
+ "node_modules"
44
+ ]
45
+ }
package/types/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Type exports for @helium/blockchain-api
3
+ *
4
+ * This module exports the ORPC router types that can be used by external packages
5
+ * to get full type safety when working with the blockchain API.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import type { BlockchainAPIClient, ORPCRouter } from "@helium/blockchain-api"
10
+ * import { createORPCClient } from "@orpc/client"
11
+ *
12
+ * const client: BlockchainAPIClient = createORPCClient(link)
13
+ * ```
14
+ */
15
+
16
+ import { RouterClient } from "@orpc/server";
17
+
18
+ // Re-export the router type
19
+ export type { ORPCRouter } from "../src/server/api";
20
+
21
+ // Re-export RouterClient type for convenience
22
+ export type { RouterClient } from "@orpc/server";
23
+
24
+ // Export a helper type for creating typed clients
25
+ export type BlockchainAPIClient = RouterClient<
26
+ import("../src/server/api").ORPCRouter
27
+ >;