@layr-labs/ecloud-sdk 1.0.0-dev.3 → 1.0.0-dev.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/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- version=1.0.0-dev.3
2
- commit=6bdd35bcdef2b55443165112b1eb91ff4cc06e27
1
+ version=1.0.0-dev.4
2
+ commit=c09e81b17f3f5e8ea24aa8df3681741dad15a710
package/dist/billing.cjs CHANGED
@@ -463,6 +463,7 @@ Please check:
463
463
  // src/client/common/config/environment.ts
464
464
  var SEPOLIA_CHAIN_ID = 11155111;
465
465
  var MAINNET_CHAIN_ID = 1;
466
+ var BASE_SEPOLIA_CHAIN_ID = 84532;
466
467
  var CommonAddresses = {
467
468
  ERC7702Delegator: "0x63c0c19a282a1b52b07dd5a65b58948a07dae32b"
468
469
  };
@@ -492,7 +493,9 @@ var ENVIRONMENTS = {
492
493
  kmsServerURL: "http://10.128.0.57:8080",
493
494
  userApiServerURL: "https://userapi-compute-sepolia-dev.eigencloud.xyz",
494
495
  defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
495
- usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376"
496
+ usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376",
497
+ baseUsdcCreditsAddress: "0x7673a47463F80c6a3553Db9E54c8cDcd5313d0ac",
498
+ baseRPCURL: "https://base-sepolia-rpc.publicnode.com"
496
499
  },
497
500
  sepolia: {
498
501
  name: "sepolia",
@@ -504,7 +507,9 @@ var ENVIRONMENTS = {
504
507
  userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
505
508
  defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
506
509
  billingRPCURL: "https://ethereum-rpc.publicnode.com",
507
- usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d"
510
+ usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d",
511
+ baseUsdcCreditsAddress: "0x7673a47463F80c6a3553Db9E54c8cDcd5313d0ac",
512
+ baseRPCURL: "https://base-sepolia-rpc.publicnode.com"
508
513
  },
509
514
  "mainnet-alpha": {
510
515
  name: "mainnet-alpha",
@@ -594,6 +599,41 @@ function isEnvironmentAvailable(environment) {
594
599
  return getAvailableEnvironments().includes(environment);
595
600
  }
596
601
 
602
+ // src/client/common/utils/helpers.ts
603
+ var import_viem2 = require("viem");
604
+ var import_chains2 = require("viem/chains");
605
+ var import_accounts = require("viem/accounts");
606
+
607
+ // src/client/common/constants.ts
608
+ var import_chains = require("viem/chains");
609
+ var SUPPORTED_CHAINS = [import_chains.mainnet, import_chains.sepolia, import_chains.baseSepolia];
610
+
611
+ // src/client/common/utils/helpers.ts
612
+ function getChainFromID(chainID, fallback2 = import_chains2.sepolia) {
613
+ const id = Number(chainID);
614
+ return (0, import_viem2.extractChain)({ chains: SUPPORTED_CHAINS, id }) || fallback2;
615
+ }
616
+ function createClients(options) {
617
+ const { privateKey, rpcUrl, chainId } = options;
618
+ const privateKeyHex = addHexPrefix(privateKey);
619
+ const account = (0, import_accounts.privateKeyToAccount)(privateKeyHex);
620
+ const chain = getChainFromID(chainId);
621
+ const transport = typeof rpcUrl === "string" ? (0, import_viem2.http)(rpcUrl) : (0, import_viem2.fallback)(rpcUrl.map((url) => (0, import_viem2.http)(url)));
622
+ const publicClient = (0, import_viem2.createPublicClient)({
623
+ chain,
624
+ transport
625
+ });
626
+ const walletClient = (0, import_viem2.createWalletClient)({
627
+ account,
628
+ chain,
629
+ transport
630
+ });
631
+ return { walletClient, publicClient };
632
+ }
633
+ function addHexPrefix(value) {
634
+ return value.startsWith("0x") ? value : `0x${value}`;
635
+ }
636
+
597
637
  // src/client/common/utils/logger.ts
598
638
  var getLogger = (verbose) => ({
599
639
  info: (...args) => console.info(...args),
@@ -605,14 +645,6 @@ var getLogger = (verbose) => ({
605
645
  // src/client/common/utils/userapi.ts
606
646
  var import_axios3 = __toESM(require("axios"), 1);
607
647
 
608
- // src/client/common/utils/helpers.ts
609
- var import_viem2 = require("viem");
610
- var import_chains2 = require("viem/chains");
611
- var import_accounts = require("viem/accounts");
612
-
613
- // src/client/common/constants.ts
614
- var import_chains = require("viem/chains");
615
-
616
648
  // src/client/common/utils/retry.ts
617
649
  var import_axios2 = __toESM(require("axios"), 1);
618
650
 
@@ -2108,7 +2140,7 @@ var ERC20_default = [
2108
2140
 
2109
2141
  // src/client/modules/billing/index.ts
2110
2142
  function createBillingModule(config) {
2111
- const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment } = config;
2143
+ const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment, privateKey } = config;
2112
2144
  if (!walletClient.account) {
2113
2145
  throw new Error("WalletClient must have an account attached");
2114
2146
  }
@@ -2117,35 +2149,69 @@ function createBillingModule(config) {
2117
2149
  const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
2118
2150
  const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
2119
2151
  const environmentConfig = getEnvironmentConfig(environment);
2120
- const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
2121
- if (!usdcCreditsAddress) {
2152
+ if (!environmentConfig.usdcCreditsAddress) {
2122
2153
  throw new Error(`USDCCredits contract address not configured for environment "${environment}"`);
2123
2154
  }
2155
+ const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
2156
+ const baseUsdcCreditsAddress = environmentConfig.baseUsdcCreditsAddress;
2157
+ const baseRPCURL = environmentConfig.baseRPCURL;
2158
+ function resolveChainConfig(chain) {
2159
+ if (chain === "base") {
2160
+ if (!baseUsdcCreditsAddress || !baseRPCURL) {
2161
+ throw new Error(`Base chain not configured for environment "${environment}"`);
2162
+ }
2163
+ if (!privateKey) {
2164
+ throw new Error("Private key required for Base chain transactions");
2165
+ }
2166
+ const baseClients = createClients({
2167
+ privateKey,
2168
+ rpcUrl: baseRPCURL,
2169
+ chainId: BigInt(BASE_SEPOLIA_CHAIN_ID)
2170
+ });
2171
+ return {
2172
+ pub: baseClients.publicClient,
2173
+ wallet: baseClients.walletClient,
2174
+ creditsAddress: baseUsdcCreditsAddress,
2175
+ envConfig: {
2176
+ ...environmentConfig,
2177
+ chainID: BigInt(BASE_SEPOLIA_CHAIN_ID),
2178
+ defaultRPCURL: baseRPCURL
2179
+ }
2180
+ };
2181
+ }
2182
+ return {
2183
+ pub: publicClient,
2184
+ wallet: walletClient,
2185
+ creditsAddress: usdcCreditsAddress,
2186
+ envConfig: environmentConfig
2187
+ };
2188
+ }
2124
2189
  const module2 = {
2125
2190
  address,
2126
- async getTopUpInfo() {
2127
- const usdcAddress = await publicClient.readContract({
2128
- address: usdcCreditsAddress,
2191
+ async getTopUpInfo(opts) {
2192
+ const { pub, creditsAddress } = resolveChainConfig(opts?.chain);
2193
+ const usdcAddress = await pub.readContract({
2194
+ address: creditsAddress,
2129
2195
  abi: USDCCredits_default,
2130
2196
  functionName: "usdc"
2131
2197
  });
2132
2198
  const [minimumPurchase, usdcBalance, currentAllowance] = await Promise.all([
2133
- publicClient.readContract({
2134
- address: usdcCreditsAddress,
2199
+ pub.readContract({
2200
+ address: creditsAddress,
2135
2201
  abi: USDCCredits_default,
2136
2202
  functionName: "minimumPurchase"
2137
2203
  }),
2138
- publicClient.readContract({
2204
+ pub.readContract({
2139
2205
  address: usdcAddress,
2140
2206
  abi: ERC20_default,
2141
2207
  functionName: "balanceOf",
2142
2208
  args: [address]
2143
2209
  }),
2144
- publicClient.readContract({
2210
+ pub.readContract({
2145
2211
  address: usdcAddress,
2146
2212
  abi: ERC20_default,
2147
2213
  functionName: "allowance",
2148
- args: [address, usdcCreditsAddress]
2214
+ args: [address, creditsAddress]
2149
2215
  })
2150
2216
  ]);
2151
2217
  return { usdcAddress, minimumPurchase, usdcBalance, currentAllowance };
@@ -2155,11 +2221,12 @@ function createBillingModule(config) {
2155
2221
  {
2156
2222
  functionName: "topUp",
2157
2223
  skipTelemetry,
2158
- properties: { amount: opts.amount.toString() }
2224
+ properties: { amount: opts.amount.toString(), chain: opts.chain || "ethereum" }
2159
2225
  },
2160
2226
  async () => {
2161
2227
  const targetAccount = opts.account ?? address;
2162
- const { usdcAddress, currentAllowance } = await module2.getTopUpInfo();
2228
+ const { pub, wallet, creditsAddress, envConfig } = resolveChainConfig(opts.chain);
2229
+ const { usdcAddress, currentAllowance } = await module2.getTopUpInfo({ chain: opts.chain });
2163
2230
  const executions = [];
2164
2231
  if (currentAllowance < opts.amount) {
2165
2232
  executions.push({
@@ -2168,12 +2235,12 @@ function createBillingModule(config) {
2168
2235
  callData: (0, import_viem5.encodeFunctionData)({
2169
2236
  abi: ERC20_default,
2170
2237
  functionName: "approve",
2171
- args: [usdcCreditsAddress, opts.amount]
2238
+ args: [creditsAddress, opts.amount]
2172
2239
  })
2173
2240
  });
2174
2241
  }
2175
2242
  executions.push({
2176
- target: usdcCreditsAddress,
2243
+ target: creditsAddress,
2177
2244
  value: 0n,
2178
2245
  callData: (0, import_viem5.encodeFunctionData)({
2179
2246
  abi: USDCCredits_default,
@@ -2183,9 +2250,9 @@ function createBillingModule(config) {
2183
2250
  });
2184
2251
  const txHash = await executeBatch(
2185
2252
  {
2186
- walletClient,
2187
- publicClient,
2188
- environmentConfig,
2253
+ walletClient: wallet,
2254
+ publicClient: pub,
2255
+ environmentConfig: envConfig,
2189
2256
  executions,
2190
2257
  pendingMessage: "Submitting credit purchase..."
2191
2258
  },
@@ -2285,6 +2352,9 @@ function createBillingModule(config) {
2285
2352
  },
2286
2353
  async purchaseCredits(amountCents, paymentMethodId) {
2287
2354
  return billingApi.purchaseCredits(amountCents, paymentMethodId);
2355
+ },
2356
+ hasBaseSupport() {
2357
+ return !!baseUsdcCreditsAddress && !!baseRPCURL;
2288
2358
  }
2289
2359
  };
2290
2360
  return module2;