@layr-labs/ecloud-sdk 1.0.0-devep7 → 1.0.0-devep8
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 +2 -2
- package/dist/billing.cjs +96 -26
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +11 -3
- package/dist/billing.d.ts +11 -3
- package/dist/billing.js +96 -26
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +6 -2
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +7 -3
- package/dist/browser.js.map +1 -1
- package/dist/{compute-CoBGVJXh.d.cts → compute-DfFZvbPD.d.cts} +1 -1
- package/dist/{compute-2WkiO-d8.d.ts → compute-GcTgGp_x.d.ts} +1 -1
- package/dist/compute.cjs +84 -4
- package/dist/compute.cjs.map +1 -1
- package/dist/compute.d.cts +2 -2
- package/dist/compute.d.ts +2 -2
- package/dist/compute.js +85 -5
- package/dist/compute.js.map +1 -1
- package/dist/{helpers-BVSe7yTf.d.cts → helpers-0Tz3MuQK.d.cts} +3 -2
- package/dist/{helpers-B8KBOdM4.d.ts → helpers-NGE0oIa9.d.ts} +3 -2
- package/dist/{index-XhjPvHIY.d.cts → index-DFqQ7v8_.d.cts} +2 -0
- package/dist/{index-XhjPvHIY.d.ts → index-DFqQ7v8_.d.ts} +2 -0
- package/dist/index.cjs +143 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +143 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/VERSION
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
version=1.0.0-
|
|
2
|
-
commit=
|
|
1
|
+
version=1.0.0-devep8
|
|
2
|
+
commit=e481d7c8e23382099664490a6725e15ebe6a1f74
|
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
|
};
|
|
@@ -496,6 +497,8 @@ var ENVIRONMENTS = {
|
|
|
496
497
|
userApiServerURL: "https://userapi-compute-sepolia-dev.eigencloud.xyz",
|
|
497
498
|
defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
498
499
|
usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376",
|
|
500
|
+
baseUsdcCreditsAddress: "0x7673a47463F80c6a3553Db9E54c8cDcd5313d0ac",
|
|
501
|
+
baseRPCURL: "https://base-sepolia-rpc.publicnode.com",
|
|
499
502
|
platformEnv: PLATFORM_ENV_TESTNET_SEPOLIA,
|
|
500
503
|
appBaseDomain: DEFAULT_APP_BASE_DOMAIN
|
|
501
504
|
},
|
|
@@ -510,6 +513,8 @@ var ENVIRONMENTS = {
|
|
|
510
513
|
defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
511
514
|
billingRPCURL: "https://ethereum-rpc.publicnode.com",
|
|
512
515
|
usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d",
|
|
516
|
+
baseUsdcCreditsAddress: "0x7673a47463F80c6a3553Db9E54c8cDcd5313d0ac",
|
|
517
|
+
baseRPCURL: "https://base-sepolia-rpc.publicnode.com",
|
|
513
518
|
platformEnv: PLATFORM_ENV_TESTNET_SEPOLIA,
|
|
514
519
|
appBaseDomain: DEFAULT_APP_BASE_DOMAIN
|
|
515
520
|
},
|
|
@@ -603,6 +608,41 @@ function isEnvironmentAvailable(environment) {
|
|
|
603
608
|
return getAvailableEnvironments().includes(environment);
|
|
604
609
|
}
|
|
605
610
|
|
|
611
|
+
// src/client/common/utils/helpers.ts
|
|
612
|
+
var import_viem2 = require("viem");
|
|
613
|
+
var import_chains2 = require("viem/chains");
|
|
614
|
+
var import_accounts = require("viem/accounts");
|
|
615
|
+
|
|
616
|
+
// src/client/common/constants.ts
|
|
617
|
+
var import_chains = require("viem/chains");
|
|
618
|
+
var SUPPORTED_CHAINS = [import_chains.mainnet, import_chains.sepolia, import_chains.baseSepolia];
|
|
619
|
+
|
|
620
|
+
// src/client/common/utils/helpers.ts
|
|
621
|
+
function getChainFromID(chainID, fallback2 = import_chains2.sepolia) {
|
|
622
|
+
const id = Number(chainID);
|
|
623
|
+
return (0, import_viem2.extractChain)({ chains: SUPPORTED_CHAINS, id }) || fallback2;
|
|
624
|
+
}
|
|
625
|
+
function createClients(options) {
|
|
626
|
+
const { privateKey, rpcUrl, chainId } = options;
|
|
627
|
+
const privateKeyHex = addHexPrefix(privateKey);
|
|
628
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKeyHex);
|
|
629
|
+
const chain = getChainFromID(chainId);
|
|
630
|
+
const transport = typeof rpcUrl === "string" ? (0, import_viem2.http)(rpcUrl) : (0, import_viem2.fallback)(rpcUrl.map((url) => (0, import_viem2.http)(url)));
|
|
631
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
632
|
+
chain,
|
|
633
|
+
transport
|
|
634
|
+
});
|
|
635
|
+
const walletClient = (0, import_viem2.createWalletClient)({
|
|
636
|
+
account,
|
|
637
|
+
chain,
|
|
638
|
+
transport
|
|
639
|
+
});
|
|
640
|
+
return { walletClient, publicClient };
|
|
641
|
+
}
|
|
642
|
+
function addHexPrefix(value) {
|
|
643
|
+
return value.startsWith("0x") ? value : `0x${value}`;
|
|
644
|
+
}
|
|
645
|
+
|
|
606
646
|
// src/client/common/utils/logger.ts
|
|
607
647
|
var getLogger = (verbose) => ({
|
|
608
648
|
info: (...args) => console.info(...args),
|
|
@@ -614,14 +654,6 @@ var getLogger = (verbose) => ({
|
|
|
614
654
|
// src/client/common/utils/userapi.ts
|
|
615
655
|
var import_axios3 = __toESM(require("axios"), 1);
|
|
616
656
|
|
|
617
|
-
// src/client/common/utils/helpers.ts
|
|
618
|
-
var import_viem2 = require("viem");
|
|
619
|
-
var import_chains2 = require("viem/chains");
|
|
620
|
-
var import_accounts = require("viem/accounts");
|
|
621
|
-
|
|
622
|
-
// src/client/common/constants.ts
|
|
623
|
-
var import_chains = require("viem/chains");
|
|
624
|
-
|
|
625
657
|
// src/client/common/utils/retry.ts
|
|
626
658
|
var import_axios2 = __toESM(require("axios"), 1);
|
|
627
659
|
|
|
@@ -2117,7 +2149,7 @@ var ERC20_default = [
|
|
|
2117
2149
|
|
|
2118
2150
|
// src/client/modules/billing/index.ts
|
|
2119
2151
|
function createBillingModule(config) {
|
|
2120
|
-
const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment } = config;
|
|
2152
|
+
const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment, privateKey } = config;
|
|
2121
2153
|
if (!walletClient.account) {
|
|
2122
2154
|
throw new Error("WalletClient must have an account attached");
|
|
2123
2155
|
}
|
|
@@ -2126,35 +2158,69 @@ function createBillingModule(config) {
|
|
|
2126
2158
|
const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
|
|
2127
2159
|
const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
|
|
2128
2160
|
const environmentConfig = getEnvironmentConfig(environment);
|
|
2129
|
-
|
|
2130
|
-
if (!usdcCreditsAddress) {
|
|
2161
|
+
if (!environmentConfig.usdcCreditsAddress) {
|
|
2131
2162
|
throw new Error(`USDCCredits contract address not configured for environment "${environment}"`);
|
|
2132
2163
|
}
|
|
2164
|
+
const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
|
|
2165
|
+
const baseUsdcCreditsAddress = environmentConfig.baseUsdcCreditsAddress;
|
|
2166
|
+
const baseRPCURL = environmentConfig.baseRPCURL;
|
|
2167
|
+
function resolveChainConfig(chain) {
|
|
2168
|
+
if (chain === "base") {
|
|
2169
|
+
if (!baseUsdcCreditsAddress || !baseRPCURL) {
|
|
2170
|
+
throw new Error(`Base chain not configured for environment "${environment}"`);
|
|
2171
|
+
}
|
|
2172
|
+
if (!privateKey) {
|
|
2173
|
+
throw new Error("Private key required for Base chain transactions");
|
|
2174
|
+
}
|
|
2175
|
+
const baseClients = createClients({
|
|
2176
|
+
privateKey,
|
|
2177
|
+
rpcUrl: baseRPCURL,
|
|
2178
|
+
chainId: BigInt(BASE_SEPOLIA_CHAIN_ID)
|
|
2179
|
+
});
|
|
2180
|
+
return {
|
|
2181
|
+
pub: baseClients.publicClient,
|
|
2182
|
+
wallet: baseClients.walletClient,
|
|
2183
|
+
creditsAddress: baseUsdcCreditsAddress,
|
|
2184
|
+
envConfig: {
|
|
2185
|
+
...environmentConfig,
|
|
2186
|
+
chainID: BigInt(BASE_SEPOLIA_CHAIN_ID),
|
|
2187
|
+
defaultRPCURL: baseRPCURL
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
return {
|
|
2192
|
+
pub: publicClient,
|
|
2193
|
+
wallet: walletClient,
|
|
2194
|
+
creditsAddress: usdcCreditsAddress,
|
|
2195
|
+
envConfig: environmentConfig
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2133
2198
|
const module2 = {
|
|
2134
2199
|
address,
|
|
2135
|
-
async getTopUpInfo() {
|
|
2136
|
-
const
|
|
2137
|
-
|
|
2200
|
+
async getTopUpInfo(opts) {
|
|
2201
|
+
const { pub, creditsAddress } = resolveChainConfig(opts?.chain);
|
|
2202
|
+
const usdcAddress = await pub.readContract({
|
|
2203
|
+
address: creditsAddress,
|
|
2138
2204
|
abi: USDCCredits_default,
|
|
2139
2205
|
functionName: "usdc"
|
|
2140
2206
|
});
|
|
2141
2207
|
const [minimumPurchase, usdcBalance, currentAllowance] = await Promise.all([
|
|
2142
|
-
|
|
2143
|
-
address:
|
|
2208
|
+
pub.readContract({
|
|
2209
|
+
address: creditsAddress,
|
|
2144
2210
|
abi: USDCCredits_default,
|
|
2145
2211
|
functionName: "minimumPurchase"
|
|
2146
2212
|
}),
|
|
2147
|
-
|
|
2213
|
+
pub.readContract({
|
|
2148
2214
|
address: usdcAddress,
|
|
2149
2215
|
abi: ERC20_default,
|
|
2150
2216
|
functionName: "balanceOf",
|
|
2151
2217
|
args: [address]
|
|
2152
2218
|
}),
|
|
2153
|
-
|
|
2219
|
+
pub.readContract({
|
|
2154
2220
|
address: usdcAddress,
|
|
2155
2221
|
abi: ERC20_default,
|
|
2156
2222
|
functionName: "allowance",
|
|
2157
|
-
args: [address,
|
|
2223
|
+
args: [address, creditsAddress]
|
|
2158
2224
|
})
|
|
2159
2225
|
]);
|
|
2160
2226
|
return { usdcAddress, minimumPurchase, usdcBalance, currentAllowance };
|
|
@@ -2164,11 +2230,12 @@ function createBillingModule(config) {
|
|
|
2164
2230
|
{
|
|
2165
2231
|
functionName: "topUp",
|
|
2166
2232
|
skipTelemetry,
|
|
2167
|
-
properties: { amount: opts.amount.toString() }
|
|
2233
|
+
properties: { amount: opts.amount.toString(), chain: opts.chain || "ethereum" }
|
|
2168
2234
|
},
|
|
2169
2235
|
async () => {
|
|
2170
2236
|
const targetAccount = opts.account ?? address;
|
|
2171
|
-
const {
|
|
2237
|
+
const { pub, wallet, creditsAddress, envConfig } = resolveChainConfig(opts.chain);
|
|
2238
|
+
const { usdcAddress, currentAllowance } = await module2.getTopUpInfo({ chain: opts.chain });
|
|
2172
2239
|
const executions = [];
|
|
2173
2240
|
if (currentAllowance < opts.amount) {
|
|
2174
2241
|
executions.push({
|
|
@@ -2177,12 +2244,12 @@ function createBillingModule(config) {
|
|
|
2177
2244
|
callData: (0, import_viem5.encodeFunctionData)({
|
|
2178
2245
|
abi: ERC20_default,
|
|
2179
2246
|
functionName: "approve",
|
|
2180
|
-
args: [
|
|
2247
|
+
args: [creditsAddress, opts.amount]
|
|
2181
2248
|
})
|
|
2182
2249
|
});
|
|
2183
2250
|
}
|
|
2184
2251
|
executions.push({
|
|
2185
|
-
target:
|
|
2252
|
+
target: creditsAddress,
|
|
2186
2253
|
value: 0n,
|
|
2187
2254
|
callData: (0, import_viem5.encodeFunctionData)({
|
|
2188
2255
|
abi: USDCCredits_default,
|
|
@@ -2192,9 +2259,9 @@ function createBillingModule(config) {
|
|
|
2192
2259
|
});
|
|
2193
2260
|
const txHash = await executeBatch(
|
|
2194
2261
|
{
|
|
2195
|
-
walletClient,
|
|
2196
|
-
publicClient,
|
|
2197
|
-
environmentConfig,
|
|
2262
|
+
walletClient: wallet,
|
|
2263
|
+
publicClient: pub,
|
|
2264
|
+
environmentConfig: envConfig,
|
|
2198
2265
|
executions,
|
|
2199
2266
|
pendingMessage: "Submitting credit purchase..."
|
|
2200
2267
|
},
|
|
@@ -2294,6 +2361,9 @@ function createBillingModule(config) {
|
|
|
2294
2361
|
},
|
|
2295
2362
|
async purchaseCredits(amountCents, paymentMethodId) {
|
|
2296
2363
|
return billingApi.purchaseCredits(amountCents, paymentMethodId);
|
|
2364
|
+
},
|
|
2365
|
+
hasBaseSupport() {
|
|
2366
|
+
return !!baseUsdcCreditsAddress && !!baseRPCURL;
|
|
2297
2367
|
}
|
|
2298
2368
|
};
|
|
2299
2369
|
return module2;
|