@antseed/node 0.2.106 → 0.2.107
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/dist/billing/index.d.ts +2 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +2 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing/unit.d.ts +3 -0
- package/dist/billing/unit.d.ts.map +1 -0
- package/dist/billing/unit.js +3 -0
- package/dist/billing/unit.js.map +1 -0
- package/dist/buyer-request-handler.d.ts +1 -54
- package/dist/buyer-request-handler.d.ts.map +1 -1
- package/dist/buyer-request-handler.js +2 -379
- package/dist/buyer-request-handler.js.map +1 -1
- package/dist/discovery/announcer.d.ts +7 -1
- package/dist/discovery/announcer.d.ts.map +1 -1
- package/dist/discovery/announcer.js +84 -33
- package/dist/discovery/announcer.js.map +1 -1
- package/dist/discovery/http-metadata-resolver.d.ts +4 -0
- package/dist/discovery/http-metadata-resolver.d.ts.map +1 -1
- package/dist/discovery/http-metadata-resolver.js +42 -2
- package/dist/discovery/http-metadata-resolver.js.map +1 -1
- package/dist/discovery/index.d.ts +1 -1
- package/dist/discovery/index.d.ts.map +1 -1
- package/dist/discovery/index.js +1 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/metadata-codec.d.ts +4 -4
- package/dist/discovery/metadata-codec.d.ts.map +1 -1
- package/dist/discovery/metadata-codec.js +339 -23
- package/dist/discovery/metadata-codec.js.map +1 -1
- package/dist/discovery/metadata-validator.d.ts +7 -3
- package/dist/discovery/metadata-validator.d.ts.map +1 -1
- package/dist/discovery/metadata-validator.js +139 -8
- package/dist/discovery/metadata-validator.js.map +1 -1
- package/dist/discovery/peer-lookup.d.ts +1 -0
- package/dist/discovery/peer-lookup.d.ts.map +1 -1
- package/dist/discovery/peer-lookup.js +23 -5
- package/dist/discovery/peer-lookup.js.map +1 -1
- package/dist/discovery/peer-metadata.d.ts +2 -90
- package/dist/discovery/peer-metadata.d.ts.map +1 -1
- package/dist/discovery/peer-metadata.js +3 -11
- package/dist/discovery/peer-metadata.js.map +1 -1
- package/dist/discovery/seller-address-resolver.d.ts +1 -49
- package/dist/discovery/seller-address-resolver.d.ts.map +1 -1
- package/dist/discovery/seller-address-resolver.js +2 -114
- package/dist/discovery/seller-address-resolver.js.map +1 -1
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +73 -0
- package/dist/errors.js.map +1 -0
- package/dist/health/model-health-checker.d.ts +6 -5
- package/dist/health/model-health-checker.d.ts.map +1 -1
- package/dist/health/model-health-checker.js +22 -10
- package/dist/health/model-health-checker.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/seller-provider.d.ts +6 -0
- package/dist/interfaces/seller-provider.d.ts.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +28 -0
- package/dist/node.js.map +1 -1
- package/dist/p2p/connection-auth.d.ts +3 -8
- package/dist/p2p/connection-auth.d.ts.map +1 -1
- package/dist/p2p/connection-auth.js +4 -6
- package/dist/p2p/connection-auth.js.map +1 -1
- package/dist/p2p/connection-manager.d.ts +3 -1
- package/dist/p2p/connection-manager.d.ts.map +1 -1
- package/dist/p2p/connection-manager.js.map +1 -1
- package/dist/p2p/identity.d.ts +1 -21
- package/dist/p2p/identity.d.ts.map +1 -1
- package/dist/p2p/identity.js +3 -62
- package/dist/p2p/identity.js.map +1 -1
- package/dist/p2p/message-protocol.d.ts +1 -49
- package/dist/p2p/message-protocol.d.ts.map +1 -1
- package/dist/p2p/message-protocol.js +2 -125
- package/dist/p2p/message-protocol.js.map +1 -1
- package/dist/p2p/payment-codec.d.ts +1 -21
- package/dist/p2p/payment-codec.d.ts.map +1 -1
- package/dist/p2p/payment-codec.js +2 -220
- package/dist/p2p/payment-codec.js.map +1 -1
- package/dist/p2p/payment-mux.d.ts +1 -51
- package/dist/p2p/payment-mux.d.ts.map +1 -1
- package/dist/p2p/payment-mux.js +2 -159
- package/dist/p2p/payment-mux.js.map +1 -1
- package/dist/payments/buyer-free-usage-manager.d.ts +1 -43
- package/dist/payments/buyer-free-usage-manager.d.ts.map +1 -1
- package/dist/payments/buyer-free-usage-manager.js +2 -298
- package/dist/payments/buyer-free-usage-manager.js.map +1 -1
- package/dist/payments/buyer-payment-manager.d.ts +1 -277
- package/dist/payments/buyer-payment-manager.d.ts.map +1 -1
- package/dist/payments/buyer-payment-manager.js +2 -1039
- package/dist/payments/buyer-payment-manager.js.map +1 -1
- package/dist/payments/buyer-payment-negotiator.d.ts +1 -130
- package/dist/payments/buyer-payment-negotiator.d.ts.map +1 -1
- package/dist/payments/buyer-payment-negotiator.js +2 -950
- package/dist/payments/buyer-payment-negotiator.js.map +1 -1
- package/dist/payments/chain-config.d.ts.map +1 -1
- package/dist/payments/chain-config.js +13 -2
- package/dist/payments/chain-config.js.map +1 -1
- package/dist/payments/channel-session-state.d.ts +1 -13
- package/dist/payments/channel-session-state.d.ts.map +1 -1
- package/dist/payments/channel-session-state.js +2 -25
- package/dist/payments/channel-session-state.js.map +1 -1
- package/dist/payments/channel-store.d.ts +2 -51
- package/dist/payments/channel-store.d.ts.map +1 -1
- package/dist/payments/channel-store.js +3 -14
- package/dist/payments/channel-store.js.map +1 -1
- package/dist/payments/channel-usage-accounting.d.ts +1 -17
- package/dist/payments/channel-usage-accounting.d.ts.map +1 -1
- package/dist/payments/channel-usage-accounting.js +2 -65
- package/dist/payments/channel-usage-accounting.js.map +1 -1
- package/dist/payments/evm/base-evm-client.d.ts +1 -26
- package/dist/payments/evm/base-evm-client.d.ts.map +1 -1
- package/dist/payments/evm/base-evm-client.js +2 -115
- package/dist/payments/evm/base-evm-client.js.map +1 -1
- package/dist/payments/evm/channels-client.d.ts +1 -85
- package/dist/payments/evm/channels-client.d.ts.map +1 -1
- package/dist/payments/evm/channels-client.js +2 -193
- package/dist/payments/evm/channels-client.js.map +1 -1
- package/dist/payments/evm/deposits-client.d.ts +1 -29
- package/dist/payments/evm/deposits-client.d.ts.map +1 -1
- package/dist/payments/evm/deposits-client.js +2 -67
- package/dist/payments/evm/deposits-client.js.map +1 -1
- package/dist/payments/evm/signatures.d.ts +1 -203
- package/dist/payments/evm/signatures.d.ts.map +1 -1
- package/dist/payments/evm/signatures.js +2 -236
- package/dist/payments/evm/signatures.js.map +1 -1
- package/dist/payments/evm/subpool-client.d.ts +32 -0
- package/dist/payments/evm/subpool-client.d.ts.map +1 -0
- package/dist/payments/evm/subpool-client.js +158 -0
- package/dist/payments/evm/subpool-client.js.map +1 -0
- package/dist/payments/index.d.ts +1 -1
- package/dist/payments/index.d.ts.map +1 -1
- package/dist/payments/index.js +1 -1
- package/dist/payments/index.js.map +1 -1
- package/dist/payments/pricing.d.ts +1 -26
- package/dist/payments/pricing.d.ts.map +1 -1
- package/dist/payments/pricing.js +2 -36
- package/dist/payments/pricing.js.map +1 -1
- package/dist/payments/usdc-utils.d.ts +1 -8
- package/dist/payments/usdc-utils.d.ts.map +1 -1
- package/dist/payments/usdc-utils.js +2 -16
- package/dist/payments/usdc-utils.js.map +1 -1
- package/dist/proxy/proxy-mux.d.ts +1 -69
- package/dist/proxy/proxy-mux.d.ts.map +1 -1
- package/dist/proxy/proxy-mux.js +2 -346
- package/dist/proxy/proxy-mux.js.map +1 -1
- package/dist/proxy/request-codec.d.ts +1 -41
- package/dist/proxy/request-codec.d.ts.map +1 -1
- package/dist/proxy/request-codec.js +2 -280
- package/dist/proxy/request-codec.js.map +1 -1
- package/dist/seller-request-handler.d.ts +10 -3
- package/dist/seller-request-handler.d.ts.map +1 -1
- package/dist/seller-request-handler.js +112 -17
- package/dist/seller-request-handler.js.map +1 -1
- package/dist/types/billing.d.ts +2 -0
- package/dist/types/billing.d.ts.map +1 -0
- package/dist/types/billing.js +2 -0
- package/dist/types/billing.js.map +1 -0
- package/dist/types/capability.d.ts +1 -25
- package/dist/types/capability.d.ts.map +1 -1
- package/dist/types/capability.js +2 -1
- package/dist/types/capability.js.map +1 -1
- package/dist/types/connection.d.ts +1 -26
- package/dist/types/connection.d.ts.map +1 -1
- package/dist/types/connection.js +2 -10
- package/dist/types/connection.js.map +1 -1
- package/dist/types/http.d.ts +1 -39
- package/dist/types/http.d.ts.map +1 -1
- package/dist/types/http.js +2 -16
- package/dist/types/http.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/peer.d.ts +9 -31
- package/dist/types/peer.d.ts.map +1 -1
- package/dist/types/peer.js +2 -14
- package/dist/types/peer.js.map +1 -1
- package/dist/types/protocol.d.ts +1 -306
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +2 -81
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/service-api.d.ts +1 -5
- package/dist/types/service-api.d.ts.map +1 -1
- package/dist/types/service-api.js +2 -12
- package/dist/types/service-api.js.map +1 -1
- package/dist/utils/debug.d.ts +1 -5
- package/dist/utils/debug.d.ts.map +1 -1
- package/dist/utils/debug.js +2 -52
- package/dist/utils/debug.js.map +1 -1
- package/dist/utils/hex.d.ts +1 -2
- package/dist/utils/hex.d.ts.map +1 -1
- package/dist/utils/hex.js +2 -14
- package/dist/utils/hex.js.map +1 -1
- package/dist/utils/json-codec.d.ts +1 -9
- package/dist/utils/json-codec.d.ts.map +1 -1
- package/dist/utils/json-codec.js +2 -51
- package/dist/utils/json-codec.js.map +1 -1
- package/dist/utils/response-usage.d.ts +1 -9
- package/dist/utils/response-usage.d.ts.map +1 -1
- package/dist/utils/response-usage.js +2 -39
- package/dist/utils/response-usage.js.map +1 -1
- package/dist/verification/codec.d.ts +1 -3
- package/dist/verification/codec.d.ts.map +1 -1
- package/dist/verification/codec.js +2 -37
- package/dist/verification/codec.js.map +1 -1
- package/dist/verification/response-auth.d.ts +1 -30
- package/dist/verification/response-auth.d.ts.map +1 -1
- package/dist/verification/response-auth.js +2 -110
- package/dist/verification/response-auth.js.map +1 -1
- package/dist/verification/verification-mux.d.ts +1 -19
- package/dist/verification/verification-mux.d.ts.map +1 -1
- package/dist/verification/verification-mux.js +2 -99
- package/dist/verification/verification-mux.js.map +1 -1
- package/package.json +4 -2
|
@@ -1,116 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const JSON_RPC_REQUEST_TIMEOUT_MS = 2_500;
|
|
4
|
-
function createJsonRpcProvider(url, network, opts) {
|
|
5
|
-
const request = new FetchRequest(url);
|
|
6
|
-
request.timeout = JSON_RPC_REQUEST_TIMEOUT_MS;
|
|
7
|
-
return new JsonRpcProvider(request, network, opts);
|
|
8
|
-
}
|
|
9
|
-
function buildProvider(rpcUrl, fallbackRpcUrls, evmChainId) {
|
|
10
|
-
const network = evmChainId ? Network.from(evmChainId) : undefined;
|
|
11
|
-
const opts = { batchMaxCount: 1, staticNetwork: network ? true : undefined };
|
|
12
|
-
if (!fallbackRpcUrls || fallbackRpcUrls.length === 0) {
|
|
13
|
-
return createJsonRpcProvider(rpcUrl, network, opts);
|
|
14
|
-
}
|
|
15
|
-
const urls = [rpcUrl, ...fallbackRpcUrls];
|
|
16
|
-
const configs = urls.map((url, i) => ({
|
|
17
|
-
provider: createJsonRpcProvider(url, network, opts),
|
|
18
|
-
priority: i + 1,
|
|
19
|
-
stallTimeout: FALLBACK_STALL_TIMEOUT_MS,
|
|
20
|
-
weight: 1,
|
|
21
|
-
}));
|
|
22
|
-
return new FallbackProvider(configs, network, { quorum: 1 });
|
|
23
|
-
}
|
|
24
|
-
export const ERC20_ABI = [
|
|
25
|
-
'function approve(address spender, uint256 amount) external returns (bool)',
|
|
26
|
-
'function balanceOf(address owner) external view returns (uint256)',
|
|
27
|
-
'function allowance(address owner, address spender) external view returns (uint256)',
|
|
28
|
-
];
|
|
29
|
-
/** Gas limit buffer multiplier over `eth_estimateGas` (30%). Protects against
|
|
30
|
-
* non-deterministic gas in contract branches (cold vs. warm SSTOREs, try/catch
|
|
31
|
-
* fallback paths, variable-length metadata hashing) — without a buffer, a tx
|
|
32
|
-
* whose actual gas is even a hair above the estimate reverts with OOG. */
|
|
33
|
-
const GAS_BUFFER_NUMERATOR = 130n;
|
|
34
|
-
const GAS_BUFFER_DENOMINATOR = 100n;
|
|
35
|
-
export class BaseEvmClient {
|
|
36
|
-
_provider;
|
|
37
|
-
_contractAddress;
|
|
38
|
-
_nonceCursor = new Map();
|
|
39
|
-
_nonceLocks = new Map();
|
|
40
|
-
constructor(rpcUrl, contractAddress, fallbackRpcUrls, evmChainId) {
|
|
41
|
-
this._provider = buildProvider(rpcUrl, fallbackRpcUrls, evmChainId);
|
|
42
|
-
this._contractAddress = contractAddress;
|
|
43
|
-
}
|
|
44
|
-
get provider() { return this._provider; }
|
|
45
|
-
get contractAddress() { return this._contractAddress; }
|
|
46
|
-
_ensureConnected(signer) {
|
|
47
|
-
if (signer.provider)
|
|
48
|
-
return signer;
|
|
49
|
-
return signer.connect(this._provider);
|
|
50
|
-
}
|
|
51
|
-
async _execWrite(signer, abi, method, ...args) {
|
|
52
|
-
const connected = this._ensureConnected(signer);
|
|
53
|
-
const signerAddress = await connected.getAddress();
|
|
54
|
-
const contract = new Contract(this._contractAddress, abi, connected);
|
|
55
|
-
const populated = await contract.getFunction(method).populateTransaction(...args);
|
|
56
|
-
const tx = await this._sendBuffered(connected, signerAddress, populated);
|
|
57
|
-
const receipt = await tx.wait();
|
|
58
|
-
if (!receipt)
|
|
59
|
-
throw new Error('Transaction was dropped or replaced');
|
|
60
|
-
return receipt.hash;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Approve USDC spending then execute a contract method.
|
|
64
|
-
*/
|
|
65
|
-
async _approveAndExec(signer, usdcAddress, amount, abi, method, ...args) {
|
|
66
|
-
const connected = this._ensureConnected(signer);
|
|
67
|
-
const signerAddress = await connected.getAddress();
|
|
68
|
-
const usdc = new Contract(usdcAddress, ERC20_ABI, connected);
|
|
69
|
-
const approvePopulated = await usdc.getFunction('approve').populateTransaction(this._contractAddress, amount);
|
|
70
|
-
const approveTx = await this._sendBuffered(connected, signerAddress, approvePopulated);
|
|
71
|
-
const approveReceipt = await approveTx.wait();
|
|
72
|
-
if (!approveReceipt)
|
|
73
|
-
throw new Error('Approve transaction was dropped or replaced');
|
|
74
|
-
return this._execWrite(signer, abi, method, ...args);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Reserve a nonce, apply the gas buffer, and broadcast. On any failure —
|
|
78
|
-
* estimateGas revert, RPC timeout, submission error — roll back the nonce
|
|
79
|
-
* cursor. `_reserveNonce` reads `getTransactionCount(..., 'pending')` on
|
|
80
|
-
* the next call, so an in-flight tx (if sendTransaction failed after the
|
|
81
|
-
* node accepted it) is still accounted for and we won't reuse its nonce.
|
|
82
|
-
*/
|
|
83
|
-
async _sendBuffered(connected, signerAddress, populated) {
|
|
84
|
-
const nonce = await this._reserveNonce(signerAddress);
|
|
85
|
-
populated.nonce = nonce;
|
|
86
|
-
try {
|
|
87
|
-
const estimated = await connected.estimateGas(populated);
|
|
88
|
-
populated.gasLimit = (estimated * GAS_BUFFER_NUMERATOR) / GAS_BUFFER_DENOMINATOR;
|
|
89
|
-
return await connected.sendTransaction(populated);
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
this._nonceCursor.delete(signerAddress);
|
|
93
|
-
throw err;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async _reserveNonce(address) {
|
|
97
|
-
// Serialize nonce reservation per address to prevent concurrent calls
|
|
98
|
-
// from reading the same network nonce before either updates the cursor
|
|
99
|
-
const prev = this._nonceLocks.get(address) ?? Promise.resolve();
|
|
100
|
-
let resolve;
|
|
101
|
-
const lock = new Promise(r => { resolve = r; });
|
|
102
|
-
this._nonceLocks.set(address, lock);
|
|
103
|
-
await prev;
|
|
104
|
-
try {
|
|
105
|
-
const networkNonce = await this._provider.getTransactionCount(address, 'pending');
|
|
106
|
-
const cachedNext = this._nonceCursor.get(address);
|
|
107
|
-
const nonce = cachedNext === undefined ? networkNonce : Math.max(networkNonce, cachedNext);
|
|
108
|
-
this._nonceCursor.set(address, nonce + 1);
|
|
109
|
-
return nonce;
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
resolve();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
1
|
+
// Moved to @antseed/buyer-core; re-exported for compatibility.
|
|
2
|
+
export * from '@antseed/buyer-core/base-evm-client';
|
|
116
3
|
//# sourceMappingURL=base-evm-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-evm-client.js","sourceRoot":"","sources":["../../../src/payments/evm/base-evm-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"base-evm-client.js","sourceRoot":"","sources":["../../../src/payments/evm/base-evm-client.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,cAAc,qCAAqC,CAAC"}
|
|
@@ -1,86 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseEvmClient } from './base-evm-client.js';
|
|
3
|
-
export interface ChannelsClientConfig {
|
|
4
|
-
rpcUrl: string;
|
|
5
|
-
fallbackRpcUrls?: string[];
|
|
6
|
-
contractAddress: string;
|
|
7
|
-
evmChainId?: number;
|
|
8
|
-
}
|
|
9
|
-
export interface AgentStats {
|
|
10
|
-
channelCount: number;
|
|
11
|
-
ghostCount: number;
|
|
12
|
-
totalVolumeUsdc: bigint;
|
|
13
|
-
lastSettledAt: number;
|
|
14
|
-
}
|
|
15
|
-
export interface ChannelInfo {
|
|
16
|
-
buyer: string;
|
|
17
|
-
seller: string;
|
|
18
|
-
deposit: bigint;
|
|
19
|
-
settled: bigint;
|
|
20
|
-
metadataHash: string;
|
|
21
|
-
deadline: bigint;
|
|
22
|
-
settledAt: bigint;
|
|
23
|
-
closeRequestedAt: bigint;
|
|
24
|
-
status: number;
|
|
25
|
-
}
|
|
26
|
-
export interface CloseRequestedEvent {
|
|
27
|
-
channelId: string;
|
|
28
|
-
buyer: string;
|
|
29
|
-
}
|
|
30
|
-
export declare class ChannelsClient extends BaseEvmClient {
|
|
31
|
-
/**
|
|
32
|
-
* The underlying AntseedChannels address used for reads + event filters.
|
|
33
|
-
* When the configured `contractAddress` is a seller facade (e.g.
|
|
34
|
-
* DiemStakingProxy), this resolves to the real channels contract via the
|
|
35
|
-
* facade's `channelsAddress()` view. Otherwise it equals `_contractAddress`.
|
|
36
|
-
* Probed lazily on first read.
|
|
37
|
-
*/
|
|
38
|
-
private _readAddressPromise;
|
|
39
|
-
constructor(config: ChannelsClientConfig);
|
|
40
|
-
/**
|
|
41
|
-
* Resolve the read address (underlying AntseedChannels). If the configured
|
|
42
|
-
* contract exposes `channelsAddress()` (i.e. is a seller facade), use that.
|
|
43
|
-
* Otherwise fall back to the configured address.
|
|
44
|
-
*
|
|
45
|
-
* Three outcomes:
|
|
46
|
-
* 1. Probe returns a single ABI-encoded address word → cache that
|
|
47
|
-
* (facade if it differs from the configured address, non-facade
|
|
48
|
-
* otherwise).
|
|
49
|
-
* 2. Probe returns `0x`, a CALL_EXCEPTION revert, or an obviously
|
|
50
|
-
* non-address payload (wrong length, non-string) → cache as
|
|
51
|
-
* non-facade. These are all "selector isn't implemented" signals.
|
|
52
|
-
* 3. Probe throws a non-CALL_EXCEPTION error (network timeout, RPC
|
|
53
|
-
* 5xx, rate limit) → *transient*. Return the configured address for
|
|
54
|
-
* this call only and do **not** memoize. Subsequent calls retry.
|
|
55
|
-
*
|
|
56
|
-
* Prior implementation memoized the fallback on any throw, which
|
|
57
|
-
* permanently wedged facade mode after a single transient RPC blip —
|
|
58
|
-
* signing every subsequent SpendingAuth against the wrong EIP-712 domain.
|
|
59
|
-
* At worst a facade seller now mis-signs *one* auth during an RPC outage
|
|
60
|
-
* (buyer verification fails, buyer retries, probe recovers, all good).
|
|
61
|
-
*/
|
|
62
|
-
private _getReadAddress;
|
|
63
|
-
/** The resolved underlying channels address. Triggers the probe if not yet resolved. */
|
|
64
|
-
get readAddress(): Promise<string>;
|
|
65
|
-
reserve(signer: AbstractSigner, buyer: string, salt: string, maxAmount: bigint, deadline: bigint, buyerSig: string): Promise<string>;
|
|
66
|
-
settle(signer: AbstractSigner, channelId: string, cumulativeAmount: bigint, metadata: string, buyerSig: string): Promise<string>;
|
|
67
|
-
close(signer: AbstractSigner, channelId: string, finalAmount: bigint, metadata: string, buyerSig: string): Promise<string>;
|
|
68
|
-
topUp(signer: AbstractSigner, channelId: string, cumulativeAmount: bigint, metadata: string, spendingSig: string, newMaxAmount: bigint, deadline: bigint, reserveSig: string): Promise<string>;
|
|
69
|
-
requestClose(signer: AbstractSigner, channelId: string): Promise<string>;
|
|
70
|
-
withdraw(signer: AbstractSigner, channelId: string): Promise<string>;
|
|
71
|
-
getSession(channelId: string): Promise<ChannelInfo>;
|
|
72
|
-
domainSeparator(): Promise<string>;
|
|
73
|
-
getFirstSignCap(): Promise<bigint>;
|
|
74
|
-
computeChannelId(buyer: string, seller: string, salt: string): Promise<string>;
|
|
75
|
-
getAgentStats(agentId: number): Promise<AgentStats>;
|
|
76
|
-
/**
|
|
77
|
-
* Query CloseRequested events from the underlying AntseedChannels contract.
|
|
78
|
-
* Returns matching events between fromBlock and toBlock (inclusive).
|
|
79
|
-
*/
|
|
80
|
-
getCloseRequestedEvents(fromBlock: number | 'latest', toBlock?: number | 'latest'): Promise<CloseRequestedEvent[]>;
|
|
81
|
-
/**
|
|
82
|
-
* Get the current block number from the provider.
|
|
83
|
-
*/
|
|
84
|
-
getBlockNumber(): Promise<number>;
|
|
85
|
-
}
|
|
1
|
+
export * from '@antseed/buyer-core/channels-client';
|
|
86
2
|
//# sourceMappingURL=channels-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels-client.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/channels-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channels-client.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/channels-client.ts"],"names":[],"mappings":"AACA,cAAc,qCAAqC,CAAC"}
|
|
@@ -1,194 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const CHANNELS_ABI = [
|
|
4
|
-
'function reserve(address buyer, bytes32 salt, uint128 maxAmount, uint256 deadline, bytes buyerSig) external',
|
|
5
|
-
'function settle(bytes32 channelId, uint128 cumulativeAmount, bytes metadata, bytes buyerSig) external',
|
|
6
|
-
'function close(bytes32 channelId, uint128 finalAmount, bytes metadata, bytes buyerSig) external',
|
|
7
|
-
'function topUp(bytes32 channelId, uint128 cumulativeAmount, bytes metadata, bytes spendingSig, uint128 newMaxAmount, uint256 deadline, bytes reserveSig) external',
|
|
8
|
-
'function requestClose(bytes32 channelId) external',
|
|
9
|
-
'function withdraw(bytes32 channelId) external',
|
|
10
|
-
'function channels(bytes32 channelId) external view returns (address buyer, address seller, uint128 deposit, uint128 settled, bytes32 metadataHash, uint256 deadline, uint256 settledAt, uint256 closeRequestedAt, uint8 status)',
|
|
11
|
-
'function computeChannelId(address buyer, address seller, bytes32 salt) external pure returns (bytes32)',
|
|
12
|
-
'function getAgentStats(uint256 agentId) external view returns (uint64 channelCount, uint64 ghostCount, uint256 totalVolumeUsdc, uint64 lastSettledAt)',
|
|
13
|
-
'function domainSeparator() external view returns (bytes32)',
|
|
14
|
-
'function FIRST_SIGN_CAP() external view returns (uint256)',
|
|
15
|
-
'event CloseRequested(bytes32 indexed channelId, address indexed buyer, address indexed seller, uint256 gracePeriodEnd)',
|
|
16
|
-
];
|
|
17
|
-
/// @dev Probe ABI for the seller-facade passthrough. Present on
|
|
18
|
-
/// AntseedSellerDelegation (and derivatives like DiemStakingProxy); absent
|
|
19
|
-
/// on plain AntseedChannels. Used at init to discover the underlying
|
|
20
|
-
/// channels contract when the configured address is a seller facade.
|
|
21
|
-
const SELLER_FACADE_PROBE_ABI = [
|
|
22
|
-
'function channelsAddress() external view returns (address)',
|
|
23
|
-
];
|
|
24
|
-
export class ChannelsClient extends BaseEvmClient {
|
|
25
|
-
/**
|
|
26
|
-
* The underlying AntseedChannels address used for reads + event filters.
|
|
27
|
-
* When the configured `contractAddress` is a seller facade (e.g.
|
|
28
|
-
* DiemStakingProxy), this resolves to the real channels contract via the
|
|
29
|
-
* facade's `channelsAddress()` view. Otherwise it equals `_contractAddress`.
|
|
30
|
-
* Probed lazily on first read.
|
|
31
|
-
*/
|
|
32
|
-
_readAddressPromise = null;
|
|
33
|
-
constructor(config) {
|
|
34
|
-
super(config.rpcUrl, config.contractAddress, config.fallbackRpcUrls, config.evmChainId);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Resolve the read address (underlying AntseedChannels). If the configured
|
|
38
|
-
* contract exposes `channelsAddress()` (i.e. is a seller facade), use that.
|
|
39
|
-
* Otherwise fall back to the configured address.
|
|
40
|
-
*
|
|
41
|
-
* Three outcomes:
|
|
42
|
-
* 1. Probe returns a single ABI-encoded address word → cache that
|
|
43
|
-
* (facade if it differs from the configured address, non-facade
|
|
44
|
-
* otherwise).
|
|
45
|
-
* 2. Probe returns `0x`, a CALL_EXCEPTION revert, or an obviously
|
|
46
|
-
* non-address payload (wrong length, non-string) → cache as
|
|
47
|
-
* non-facade. These are all "selector isn't implemented" signals.
|
|
48
|
-
* 3. Probe throws a non-CALL_EXCEPTION error (network timeout, RPC
|
|
49
|
-
* 5xx, rate limit) → *transient*. Return the configured address for
|
|
50
|
-
* this call only and do **not** memoize. Subsequent calls retry.
|
|
51
|
-
*
|
|
52
|
-
* Prior implementation memoized the fallback on any throw, which
|
|
53
|
-
* permanently wedged facade mode after a single transient RPC blip —
|
|
54
|
-
* signing every subsequent SpendingAuth against the wrong EIP-712 domain.
|
|
55
|
-
* At worst a facade seller now mis-signs *one* auth during an RPC outage
|
|
56
|
-
* (buyer verification fails, buyer retries, probe recovers, all good).
|
|
57
|
-
*/
|
|
58
|
-
_getReadAddress() {
|
|
59
|
-
if (this._readAddressPromise)
|
|
60
|
-
return this._readAddressPromise;
|
|
61
|
-
const attempt = (async () => {
|
|
62
|
-
const iface = new ethers.Interface(SELLER_FACADE_PROBE_ABI);
|
|
63
|
-
const callData = iface.encodeFunctionData('channelsAddress');
|
|
64
|
-
let raw;
|
|
65
|
-
try {
|
|
66
|
-
raw = await this._provider.call({
|
|
67
|
-
to: this._contractAddress,
|
|
68
|
-
data: callData,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
const code = err?.code;
|
|
73
|
-
if (code === 'CALL_EXCEPTION') {
|
|
74
|
-
// Contract didn't implement the selector — cache non-facade.
|
|
75
|
-
return { value: this._contractAddress, cache: true };
|
|
76
|
-
}
|
|
77
|
-
// Transient network/RPC error — don't cache.
|
|
78
|
-
return { value: this._contractAddress, cache: false };
|
|
79
|
-
}
|
|
80
|
-
// Treat any non-66-char response (including `0x`, tuples, malformed
|
|
81
|
-
// payloads) as "selector not implemented" — safe to cache as non-facade.
|
|
82
|
-
if (typeof raw !== 'string' || raw.length !== 66) {
|
|
83
|
-
return { value: this._contractAddress, cache: true };
|
|
84
|
-
}
|
|
85
|
-
const [resolved] = iface.decodeFunctionResult('channelsAddress', raw);
|
|
86
|
-
const value = resolved.toLowerCase() === this._contractAddress.toLowerCase()
|
|
87
|
-
? this._contractAddress
|
|
88
|
-
: resolved;
|
|
89
|
-
return { value, cache: true };
|
|
90
|
-
})();
|
|
91
|
-
// Memoize the promise that resolves to the *value* only when the probe
|
|
92
|
-
// reports a cacheable outcome. Otherwise clear the memo post-resolution
|
|
93
|
-
// so the next caller re-probes.
|
|
94
|
-
const valuePromise = attempt.then(({ value, cache }) => {
|
|
95
|
-
if (!cache && this._readAddressPromise === valuePromise) {
|
|
96
|
-
this._readAddressPromise = null;
|
|
97
|
-
}
|
|
98
|
-
return value;
|
|
99
|
-
});
|
|
100
|
-
// If `attempt` itself rejects (shouldn't, since we catch above, but
|
|
101
|
-
// defence in depth), clear the memo.
|
|
102
|
-
valuePromise.catch(() => {
|
|
103
|
-
if (this._readAddressPromise === valuePromise) {
|
|
104
|
-
this._readAddressPromise = null;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
this._readAddressPromise = valuePromise;
|
|
108
|
-
return valuePromise;
|
|
109
|
-
}
|
|
110
|
-
/** The resolved underlying channels address. Triggers the probe if not yet resolved. */
|
|
111
|
-
get readAddress() {
|
|
112
|
-
return this._getReadAddress();
|
|
113
|
-
}
|
|
114
|
-
async reserve(signer, buyer, salt, maxAmount, deadline, buyerSig) {
|
|
115
|
-
return this._execWrite(signer, CHANNELS_ABI, 'reserve', buyer, salt, maxAmount, deadline, buyerSig);
|
|
116
|
-
}
|
|
117
|
-
async settle(signer, channelId, cumulativeAmount, metadata, buyerSig) {
|
|
118
|
-
return this._execWrite(signer, CHANNELS_ABI, 'settle', channelId, cumulativeAmount, metadata, buyerSig);
|
|
119
|
-
}
|
|
120
|
-
async close(signer, channelId, finalAmount, metadata, buyerSig) {
|
|
121
|
-
return this._execWrite(signer, CHANNELS_ABI, 'close', channelId, finalAmount, metadata, buyerSig);
|
|
122
|
-
}
|
|
123
|
-
async topUp(signer, channelId, cumulativeAmount, metadata, spendingSig, newMaxAmount, deadline, reserveSig) {
|
|
124
|
-
return this._execWrite(signer, CHANNELS_ABI, 'topUp', channelId, cumulativeAmount, metadata, spendingSig, newMaxAmount, deadline, reserveSig);
|
|
125
|
-
}
|
|
126
|
-
async requestClose(signer, channelId) {
|
|
127
|
-
return this._execWrite(signer, CHANNELS_ABI, 'requestClose', channelId);
|
|
128
|
-
}
|
|
129
|
-
async withdraw(signer, channelId) {
|
|
130
|
-
return this._execWrite(signer, CHANNELS_ABI, 'withdraw', channelId);
|
|
131
|
-
}
|
|
132
|
-
async getSession(channelId) {
|
|
133
|
-
const contract = new Contract(await this._getReadAddress(), CHANNELS_ABI, this._provider);
|
|
134
|
-
const result = await contract.getFunction('channels')(channelId);
|
|
135
|
-
return {
|
|
136
|
-
buyer: result[0],
|
|
137
|
-
seller: result[1],
|
|
138
|
-
deposit: result[2],
|
|
139
|
-
settled: result[3],
|
|
140
|
-
metadataHash: result[4],
|
|
141
|
-
deadline: result[5],
|
|
142
|
-
settledAt: result[6],
|
|
143
|
-
closeRequestedAt: result[7],
|
|
144
|
-
status: Number(result[8]),
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
async domainSeparator() {
|
|
148
|
-
const contract = new Contract(await this._getReadAddress(), CHANNELS_ABI, this._provider);
|
|
149
|
-
return contract.getFunction('domainSeparator')();
|
|
150
|
-
}
|
|
151
|
-
async getFirstSignCap() {
|
|
152
|
-
const contract = new Contract(await this._getReadAddress(), CHANNELS_ABI, this._provider);
|
|
153
|
-
return contract.getFunction('FIRST_SIGN_CAP')();
|
|
154
|
-
}
|
|
155
|
-
async computeChannelId(buyer, seller, salt) {
|
|
156
|
-
const contract = new Contract(await this._getReadAddress(), CHANNELS_ABI, this._provider);
|
|
157
|
-
return contract.getFunction('computeChannelId')(buyer, seller, salt);
|
|
158
|
-
}
|
|
159
|
-
async getAgentStats(agentId) {
|
|
160
|
-
const contract = new Contract(await this._getReadAddress(), CHANNELS_ABI, this._provider);
|
|
161
|
-
const result = await contract.getFunction('getAgentStats')(agentId);
|
|
162
|
-
return {
|
|
163
|
-
channelCount: Number(result[0]),
|
|
164
|
-
ghostCount: Number(result[1]),
|
|
165
|
-
totalVolumeUsdc: result[2],
|
|
166
|
-
lastSettledAt: Number(result[3]),
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Query CloseRequested events from the underlying AntseedChannels contract.
|
|
171
|
-
* Returns matching events between fromBlock and toBlock (inclusive).
|
|
172
|
-
*/
|
|
173
|
-
async getCloseRequestedEvents(fromBlock, toBlock = 'latest') {
|
|
174
|
-
const iface = new ethers.Interface(CHANNELS_ABI);
|
|
175
|
-
const eventTopic = iface.getEvent('CloseRequested').topicHash;
|
|
176
|
-
const logs = await this._provider.getLogs({
|
|
177
|
-
address: await this._getReadAddress(),
|
|
178
|
-
topics: [eventTopic],
|
|
179
|
-
fromBlock,
|
|
180
|
-
toBlock,
|
|
181
|
-
});
|
|
182
|
-
return logs.map((log) => ({
|
|
183
|
-
channelId: log.topics[1],
|
|
184
|
-
buyer: ethers.getAddress('0x' + log.topics[2].slice(26)),
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Get the current block number from the provider.
|
|
189
|
-
*/
|
|
190
|
-
async getBlockNumber() {
|
|
191
|
-
return this._provider.getBlockNumber();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
1
|
+
// Moved to @antseed/buyer-core; re-exported for compatibility.
|
|
2
|
+
export * from '@antseed/buyer-core/channels-client';
|
|
194
3
|
//# sourceMappingURL=channels-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels-client.js","sourceRoot":"","sources":["../../../src/payments/evm/channels-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"channels-client.js","sourceRoot":"","sources":["../../../src/payments/evm/channels-client.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,cAAc,qCAAqC,CAAC"}
|
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseEvmClient } from './base-evm-client.js';
|
|
3
|
-
export interface DepositsClientConfig {
|
|
4
|
-
rpcUrl: string;
|
|
5
|
-
fallbackRpcUrls?: string[];
|
|
6
|
-
contractAddress: string;
|
|
7
|
-
usdcAddress: string;
|
|
8
|
-
evmChainId?: number;
|
|
9
|
-
}
|
|
10
|
-
export interface BuyerBalanceInfo {
|
|
11
|
-
available: bigint;
|
|
12
|
-
reserved: bigint;
|
|
13
|
-
lastActivityAt: bigint;
|
|
14
|
-
}
|
|
15
|
-
export declare class DepositsClient extends BaseEvmClient {
|
|
16
|
-
private readonly _usdcAddress;
|
|
17
|
-
constructor(config: DepositsClientConfig);
|
|
18
|
-
get usdcAddress(): string;
|
|
19
|
-
deposit(signer: AbstractSigner, buyer: string, amount: bigint): Promise<string>;
|
|
20
|
-
withdraw(signer: AbstractSigner, buyer: string, amount: bigint): Promise<string>;
|
|
21
|
-
getBuyerBalance(buyerAddr: string): Promise<BuyerBalanceInfo>;
|
|
22
|
-
getBuyerCreditLimit(buyerAddr: string): Promise<bigint>;
|
|
23
|
-
getOperator(buyerAddr: string): Promise<string>;
|
|
24
|
-
getOperatorNonce(buyerAddr: string): Promise<bigint>;
|
|
25
|
-
setOperator(signer: AbstractSigner, buyer: string, operator: string, nonce: bigint, buyerSig: string): Promise<string>;
|
|
26
|
-
transferOperator(signer: AbstractSigner, buyer: string, newOperator: string): Promise<string>;
|
|
27
|
-
domainSeparator(): Promise<string>;
|
|
28
|
-
getUSDCBalance(ownerAddr: string): Promise<bigint>;
|
|
29
|
-
}
|
|
1
|
+
export * from '@antseed/buyer-core/deposits-client';
|
|
30
2
|
//# sourceMappingURL=deposits-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposits-client.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/deposits-client.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"deposits-client.d.ts","sourceRoot":"","sources":["../../../src/payments/evm/deposits-client.ts"],"names":[],"mappings":"AACA,cAAc,qCAAqC,CAAC"}
|
|
@@ -1,68 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const DEPOSITS_ABI = [
|
|
4
|
-
'function deposit(address buyer, uint256 amount) external',
|
|
5
|
-
'function withdraw(address buyer, uint256 amount) external',
|
|
6
|
-
'function getBuyerBalance(address buyer) external view returns (uint256 available, uint256 reserved, uint256 lastActivityAt)',
|
|
7
|
-
'function getBuyerCreditLimit(address buyer) external view returns (uint256)',
|
|
8
|
-
'function uniqueSellersCharged(address buyer) external view returns (uint256)',
|
|
9
|
-
'function getOperator(address buyer) external view returns (address)',
|
|
10
|
-
'function getOperatorNonce(address buyer) external view returns (uint256)',
|
|
11
|
-
'function setOperator(address buyer, address operator, uint256 nonce, bytes buyerSig) external',
|
|
12
|
-
'function transferOperator(address buyer, address newOperator) external',
|
|
13
|
-
'function domainSeparator() external view returns (bytes32)',
|
|
14
|
-
];
|
|
15
|
-
export class DepositsClient extends BaseEvmClient {
|
|
16
|
-
_usdcAddress;
|
|
17
|
-
constructor(config) {
|
|
18
|
-
super(config.rpcUrl, config.contractAddress, config.fallbackRpcUrls, config.evmChainId);
|
|
19
|
-
this._usdcAddress = config.usdcAddress;
|
|
20
|
-
}
|
|
21
|
-
get usdcAddress() { return this._usdcAddress; }
|
|
22
|
-
// ─── Buyer Operations ──────────────────────────────────────────────
|
|
23
|
-
async deposit(signer, buyer, amount) {
|
|
24
|
-
return this._approveAndExec(signer, this._usdcAddress, amount, DEPOSITS_ABI, 'deposit', buyer, amount);
|
|
25
|
-
}
|
|
26
|
-
async withdraw(signer, buyer, amount) {
|
|
27
|
-
return this._execWrite(signer, DEPOSITS_ABI, 'withdraw', buyer, amount);
|
|
28
|
-
}
|
|
29
|
-
// ─── View Functions ─────────────────────────────────────────────────
|
|
30
|
-
async getBuyerBalance(buyerAddr) {
|
|
31
|
-
const contract = new Contract(this._contractAddress, DEPOSITS_ABI, this._provider);
|
|
32
|
-
const result = await contract.getFunction('getBuyerBalance')(buyerAddr);
|
|
33
|
-
return {
|
|
34
|
-
available: result[0],
|
|
35
|
-
reserved: result[1],
|
|
36
|
-
lastActivityAt: result[2],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
async getBuyerCreditLimit(buyerAddr) {
|
|
40
|
-
const contract = new Contract(this._contractAddress, DEPOSITS_ABI, this._provider);
|
|
41
|
-
return contract.getFunction('getBuyerCreditLimit')(buyerAddr);
|
|
42
|
-
}
|
|
43
|
-
// ─── Operator Management ─────────────────────────────────────────
|
|
44
|
-
async getOperator(buyerAddr) {
|
|
45
|
-
const contract = new Contract(this._contractAddress, DEPOSITS_ABI, this._provider);
|
|
46
|
-
return contract.getFunction('getOperator')(buyerAddr);
|
|
47
|
-
}
|
|
48
|
-
async getOperatorNonce(buyerAddr) {
|
|
49
|
-
const contract = new Contract(this._contractAddress, DEPOSITS_ABI, this._provider);
|
|
50
|
-
return contract.getFunction('getOperatorNonce')(buyerAddr);
|
|
51
|
-
}
|
|
52
|
-
async setOperator(signer, buyer, operator, nonce, buyerSig) {
|
|
53
|
-
return this._execWrite(signer, DEPOSITS_ABI, 'setOperator', buyer, operator, nonce, buyerSig);
|
|
54
|
-
}
|
|
55
|
-
async transferOperator(signer, buyer, newOperator) {
|
|
56
|
-
return this._execWrite(signer, DEPOSITS_ABI, 'transferOperator', buyer, newOperator);
|
|
57
|
-
}
|
|
58
|
-
async domainSeparator() {
|
|
59
|
-
const contract = new Contract(this._contractAddress, DEPOSITS_ABI, this._provider);
|
|
60
|
-
return contract.getFunction('domainSeparator')();
|
|
61
|
-
}
|
|
62
|
-
// ─── USDC Balance ───────────────────────────────────────────────
|
|
63
|
-
async getUSDCBalance(ownerAddr) {
|
|
64
|
-
const usdc = new Contract(this._usdcAddress, ERC20_ABI, this._provider);
|
|
65
|
-
return usdc.getFunction('balanceOf')(ownerAddr);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
1
|
+
// Moved to @antseed/buyer-core; re-exported for compatibility.
|
|
2
|
+
export * from '@antseed/buyer-core/deposits-client';
|
|
68
3
|
//# sourceMappingURL=deposits-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposits-client.js","sourceRoot":"","sources":["../../../src/payments/evm/deposits-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"deposits-client.js","sourceRoot":"","sources":["../../../src/payments/evm/deposits-client.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,cAAc,qCAAqC,CAAC"}
|