{"version":3,"sources":["../../src/protocol/escrow-deposit.ts"],"sourcesContent":["/**\n * On-chain deposit primitives for the DataPortabilityEscrow contract.\n *\n * The escrow holds the finalized balance that `/v1/escrow/pay` debits against.\n * A payer credits their balance by sending one of two function calls to the\n * escrow contract — depositNative (native VANA, amount via `msg.value`) or\n * depositToken (ERC-20, caller must `approve` the escrow first). The credited\n * `account` need not equal `msg.sender`, so a third party can fund someone\n * else's escrow.\n *\n * Once the on-chain tx lands, call `GatewayClient.submitEscrowDeposit({txHash})`\n * to announce it; the gateway reconciles it into the balance and surfaces it\n * under `getEscrowBalance(account).deposits.finalized`.\n *\n * These helpers are signer/transport-agnostic — they return the raw\n * `{to, data, value?}` request object so callers can feed it to any wallet\n * stack (viem `sendTransaction`/`writeContract`, ethers, wallet-rpc, MPC,\n * Safe transactions, etc.).\n *\n * @category Protocol\n */\nimport { encodeFunctionData } from \"viem\";\nimport type { DataPortabilityGatewayConfig } from \"./eip712\";\n\n// ABI for the two deposit entry points on DataPortabilityEscrow. Same shape\n// the gateway uses to decode pending/mined tx calldata at\n// /v1/escrow/deposit time (data-gateway/lib/escrow.ts:39).\nexport const ESCROW_DEPOSIT_ABI = [\n  {\n    type: \"function\",\n    name: \"depositNative\",\n    stateMutability: \"payable\",\n    inputs: [{ name: \"account\", type: \"address\" }],\n    outputs: [],\n  },\n  {\n    type: \"function\",\n    name: \"depositToken\",\n    stateMutability: \"nonpayable\",\n    inputs: [\n      { name: \"account\", type: \"address\" },\n      { name: \"token\", type: \"address\" },\n      { name: \"amount\", type: \"uint256\" },\n    ],\n    outputs: [],\n  },\n] as const;\n\nexport function escrowContractAddress(\n  config: DataPortabilityGatewayConfig,\n): `0x${string}` {\n  return config.contracts.dataPortabilityEscrow as `0x${string}`;\n}\n\nexport interface DepositNativeInput {\n  // Address credited inside the escrow. Often the same as the wallet sending\n  // the tx, but third-party funding is supported.\n  account: `0x${string}`;\n  amount: bigint;\n}\n\nexport interface DepositTokenInput {\n  account: `0x${string}`;\n  // ERC-20 contract address.\n  token: `0x${string}`;\n  amount: bigint;\n}\n\n// Shape compatible with viem's `sendTransaction` / `writeContract` request\n// objects. `value` is omitted on the ERC-20 path because the amount lives in\n// the token contract, not `msg.value`.\nexport interface DepositTransactionRequest {\n  to: `0x${string}`;\n  data: `0x${string}`;\n  value?: bigint;\n}\n\nexport function encodeDepositNativeData(input: {\n  account: `0x${string}`;\n}): `0x${string}` {\n  return encodeFunctionData({\n    abi: ESCROW_DEPOSIT_ABI,\n    functionName: \"depositNative\",\n    args: [input.account],\n  });\n}\n\nexport function encodeDepositTokenData(\n  input: DepositTokenInput,\n): `0x${string}` {\n  return encodeFunctionData({\n    abi: ESCROW_DEPOSIT_ABI,\n    functionName: \"depositToken\",\n    args: [input.account, input.token, input.amount],\n  });\n}\n\n// Build the full tx request for a native-VANA deposit. Feed it straight to\n// `walletClient.sendTransaction({...req, account, chain})`. ERC-20 needs a\n// prior `approve(escrow, amount)` on the token — use viem's built-in\n// `erc20Abi` for that; the SDK doesn't bundle one to avoid the import surface.\nexport function buildDepositNativeRequest(\n  config: DataPortabilityGatewayConfig,\n  input: DepositNativeInput,\n): DepositTransactionRequest {\n  return {\n    to: escrowContractAddress(config),\n    data: encodeDepositNativeData({ account: input.account }),\n    value: input.amount,\n  };\n}\n\nexport function buildDepositTokenRequest(\n  config: DataPortabilityGatewayConfig,\n  input: DepositTokenInput,\n): DepositTransactionRequest {\n  return {\n    to: escrowContractAddress(config),\n    data: encodeDepositTokenData(input),\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,kBAAmC;AAM5B,MAAM,qBAAqB;AAAA,EAChC;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,iBAAiB;AAAA,IACjB,QAAQ,CAAC,EAAE,MAAM,WAAW,MAAM,UAAU,CAAC;AAAA,IAC7C,SAAS,CAAC;AAAA,EACZ;AAAA,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