@aomi-labs/client 0.1.21 → 0.1.22
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/cli.js +3719 -2778
- package/dist/index.cjs +207 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +131 -141
- package/dist/index.d.ts +131 -141
- package/dist/index.js +205 -193
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/skills/aomi-transact/SKILL.md +239 -109
package/dist/index.js
CHANGED
|
@@ -1272,6 +1272,9 @@ function parseAAConfig(value) {
|
|
|
1272
1272
|
if (typeof value.provider !== "string" || !value.provider) {
|
|
1273
1273
|
throw new Error("Invalid AA config: provider must be a non-empty string");
|
|
1274
1274
|
}
|
|
1275
|
+
if (value.provider !== "alchemy" && value.provider !== "pimlico") {
|
|
1276
|
+
throw new Error('Invalid AA config: provider must be either "alchemy" or "pimlico"');
|
|
1277
|
+
}
|
|
1275
1278
|
if (typeof value.fallbackToEoa !== "boolean") {
|
|
1276
1279
|
throw new Error("Invalid AA config: fallbackToEoa must be a boolean");
|
|
1277
1280
|
}
|
|
@@ -1322,7 +1325,7 @@ function buildAAExecutionPlan(config, chainConfig) {
|
|
|
1322
1325
|
};
|
|
1323
1326
|
}
|
|
1324
1327
|
function getWalletExecutorReady(providerState) {
|
|
1325
|
-
return !providerState.
|
|
1328
|
+
return !providerState.resolved || !providerState.pending && (Boolean(providerState.account) || Boolean(providerState.error) || providerState.resolved.fallbackToEoa);
|
|
1326
1329
|
}
|
|
1327
1330
|
function mapCall(call) {
|
|
1328
1331
|
return {
|
|
@@ -1391,10 +1394,10 @@ async function executeWalletCalls(params) {
|
|
|
1391
1394
|
chainsById,
|
|
1392
1395
|
getPreferredRpcUrl
|
|
1393
1396
|
} = params;
|
|
1394
|
-
if (providerState.
|
|
1397
|
+
if (providerState.resolved && providerState.account) {
|
|
1395
1398
|
return executeViaAA(callList, providerState);
|
|
1396
1399
|
}
|
|
1397
|
-
if (providerState.
|
|
1400
|
+
if (providerState.resolved && providerState.error && !providerState.resolved.fallbackToEoa) {
|
|
1398
1401
|
throw providerState.error;
|
|
1399
1402
|
}
|
|
1400
1403
|
return executeViaEoa({
|
|
@@ -1411,26 +1414,26 @@ async function executeWalletCalls(params) {
|
|
|
1411
1414
|
}
|
|
1412
1415
|
async function executeViaAA(callList, providerState) {
|
|
1413
1416
|
var _a;
|
|
1414
|
-
const
|
|
1415
|
-
const
|
|
1416
|
-
if (!
|
|
1417
|
+
const account = providerState.account;
|
|
1418
|
+
const resolved = providerState.resolved;
|
|
1419
|
+
if (!account || !resolved) {
|
|
1417
1420
|
throw (_a = providerState.error) != null ? _a : new Error("smart_account_unavailable");
|
|
1418
1421
|
}
|
|
1419
1422
|
const callsPayload = callList.map(mapCall);
|
|
1420
|
-
const receipt = callList.length > 1 ? await
|
|
1423
|
+
const receipt = callList.length > 1 ? await account.sendBatchTransaction(callsPayload) : await account.sendTransaction(callsPayload[0]);
|
|
1421
1424
|
const txHash = receipt.transactionHash;
|
|
1422
|
-
const providerPrefix =
|
|
1423
|
-
let delegationAddress =
|
|
1424
|
-
if (
|
|
1425
|
+
const providerPrefix = account.provider.toLowerCase();
|
|
1426
|
+
let delegationAddress = account.mode === "7702" ? account.delegationAddress : void 0;
|
|
1427
|
+
if (account.mode === "7702" && !delegationAddress) {
|
|
1425
1428
|
delegationAddress = await resolve7702Delegation(txHash, callList);
|
|
1426
1429
|
}
|
|
1427
1430
|
return {
|
|
1428
1431
|
txHash,
|
|
1429
1432
|
txHashes: [txHash],
|
|
1430
|
-
executionKind: `${providerPrefix}_${
|
|
1433
|
+
executionKind: `${providerPrefix}_${account.mode}`,
|
|
1431
1434
|
batched: callList.length > 1,
|
|
1432
|
-
sponsored:
|
|
1433
|
-
AAAddress:
|
|
1435
|
+
sponsored: resolved.sponsorship !== "disabled",
|
|
1436
|
+
AAAddress: account.AAAddress,
|
|
1434
1437
|
delegationAddress
|
|
1435
1438
|
};
|
|
1436
1439
|
}
|
|
@@ -1474,7 +1477,7 @@ async function executeViaEoa({
|
|
|
1474
1477
|
}) {
|
|
1475
1478
|
var _a, _b;
|
|
1476
1479
|
const { createPublicClient, createWalletClient, http } = await import("viem");
|
|
1477
|
-
const { privateKeyToAccount:
|
|
1480
|
+
const { privateKeyToAccount: privateKeyToAccount3 } = await import("viem/accounts");
|
|
1478
1481
|
const hashes = [];
|
|
1479
1482
|
if (localPrivateKey) {
|
|
1480
1483
|
for (const call of callList) {
|
|
@@ -1486,7 +1489,7 @@ async function executeViaEoa({
|
|
|
1486
1489
|
if (!rpcUrl) {
|
|
1487
1490
|
throw new Error(`No RPC for chain ${call.chainId}`);
|
|
1488
1491
|
}
|
|
1489
|
-
const account =
|
|
1492
|
+
const account = privateKeyToAccount3(localPrivateKey);
|
|
1490
1493
|
const walletClient = createWalletClient({
|
|
1491
1494
|
account,
|
|
1492
1495
|
chain,
|
|
@@ -1559,7 +1562,7 @@ async function executeViaEoa({
|
|
|
1559
1562
|
};
|
|
1560
1563
|
}
|
|
1561
1564
|
|
|
1562
|
-
// src/aa/env.ts
|
|
1565
|
+
// src/aa/alchemy/env.ts
|
|
1563
1566
|
var ALCHEMY_API_KEY_ENVS = [
|
|
1564
1567
|
"ALCHEMY_API_KEY",
|
|
1565
1568
|
"NEXT_PUBLIC_ALCHEMY_API_KEY"
|
|
@@ -1568,10 +1571,14 @@ var ALCHEMY_GAS_POLICY_ENVS = [
|
|
|
1568
1571
|
"ALCHEMY_GAS_POLICY_ID",
|
|
1569
1572
|
"NEXT_PUBLIC_ALCHEMY_GAS_POLICY_ID"
|
|
1570
1573
|
];
|
|
1574
|
+
|
|
1575
|
+
// src/aa/pimlico/env.ts
|
|
1571
1576
|
var PIMLICO_API_KEY_ENVS = [
|
|
1572
1577
|
"PIMLICO_API_KEY",
|
|
1573
1578
|
"NEXT_PUBLIC_PIMLICO_API_KEY"
|
|
1574
1579
|
];
|
|
1580
|
+
|
|
1581
|
+
// src/aa/env.ts
|
|
1575
1582
|
function readEnv(candidates, options = {}) {
|
|
1576
1583
|
var _a;
|
|
1577
1584
|
const { publicOnly = false } = options;
|
|
@@ -1606,7 +1613,7 @@ function resolveDefaultProvider(options = {}) {
|
|
|
1606
1613
|
);
|
|
1607
1614
|
}
|
|
1608
1615
|
|
|
1609
|
-
// src/aa/resolve.ts
|
|
1616
|
+
// src/aa/alchemy/resolve.ts
|
|
1610
1617
|
function resolveAlchemyConfig(options) {
|
|
1611
1618
|
const {
|
|
1612
1619
|
calls,
|
|
@@ -1674,77 +1681,17 @@ function resolveAlchemyConfig(options) {
|
|
|
1674
1681
|
return null;
|
|
1675
1682
|
}
|
|
1676
1683
|
const resolvedChainConfig = modeOverride ? __spreadProps(__spreadValues({}, chainConfig), { defaultMode: modeOverride }) : chainConfig;
|
|
1677
|
-
const
|
|
1678
|
-
return {
|
|
1679
|
-
chainConfig: resolvedChainConfig,
|
|
1680
|
-
plan,
|
|
1684
|
+
const resolved = buildAAExecutionPlan(config, resolvedChainConfig);
|
|
1685
|
+
return __spreadProps(__spreadValues({}, resolved), {
|
|
1681
1686
|
apiKey,
|
|
1682
1687
|
chain,
|
|
1683
1688
|
rpcUrl: getPreferredRpcUrl(chain),
|
|
1684
1689
|
gasPolicyId,
|
|
1685
1690
|
mode: resolvedChainConfig.defaultMode
|
|
1686
|
-
};
|
|
1687
|
-
}
|
|
1688
|
-
function resolvePimlicoConfig(options) {
|
|
1689
|
-
const {
|
|
1690
|
-
calls,
|
|
1691
|
-
localPrivateKey,
|
|
1692
|
-
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1693
|
-
chainsById,
|
|
1694
|
-
rpcUrl,
|
|
1695
|
-
modeOverride,
|
|
1696
|
-
publicOnly = false,
|
|
1697
|
-
throwOnMissingConfig = false,
|
|
1698
|
-
apiKey: preResolvedApiKey
|
|
1699
|
-
} = options;
|
|
1700
|
-
if (!calls || localPrivateKey) {
|
|
1701
|
-
return null;
|
|
1702
|
-
}
|
|
1703
|
-
const config = __spreadProps(__spreadValues({}, accountAbstractionConfig), {
|
|
1704
|
-
provider: "pimlico"
|
|
1705
1691
|
});
|
|
1706
|
-
const chainConfig = getAAChainConfig(config, calls, chainsById);
|
|
1707
|
-
if (!chainConfig) {
|
|
1708
|
-
if (throwOnMissingConfig) {
|
|
1709
|
-
const chainIds = Array.from(new Set(calls.map((c) => c.chainId)));
|
|
1710
|
-
throw new Error(
|
|
1711
|
-
`AA is not configured for chain ${chainIds[0]}, or batching is disabled for that chain.`
|
|
1712
|
-
);
|
|
1713
|
-
}
|
|
1714
|
-
return null;
|
|
1715
|
-
}
|
|
1716
|
-
const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
|
|
1717
|
-
if (!apiKey) {
|
|
1718
|
-
if (throwOnMissingConfig) {
|
|
1719
|
-
throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
|
|
1720
|
-
}
|
|
1721
|
-
return null;
|
|
1722
|
-
}
|
|
1723
|
-
const chain = chainsById[chainConfig.chainId];
|
|
1724
|
-
if (!chain) {
|
|
1725
|
-
return null;
|
|
1726
|
-
}
|
|
1727
|
-
if (modeOverride && !chainConfig.supportedModes.includes(modeOverride)) {
|
|
1728
|
-
if (throwOnMissingConfig) {
|
|
1729
|
-
throw new Error(
|
|
1730
|
-
`AA mode "${modeOverride}" is not supported on chain ${chainConfig.chainId}.`
|
|
1731
|
-
);
|
|
1732
|
-
}
|
|
1733
|
-
return null;
|
|
1734
|
-
}
|
|
1735
|
-
const resolvedChainConfig = modeOverride ? __spreadProps(__spreadValues({}, chainConfig), { defaultMode: modeOverride }) : chainConfig;
|
|
1736
|
-
const plan = buildAAExecutionPlan(config, resolvedChainConfig);
|
|
1737
|
-
return {
|
|
1738
|
-
chainConfig: resolvedChainConfig,
|
|
1739
|
-
plan,
|
|
1740
|
-
apiKey,
|
|
1741
|
-
chain,
|
|
1742
|
-
rpcUrl,
|
|
1743
|
-
mode: resolvedChainConfig.defaultMode
|
|
1744
|
-
};
|
|
1745
1692
|
}
|
|
1746
1693
|
|
|
1747
|
-
// src/aa/alchemy.ts
|
|
1694
|
+
// src/aa/alchemy/provider.ts
|
|
1748
1695
|
function createAlchemyAAProvider({
|
|
1749
1696
|
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1750
1697
|
useAlchemyAA,
|
|
@@ -1753,7 +1700,7 @@ function createAlchemyAAProvider({
|
|
|
1753
1700
|
getPreferredRpcUrl
|
|
1754
1701
|
}) {
|
|
1755
1702
|
return function useAlchemyAAProvider(calls, localPrivateKey) {
|
|
1756
|
-
var _a
|
|
1703
|
+
var _a;
|
|
1757
1704
|
const resolved = resolveAlchemyConfig({
|
|
1758
1705
|
calls,
|
|
1759
1706
|
localPrivateKey,
|
|
@@ -1773,49 +1720,16 @@ function createAlchemyAAProvider({
|
|
|
1773
1720
|
} : void 0;
|
|
1774
1721
|
const query = useAlchemyAA(params);
|
|
1775
1722
|
return {
|
|
1776
|
-
|
|
1777
|
-
query,
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
error: (_b = query.error) != null ? _b : null
|
|
1723
|
+
resolved: resolved != null ? resolved : null,
|
|
1724
|
+
account: query.account,
|
|
1725
|
+
pending: Boolean(resolved && query.pending),
|
|
1726
|
+
error: (_a = query.error) != null ? _a : null
|
|
1781
1727
|
};
|
|
1782
1728
|
};
|
|
1783
1729
|
}
|
|
1784
1730
|
|
|
1785
|
-
// src/aa/
|
|
1786
|
-
|
|
1787
|
-
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1788
|
-
usePimlicoAA,
|
|
1789
|
-
chainsById,
|
|
1790
|
-
rpcUrl
|
|
1791
|
-
}) {
|
|
1792
|
-
return function usePimlicoAAProvider(calls, localPrivateKey) {
|
|
1793
|
-
var _a, _b;
|
|
1794
|
-
const resolved = resolvePimlicoConfig({
|
|
1795
|
-
calls,
|
|
1796
|
-
localPrivateKey,
|
|
1797
|
-
accountAbstractionConfig,
|
|
1798
|
-
chainsById,
|
|
1799
|
-
rpcUrl,
|
|
1800
|
-
publicOnly: true
|
|
1801
|
-
});
|
|
1802
|
-
const params = resolved ? {
|
|
1803
|
-
enabled: true,
|
|
1804
|
-
apiKey: resolved.apiKey,
|
|
1805
|
-
chain: resolved.chain,
|
|
1806
|
-
mode: resolved.mode,
|
|
1807
|
-
rpcUrl: resolved.rpcUrl
|
|
1808
|
-
} : void 0;
|
|
1809
|
-
const query = usePimlicoAA(params);
|
|
1810
|
-
return {
|
|
1811
|
-
plan: (_a = resolved == null ? void 0 : resolved.plan) != null ? _a : null,
|
|
1812
|
-
query,
|
|
1813
|
-
AA: query.AA,
|
|
1814
|
-
isPending: Boolean(resolved && query.isPending),
|
|
1815
|
-
error: (_b = query.error) != null ? _b : null
|
|
1816
|
-
};
|
|
1817
|
-
};
|
|
1818
|
-
}
|
|
1731
|
+
// src/aa/alchemy/create.ts
|
|
1732
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
1819
1733
|
|
|
1820
1734
|
// src/aa/adapt.ts
|
|
1821
1735
|
function adaptSmartAccount(account) {
|
|
@@ -1841,33 +1755,8 @@ function isAlchemySponsorshipLimitError(error) {
|
|
|
1841
1755
|
return normalized.includes("gas sponsorship limit") || normalized.includes("put your team over your gas sponsorship limit") || normalized.includes("buy gas credits in your gas manager dashboard");
|
|
1842
1756
|
}
|
|
1843
1757
|
|
|
1844
|
-
// src/aa/
|
|
1845
|
-
import { createAlchemySmartAccount } from "@getpara/aa-alchemy";
|
|
1846
|
-
import { createPimlicoSmartAccount } from "@getpara/aa-pimlico";
|
|
1758
|
+
// src/aa/owner.ts
|
|
1847
1759
|
import { privateKeyToAccount } from "viem/accounts";
|
|
1848
|
-
var ALCHEMY_7702_DELEGATION_ADDRESS = "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
1849
|
-
async function createAAProviderState(options) {
|
|
1850
|
-
if (options.provider === "alchemy") {
|
|
1851
|
-
return createAlchemyAAState({
|
|
1852
|
-
chain: options.chain,
|
|
1853
|
-
owner: options.owner,
|
|
1854
|
-
rpcUrl: options.rpcUrl,
|
|
1855
|
-
callList: options.callList,
|
|
1856
|
-
mode: options.mode,
|
|
1857
|
-
apiKey: options.apiKey,
|
|
1858
|
-
gasPolicyId: options.gasPolicyId,
|
|
1859
|
-
sponsored: options.sponsored
|
|
1860
|
-
});
|
|
1861
|
-
}
|
|
1862
|
-
return createPimlicoAAState({
|
|
1863
|
-
chain: options.chain,
|
|
1864
|
-
owner: options.owner,
|
|
1865
|
-
rpcUrl: options.rpcUrl,
|
|
1866
|
-
callList: options.callList,
|
|
1867
|
-
mode: options.mode,
|
|
1868
|
-
apiKey: options.apiKey
|
|
1869
|
-
});
|
|
1870
|
-
}
|
|
1871
1760
|
function getDirectOwnerParams(owner) {
|
|
1872
1761
|
return {
|
|
1873
1762
|
kind: "ready",
|
|
@@ -1913,24 +1802,27 @@ function getOwnerParams(owner) {
|
|
|
1913
1802
|
return getSessionOwnerParams(owner);
|
|
1914
1803
|
}
|
|
1915
1804
|
}
|
|
1916
|
-
function getMissingOwnerState(
|
|
1805
|
+
function getMissingOwnerState(resolved, provider) {
|
|
1917
1806
|
return {
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1807
|
+
resolved,
|
|
1808
|
+
account: null,
|
|
1809
|
+
pending: false,
|
|
1921
1810
|
error: new Error(
|
|
1922
1811
|
`${provider} AA account creation requires a direct owner or a supported session owner.`
|
|
1923
1812
|
)
|
|
1924
1813
|
};
|
|
1925
1814
|
}
|
|
1926
|
-
function getUnsupportedAdapterState(
|
|
1815
|
+
function getUnsupportedAdapterState(resolved, adapter) {
|
|
1927
1816
|
return {
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1817
|
+
resolved,
|
|
1818
|
+
account: null,
|
|
1819
|
+
pending: false,
|
|
1931
1820
|
error: new Error(`Session adapter "${adapter}" is not implemented.`)
|
|
1932
1821
|
};
|
|
1933
1822
|
}
|
|
1823
|
+
|
|
1824
|
+
// src/aa/alchemy/create.ts
|
|
1825
|
+
var ALCHEMY_7702_DELEGATION_ADDRESS = "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
1934
1826
|
async function createAlchemyAAState(options) {
|
|
1935
1827
|
var _a, _b;
|
|
1936
1828
|
const {
|
|
@@ -1955,70 +1847,71 @@ async function createAlchemyAAState(options) {
|
|
|
1955
1847
|
}
|
|
1956
1848
|
const apiKey = (_a = options.apiKey) != null ? _a : resolved.apiKey;
|
|
1957
1849
|
const gasPolicyId = sponsored ? (_b = options.gasPolicyId) != null ? _b : readEnv(ALCHEMY_GAS_POLICY_ENVS) : void 0;
|
|
1958
|
-
const
|
|
1959
|
-
sponsorship: gasPolicyId ? resolved.
|
|
1850
|
+
const execution = __spreadProps(__spreadValues({}, resolved), {
|
|
1851
|
+
sponsorship: gasPolicyId ? resolved.sponsorship : "disabled",
|
|
1960
1852
|
fallbackToEoa: false
|
|
1961
1853
|
});
|
|
1962
1854
|
const ownerParams = getOwnerParams(owner);
|
|
1963
1855
|
if (ownerParams.kind === "missing") {
|
|
1964
|
-
return getMissingOwnerState(
|
|
1856
|
+
return getMissingOwnerState(execution, "alchemy");
|
|
1965
1857
|
}
|
|
1966
1858
|
if (ownerParams.kind === "unsupported_adapter") {
|
|
1967
|
-
return getUnsupportedAdapterState(
|
|
1859
|
+
return getUnsupportedAdapterState(execution, ownerParams.adapter);
|
|
1968
1860
|
}
|
|
1969
1861
|
if (owner.kind === "direct") {
|
|
1970
1862
|
try {
|
|
1971
1863
|
return await createAlchemyWalletApisState({
|
|
1972
|
-
|
|
1864
|
+
resolved: execution,
|
|
1973
1865
|
chain,
|
|
1974
1866
|
privateKey: owner.privateKey,
|
|
1975
1867
|
apiKey,
|
|
1976
1868
|
gasPolicyId,
|
|
1977
|
-
mode:
|
|
1869
|
+
mode: execution.mode
|
|
1978
1870
|
});
|
|
1979
1871
|
} catch (error) {
|
|
1980
1872
|
return {
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1873
|
+
resolved: execution,
|
|
1874
|
+
account: null,
|
|
1875
|
+
pending: false,
|
|
1984
1876
|
error: error instanceof Error ? error : new Error(String(error))
|
|
1985
1877
|
};
|
|
1986
1878
|
}
|
|
1987
1879
|
}
|
|
1988
1880
|
try {
|
|
1881
|
+
const { createAlchemySmartAccount } = await import("@getpara/aa-alchemy");
|
|
1989
1882
|
const smartAccount = await createAlchemySmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
|
|
1990
1883
|
apiKey,
|
|
1991
1884
|
gasPolicyId,
|
|
1992
1885
|
chain,
|
|
1993
1886
|
rpcUrl,
|
|
1994
|
-
mode:
|
|
1887
|
+
mode: execution.mode
|
|
1995
1888
|
}));
|
|
1996
1889
|
if (!smartAccount) {
|
|
1997
1890
|
return {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
1891
|
+
resolved: execution,
|
|
1892
|
+
account: null,
|
|
1893
|
+
pending: false,
|
|
2001
1894
|
error: new Error("Alchemy AA account could not be initialized.")
|
|
2002
1895
|
};
|
|
2003
1896
|
}
|
|
2004
1897
|
return {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
1898
|
+
resolved: execution,
|
|
1899
|
+
account: adaptSmartAccount(smartAccount),
|
|
1900
|
+
pending: false,
|
|
2008
1901
|
error: null
|
|
2009
1902
|
};
|
|
2010
1903
|
} catch (error) {
|
|
2011
1904
|
return {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
1905
|
+
resolved: execution,
|
|
1906
|
+
account: null,
|
|
1907
|
+
pending: false,
|
|
2015
1908
|
error: error instanceof Error ? error : new Error(String(error))
|
|
2016
1909
|
};
|
|
2017
1910
|
}
|
|
2018
1911
|
}
|
|
2019
1912
|
async function createAlchemyWalletApisState(params) {
|
|
2020
1913
|
const { createSmartWalletClient, alchemyWalletTransport } = await import("@alchemy/wallet-apis");
|
|
2021
|
-
const signer =
|
|
1914
|
+
const signer = privateKeyToAccount2(params.privateKey);
|
|
2022
1915
|
const walletClient = createSmartWalletClient(__spreadValues({
|
|
2023
1916
|
transport: alchemyWalletTransport({ apiKey: params.apiKey }),
|
|
2024
1917
|
chain: params.chain,
|
|
@@ -2026,8 +1919,8 @@ async function createAlchemyWalletApisState(params) {
|
|
|
2026
1919
|
}, params.gasPolicyId ? { paymaster: { policyId: params.gasPolicyId } } : {}));
|
|
2027
1920
|
let accountAddress = signer.address;
|
|
2028
1921
|
if (params.mode === "4337") {
|
|
2029
|
-
const
|
|
2030
|
-
accountAddress =
|
|
1922
|
+
const account2 = await walletClient.requestAccount();
|
|
1923
|
+
accountAddress = account2.address;
|
|
2031
1924
|
}
|
|
2032
1925
|
const sendCalls = async (calls) => {
|
|
2033
1926
|
var _a, _b;
|
|
@@ -2041,7 +1934,7 @@ async function createAlchemyWalletApisState(params) {
|
|
|
2041
1934
|
}
|
|
2042
1935
|
return { transactionHash };
|
|
2043
1936
|
};
|
|
2044
|
-
const
|
|
1937
|
+
const account = {
|
|
2045
1938
|
provider: "alchemy",
|
|
2046
1939
|
mode: params.mode,
|
|
2047
1940
|
AAAddress: accountAddress,
|
|
@@ -2050,12 +1943,106 @@ async function createAlchemyWalletApisState(params) {
|
|
|
2050
1943
|
sendBatchTransaction: async (calls) => sendCalls(calls)
|
|
2051
1944
|
};
|
|
2052
1945
|
return {
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
1946
|
+
resolved: params.resolved,
|
|
1947
|
+
account,
|
|
1948
|
+
pending: false,
|
|
2056
1949
|
error: null
|
|
2057
1950
|
};
|
|
2058
1951
|
}
|
|
1952
|
+
|
|
1953
|
+
// src/aa/pimlico/resolve.ts
|
|
1954
|
+
function resolvePimlicoConfig(options) {
|
|
1955
|
+
const {
|
|
1956
|
+
calls,
|
|
1957
|
+
localPrivateKey,
|
|
1958
|
+
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
1959
|
+
chainsById,
|
|
1960
|
+
rpcUrl,
|
|
1961
|
+
modeOverride,
|
|
1962
|
+
publicOnly = false,
|
|
1963
|
+
throwOnMissingConfig = false,
|
|
1964
|
+
apiKey: preResolvedApiKey
|
|
1965
|
+
} = options;
|
|
1966
|
+
if (!calls || localPrivateKey) {
|
|
1967
|
+
return null;
|
|
1968
|
+
}
|
|
1969
|
+
const config = __spreadProps(__spreadValues({}, accountAbstractionConfig), {
|
|
1970
|
+
provider: "pimlico"
|
|
1971
|
+
});
|
|
1972
|
+
const chainConfig = getAAChainConfig(config, calls, chainsById);
|
|
1973
|
+
if (!chainConfig) {
|
|
1974
|
+
if (throwOnMissingConfig) {
|
|
1975
|
+
const chainIds = Array.from(new Set(calls.map((c) => c.chainId)));
|
|
1976
|
+
throw new Error(
|
|
1977
|
+
`AA is not configured for chain ${chainIds[0]}, or batching is disabled for that chain.`
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
return null;
|
|
1981
|
+
}
|
|
1982
|
+
const apiKey = preResolvedApiKey != null ? preResolvedApiKey : readEnv(PIMLICO_API_KEY_ENVS, { publicOnly });
|
|
1983
|
+
if (!apiKey) {
|
|
1984
|
+
if (throwOnMissingConfig) {
|
|
1985
|
+
throw new Error("Pimlico AA requires PIMLICO_API_KEY.");
|
|
1986
|
+
}
|
|
1987
|
+
return null;
|
|
1988
|
+
}
|
|
1989
|
+
const chain = chainsById[chainConfig.chainId];
|
|
1990
|
+
if (!chain) {
|
|
1991
|
+
return null;
|
|
1992
|
+
}
|
|
1993
|
+
if (modeOverride && !chainConfig.supportedModes.includes(modeOverride)) {
|
|
1994
|
+
if (throwOnMissingConfig) {
|
|
1995
|
+
throw new Error(
|
|
1996
|
+
`AA mode "${modeOverride}" is not supported on chain ${chainConfig.chainId}.`
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
return null;
|
|
2000
|
+
}
|
|
2001
|
+
const resolvedChainConfig = modeOverride ? __spreadProps(__spreadValues({}, chainConfig), { defaultMode: modeOverride }) : chainConfig;
|
|
2002
|
+
const resolved = buildAAExecutionPlan(config, resolvedChainConfig);
|
|
2003
|
+
return __spreadProps(__spreadValues({}, resolved), {
|
|
2004
|
+
apiKey,
|
|
2005
|
+
chain,
|
|
2006
|
+
rpcUrl,
|
|
2007
|
+
mode: resolvedChainConfig.defaultMode
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
// src/aa/pimlico/provider.ts
|
|
2012
|
+
function createPimlicoAAProvider({
|
|
2013
|
+
accountAbstractionConfig = DEFAULT_AA_CONFIG,
|
|
2014
|
+
usePimlicoAA,
|
|
2015
|
+
chainsById,
|
|
2016
|
+
rpcUrl
|
|
2017
|
+
}) {
|
|
2018
|
+
return function usePimlicoAAProvider(calls, localPrivateKey) {
|
|
2019
|
+
var _a;
|
|
2020
|
+
const resolved = resolvePimlicoConfig({
|
|
2021
|
+
calls,
|
|
2022
|
+
localPrivateKey,
|
|
2023
|
+
accountAbstractionConfig,
|
|
2024
|
+
chainsById,
|
|
2025
|
+
rpcUrl,
|
|
2026
|
+
publicOnly: true
|
|
2027
|
+
});
|
|
2028
|
+
const params = resolved ? {
|
|
2029
|
+
enabled: true,
|
|
2030
|
+
apiKey: resolved.apiKey,
|
|
2031
|
+
chain: resolved.chain,
|
|
2032
|
+
mode: resolved.mode,
|
|
2033
|
+
rpcUrl: resolved.rpcUrl
|
|
2034
|
+
} : void 0;
|
|
2035
|
+
const query = usePimlicoAA(params);
|
|
2036
|
+
return {
|
|
2037
|
+
resolved: resolved != null ? resolved : null,
|
|
2038
|
+
account: query.account,
|
|
2039
|
+
pending: Boolean(resolved && query.pending),
|
|
2040
|
+
error: (_a = query.error) != null ? _a : null
|
|
2041
|
+
};
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
// src/aa/pimlico/create.ts
|
|
2059
2046
|
async function createPimlicoAAState(options) {
|
|
2060
2047
|
var _a;
|
|
2061
2048
|
const {
|
|
@@ -2077,46 +2064,71 @@ async function createPimlicoAAState(options) {
|
|
|
2077
2064
|
throw new Error("Pimlico AA config resolution failed.");
|
|
2078
2065
|
}
|
|
2079
2066
|
const apiKey = (_a = options.apiKey) != null ? _a : resolved.apiKey;
|
|
2080
|
-
const
|
|
2067
|
+
const execution = __spreadProps(__spreadValues({}, resolved), {
|
|
2081
2068
|
fallbackToEoa: false
|
|
2082
2069
|
});
|
|
2083
2070
|
const ownerParams = getOwnerParams(owner);
|
|
2084
2071
|
if (ownerParams.kind === "missing") {
|
|
2085
|
-
return getMissingOwnerState(
|
|
2072
|
+
return getMissingOwnerState(execution, "pimlico");
|
|
2086
2073
|
}
|
|
2087
2074
|
if (ownerParams.kind === "unsupported_adapter") {
|
|
2088
|
-
return getUnsupportedAdapterState(
|
|
2075
|
+
return getUnsupportedAdapterState(execution, ownerParams.adapter);
|
|
2089
2076
|
}
|
|
2090
2077
|
try {
|
|
2078
|
+
const { createPimlicoSmartAccount } = await import("@getpara/aa-pimlico");
|
|
2091
2079
|
const smartAccount = await createPimlicoSmartAccount(__spreadProps(__spreadValues({}, ownerParams.ownerParams), {
|
|
2092
2080
|
apiKey,
|
|
2093
2081
|
chain,
|
|
2094
2082
|
rpcUrl,
|
|
2095
|
-
mode:
|
|
2083
|
+
mode: execution.mode
|
|
2096
2084
|
}));
|
|
2097
2085
|
if (!smartAccount) {
|
|
2098
2086
|
return {
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2087
|
+
resolved: execution,
|
|
2088
|
+
account: null,
|
|
2089
|
+
pending: false,
|
|
2102
2090
|
error: new Error("Pimlico AA account could not be initialized.")
|
|
2103
2091
|
};
|
|
2104
2092
|
}
|
|
2105
2093
|
return {
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2094
|
+
resolved: execution,
|
|
2095
|
+
account: adaptSmartAccount(smartAccount),
|
|
2096
|
+
pending: false,
|
|
2109
2097
|
error: null
|
|
2110
2098
|
};
|
|
2111
2099
|
} catch (error) {
|
|
2112
2100
|
return {
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2101
|
+
resolved: execution,
|
|
2102
|
+
account: null,
|
|
2103
|
+
pending: false,
|
|
2116
2104
|
error: error instanceof Error ? error : new Error(String(error))
|
|
2117
2105
|
};
|
|
2118
2106
|
}
|
|
2119
2107
|
}
|
|
2108
|
+
|
|
2109
|
+
// src/aa/create.ts
|
|
2110
|
+
async function createAAProviderState(options) {
|
|
2111
|
+
if (options.provider === "alchemy") {
|
|
2112
|
+
return createAlchemyAAState({
|
|
2113
|
+
chain: options.chain,
|
|
2114
|
+
owner: options.owner,
|
|
2115
|
+
rpcUrl: options.rpcUrl,
|
|
2116
|
+
callList: options.callList,
|
|
2117
|
+
mode: options.mode,
|
|
2118
|
+
apiKey: options.apiKey,
|
|
2119
|
+
gasPolicyId: options.gasPolicyId,
|
|
2120
|
+
sponsored: options.sponsored
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
return createPimlicoAAState({
|
|
2124
|
+
chain: options.chain,
|
|
2125
|
+
owner: options.owner,
|
|
2126
|
+
rpcUrl: options.rpcUrl,
|
|
2127
|
+
callList: options.callList,
|
|
2128
|
+
mode: options.mode,
|
|
2129
|
+
apiKey: options.apiKey
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2120
2132
|
export {
|
|
2121
2133
|
AomiClient,
|
|
2122
2134
|
CLIENT_TYPE_TS_CLI,
|