@tuwaio/nova-payments 0.0.1 → 0.2.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 (49) hide show
  1. package/README.md +11 -6
  2. package/dist/chunk-4HBN6N7D.cjs +1 -0
  3. package/dist/chunk-7FQXTBOY.cjs +1 -0
  4. package/dist/chunk-7HSDAUKN.js +1 -0
  5. package/dist/chunk-A2WIFZQB.js +1 -0
  6. package/dist/de-5UOOKHHH.cjs +1 -0
  7. package/dist/de-U3SERR3Y.js +1 -0
  8. package/dist/es-J6MJIGEI.js +1 -0
  9. package/dist/es-WSJ36B6Y.cjs +1 -0
  10. package/dist/evm/index.cjs +1 -1
  11. package/dist/evm/index.d.cts +13 -5
  12. package/dist/evm/index.d.ts +13 -5
  13. package/dist/evm/index.js +1 -1
  14. package/dist/i18n/index.cjs +1 -1
  15. package/dist/i18n/index.d.cts +2 -2
  16. package/dist/i18n/index.d.ts +2 -2
  17. package/dist/i18n/index.js +1 -1
  18. package/dist/index.cjs +2 -2
  19. package/dist/index.css +198 -50
  20. package/dist/index.d.cts +197 -177
  21. package/dist/index.d.ts +197 -177
  22. package/dist/index.js +2 -2
  23. package/dist/it-KX7WWME3.js +1 -0
  24. package/dist/it-QORQLELA.cjs +1 -0
  25. package/dist/{locales-DzMinYsr.d.cts → locales-dTcrLl9B.d.cts} +69 -97
  26. package/dist/{locales-DzMinYsr.d.ts → locales-dTcrLl9B.d.ts} +69 -97
  27. package/dist/solana/index.cjs +1 -1
  28. package/dist/solana/index.js +1 -1
  29. package/dist/{types-Bp6JUt56.d.cts → types-DkYd2XhD.d.cts} +1 -49
  30. package/dist/{types-Bp6JUt56.d.ts → types-DkYd2XhD.d.ts} +1 -49
  31. package/dist/uk-GMKBC44N.js +1 -0
  32. package/dist/uk-R2A3XIGT.cjs +1 -0
  33. package/dist/zhCN-5JP4MWXH.cjs +1 -0
  34. package/dist/zhCN-AX2E4I6A.js +1 -0
  35. package/package.json +10 -11
  36. package/dist/chunk-PUMIYLSN.js +0 -1
  37. package/dist/chunk-S3L4QDPT.cjs +0 -1
  38. package/dist/chunk-WOAPFVQF.js +0 -1
  39. package/dist/chunk-XOVRZTAM.cjs +0 -1
  40. package/dist/de-53SSE6O2.js +0 -1
  41. package/dist/de-LB5XSRMX.cjs +0 -1
  42. package/dist/es-LP3HJ4KB.js +0 -1
  43. package/dist/es-VDW2RZMP.cjs +0 -1
  44. package/dist/it-6IQFXLAR.cjs +0 -1
  45. package/dist/it-JJ5Z5EUF.js +0 -1
  46. package/dist/uk-EI4N5BMM.js +0 -1
  47. package/dist/uk-FVCYLYSB.cjs +0 -1
  48. package/dist/zhCN-BZBMKUUA.js +0 -1
  49. package/dist/zhCN-TA7WU5XS.cjs +0 -1
@@ -1 +1 @@
1
- 'use strict';var chunkS3L4QDPT_cjs=require('../chunk-S3L4QDPT.cjs'),orbitCore=require('@tuwaio/orbit-core'),pulsarCore=require('@tuwaio/pulsar-core'),core=require('@wagmi/core'),viem=require('viem');var y=18e4,q=30*6e4,G=15e3,k={to:"0x000000000000000000000000000000000000dEaD",value:0n},V=5,K=2e3;function h(a){let d=orbitCore.toEvmChainId(a);if(d===void 0)throw new Error(`${a} is not an EVM chain`);return d}function A(a){if(a.family!=="eip155")throw new Error(`${a.chainId} is not an EVM chain`);return a}function W(a){return a.token==="native"?{to:a.to,value:BigInt(a.amount)}:{to:a.token,data:viem.encodeFunctionData({abi:viem.erc20Abi,functionName:"transfer",args:[a.to,BigInt(a.amount)]})}}async function z(a){if(a?.type!=="walletConnect")return false;try{let d=await a.getProvider();return /^safe\b/i.test(d.session?.peer?.metadata?.name??"")}catch{return false}}function Z(a){let d=async()=>{let t=core.getConnection(a).connector;if(t?.id==="safe"||t?.type==="safe"||await z(t))throw new chunkS3L4QDPT_cjs.a("unsupported","A Safe wallet cannot pay this checkout")},C=async(t,n,e)=>{for(;Date.now()<n;){try{let s=await core.waitForCallsStatus(a,{id:t,timeout:n-Date.now()});if(s.status==="failure")return;let r=s.status==="success"?s.receipts?.at(-1)?.transactionHash:void 0;if(r)return e?.(r)}catch{}await orbitCore.delay(void 0,G);}};return {family:"eip155",getBalance:async({chainId:t,account:n,token:e})=>{let s=h(t);return e==="native"?(await core.getBalance(a,{address:n,chainId:s})).value:core.readContract(a,{address:e,abi:viem.erc20Abi,functionName:"balanceOf",args:[n],chainId:s})},estimateFee:async({instructions:t,account:n})=>{let e=A(t),s=await core.estimateGas(a,{account:n,chainId:e.chainId,...W(e)}),r=await core.estimateFeesPerGas(a,{chainId:e.chainId}),i=r.maxFeePerGas??r.gasPrice;if(i===void 0)return null;let c=a.chains.find(o=>o.id===e.chainId)?.nativeCurrency;return {amount:s*i,decimals:c?.decimals??18,symbol:c?.symbol??"ETH"}},canSponsorCalls:async({chainId:t,account:n})=>{try{return (await core.getCapabilities(a,{account:n,chainId:h(t)})).paymasterService?.supported===!0}catch{return false}},switchChain:async t=>{await core.switchChain(a,{chainId:h(t)});},sendTransfer:async({instructions:t,account:n})=>{let e=A(t);return await d(),e.token==="native"?core.sendTransaction(a,{account:n,chainId:e.chainId,to:e.to,value:BigInt(e.amount)}):core.writeContract(a,{account:n,chainId:e.chainId,address:e.token,abi:viem.erc20Abi,functionName:"transfer",args:[e.to,BigInt(e.amount)]})},signTransferAuthorization:async({typedData:t,account:n})=>(await d(),(await core.getConnectorClient(a,{chainId:Number(t.domain.chainId)})).request({method:"eth_signTypedData_v4",params:[n,JSON.stringify(t)]})),signMessage:async({message:t,account:n})=>(await d(),core.signMessage(a,{account:n,message:t})),followSponsoredCalls:({batchId:t,until:n,onLate:e})=>{C(t,n,e).catch(()=>{});},sendSponsoredCalls:async({calls:t,paymasterUrl:n,chainId:e,account:s,onSent:r,onAccepted:i,onLate:c})=>{await d();let{id:o}=await core.sendCalls(a,{account:s,chainId:h(e),calls:t.map(u=>({to:u.to,value:BigInt(u.value),data:u.data})),capabilities:{paymasterService:{url:n}}});i?.(o),r?.();let p=u=>(C(o,Date.now()+q,c).catch(()=>{}),new chunkS3L4QDPT_cjs.a("sentUnconfirmed","The sponsored payment is not confirmed yet",{cause:u})),w=await core.waitForCallsStatus(a,{id:o,timeout:y}).catch(u=>{throw p(u)});if(w.status==="failure")throw new chunkS3L4QDPT_cjs.a("failed","The sponsored payment failed");let T=w.status==="success"?w.receipts?.at(-1)?.transactionHash:void 0;if(!T)throw p();return T},explorerUrl:({chainId:t,txKey:n})=>{let s=a.chains.find(r=>r.id===orbitCore.toEvmChainId(t))?.blockExplorers?.default.url;return s?`${s}/tx/${n}`:void 0},explorerAddressUrl:({chainId:t,address:n})=>{let s=a.chains.find(r=>r.id===orbitCore.toEvmChainId(t))?.blockExplorers?.default.url;return s?`${s}/address/${n}`:void 0},smartAccountStatus:async({chainId:t,account:n})=>{let e=h(t);try{let s=await core.getBytecode(a,{address:n,chainId:e});return s&&s!=="0x"?"smart":(await core.getCapabilities(a,{account:n,chainId:e})).atomic?.status==="ready"?"upgradable":"unknown"}catch{return "unknown"}},upgradeToSmartAccount:async({chainId:t,account:n})=>{await d();let e=h(t),s=n;await core.switchChain(a,{chainId:e});let{id:r}=await core.sendCalls(a,{account:s,chainId:e,forceAtomic:true,calls:[k,k]});await core.waitForCallsStatus(a,{id:r,timeout:y}).catch(()=>{});for(let i=0;i<V;i++){let c=await core.getBytecode(a,{address:s,chainId:e}).catch(()=>{});if(c&&c!=="0x")return;await new Promise(o=>setTimeout(o,K));}throw new chunkS3L4QDPT_cjs.a("failed","The wallet did not switch the account")},requestPermission:async({request:t,account:n})=>{let e=Number.parseInt(t.chainId,16);await core.switchChain(a,{chainId:e});let r=await(await core.getConnectorClient(a,{chainId:e})).request({method:"wallet_requestExecutionPermissions",params:[{...t,from:n}]}),[i]=Array.isArray(r)?r:[r];if(!i?.context||!i.delegationManager)throw new chunkS3L4QDPT_cjs.a("failed","The wallet did not grant the permission");return {context:i.context,delegationManager:i.delegationManager,dependencies:i.dependencies??[]}},revokePermission:async({revocation:t,chainId:n,account:e,onSent:s})=>{await d();let r=h(n);await core.switchChain(a,{chainId:r});let i=await core.sendTransaction(a,{account:e,chainId:r,to:t.to,data:t.data});s?.();try{await core.waitForTransactionReceipt(a,{chainId:r,hash:i,timeout:y});}catch(c){throw (await core.getTransactionReceipt(a,{chainId:r,hash:i}).catch(()=>null))?.status==="reverted"?new chunkS3L4QDPT_cjs.a("failed","The revocation reverted",{cause:c}):c}},pulsarTransaction:({txKey:t,instructions:n,account:e,connectorType:s,title:r,description:i,payload:c})=>{let o=A(n);return {adapter:orbitCore.OrbitAdapter.EVM,tracker:pulsarCore.TransactionTracker.Ethereum,txKey:t,hash:t,chainId:o.chainId,from:e,to:o.token==="native"?o.to:o.token,type:"payment",connectorType:s,title:r,description:i,payload:c,pending:true,localTimestamp:Math.floor(Date.now()/1e3),isTrackedModalOpen:false}}}}exports.paymentsEVMAdapter=Z;
1
+ 'use strict';var chunk7FQXTBOY_cjs=require('../chunk-7FQXTBOY.cjs'),orbitCore=require('@tuwaio/orbit-core'),pulsarCore=require('@tuwaio/pulsar-core'),core=require('@wagmi/core'),viem=require('viem');var R=18e4,U=30*6e4,G=15e3,V=25n;function h(t){let i=orbitCore.toEvmChainId(t);if(i===void 0)throw new Error(`${t} is not an EVM chain`);return i}function A(t){if(t.family!=="eip155")throw new Error(`${t.chainId} is not an EVM chain`);return t}function S(t){return t.token==="native"?{to:t.to,value:BigInt(t.amount)}:{to:t.token,data:viem.encodeFunctionData({abi:viem.erc20Abi,functionName:"transfer",args:[t.to,BigInt(t.amount)]})}}async function q(t,i,d){try{return {gas:(await core.estimateGas(t,{account:i,chainId:d.chainId,...S(d)})*(100n+V)+99n)/100n}}catch{return {}}}async function W(t){if(t?.type!=="walletConnect")return false;try{let i=await t.getProvider();return /^safe\b/i.test(i.session?.peer?.metadata?.name??"")}catch{return false}}function X(t){let i=async()=>{let a=core.getConnection(t).connector;if(a?.id==="safe"||a?.type==="safe"||await W(a))throw new chunk7FQXTBOY_cjs.a("unsupported","A Safe wallet cannot pay this checkout")},d=async a=>{let n;try{n=await core.getConnection(t).connector?.getChainId();}catch{return}if(!(n===void 0||n===a))try{await core.switchChain(t,{chainId:a});}catch(e){let s=chunk7FQXTBOY_cjs.b(e);throw s==="declined"?new chunk7FQXTBOY_cjs.a("declined",`The wallet declined the switch to ${a}`,{cause:e,step:"switch"}):s!=="failed"?e:new chunk7FQXTBOY_cjs.a("switchFailed",`The wallet did not switch to ${a}`,{cause:e,step:"switch"})}},f=async(a,n,e)=>{for(;Date.now()<n;){try{let s=await core.waitForCallsStatus(t,{id:a,timeout:n-Date.now()});if(s.status==="failure")return;let r=s.status==="success"?s.receipts?.at(-1)?.transactionHash:void 0;if(r)return e?.(r)}catch{}await orbitCore.delay(void 0,G);}};return {family:"eip155",getBalance:async({chainId:a,account:n,token:e})=>{let s=h(a);return e==="native"?(await core.getBalance(t,{address:n,chainId:s})).value:core.readContract(t,{address:e,abi:viem.erc20Abi,functionName:"balanceOf",args:[n],chainId:s})},estimateFee:async({instructions:a,account:n})=>{let e=A(a),s=await core.estimateGas(t,{account:n,chainId:e.chainId,...S(e)}),r=await core.estimateFeesPerGas(t,{chainId:e.chainId}),u=r.maxFeePerGas??r.gasPrice;if(u===void 0)return null;let l=t.chains.find(o=>o.id===e.chainId)?.nativeCurrency;return {amount:s*u,decimals:l?.decimals??18,symbol:l?.symbol??"ETH"}},canSponsorCalls:async({chainId:a,account:n})=>{try{return (await core.getCapabilities(t,{account:n,chainId:h(a)})).paymasterService?.supported===!0}catch{return false}},switchChain:async a=>{await core.switchChain(t,{chainId:h(a)});},sendTransfer:async({instructions:a,account:n})=>{let e=A(a);if(await i(),await d(e.chainId),e.token==="native"){let s=await q(t,n,e);return core.sendTransaction(t,{account:n,chainId:e.chainId,to:e.to,value:BigInt(e.amount),...s})}return core.writeContract(t,{account:n,chainId:e.chainId,address:e.token,abi:viem.erc20Abi,functionName:"transfer",args:[e.to,BigInt(e.amount)]})},signTransferAuthorization:async({typedData:a,account:n})=>{await i();let e=Number(a.domain.chainId);return await d(e),(await core.getConnectorClient(t,{chainId:e})).request({method:"eth_signTypedData_v4",params:[n,JSON.stringify(a)]})},signMessage:async({message:a,account:n,chainId:e})=>{await i();let s=orbitCore.toEvmChainId(e);return s!==void 0&&await d(s),core.signMessage(t,{account:n,message:a})},followSponsoredCalls:({batchId:a,until:n,onLate:e})=>{f(a,n,e).catch(()=>{});},sendSponsoredCalls:async({calls:a,paymasterUrl:n,chainId:e,account:s,onSent:r,onAccepted:u,onLate:l})=>{await i(),await d(h(e));let{id:o}=await core.sendCalls(t,{account:s,chainId:h(e),calls:a.map(c=>({to:c.to,value:BigInt(c.value),data:c.data})),capabilities:{paymasterService:{url:n}}});u?.(o),r?.();let w=c=>(f(o,Date.now()+U,l).catch(()=>{}),new chunk7FQXTBOY_cjs.a("sentUnconfirmed","The sponsored payment is not confirmed yet",{cause:c})),y=await core.waitForCallsStatus(t,{id:o,timeout:R}).catch(c=>{throw w(c)});if(y.status==="failure")throw new chunk7FQXTBOY_cjs.a("failed","The sponsored payment failed");let C=y.status==="success"?y.receipts?.at(-1)?.transactionHash:void 0;if(!C)throw w();return C},explorerUrl:({chainId:a,txKey:n})=>{let s=t.chains.find(r=>r.id===orbitCore.toEvmChainId(a))?.blockExplorers?.default.url;return s?`${s}/tx/${n}`:void 0},explorerAddressUrl:({chainId:a,address:n})=>{let s=t.chains.find(r=>r.id===orbitCore.toEvmChainId(a))?.blockExplorers?.default.url;return s?`${s}/address/${n}`:void 0},pulsarTransaction:({txKey:a,instructions:n,account:e,connectorType:s,title:r,description:u,payload:l})=>{let o=A(n);return {adapter:orbitCore.OrbitAdapter.EVM,tracker:pulsarCore.TransactionTracker.Ethereum,txKey:a,hash:a,chainId:o.chainId,from:e,to:o.token==="native"?o.to:o.token,type:"payment",connectorType:s,title:r,description:u,payload:l,pending:true,localTimestamp:Math.floor(Date.now()/1e3),isTrackedModalOpen:false}}}}exports.paymentsEVMAdapter=X;
@@ -6,12 +6,20 @@ import '@tuwaio/quasar-sdk/checkout';
6
6
  /**
7
7
  * The adapter that pays EVM methods of a Nova Payments checkout from the wallet connected through wagmi (the config
8
8
  * Satellite Connect and Nova Connect use). It reads balances and estimates fees on the network, asks the wallet to
9
- * switch networks, sends the transfer (native coin or ERC-20 `transfer`), signs the EIP-3009 authorization of a gasless
10
- * quote with `eth_signTypedData_v4` exactly as Quasar issued it, signs Quasar's message that confirms the paying wallet
11
- * with `personal_sign`, and sends sponsored calls with `wallet_sendCalls` and the checkout's ERC-7677 paymaster. A Safe wallet is refused: it returns a Safe transaction hash, not the transaction
12
- * Quasar follows. Pass it in `adapters` of `NovaPaymentsProvider`.
9
+ * switch networks, sends the transfer (native coin or ERC-20 `transfer`; the native coin with the gas limit the app's
10
+ * RPC estimates plus 25%, as a recipient with an EIP-7702 delegation runs code on receipt; the wallet estimates the
11
+ * gas of a token transfer, and of any transfer when that read fails),
12
+ * signs the EIP-3009 authorization of a gasless quote with `eth_signTypedData_v4` exactly as Quasar issued it, signs
13
+ * Quasar's message that confirms the paying wallet with `personal_sign`, and sends sponsored calls with
14
+ * `wallet_sendCalls` and the checkout's ERC-7677 paymaster. Before each of these four requests, a wallet that reports
15
+ * another network than the request's is asked to switch (wagmi would refuse the request before the wallet saw it); a
16
+ * switch that fails is a `PaymentWalletError` of the kind `switchFailed`, a refused one stays `declined`, both with
17
+ * `step: 'switch'`. A Safe wallet
18
+ * is refused: it returns a Safe transaction hash, not the transaction Quasar follows. Pass it in `adapters` of
19
+ * `NovaPaymentsProvider`.
13
20
  *
14
- * Side effects: RPC reads through the wagmi transports; wallet prompts.
21
+ * Side effects: RPC reads through the wagmi transports (`eth_estimateGas` before each transfer); wallet prompts,
22
+ * including a network switch.
15
23
  *
16
24
  * @param config - The wagmi config of the app.
17
25
  * @returns The EVM adapter.
@@ -6,12 +6,20 @@ import '@tuwaio/quasar-sdk/checkout';
6
6
  /**
7
7
  * The adapter that pays EVM methods of a Nova Payments checkout from the wallet connected through wagmi (the config
8
8
  * Satellite Connect and Nova Connect use). It reads balances and estimates fees on the network, asks the wallet to
9
- * switch networks, sends the transfer (native coin or ERC-20 `transfer`), signs the EIP-3009 authorization of a gasless
10
- * quote with `eth_signTypedData_v4` exactly as Quasar issued it, signs Quasar's message that confirms the paying wallet
11
- * with `personal_sign`, and sends sponsored calls with `wallet_sendCalls` and the checkout's ERC-7677 paymaster. A Safe wallet is refused: it returns a Safe transaction hash, not the transaction
12
- * Quasar follows. Pass it in `adapters` of `NovaPaymentsProvider`.
9
+ * switch networks, sends the transfer (native coin or ERC-20 `transfer`; the native coin with the gas limit the app's
10
+ * RPC estimates plus 25%, as a recipient with an EIP-7702 delegation runs code on receipt; the wallet estimates the
11
+ * gas of a token transfer, and of any transfer when that read fails),
12
+ * signs the EIP-3009 authorization of a gasless quote with `eth_signTypedData_v4` exactly as Quasar issued it, signs
13
+ * Quasar's message that confirms the paying wallet with `personal_sign`, and sends sponsored calls with
14
+ * `wallet_sendCalls` and the checkout's ERC-7677 paymaster. Before each of these four requests, a wallet that reports
15
+ * another network than the request's is asked to switch (wagmi would refuse the request before the wallet saw it); a
16
+ * switch that fails is a `PaymentWalletError` of the kind `switchFailed`, a refused one stays `declined`, both with
17
+ * `step: 'switch'`. A Safe wallet
18
+ * is refused: it returns a Safe transaction hash, not the transaction Quasar follows. Pass it in `adapters` of
19
+ * `NovaPaymentsProvider`.
13
20
  *
14
- * Side effects: RPC reads through the wagmi transports; wallet prompts.
21
+ * Side effects: RPC reads through the wagmi transports (`eth_estimateGas` before each transfer); wallet prompts,
22
+ * including a network switch.
15
23
  *
16
24
  * @param config - The wagmi config of the app.
17
25
  * @returns The EVM adapter.
package/dist/evm/index.js CHANGED
@@ -1 +1 @@
1
- import {a}from'../chunk-PUMIYLSN.js';import {OrbitAdapter,toEvmChainId,delay}from'@tuwaio/orbit-core';import {TransactionTracker}from'@tuwaio/pulsar-core';import {switchChain,sendTransaction,waitForTransactionReceipt,getTransactionReceipt,getConnectorClient,sendCalls,waitForCallsStatus,getBytecode,getCapabilities,signMessage,writeContract,estimateGas,estimateFeesPerGas,getBalance,readContract,getConnection}from'@wagmi/core';import {erc20Abi,encodeFunctionData}from'viem';var y=18e4,q=30*6e4,G=15e3,k={to:"0x000000000000000000000000000000000000dEaD",value:0n},V=5,K=2e3;function h(a){let d=toEvmChainId(a);if(d===void 0)throw new Error(`${a} is not an EVM chain`);return d}function A(a){if(a.family!=="eip155")throw new Error(`${a.chainId} is not an EVM chain`);return a}function W(a){return a.token==="native"?{to:a.to,value:BigInt(a.amount)}:{to:a.token,data:encodeFunctionData({abi:erc20Abi,functionName:"transfer",args:[a.to,BigInt(a.amount)]})}}async function z(a){if(a?.type!=="walletConnect")return false;try{let d=await a.getProvider();return /^safe\b/i.test(d.session?.peer?.metadata?.name??"")}catch{return false}}function Z(a$1){let d=async()=>{let t=getConnection(a$1).connector;if(t?.id==="safe"||t?.type==="safe"||await z(t))throw new a("unsupported","A Safe wallet cannot pay this checkout")},C=async(t,n,e)=>{for(;Date.now()<n;){try{let s=await waitForCallsStatus(a$1,{id:t,timeout:n-Date.now()});if(s.status==="failure")return;let r=s.status==="success"?s.receipts?.at(-1)?.transactionHash:void 0;if(r)return e?.(r)}catch{}await delay(void 0,G);}};return {family:"eip155",getBalance:async({chainId:t,account:n,token:e})=>{let s=h(t);return e==="native"?(await getBalance(a$1,{address:n,chainId:s})).value:readContract(a$1,{address:e,abi:erc20Abi,functionName:"balanceOf",args:[n],chainId:s})},estimateFee:async({instructions:t,account:n})=>{let e=A(t),s=await estimateGas(a$1,{account:n,chainId:e.chainId,...W(e)}),r=await estimateFeesPerGas(a$1,{chainId:e.chainId}),i=r.maxFeePerGas??r.gasPrice;if(i===void 0)return null;let c=a$1.chains.find(o=>o.id===e.chainId)?.nativeCurrency;return {amount:s*i,decimals:c?.decimals??18,symbol:c?.symbol??"ETH"}},canSponsorCalls:async({chainId:t,account:n})=>{try{return (await getCapabilities(a$1,{account:n,chainId:h(t)})).paymasterService?.supported===!0}catch{return false}},switchChain:async t=>{await switchChain(a$1,{chainId:h(t)});},sendTransfer:async({instructions:t,account:n})=>{let e=A(t);return await d(),e.token==="native"?sendTransaction(a$1,{account:n,chainId:e.chainId,to:e.to,value:BigInt(e.amount)}):writeContract(a$1,{account:n,chainId:e.chainId,address:e.token,abi:erc20Abi,functionName:"transfer",args:[e.to,BigInt(e.amount)]})},signTransferAuthorization:async({typedData:t,account:n})=>(await d(),(await getConnectorClient(a$1,{chainId:Number(t.domain.chainId)})).request({method:"eth_signTypedData_v4",params:[n,JSON.stringify(t)]})),signMessage:async({message:t,account:n})=>(await d(),signMessage(a$1,{account:n,message:t})),followSponsoredCalls:({batchId:t,until:n,onLate:e})=>{C(t,n,e).catch(()=>{});},sendSponsoredCalls:async({calls:t,paymasterUrl:n,chainId:e,account:s,onSent:r,onAccepted:i,onLate:c})=>{await d();let{id:o}=await sendCalls(a$1,{account:s,chainId:h(e),calls:t.map(u=>({to:u.to,value:BigInt(u.value),data:u.data})),capabilities:{paymasterService:{url:n}}});i?.(o),r?.();let p=u=>(C(o,Date.now()+q,c).catch(()=>{}),new a("sentUnconfirmed","The sponsored payment is not confirmed yet",{cause:u})),w=await waitForCallsStatus(a$1,{id:o,timeout:y}).catch(u=>{throw p(u)});if(w.status==="failure")throw new a("failed","The sponsored payment failed");let T=w.status==="success"?w.receipts?.at(-1)?.transactionHash:void 0;if(!T)throw p();return T},explorerUrl:({chainId:t,txKey:n})=>{let s=a$1.chains.find(r=>r.id===toEvmChainId(t))?.blockExplorers?.default.url;return s?`${s}/tx/${n}`:void 0},explorerAddressUrl:({chainId:t,address:n})=>{let s=a$1.chains.find(r=>r.id===toEvmChainId(t))?.blockExplorers?.default.url;return s?`${s}/address/${n}`:void 0},smartAccountStatus:async({chainId:t,account:n})=>{let e=h(t);try{let s=await getBytecode(a$1,{address:n,chainId:e});return s&&s!=="0x"?"smart":(await getCapabilities(a$1,{account:n,chainId:e})).atomic?.status==="ready"?"upgradable":"unknown"}catch{return "unknown"}},upgradeToSmartAccount:async({chainId:t,account:n})=>{await d();let e=h(t),s=n;await switchChain(a$1,{chainId:e});let{id:r}=await sendCalls(a$1,{account:s,chainId:e,forceAtomic:true,calls:[k,k]});await waitForCallsStatus(a$1,{id:r,timeout:y}).catch(()=>{});for(let i=0;i<V;i++){let c=await getBytecode(a$1,{address:s,chainId:e}).catch(()=>{});if(c&&c!=="0x")return;await new Promise(o=>setTimeout(o,K));}throw new a("failed","The wallet did not switch the account")},requestPermission:async({request:t,account:n})=>{let e=Number.parseInt(t.chainId,16);await switchChain(a$1,{chainId:e});let r=await(await getConnectorClient(a$1,{chainId:e})).request({method:"wallet_requestExecutionPermissions",params:[{...t,from:n}]}),[i]=Array.isArray(r)?r:[r];if(!i?.context||!i.delegationManager)throw new a("failed","The wallet did not grant the permission");return {context:i.context,delegationManager:i.delegationManager,dependencies:i.dependencies??[]}},revokePermission:async({revocation:t,chainId:n,account:e,onSent:s})=>{await d();let r=h(n);await switchChain(a$1,{chainId:r});let i=await sendTransaction(a$1,{account:e,chainId:r,to:t.to,data:t.data});s?.();try{await waitForTransactionReceipt(a$1,{chainId:r,hash:i,timeout:y});}catch(c){throw (await getTransactionReceipt(a$1,{chainId:r,hash:i}).catch(()=>null))?.status==="reverted"?new a("failed","The revocation reverted",{cause:c}):c}},pulsarTransaction:({txKey:t,instructions:n,account:e,connectorType:s,title:r,description:i,payload:c})=>{let o=A(n);return {adapter:OrbitAdapter.EVM,tracker:TransactionTracker.Ethereum,txKey:t,hash:t,chainId:o.chainId,from:e,to:o.token==="native"?o.to:o.token,type:"payment",connectorType:s,title:r,description:i,payload:c,pending:true,localTimestamp:Math.floor(Date.now()/1e3),isTrackedModalOpen:false}}}}export{Z as paymentsEVMAdapter};
1
+ import {a,b}from'../chunk-7HSDAUKN.js';import {OrbitAdapter,toEvmChainId,delay}from'@tuwaio/orbit-core';import {TransactionTracker}from'@tuwaio/pulsar-core';import {sendCalls,waitForCallsStatus,signMessage,getConnectorClient,sendTransaction,writeContract,switchChain,getCapabilities,estimateGas,estimateFeesPerGas,getBalance,readContract,getConnection}from'@wagmi/core';import {erc20Abi,encodeFunctionData}from'viem';var R=18e4,U=30*6e4,G=15e3,V=25n;function h(t){let i=toEvmChainId(t);if(i===void 0)throw new Error(`${t} is not an EVM chain`);return i}function A(t){if(t.family!=="eip155")throw new Error(`${t.chainId} is not an EVM chain`);return t}function S(t){return t.token==="native"?{to:t.to,value:BigInt(t.amount)}:{to:t.token,data:encodeFunctionData({abi:erc20Abi,functionName:"transfer",args:[t.to,BigInt(t.amount)]})}}async function q(t,i,d){try{return {gas:(await estimateGas(t,{account:i,chainId:d.chainId,...S(d)})*(100n+V)+99n)/100n}}catch{return {}}}async function W(t){if(t?.type!=="walletConnect")return false;try{let i=await t.getProvider();return /^safe\b/i.test(i.session?.peer?.metadata?.name??"")}catch{return false}}function X(t){let i=async()=>{let a$1=getConnection(t).connector;if(a$1?.id==="safe"||a$1?.type==="safe"||await W(a$1))throw new a("unsupported","A Safe wallet cannot pay this checkout")},d=async a$1=>{let n;try{n=await getConnection(t).connector?.getChainId();}catch{return}if(!(n===void 0||n===a$1))try{await switchChain(t,{chainId:a$1});}catch(e){let s=b(e);throw s==="declined"?new a("declined",`The wallet declined the switch to ${a$1}`,{cause:e,step:"switch"}):s!=="failed"?e:new a("switchFailed",`The wallet did not switch to ${a$1}`,{cause:e,step:"switch"})}},f=async(a,n,e)=>{for(;Date.now()<n;){try{let s=await waitForCallsStatus(t,{id:a,timeout:n-Date.now()});if(s.status==="failure")return;let r=s.status==="success"?s.receipts?.at(-1)?.transactionHash:void 0;if(r)return e?.(r)}catch{}await delay(void 0,G);}};return {family:"eip155",getBalance:async({chainId:a,account:n,token:e})=>{let s=h(a);return e==="native"?(await getBalance(t,{address:n,chainId:s})).value:readContract(t,{address:e,abi:erc20Abi,functionName:"balanceOf",args:[n],chainId:s})},estimateFee:async({instructions:a,account:n})=>{let e=A(a),s=await estimateGas(t,{account:n,chainId:e.chainId,...S(e)}),r=await estimateFeesPerGas(t,{chainId:e.chainId}),u=r.maxFeePerGas??r.gasPrice;if(u===void 0)return null;let l=t.chains.find(o=>o.id===e.chainId)?.nativeCurrency;return {amount:s*u,decimals:l?.decimals??18,symbol:l?.symbol??"ETH"}},canSponsorCalls:async({chainId:a,account:n})=>{try{return (await getCapabilities(t,{account:n,chainId:h(a)})).paymasterService?.supported===!0}catch{return false}},switchChain:async a=>{await switchChain(t,{chainId:h(a)});},sendTransfer:async({instructions:a,account:n})=>{let e=A(a);if(await i(),await d(e.chainId),e.token==="native"){let s=await q(t,n,e);return sendTransaction(t,{account:n,chainId:e.chainId,to:e.to,value:BigInt(e.amount),...s})}return writeContract(t,{account:n,chainId:e.chainId,address:e.token,abi:erc20Abi,functionName:"transfer",args:[e.to,BigInt(e.amount)]})},signTransferAuthorization:async({typedData:a,account:n})=>{await i();let e=Number(a.domain.chainId);return await d(e),(await getConnectorClient(t,{chainId:e})).request({method:"eth_signTypedData_v4",params:[n,JSON.stringify(a)]})},signMessage:async({message:a,account:n,chainId:e})=>{await i();let s=toEvmChainId(e);return s!==void 0&&await d(s),signMessage(t,{account:n,message:a})},followSponsoredCalls:({batchId:a,until:n,onLate:e})=>{f(a,n,e).catch(()=>{});},sendSponsoredCalls:async({calls:a$1,paymasterUrl:n,chainId:e,account:s,onSent:r,onAccepted:u,onLate:l})=>{await i(),await d(h(e));let{id:o}=await sendCalls(t,{account:s,chainId:h(e),calls:a$1.map(c=>({to:c.to,value:BigInt(c.value),data:c.data})),capabilities:{paymasterService:{url:n}}});u?.(o),r?.();let w=c=>(f(o,Date.now()+U,l).catch(()=>{}),new a("sentUnconfirmed","The sponsored payment is not confirmed yet",{cause:c})),y=await waitForCallsStatus(t,{id:o,timeout:R}).catch(c=>{throw w(c)});if(y.status==="failure")throw new a("failed","The sponsored payment failed");let C=y.status==="success"?y.receipts?.at(-1)?.transactionHash:void 0;if(!C)throw w();return C},explorerUrl:({chainId:a,txKey:n})=>{let s=t.chains.find(r=>r.id===toEvmChainId(a))?.blockExplorers?.default.url;return s?`${s}/tx/${n}`:void 0},explorerAddressUrl:({chainId:a,address:n})=>{let s=t.chains.find(r=>r.id===toEvmChainId(a))?.blockExplorers?.default.url;return s?`${s}/address/${n}`:void 0},pulsarTransaction:({txKey:a,instructions:n,account:e,connectorType:s,title:r,description:u,payload:l})=>{let o=A(n);return {adapter:OrbitAdapter.EVM,tracker:TransactionTracker.Ethereum,txKey:a,hash:a,chainId:o.chainId,from:e,to:o.token==="native"?o.to:o.token,type:"payment",connectorType:s,title:r,description:u,payload:l,pending:true,localTimestamp:Math.floor(Date.now()/1e3),isTrackedModalOpen:false}}}}export{X as paymentsEVMAdapter};
@@ -1 +1 @@
1
- 'use strict';var chunkXOVRZTAM_cjs=require('../chunk-XOVRZTAM.cjs');Object.defineProperty(exports,"CHECKOUT_LOCALES",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.e}});Object.defineProperty(exports,"defaultLabels",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.a}});Object.defineProperty(exports,"formatCountLabel",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.b}});Object.defineProperty(exports,"formatLabel",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.c}});Object.defineProperty(exports,"formatLabelParts",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.d}});Object.defineProperty(exports,"hasLabels",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.f}});Object.defineProperty(exports,"labelsForLocale",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.g}});Object.defineProperty(exports,"loadLabels",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.h}});Object.defineProperty(exports,"mergeLabels",{enumerable:true,get:function(){return chunkXOVRZTAM_cjs.i}});
1
+ 'use strict';var chunk4HBN6N7D_cjs=require('../chunk-4HBN6N7D.cjs');Object.defineProperty(exports,"CHECKOUT_LOCALES",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.e}});Object.defineProperty(exports,"checkoutLocaleOf",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.f}});Object.defineProperty(exports,"defaultLabels",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.a}});Object.defineProperty(exports,"formatCountLabel",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.b}});Object.defineProperty(exports,"formatLabel",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.c}});Object.defineProperty(exports,"formatLabelParts",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.d}});Object.defineProperty(exports,"hasLabels",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.g}});Object.defineProperty(exports,"labelsForLocale",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.h}});Object.defineProperty(exports,"loadLabels",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.i}});Object.defineProperty(exports,"mergeLabels",{enumerable:true,get:function(){return chunk4HBN6N7D_cjs.j}});
@@ -1,5 +1,5 @@
1
- import { N as NovaPaymentsLabels } from '../locales-DzMinYsr.cjs';
2
- export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, h as hasLabels, l as labelsForLocale, c as loadLabels, m as mergeLabels } from '../locales-DzMinYsr.cjs';
1
+ import { N as NovaPaymentsLabels } from '../locales-dTcrLl9B.cjs';
2
+ export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, c as checkoutLocaleOf, h as hasLabels, l as labelsForLocale, d as loadLabels, m as mergeLabels } from '../locales-dTcrLl9B.cjs';
3
3
  export { formatCountLabel, formatLabel, formatLabelParts } from '@tuwaio/nova-core/utils';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { N as NovaPaymentsLabels } from '../locales-DzMinYsr.js';
2
- export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, h as hasLabels, l as labelsForLocale, c as loadLabels, m as mergeLabels } from '../locales-DzMinYsr.js';
1
+ import { N as NovaPaymentsLabels } from '../locales-dTcrLl9B.js';
2
+ export { C as CHECKOUT_LOCALES, a as CheckoutLocale, b as NovaPaymentsLabelOverrides, c as checkoutLocaleOf, h as hasLabels, l as labelsForLocale, d as loadLabels, m as mergeLabels } from '../locales-dTcrLl9B.js';
3
3
  export { formatCountLabel, formatLabel, formatLabelParts } from '@tuwaio/nova-core/utils';
4
4
 
5
5
  /**
@@ -1 +1 @@
1
- export{e as CHECKOUT_LOCALES,a as defaultLabels,b as formatCountLabel,c as formatLabel,d as formatLabelParts,f as hasLabels,g as labelsForLocale,h as loadLabels,i as mergeLabels}from'../chunk-WOAPFVQF.js';
1
+ export{e as CHECKOUT_LOCALES,f as checkoutLocaleOf,a as defaultLabels,b as formatCountLabel,c as formatLabel,d as formatLabelParts,g as hasLabels,h as labelsForLocale,i as loadLabels,j as mergeLabels}from'../chunk-A2WIFZQB.js';