@pafi-dev/trading 0.11.2 → 0.13.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.cjs CHANGED
@@ -1186,6 +1186,80 @@ var TradingHandlers = class {
1186
1186
  };
1187
1187
  }
1188
1188
  // =========================================================================
1189
+ // POST /aster-deposit — Aster perp deposit (same-chain on Arbitrum)
1190
+ // =========================================================================
1191
+ /**
1192
+ * Build a sponsored Aster deposit UserOp pair (sponsored + fallback).
1193
+ *
1194
+ * Aster is same-chain (Arbitrum), so — unlike Orderly — there is NO Relay,
1195
+ * Vault, broker-hash, or LayerZero msg.value. The user's own delegated
1196
+ * account deposits USDT straight into the Aster Deposit Bridge:
1197
+ * sponsored: `[USDT.transfer(PAFI, fee), USDT.approve(bridge, amount), Bridge.deposit(token, amount, broker)]`
1198
+ * fallback: `[ USDT.approve(bridge, amount), Bridge.deposit(token, amount, broker)]`
1199
+ *
1200
+ * ⚠️ Built against an ASSUMED Aster Deposit Bridge ABI (`ASTER_DEPOSIT_ABI`
1201
+ * in @pafi-dev/core) — Aster has not published it. Confirm the deposit
1202
+ * signature + PAFI's `broker` id before mainnet.
1203
+ */
1204
+ async handleAsterDeposit(authenticatedAddress, request) {
1205
+ const userAddress = (0, import_viem4.getAddress)(request.userAddress);
1206
+ if ((0, import_viem4.getAddress)(authenticatedAddress) !== userAddress) {
1207
+ throw new import_core9.ValidationError(
1208
+ "ADDRESS_MISMATCH",
1209
+ `handleAsterDeposit: authenticatedAddress (${authenticatedAddress}) does not match request.userAddress (${request.userAddress})`
1210
+ );
1211
+ }
1212
+ if (request.chainId !== this.chainId) {
1213
+ throw new import_core9.ValidationError(
1214
+ "CHAIN_MISMATCH",
1215
+ `handleAsterDeposit: unsupported chainId ${request.chainId}`
1216
+ );
1217
+ }
1218
+ if (request.amount <= 0n) {
1219
+ throw new import_core9.ValidationError(
1220
+ "INVALID_AMOUNT",
1221
+ "handleAsterDeposit: amount must be positive"
1222
+ );
1223
+ }
1224
+ const { asterDepositBridge, usdt, pafiFeeRecipient } = (0, import_core9.getContractAddresses)(
1225
+ request.chainId
1226
+ );
1227
+ if (!asterDepositBridge) {
1228
+ throw new import_core9.ValidationError(
1229
+ "ASTER_NOT_AVAILABLE",
1230
+ `handleAsterDeposit: Aster is not deployed on chainId ${request.chainId} (no Deposit Bridge)`
1231
+ );
1232
+ }
1233
+ const broker = (0, import_core9.getAsterBrokerId)(request.chainId);
1234
+ const gasFee = request.gasFee !== void 0 ? request.gasFee : await (0, import_core9.quoteOperatorFeeUsdt)({
1235
+ provider: this.provider,
1236
+ chainId: request.chainId
1237
+ }).catch(() => 0n);
1238
+ const common = {
1239
+ userAddress,
1240
+ aaNonce: request.aaNonce,
1241
+ bridgeAddress: asterDepositBridge,
1242
+ token: usdt,
1243
+ amount: request.amount,
1244
+ broker
1245
+ };
1246
+ const userOp = (0, import_core9.buildAsterDeposit)({
1247
+ ...common,
1248
+ gasFee: gasFee > 0n ? gasFee : void 0,
1249
+ gasFeeRecipient: gasFee > 0n ? pafiFeeRecipient : void 0
1250
+ });
1251
+ const userOpFallback = gasFee > 0n ? (0, import_core9.buildAsterDeposit)(common) : void 0;
1252
+ return {
1253
+ userOp,
1254
+ userOpFallback,
1255
+ feeAmount: gasFee > 0n ? gasFee : 0n,
1256
+ feeRecipient: pafiFeeRecipient,
1257
+ bridgeAddress: asterDepositBridge,
1258
+ token: usdt,
1259
+ broker
1260
+ };
1261
+ }
1262
+ // =========================================================================
1189
1263
  // POST /erc20-transfer — gasless ERC-20 send (USDC/USDT/active-PT)
1190
1264
  // =========================================================================
1191
1265
  /**
@@ -1364,7 +1438,7 @@ async function swapDirect(params) {
1364
1438
  const impl = (0, import_core11.detectDelegateImpl)(delegate);
1365
1439
  if (impl === "unknown") {
1366
1440
  params.onWarning?.(
1367
- `swapDirect: user delegated to ${delegate} which is not a PAFI-recognised impl (expected ${import_core11.SIMPLE_7702_IMPL_BASE_MAINNET} or ${import_core11.BATCH_EXECUTOR_7702_IMPL}). Continuing \u2014 execute will revert if the impl doesn't expose executeBatch.`
1441
+ `swapDirect: user delegated to ${delegate} which is not a PAFI-recognised impl (expected ${import_core11.KERNEL_V3_3_IMPL}). Continuing \u2014 execute will revert if the impl doesn't expose the Kernel execute() entrypoint.`
1368
1442
  );
1369
1443
  }
1370
1444
  let quoteResult;
@@ -1479,7 +1553,7 @@ async function swapDirectExactOut(params) {
1479
1553
  const impl = (0, import_core12.detectDelegateImpl)(delegate);
1480
1554
  if (impl === "unknown") {
1481
1555
  params.onWarning?.(
1482
- `swapDirectExactOut: user delegated to ${delegate} which is not a PAFI-recognised impl (expected ${import_core12.SIMPLE_7702_IMPL_BASE_MAINNET} or ${import_core12.BATCH_EXECUTOR_7702_IMPL}). Continuing \u2014 execute will revert if the impl doesn't expose executeBatch.`
1556
+ `swapDirectExactOut: user delegated to ${delegate} which is not a PAFI-recognised impl (expected ${import_core12.KERNEL_V3_3_IMPL}). Continuing \u2014 execute will revert if the impl doesn't expose the Kernel execute() entrypoint.`
1483
1557
  );
1484
1558
  }
1485
1559
  let quoteResult;
@@ -1569,7 +1643,7 @@ async function perpDepositDirect(params) {
1569
1643
  const impl = (0, import_core13.detectDelegateImpl)(delegate);
1570
1644
  if (impl === "unknown") {
1571
1645
  params.onWarning?.(
1572
- `perpDepositDirect: user delegated to ${delegate} (not a PAFI-recognised impl ${import_core13.SIMPLE_7702_IMPL_BASE_MAINNET} / ${import_core13.BATCH_EXECUTOR_7702_IMPL}). Continuing \u2014 execute will revert if the impl doesn't expose executeBatch.`
1646
+ `perpDepositDirect: user delegated to ${delegate} (not a PAFI-recognised impl ${import_core13.KERNEL_V3_3_IMPL}). Continuing \u2014 execute will revert if the impl doesn't expose the Kernel execute() entrypoint.`
1573
1647
  );
1574
1648
  }
1575
1649
  const vault = import_core13.ORDERLY_VAULT_ADDRESSES[params.chainId];