@wopr-network/platform-core 1.35.1 → 1.36.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.
@@ -28,8 +28,9 @@ export async function settleBtcPayment(deps, event) {
28
28
  if (await creditLedger.hasReferenceId(creditRef)) {
29
29
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
30
30
  }
31
- // Underpayment check
32
- if (event.amountUsdCents < charge.amountUsdCents) {
31
+ // 2% underpayment tolerance for oracle price drift between checkout and settlement.
32
+ const UNDERPAYMENT_TOLERANCE = 0.98;
33
+ if (event.amountUsdCents < charge.amountUsdCents * UNDERPAYMENT_TOLERANCE) {
33
34
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
34
35
  }
35
36
  const creditCents = charge.amountUsdCents;
@@ -26,7 +26,9 @@ export async function settleEthPayment(deps, event) {
26
26
  if (await creditLedger.hasReferenceId(creditRef)) {
27
27
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
28
28
  }
29
- if (event.amountUsdCents < charge.amountUsdCents) {
29
+ // 2% underpayment tolerance for oracle price drift between checkout and settlement.
30
+ const UNDERPAYMENT_TOLERANCE = 0.98;
31
+ if (event.amountUsdCents < charge.amountUsdCents * UNDERPAYMENT_TOLERANCE) {
30
32
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
31
33
  }
32
34
  const creditCents = charge.amountUsdCents;
@@ -7,6 +7,8 @@ export interface UnifiedCheckoutDeps {
7
7
  oracle: IPriceOracle;
8
8
  evmXpub: string;
9
9
  btcXpub?: string;
10
+ /** UTXO network override (auto-detected from node in production). Default: "mainnet". */
11
+ utxoNetwork?: "mainnet" | "testnet" | "regtest";
10
12
  }
11
13
  export interface UnifiedCheckoutResult {
12
14
  depositAddress: string;
@@ -53,7 +53,7 @@ async function handleNativeEvm(deps, method, tenant, amountUsdCents, amountUsd)
53
53
  amountUsd,
54
54
  token: "ETH",
55
55
  chain: method.chain,
56
- referenceId: `eth:${method.chain}:${depositAddress}`,
56
+ referenceId: `${method.type}:${method.chain}:${depositAddress}`,
57
57
  priceCents,
58
58
  };
59
59
  }
@@ -77,7 +77,7 @@ async function handleNativeUtxo(deps, method, tenant, amountUsdCents, amountUsd)
77
77
  depositAddress = deriveP2pkhAddress(xpub, derivationIndex, "dogecoin");
78
78
  }
79
79
  else {
80
- depositAddress = deriveAddress(xpub, derivationIndex, "mainnet", method.chain);
80
+ depositAddress = deriveAddress(xpub, derivationIndex, deps.utxoNetwork ?? "mainnet", method.chain);
81
81
  }
82
82
  const referenceId = `${method.token.toLowerCase()}:${depositAddress}`;
83
83
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/platform-core",
3
- "version": "1.35.1",
3
+ "version": "1.36.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,8 +44,9 @@ export async function settleBtcPayment(deps: BtcSettlerDeps, event: BtcPaymentEv
44
44
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
45
45
  }
46
46
 
47
- // Underpayment check
48
- if (event.amountUsdCents < charge.amountUsdCents) {
47
+ // 2% underpayment tolerance for oracle price drift between checkout and settlement.
48
+ const UNDERPAYMENT_TOLERANCE = 0.98;
49
+ if (event.amountUsdCents < charge.amountUsdCents * UNDERPAYMENT_TOLERANCE) {
49
50
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
50
51
  }
51
52
 
@@ -42,7 +42,9 @@ export async function settleEthPayment(deps: EthSettlerDeps, event: EthPaymentEv
42
42
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
43
43
  }
44
44
 
45
- if (event.amountUsdCents < charge.amountUsdCents) {
45
+ // 2% underpayment tolerance for oracle price drift between checkout and settlement.
46
+ const UNDERPAYMENT_TOLERANCE = 0.98;
47
+ if (event.amountUsdCents < charge.amountUsdCents * UNDERPAYMENT_TOLERANCE) {
46
48
  return { handled: true, status: "Settled", tenant: charge.tenantId, creditedCents: 0 };
47
49
  }
48
50
 
@@ -13,6 +13,8 @@ export interface UnifiedCheckoutDeps {
13
13
  oracle: IPriceOracle;
14
14
  evmXpub: string;
15
15
  btcXpub?: string;
16
+ /** UTXO network override (auto-detected from node in production). Default: "mainnet". */
17
+ utxoNetwork?: "mainnet" | "testnet" | "regtest";
16
18
  }
17
19
 
18
20
  export interface UnifiedCheckoutResult {
@@ -101,7 +103,7 @@ async function handleNativeEvm(
101
103
  amountUsd,
102
104
  token: "ETH",
103
105
  chain: method.chain,
104
- referenceId: `eth:${method.chain}:${depositAddress}`,
106
+ referenceId: `${method.type}:${method.chain}:${depositAddress}`,
105
107
  priceCents,
106
108
  };
107
109
  }
@@ -133,7 +135,12 @@ async function handleNativeUtxo(
133
135
  if (method.chain === "dogecoin") {
134
136
  depositAddress = deriveP2pkhAddress(xpub, derivationIndex, "dogecoin");
135
137
  } else {
136
- depositAddress = deriveAddress(xpub, derivationIndex, "mainnet", method.chain as "bitcoin" | "litecoin");
138
+ depositAddress = deriveAddress(
139
+ xpub,
140
+ derivationIndex,
141
+ deps.utxoNetwork ?? "mainnet",
142
+ method.chain as "bitcoin" | "litecoin",
143
+ );
137
144
  }
138
145
 
139
146
  const referenceId = `${method.token.toLowerCase()}:${depositAddress}`;