@piprail/sdk 3.0.0 → 3.1.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.
@@ -89,6 +89,13 @@ async function payXrpl(params) {
89
89
  client.feeDrops(),
90
90
  client.currentLedgerIndex()
91
91
  ]);
92
+ for (const [field, value] of [["Sequence", sequence], ["LastLedgerSequence", ledgerIndex]]) {
93
+ if (!Number.isSafeInteger(value) || value < 0) {
94
+ throw new Error(
95
+ `XRPL: could not read ${field} from the ledger (got ${String(value)}) \u2014 the RPC read failed or was throttled. NOTHING was signed or submitted, so this is safe to retry. A dedicated rpcUrl avoids the public cluster's rate limits.`
96
+ );
97
+ }
98
+ }
92
99
  const tx = {
93
100
  TransactionType: "Payment",
94
101
  Account: wallet.classicAddress,
@@ -695,6 +702,8 @@ function resolveXrplWallet(config) {
695
702
  function isXrplActNotFound(e) {
696
703
  return /actNotFound/i.test(String(e?.message ?? e));
697
704
  }
705
+ var XRPL_BASE_RESERVE_DROPS = 1000000n;
706
+ var XRPL_OWNER_RESERVE_DROPS = 200000n;
698
707
  var xrplDriver = {
699
708
  family: "xrpl",
700
709
  resolve(opts) {
@@ -924,16 +933,22 @@ function makeXrplNetwork(preset, rpcUrl) {
924
933
  return { token: null, native: null };
925
934
  }
926
935
  let native = null;
936
+ let ownerCount = 0n;
927
937
  try {
928
938
  const r = await rpc("account_info", {
929
939
  account: owner,
930
940
  ledger_index: "validated"
931
941
  });
932
942
  native = BigInt(r.account_data.Balance);
943
+ ownerCount = BigInt(r.account_data.OwnerCount ?? 0);
933
944
  } catch (e) {
934
945
  native = isXrplActNotFound(e) ? 0n : null;
935
946
  }
936
- if (isXrpNative(asset)) return { token: native, native };
947
+ if (isXrpNative(asset)) {
948
+ if (native === null) return { token: null, native };
949
+ const reserve = XRPL_BASE_RESERVE_DROPS + XRPL_OWNER_RESERVE_DROPS * ownerCount;
950
+ return { token: native > reserve ? native - reserve : 0n, native };
951
+ }
937
952
  let token = null;
938
953
  try {
939
954
  const [currencyHex, issuer] = asset.split(":");
@@ -89,6 +89,13 @@ async function payXrpl(params) {
89
89
  client.feeDrops(),
90
90
  client.currentLedgerIndex()
91
91
  ]);
92
+ for (const [field, value] of [["Sequence", sequence], ["LastLedgerSequence", ledgerIndex]]) {
93
+ if (!Number.isSafeInteger(value) || value < 0) {
94
+ throw new Error(
95
+ `XRPL: could not read ${field} from the ledger (got ${String(value)}) \u2014 the RPC read failed or was throttled. NOTHING was signed or submitted, so this is safe to retry. A dedicated rpcUrl avoids the public cluster's rate limits.`
96
+ );
97
+ }
98
+ }
92
99
  const tx = {
93
100
  TransactionType: "Payment",
94
101
  Account: wallet.classicAddress,
@@ -695,6 +702,8 @@ function resolveXrplWallet(config) {
695
702
  function isXrplActNotFound(e) {
696
703
  return /actNotFound/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _30 => _30.message]), () => ( e))));
697
704
  }
705
+ var XRPL_BASE_RESERVE_DROPS = 1000000n;
706
+ var XRPL_OWNER_RESERVE_DROPS = 200000n;
698
707
  var xrplDriver = {
699
708
  family: "xrpl",
700
709
  resolve(opts) {
@@ -924,16 +933,22 @@ function makeXrplNetwork(preset, rpcUrl) {
924
933
  return { token: null, native: null };
925
934
  }
926
935
  let native = null;
936
+ let ownerCount = 0n;
927
937
  try {
928
938
  const r = await rpc("account_info", {
929
939
  account: owner,
930
940
  ledger_index: "validated"
931
941
  });
932
942
  native = BigInt(r.account_data.Balance);
943
+ ownerCount = BigInt(_nullishCoalesce(r.account_data.OwnerCount, () => ( 0)));
933
944
  } catch (e) {
934
945
  native = isXrplActNotFound(e) ? 0n : null;
935
946
  }
936
- if (isXrpNative(asset)) return { token: native, native };
947
+ if (isXrpNative(asset)) {
948
+ if (native === null) return { token: null, native };
949
+ const reserve = XRPL_BASE_RESERVE_DROPS + XRPL_OWNER_RESERVE_DROPS * ownerCount;
950
+ return { token: native > reserve ? native - reserve : 0n, native };
951
+ }
937
952
  let token = null;
938
953
  try {
939
954
  const [currencyHex, issuer] = asset.split(":");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@piprail/sdk",
3
- "version": "3.0.0",
4
- "description": "Accept x402 crypto payments across 30 chains \u2014 every major EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Algorand, Stellar & XRPL \u2014 in a couple of lines. No backend, no database, no fee; payments settle straight to your wallet.",
3
+ "version": "3.1.0",
4
+ "description": "Accept x402 crypto payments across 30 chains every major EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Algorand, Stellar & XRPL in a couple of lines. No backend, no database, no fee; payments settle straight to your wallet.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",