@basedone/core 0.2.7 → 0.3.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 (41) hide show
  1. package/dist/{chunk-L63E7FZC.mjs → chunk-35WGIB5F.mjs} +165 -1
  2. package/dist/{client-CgmiTuEX.d.mts → client-BQzYwHDY.d.mts} +5 -2
  3. package/dist/{client-CgmiTuEX.d.ts → client-BQzYwHDY.d.ts} +5 -2
  4. package/dist/ecommerce.d.mts +195 -2
  5. package/dist/ecommerce.d.ts +195 -2
  6. package/dist/ecommerce.js +176 -0
  7. package/dist/ecommerce.mjs +1 -2
  8. package/dist/index.d.mts +114 -160
  9. package/dist/index.d.ts +114 -160
  10. package/dist/index.js +462 -41454
  11. package/dist/index.mjs +246 -639
  12. package/dist/react.d.mts +1 -1
  13. package/dist/react.d.ts +1 -1
  14. package/dist/react.mjs +0 -1
  15. package/index.ts +3 -0
  16. package/lib/abstraction/api.ts +106 -0
  17. package/lib/abstraction/index.ts +3 -0
  18. package/lib/abstraction/ratio.ts +61 -0
  19. package/lib/abstraction/types.ts +73 -0
  20. package/lib/constants/admin.ts +30 -0
  21. package/lib/ecommerce/client/customer.ts +42 -0
  22. package/lib/ecommerce/index.ts +14 -0
  23. package/lib/ecommerce/types/entities.ts +70 -0
  24. package/lib/ecommerce/types/enums.ts +37 -1
  25. package/lib/ecommerce/types/requests.ts +2 -0
  26. package/lib/ecommerce/types/responses.ts +28 -0
  27. package/lib/ecommerce/utils/orderStateMachine.ts +197 -0
  28. package/lib/hip3/market-info.ts +5 -1
  29. package/lib/hip3/utils.ts +2 -0
  30. package/lib/meta/metadata.ts +0 -666
  31. package/lib/types.ts +29 -0
  32. package/package.json +1 -1
  33. package/dist/chunk-4UEJOM6W.mjs +0 -7
  34. package/dist/meta-JB5ITE27.mjs +0 -1390
  35. package/dist/meta-UOGUG3OW.mjs +0 -1504
  36. package/dist/perpDexs-3LRJ5ZHM.mjs +0 -288
  37. package/dist/perpDexs-4ISLD7NX.mjs +0 -2975
  38. package/dist/spotMeta-GHXX7C5M.mjs +0 -6968
  39. package/dist/spotMeta-IBBUP2SG.mjs +0 -27592
  40. package/dist/staticMeta-GM7T3OYL.mjs +0 -20
  41. package/dist/staticMeta-QV2KMX57.mjs +0 -22
@@ -0,0 +1,197 @@
1
+ import { OrderStatus } from "../types/enums";
2
+
3
+ /** Detect pickup / on-site-collection shipping methods (normalised matching) */
4
+ export function isPickupOrder(
5
+ shippingMethod?: string | null,
6
+ shippingRateId?: string | null
7
+ ): boolean {
8
+ // Primary check: shippingRateId === "PICKUP" (from mobile app)
9
+ if (shippingRateId && shippingRateId.trim().toUpperCase() === "PICKUP") {
10
+ return true;
11
+ }
12
+
13
+ if (!shippingMethod) return false;
14
+ const normalized = shippingMethod
15
+ .trim()
16
+ .toLowerCase()
17
+ .replace(/[\s-]+/g, " ");
18
+ return (
19
+ normalized === "pickup" ||
20
+ normalized === "on site collection" ||
21
+ normalized === "onsite collection"
22
+ );
23
+ }
24
+
25
+ /**
26
+ * Canonical order status transitions.
27
+ *
28
+ * Buyer-protected escrow flow:
29
+ * CREATED → PAYMENT_RESERVED → MERCHANT_ACCEPTED → SHIPPED → DELIVERED → SETTLED
30
+ *
31
+ * Cancellation is allowed from any non-terminal state except DELIVERED (already in settlement).
32
+ */
33
+ export const ORDER_STATUS_TRANSITIONS: Partial<Record<OrderStatus, OrderStatus[]>> = {
34
+ [OrderStatus.CREATED]: [
35
+ OrderStatus.PAYMENT_RESERVED,
36
+ OrderStatus.MERCHANT_ACCEPTED,
37
+ OrderStatus.CANCELLED,
38
+ ],
39
+ [OrderStatus.PAYMENT_RESERVED]: [
40
+ OrderStatus.MERCHANT_ACCEPTED,
41
+ OrderStatus.CANCELLED,
42
+ ],
43
+ [OrderStatus.MERCHANT_ACCEPTED]: [
44
+ OrderStatus.SHIPPED,
45
+ OrderStatus.CANCELLED,
46
+ ],
47
+ // Backward compat for existing SETTLED orders created before escrow change
48
+ // Note: CANCELLED removed — settled orders have funds paid out, no clawback mechanism
49
+ [OrderStatus.SETTLED]: [OrderStatus.SHIPPED],
50
+ [OrderStatus.SHIPPED]: [OrderStatus.DELIVERED, OrderStatus.CANCELLED],
51
+ // Settlement triggered on delivery (buyer-protected escrow)
52
+ [OrderStatus.DELIVERED]: [OrderStatus.SETTLED],
53
+ // Terminal states
54
+ [OrderStatus.CANCELLED]: [],
55
+ };
56
+
57
+ /**
58
+ * Validate whether transitioning from `currentStatus` to `newStatus` is allowed.
59
+ *
60
+ * For pickup / on-site-collection orders, MERCHANT_ACCEPTED → DELIVERED and
61
+ * SETTLED → DELIVERED are permitted (skipping SHIPPED).
62
+ */
63
+ export function validateStatusTransition(
64
+ currentStatus: string,
65
+ newStatus: string,
66
+ options?: {
67
+ shippingMethod?: string | null;
68
+ shippingRateId?: string | null;
69
+ }
70
+ ): { valid: boolean; error?: string } {
71
+ // Pickup orders can skip SHIPPED and go directly to DELIVERED
72
+ if (
73
+ isPickupOrder(options?.shippingMethod, options?.shippingRateId) &&
74
+ (currentStatus === OrderStatus.MERCHANT_ACCEPTED ||
75
+ currentStatus === OrderStatus.SETTLED) &&
76
+ newStatus === OrderStatus.DELIVERED
77
+ ) {
78
+ return { valid: true };
79
+ }
80
+
81
+ const allowed =
82
+ ORDER_STATUS_TRANSITIONS[currentStatus as OrderStatus] ?? [];
83
+ if (!allowed.includes(newStatus as OrderStatus)) {
84
+ if (allowed.length === 0) {
85
+ return {
86
+ valid: false,
87
+ error: `Cannot change status from ${currentStatus} — this is a final state`,
88
+ };
89
+ }
90
+ return {
91
+ valid: false,
92
+ error: `Cannot transition from ${currentStatus} to ${newStatus}. Allowed: ${allowed.join(", ")}`,
93
+ };
94
+ }
95
+
96
+ return { valid: true };
97
+ }
98
+
99
+ /**
100
+ * Return the list of statuses reachable from `currentStatus`.
101
+ * For pickup orders, DELIVERED is added when on MERCHANT_ACCEPTED or SETTLED.
102
+ */
103
+ export function getNextStatuses(
104
+ currentStatus: string,
105
+ options?: {
106
+ shippingMethod?: string | null;
107
+ shippingRateId?: string | null;
108
+ }
109
+ ): string[] {
110
+ const base = [
111
+ ...(ORDER_STATUS_TRANSITIONS[currentStatus as OrderStatus] ?? []),
112
+ ];
113
+
114
+ if (
115
+ isPickupOrder(options?.shippingMethod, options?.shippingRateId) &&
116
+ (currentStatus === OrderStatus.MERCHANT_ACCEPTED ||
117
+ currentStatus === OrderStatus.SETTLED) &&
118
+ !base.includes(OrderStatus.DELIVERED)
119
+ ) {
120
+ base.push(OrderStatus.DELIVERED);
121
+ }
122
+
123
+ return base;
124
+ }
125
+
126
+ /** Human-readable label for a status. */
127
+ export function getStatusLabel(status: string): string {
128
+ const labels: Record<string, string> = {
129
+ CREATED: "Created",
130
+ PAYMENT_RESERVED: "Payment Reserved",
131
+ MERCHANT_ACCEPTED: "Accepted",
132
+ SETTLED: "Completed (Paid)",
133
+ SHIPPED: "Shipped",
134
+ DELIVERED: "Delivered",
135
+ CANCELLED: "Cancelled",
136
+ };
137
+ return labels[status] || status;
138
+ }
139
+
140
+ /** UI colour key for a status. */
141
+ export function getStatusColor(status: string): string {
142
+ const colors: Record<string, string> = {
143
+ CREATED: "gray",
144
+ PAYMENT_RESERVED: "blue",
145
+ MERCHANT_ACCEPTED: "purple",
146
+ SETTLED: "indigo",
147
+ SHIPPED: "yellow",
148
+ DELIVERED: "green",
149
+ CANCELLED: "red",
150
+ };
151
+ return colors[status] || "gray";
152
+ }
153
+
154
+ /** Whether the order can be cancelled from its current status. */
155
+ export function canCancelOrder(currentStatus: string): boolean {
156
+ return (
157
+ ORDER_STATUS_TRANSITIONS[currentStatus as OrderStatus]?.includes(
158
+ OrderStatus.CANCELLED
159
+ ) ?? false
160
+ );
161
+ }
162
+
163
+ /** Whether tracking info is required for a status change. */
164
+ export function requiresTrackingInfo(
165
+ newStatus: string,
166
+ options?: {
167
+ shippingMethod?: string | null;
168
+ shippingRateId?: string | null;
169
+ }
170
+ ): boolean {
171
+ if (newStatus !== OrderStatus.SHIPPED) return false;
172
+ return !isPickupOrder(options?.shippingMethod, options?.shippingRateId);
173
+ }
174
+
175
+ /** Whether a status change should trigger customer notification. */
176
+ export function shouldNotifyCustomer(newStatus: string): boolean {
177
+ return [
178
+ OrderStatus.MERCHANT_ACCEPTED,
179
+ OrderStatus.SHIPPED,
180
+ OrderStatus.DELIVERED,
181
+ OrderStatus.CANCELLED,
182
+ ].includes(newStatus as OrderStatus);
183
+ }
184
+
185
+ /** Status progression percentage (for progress bars). */
186
+ export function getStatusProgress(status: string): number {
187
+ const progressMap: Record<string, number> = {
188
+ CREATED: 10,
189
+ PAYMENT_RESERVED: 25,
190
+ MERCHANT_ACCEPTED: 40,
191
+ SETTLED: 50,
192
+ SHIPPED: 75,
193
+ DELIVERED: 100,
194
+ CANCELLED: 0,
195
+ };
196
+ return progressMap[status] || 0;
197
+ }
@@ -1,4 +1,4 @@
1
- import { InfoClient, PerpsAssetCtx, MarginTables } from "@nktkas/hyperliquid";
1
+ import { InfoClient, PerpsAssetCtx, MarginTables, PerpDex as LegacyPerpDex } from "@nktkas/hyperliquid";
2
2
 
3
3
  export interface PerpsMeta {
4
4
  collateralToken: number;
@@ -34,6 +34,10 @@ export interface PerpsUniverse {
34
34
  marginMode?: "strictIsolated" | "noCross";
35
35
  }
36
36
 
37
+ export interface PerpDex extends LegacyPerpDex {
38
+ deployerFeeScale: string;
39
+ }
40
+
37
41
  export type AllPerpsMeta = PerpsMeta[];
38
42
 
39
43
  export async function getAllPerpsMeta(
package/lib/hip3/utils.ts CHANGED
@@ -102,6 +102,8 @@ const dexToCollateralTokenSymbol = {
102
102
  hyna: "USDE",
103
103
  flx: "USDH",
104
104
  vntl: "USDH",
105
+ km: "USDH",
106
+ cash: "USDT0",
105
107
  };
106
108
 
107
109
  export const isSpotSymbol = (coin: string | undefined) => {