@vapi-network/core 0.13.0 → 0.14.0
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/README.md +1 -1
- package/dist/index.js +251 -6
- package/dist/index.js.map +3 -3
- package/dist/router-client.js +1 -1
- package/dist/router-client.js.map +1 -1
- package/dist/support-report.d.ts +1 -1
- package/dist/sweep.d.ts +11 -0
- package/dist/sweep.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -259,7 +259,7 @@ basis points, or the registry label and computed percentage for legacy fees.
|
|
|
259
259
|
| `validatePrivateKey` | function (value: string): Hex | 0.5.0 or earlier |
|
|
260
260
|
| `validateRecoveryPhrase` | function (phrase: string): string | 0.5.0 or earlier |
|
|
261
261
|
| `VAPI_BUILDER_CODE` | constant VAPI_BUILDER_CODE: "vapi" | 0.5.0 or earlier |
|
|
262
|
-
| `VAPI_CLIENT_VERSION` | constant VAPI_CLIENT_VERSION: "0.
|
|
262
|
+
| `VAPI_CLIENT_VERSION` | constant VAPI_CLIENT_VERSION: "0.14.0" | 0.4.0 |
|
|
263
263
|
| `WALLET_NAME_PATTERN` | constant WALLET_NAME_PATTERN: RegExp | 0.5.0 or earlier |
|
|
264
264
|
| `walletEntrySchema` | constant walletEntrySchema: ZodObject<{ createdAt: ZodISODateTime; label: ZodOptional<ZodString>; spendCaps: ZodObject<{ perCallAtomic: ZodString; perDayAtomic: ZodString; }, $strip>; routerRefill: ZodOptional<...>; link: ZodOptional<...>; }, $strip> | 0.5.0 or earlier |
|
|
265
265
|
| `walletNameSchema` | constant walletNameSchema: ZodString | 0.5.0 or earlier |
|
package/dist/index.js
CHANGED
|
@@ -3511,6 +3511,9 @@ function carry(digits) {
|
|
|
3511
3511
|
}
|
|
3512
3512
|
return `1${out.join("")}`;
|
|
3513
3513
|
}
|
|
3514
|
+
function fromGwei(gwei, unit = "wei") {
|
|
3515
|
+
return from(gwei, exponents.gwei - exponents[unit]);
|
|
3516
|
+
}
|
|
3514
3517
|
var exponents, InvalidDecimalNumberError, InvalidDecimalsError;
|
|
3515
3518
|
var init_Value = __esm({
|
|
3516
3519
|
"../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/utils/unit/Value.js"() {
|
|
@@ -35471,6 +35474,12 @@ function formatUnits(value, decimals) {
|
|
|
35471
35474
|
return format(value, decimals);
|
|
35472
35475
|
}
|
|
35473
35476
|
|
|
35477
|
+
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/utils/unit/parseGwei.js
|
|
35478
|
+
init_Value();
|
|
35479
|
+
function parseGwei(ether, unit = "wei") {
|
|
35480
|
+
return fromGwei(ether, unit);
|
|
35481
|
+
}
|
|
35482
|
+
|
|
35474
35483
|
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/utils/unit/parseUnits.js
|
|
35475
35484
|
init_Value();
|
|
35476
35485
|
function parseUnits(value, decimals) {
|
|
@@ -35614,7 +35623,7 @@ init_createBatchScheduler();
|
|
|
35614
35623
|
init_stringify();
|
|
35615
35624
|
async function multicall(client, parameters) {
|
|
35616
35625
|
const { account, authorizationList, allowFailure = true, blockHash, blockNumber, blockOverrides, blockTag, requireCanonical, stateOverride } = parameters;
|
|
35617
|
-
const
|
|
35626
|
+
const contracts2 = parameters.contracts;
|
|
35618
35627
|
const batch = typeof client.batch?.multicall === "object" ? client.batch.multicall : {};
|
|
35619
35628
|
const batchSize = parameters.batchSize ?? batch.batchSize ?? 1024;
|
|
35620
35629
|
const deployless = parameters.deployless ?? batch.deployless ?? false;
|
|
@@ -35635,8 +35644,8 @@ async function multicall(client, parameters) {
|
|
|
35635
35644
|
const chunkedCalls = [[]];
|
|
35636
35645
|
let currentChunk = 0;
|
|
35637
35646
|
let currentChunkSize = 0;
|
|
35638
|
-
for (let i = 0; i <
|
|
35639
|
-
const { abi: abi2, address: address2, args, functionName } =
|
|
35647
|
+
for (let i = 0; i < contracts2.length; i++) {
|
|
35648
|
+
const { abi: abi2, address: address2, args, functionName } = contracts2[i];
|
|
35640
35649
|
try {
|
|
35641
35650
|
const callData = encodeFunctionData({ abi: abi2, args, functionName });
|
|
35642
35651
|
currentChunkSize += (callData.length - 2) / 2;
|
|
@@ -35730,7 +35739,7 @@ async function multicall(client, parameters) {
|
|
|
35730
35739
|
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
35731
35740
|
const { returnData, success: success2 } = aggregate3Result[j];
|
|
35732
35741
|
const { callData } = batches[i][j];
|
|
35733
|
-
const { abi: abi2, address: address2, functionName, args } =
|
|
35742
|
+
const { abi: abi2, address: address2, functionName, args } = contracts2[results.length];
|
|
35734
35743
|
try {
|
|
35735
35744
|
if (callData === "0x")
|
|
35736
35745
|
throw new AbiDecodingZeroDataError();
|
|
@@ -35757,7 +35766,7 @@ async function multicall(client, parameters) {
|
|
|
35757
35766
|
}
|
|
35758
35767
|
}
|
|
35759
35768
|
}
|
|
35760
|
-
if (results.length !==
|
|
35769
|
+
if (results.length !== contracts2.length)
|
|
35761
35770
|
throw new BaseError2("multicall results mismatch");
|
|
35762
35771
|
return results;
|
|
35763
35772
|
}
|
|
@@ -38705,6 +38714,7 @@ init_isAddress();
|
|
|
38705
38714
|
init_toBytes();
|
|
38706
38715
|
init_toHex();
|
|
38707
38716
|
init_keccak256();
|
|
38717
|
+
init_formatEther();
|
|
38708
38718
|
|
|
38709
38719
|
// src/x402-networks.ts
|
|
38710
38720
|
var BASE_MAINNET_CAIP2 = "eip155:8453";
|
|
@@ -45757,6 +45767,143 @@ function rawServiceId(raw, serviceIndex) {
|
|
|
45757
45767
|
return typeof id === "string" ? id : void 0;
|
|
45758
45768
|
}
|
|
45759
45769
|
|
|
45770
|
+
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/op-stack/contracts.js
|
|
45771
|
+
var contracts = {
|
|
45772
|
+
gasPriceOracle: { address: "0x420000000000000000000000000000000000000F" },
|
|
45773
|
+
l1Block: { address: "0x4200000000000000000000000000000000000015" },
|
|
45774
|
+
l2CrossDomainMessenger: {
|
|
45775
|
+
address: "0x4200000000000000000000000000000000000007"
|
|
45776
|
+
},
|
|
45777
|
+
l2Erc721Bridge: { address: "0x4200000000000000000000000000000000000014" },
|
|
45778
|
+
l2StandardBridge: { address: "0x4200000000000000000000000000000000000010" },
|
|
45779
|
+
l2ToL1MessagePasser: {
|
|
45780
|
+
address: "0x4200000000000000000000000000000000000016"
|
|
45781
|
+
}
|
|
45782
|
+
};
|
|
45783
|
+
|
|
45784
|
+
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/op-stack/abis.js
|
|
45785
|
+
var gasPriceOracleAbi = [
|
|
45786
|
+
{ inputs: [], stateMutability: "nonpayable", type: "constructor" },
|
|
45787
|
+
{
|
|
45788
|
+
inputs: [],
|
|
45789
|
+
name: "DECIMALS",
|
|
45790
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45791
|
+
stateMutability: "view",
|
|
45792
|
+
type: "function"
|
|
45793
|
+
},
|
|
45794
|
+
{
|
|
45795
|
+
inputs: [],
|
|
45796
|
+
name: "baseFee",
|
|
45797
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45798
|
+
stateMutability: "view",
|
|
45799
|
+
type: "function"
|
|
45800
|
+
},
|
|
45801
|
+
{
|
|
45802
|
+
inputs: [],
|
|
45803
|
+
name: "decimals",
|
|
45804
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45805
|
+
stateMutability: "pure",
|
|
45806
|
+
type: "function"
|
|
45807
|
+
},
|
|
45808
|
+
{
|
|
45809
|
+
inputs: [],
|
|
45810
|
+
name: "gasPrice",
|
|
45811
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45812
|
+
stateMutability: "view",
|
|
45813
|
+
type: "function"
|
|
45814
|
+
},
|
|
45815
|
+
{
|
|
45816
|
+
inputs: [{ internalType: "bytes", name: "_data", type: "bytes" }],
|
|
45817
|
+
name: "getL1Fee",
|
|
45818
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45819
|
+
stateMutability: "view",
|
|
45820
|
+
type: "function"
|
|
45821
|
+
},
|
|
45822
|
+
{
|
|
45823
|
+
inputs: [{ internalType: "bytes", name: "_data", type: "bytes" }],
|
|
45824
|
+
name: "getL1GasUsed",
|
|
45825
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45826
|
+
stateMutability: "view",
|
|
45827
|
+
type: "function"
|
|
45828
|
+
},
|
|
45829
|
+
{
|
|
45830
|
+
inputs: [{ internalType: "uint256", name: "_gasUsed", type: "uint256" }],
|
|
45831
|
+
name: "getOperatorFee",
|
|
45832
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45833
|
+
stateMutability: "view",
|
|
45834
|
+
type: "function"
|
|
45835
|
+
},
|
|
45836
|
+
{
|
|
45837
|
+
inputs: [],
|
|
45838
|
+
name: "isJovian",
|
|
45839
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
45840
|
+
stateMutability: "view",
|
|
45841
|
+
type: "function"
|
|
45842
|
+
},
|
|
45843
|
+
{
|
|
45844
|
+
inputs: [],
|
|
45845
|
+
name: "l1BaseFee",
|
|
45846
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45847
|
+
stateMutability: "view",
|
|
45848
|
+
type: "function"
|
|
45849
|
+
},
|
|
45850
|
+
{
|
|
45851
|
+
inputs: [],
|
|
45852
|
+
name: "overhead",
|
|
45853
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45854
|
+
stateMutability: "view",
|
|
45855
|
+
type: "function"
|
|
45856
|
+
},
|
|
45857
|
+
{
|
|
45858
|
+
inputs: [],
|
|
45859
|
+
name: "scalar",
|
|
45860
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
45861
|
+
stateMutability: "view",
|
|
45862
|
+
type: "function"
|
|
45863
|
+
},
|
|
45864
|
+
{
|
|
45865
|
+
inputs: [],
|
|
45866
|
+
name: "version",
|
|
45867
|
+
outputs: [{ internalType: "string", name: "", type: "string" }],
|
|
45868
|
+
stateMutability: "view",
|
|
45869
|
+
type: "function"
|
|
45870
|
+
}
|
|
45871
|
+
];
|
|
45872
|
+
|
|
45873
|
+
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/op-stack/actions/estimateL1Fee.js
|
|
45874
|
+
init_getChainContractAddress();
|
|
45875
|
+
async function estimateL1Fee(client, args) {
|
|
45876
|
+
const { chain: chain2 = client.chain, gasPriceOracleAddress: gasPriceOracleAddress_ } = args;
|
|
45877
|
+
const gasPriceOracleAddress = (() => {
|
|
45878
|
+
if (gasPriceOracleAddress_)
|
|
45879
|
+
return gasPriceOracleAddress_;
|
|
45880
|
+
if (chain2)
|
|
45881
|
+
return getChainContractAddress({
|
|
45882
|
+
chain: chain2,
|
|
45883
|
+
contract: "gasPriceOracle"
|
|
45884
|
+
});
|
|
45885
|
+
return contracts.gasPriceOracle.address;
|
|
45886
|
+
})();
|
|
45887
|
+
const transaction = serializeTransaction({
|
|
45888
|
+
...args,
|
|
45889
|
+
chainId: chain2?.id ?? 1,
|
|
45890
|
+
type: "eip1559",
|
|
45891
|
+
// Set upper-limit-ish stub values. Shouldn't affect the estimate too much as we are
|
|
45892
|
+
// tweaking dust bytes here (as opposed to long `data` bytes).
|
|
45893
|
+
// See: https://github.com/ethereum-optimism/optimism/blob/54d02df55523c9e1b4b38ed082c12a42087323a0/packages/contracts-bedrock/src/L2/GasPriceOracle.sol#L242-L248.
|
|
45894
|
+
gas: args.data ? 300000n : 21000n,
|
|
45895
|
+
maxFeePerGas: parseGwei("5"),
|
|
45896
|
+
maxPriorityFeePerGas: parseGwei("1"),
|
|
45897
|
+
nonce: 1
|
|
45898
|
+
});
|
|
45899
|
+
return readContract(client, {
|
|
45900
|
+
abi: gasPriceOracleAbi,
|
|
45901
|
+
address: gasPriceOracleAddress,
|
|
45902
|
+
functionName: "getL1Fee",
|
|
45903
|
+
args: [transaction]
|
|
45904
|
+
});
|
|
45905
|
+
}
|
|
45906
|
+
|
|
45760
45907
|
// src/sweep.ts
|
|
45761
45908
|
var ERC20_ABI = [
|
|
45762
45909
|
{
|
|
@@ -45915,6 +46062,100 @@ async function sweepBack(args) {
|
|
|
45915
46062
|
transaction
|
|
45916
46063
|
};
|
|
45917
46064
|
}
|
|
46065
|
+
var NATIVE_ETH_L1_FEE_FALLBACK_WEI = 10000000000000n;
|
|
46066
|
+
var NATIVE_ETH_FEE_MARGIN_PERCENT = 20n;
|
|
46067
|
+
function supportsNativeEthSweep(network) {
|
|
46068
|
+
return network === BASE_MAINNET_CAIP2 || network === "eip155:84532";
|
|
46069
|
+
}
|
|
46070
|
+
async function sweepNativeEth(args) {
|
|
46071
|
+
const configured = configuredNetworkFor(args.config.networks, args.network);
|
|
46072
|
+
if (!configured) throw new Error(`Network ${args.network} is not configured.`);
|
|
46073
|
+
if (isSolanaNetwork(args.network)) {
|
|
46074
|
+
throw new Error("Solana has no native ETH; use vapi sweep --asset usdc.");
|
|
46075
|
+
}
|
|
46076
|
+
if (usesUsdcGas(args.network)) {
|
|
46077
|
+
throw new Error("Arc has no native ETH; use vapi sweep --asset usdc.");
|
|
46078
|
+
}
|
|
46079
|
+
if (!supportsNativeEthSweep(args.network)) {
|
|
46080
|
+
throw new Error("Native ETH sweeps are supported only on Base mainnet and Base Sepolia.");
|
|
46081
|
+
}
|
|
46082
|
+
const rpcUrl = requireRpcUrl(args.network, configured);
|
|
46083
|
+
const chain2 = createChain(args.network, rpcUrl);
|
|
46084
|
+
const options = {
|
|
46085
|
+
allowPrivateNetwork: args.config.allowPrivateNetwork,
|
|
46086
|
+
...args.fetchImpl ? { fetch: args.fetchImpl } : {},
|
|
46087
|
+
...args.lookup ? { lookup: args.lookup } : {}
|
|
46088
|
+
};
|
|
46089
|
+
const publicClient = createNetworkPublicClient(args.network, configured, options);
|
|
46090
|
+
const to = getAddress(args.destination);
|
|
46091
|
+
const balance = await publicClient.getBalance({ address: args.account.address });
|
|
46092
|
+
const estimateTransferGas = async (value) => {
|
|
46093
|
+
try {
|
|
46094
|
+
return await publicClient.estimateGas({ account: args.account.address, to, value });
|
|
46095
|
+
} catch (error61) {
|
|
46096
|
+
const code = await publicClient.getCode({ address: to });
|
|
46097
|
+
if (code && code !== "0x") throw error61;
|
|
46098
|
+
return 21000n;
|
|
46099
|
+
}
|
|
46100
|
+
};
|
|
46101
|
+
let gas = await estimateTransferGas(1n);
|
|
46102
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = await publicClient.estimateFeesPerGas();
|
|
46103
|
+
let l1Fee;
|
|
46104
|
+
try {
|
|
46105
|
+
l1Fee = await estimateL1Fee(publicClient, {
|
|
46106
|
+
chain: chain2,
|
|
46107
|
+
account: args.account.address,
|
|
46108
|
+
to,
|
|
46109
|
+
value: balance,
|
|
46110
|
+
gas,
|
|
46111
|
+
maxFeePerGas,
|
|
46112
|
+
maxPriorityFeePerGas,
|
|
46113
|
+
gasPriceOracleAddress: "0x420000000000000000000000000000000000000F"
|
|
46114
|
+
});
|
|
46115
|
+
} catch {
|
|
46116
|
+
l1Fee = NATIVE_ETH_L1_FEE_FALLBACK_WEI;
|
|
46117
|
+
}
|
|
46118
|
+
let amount = 0n;
|
|
46119
|
+
let validated = false;
|
|
46120
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
46121
|
+
const fee = (maxFeePerGas * gas + l1Fee) * (100n + NATIVE_ETH_FEE_MARGIN_PERCENT) / 100n;
|
|
46122
|
+
amount = balance - fee;
|
|
46123
|
+
if (amount <= 0n) {
|
|
46124
|
+
const name = getNetworkDefinition(args.network).name;
|
|
46125
|
+
throw new Error(
|
|
46126
|
+
`The ETH balance on ${name} (${formatEther2(balance)} ETH) is too small to cover the ${name} network fee.`
|
|
46127
|
+
);
|
|
46128
|
+
}
|
|
46129
|
+
const requiredGas = await estimateTransferGas(amount);
|
|
46130
|
+
if (requiredGas <= gas) {
|
|
46131
|
+
validated = true;
|
|
46132
|
+
break;
|
|
46133
|
+
}
|
|
46134
|
+
gas = requiredGas;
|
|
46135
|
+
}
|
|
46136
|
+
if (!validated) {
|
|
46137
|
+
throw new Error(
|
|
46138
|
+
"Could not safely estimate gas for the ETH withdrawal; no transaction was sent."
|
|
46139
|
+
);
|
|
46140
|
+
}
|
|
46141
|
+
const walletClient = createWalletClient({
|
|
46142
|
+
account: args.account,
|
|
46143
|
+
chain: chain2,
|
|
46144
|
+
transport: createNetworkHttpTransport(rpcUrl, options)
|
|
46145
|
+
});
|
|
46146
|
+
const transaction = await walletClient.sendTransaction({
|
|
46147
|
+
to,
|
|
46148
|
+
value: amount,
|
|
46149
|
+
gas,
|
|
46150
|
+
maxFeePerGas,
|
|
46151
|
+
maxPriorityFeePerGas
|
|
46152
|
+
});
|
|
46153
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: transaction });
|
|
46154
|
+
if (receipt.status !== "success") {
|
|
46155
|
+
throw new Error(`Sweep transaction ${transaction} reverted on ${args.network}.`);
|
|
46156
|
+
}
|
|
46157
|
+
return { network: args.network, amountAtomic: amount.toString(), transaction };
|
|
46158
|
+
}
|
|
45918
46159
|
function isInsufficientGasError(error61) {
|
|
45919
46160
|
const seen = /* @__PURE__ */ new Set();
|
|
45920
46161
|
let current = error61;
|
|
@@ -77421,7 +77662,7 @@ function createRunBudget(args) {
|
|
|
77421
77662
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77422
77663
|
import { arch, platform, release } from "node:os";
|
|
77423
77664
|
import { join as join14 } from "node:path";
|
|
77424
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
77665
|
+
var VAPI_CLIENT_VERSION = "0.14.0";
|
|
77425
77666
|
async function createSupportReport(options) {
|
|
77426
77667
|
const message = options.message.trim();
|
|
77427
77668
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -82055,6 +82296,8 @@ export {
|
|
|
82055
82296
|
MARKETPLACE_RANKING_VERSION,
|
|
82056
82297
|
MAX_RESTORE_ACCOUNTS,
|
|
82057
82298
|
MovementError,
|
|
82299
|
+
NATIVE_ETH_FEE_MARGIN_PERCENT,
|
|
82300
|
+
NATIVE_ETH_L1_FEE_FALLBACK_WEI,
|
|
82058
82301
|
NETWORKS2 as NETWORKS,
|
|
82059
82302
|
ONRAMP_FALLBACK_INSTRUCTIONS,
|
|
82060
82303
|
ONRAMP_NETWORK,
|
|
@@ -82325,6 +82568,7 @@ export {
|
|
|
82325
82568
|
spendCapsSchema,
|
|
82326
82569
|
staleStoredPassphraseMessage,
|
|
82327
82570
|
startAccountLink,
|
|
82571
|
+
supportsNativeEthSweep,
|
|
82328
82572
|
swarmAccountNames,
|
|
82329
82573
|
swarmFilePath,
|
|
82330
82574
|
swarmFileSchema,
|
|
@@ -82336,6 +82580,7 @@ export {
|
|
|
82336
82580
|
sweepAboveCeiling,
|
|
82337
82581
|
sweepAllAboveCeiling,
|
|
82338
82582
|
sweepBack,
|
|
82583
|
+
sweepNativeEth,
|
|
82339
82584
|
sweepSolanaUsdc,
|
|
82340
82585
|
sweepTarget,
|
|
82341
82586
|
taskReservedAtomic,
|