@pushchain/core 6.0.26 → 6.0.27-alpha.1
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/AGW.md +226 -0
- package/CHANGELOG.md +18 -0
- package/README.md +2 -0
- package/package.json +7 -1
- package/src/lib/agentic/agentic.d.ts +23 -0
- package/src/lib/agentic/agentic.js +51 -0
- package/src/lib/agentic/agentic.types.d.ts +414 -0
- package/src/lib/agentic/agentic.types.js +3 -0
- package/src/lib/agentic/capabilities.d.ts +37 -0
- package/src/lib/agentic/capabilities.js +64 -0
- package/src/lib/agentic/chain.d.ts +3 -0
- package/src/lib/agentic/chain.js +15 -0
- package/src/lib/agentic/codec/abi-layout.d.ts +20 -0
- package/src/lib/agentic/codec/abi-layout.js +168 -0
- package/src/lib/agentic/codec/defaults.d.ts +51 -0
- package/src/lib/agentic/codec/defaults.js +53 -0
- package/src/lib/agentic/codec/ids.d.ts +35 -0
- package/src/lib/agentic/codec/ids.js +74 -0
- package/src/lib/agentic/codec/native.d.ts +73 -0
- package/src/lib/agentic/codec/native.js +341 -0
- package/src/lib/agentic/codec/pins.d.ts +20 -0
- package/src/lib/agentic/codec/pins.js +29 -0
- package/src/lib/agentic/codec/rules.d.ts +45 -0
- package/src/lib/agentic/codec/rules.js +110 -0
- package/src/lib/agentic/codec/selectors.d.ts +19 -0
- package/src/lib/agentic/codec/selectors.js +60 -0
- package/src/lib/agentic/codec/session.d.ts +54 -0
- package/src/lib/agentic/codec/session.js +65 -0
- package/src/lib/agentic/codec/svm-accounts.d.ts +35 -0
- package/src/lib/agentic/codec/svm-accounts.js +68 -0
- package/src/lib/agentic/codec/svm-idl.d.ts +11 -0
- package/src/lib/agentic/codec/svm-idl.js +226 -0
- package/src/lib/agentic/codec/svm-terms.d.ts +157 -0
- package/src/lib/agentic/codec/svm-terms.js +246 -0
- package/src/lib/agentic/codec/universal-terms.d.ts +82 -0
- package/src/lib/agentic/codec/universal-terms.js +43 -0
- package/src/lib/agentic/codec/universal.d.ts +14 -0
- package/src/lib/agentic/codec/universal.js +173 -0
- package/src/lib/agentic/constants.d.ts +12 -0
- package/src/lib/agentic/constants.js +16 -0
- package/src/lib/agentic/context.d.ts +29 -0
- package/src/lib/agentic/context.js +56 -0
- package/src/lib/agentic/contracts/abi/v6/agent-validator.d.ts +105 -0
- package/src/lib/agentic/contracts/abi/v6/agent-validator.js +149 -0
- package/src/lib/agentic/contracts/abi/v6/agw-factory.d.ts +1146 -0
- package/src/lib/agentic/contracts/abi/v6/agw-factory.js +1499 -0
- package/src/lib/agentic/contracts/abi/v6/agw.d.ts +1306 -0
- package/src/lib/agentic/contracts/abi/v6/agw.js +1713 -0
- package/src/lib/agentic/contracts/abi/v6/index.d.ts +6 -0
- package/src/lib/agentic/contracts/abi/v6/index.js +17 -0
- package/src/lib/agentic/contracts/abi/v6/smart-session.d.ts +1493 -0
- package/src/lib/agentic/contracts/abi/v6/smart-session.js +1965 -0
- package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.d.ts +1661 -0
- package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.js +2187 -0
- package/src/lib/agentic/contracts/donut-v6.d.ts +11 -0
- package/src/lib/agentic/contracts/donut-v6.js +15 -0
- package/src/lib/agentic/contracts/prc20-metadata.d.ts +26 -0
- package/src/lib/agentic/contracts/prc20-metadata.js +87 -0
- package/src/lib/agentic/contracts/reader.d.ts +35 -0
- package/src/lib/agentic/contracts/reader.js +16 -0
- package/src/lib/agentic/contracts/v6.d.ts +5739 -0
- package/src/lib/agentic/contracts/v6.js +343 -0
- package/src/lib/agentic/deployments.d.ts +61 -0
- package/src/lib/agentic/deployments.js +203 -0
- package/src/lib/agentic/errors.d.ts +65 -0
- package/src/lib/agentic/errors.js +84 -0
- package/src/lib/agentic/execution/guards.d.ts +9 -0
- package/src/lib/agentic/execution/guards.js +30 -0
- package/src/lib/agentic/execution/outbound.d.ts +55 -0
- package/src/lib/agentic/execution/outbound.js +187 -0
- package/src/lib/agentic/execution/send.d.ts +9 -0
- package/src/lib/agentic/execution/send.js +268 -0
- package/src/lib/agentic/execution/svm-instruction.d.ts +24 -0
- package/src/lib/agentic/execution/svm-instruction.js +40 -0
- package/src/lib/agentic/execution/svm-outbound.d.ts +18 -0
- package/src/lib/agentic/execution/svm-outbound.js +86 -0
- package/src/lib/agentic/execution/svm-payload.d.ts +18 -0
- package/src/lib/agentic/execution/svm-payload.js +136 -0
- package/src/lib/agentic/execution/svm-public.d.ts +5 -0
- package/src/lib/agentic/execution/svm-public.js +176 -0
- package/src/lib/agentic/execution/svm-quote.d.ts +11 -0
- package/src/lib/agentic/execution/svm-quote.js +24 -0
- package/src/lib/agentic/execution/svm-send.d.ts +44 -0
- package/src/lib/agentic/execution/svm-send.js +87 -0
- package/src/lib/agentic/index.d.ts +5 -0
- package/src/lib/agentic/index.js +10 -0
- package/src/lib/agentic/management/common.d.ts +29 -0
- package/src/lib/agentic/management/common.js +116 -0
- package/src/lib/agentic/management/create.d.ts +4 -0
- package/src/lib/agentic/management/create.js +138 -0
- package/src/lib/agentic/management/duplicates.d.ts +4 -0
- package/src/lib/agentic/management/duplicates.js +20 -0
- package/src/lib/agentic/management/label.d.ts +3 -0
- package/src/lib/agentic/management/label.js +17 -0
- package/src/lib/agentic/management/prepare.d.ts +7 -0
- package/src/lib/agentic/management/prepare.js +95 -0
- package/src/lib/agentic/management/rules-write.d.ts +42 -0
- package/src/lib/agentic/management/rules-write.js +279 -0
- package/src/lib/agentic/management/svm-context.d.ts +25 -0
- package/src/lib/agentic/management/svm-context.js +55 -0
- package/src/lib/agentic/management/svm-metadata.d.ts +10 -0
- package/src/lib/agentic/management/svm-metadata.js +56 -0
- package/src/lib/agentic/management/svm-public.d.ts +6 -0
- package/src/lib/agentic/management/svm-public.js +125 -0
- package/src/lib/agentic/management/svm.d.ts +27 -0
- package/src/lib/agentic/management/svm.js +150 -0
- package/src/lib/agentic/presets/catalog.d.ts +26 -0
- package/src/lib/agentic/presets/catalog.js +307 -0
- package/src/lib/agentic/presets/index.d.ts +5 -0
- package/src/lib/agentic/presets/index.js +265 -0
- package/src/lib/agentic/presets/types.d.ts +48 -0
- package/src/lib/agentic/presets/types.js +3 -0
- package/src/lib/agentic/public-rule.d.ts +9 -0
- package/src/lib/agentic/public-rule.js +326 -0
- package/src/lib/agentic/reads/checkpoints.d.ts +17 -0
- package/src/lib/agentic/reads/checkpoints.js +109 -0
- package/src/lib/agentic/reads/rules.d.ts +42 -0
- package/src/lib/agentic/reads/rules.js +302 -0
- package/src/lib/agentic/reads/snapshot.d.ts +28 -0
- package/src/lib/agentic/reads/snapshot.js +85 -0
- package/src/lib/agentic/reads/svm.d.ts +17 -0
- package/src/lib/agentic/reads/svm.js +52 -0
- package/src/lib/agentic/reads/wallets.d.ts +25 -0
- package/src/lib/agentic/reads/wallets.js +122 -0
- package/src/lib/agentic/response.d.ts +41 -0
- package/src/lib/agentic/response.js +358 -0
- package/src/lib/agentic/revert.d.ts +7 -0
- package/src/lib/agentic/revert.js +102 -0
- package/src/lib/agentic/runtime.d.ts +58 -0
- package/src/lib/agentic/runtime.js +104 -0
- package/src/lib/agentic/utils.d.ts +57 -0
- package/src/lib/agentic/utils.js +165 -0
- package/src/lib/agentic/wallet.d.ts +32 -0
- package/src/lib/agentic/wallet.js +130 -0
- package/src/lib/constants/enums.d.ts +6 -3
- package/src/lib/constants/enums.js +6 -3
- package/src/lib/constants/index.d.ts +61 -4
- package/src/lib/constants/index.js +17 -3
- package/src/lib/constants/read-state.d.ts +9 -0
- package/src/lib/constants/read-state.js +13 -1
- package/src/lib/index.d.ts +8 -2
- package/src/lib/index.js +9 -1
- package/src/lib/orchestrator/internals/errors.d.ts +7 -0
- package/src/lib/orchestrator/internals/errors.js +13 -1
- package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
- package/src/lib/orchestrator/internals/execute-standard.js +3 -3
- package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
- package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
- package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
- package/src/lib/orchestrator/orchestrator.d.ts +3 -0
- package/src/lib/orchestrator/orchestrator.js +13 -1
- package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
- package/src/lib/orchestrator/route-detector.js +3 -2
- package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
- package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
- package/src/lib/progress-hook/progress-hook.js +63 -0
- package/src/lib/progress-hook/progress-hook.types.d.ts +10 -1
- package/src/lib/progress-hook/progress-hook.types.js +10 -0
- package/src/lib/push-chain/push-chain.d.ts +57 -15
- package/src/lib/push-chain/push-chain.js +66 -7
- package/src/lib/read-state/destination.js +6 -1
- package/src/lib/read-state/read-params.d.ts +3 -3
- package/src/lib/read-state/read-params.js +3 -2
- package/src/lib/read-state/read-state.types.d.ts +3 -1
- package/src/lib/read-state/read-tracker.js +2 -2
- package/src/lib/read-state/spec-builder.js +1 -1
- package/src/lib/universal/prc20-address.d.ts +15 -0
- package/src/lib/universal/prc20-address.js +135 -0
- package/src/lib/utils.d.ts +6 -13
- package/src/lib/utils.js +5 -128
- package/src/lib/vm-client/evm-client.js +34 -20
package/src/lib/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { convertOriginToExecutor, fromChainAgnostic, convertExecutorToOriginAccount, toChainAgnostic, toUniversal, deriveExecutorAccount, resolveControllerAccount } from './universal/account';
|
|
2
2
|
import { construct, toUniversal as toUniversalSigner, toUniversalFromKeypair } from './universal/signer';
|
|
3
3
|
import { CHAIN, PUSH_NETWORK } from './constants/enums';
|
|
4
|
-
import {
|
|
4
|
+
import { getPRC20Address } from './universal/prc20-address';
|
|
5
5
|
import type { PushChain } from './push-chain/push-chain';
|
|
6
6
|
import type { PC20AddressResult } from './orchestrator/orchestrator.types';
|
|
7
7
|
import type { Idl } from '@coral-xyz/anchor';
|
|
@@ -274,18 +274,7 @@ export declare class Utils {
|
|
|
274
274
|
* });
|
|
275
275
|
* ```
|
|
276
276
|
*/
|
|
277
|
-
getPRC20Address
|
|
278
|
-
chain: string;
|
|
279
|
-
address: string;
|
|
280
|
-
}, options?: {
|
|
281
|
-
network?: PUSH_NETWORK;
|
|
282
|
-
}): {
|
|
283
|
-
address: `0x${string}`;
|
|
284
|
-
chain: CHAIN;
|
|
285
|
-
symbol: string;
|
|
286
|
-
decimals: number;
|
|
287
|
-
network: PUSH_NETWORK;
|
|
288
|
-
};
|
|
277
|
+
getPRC20Address: typeof getPRC20Address;
|
|
289
278
|
/**
|
|
290
279
|
* Resolve a PC20 token against UniversalCore's on-chain registry, and list
|
|
291
280
|
* every confirmed address it has across chains.
|
|
@@ -330,6 +319,10 @@ export declare class Utils {
|
|
|
330
319
|
strict?: boolean;
|
|
331
320
|
}): Promise<PC20AddressResult>;
|
|
332
321
|
};
|
|
322
|
+
/** Pure preset discovery/templates; internal encoders and identifiers stay private. */
|
|
323
|
+
static readonly agentic: Readonly<{
|
|
324
|
+
presets: import("./agentic").AgenticPresets;
|
|
325
|
+
}>;
|
|
333
326
|
/**
|
|
334
327
|
* Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
|
|
335
328
|
*/
|
package/src/lib/utils.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Utils = void 0;
|
|
4
|
+
const presets_1 = require("./agentic/presets");
|
|
4
5
|
const account_1 = require("./universal/account");
|
|
5
6
|
const signer_1 = require("./universal/signer");
|
|
6
7
|
const enums_1 = require("./constants/enums");
|
|
7
8
|
const tokens_1 = require("./constants/tokens");
|
|
8
|
-
const
|
|
9
|
+
const prc20_address_1 = require("./universal/prc20-address");
|
|
9
10
|
const viem_1 = require("viem");
|
|
10
11
|
const resolver_1 = require("./orchestrator/internals/pc20/resolver");
|
|
11
12
|
const errors_1 = require("./orchestrator/internals/pc20/errors");
|
|
@@ -584,133 +585,7 @@ class Utils {
|
|
|
584
585
|
* });
|
|
585
586
|
* ```
|
|
586
587
|
*/
|
|
587
|
-
getPRC20Address
|
|
588
|
-
const network = options?.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT;
|
|
589
|
-
const assertDeployed = (addr, ctx) => {
|
|
590
|
-
if (!addr || addr === '0xTBD') {
|
|
591
|
-
throw new Error(`PRC20 address not available for ${ctx} on network ${network}`);
|
|
592
|
-
}
|
|
593
|
-
return addr;
|
|
594
|
-
};
|
|
595
|
-
// PushChainMoveableToken (pETH, pSOL, pUSDT(BNB), …) carries its PRC-20 address
|
|
596
|
-
// and origin `sourceChain` directly — no registry lookup needed.
|
|
597
|
-
const pcToken = token;
|
|
598
|
-
if (pcToken.prc20Address) {
|
|
599
|
-
return {
|
|
600
|
-
address: assertDeployed(pcToken.prc20Address, `${pcToken.symbol ?? 'token'} (${pcToken.sourceChain ?? 'unknown'})`),
|
|
601
|
-
chain: pcToken.sourceChain,
|
|
602
|
-
symbol: pcToken.symbol,
|
|
603
|
-
decimals: pcToken.decimals,
|
|
604
|
-
network,
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
// Infer origin chain, symbol, decimals by matching against MOVEABLE_TOKENS
|
|
608
|
-
let originChain;
|
|
609
|
-
let tokenSymbol;
|
|
610
|
-
let tokenDecimals;
|
|
611
|
-
if ('symbol' in token) {
|
|
612
|
-
// MoveableToken path: infer chain by symbol + address
|
|
613
|
-
for (const [key, list] of Object.entries(tokens_1.MOVEABLE_TOKENS)) {
|
|
614
|
-
const k = key;
|
|
615
|
-
const match = (list ?? []).find((t) => t.symbol === token.symbol && t.address === token.address);
|
|
616
|
-
if (match) {
|
|
617
|
-
originChain = k;
|
|
618
|
-
tokenSymbol = match.symbol;
|
|
619
|
-
tokenDecimals = match.decimals;
|
|
620
|
-
break;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
else {
|
|
625
|
-
// { chain, address } path: trust the provided chain and resolve symbol via registry
|
|
626
|
-
originChain = token.chain;
|
|
627
|
-
const list = tokens_1.MOVEABLE_TOKENS[originChain] ?? [];
|
|
628
|
-
const match = list.find((t) => t.address === token.address);
|
|
629
|
-
if (match) {
|
|
630
|
-
tokenSymbol = match.symbol;
|
|
631
|
-
tokenDecimals = match.decimals;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
if (!originChain || !tokenSymbol || tokenDecimals === undefined) {
|
|
635
|
-
throw new Error('Unable to infer origin chain or token symbol for token');
|
|
636
|
-
}
|
|
637
|
-
const map = chain_1.SYNTHETIC_PUSH_ERC20[network];
|
|
638
|
-
if (!map) {
|
|
639
|
-
throw new Error(`No PRC20 address map configured for network: ${network}`);
|
|
640
|
-
}
|
|
641
|
-
// Map token → synthetic key by origin chain family
|
|
642
|
-
const isEthFamily = originChain === enums_1.CHAIN.ETHEREUM_MAINNET ||
|
|
643
|
-
originChain === enums_1.CHAIN.ETHEREUM_SEPOLIA;
|
|
644
|
-
const isArbFamily = originChain === enums_1.CHAIN.ARBITRUM_SEPOLIA;
|
|
645
|
-
const isBaseFamily = originChain === enums_1.CHAIN.BASE_SEPOLIA;
|
|
646
|
-
const isBnbFamily = originChain === enums_1.CHAIN.BNB_TESTNET;
|
|
647
|
-
const isSolFamily = originChain === enums_1.CHAIN.SOLANA_DEVNET;
|
|
648
|
-
let key;
|
|
649
|
-
switch (tokenSymbol) {
|
|
650
|
-
case 'ETH': {
|
|
651
|
-
if (isEthFamily)
|
|
652
|
-
key = 'pETH';
|
|
653
|
-
else if (isArbFamily)
|
|
654
|
-
key = 'pETH_ARB';
|
|
655
|
-
else if (isBaseFamily)
|
|
656
|
-
key = 'pETH_BASE';
|
|
657
|
-
else
|
|
658
|
-
throw new Error('Unsupported ETH origin chain for synthetic mapping');
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
661
|
-
case 'SOL': {
|
|
662
|
-
if (!isSolFamily)
|
|
663
|
-
throw new Error('SOL token provided but origin is not Solana');
|
|
664
|
-
key = 'pSOL';
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
case 'BNB': {
|
|
668
|
-
if (!isBnbFamily)
|
|
669
|
-
throw new Error('BNB token provided but origin is not BNB Testnet');
|
|
670
|
-
key = 'pBNB';
|
|
671
|
-
break;
|
|
672
|
-
}
|
|
673
|
-
case 'USDT': {
|
|
674
|
-
if (isEthFamily)
|
|
675
|
-
key = 'USDT_ETH';
|
|
676
|
-
else if (isArbFamily)
|
|
677
|
-
key = 'USDT_ARB';
|
|
678
|
-
else if (isBaseFamily)
|
|
679
|
-
key = 'USDT_BASE';
|
|
680
|
-
else if (isBnbFamily)
|
|
681
|
-
key = 'USDT_BSC';
|
|
682
|
-
else if (isSolFamily)
|
|
683
|
-
key = 'USDT_SOL';
|
|
684
|
-
else
|
|
685
|
-
throw new Error('Unsupported USDT origin chain for synthetic mapping');
|
|
686
|
-
break;
|
|
687
|
-
}
|
|
688
|
-
case 'USDC': {
|
|
689
|
-
if (isEthFamily)
|
|
690
|
-
key = 'USDC_ETH';
|
|
691
|
-
else if (isArbFamily)
|
|
692
|
-
key = 'USDC_ARB';
|
|
693
|
-
else if (isBaseFamily)
|
|
694
|
-
key = 'USDC_BASE';
|
|
695
|
-
else if (isBnbFamily)
|
|
696
|
-
key = 'USDC_BSC';
|
|
697
|
-
else if (isSolFamily)
|
|
698
|
-
key = 'USDC_SOL';
|
|
699
|
-
else
|
|
700
|
-
throw new Error('Unsupported USDC origin chain for synthetic mapping');
|
|
701
|
-
break;
|
|
702
|
-
}
|
|
703
|
-
default:
|
|
704
|
-
throw new Error(`Unsupported token symbol: ${tokenSymbol}`);
|
|
705
|
-
}
|
|
706
|
-
return {
|
|
707
|
-
address: assertDeployed(map[key], `${tokenSymbol} on ${originChain}`),
|
|
708
|
-
chain: originChain,
|
|
709
|
-
symbol: tokenSymbol,
|
|
710
|
-
decimals: tokenDecimals,
|
|
711
|
-
network,
|
|
712
|
-
};
|
|
713
|
-
},
|
|
588
|
+
getPRC20Address: prc20_address_1.getPRC20Address,
|
|
714
589
|
/**
|
|
715
590
|
* Resolve a PC20 token against UniversalCore's on-chain registry, and list
|
|
716
591
|
* every confirmed address it has across chains.
|
|
@@ -788,6 +663,8 @@ class Utils {
|
|
|
788
663
|
};
|
|
789
664
|
},
|
|
790
665
|
};
|
|
666
|
+
/** Pure preset discovery/templates; internal encoders and identifiers stay private. */
|
|
667
|
+
static agentic = Object.freeze({ presets: presets_1.agenticPresets });
|
|
791
668
|
/**
|
|
792
669
|
* Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
|
|
793
670
|
*/
|
|
@@ -205,12 +205,19 @@ class EvmClient {
|
|
|
205
205
|
const resolveGas = async () => {
|
|
206
206
|
if (explicitGas)
|
|
207
207
|
return explicitGas;
|
|
208
|
-
const estimate = () =>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
const estimate = async () => {
|
|
209
|
+
const estimatedGas = await this.publicClient.estimateGas({
|
|
210
|
+
account: signer.account.address,
|
|
211
|
+
to,
|
|
212
|
+
data,
|
|
213
|
+
value,
|
|
214
|
+
});
|
|
215
|
+
// Leave headroom for nested calls and state changes before inclusion,
|
|
216
|
+
// as on the EIP-7702 batch path. Donut can return an estimate that
|
|
217
|
+
// reverts inside an AGW -> gateway -> token call even at the same state.
|
|
218
|
+
// This is the Push execution limit, separate from destination gas.
|
|
219
|
+
return (estimatedGas * BigInt(120) + BigInt(99)) / BigInt(100);
|
|
220
|
+
};
|
|
214
221
|
if (data !== '0x')
|
|
215
222
|
return estimate();
|
|
216
223
|
// A plain native transfer to a code-free EOA always costs 21k. Empty
|
|
@@ -323,30 +330,37 @@ class EvmClient {
|
|
|
323
330
|
catch (err) {
|
|
324
331
|
throw new EIP7702NotSupportedError(err);
|
|
325
332
|
}
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
//
|
|
333
|
+
// Prefer authorization-aware estimation of the actual type-4 transaction.
|
|
334
|
+
// Some RPCs reject that format or state overrides. An ordinary estimate is
|
|
335
|
+
// valid only if the account is already delegated to this exact executor.
|
|
336
|
+
// Never guess a per-call ceiling: contract deployment/grants vary in cost.
|
|
337
|
+
const delegation = ('0xef0100' + executor.slice(2));
|
|
329
338
|
let gas;
|
|
330
339
|
try {
|
|
331
340
|
gas = await this.publicClient.estimateGas({
|
|
332
341
|
account,
|
|
333
342
|
to: account,
|
|
334
343
|
data,
|
|
335
|
-
|
|
336
|
-
{
|
|
337
|
-
address: account,
|
|
338
|
-
code: ('0xef0100' + executor.slice(2)),
|
|
339
|
-
},
|
|
340
|
-
],
|
|
344
|
+
authorizationList: [authorization],
|
|
341
345
|
});
|
|
342
|
-
gas = (gas * BigInt(120)) / BigInt(100); // headroom for delegation + auth
|
|
343
346
|
}
|
|
344
347
|
catch {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
348
|
+
const code = await this.publicClient.getCode({ address: account });
|
|
349
|
+
if (code?.toLowerCase() === delegation.toLowerCase()) {
|
|
350
|
+
gas = await this.publicClient.estimateGas({ account, to: account, data });
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
gas = await this.publicClient.estimateGas({
|
|
354
|
+
account,
|
|
355
|
+
to: account,
|
|
356
|
+
data,
|
|
357
|
+
stateOverride: [{ address: account, code: delegation }],
|
|
358
|
+
});
|
|
359
|
+
}
|
|
349
360
|
}
|
|
361
|
+
// The fallback estimates omit authorization processing (25k intrinsic).
|
|
362
|
+
// Include it conservatively on every path, plus 20% execution headroom.
|
|
363
|
+
gas = (gas * BigInt(120) + BigInt(99)) / BigInt(100) + BigInt(25_000);
|
|
350
364
|
const unsignedTx = (0, viem_1.serializeTransaction)({
|
|
351
365
|
chainId,
|
|
352
366
|
type: 'eip7702',
|