@oceanprotocol/lib 9.3.0-next.2 → 9.3.0-next.4
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/lib.modern.mjs +2 -2
- package/dist/lib.module.mjs +2 -2
- package/dist/types/@types/Escrow.d.ts +72 -0
- package/dist/types/@types/OneTimeSubsidyProvider.d.ts +5 -4
- package/dist/types/@types/SubsidyView.d.ts +55 -2
- package/dist/types/config/Config.d.ts +8 -0
- package/dist/types/contracts/Escrow.d.ts +154 -12
- package/dist/types/contracts/SubsidyView.d.ts +58 -1
- package/dist/types/utils/ContractUtils.d.ts +10 -0
- package/package.json +3 -3
|
@@ -16,7 +16,19 @@ export interface AuthData {
|
|
|
16
16
|
maxLockedAmount: string;
|
|
17
17
|
maxLockSeconds: string;
|
|
18
18
|
maxLockCounts: string;
|
|
19
|
+
/**
|
|
20
|
+
* Unix timestamp (seconds) after which the payee can no longer create or extend locks (Escrow
|
|
21
|
+
* v2). `'0'` (the default) = indefinite, i.e. today's behaviour. Claim and cancel are never
|
|
22
|
+
* gated by expiry, so funds are never stuck.
|
|
23
|
+
*/
|
|
24
|
+
expiryTimestamp?: string;
|
|
19
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A lock as returned by `getLocks`. NOTE (Escrow v2): `amount` is the **gross** lock amount `L`
|
|
28
|
+
* (payer-funded portion `P` + sponsored portion `S`), unchanged from v1. The payer-funded part is
|
|
29
|
+
* tracked separately in `getUserFunds(...).locked`; read `getSponsorship(payee, payer, jobId)` for
|
|
30
|
+
* the sponsored breakdown.
|
|
31
|
+
*/
|
|
20
32
|
export interface LockData {
|
|
21
33
|
jobId: string;
|
|
22
34
|
payer: string;
|
|
@@ -25,3 +37,63 @@ export interface LockData {
|
|
|
25
37
|
token: string;
|
|
26
38
|
startTime: string;
|
|
27
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* One authorization as returned by `getAuthorizations` (Escrow v2 tuple shape). Amounts are raw
|
|
42
|
+
* on-chain values (the wrapper returns the raw ethers result; convert with `unitsToAmount` if
|
|
43
|
+
* needed).
|
|
44
|
+
*/
|
|
45
|
+
export interface EscrowAuthorization {
|
|
46
|
+
/** The authorized payee (node). */
|
|
47
|
+
payee: string;
|
|
48
|
+
/** Max the payee may have locked from the payer's own funds at once (raw units). */
|
|
49
|
+
maxLockedAmount: bigint;
|
|
50
|
+
/**
|
|
51
|
+
* Currently locked from the payer's **own** funds (Escrow v2: the payer-funded portion `P`
|
|
52
|
+
* only — sponsored tokens are not counted here; raw units).
|
|
53
|
+
*/
|
|
54
|
+
currentLockedAmount: bigint;
|
|
55
|
+
/** Max lock duration the payee may set, in seconds. */
|
|
56
|
+
maxLockSeconds: bigint;
|
|
57
|
+
/** Max number of concurrent locks the payee may hold. */
|
|
58
|
+
maxLockCounts: bigint;
|
|
59
|
+
/** Number of locks the payee currently holds. */
|
|
60
|
+
currentLocks: bigint;
|
|
61
|
+
/**
|
|
62
|
+
* Unix timestamp (seconds) after which the payee can no longer create or extend locks; `0`
|
|
63
|
+
* = indefinite (Escrow v2).
|
|
64
|
+
*/
|
|
65
|
+
expiryTimestamp: bigint;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Per-lock sponsorship breakdown from `getSponsorship(payee, payer, jobId)` (Escrow v2). Amounts
|
|
69
|
+
* are returned in human-readable token units by the wrapper.
|
|
70
|
+
*/
|
|
71
|
+
export interface Sponsorship {
|
|
72
|
+
/** Total sponsored amount `S` backing this lock, in human-readable token units. */
|
|
73
|
+
total: string;
|
|
74
|
+
/** The providers that sponsored this lock. */
|
|
75
|
+
providers: string[];
|
|
76
|
+
/** Each provider's contribution, aligned with `providers`, in human-readable token units. */
|
|
77
|
+
amounts: string[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The flavour of an escrow deployment, from `escrowKind()` (Escrow v2). Use it to tell the
|
|
81
|
+
* permissionless community escrow apart from the fee-gated enterprise one.
|
|
82
|
+
*/
|
|
83
|
+
export declare enum EscrowKind {
|
|
84
|
+
COMMUNITY = 0,
|
|
85
|
+
ENTERPRISE = 1
|
|
86
|
+
}
|
|
87
|
+
/** ERC-165 interface id of `IEscrowCore` (base escrow surface at v2 signatures). */
|
|
88
|
+
export declare const IESCROW_CORE_INTERFACE_ID = "0xd31a4ec5";
|
|
89
|
+
/**
|
|
90
|
+
* ERC-165 interface id of `IEscrowLockSubsidy` (the lock-time / prefunded sponsorship surface:
|
|
91
|
+
* `sweepReclaimable`, `maxSponsorsPerLock`, `getSponsoredTotal`, `getReclaimable`,
|
|
92
|
+
* `getSponsorship`). Feature-detect it before using sponsorship on an escrow.
|
|
93
|
+
*/
|
|
94
|
+
export declare const IESCROW_LOCK_SUBSIDY_INTERFACE_ID = "0x016d7f65";
|
|
95
|
+
/**
|
|
96
|
+
* ERC-165 interface id of `IEscrowEnterprise` (enterprise-only read passthroughs:
|
|
97
|
+
* `feeCollector`, `isTokenAllowed`, `previewFee`). The community escrow does not advertise it.
|
|
98
|
+
*/
|
|
99
|
+
export declare const IESCROW_ENTERPRISE_INTERFACE_ID = "0xb2f20641";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-token configuration of a `OneTimeSubsidyProvider`, as returned by `getTokenConfig`.
|
|
3
|
-
* `defaultCredit` is expressed in human-readable token units; `pctBps` is the
|
|
4
|
-
* per-job percentage ceiling in basis points (here `0` means "
|
|
5
|
-
*
|
|
3
|
+
* `defaultCredit` is expressed in human-readable token units; `pctBps` is the REQUIRED
|
|
4
|
+
* per-job percentage ceiling in basis points (here `0` means "grant nothing" and `10000`
|
|
5
|
+
* (= `BPS`) means up to 100% of the job may be sponsored — same meaning as
|
|
6
|
+
* `OPFSubsidyProvider`). A token must have a non-zero `pctBps` to sponsor anything.
|
|
6
7
|
*/
|
|
7
8
|
export interface OneTimeTokenConfig {
|
|
8
|
-
/**
|
|
9
|
+
/** Per-job ceiling in basis points (1% = 100 bps); `'0'` = grant nothing, `'10000'` = 100% of job. */
|
|
9
10
|
pctBps: string;
|
|
10
11
|
/** Global one-time credit granted per user for this token, in human-readable token units. */
|
|
11
12
|
defaultCredit: string;
|
|
@@ -22,6 +22,32 @@ export declare enum SubsidyKind {
|
|
|
22
22
|
ONE_TIME = 1,
|
|
23
23
|
OTHER = 2
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The two ways a subsidy can be delivered, from `ISubsidyViewV2` (contracts v2). Both legs
|
|
27
|
+
* draw from the **same** per-provider budget (they are alternatives, never additive).
|
|
28
|
+
* - `REIMBURSEMENT` (0): the legacy claim-time path — `onSubsidyClaim` runs at claim and the
|
|
29
|
+
* subsidy is released to the payer *after* the job. The payer must still have fronted the
|
|
30
|
+
* funds (deposit + lock the full amount).
|
|
31
|
+
* - `PREFUNDED` (1): the new lock-time path — `onSubsidyLock` runs when the lock is created and
|
|
32
|
+
* the provider's tokens are pulled into a non-withdrawable sponsored bucket that backs the
|
|
33
|
+
* lock. A fully-sponsored lock needs **no payer deposit** (zero-deposit onboarding).
|
|
34
|
+
*/
|
|
35
|
+
export declare enum SubsidyMode {
|
|
36
|
+
REIMBURSEMENT = 0,
|
|
37
|
+
PREFUNDED = 1
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Which subsidy mode(s) a provider currently honours, from `ISubsidyModeConfig.subsidyModeConfig()`
|
|
41
|
+
* (owner-settable). Default is `BOTH`. When a mode is disabled its callback returns 0 **and** the
|
|
42
|
+
* matching `quoteSubsidyModes` leg (and, for the refund leg, the v1 `quoteSubsidy`) reports 0.
|
|
43
|
+
* `pause()` disables *all* subsidy; this only selects between the two modes. A dashboard reads this
|
|
44
|
+
* to know whether to offer a prepaid vs refund flow.
|
|
45
|
+
*/
|
|
46
|
+
export declare enum SubsidyModeConfig {
|
|
47
|
+
BOTH = 0,
|
|
48
|
+
REFUND_ONLY = 1,
|
|
49
|
+
PREPAID_ONLY = 2
|
|
50
|
+
}
|
|
25
51
|
/**
|
|
26
52
|
* One budget window as reported by `subsidyBuckets`. Amount fields (`limit`, `used`,
|
|
27
53
|
* `remaining`) are in human-readable token units. Always check `unlimited` first: when
|
|
@@ -68,9 +94,36 @@ export interface SubsidyQuote {
|
|
|
68
94
|
/** Bonus paid to the node, in human-readable token units. */
|
|
69
95
|
bonus: string;
|
|
70
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Result of one leg of `quoteSubsidyModes` (or of `quoteSubsidyByMode`), in human-readable
|
|
99
|
+
* token units. `subsidy` is how much of the job cost the provider covers under this mode (for
|
|
100
|
+
* `PREFUNDED` it is pre-funded into the lock, not paid to the payer; for `REIMBURSEMENT` it is
|
|
101
|
+
* released to the payer at claim). `bonus` rewards the node.
|
|
102
|
+
*/
|
|
103
|
+
export interface ModeQuote {
|
|
104
|
+
/** Which delivery mode this quote is for. */
|
|
105
|
+
mode: SubsidyMode;
|
|
106
|
+
/** Job cost covered by the provider under this mode, in human-readable token units. */
|
|
107
|
+
subsidy: string;
|
|
108
|
+
/** Bonus paid to the node under this mode, in human-readable token units. */
|
|
109
|
+
bonus: string;
|
|
110
|
+
}
|
|
71
111
|
/** ERC-165 base interface id (`IERC165.supportsInterface`). */
|
|
72
112
|
export declare const ERC165_INTERFACE_ID = "0x01ffc9a7";
|
|
73
|
-
/** ERC-165 interface id of `ISubsidyView` (the read/quote surface dashboards consume). */
|
|
113
|
+
/** ERC-165 interface id of `ISubsidyView` (the v1 read/quote surface dashboards consume). */
|
|
74
114
|
export declare const ISUBSIDY_VIEW_INTERFACE_ID = "0xcf08f23a";
|
|
75
|
-
/** ERC-165 interface id of `ISubsidyProvider` (the escrow-facing claim surface). */
|
|
115
|
+
/** ERC-165 interface id of `ISubsidyProvider` (the escrow-facing claim-time subsidy surface). */
|
|
76
116
|
export declare const ISUBSIDY_PROVIDER_INTERFACE_ID = "0x659fa925";
|
|
117
|
+
/**
|
|
118
|
+
* ERC-165 interface id of `ISubsidyViewV2` (dual-mode quoting: `quoteSubsidyModes` /
|
|
119
|
+
* `quoteSubsidyByMode`). Feature-detect it before calling the v2 quote methods.
|
|
120
|
+
*/
|
|
121
|
+
export declare const ISUBSIDY_VIEW_V2_INTERFACE_ID = "0x8cd610bb";
|
|
122
|
+
/** ERC-165 interface id of `ISubsidyModeConfig` (the owner-settable `subsidyModeConfig` switch). */
|
|
123
|
+
export declare const ISUBSIDY_MODE_CONFIG_INTERFACE_ID = "0x63edab4f";
|
|
124
|
+
/**
|
|
125
|
+
* ERC-165 interface id of `ISubsidyLockProvider` (the escrow-facing lock-time / prefunded
|
|
126
|
+
* sponsorship surface: `onSubsidyLock` / `onSubsidyRefund`). A provider advertising this can be
|
|
127
|
+
* passed as a `subsidyProvider` to `createLock`/`reLock`.
|
|
128
|
+
*/
|
|
129
|
+
export declare const ISUBSIDY_LOCK_PROVIDER_INTERFACE_ID = "0xefed9e7b";
|
|
@@ -152,5 +152,13 @@ export declare class Config {
|
|
|
152
152
|
* @type {string[]}
|
|
153
153
|
*/
|
|
154
154
|
SubsidyProviders?: string[];
|
|
155
|
+
/**
|
|
156
|
+
* Address of the external `SponsorshipLib` the Escrow v2 contracts delegatecall into (deployed
|
|
157
|
+
* once per network, shared by the community and enterprise escrows). Not needed to *call* a
|
|
158
|
+
* deployed escrow (the ABI is unaffected by library linking); kept here only for tooling that
|
|
159
|
+
* deploys/verifies escrows.
|
|
160
|
+
* @type {string}
|
|
161
|
+
*/
|
|
162
|
+
SponsorshipLib?: string;
|
|
155
163
|
}
|
|
156
164
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signer, TransactionRequest } from 'ethers';
|
|
2
|
-
import { AbiItem, ReceiptOrEstimate, ValidationResponse, DepositData, PermitData, AuthData, LockData } from '../@types/index.js';
|
|
2
|
+
import { AbiItem, ReceiptOrEstimate, ValidationResponse, DepositData, PermitData, AuthData, LockData, EscrowKind, Sponsorship } from '../@types/index.js';
|
|
3
3
|
import { Config } from '../config/index.js';
|
|
4
4
|
import { SmartContractWithAddress } from './SmartContractWithAddress.js';
|
|
5
5
|
export declare class EscrowContract extends SmartContractWithAddress {
|
|
@@ -20,7 +20,12 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
20
20
|
*/
|
|
21
21
|
getFunds(token: string): Promise<any>;
|
|
22
22
|
/**
|
|
23
|
-
* Get User Funds
|
|
23
|
+
* Get User Funds — `{ available, locked }`.
|
|
24
|
+
*
|
|
25
|
+
* NOTE (Escrow v2): `locked` now tracks only the payer's **own** locked funds (the payer-funded
|
|
26
|
+
* portion `P`), NOT the gross lock total. Any tokens a provider pre-funded (`S`) live in the
|
|
27
|
+
* separate sponsored bucket (`getSponsoredTotal` / `getSponsorship`) and are no longer counted
|
|
28
|
+
* here. If you previously assumed `locked == Σ getLocks().amount`, that is no longer true.
|
|
24
29
|
* @return {Promise<any>} User funds
|
|
25
30
|
*/
|
|
26
31
|
getUserFunds(payer: string, token: string): Promise<any>;
|
|
@@ -35,8 +40,14 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
35
40
|
*/
|
|
36
41
|
getLocks(token: string, payer: string, payee: string): Promise<LockData[]>;
|
|
37
42
|
/**
|
|
38
|
-
* Get Authorizations
|
|
39
|
-
*
|
|
43
|
+
* Get Authorizations. Each entry is an `auth` tuple; see {@link EscrowAuthorization} for the
|
|
44
|
+
* field order.
|
|
45
|
+
*
|
|
46
|
+
* NOTE (Escrow v2): the tuple gained a 7th field `expiryTimestamp` (unix seconds; `0` =
|
|
47
|
+
* indefinite) after which the payee can no longer create/extend locks — surface it in UIs and
|
|
48
|
+
* for "revoke" (re-authorize with a past timestamp). Also, `currentLockedAmount` now reflects
|
|
49
|
+
* only the payer-funded portion `P`.
|
|
50
|
+
* @return {Promise<[]>} Authorizations (raw ethers tuples; index or field-name access)
|
|
40
51
|
*/
|
|
41
52
|
getAuthorizations(token: string, payer: string, payee: string): Promise<any[]>;
|
|
42
53
|
/**
|
|
@@ -80,18 +91,27 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
80
91
|
withdrawTx(tokens: string[], amounts: string[], tokenDecimals?: number): Promise<TransactionRequest>;
|
|
81
92
|
private prepareWithdrawInputs;
|
|
82
93
|
/**
|
|
83
|
-
* Authorize locks
|
|
94
|
+
* Authorize a payee to create locks against the caller's escrow funds — or **update** an existing
|
|
95
|
+
* authorization (change `maxLockedAmount`/`maxLockSeconds`/`maxLockCounts`/`expiryTimestamp`).
|
|
96
|
+
*
|
|
97
|
+
* Unlike the earlier behaviour, this no longer no-ops when an authorization already exists: the
|
|
98
|
+
* call always goes through, so the on-chain record is created or overwritten. This is what makes
|
|
99
|
+
* **renew / shorten / revoke** reachable from the SDK — to revoke, re-authorize with a past
|
|
100
|
+
* `expiryTimestamp` (existing locks remain claimable/cancellable).
|
|
84
101
|
* @param {String} token Token address
|
|
85
102
|
* @param {String} payee,
|
|
86
103
|
* @param {String} maxLockedAmount,
|
|
87
104
|
* @param {String} maxLockSeconds,
|
|
88
105
|
* @param {String} maxLockCounts,
|
|
106
|
+
* @param {String} [expiryTimestamp='0'] unix ts (seconds) after which the payee can no longer
|
|
107
|
+
* create/extend locks (Escrow v2). `'0'` = indefinite (today's behaviour). A past timestamp
|
|
108
|
+
* revokes. Claim and cancel are never gated by it.
|
|
89
109
|
* @param {number} [tokenDecimals] optional number of decimals of the token
|
|
90
110
|
* @param {Boolean} estimateGas if True, return gas estimate
|
|
91
111
|
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
92
112
|
*/
|
|
93
|
-
authorize<G extends boolean = false>(token: string, payee: string, maxLockedAmount: string, maxLockSeconds: string, maxLockCounts: string, tokenDecimals?: number, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
94
|
-
authorizeTx(token: string, payee: string, maxLockedAmount: string, maxLockSeconds: string, maxLockCounts: string, tokenDecimals?: number): Promise<TransactionRequest
|
|
113
|
+
authorize<G extends boolean = false>(token: string, payee: string, maxLockedAmount: string, maxLockSeconds: string, maxLockCounts: string, expiryTimestamp?: string, tokenDecimals?: number, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
114
|
+
authorizeTx(token: string, payee: string, maxLockedAmount: string, maxLockSeconds: string, maxLockCounts: string, expiryTimestamp?: string, tokenDecimals?: number): Promise<TransactionRequest>;
|
|
95
115
|
private assertSingleTokenForDecimalsOverride;
|
|
96
116
|
private prepareAuthorizeInputs;
|
|
97
117
|
/**
|
|
@@ -110,14 +130,18 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
110
130
|
* @param {string} jobId
|
|
111
131
|
* @param {string} token
|
|
112
132
|
* @param {string} payer
|
|
113
|
-
* @param {string} amount
|
|
133
|
+
* @param {string} amount gross lock amount `L` (payer + sponsored)
|
|
114
134
|
* @param {string} expiry
|
|
135
|
+
* @param {string | number} [jobType='0'] job type (Escrow v2); routes the sponsorship gates
|
|
136
|
+
* @param {string[]} [subsidyProviders=[]] providers that may pre-fund the lock (Escrow v2);
|
|
137
|
+
* `[]` = plain payer-funded (identical to the old behaviour). At most `maxSponsorsPerLock()`
|
|
138
|
+
* (==10) unique providers; the payer covers whatever they don't.
|
|
115
139
|
* @param {number} [tokenDecimals]
|
|
116
140
|
* @param {Boolean} estimateGas if True, return gas estimate
|
|
117
141
|
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
118
142
|
*/
|
|
119
|
-
reLock<G extends boolean = false>(jobId: string, token: string, payer: string, amount: string, expiry: string, tokenDecimals?: number, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
120
|
-
reLockTx(jobId: string, token: string, payer: string, amount: string, expiry: string, tokenDecimals?: number): Promise<TransactionRequest>;
|
|
143
|
+
reLock<G extends boolean = false>(jobId: string, token: string, payer: string, amount: string, expiry: string, jobType?: string | number, subsidyProviders?: string[], tokenDecimals?: number, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
144
|
+
reLockTx(jobId: string, token: string, payer: string, amount: string, expiry: string, jobType?: string | number, subsidyProviders?: string[], tokenDecimals?: number): Promise<TransactionRequest>;
|
|
121
145
|
/**
|
|
122
146
|
* Extend multiple existing locks by updating amount/expiry.
|
|
123
147
|
* @param {string[]} jobIds
|
|
@@ -125,12 +149,23 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
125
149
|
* @param {string[]} payers
|
|
126
150
|
* @param {string[]} amounts
|
|
127
151
|
* @param {string[]} expiries
|
|
152
|
+
* @param {(string | number)[]} [jobTypes=[]] per-entry job types (Escrow v2); defaults to `0` per
|
|
153
|
+
* job when omitted. A non-empty array must match the number of jobs.
|
|
154
|
+
* @param {string[][]} [subsidyProvidersList=[]] per-entry provider lists (Escrow v2); defaults to
|
|
155
|
+
* `[]` (plain payer-funded) per job when omitted. A non-empty array must match the number of jobs.
|
|
128
156
|
* @param {number} [tokenDecimals]
|
|
129
157
|
* @param {Boolean} estimateGas if True, return gas estimate
|
|
130
158
|
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
131
159
|
*/
|
|
132
|
-
reLocks<G extends boolean = false>(jobIds: string[], tokens: string[], payers: string[], amounts: string[], expiries: string[], tokenDecimals?: number, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
133
|
-
reLocksTx(jobIds: string[], tokens: string[], payers: string[], amounts: string[], expiries: string[], tokenDecimals?: number): Promise<TransactionRequest>;
|
|
160
|
+
reLocks<G extends boolean = false>(jobIds: string[], tokens: string[], payers: string[], amounts: string[], expiries: string[], jobTypes?: (string | number)[], subsidyProvidersList?: string[][], tokenDecimals?: number, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
161
|
+
reLocksTx(jobIds: string[], tokens: string[], payers: string[], amounts: string[], expiries: string[], jobTypes?: (string | number)[], subsidyProvidersList?: string[][], tokenDecimals?: number): Promise<TransactionRequest>;
|
|
162
|
+
/**
|
|
163
|
+
* Normalize a per-entry optional array to exactly `length` entries. An empty/omitted array is
|
|
164
|
+
* padded with a FRESH `fallback` per entry (via the factory, so array fallbacks like `[]` are not
|
|
165
|
+
* shared references). A non-empty array of the wrong length throws, naming the offending array —
|
|
166
|
+
* a mismatch is a caller bug, not something to silently pad.
|
|
167
|
+
*/
|
|
168
|
+
private fillPerEntry;
|
|
134
169
|
private mapDeposits;
|
|
135
170
|
private mapPermits;
|
|
136
171
|
private mapAuths;
|
|
@@ -145,4 +180,111 @@ export declare class EscrowContract extends SmartContractWithAddress {
|
|
|
145
180
|
*/
|
|
146
181
|
cancelExpiredLocks<G extends boolean = false>(jobIds: string[], tokens: string[], payers: string[], payees: string[], estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
147
182
|
cancelExpiredLocksTx(jobIds: string[], tokens: string[], payers: string[], payees: string[]): Promise<TransactionRequest>;
|
|
183
|
+
/**
|
|
184
|
+
* A provider pulls its failed-push sponsorship refunds (parked when a push-back failed, see
|
|
185
|
+
* `SponsorRefunded` with `reclaimable=true`). Escrow v2 (`IEscrowLockSubsidy`).
|
|
186
|
+
* @param {string} token Token address
|
|
187
|
+
* @param {Boolean} estimateGas if True, return gas estimate
|
|
188
|
+
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
189
|
+
*/
|
|
190
|
+
sweepReclaimable<G extends boolean = false>(token: string, estimateGas?: G): Promise<ReceiptOrEstimate<G>>;
|
|
191
|
+
sweepReclaimableTx(token: string): Promise<TransactionRequest>;
|
|
192
|
+
/**
|
|
193
|
+
* Total tokens currently held in the non-withdrawable sponsored bucket (Escrow v2). This is the
|
|
194
|
+
* aggregate of all providers' pre-funded contributions backing live locks for `token`.
|
|
195
|
+
* @param {string} token Token address
|
|
196
|
+
* @param {number} [tokenDecimals] optional number of decimals of the token
|
|
197
|
+
* @return {Promise<string>} sponsored total, in human-readable token units
|
|
198
|
+
*/
|
|
199
|
+
getSponsoredTotal(token: string, tokenDecimals?: number): Promise<string>;
|
|
200
|
+
/**
|
|
201
|
+
* The amount a specific provider can `sweepReclaimable` for `token` (failed push-backs parked
|
|
202
|
+
* for later pull). Escrow v2.
|
|
203
|
+
* @param {string} provider Provider address
|
|
204
|
+
* @param {string} token Token address
|
|
205
|
+
* @param {number} [tokenDecimals] optional number of decimals of the token
|
|
206
|
+
* @return {Promise<string>} reclaimable amount, in human-readable token units
|
|
207
|
+
*/
|
|
208
|
+
getReclaimable(provider: string, token: string, tokenDecimals?: number): Promise<string>;
|
|
209
|
+
/**
|
|
210
|
+
* The per-lock sponsorship breakdown (Escrow v2): the total sponsored amount and each
|
|
211
|
+
* contributing provider with its share.
|
|
212
|
+
*
|
|
213
|
+
* The on-chain getter is token-agnostic, so the lock's `token` is **required** here to convert
|
|
214
|
+
* the amounts to the correct decimals (the caller already knows it from `getLocks`). It is not
|
|
215
|
+
* sent on-chain. Omitting the token and guessing decimals would silently mis-scale amounts for
|
|
216
|
+
* non-18-decimal tokens (e.g. USDC), so it is not allowed.
|
|
217
|
+
* @param {string} payee Payee (node) address
|
|
218
|
+
* @param {string} payer Payer address
|
|
219
|
+
* @param {string} jobId Job id of the lock
|
|
220
|
+
* @param {string} token The lock's token address (used only to resolve decimals)
|
|
221
|
+
* @param {number} [tokenDecimals] optional number of decimals of the token (skips the on-chain
|
|
222
|
+
* `decimals()` lookup)
|
|
223
|
+
* @return {Promise<Sponsorship>} `{ total, providers[], amounts[] }`, amounts in token units
|
|
224
|
+
*/
|
|
225
|
+
getSponsorship(payee: string, payer: string, jobId: string, token: string, tokenDecimals?: number): Promise<Sponsorship>;
|
|
226
|
+
/**
|
|
227
|
+
* The maximum number of unique providers that may sponsor a single lock (Escrow v2); passing
|
|
228
|
+
* more to `createLock`/`reLock` reverts "Too many sponsors". Cap your provider list to this.
|
|
229
|
+
* @return {Promise<number>} the cap (10 at v2)
|
|
230
|
+
*/
|
|
231
|
+
maxSponsorsPerLock(): Promise<number>;
|
|
232
|
+
/**
|
|
233
|
+
* The escrow flavour (Escrow v2): `COMMUNITY` (permissionless) or `ENTERPRISE` (fee-gated).
|
|
234
|
+
* @return {Promise<EscrowKind>} the escrow kind
|
|
235
|
+
*/
|
|
236
|
+
escrowKind(): Promise<EscrowKind>;
|
|
237
|
+
/**
|
|
238
|
+
* The escrow contract version (Escrow v2 returns 2). Use it, with ERC-165 discovery, to tell a
|
|
239
|
+
* v2 escrow apart from a legacy one.
|
|
240
|
+
* @return {Promise<number>} the version
|
|
241
|
+
*/
|
|
242
|
+
version(): Promise<number>;
|
|
243
|
+
/**
|
|
244
|
+
* ERC-165 feature detection (Escrow v2). Treats a revert / missing method as `false` so it is
|
|
245
|
+
* safe to call against a legacy escrow.
|
|
246
|
+
* @param {string} interfaceId The 4-byte interface id
|
|
247
|
+
* @return {Promise<boolean>} true if the interface is supported
|
|
248
|
+
*/
|
|
249
|
+
supportsInterface(interfaceId: string): Promise<boolean>;
|
|
250
|
+
/**
|
|
251
|
+
* Convenience check that the escrow implements `IEscrowCore` (the base escrow surface at v2
|
|
252
|
+
* signatures). A `false` here means a legacy (pre-v2) escrow.
|
|
253
|
+
* @return {Promise<boolean>} true if `IEscrowCore` is supported
|
|
254
|
+
*/
|
|
255
|
+
isEscrowCore(): Promise<boolean>;
|
|
256
|
+
/**
|
|
257
|
+
* Convenience check that the escrow implements `IEscrowLockSubsidy` (lock-time / prefunded
|
|
258
|
+
* sponsorship). Gate any sponsorship flow behind this.
|
|
259
|
+
* @return {Promise<boolean>} true if `IEscrowLockSubsidy` is supported
|
|
260
|
+
*/
|
|
261
|
+
isEscrowLockSubsidy(): Promise<boolean>;
|
|
262
|
+
/**
|
|
263
|
+
* Convenience check that the escrow implements `IEscrowEnterprise` (the fee-gated flavour's read
|
|
264
|
+
* passthroughs). The community escrow returns `false`.
|
|
265
|
+
* @return {Promise<boolean>} true if `IEscrowEnterprise` is supported
|
|
266
|
+
*/
|
|
267
|
+
isEscrowEnterprise(): Promise<boolean>;
|
|
268
|
+
/**
|
|
269
|
+
* (EnterpriseEscrow only) The configured fee collector; `ZERO_ADDRESS` means no fee gate.
|
|
270
|
+
* Feature-detect with {@link isEscrowEnterprise} first.
|
|
271
|
+
* @return {Promise<string>} the fee collector address
|
|
272
|
+
*/
|
|
273
|
+
feeCollector(): Promise<string>;
|
|
274
|
+
/**
|
|
275
|
+
* (EnterpriseEscrow only) Whether `token` passes the enterprise token gate (true if no
|
|
276
|
+
* collector). A lock passes the gate iff `isTokenAllowed(token) && previewFee(token, amount) <
|
|
277
|
+
* amount`; check both **before** a would-be reverting `createLock`.
|
|
278
|
+
* @param {string} token Token address
|
|
279
|
+
* @return {Promise<boolean>} true if the token is allowed
|
|
280
|
+
*/
|
|
281
|
+
isTokenAllowed(token: string): Promise<boolean>;
|
|
282
|
+
/**
|
|
283
|
+
* (EnterpriseEscrow only) The enterprise fee charged on `amount` (0 if no collector).
|
|
284
|
+
* @param {string} token Token address
|
|
285
|
+
* @param {string} amount gross lock amount, in human-readable token units
|
|
286
|
+
* @param {number} [tokenDecimals] optional number of decimals of the token
|
|
287
|
+
* @return {Promise<string>} the fee, in human-readable token units
|
|
288
|
+
*/
|
|
289
|
+
previewFee(token: string, amount: string, tokenDecimals?: number): Promise<string>;
|
|
148
290
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import { AbiItem, SubsidyBucketReport, SubsidyKind, SubsidyQuote } from '../@types/index.js';
|
|
2
|
+
import { AbiItem, ModeQuote, SubsidyBucketReport, SubsidyKind, SubsidyMode, SubsidyModeConfig, SubsidyQuote } from '../@types/index.js';
|
|
3
3
|
import { Config } from '../config/index.js';
|
|
4
4
|
import { SmartContractWithAddress } from './SmartContractWithAddress.js';
|
|
5
5
|
/**
|
|
@@ -59,6 +59,25 @@ export declare class SubsidyView extends SmartContractWithAddress {
|
|
|
59
59
|
* @return {Promise<boolean>} true if `ISubsidyProvider` is supported
|
|
60
60
|
*/
|
|
61
61
|
isSubsidyProvider(): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Convenience check that the provider implements `ISubsidyViewV2` (dual-mode quoting). Gate
|
|
64
|
+
* `quoteSubsidyModes` / `quoteSubsidyByMode` behind this.
|
|
65
|
+
* @return {Promise<boolean>} true if `ISubsidyViewV2` is supported
|
|
66
|
+
*/
|
|
67
|
+
isSubsidyViewV2(): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Convenience check that the provider implements `ISubsidyModeConfig` (the owner-settable
|
|
70
|
+
* mode switch). Gate `subsidyModeConfig` behind this.
|
|
71
|
+
* @return {Promise<boolean>} true if `ISubsidyModeConfig` is supported
|
|
72
|
+
*/
|
|
73
|
+
isSubsidyModeConfig(): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Convenience check that the provider implements `ISubsidyLockProvider` (the lock-time /
|
|
76
|
+
* prefunded sponsorship callbacks). A provider advertising this can be passed as a
|
|
77
|
+
* `subsidyProvider` to the escrow's `createLock`/`reLock`.
|
|
78
|
+
* @return {Promise<boolean>} true if `ISubsidyLockProvider` is supported
|
|
79
|
+
*/
|
|
80
|
+
isSubsidyLockProvider(): Promise<boolean>;
|
|
62
81
|
/**
|
|
63
82
|
* Get the full per-window budget report for a payer/token — the data behind a
|
|
64
83
|
* per-provider breakdown card. Amount fields are converted to human-readable token
|
|
@@ -96,6 +115,44 @@ export declare class SubsidyView extends SmartContractWithAddress {
|
|
|
96
115
|
* in human-readable token units
|
|
97
116
|
*/
|
|
98
117
|
quoteSubsidy(node: string, payer: string, jobType: number | string, token: string, amount: string, subsidyNeeded: string, tokenDecimals?: number): Promise<SubsidyQuote>;
|
|
118
|
+
/**
|
|
119
|
+
* Quote the subsidy a specific job would receive under **both** delivery modes in one call
|
|
120
|
+
* (`ISubsidyViewV2`) — the data behind a "refund vs prepaid" choice in the UI. Returns a
|
|
121
|
+
* two-element array `[{mode: REIMBURSEMENT, ...}, {mode: PREFUNDED, ...}]`. Both legs draw from
|
|
122
|
+
* the same per-provider budget (they are alternatives, not additive); a leg disabled via
|
|
123
|
+
* `subsidyModeConfig` reports `'0'`. Feature-detect with {@link isSubsidyViewV2} first — on a
|
|
124
|
+
* provider that does not implement v2 this reverts.
|
|
125
|
+
* @param {string} node Node address.
|
|
126
|
+
* @param {string} payer Payer address.
|
|
127
|
+
* @param {number | string} jobType Job type identifier.
|
|
128
|
+
* @param {string} token Token address.
|
|
129
|
+
* @param {string} amount Job cost, in human-readable token units.
|
|
130
|
+
* @param {string} subsidyNeeded Subsidy requested, in human-readable token units.
|
|
131
|
+
* @param {number} [tokenDecimals] optional number of decimals of the token.
|
|
132
|
+
* @return {Promise<ModeQuote[]>} one quote per mode, amounts in human-readable token units
|
|
133
|
+
*/
|
|
134
|
+
quoteSubsidyModes(node: string, payer: string, jobType: number | string, token: string, amount: string, subsidyNeeded: string, tokenDecimals?: number): Promise<ModeQuote[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Quote the subsidy a specific job would receive under a **single** delivery mode
|
|
137
|
+
* (`ISubsidyViewV2`). Feature-detect with {@link isSubsidyViewV2} first.
|
|
138
|
+
* @param {string} node Node address.
|
|
139
|
+
* @param {string} payer Payer address.
|
|
140
|
+
* @param {number | string} jobType Job type identifier.
|
|
141
|
+
* @param {string} token Token address.
|
|
142
|
+
* @param {string} amount Job cost, in human-readable token units.
|
|
143
|
+
* @param {string} subsidyNeeded Subsidy requested, in human-readable token units.
|
|
144
|
+
* @param {SubsidyMode} mode The delivery mode to quote (REIMBURSEMENT or PREFUNDED).
|
|
145
|
+
* @param {number} [tokenDecimals] optional number of decimals of the token.
|
|
146
|
+
* @return {Promise<SubsidyQuote>} the granted `subsidy` and `bonus`, in human-readable token units
|
|
147
|
+
*/
|
|
148
|
+
quoteSubsidyByMode(node: string, payer: string, jobType: number | string, token: string, amount: string, subsidyNeeded: string, mode: SubsidyMode, tokenDecimals?: number): Promise<SubsidyQuote>;
|
|
149
|
+
/**
|
|
150
|
+
* Get which subsidy mode(s) the provider currently honours (`ISubsidyModeConfig`): `BOTH`,
|
|
151
|
+
* `REFUND_ONLY` or `PREPAID_ONLY`. Read it to decide whether to offer a prepaid vs refund flow.
|
|
152
|
+
* Feature-detect with {@link isSubsidyModeConfig} first.
|
|
153
|
+
* @return {Promise<SubsidyModeConfig>} the configured mode
|
|
154
|
+
*/
|
|
155
|
+
subsidyModeConfig(): Promise<SubsidyModeConfig>;
|
|
99
156
|
/**
|
|
100
157
|
* Check whether a payer passes the user AccessList gate.
|
|
101
158
|
* @param {string} payer Payer address.
|
|
@@ -15,6 +15,16 @@ export declare function getFairGasPrice(signer: Signer, gasFeeMultiplier: number
|
|
|
15
15
|
* @returns A Promise that resolves to the number of decimal places for the token.
|
|
16
16
|
*/
|
|
17
17
|
export declare function getTokenDecimals(signer: Signer, token: string): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether an error from an ERC-165 `supportsInterface` (or similar view) call means "the contract
|
|
20
|
+
* does not implement this" rather than a transient infrastructure failure. Used so feature
|
|
21
|
+
* detection returns `false` for an unsupported/legacy contract but RE-THROWS genuine network/RPC
|
|
22
|
+
* errors (which should not be silently reported as "not supported"). Recognizes an on-chain revert
|
|
23
|
+
* (`CALL_EXCEPTION`), empty/garbage return data (`BAD_DATA`), and a missing ABI method (`TypeError`).
|
|
24
|
+
* @param {any} error The caught error
|
|
25
|
+
* @returns {boolean} true if the error indicates the feature is unsupported
|
|
26
|
+
*/
|
|
27
|
+
export declare function isUnsupportedInterfaceError(error: any): boolean;
|
|
18
28
|
/**
|
|
19
29
|
* Converts an amount of units to tokens
|
|
20
30
|
* @param {Signer} signer - The signer object to use.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oceanprotocol/lib",
|
|
3
3
|
"source": "./src/index.ts",
|
|
4
|
-
"version": "9.3.0-next.
|
|
4
|
+
"version": "9.3.0-next.4",
|
|
5
5
|
"description": "JavaScript client library for Ocean Protocol",
|
|
6
6
|
"module": "./dist/lib.module.mjs",
|
|
7
7
|
"type": "module",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@libp2p/websockets": "^10.1.21",
|
|
84
84
|
"@multiformats/multiaddr": "^13.0.3",
|
|
85
85
|
"@oasisprotocol/sapphire-ethers-v6": "^6.0.1",
|
|
86
|
-
"@oceanprotocol/ddo-js": "^0.
|
|
86
|
+
"@oceanprotocol/ddo-js": "^1.0.0",
|
|
87
87
|
"bignumber.js": "^11.1.5",
|
|
88
88
|
"cross-fetch": "^4.1.0",
|
|
89
89
|
"crypto-js": "^4.2.0",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@eslint/js": "^10.0.1",
|
|
100
100
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
101
|
-
"@oceanprotocol/contracts": "^3.
|
|
101
|
+
"@oceanprotocol/contracts": "^3.2.0-rc.1",
|
|
102
102
|
"@types/chai": "^5.2.3",
|
|
103
103
|
"@types/crypto-js": "^4.2.2",
|
|
104
104
|
"@types/jsonwebtoken": "^9.0.10",
|