@nevermined-io/core-kit 0.2.9 → 0.2.11
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/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +46 -0
- package/dist/contracts/CryptoTemplateBase.d.ts.map +1 -1
- package/dist/contracts/CryptoTemplateBase.js +4 -7
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +6 -4
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -1
- package/dist/nevermined/utils/ZeroDevPolicies.js +41 -53
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,GAAG,EACH,OAAO,EACP,OAAO,EAQP,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE7E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAKxD,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,GAAG,CAAA;IACR,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ;
|
|
1
|
+
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,GAAG,EACH,OAAO,EACP,OAAO,EAQP,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE7E,OAAO,EAAE,YAAY,EAAE,kBAAkB,E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AC5B,MAAM,GAAE,YAAiB;IAgBd,iBAAiB,CAC5B,KAAK,EAAE,sBAAsB,EAAE,EAC/B,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,MAAM,GAAE,YAAiB;IAgBd,QAAQ,CACnB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,YAAiB;IAgBd,IAAI,CACf,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,YAAiB,GACxB,OAAO,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;YAiBvC,6BAA6B;YA6E7B,wBAAwB;YAiHxB,4BAA4B;YAuB5B,oBAAoB;YAuBpB,gBAAgB;YAmIhB,qBAAqB;YAyBrB,6BAA6B;YAqB7B,qCAAqC;IAyEnD,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,aAAa;CAGtB"}
|
|
@@ -4,6 +4,28 @@ import { ContractsError, ContractSimulationError } from '../errors/index.js';
|
|
|
4
4
|
import { Instantiable } from '../Instantiable.abstract.js';
|
|
5
5
|
import { getInputsOfFunctionFormatted, getTransactionReceipt } from '../nevermined/index.js';
|
|
6
6
|
import { getChain } from '../utils/Network.js';
|
|
7
|
+
/**
|
|
8
|
+
* When a testnet RPC (Base Sepolia) fails internally, some providers return
|
|
9
|
+
* `eth_estimateGas` values equal to — or even above — the block gas limit
|
|
10
|
+
* instead of a real error. Using that value causes the node to reject the tx
|
|
11
|
+
* with `intrinsic gas too high` before it ever reaches the mempool.
|
|
12
|
+
*
|
|
13
|
+
* `writeContract` in viem re-estimates gas internally when `gas` isn't
|
|
14
|
+
* already set on the request (viem's `simulateContract` only performs
|
|
15
|
+
* `eth_call`, not `eth_estimateGas`). That means the naïve path has no
|
|
16
|
+
* chance to intercept a bogus estimate. We run the estimation ourselves
|
|
17
|
+
* here, sanity-check the result, and always pass an explicit gas value
|
|
18
|
+
* into `writeContract` so it doesn't re-query the misbehaving RPC.
|
|
19
|
+
*/
|
|
20
|
+
const GAS_SANITY_THRESHOLD = 25000000n;
|
|
21
|
+
const GAS_FALLBACK_CAP = 5000000n;
|
|
22
|
+
function capForBogusEstimate(estimatedGas, logger) {
|
|
23
|
+
if (estimatedGas < GAS_SANITY_THRESHOLD)
|
|
24
|
+
return estimatedGas;
|
|
25
|
+
logger.warn(`Estimated gas (${estimatedGas}) exceeds sanity threshold ` +
|
|
26
|
+
`(${GAS_SANITY_THRESHOLD}); overriding with ${GAS_FALLBACK_CAP} to bypass misbehaving RPC estimate.`);
|
|
27
|
+
return GAS_FALLBACK_CAP;
|
|
28
|
+
}
|
|
7
29
|
export class ContractBase extends Instantiable {
|
|
8
30
|
contractName;
|
|
9
31
|
contract;
|
|
@@ -369,9 +391,33 @@ export class ContractBase extends Instantiable {
|
|
|
369
391
|
account: from,
|
|
370
392
|
...(txparams.value && { value: txparams.value }),
|
|
371
393
|
});
|
|
394
|
+
// Resolve gas ourselves so `writeContract` never falls back to its own
|
|
395
|
+
// `eth_estimateGas`. An explicit caller `gasLimit` always wins; otherwise
|
|
396
|
+
// we estimate, apply the block-limit sanity check, and pin the result.
|
|
397
|
+
// If estimation itself fails we still honour any explicit cap.
|
|
398
|
+
let resolvedGas = gasLimit;
|
|
399
|
+
if (resolvedGas === undefined) {
|
|
400
|
+
try {
|
|
401
|
+
const estimate = await this.client.public.estimateContractGas({
|
|
402
|
+
address: contractAddress,
|
|
403
|
+
abi,
|
|
404
|
+
functionName: name,
|
|
405
|
+
args,
|
|
406
|
+
account: from,
|
|
407
|
+
...(txparams.value && { value: txparams.value }),
|
|
408
|
+
});
|
|
409
|
+
resolvedGas = capForBogusEstimate(estimate, this.logger);
|
|
410
|
+
}
|
|
411
|
+
catch (estErr) {
|
|
412
|
+
this.logger.warn(`estimateContractGas for "${name}" on "${contractName}" failed (${estErr}); ` +
|
|
413
|
+
`falling back to ${GAS_FALLBACK_CAP} to avoid a bogus RPC re-estimate in writeContract.`);
|
|
414
|
+
resolvedGas = GAS_FALLBACK_CAP;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
372
417
|
txHash = await this.client.wallet.writeContract({
|
|
373
418
|
...request,
|
|
374
419
|
account: from,
|
|
420
|
+
gas: resolvedGas,
|
|
375
421
|
});
|
|
376
422
|
}
|
|
377
423
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoTemplateBase.d.ts","sourceRoot":"","sources":["../../src/contracts/CryptoTemplateBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAY,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAA;AAEhE,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,SAAS,CAAC,iBAAiB,EAErB,GAAG,CAAA;IAET,SAAS,CAAC,kBAAkB,EAEtB,GAAG,CAAA;IAEI,aAAa,CACxB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,QAAQ,CAAC,EAAE,YAAY;
|
|
1
|
+
{"version":3,"file":"CryptoTemplateBase.d.ts","sourceRoot":"","sources":["../../src/contracts/CryptoTemplateBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAY,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAA;AAEhE,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,SAAS,CAAC,iBAAiB,EAErB,GAAG,CAAA;IAET,SAAS,CAAC,kBAAkB,EAEtB,GAAG,CAAA;IAEI,aAAa,CACxB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,QAAQ,CAAC,EAAE,YAAY;IAkBZ,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY;CAqB1B"}
|
|
@@ -9,14 +9,11 @@ export class CryptoTemplateBase extends ContractBase {
|
|
|
9
9
|
'function transfer(address to, uint256 amount) external returns (bool)',
|
|
10
10
|
]);
|
|
11
11
|
async transferERC20(from, to, amount, erc20Address, txParams) {
|
|
12
|
+
// An EOA transferring its own ERC-20 does not need to approve itself —
|
|
13
|
+
// `approve` only gates third-party `transferFrom`. The previous
|
|
14
|
+
// self-approve was a semantic no-op and doubled the gas-estimation
|
|
15
|
+
// footprint, making this path sensitive to misbehaving testnet RPCs.
|
|
12
16
|
const calls = [
|
|
13
|
-
{
|
|
14
|
-
contractAddress: erc20Address,
|
|
15
|
-
contractName: 'ERC20',
|
|
16
|
-
abi: this.TOKEN_APPROVE_ABI,
|
|
17
|
-
functionName: 'approve',
|
|
18
|
-
args: [from.address, amount],
|
|
19
|
-
},
|
|
20
17
|
{
|
|
21
18
|
contractAddress: erc20Address,
|
|
22
19
|
contractName: 'ERC20',
|
|
@@ -18,17 +18,19 @@ export declare const getRegisterPolicy: () => Policy;
|
|
|
18
18
|
export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) => Policy;
|
|
19
19
|
export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) => Policy;
|
|
20
20
|
export type BurnPolicyOptions = {
|
|
21
|
-
|
|
22
|
-
planId?: bigint;
|
|
21
|
+
contractAddresses: `0x${string}`[];
|
|
23
22
|
subscriberAddress: `0x${string}`;
|
|
24
23
|
maxAmount: bigint;
|
|
25
24
|
count?: number;
|
|
26
25
|
validUntil?: number;
|
|
27
26
|
};
|
|
28
27
|
export declare const getZeroDevBurnPolicies: (burnPolicyOptions: BurnPolicyOptions) => Policy[];
|
|
28
|
+
export type OrderContract = {
|
|
29
|
+
address: `0x${string}`;
|
|
30
|
+
isPayAsYouGo: boolean;
|
|
31
|
+
};
|
|
29
32
|
export type OrderPolicyOptions = {
|
|
30
|
-
|
|
31
|
-
planId?: bigint;
|
|
33
|
+
contracts: OrderContract[];
|
|
32
34
|
subscriberAddress: `0x${string}`;
|
|
33
35
|
numberOfPurchases: bigint;
|
|
34
36
|
totalAmount: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,GAAG,EAAoC,MAAM,MAAM,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAgB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,UAK3C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,SAelE;AAED,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,KAAK,MAAM,EAAE;;SAK/D,GAAG;;EAGZ;AACD,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WACV,CAAA;AAE1D,eAAO,MAAM,0BAA0B,cACwB,CAAA;AAE/D,eAAO,MAAM,gCAAgC,cAC2C,CAAA;AAExF,eAAO,MAAM,uBAAuB,cACuC,CAAA;AAE3E,eAAO,MAAM,cAAc,cAM1B,CAAA;AAED,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eA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,KAAK,MAAM,EAAE,EAAE,CAAA;IAClC,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,mBAAmB,iBAAiB,KAAG,MAAM,EAuCnF,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,aAAa,EAAE,CAAA;IAC1B,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;IACpC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,oBAAoB,kBAAkB,KAAG,MAAM,EAgFtF,CAAA"}
|
|
@@ -87,8 +87,8 @@ export const getAllContractsPolicy = (contractAddress) => getPolicy([
|
|
|
87
87
|
].filter(Boolean));
|
|
88
88
|
export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
|
|
89
89
|
const policies = [];
|
|
90
|
-
const
|
|
91
|
-
target:
|
|
90
|
+
const burnPermissions = burnPolicyOptions.contractAddresses.map((contractAddress) => ({
|
|
91
|
+
target: contractAddress,
|
|
92
92
|
abi: parseAbi([
|
|
93
93
|
'function burn(address _from, uint256 _planId, uint256 _value, uint256 _keyspace, bytes calldata _signature) external',
|
|
94
94
|
]),
|
|
@@ -99,19 +99,14 @@ export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
|
|
|
99
99
|
condition: ParamCondition.EQUAL,
|
|
100
100
|
value: burnPolicyOptions.subscriberAddress,
|
|
101
101
|
},
|
|
102
|
-
|
|
103
|
-
? {
|
|
104
|
-
condition: ParamCondition.EQUAL,
|
|
105
|
-
value: '0x' + burnPolicyOptions.planId.toString(16).padStart(64, '0'),
|
|
106
|
-
}
|
|
107
|
-
: null,
|
|
102
|
+
null,
|
|
108
103
|
{
|
|
109
104
|
condition: ParamCondition.LESS_THAN_OR_EQUAL,
|
|
110
105
|
value: burnPolicyOptions.maxAmount,
|
|
111
106
|
},
|
|
112
107
|
],
|
|
113
|
-
};
|
|
114
|
-
policies.push(getPolicy(
|
|
108
|
+
}));
|
|
109
|
+
policies.push(getPolicy(burnPermissions));
|
|
115
110
|
if (burnPolicyOptions.count) {
|
|
116
111
|
const rateLimitPolicy = toRateLimitPolicy({
|
|
117
112
|
count: burnPolicyOptions.count,
|
|
@@ -128,47 +123,43 @@ export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
|
|
|
128
123
|
};
|
|
129
124
|
export const getZeroDevOrderPolicies = (orderPolicyOptions) => {
|
|
130
125
|
const policies = [];
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
const orderPermissions = orderPolicyOptions.contracts.map((contract) => {
|
|
127
|
+
if (contract.isPayAsYouGo) {
|
|
128
|
+
return {
|
|
129
|
+
target: contract.address,
|
|
130
|
+
abi: parseAbi([
|
|
131
|
+
'function order(bytes32 _seed, uint256 _planId, bytes[] memory _params) external payable',
|
|
132
|
+
]),
|
|
133
|
+
valueLimit: 0n,
|
|
134
|
+
functionName: 'order',
|
|
135
|
+
args: [null, null],
|
|
136
|
+
};
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
];
|
|
161
|
-
}
|
|
162
|
-
const orderCallPolicy = {
|
|
163
|
-
target: orderPolicyOptions.contractAddress,
|
|
164
|
-
abi,
|
|
165
|
-
valueLimit: 0n,
|
|
166
|
-
functionName: 'order',
|
|
167
|
-
args,
|
|
168
|
-
};
|
|
138
|
+
return {
|
|
139
|
+
target: contract.address,
|
|
140
|
+
abi: parseAbi([
|
|
141
|
+
'function order(bytes32 _seed, uint256 _planId, address _creditsReceiver, uint256 _numberOfPurchases, bytes[] memory _params) external payable',
|
|
142
|
+
]),
|
|
143
|
+
valueLimit: 0n,
|
|
144
|
+
functionName: 'order',
|
|
145
|
+
args: [
|
|
146
|
+
null,
|
|
147
|
+
null,
|
|
148
|
+
{
|
|
149
|
+
condition: ParamCondition.EQUAL,
|
|
150
|
+
value: orderPolicyOptions.subscriberAddress,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
condition: ParamCondition.EQUAL,
|
|
154
|
+
value: orderPolicyOptions.numberOfPurchases,
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
const callPermissions = [...orderPermissions];
|
|
169
160
|
if (orderPolicyOptions.erc20ContractAddress &&
|
|
170
161
|
isAddress(orderPolicyOptions.erc20ContractAddress)) {
|
|
171
|
-
|
|
162
|
+
callPermissions.push({
|
|
172
163
|
target: orderPolicyOptions.erc20ContractAddress,
|
|
173
164
|
abi: parseAbi([
|
|
174
165
|
'function approve(address spender, uint256 amount) external returns (bool)',
|
|
@@ -185,12 +176,9 @@ export const getZeroDevOrderPolicies = (orderPolicyOptions) => {
|
|
|
185
176
|
value: orderPolicyOptions.totalAmount,
|
|
186
177
|
},
|
|
187
178
|
],
|
|
188
|
-
};
|
|
189
|
-
policies.push(getPolicy([orderCallPolicy, approvePolicy]));
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
policies.push(getPolicy([orderCallPolicy]));
|
|
179
|
+
});
|
|
193
180
|
}
|
|
181
|
+
policies.push(getPolicy(callPermissions));
|
|
194
182
|
if (orderPolicyOptions.count) {
|
|
195
183
|
const rateLimitPolicy = toRateLimitPolicy({
|
|
196
184
|
count: orderPolicyOptions.count,
|