uvd-x402-sdk 2.97.0 → 2.99.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/README.md +13 -8
- package/dist/backend/index.d.mts +1 -1
- package/dist/backend/index.d.ts +1 -1
- package/dist/backend/index.js +238 -6
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +232 -7
- package/dist/backend/index.mjs.map +1 -1
- package/dist/{index-DNTFp6WT.d.ts → index-BiL4seGs.d.ts} +124 -7
- package/dist/{index-ClOAmprt.d.mts → index-SaqboHsK.d.mts} +124 -7
- package/dist/index.d.mts +28 -6
- package/dist/index.d.ts +28 -6
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +343 -15
- package/src/escrow-preauth.arc-vector.json +101 -0
- package/src/escrow-preauth.ts +45 -4
- package/src/fixtures/arc-escrow-d.rpc.json +553 -0
- package/src/fixtures/escrow-operator-snapshot.json +1254 -0
- package/src/index.ts +1 -0
package/dist/backend/index.mjs
CHANGED
|
@@ -1519,6 +1519,13 @@ var DEFAULT_MIN_FEE_BPS = 0;
|
|
|
1519
1519
|
var DEFAULT_MAX_FEE_BPS = OPERATOR_FEE_BPS + MAX_PROTOCOL_FEE_BPS;
|
|
1520
1520
|
var REVIEW_WINDOW_SEC = 7 * 24 * 3600;
|
|
1521
1521
|
var REFUND_WINDOW_SEC = 7 * 24 * 3600;
|
|
1522
|
+
Object.fromEntries(
|
|
1523
|
+
["arc", "arc-testnet"].map((network) => {
|
|
1524
|
+
const chain = getChainByName(network);
|
|
1525
|
+
if (!chain) throw new Error(`The chain registry has no '${network}'.`);
|
|
1526
|
+
return [chain.chainId, { name: chain.usdc.name, version: chain.usdc.version }];
|
|
1527
|
+
})
|
|
1528
|
+
);
|
|
1522
1529
|
var LIFECYCLE_DOMAIN_NAME = "x402 escrow lifecycle";
|
|
1523
1530
|
var LIFECYCLE_DOMAIN_VERSION = "1";
|
|
1524
1531
|
var LIFECYCLE_MAX_DEADLINE_SECS = 900;
|
|
@@ -3677,7 +3684,7 @@ var TESTNET_VALIDATION = "0x8004Cb1BF31DAf7788923b405b754f57acEB4272";
|
|
|
3677
3684
|
var SOLANA_AGENT_REGISTRY = "8oo4dC4JvBLwy5tGgiH3WwK4B9PWxL9Z4XjA2jzkQMbQ";
|
|
3678
3685
|
var SOLANA_ATOM_ENGINE = "AToMw53aiPQ8j7iHVb4fGt6nzUNxUhcPc3tbPBZuzVVb";
|
|
3679
3686
|
var ERC8004_CONTRACTS = {
|
|
3680
|
-
// Mainnets (
|
|
3687
|
+
// Mainnets (12)
|
|
3681
3688
|
ethereum: {
|
|
3682
3689
|
identityRegistry: MAINNET_IDENTITY,
|
|
3683
3690
|
reputationRegistry: MAINNET_REPUTATION,
|
|
@@ -3734,13 +3741,22 @@ var ERC8004_CONTRACTS = {
|
|
|
3734
3741
|
identityRegistry: MAINNET_IDENTITY,
|
|
3735
3742
|
reputationRegistry: MAINNET_REPUTATION
|
|
3736
3743
|
},
|
|
3744
|
+
// Arc (Circle, chain 5042). The facilitator names these three in
|
|
3745
|
+
// ARC_MAINNET_CONTRACTS (x402-rs 2.37.0+). Read on 2026-09-23 against
|
|
3746
|
+
// rpc.mainnet.arc.io: each is a 130-byte EIP-1967 proxy whose implementation
|
|
3747
|
+
// is the one Base runs, and getVersion() answers 2.0.0.
|
|
3748
|
+
arc: {
|
|
3749
|
+
identityRegistry: MAINNET_IDENTITY,
|
|
3750
|
+
reputationRegistry: MAINNET_REPUTATION,
|
|
3751
|
+
validationRegistry: MAINNET_VALIDATION
|
|
3752
|
+
},
|
|
3737
3753
|
// Deprecated alias for 'base' -- kept so existing lookups keep resolving.
|
|
3738
3754
|
"base-mainnet": {
|
|
3739
3755
|
identityRegistry: MAINNET_IDENTITY,
|
|
3740
3756
|
reputationRegistry: MAINNET_REPUTATION,
|
|
3741
3757
|
validationRegistry: MAINNET_VALIDATION
|
|
3742
3758
|
},
|
|
3743
|
-
// Testnets (
|
|
3759
|
+
// Testnets (9)
|
|
3744
3760
|
"ethereum-sepolia": {
|
|
3745
3761
|
identityRegistry: TESTNET_IDENTITY,
|
|
3746
3762
|
reputationRegistry: TESTNET_REPUTATION,
|
|
@@ -3781,6 +3797,15 @@ var ERC8004_CONTRACTS = {
|
|
|
3781
3797
|
reputationRegistry: TESTNET_REPUTATION,
|
|
3782
3798
|
validationRegistry: TESTNET_VALIDATION
|
|
3783
3799
|
},
|
|
3800
|
+
// Arc testnet (chain 5042002), ARC_TESTNET_CONTRACTS in the facilitator. Read
|
|
3801
|
+
// on 2026-09-23 against rpc.testnet.arc.io and rpc.testnet.arc.network: the
|
|
3802
|
+
// proxies Base Sepolia runs, validation registry included. Reads only -- no
|
|
3803
|
+
// FeedbackDelegate is deployed here, so it is not in RELAYED_FEEDBACK_NETWORKS.
|
|
3804
|
+
"arc-testnet": {
|
|
3805
|
+
identityRegistry: TESTNET_IDENTITY,
|
|
3806
|
+
reputationRegistry: TESTNET_REPUTATION,
|
|
3807
|
+
validationRegistry: TESTNET_VALIDATION
|
|
3808
|
+
},
|
|
3784
3809
|
// Solana (2) - uses QuantuLabs 8004-solana Anchor program + ATOM Engine
|
|
3785
3810
|
solana: {
|
|
3786
3811
|
agentRegistryProgram: SOLANA_AGENT_REGISTRY,
|
|
@@ -3803,6 +3828,7 @@ var RELAYED_FEEDBACK_NETWORKS = [
|
|
|
3803
3828
|
"celo",
|
|
3804
3829
|
"bsc",
|
|
3805
3830
|
"monad",
|
|
3831
|
+
"arc",
|
|
3806
3832
|
"base-sepolia"
|
|
3807
3833
|
];
|
|
3808
3834
|
function supportsRelayedFeedback(network) {
|
|
@@ -4921,6 +4947,11 @@ var ESCROW_TIMEOUT_MS = {
|
|
|
4921
4947
|
// Monad: 90s
|
|
4922
4948
|
};
|
|
4923
4949
|
var DEFAULT_ESCROW_TIMEOUT_MS = 3e4;
|
|
4950
|
+
function arcUsdc(network) {
|
|
4951
|
+
const chain = getChainByName(network);
|
|
4952
|
+
if (!chain) throw new Error(`The chain registry has no '${network}'.`);
|
|
4953
|
+
return chain.usdc;
|
|
4954
|
+
}
|
|
4924
4955
|
var USDC_DOMAIN_NAME = {
|
|
4925
4956
|
8453: "USD Coin",
|
|
4926
4957
|
// Base Mainnet
|
|
@@ -4938,8 +4969,12 @@ var USDC_DOMAIN_NAME = {
|
|
|
4938
4969
|
// Avalanche
|
|
4939
4970
|
42220: "USDC",
|
|
4940
4971
|
// Celo
|
|
4941
|
-
143: "USDC"
|
|
4972
|
+
143: "USDC",
|
|
4942
4973
|
// Monad
|
|
4974
|
+
5042: arcUsdc("arc").name,
|
|
4975
|
+
// Arc ('USDC', from src/chains)
|
|
4976
|
+
5042002: arcUsdc("arc-testnet").name
|
|
4977
|
+
// Arc Testnet ('USDC', from src/chains)
|
|
4943
4978
|
};
|
|
4944
4979
|
var ESCROW_CONTRACTS = {
|
|
4945
4980
|
// Base Sepolia (testnet, chain 84532)
|
|
@@ -5040,6 +5075,24 @@ var ESCROW_CONTRACTS = {
|
|
|
5040
5075
|
protocolFeeConfig: "0xf62788834C99B2E85a6891C0b46D1EB996f8f596",
|
|
5041
5076
|
refundRequest: "0x69e9BF2b40Ed472b55E47e9D4205d93Ed673093F",
|
|
5042
5077
|
usdc: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20"
|
|
5078
|
+
},
|
|
5079
|
+
// Arc (chain 5042) - x402r canonical escrow, 'v3' operator
|
|
5080
|
+
5042: {
|
|
5081
|
+
operator: "0x0258472A1410Ac3Ad720f1BC83f22B3c0af1Fd9D",
|
|
5082
|
+
escrow: "0xBdEA0D1bcC5966192B070Fdf62aB4EF5b4420cff",
|
|
5083
|
+
tokenCollector: "0x0E3dF9510de65469C4518D7843919c0b8C7A7757",
|
|
5084
|
+
protocolFeeConfig: "0xBe2d24614F339a1eB103A399F93AA2a39Ca815Bc",
|
|
5085
|
+
refundRequest: "0xe971C674fD5c3462023f3F891dF6289DFbC9CEFC",
|
|
5086
|
+
usdc: arcUsdc("arc").address
|
|
5087
|
+
},
|
|
5088
|
+
// Arc Testnet (chain 5042002) - same canonical addresses as Arc
|
|
5089
|
+
5042002: {
|
|
5090
|
+
operator: "0x0258472A1410Ac3Ad720f1BC83f22B3c0af1Fd9D",
|
|
5091
|
+
escrow: "0xBdEA0D1bcC5966192B070Fdf62aB4EF5b4420cff",
|
|
5092
|
+
tokenCollector: "0x0E3dF9510de65469C4518D7843919c0b8C7A7757",
|
|
5093
|
+
protocolFeeConfig: "0xBe2d24614F339a1eB103A399F93AA2a39Ca815Bc",
|
|
5094
|
+
refundRequest: "0xe971C674fD5c3462023f3F891dF6289DFbC9CEFC",
|
|
5095
|
+
usdc: arcUsdc("arc-testnet").address
|
|
5043
5096
|
}
|
|
5044
5097
|
};
|
|
5045
5098
|
var BASE_MAINNET_CONTRACTS = ESCROW_CONTRACTS[8453];
|
|
@@ -5089,7 +5142,56 @@ var OPERATOR_ABI_CREATE3 = [
|
|
|
5089
5142
|
"function charge(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)",
|
|
5090
5143
|
"function refundPostEscrow(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)"
|
|
5091
5144
|
];
|
|
5092
|
-
var
|
|
5145
|
+
var OPERATOR_ABI_V3 = [
|
|
5146
|
+
"function capture(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, bytes data)",
|
|
5147
|
+
"function void(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, bytes data)",
|
|
5148
|
+
"function refund(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount, address tokenCollector, bytes collectorData)",
|
|
5149
|
+
"function FEE_RECEIVER() view returns (address)",
|
|
5150
|
+
"function AUTHORIZE_PRE_ACTION_CONDITION() view returns (address)",
|
|
5151
|
+
"function CHARGE_PRE_ACTION_CONDITION() view returns (address)",
|
|
5152
|
+
"function CAPTURE_PRE_ACTION_CONDITION() view returns (address)",
|
|
5153
|
+
"function VOID_PRE_ACTION_CONDITION() view returns (address)",
|
|
5154
|
+
"function REFUND_PRE_ACTION_CONDITION() view returns (address)"
|
|
5155
|
+
];
|
|
5156
|
+
var AUTH_CAPTURE_ESCROW_STATE_ABI = [
|
|
5157
|
+
"function getHash(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo) view returns (bytes32)",
|
|
5158
|
+
"function paymentState(bytes32 paymentInfoHash) view returns (bool hasCollectedPayment, uint120 capturableAmount, uint120 refundableAmount)"
|
|
5159
|
+
];
|
|
5160
|
+
var ESCROW_VOID_AMOUNT_MISMATCH = "escrow_void_amount_mismatch";
|
|
5161
|
+
var ESCROW_NOTHING_TO_VOID = "escrow_nothing_to_void";
|
|
5162
|
+
var ESCROW_OPERATOR_NOT_DEPLOYED = "escrow_operator_not_deployed";
|
|
5163
|
+
var ESCROW_UNSUPPORTED_ON_GENERATION = "escrow_unsupported_on_generation";
|
|
5164
|
+
var ESCROW_OPERATOR_GENERATION = {
|
|
5165
|
+
84532: "v1",
|
|
5166
|
+
// Base Sepolia
|
|
5167
|
+
8453: "v1",
|
|
5168
|
+
// Base
|
|
5169
|
+
11155111: "v1",
|
|
5170
|
+
// Ethereum Sepolia
|
|
5171
|
+
1: "v1",
|
|
5172
|
+
// Ethereum
|
|
5173
|
+
137: "v1",
|
|
5174
|
+
// Polygon
|
|
5175
|
+
42161: "v1",
|
|
5176
|
+
// Arbitrum
|
|
5177
|
+
42220: "v1",
|
|
5178
|
+
// Celo
|
|
5179
|
+
143: "v1",
|
|
5180
|
+
// Monad
|
|
5181
|
+
43114: "v1",
|
|
5182
|
+
// Avalanche
|
|
5183
|
+
10: "v1",
|
|
5184
|
+
// Optimism
|
|
5185
|
+
1187947933: "v2",
|
|
5186
|
+
// SKALE Base
|
|
5187
|
+
5042: "v3",
|
|
5188
|
+
// Arc
|
|
5189
|
+
5042002: "v3"
|
|
5190
|
+
// Arc Testnet
|
|
5191
|
+
};
|
|
5192
|
+
function getEscrowOperatorGeneration(chainId) {
|
|
5193
|
+
return ESCROW_OPERATOR_GENERATION[chainId] ?? "v1";
|
|
5194
|
+
}
|
|
5093
5195
|
var AdvancedEscrowClient = class {
|
|
5094
5196
|
facilitatorUrl;
|
|
5095
5197
|
chainId;
|
|
@@ -5395,6 +5497,10 @@ var AdvancedEscrowClient = class {
|
|
|
5395
5497
|
*
|
|
5396
5498
|
* Calls PaymentOperator.release() -> escrow.capture()
|
|
5397
5499
|
*
|
|
5500
|
+
* On a `'v3'` operator (Arc, Arc Testnet) it calls
|
|
5501
|
+
* `PaymentOperator.capture(paymentInfo, amount, 0x)` instead, after checking
|
|
5502
|
+
* that the operator has code ({@link ESCROW_OPERATOR_NOT_DEPLOYED}).
|
|
5503
|
+
*
|
|
5398
5504
|
* @param paymentInfo - PaymentInfo from the authorize step
|
|
5399
5505
|
* @param amount - Amount to release (defaults to maxAmount)
|
|
5400
5506
|
*/
|
|
@@ -5402,10 +5508,14 @@ var AdvancedEscrowClient = class {
|
|
|
5402
5508
|
if (!this.payerAddress) await this.init();
|
|
5403
5509
|
try {
|
|
5404
5510
|
const { ethers: ethers4 } = await import('ethers');
|
|
5405
|
-
const
|
|
5511
|
+
const generation = getEscrowOperatorGeneration(this.chainId);
|
|
5512
|
+
const isCreate3 = generation === "v2";
|
|
5406
5513
|
const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
|
|
5407
5514
|
const amt = amount || paymentInfo.maxAmount;
|
|
5408
5515
|
const tuple = this.buildTuple(paymentInfo);
|
|
5516
|
+
if (generation === "v3") {
|
|
5517
|
+
return await this.sendV3OperatorCall(ethers4, this.v3Provider(ethers4), "capture", [tuple, amt, "0x"]);
|
|
5518
|
+
}
|
|
5409
5519
|
if (this.walletAdapter) {
|
|
5410
5520
|
return this.sendViaAdapter(ethers4, abi, (iface) => {
|
|
5411
5521
|
return isCreate3 ? iface.encodeFunctionData("release", [tuple, amt, "0x"]) : iface.encodeFunctionData("release", [tuple, amt]);
|
|
@@ -5429,6 +5539,16 @@ var AdvancedEscrowClient = class {
|
|
|
5429
5539
|
*
|
|
5430
5540
|
* Calls PaymentOperator.refundInEscrow() -> escrow.partialVoid()
|
|
5431
5541
|
*
|
|
5542
|
+
* On a `'v3'` operator (Arc, Arc Testnet) it calls
|
|
5543
|
+
* `PaymentOperator.void(paymentInfo, 0x)`, which takes no amount and returns
|
|
5544
|
+
* the WHOLE `capturableAmount`. So it first reads that amount on-chain
|
|
5545
|
+
* (`AuthCaptureEscrow.getHash` + `paymentState`) and sends only when
|
|
5546
|
+
* `amount` equals it. Otherwise nothing is sent and `errorCode` says why:
|
|
5547
|
+
* {@link ESCROW_NOTHING_TO_VOID} when it is 0,
|
|
5548
|
+
* {@link ESCROW_VOID_AMOUNT_MISMATCH} for any other amount. To return part
|
|
5549
|
+
* of an escrow on v3, `release` the part the receiver keeps, then
|
|
5550
|
+
* `refundInEscrow` what is left.
|
|
5551
|
+
*
|
|
5432
5552
|
* @param paymentInfo - PaymentInfo from the authorize step
|
|
5433
5553
|
* @param amount - Amount to refund (defaults to maxAmount)
|
|
5434
5554
|
*/
|
|
@@ -5436,10 +5556,14 @@ var AdvancedEscrowClient = class {
|
|
|
5436
5556
|
if (!this.payerAddress) await this.init();
|
|
5437
5557
|
try {
|
|
5438
5558
|
const { ethers: ethers4 } = await import('ethers');
|
|
5439
|
-
const
|
|
5559
|
+
const generation = getEscrowOperatorGeneration(this.chainId);
|
|
5560
|
+
const isCreate3 = generation === "v2";
|
|
5440
5561
|
const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
|
|
5441
5562
|
const amt = amount || paymentInfo.maxAmount;
|
|
5442
5563
|
const tuple = this.buildTuple(paymentInfo);
|
|
5564
|
+
if (generation === "v3") {
|
|
5565
|
+
return await this.voidWholeCapturable(ethers4, tuple, amt);
|
|
5566
|
+
}
|
|
5443
5567
|
if (this.walletAdapter) {
|
|
5444
5568
|
return this.sendViaAdapter(ethers4, abi, (iface) => {
|
|
5445
5569
|
return isCreate3 ? iface.encodeFunctionData("refundInEscrow", [tuple, amt, "0x"]) : iface.encodeFunctionData("refundInEscrow", [tuple, amt]);
|
|
@@ -5774,10 +5898,15 @@ var AdvancedEscrowClient = class {
|
|
|
5774
5898
|
* Calls PaymentOperator.charge() -> escrow.charge()
|
|
5775
5899
|
* Funds go directly from payer to receiver.
|
|
5776
5900
|
*
|
|
5901
|
+
* Not available on a `'v3'` operator (Arc, Arc Testnet): it returns
|
|
5902
|
+
* {@link ESCROW_UNSUPPORTED_ON_GENERATION} without signing or sending.
|
|
5903
|
+
*
|
|
5777
5904
|
* @param paymentInfo - PaymentInfo with receiver and amount
|
|
5778
5905
|
* @param amount - Amount to charge (defaults to maxAmount)
|
|
5779
5906
|
*/
|
|
5780
5907
|
async charge(paymentInfo, amount) {
|
|
5908
|
+
const unsupported = this.unsupportedOnV3("charge");
|
|
5909
|
+
if (unsupported) return unsupported;
|
|
5781
5910
|
if (!this.payerAddress) await this.init();
|
|
5782
5911
|
try {
|
|
5783
5912
|
const { ethers: ethers4 } = await import('ethers');
|
|
@@ -5838,6 +5967,11 @@ var AdvancedEscrowClient = class {
|
|
|
5838
5967
|
*
|
|
5839
5968
|
* Kept for future use when tokenCollector is implemented.
|
|
5840
5969
|
*
|
|
5970
|
+
* On a `'v3'` operator (Arc, Arc Testnet) it calls
|
|
5971
|
+
* `PaymentOperator.refund(paymentInfo, amount, tokenCollector, collectorData)`
|
|
5972
|
+
* -> escrow.refund(), the same arguments, after checking that the operator
|
|
5973
|
+
* has code ({@link ESCROW_OPERATOR_NOT_DEPLOYED}).
|
|
5974
|
+
*
|
|
5841
5975
|
* @param paymentInfo - PaymentInfo from the original authorization
|
|
5842
5976
|
* @param amount - Amount to refund (defaults to maxAmount)
|
|
5843
5977
|
* @param tokenCollector - Address of token collector for refund sourcing
|
|
@@ -5849,6 +5983,14 @@ var AdvancedEscrowClient = class {
|
|
|
5849
5983
|
const { ethers: ethers4 } = await import('ethers');
|
|
5850
5984
|
const amt = amount || paymentInfo.maxAmount;
|
|
5851
5985
|
const tuple = this.buildTuple(paymentInfo);
|
|
5986
|
+
if (getEscrowOperatorGeneration(this.chainId) === "v3") {
|
|
5987
|
+
return await this.sendV3OperatorCall(ethers4, this.v3Provider(ethers4), "refund", [
|
|
5988
|
+
tuple,
|
|
5989
|
+
amt,
|
|
5990
|
+
tokenCollector || ZERO_ADDRESS,
|
|
5991
|
+
collectorData || "0x"
|
|
5992
|
+
]);
|
|
5993
|
+
}
|
|
5852
5994
|
if (this.walletAdapter) {
|
|
5853
5995
|
return this.sendViaAdapter(ethers4, OPERATOR_ABI, (iface) => {
|
|
5854
5996
|
return iface.encodeFunctionData("refundPostEscrow", [
|
|
@@ -5879,6 +6021,89 @@ var AdvancedEscrowClient = class {
|
|
|
5879
6021
|
}
|
|
5880
6022
|
}
|
|
5881
6023
|
// ==========================================================================
|
|
6024
|
+
// INTERNAL: 'v3' operator (Arc, Arc Testnet)
|
|
6025
|
+
// ==========================================================================
|
|
6026
|
+
/** The refusal of a call a 'v3' operator does not have, or null elsewhere. */
|
|
6027
|
+
unsupportedOnV3(method) {
|
|
6028
|
+
if (getEscrowOperatorGeneration(this.chainId) !== "v3") return null;
|
|
6029
|
+
return {
|
|
6030
|
+
success: false,
|
|
6031
|
+
errorCode: ESCROW_UNSUPPORTED_ON_GENERATION,
|
|
6032
|
+
error: `${method} is not available on the v3 escrow operator of chain ${this.chainId} (OPERATOR_ABI_V3). Nothing was signed or sent.`
|
|
6033
|
+
};
|
|
6034
|
+
}
|
|
6035
|
+
/** The provider a 'v3' call reads with before it sends anything. */
|
|
6036
|
+
v3Provider(ethersModule) {
|
|
6037
|
+
const provider = this.walletAdapter ? new ethersModule.JsonRpcProvider(this.rpcUrl) : this.signer?.provider;
|
|
6038
|
+
if (!provider) {
|
|
6039
|
+
throw new Error(
|
|
6040
|
+
`AdvancedEscrowClient: chain ${this.chainId} uses a v3 escrow operator, which is read on-chain before any call; the signer has no provider to read with.`
|
|
6041
|
+
);
|
|
6042
|
+
}
|
|
6043
|
+
return provider;
|
|
6044
|
+
}
|
|
6045
|
+
/**
|
|
6046
|
+
* Send one OPERATOR_ABI_V3 call, once the operator is known to have code.
|
|
6047
|
+
* A call to an address with no code succeeds and moves nothing, and would be
|
|
6048
|
+
* reported as a success.
|
|
6049
|
+
*/
|
|
6050
|
+
async sendV3OperatorCall(ethersModule, provider, method, args) {
|
|
6051
|
+
const code = await provider.getCode(this.contracts.operator);
|
|
6052
|
+
if (!code || code === "0x") {
|
|
6053
|
+
return {
|
|
6054
|
+
success: false,
|
|
6055
|
+
errorCode: ESCROW_OPERATOR_NOT_DEPLOYED,
|
|
6056
|
+
error: `The escrow operator ${this.contracts.operator} has no code on chain ${this.chainId}. Nothing was sent.`
|
|
6057
|
+
};
|
|
6058
|
+
}
|
|
6059
|
+
if (this.walletAdapter) {
|
|
6060
|
+
return await this.sendViaAdapter(
|
|
6061
|
+
ethersModule,
|
|
6062
|
+
OPERATOR_ABI_V3,
|
|
6063
|
+
(iface) => iface.encodeFunctionData(method, args)
|
|
6064
|
+
);
|
|
6065
|
+
}
|
|
6066
|
+
const contract = new ethersModule.Contract(this.contracts.operator, OPERATOR_ABI_V3, this.signer);
|
|
6067
|
+
const tx = await contract.getFunction(method)(...args, { gasLimit: this.gasLimit });
|
|
6068
|
+
const receipt = await tx.wait();
|
|
6069
|
+
return {
|
|
6070
|
+
success: receipt.status === 1,
|
|
6071
|
+
transactionHash: receipt.hash,
|
|
6072
|
+
gasUsed: Number(receipt.gasUsed),
|
|
6073
|
+
error: receipt.status !== 1 ? "Transaction reverted" : void 0
|
|
6074
|
+
};
|
|
6075
|
+
}
|
|
6076
|
+
/**
|
|
6077
|
+
* `refundInEscrow` on a 'v3' operator: `void` returns the whole capturable
|
|
6078
|
+
* amount, so it is sent only when that is exactly what was asked for.
|
|
6079
|
+
*/
|
|
6080
|
+
async voidWholeCapturable(ethersModule, tuple, amount) {
|
|
6081
|
+
const requested = BigInt(amount);
|
|
6082
|
+
if (requested <= 0n) {
|
|
6083
|
+
return { success: false, error: `refundInEscrow amount must be positive, got ${amount}. Nothing was sent.` };
|
|
6084
|
+
}
|
|
6085
|
+
const provider = this.v3Provider(ethersModule);
|
|
6086
|
+
const escrow = new ethersModule.Contract(this.contracts.escrow, AUTH_CAPTURE_ESCROW_STATE_ABI, provider);
|
|
6087
|
+
const paymentInfoHash = await escrow.getHash(tuple);
|
|
6088
|
+
const [, capturable] = await escrow.paymentState(paymentInfoHash);
|
|
6089
|
+
const capturableAmount = BigInt(capturable);
|
|
6090
|
+
if (capturableAmount === 0n) {
|
|
6091
|
+
return {
|
|
6092
|
+
success: false,
|
|
6093
|
+
errorCode: ESCROW_NOTHING_TO_VOID,
|
|
6094
|
+
error: `Nothing to void on chain ${this.chainId}: capturableAmount is 0 for payment ${paymentInfoHash}. Nothing was sent.`
|
|
6095
|
+
};
|
|
6096
|
+
}
|
|
6097
|
+
if (requested !== capturableAmount) {
|
|
6098
|
+
return {
|
|
6099
|
+
success: false,
|
|
6100
|
+
errorCode: ESCROW_VOID_AMOUNT_MISMATCH,
|
|
6101
|
+
error: `refundInEscrow asked for ${requested} but the v3 operator's void() returns the whole capturableAmount, ${capturableAmount}. Pass ${capturableAmount}, or release the part the receiver keeps first. Nothing was sent.`
|
|
6102
|
+
};
|
|
6103
|
+
}
|
|
6104
|
+
return await this.sendV3OperatorCall(ethersModule, provider, "void", [tuple, "0x"]);
|
|
6105
|
+
}
|
|
6106
|
+
// ==========================================================================
|
|
5882
6107
|
// INTERNAL: Adapter-based transaction signing and broadcast
|
|
5883
6108
|
// ==========================================================================
|
|
5884
6109
|
/**
|
|
@@ -5922,6 +6147,6 @@ var AdvancedEscrowClient = class {
|
|
|
5922
6147
|
}
|
|
5923
6148
|
};
|
|
5924
6149
|
|
|
5925
|
-
export { AMBIGUOUS_LEASE_REASONS, AUTHORIZATION_ALREADY_SETTLED, AUTHORIZATION_IN_FLIGHT, AdvancedEscrowClient, BASE_MAINNET_CONTRACTS, BazaarClient, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, Erc8004LookupError, EscrowClient, FacilitatorClient, HEALTH_FILTERS, IDEMPOTENCY_KEY_HEADER, IDEMPOTENT_REPLAYED_HEADER, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, RECEIPT_ISSUER, RECEIPT_REQUEST_CONFLICT, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, RegistrationPendingError, SETTLEMENT_UNCONFIRMED, SOLANA_FEEDBACK_NETWORKS, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, WRITER_LEASE_REASONS, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentConflictResponse, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildUnavailableResponse, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, canonicalReceiptJson, carryFailureFields, create402Response, createHonoMiddleware, createIdempotencyKey, createPaymentMiddleware, createPurchaseContext, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, fetchWithReceipt, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, getFacilitatorReceipt, isAlive, isAmbiguousLeaseReason, isAuthorizationAlreadyUsed, isAuthorizationInFlight, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, isSettlementUnconfirmed, mergeHeaderList, mergePaymentResponseHeaders, parseFacilitatorErrorBody, parseFacilitatorReceipt, parsePaymentHeader, parseRetryAfterSeconds, paymentResponseHeaders, purchaseContextHeader, readFacilitatorError, receiptCommitment, receiptFromErrorBody, receiptFromResponse, resolveEnvelopeVersion, supportsRelayedFeedback, supportsSolanaFeedback, toPaymentRequirementsV2, toResourceInfoV2, validatePurchaseContext, verifyFacilitatorReceipt, wireNetwork };
|
|
6150
|
+
export { AMBIGUOUS_LEASE_REASONS, AUTHORIZATION_ALREADY_SETTLED, AUTHORIZATION_IN_FLIGHT, AdvancedEscrowClient, BASE_MAINNET_CONTRACTS, BazaarClient, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_NOTHING_TO_VOID, ESCROW_OPERATOR_GENERATION, ESCROW_OPERATOR_NOT_DEPLOYED, ESCROW_TIMEOUT_MS, ESCROW_UNSUPPORTED_ON_GENERATION, ESCROW_VOID_AMOUNT_MISMATCH, Erc8004Client, Erc8004LookupError, EscrowClient, FacilitatorClient, HEALTH_FILTERS, IDEMPOTENCY_KEY_HEADER, IDEMPOTENT_REPLAYED_HEADER, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, OPERATOR_ABI, OPERATOR_ABI_CREATE3, OPERATOR_ABI_V3, PAYMENT_INFO_TYPEHASH, RECEIPT_ISSUER, RECEIPT_REQUEST_CONFLICT, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, RegistrationPendingError, SETTLEMENT_UNCONFIRMED, SOLANA_FEEDBACK_NETWORKS, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, WRITER_LEASE_REASONS, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentConflictResponse, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildUnavailableResponse, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, canonicalReceiptJson, carryFailureFields, create402Response, createHonoMiddleware, createIdempotencyKey, createPaymentMiddleware, createPurchaseContext, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, fetchWithReceipt, getCorsHeaders, getEscrowContractsByChainId, getEscrowOperatorGeneration, getEscrowSupportedChainIds, getFacilitatorReceipt, isAlive, isAmbiguousLeaseReason, isAuthorizationAlreadyUsed, isAuthorizationInFlight, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, isSettlementUnconfirmed, mergeHeaderList, mergePaymentResponseHeaders, parseFacilitatorErrorBody, parseFacilitatorReceipt, parsePaymentHeader, parseRetryAfterSeconds, paymentResponseHeaders, purchaseContextHeader, readFacilitatorError, receiptCommitment, receiptFromErrorBody, receiptFromResponse, resolveEnvelopeVersion, supportsRelayedFeedback, supportsSolanaFeedback, toPaymentRequirementsV2, toResourceInfoV2, validatePurchaseContext, verifyFacilitatorReceipt, wireNetwork };
|
|
5926
6151
|
//# sourceMappingURL=index.mjs.map
|
|
5927
6152
|
//# sourceMappingURL=index.mjs.map
|