@basedone/core 0.2.8 → 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.
package/dist/index.js CHANGED
@@ -550,6 +550,39 @@ var TESTNET_USDC_SPOT_TOKEN = {
550
550
  deployerTradingFeeShare: "0.0"
551
551
  };
552
552
 
553
+ // lib/constants/admin.ts
554
+ var ADMINS = [
555
+ "did:privy:cmc3hycnb00pljs0m1z010geq",
556
+ "did:privy:cmc8w2ddl01rdju0nylb6rp1v",
557
+ "did:privy:cmc3oftiz005fjx0msox3xgey",
558
+ "did:privy:cmcbx7i4400q8l90mawdymaag",
559
+ "did:privy:cmctbwphs00vzjz0m3la3zm4c",
560
+ "did:privy:cmcblrplb009ol70mia13winn",
561
+ "did:privy:cmcmizpxm02xfju0oc81alfy0",
562
+ "did:privy:cmcd2bvft00w3l90ljeyb4wn6",
563
+ "did:privy:cmc4y13ka0119kv0nckvgla1u",
564
+ "did:privy:cmc8qc36g00c1l70nnutuscue",
565
+ "did:privy:cmc8f1tf9019zlh0myjpi420p",
566
+ "did:privy:cmc6bturg002ql80mhzqr1d76",
567
+ "did:privy:cmc8uyr4t01kljo0mk3unzjl3",
568
+ "did:privy:cmcke9v7h00yijy0o2a41nhms",
569
+ "did:privy:cmgfcjt2y0024kz0cpymoqbmp",
570
+ "did:privy:cmeqj8tsi01k6la0c3s7gsl6w",
571
+ // elroy
572
+ "did:privy:cmiwrno1i00cdl70c5ro13eyp",
573
+ // adele
574
+ "did:privy:cmkc0jyy200abji0d42a0syil",
575
+ // matthew
576
+ "did:privy:cmlgc2zjk005vjo0cct10trdl"
577
+ // adele
578
+ ];
579
+ var ADMIN_WALLETS = [
580
+ "0x0c7582A67B8B6AD04Ea404A6C2A06aAc9E0d4e7c",
581
+ "0xDec587aDD20A6447fF0b29D70E95b10b197b1283",
582
+ "0x3e83987019c4CE29680401b72F8b18A2dE3f8fe6",
583
+ "0x5446A5Bc711170d5197DE33D8C193487794f30C0"
584
+ ];
585
+
553
586
  // lib/meta/metadata.ts
554
587
  var ROOT_DEX = "hyperliquid";
555
588
  var formatPriceAndSize = ({
@@ -792,6 +825,105 @@ async function getAllPerpsMeta(infoClient) {
792
825
  });
793
826
  }
794
827
 
828
+ // lib/abstraction/types.ts
829
+ var ABSTRACTION_MODE_TO_AGENT_CODE = {
830
+ disabled: "i",
831
+ unifiedAccount: "u",
832
+ portfolioMargin: "p"
833
+ };
834
+ var AGENT_CODE_TO_ABSTRACTION_MODE = {
835
+ i: "disabled",
836
+ u: "unifiedAccount",
837
+ p: "portfolioMargin"
838
+ };
839
+ var UserSetAbstractionTypes = {
840
+ "HyperliquidTransaction:UserSetAbstraction": [
841
+ { name: "hyperliquidChain", type: "string" },
842
+ { name: "user", type: "address" },
843
+ { name: "abstraction", type: "string" },
844
+ { name: "nonce", type: "uint64" }
845
+ ]
846
+ };
847
+ async function getUserAbstraction(client, user) {
848
+ return await client.transport.request("info", {
849
+ type: "userAbstraction",
850
+ user
851
+ });
852
+ }
853
+ async function setUserAbstraction(client, abstraction, user) {
854
+ const nonce = Date.now();
855
+ const isTestnet = client.isTestnet;
856
+ const action = {
857
+ type: "userSetAbstraction",
858
+ hyperliquidChain: isTestnet ? "Testnet" : "Mainnet",
859
+ signatureChainId: isTestnet ? "0x66eee" : "0xa4b1",
860
+ user,
861
+ abstraction,
862
+ nonce
863
+ };
864
+ const signature = await signing.signUserSignedAction({
865
+ wallet: client.wallet,
866
+ action,
867
+ types: UserSetAbstractionTypes
868
+ });
869
+ return await client.transport.request("exchange", {
870
+ action,
871
+ signature,
872
+ nonce: action.nonce
873
+ });
874
+ }
875
+ async function agentSetAbstraction(client, abstraction) {
876
+ const nonce = Date.now();
877
+ const code = ABSTRACTION_MODE_TO_AGENT_CODE[abstraction];
878
+ const action = {
879
+ type: "agentSetAbstraction",
880
+ abstraction: code
881
+ };
882
+ const signature = await signing.signL1Action({
883
+ wallet: client.wallet,
884
+ action,
885
+ isTestnet: client.isTestnet,
886
+ nonce
887
+ });
888
+ return await client.transport.request("exchange", {
889
+ action,
890
+ signature,
891
+ nonce
892
+ });
893
+ }
894
+
895
+ // lib/abstraction/ratio.ts
896
+ function computeUnifiedAccountRatio(multiverse, perpDexStates, spotBalances) {
897
+ const indexToCollateralToken = {};
898
+ for (const meta of Object.values(multiverse)) {
899
+ indexToCollateralToken[meta.index] = meta.collateralToken;
900
+ }
901
+ const crossMarginByToken = {};
902
+ const isolatedMarginByToken = {};
903
+ for (let index = 0; index < perpDexStates.length; index++) {
904
+ const dex = perpDexStates[index];
905
+ const token = indexToCollateralToken[index];
906
+ if (dex === void 0 || token === void 0) continue;
907
+ crossMarginByToken[token] = (crossMarginByToken[token] ?? 0) + dex.clearinghouseState.crossMaintenanceMarginUsed;
908
+ for (const ap of dex.clearinghouseState.assetPositions) {
909
+ if (ap.position.leverage.type === "isolated") {
910
+ isolatedMarginByToken[token] = (isolatedMarginByToken[token] ?? 0) + ap.position.marginUsed;
911
+ }
912
+ }
913
+ }
914
+ let maxRatio = 0;
915
+ for (const [tokenStr, crossMargin] of Object.entries(crossMarginByToken)) {
916
+ const token = Number(tokenStr);
917
+ const spotTotal = spotBalances.find((b) => b.token === token)?.total ?? 0;
918
+ const isolatedMargin = isolatedMarginByToken[token] ?? 0;
919
+ const available = spotTotal - isolatedMargin;
920
+ if (available > 0) {
921
+ maxRatio = Math.max(maxRatio, crossMargin / available);
922
+ }
923
+ }
924
+ return maxRatio;
925
+ }
926
+
795
927
  // lib/instrument/client.ts
796
928
  var AssetIdUtils = {
797
929
  /**
@@ -2248,6 +2380,38 @@ var CustomerEcommerceClient = class extends BaseEcommerceClient {
2248
2380
  async getDeliveryAddress() {
2249
2381
  return this.get("/api/basedpay/delivery-address");
2250
2382
  }
2383
+ /**
2384
+ * Get user's Hyperliquid USDC balance (perp withdrawable)
2385
+ *
2386
+ * Returns the USDC balance available for escrow deposits via usdSend.
2387
+ *
2388
+ * @returns Balance response with amount and currency
2389
+ */
2390
+ async getUsdcBalance() {
2391
+ return this.get("/api/marketplace/usdc-balance");
2392
+ }
2393
+ // ============================================================================
2394
+ // Notifications API
2395
+ // ============================================================================
2396
+ /**
2397
+ * List notifications for the authenticated customer
2398
+ *
2399
+ * @param params - Query parameters for filtering and pagination
2400
+ * @returns Paginated list of notifications with unread count
2401
+ */
2402
+ async listNotifications(params) {
2403
+ const queryString = params ? buildQueryString(params) : "";
2404
+ return this.get(`/api/marketplace/notifications${queryString}`);
2405
+ }
2406
+ /**
2407
+ * Mark notifications as read
2408
+ *
2409
+ * @param ids - Specific notification IDs to mark as read. If omitted, marks all as read.
2410
+ * @returns Count of updated notifications
2411
+ */
2412
+ async markNotificationsAsRead(ids) {
2413
+ return this.patch("/api/marketplace/notifications/read", { ids });
2414
+ }
2251
2415
  };
2252
2416
 
2253
2417
  // lib/ecommerce/client/merchant.ts
@@ -3793,6 +3957,7 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
3793
3957
  OrderStatus2["SHIPPED"] = "SHIPPED";
3794
3958
  OrderStatus2["DELIVERED"] = "DELIVERED";
3795
3959
  OrderStatus2["CANCELLED"] = "CANCELLED";
3960
+ OrderStatus2["SETTLED"] = "SETTLED";
3796
3961
  OrderStatus2["CONFIRMED"] = "CONFIRMED";
3797
3962
  OrderStatus2["COMPLETED"] = "COMPLETED";
3798
3963
  return OrderStatus2;
@@ -3926,6 +4091,7 @@ var ProductSortBy = /* @__PURE__ */ ((ProductSortBy2) => {
3926
4091
  ProductSortBy2["PRICE_ASC"] = "price_asc";
3927
4092
  ProductSortBy2["PRICE_DESC"] = "price_desc";
3928
4093
  ProductSortBy2["POPULAR"] = "popular";
4094
+ ProductSortBy2["BEST_SELLING"] = "best_selling";
3929
4095
  ProductSortBy2["FEATURED"] = "featured";
3930
4096
  ProductSortBy2["NEARBY"] = "nearby";
3931
4097
  return ProductSortBy2;
@@ -3937,6 +4103,124 @@ var ReviewSortBy = /* @__PURE__ */ ((ReviewSortBy2) => {
3937
4103
  return ReviewSortBy2;
3938
4104
  })(ReviewSortBy || {});
3939
4105
 
4106
+ // lib/ecommerce/utils/orderStateMachine.ts
4107
+ function isPickupOrder(shippingMethod, shippingRateId) {
4108
+ if (shippingRateId && shippingRateId.trim().toUpperCase() === "PICKUP") {
4109
+ return true;
4110
+ }
4111
+ if (!shippingMethod) return false;
4112
+ const normalized = shippingMethod.trim().toLowerCase().replace(/[\s-]+/g, " ");
4113
+ return normalized === "pickup" || normalized === "on site collection" || normalized === "onsite collection";
4114
+ }
4115
+ var ORDER_STATUS_TRANSITIONS = {
4116
+ ["CREATED" /* CREATED */]: [
4117
+ "PAYMENT_RESERVED" /* PAYMENT_RESERVED */,
4118
+ "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */,
4119
+ "CANCELLED" /* CANCELLED */
4120
+ ],
4121
+ ["PAYMENT_RESERVED" /* PAYMENT_RESERVED */]: [
4122
+ "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */,
4123
+ "CANCELLED" /* CANCELLED */
4124
+ ],
4125
+ ["MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */]: [
4126
+ "SHIPPED" /* SHIPPED */,
4127
+ "CANCELLED" /* CANCELLED */
4128
+ ],
4129
+ // Backward compat for existing SETTLED orders created before escrow change
4130
+ // Note: CANCELLED removed — settled orders have funds paid out, no clawback mechanism
4131
+ ["SETTLED" /* SETTLED */]: ["SHIPPED" /* SHIPPED */],
4132
+ ["SHIPPED" /* SHIPPED */]: ["DELIVERED" /* DELIVERED */, "CANCELLED" /* CANCELLED */],
4133
+ // Settlement triggered on delivery (buyer-protected escrow)
4134
+ ["DELIVERED" /* DELIVERED */]: ["SETTLED" /* SETTLED */],
4135
+ // Terminal states
4136
+ ["CANCELLED" /* CANCELLED */]: []
4137
+ };
4138
+ function validateStatusTransition(currentStatus, newStatus, options) {
4139
+ if (isPickupOrder(options?.shippingMethod, options?.shippingRateId) && (currentStatus === "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */ || currentStatus === "SETTLED" /* SETTLED */) && newStatus === "DELIVERED" /* DELIVERED */) {
4140
+ return { valid: true };
4141
+ }
4142
+ const allowed = ORDER_STATUS_TRANSITIONS[currentStatus] ?? [];
4143
+ if (!allowed.includes(newStatus)) {
4144
+ if (allowed.length === 0) {
4145
+ return {
4146
+ valid: false,
4147
+ error: `Cannot change status from ${currentStatus} \u2014 this is a final state`
4148
+ };
4149
+ }
4150
+ return {
4151
+ valid: false,
4152
+ error: `Cannot transition from ${currentStatus} to ${newStatus}. Allowed: ${allowed.join(", ")}`
4153
+ };
4154
+ }
4155
+ return { valid: true };
4156
+ }
4157
+ function getNextStatuses(currentStatus, options) {
4158
+ const base = [
4159
+ ...ORDER_STATUS_TRANSITIONS[currentStatus] ?? []
4160
+ ];
4161
+ if (isPickupOrder(options?.shippingMethod, options?.shippingRateId) && (currentStatus === "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */ || currentStatus === "SETTLED" /* SETTLED */) && !base.includes("DELIVERED" /* DELIVERED */)) {
4162
+ base.push("DELIVERED" /* DELIVERED */);
4163
+ }
4164
+ return base;
4165
+ }
4166
+ function getStatusLabel(status) {
4167
+ const labels = {
4168
+ CREATED: "Created",
4169
+ PAYMENT_RESERVED: "Payment Reserved",
4170
+ MERCHANT_ACCEPTED: "Accepted",
4171
+ SETTLED: "Completed (Paid)",
4172
+ SHIPPED: "Shipped",
4173
+ DELIVERED: "Delivered",
4174
+ CANCELLED: "Cancelled"
4175
+ };
4176
+ return labels[status] || status;
4177
+ }
4178
+ function getStatusColor(status) {
4179
+ const colors = {
4180
+ CREATED: "gray",
4181
+ PAYMENT_RESERVED: "blue",
4182
+ MERCHANT_ACCEPTED: "purple",
4183
+ SETTLED: "indigo",
4184
+ SHIPPED: "yellow",
4185
+ DELIVERED: "green",
4186
+ CANCELLED: "red"
4187
+ };
4188
+ return colors[status] || "gray";
4189
+ }
4190
+ function canCancelOrder(currentStatus) {
4191
+ return ORDER_STATUS_TRANSITIONS[currentStatus]?.includes(
4192
+ "CANCELLED" /* CANCELLED */
4193
+ ) ?? false;
4194
+ }
4195
+ function requiresTrackingInfo(newStatus, options) {
4196
+ if (newStatus !== "SHIPPED" /* SHIPPED */) return false;
4197
+ return !isPickupOrder(options?.shippingMethod, options?.shippingRateId);
4198
+ }
4199
+ function shouldNotifyCustomer(newStatus) {
4200
+ return [
4201
+ "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */,
4202
+ "SHIPPED" /* SHIPPED */,
4203
+ "DELIVERED" /* DELIVERED */,
4204
+ "CANCELLED" /* CANCELLED */
4205
+ ].includes(newStatus);
4206
+ }
4207
+ function getStatusProgress(status) {
4208
+ const progressMap = {
4209
+ CREATED: 10,
4210
+ PAYMENT_RESERVED: 25,
4211
+ MERCHANT_ACCEPTED: 40,
4212
+ SETTLED: 50,
4213
+ SHIPPED: 75,
4214
+ DELIVERED: 100,
4215
+ CANCELLED: 0
4216
+ };
4217
+ return progressMap[status] || 0;
4218
+ }
4219
+
4220
+ exports.ABSTRACTION_MODE_TO_AGENT_CODE = ABSTRACTION_MODE_TO_AGENT_CODE;
4221
+ exports.ADMINS = ADMINS;
4222
+ exports.ADMIN_WALLETS = ADMIN_WALLETS;
4223
+ exports.AGENT_CODE_TO_ABSTRACTION_MODE = AGENT_CODE_TO_ABSTRACTION_MODE;
3940
4224
  exports.AssetIdUtils = AssetIdUtils;
3941
4225
  exports.BannerType = BannerType;
3942
4226
  exports.BaseEcommerceClient = BaseEcommerceClient;
@@ -3954,6 +4238,7 @@ exports.MerchantBusinessType = MerchantBusinessType;
3954
4238
  exports.MerchantEcommerceClient = MerchantEcommerceClient;
3955
4239
  exports.MerchantReturnPolicyType = MerchantReturnPolicyType;
3956
4240
  exports.MerchantStatus = MerchantStatus;
4241
+ exports.ORDER_STATUS_TRANSITIONS = ORDER_STATUS_TRANSITIONS;
3957
4242
  exports.OrderStatus = OrderStatus;
3958
4243
  exports.PUP_TOKEN_ADDRESS = PUP_TOKEN_ADDRESS;
3959
4244
  exports.PUP_TOKEN_THRESHOLDS = PUP_TOKEN_THRESHOLDS;
@@ -3975,15 +4260,19 @@ exports.TaxReportStatus = TaxReportStatus;
3975
4260
  exports.TaxType = TaxType;
3976
4261
  exports.USDC_SPOT_TOKEN = USDC_SPOT_TOKEN;
3977
4262
  exports.UserDexAbstractionTypes = UserDexAbstractionTypes;
4263
+ exports.UserSetAbstractionTypes = UserSetAbstractionTypes;
3978
4264
  exports.WidgetType = WidgetType;
3979
4265
  exports.WidgetTypeById = WidgetTypeById;
3980
4266
  exports.XP_BOOST_PERCENTAGES = XP_BOOST_PERCENTAGES;
4267
+ exports.agentSetAbstraction = agentSetAbstraction;
3981
4268
  exports.buildCloid = buildCloid;
3982
4269
  exports.buildQueryString = buildQueryString;
3983
4270
  exports.calculateBoostPercentage = calculateBoostPercentage;
3984
4271
  exports.calculateDiscountAmount = calculateDiscountAmount;
3985
4272
  exports.calculateFinalPrice = calculateFinalPrice;
3986
4273
  exports.calculateTotalPupAmount = calculateTotalPupAmount;
4274
+ exports.canCancelOrder = canCancelOrder;
4275
+ exports.computeUnifiedAccountRatio = computeUnifiedAccountRatio;
3987
4276
  exports.decodeSlug = decodeSlug;
3988
4277
  exports.enableHip3DexAbstractionWithAgent = enableHip3DexAbstractionWithAgent;
3989
4278
  exports.encodeSlug = encodeSlug;
@@ -4007,10 +4296,15 @@ exports.getDisplayMarketSymbol = getDisplayMarketSymbol;
4007
4296
  exports.getHip3Dex = getHip3Dex;
4008
4297
  exports.getHip3DexAbstraction = getHip3DexAbstraction;
4009
4298
  exports.getLatestCompletedWeek = getLatestCompletedWeek;
4299
+ exports.getNextStatuses = getNextStatuses;
4010
4300
  exports.getNextTierInfo = getNextTierInfo;
4011
4301
  exports.getPriceDecimals = getPriceDecimals;
4012
4302
  exports.getStaticCollateralTokenByDex = getStaticCollateralTokenByDex;
4013
4303
  exports.getStaticCollateralTokenSymbol = getStaticCollateralTokenSymbol;
4304
+ exports.getStatusColor = getStatusColor;
4305
+ exports.getStatusLabel = getStatusLabel;
4306
+ exports.getStatusProgress = getStatusProgress;
4307
+ exports.getUserAbstraction = getUserAbstraction;
4014
4308
  exports.getWeekInfoFromNumber = getWeekInfoFromNumber;
4015
4309
  exports.getWidgetTypeById = getWidgetTypeById;
4016
4310
  exports.isBasedCloid = isBasedCloid;
@@ -4018,6 +4312,7 @@ exports.isClientCode = isClientCode;
4018
4312
  exports.isHip3Symbol = isHip3Symbol;
4019
4313
  exports.isMiniAppCloid = isMiniAppCloid;
4020
4314
  exports.isMiniAppTriggeredCloid = isMiniAppTriggeredCloid;
4315
+ exports.isPickupOrder = isPickupOrder;
4021
4316
  exports.isRetryableError = isRetryableError;
4022
4317
  exports.isSpotSymbol = isSpotSymbol;
4023
4318
  exports.isStableQuoteToken = isStableQuoteToken;
@@ -4032,8 +4327,12 @@ exports.normaliseTrackingId = normaliseTrackingId;
4032
4327
  exports.normalizeAirdropAmount = normalizeAirdropAmount;
4033
4328
  exports.parseCloid = parseCloid;
4034
4329
  exports.parseError = parseError;
4330
+ exports.requiresTrackingInfo = requiresTrackingInfo;
4035
4331
  exports.retryWithBackoff = retryWithBackoff;
4036
4332
  exports.setHip3DexAbstraction = setHip3DexAbstraction;
4333
+ exports.setUserAbstraction = setUserAbstraction;
4334
+ exports.shouldNotifyCustomer = shouldNotifyCustomer;
4037
4335
  exports.sleep = sleep;
4038
4336
  exports.stableQuoteTokens = stableQuoteTokens;
4039
4337
  exports.truncateAddress = truncateAddress;
4338
+ exports.validateStatusTransition = validateStatusTransition;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { BannerType, BaseEcommerceClient, CustomerEcommerceClient, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, InventoryAuditAction, MerchantBusinessType, MerchantEcommerceClient, MerchantReturnPolicyType, MerchantStatus, OrderStatus, PaymentMethod, PaymentStatus, ProductSortBy, ReturnStatus, ReviewSortBy, ReviewStatus, ShipmentStatus, SortOrder, TaxBehavior, TaxReportPeriodType, TaxReportStatus, TaxType, buildQueryString, calculateDiscountAmount, calculateFinalPrice, formatPrice, getBackoffDelay, isRetryableError, isValidAddress, isValidEmail, parseError, retryWithBackoff, sleep, truncateAddress } from './chunk-NKSQEISP.mjs';
1
+ export { BannerType, BaseEcommerceClient, CustomerEcommerceClient, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, InventoryAuditAction, MerchantBusinessType, MerchantEcommerceClient, MerchantReturnPolicyType, MerchantStatus, ORDER_STATUS_TRANSITIONS, OrderStatus, PaymentMethod, PaymentStatus, ProductSortBy, ReturnStatus, ReviewSortBy, ReviewStatus, ShipmentStatus, SortOrder, TaxBehavior, TaxReportPeriodType, TaxReportStatus, TaxType, buildQueryString, calculateDiscountAmount, calculateFinalPrice, canCancelOrder, formatPrice, getBackoffDelay, getNextStatuses, getStatusColor, getStatusLabel, getStatusProgress, isPickupOrder, isRetryableError, isValidAddress, isValidEmail, parseError, requiresTrackingInfo, retryWithBackoff, shouldNotifyCustomer, sleep, truncateAddress, validateStatusTransition } from './chunk-35WGIB5F.mjs';
2
2
  export { AssetIdUtils, InstrumentClient } from './chunk-VBC6EQ7Q.mjs';
3
3
  import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
4
4
  import { signL1Action, signUserSignedAction } from '@nktkas/hyperliquid/signing';
@@ -544,6 +544,39 @@ var TESTNET_USDC_SPOT_TOKEN = {
544
544
  deployerTradingFeeShare: "0.0"
545
545
  };
546
546
 
547
+ // lib/constants/admin.ts
548
+ var ADMINS = [
549
+ "did:privy:cmc3hycnb00pljs0m1z010geq",
550
+ "did:privy:cmc8w2ddl01rdju0nylb6rp1v",
551
+ "did:privy:cmc3oftiz005fjx0msox3xgey",
552
+ "did:privy:cmcbx7i4400q8l90mawdymaag",
553
+ "did:privy:cmctbwphs00vzjz0m3la3zm4c",
554
+ "did:privy:cmcblrplb009ol70mia13winn",
555
+ "did:privy:cmcmizpxm02xfju0oc81alfy0",
556
+ "did:privy:cmcd2bvft00w3l90ljeyb4wn6",
557
+ "did:privy:cmc4y13ka0119kv0nckvgla1u",
558
+ "did:privy:cmc8qc36g00c1l70nnutuscue",
559
+ "did:privy:cmc8f1tf9019zlh0myjpi420p",
560
+ "did:privy:cmc6bturg002ql80mhzqr1d76",
561
+ "did:privy:cmc8uyr4t01kljo0mk3unzjl3",
562
+ "did:privy:cmcke9v7h00yijy0o2a41nhms",
563
+ "did:privy:cmgfcjt2y0024kz0cpymoqbmp",
564
+ "did:privy:cmeqj8tsi01k6la0c3s7gsl6w",
565
+ // elroy
566
+ "did:privy:cmiwrno1i00cdl70c5ro13eyp",
567
+ // adele
568
+ "did:privy:cmkc0jyy200abji0d42a0syil",
569
+ // matthew
570
+ "did:privy:cmlgc2zjk005vjo0cct10trdl"
571
+ // adele
572
+ ];
573
+ var ADMIN_WALLETS = [
574
+ "0x0c7582A67B8B6AD04Ea404A6C2A06aAc9E0d4e7c",
575
+ "0xDec587aDD20A6447fF0b29D70E95b10b197b1283",
576
+ "0x3e83987019c4CE29680401b72F8b18A2dE3f8fe6",
577
+ "0x5446A5Bc711170d5197DE33D8C193487794f30C0"
578
+ ];
579
+
547
580
  // lib/meta/metadata.ts
548
581
  var ROOT_DEX = "hyperliquid";
549
582
  var formatPriceAndSize = ({
@@ -786,4 +819,103 @@ async function getAllPerpsMeta(infoClient) {
786
819
  });
787
820
  }
788
821
 
789
- export { CloidClientCode, CloidClientCodeNameById, DayOfWeek, PUP_TOKEN_ADDRESS, PUP_TOKEN_THRESHOLDS, ROOT_DEX, TARGET_APPROVED_MAX_BUILDER_FEE, TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT, TESTNET_USDC_SPOT_TOKEN, USDC_SPOT_TOKEN, UserDexAbstractionTypes, WidgetType, WidgetTypeById, XP_BOOST_PERCENTAGES, buildCloid, calculateBoostPercentage, calculateTotalPupAmount, decodeSlug, enableHip3DexAbstractionWithAgent, encodeSlug, floorUtcDay, floorUtcHour, floorUtcMinutes, floorUtcWeek, formatPriceAndSize, formatPriceForDisplay, formatPriceForOrder, formatSizeForDisplay, formatSizeForOrder, getAllPerpsMeta, getApprovalAmount, getClientCodeNameById, getCloid, getDexFromCollateralTokenSymbol, getDisplayMarketSymbol, getHip3Dex, getHip3DexAbstraction, getLatestCompletedWeek, getNextTierInfo, getPriceDecimals, getStaticCollateralTokenByDex, getStaticCollateralTokenSymbol, getWeekInfoFromNumber, getWidgetTypeById, isBasedCloid, isClientCode, isHip3Symbol, isMiniAppCloid, isMiniAppTriggeredCloid, isSpotSymbol, isStableQuoteToken, isTenantCloid, isTrackingIdCloid, isWidgetType, makeUtcRounder, normaliseSlug, normaliseTrackingId, normalizeAirdropAmount, parseCloid, setHip3DexAbstraction, stableQuoteTokens };
822
+ // lib/abstraction/types.ts
823
+ var ABSTRACTION_MODE_TO_AGENT_CODE = {
824
+ disabled: "i",
825
+ unifiedAccount: "u",
826
+ portfolioMargin: "p"
827
+ };
828
+ var AGENT_CODE_TO_ABSTRACTION_MODE = {
829
+ i: "disabled",
830
+ u: "unifiedAccount",
831
+ p: "portfolioMargin"
832
+ };
833
+ var UserSetAbstractionTypes = {
834
+ "HyperliquidTransaction:UserSetAbstraction": [
835
+ { name: "hyperliquidChain", type: "string" },
836
+ { name: "user", type: "address" },
837
+ { name: "abstraction", type: "string" },
838
+ { name: "nonce", type: "uint64" }
839
+ ]
840
+ };
841
+ async function getUserAbstraction(client, user) {
842
+ return await client.transport.request("info", {
843
+ type: "userAbstraction",
844
+ user
845
+ });
846
+ }
847
+ async function setUserAbstraction(client, abstraction, user) {
848
+ const nonce = Date.now();
849
+ const isTestnet = client.isTestnet;
850
+ const action = {
851
+ type: "userSetAbstraction",
852
+ hyperliquidChain: isTestnet ? "Testnet" : "Mainnet",
853
+ signatureChainId: isTestnet ? "0x66eee" : "0xa4b1",
854
+ user,
855
+ abstraction,
856
+ nonce
857
+ };
858
+ const signature = await signUserSignedAction({
859
+ wallet: client.wallet,
860
+ action,
861
+ types: UserSetAbstractionTypes
862
+ });
863
+ return await client.transport.request("exchange", {
864
+ action,
865
+ signature,
866
+ nonce: action.nonce
867
+ });
868
+ }
869
+ async function agentSetAbstraction(client, abstraction) {
870
+ const nonce = Date.now();
871
+ const code = ABSTRACTION_MODE_TO_AGENT_CODE[abstraction];
872
+ const action = {
873
+ type: "agentSetAbstraction",
874
+ abstraction: code
875
+ };
876
+ const signature = await signL1Action({
877
+ wallet: client.wallet,
878
+ action,
879
+ isTestnet: client.isTestnet,
880
+ nonce
881
+ });
882
+ return await client.transport.request("exchange", {
883
+ action,
884
+ signature,
885
+ nonce
886
+ });
887
+ }
888
+
889
+ // lib/abstraction/ratio.ts
890
+ function computeUnifiedAccountRatio(multiverse, perpDexStates, spotBalances) {
891
+ const indexToCollateralToken = {};
892
+ for (const meta of Object.values(multiverse)) {
893
+ indexToCollateralToken[meta.index] = meta.collateralToken;
894
+ }
895
+ const crossMarginByToken = {};
896
+ const isolatedMarginByToken = {};
897
+ for (let index = 0; index < perpDexStates.length; index++) {
898
+ const dex = perpDexStates[index];
899
+ const token = indexToCollateralToken[index];
900
+ if (dex === void 0 || token === void 0) continue;
901
+ crossMarginByToken[token] = (crossMarginByToken[token] ?? 0) + dex.clearinghouseState.crossMaintenanceMarginUsed;
902
+ for (const ap of dex.clearinghouseState.assetPositions) {
903
+ if (ap.position.leverage.type === "isolated") {
904
+ isolatedMarginByToken[token] = (isolatedMarginByToken[token] ?? 0) + ap.position.marginUsed;
905
+ }
906
+ }
907
+ }
908
+ let maxRatio = 0;
909
+ for (const [tokenStr, crossMargin] of Object.entries(crossMarginByToken)) {
910
+ const token = Number(tokenStr);
911
+ const spotTotal = spotBalances.find((b) => b.token === token)?.total ?? 0;
912
+ const isolatedMargin = isolatedMarginByToken[token] ?? 0;
913
+ const available = spotTotal - isolatedMargin;
914
+ if (available > 0) {
915
+ maxRatio = Math.max(maxRatio, crossMargin / available);
916
+ }
917
+ }
918
+ return maxRatio;
919
+ }
920
+
921
+ export { ABSTRACTION_MODE_TO_AGENT_CODE, ADMINS, ADMIN_WALLETS, AGENT_CODE_TO_ABSTRACTION_MODE, CloidClientCode, CloidClientCodeNameById, DayOfWeek, PUP_TOKEN_ADDRESS, PUP_TOKEN_THRESHOLDS, ROOT_DEX, TARGET_APPROVED_MAX_BUILDER_FEE, TARGET_APPROVED_MAX_BUILDER_FEE_PERCENT, TESTNET_USDC_SPOT_TOKEN, USDC_SPOT_TOKEN, UserDexAbstractionTypes, UserSetAbstractionTypes, WidgetType, WidgetTypeById, XP_BOOST_PERCENTAGES, agentSetAbstraction, buildCloid, calculateBoostPercentage, calculateTotalPupAmount, computeUnifiedAccountRatio, decodeSlug, enableHip3DexAbstractionWithAgent, encodeSlug, floorUtcDay, floorUtcHour, floorUtcMinutes, floorUtcWeek, formatPriceAndSize, formatPriceForDisplay, formatPriceForOrder, formatSizeForDisplay, formatSizeForOrder, getAllPerpsMeta, getApprovalAmount, getClientCodeNameById, getCloid, getDexFromCollateralTokenSymbol, getDisplayMarketSymbol, getHip3Dex, getHip3DexAbstraction, getLatestCompletedWeek, getNextTierInfo, getPriceDecimals, getStaticCollateralTokenByDex, getStaticCollateralTokenSymbol, getUserAbstraction, getWeekInfoFromNumber, getWidgetTypeById, isBasedCloid, isClientCode, isHip3Symbol, isMiniAppCloid, isMiniAppTriggeredCloid, isSpotSymbol, isStableQuoteToken, isTenantCloid, isTrackingIdCloid, isWidgetType, makeUtcRounder, normaliseSlug, normaliseTrackingId, normalizeAirdropAmount, parseCloid, setHip3DexAbstraction, setUserAbstraction, stableQuoteTokens };
package/dist/react.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
3
  import { SpotMeta } from '@nktkas/hyperliquid';
4
- import { A as AllPerpsMeta, I as InstrumentClient } from './client-DMVXX1Gw.mjs';
4
+ import { A as AllPerpsMeta, I as InstrumentClient } from './client-BQzYwHDY.mjs';
5
5
 
6
6
  interface InstrumentsProviderProps {
7
7
  spotMeta: SpotMeta;
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
3
  import { SpotMeta } from '@nktkas/hyperliquid';
4
- import { A as AllPerpsMeta, I as InstrumentClient } from './client-DMVXX1Gw.js';
4
+ import { A as AllPerpsMeta, I as InstrumentClient } from './client-BQzYwHDY.js';
5
5
 
6
6
  interface InstrumentsProviderProps {
7
7
  spotMeta: SpotMeta;
package/index.ts CHANGED
@@ -2,13 +2,16 @@ export * from "./lib/cloid/cloid";
2
2
  export * from "./lib/fee";
3
3
  export * from "./lib/pup";
4
4
  export * from "./lib/constants/tokens";
5
+ export * from "./lib/constants/admin";
5
6
  export * from "./lib/meta/metadata";
6
7
  export * from "./lib/utils/formatter";
7
8
  export * from "./lib/utils/flooredDateTime";
8
9
  export * from "./lib/utils/time";
9
10
  export * from "./lib/hip3/utils";
10
11
  export * from "./lib/hip3/market-info";
12
+ export * from "./lib/abstraction";
11
13
  export * from "./lib/instrument/client";
14
+ export * from "./lib/types";
12
15
 
13
16
  // Ecommerce SDK
14
17
  export * from "./lib/ecommerce";
@@ -0,0 +1,106 @@
1
+ import {
2
+ ExchangeClient,
3
+ InfoClient,
4
+ SuccessResponse,
5
+ } from "@nktkas/hyperliquid";
6
+ import {
7
+ signL1Action,
8
+ signUserSignedAction,
9
+ } from "@nktkas/hyperliquid/signing";
10
+ import type {
11
+ UserAbstractionMode,
12
+ SettableAbstractionMode,
13
+ AgentAbstractionCode,
14
+ } from "./types";
15
+ import { ABSTRACTION_MODE_TO_AGENT_CODE } from "./types";
16
+
17
+ export const UserSetAbstractionTypes = {
18
+ "HyperliquidTransaction:UserSetAbstraction": [
19
+ { name: "hyperliquidChain", type: "string" },
20
+ { name: "user", type: "address" },
21
+ { name: "abstraction", type: "string" },
22
+ { name: "nonce", type: "uint64" },
23
+ ],
24
+ };
25
+
26
+ /**
27
+ * Query a user's current account abstraction mode.
28
+ */
29
+ export async function getUserAbstraction(
30
+ client: InfoClient,
31
+ user: string,
32
+ ): Promise<UserAbstractionMode> {
33
+ return await client.transport.request<UserAbstractionMode>("info", {
34
+ type: "userAbstraction",
35
+ user,
36
+ });
37
+ }
38
+
39
+ /**
40
+ * Set account abstraction mode using the owner wallet (user-signed action).
41
+ *
42
+ * Requires EIP-712 signature from the account owner.
43
+ */
44
+ export async function setUserAbstraction(
45
+ client: ExchangeClient,
46
+ abstraction: SettableAbstractionMode,
47
+ user: string,
48
+ ): Promise<SuccessResponse> {
49
+ const nonce = Date.now();
50
+ const isTestnet = client.isTestnet;
51
+
52
+ const action = {
53
+ type: "userSetAbstraction" as const,
54
+ hyperliquidChain: isTestnet ? "Testnet" : ("Mainnet" as string),
55
+ signatureChainId: isTestnet
56
+ ? ("0x66eee" as `0x${string}`)
57
+ : ("0xa4b1" as `0x${string}`),
58
+ user,
59
+ abstraction,
60
+ nonce,
61
+ };
62
+
63
+ const signature = await signUserSignedAction({
64
+ wallet: client.wallet,
65
+ action,
66
+ types: UserSetAbstractionTypes,
67
+ });
68
+
69
+ return await client.transport.request<SuccessResponse>("exchange", {
70
+ action,
71
+ signature,
72
+ nonce: action.nonce,
73
+ });
74
+ }
75
+
76
+ /**
77
+ * Set account abstraction mode using an agent wallet.
78
+ *
79
+ * Uses shorthand codes: "i" (disabled), "u" (unifiedAccount), "p" (portfolioMargin).
80
+ */
81
+ export async function agentSetAbstraction(
82
+ client: ExchangeClient,
83
+ abstraction: SettableAbstractionMode,
84
+ ): Promise<SuccessResponse> {
85
+ const nonce = Date.now();
86
+ const code: AgentAbstractionCode =
87
+ ABSTRACTION_MODE_TO_AGENT_CODE[abstraction];
88
+
89
+ const action = {
90
+ type: "agentSetAbstraction" as const,
91
+ abstraction: code,
92
+ };
93
+
94
+ const signature = await signL1Action({
95
+ wallet: client.wallet,
96
+ action,
97
+ isTestnet: client.isTestnet,
98
+ nonce,
99
+ });
100
+
101
+ return await client.transport.request<SuccessResponse>("exchange", {
102
+ action,
103
+ signature,
104
+ nonce,
105
+ });
106
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./api";
3
+ export * from "./ratio";