@layr-labs/ecloud-sdk 1.0.0-dev.3 → 1.0.0-dev.5
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 +158 -28
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +12 -3
- package/dist/billing.d.ts +12 -3
- package/dist/billing.js +158 -28
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +65 -4
- 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 +66 -5
- package/dist/browser.js.map +1 -1
- package/dist/{compute-BbgMH6Ef.d.ts → compute-9bzsfthb.d.ts} +1 -1
- package/dist/{compute-yAqGf5hM.d.cts → compute-RhRi2H8h.d.cts} +1 -1
- package/dist/compute.cjs +8 -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 +9 -5
- package/dist/compute.js.map +1 -1
- package/dist/{helpers-GWlLS3gz.d.ts → helpers-CqrBJ39N.d.cts} +17 -2
- package/dist/{helpers-CnlJ5yPE.d.cts → helpers-DEGFGA-T.d.ts} +17 -2
- package/dist/{index-Bac4HjC0.d.cts → index-CLhRJNai.d.cts} +36 -1
- package/dist/{index-Bac4HjC0.d.ts → index-CLhRJNai.d.ts} +36 -1
- package/dist/index.cjs +167 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -8
- package/dist/index.d.ts +32 -8
- package/dist/index.js +166 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/tools/tls-keygen-linux-amd64 +0 -0
package/VERSION
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
version=1.0.0-dev.
|
|
2
|
-
commit=
|
|
1
|
+
version=1.0.0-dev.5
|
|
2
|
+
commit=7451666189ca42c9ef358346e8998e3e35640e42
|
package/dist/billing.cjs
CHANGED
|
@@ -332,6 +332,63 @@ var BillingApiClient = class {
|
|
|
332
332
|
return resp.json();
|
|
333
333
|
}
|
|
334
334
|
// ==========================================================================
|
|
335
|
+
// Admin - Coupon Methods
|
|
336
|
+
// ==========================================================================
|
|
337
|
+
async createCoupon(amountCents) {
|
|
338
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/coupons`;
|
|
339
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", "compute", { amountCents });
|
|
340
|
+
return resp.json();
|
|
341
|
+
}
|
|
342
|
+
async listCoupons(opts) {
|
|
343
|
+
const params = new URLSearchParams();
|
|
344
|
+
if (opts?.offset !== void 0) params.set("offset", opts.offset.toString());
|
|
345
|
+
if (opts?.limit !== void 0) params.set("limit", opts.limit.toString());
|
|
346
|
+
if (opts?.active !== void 0) params.set("active", opts.active.toString());
|
|
347
|
+
if (opts?.redeemed !== void 0) params.set("redeemed", opts.redeemed.toString());
|
|
348
|
+
const qs = params.toString();
|
|
349
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/coupons${qs ? `?${qs}` : ""}`;
|
|
350
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "GET", "compute");
|
|
351
|
+
return resp.json();
|
|
352
|
+
}
|
|
353
|
+
async getCoupon(id) {
|
|
354
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/coupons/${id}`;
|
|
355
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "GET", "compute");
|
|
356
|
+
return resp.json();
|
|
357
|
+
}
|
|
358
|
+
async deactivateCoupon(id) {
|
|
359
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/coupons/${id}/deactivate`;
|
|
360
|
+
await this.makeAuthenticatedRequest(endpoint, "POST", "compute");
|
|
361
|
+
}
|
|
362
|
+
async redeemCouponForUser(id, address) {
|
|
363
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/coupons/${id}/redeem`;
|
|
364
|
+
await this.makeAuthenticatedRequest(endpoint, "POST", "compute", { address });
|
|
365
|
+
}
|
|
366
|
+
// ==========================================================================
|
|
367
|
+
// Admin - Admin Management Methods
|
|
368
|
+
// ==========================================================================
|
|
369
|
+
async addAdmin(address) {
|
|
370
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/admins`;
|
|
371
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", "compute", { address });
|
|
372
|
+
return resp.json();
|
|
373
|
+
}
|
|
374
|
+
async removeAdmin(address) {
|
|
375
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/admins/${address}`;
|
|
376
|
+
await this.makeAuthenticatedRequest(endpoint, "DELETE", "compute");
|
|
377
|
+
}
|
|
378
|
+
async listAdmins() {
|
|
379
|
+
const endpoint = `${this.config.billingApiServerURL}/admin/admins`;
|
|
380
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "GET", "compute");
|
|
381
|
+
return resp.json();
|
|
382
|
+
}
|
|
383
|
+
// ==========================================================================
|
|
384
|
+
// User - Coupon Redemption
|
|
385
|
+
// ==========================================================================
|
|
386
|
+
async redeemCoupon(code) {
|
|
387
|
+
const endpoint = `${this.config.billingApiServerURL}/v1/coupons/redeem`;
|
|
388
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", "compute", { code });
|
|
389
|
+
return resp.json();
|
|
390
|
+
}
|
|
391
|
+
// ==========================================================================
|
|
335
392
|
// Internal Methods
|
|
336
393
|
// ==========================================================================
|
|
337
394
|
/**
|
|
@@ -463,6 +520,7 @@ Please check:
|
|
|
463
520
|
// src/client/common/config/environment.ts
|
|
464
521
|
var SEPOLIA_CHAIN_ID = 11155111;
|
|
465
522
|
var MAINNET_CHAIN_ID = 1;
|
|
523
|
+
var BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
466
524
|
var CommonAddresses = {
|
|
467
525
|
ERC7702Delegator: "0x63c0c19a282a1b52b07dd5a65b58948a07dae32b"
|
|
468
526
|
};
|
|
@@ -492,7 +550,9 @@ var ENVIRONMENTS = {
|
|
|
492
550
|
kmsServerURL: "http://10.128.0.57:8080",
|
|
493
551
|
userApiServerURL: "https://userapi-compute-sepolia-dev.eigencloud.xyz",
|
|
494
552
|
defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
495
|
-
usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376"
|
|
553
|
+
usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376",
|
|
554
|
+
baseUsdcCreditsAddress: "0x7673a47463F80c6a3553Db9E54c8cDcd5313d0ac",
|
|
555
|
+
baseRPCURL: "https://base-sepolia-rpc.publicnode.com"
|
|
496
556
|
},
|
|
497
557
|
sepolia: {
|
|
498
558
|
name: "sepolia",
|
|
@@ -504,7 +564,9 @@ var ENVIRONMENTS = {
|
|
|
504
564
|
userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
|
|
505
565
|
defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
506
566
|
billingRPCURL: "https://ethereum-rpc.publicnode.com",
|
|
507
|
-
usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d"
|
|
567
|
+
usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d",
|
|
568
|
+
baseUsdcCreditsAddress: "0x7673a47463F80c6a3553Db9E54c8cDcd5313d0ac",
|
|
569
|
+
baseRPCURL: "https://base-sepolia-rpc.publicnode.com"
|
|
508
570
|
},
|
|
509
571
|
"mainnet-alpha": {
|
|
510
572
|
name: "mainnet-alpha",
|
|
@@ -594,6 +656,41 @@ function isEnvironmentAvailable(environment) {
|
|
|
594
656
|
return getAvailableEnvironments().includes(environment);
|
|
595
657
|
}
|
|
596
658
|
|
|
659
|
+
// src/client/common/utils/helpers.ts
|
|
660
|
+
var import_viem2 = require("viem");
|
|
661
|
+
var import_chains2 = require("viem/chains");
|
|
662
|
+
var import_accounts = require("viem/accounts");
|
|
663
|
+
|
|
664
|
+
// src/client/common/constants.ts
|
|
665
|
+
var import_chains = require("viem/chains");
|
|
666
|
+
var SUPPORTED_CHAINS = [import_chains.mainnet, import_chains.sepolia, import_chains.baseSepolia];
|
|
667
|
+
|
|
668
|
+
// src/client/common/utils/helpers.ts
|
|
669
|
+
function getChainFromID(chainID, fallback2 = import_chains2.sepolia) {
|
|
670
|
+
const id = Number(chainID);
|
|
671
|
+
return (0, import_viem2.extractChain)({ chains: SUPPORTED_CHAINS, id }) || fallback2;
|
|
672
|
+
}
|
|
673
|
+
function createClients(options) {
|
|
674
|
+
const { privateKey, rpcUrl, chainId } = options;
|
|
675
|
+
const privateKeyHex = addHexPrefix(privateKey);
|
|
676
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKeyHex);
|
|
677
|
+
const chain = getChainFromID(chainId);
|
|
678
|
+
const transport = typeof rpcUrl === "string" ? (0, import_viem2.http)(rpcUrl) : (0, import_viem2.fallback)(rpcUrl.map((url) => (0, import_viem2.http)(url)));
|
|
679
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
680
|
+
chain,
|
|
681
|
+
transport
|
|
682
|
+
});
|
|
683
|
+
const walletClient = (0, import_viem2.createWalletClient)({
|
|
684
|
+
account,
|
|
685
|
+
chain,
|
|
686
|
+
transport
|
|
687
|
+
});
|
|
688
|
+
return { walletClient, publicClient };
|
|
689
|
+
}
|
|
690
|
+
function addHexPrefix(value) {
|
|
691
|
+
return value.startsWith("0x") ? value : `0x${value}`;
|
|
692
|
+
}
|
|
693
|
+
|
|
597
694
|
// src/client/common/utils/logger.ts
|
|
598
695
|
var getLogger = (verbose) => ({
|
|
599
696
|
info: (...args) => console.info(...args),
|
|
@@ -605,14 +702,6 @@ var getLogger = (verbose) => ({
|
|
|
605
702
|
// src/client/common/utils/userapi.ts
|
|
606
703
|
var import_axios3 = __toESM(require("axios"), 1);
|
|
607
704
|
|
|
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
705
|
// src/client/common/utils/retry.ts
|
|
617
706
|
var import_axios2 = __toESM(require("axios"), 1);
|
|
618
707
|
|
|
@@ -2108,7 +2197,7 @@ var ERC20_default = [
|
|
|
2108
2197
|
|
|
2109
2198
|
// src/client/modules/billing/index.ts
|
|
2110
2199
|
function createBillingModule(config) {
|
|
2111
|
-
const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment } = config;
|
|
2200
|
+
const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment, privateKey } = config;
|
|
2112
2201
|
if (!walletClient.account) {
|
|
2113
2202
|
throw new Error("WalletClient must have an account attached");
|
|
2114
2203
|
}
|
|
@@ -2117,35 +2206,69 @@ function createBillingModule(config) {
|
|
|
2117
2206
|
const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
|
|
2118
2207
|
const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
|
|
2119
2208
|
const environmentConfig = getEnvironmentConfig(environment);
|
|
2120
|
-
|
|
2121
|
-
if (!usdcCreditsAddress) {
|
|
2209
|
+
if (!environmentConfig.usdcCreditsAddress) {
|
|
2122
2210
|
throw new Error(`USDCCredits contract address not configured for environment "${environment}"`);
|
|
2123
2211
|
}
|
|
2212
|
+
const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
|
|
2213
|
+
const baseUsdcCreditsAddress = environmentConfig.baseUsdcCreditsAddress;
|
|
2214
|
+
const baseRPCURL = environmentConfig.baseRPCURL;
|
|
2215
|
+
function resolveChainConfig(chain) {
|
|
2216
|
+
if (chain === "base") {
|
|
2217
|
+
if (!baseUsdcCreditsAddress || !baseRPCURL) {
|
|
2218
|
+
throw new Error(`Base chain not configured for environment "${environment}"`);
|
|
2219
|
+
}
|
|
2220
|
+
if (!privateKey) {
|
|
2221
|
+
throw new Error("Private key required for Base chain transactions");
|
|
2222
|
+
}
|
|
2223
|
+
const baseClients = createClients({
|
|
2224
|
+
privateKey,
|
|
2225
|
+
rpcUrl: baseRPCURL,
|
|
2226
|
+
chainId: BigInt(BASE_SEPOLIA_CHAIN_ID)
|
|
2227
|
+
});
|
|
2228
|
+
return {
|
|
2229
|
+
pub: baseClients.publicClient,
|
|
2230
|
+
wallet: baseClients.walletClient,
|
|
2231
|
+
creditsAddress: baseUsdcCreditsAddress,
|
|
2232
|
+
envConfig: {
|
|
2233
|
+
...environmentConfig,
|
|
2234
|
+
chainID: BigInt(BASE_SEPOLIA_CHAIN_ID),
|
|
2235
|
+
defaultRPCURL: baseRPCURL
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
return {
|
|
2240
|
+
pub: publicClient,
|
|
2241
|
+
wallet: walletClient,
|
|
2242
|
+
creditsAddress: usdcCreditsAddress,
|
|
2243
|
+
envConfig: environmentConfig
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2124
2246
|
const module2 = {
|
|
2125
2247
|
address,
|
|
2126
|
-
async getTopUpInfo() {
|
|
2127
|
-
const
|
|
2128
|
-
|
|
2248
|
+
async getTopUpInfo(opts) {
|
|
2249
|
+
const { pub, creditsAddress } = resolveChainConfig(opts?.chain);
|
|
2250
|
+
const usdcAddress = await pub.readContract({
|
|
2251
|
+
address: creditsAddress,
|
|
2129
2252
|
abi: USDCCredits_default,
|
|
2130
2253
|
functionName: "usdc"
|
|
2131
2254
|
});
|
|
2132
2255
|
const [minimumPurchase, usdcBalance, currentAllowance] = await Promise.all([
|
|
2133
|
-
|
|
2134
|
-
address:
|
|
2256
|
+
pub.readContract({
|
|
2257
|
+
address: creditsAddress,
|
|
2135
2258
|
abi: USDCCredits_default,
|
|
2136
2259
|
functionName: "minimumPurchase"
|
|
2137
2260
|
}),
|
|
2138
|
-
|
|
2261
|
+
pub.readContract({
|
|
2139
2262
|
address: usdcAddress,
|
|
2140
2263
|
abi: ERC20_default,
|
|
2141
2264
|
functionName: "balanceOf",
|
|
2142
2265
|
args: [address]
|
|
2143
2266
|
}),
|
|
2144
|
-
|
|
2267
|
+
pub.readContract({
|
|
2145
2268
|
address: usdcAddress,
|
|
2146
2269
|
abi: ERC20_default,
|
|
2147
2270
|
functionName: "allowance",
|
|
2148
|
-
args: [address,
|
|
2271
|
+
args: [address, creditsAddress]
|
|
2149
2272
|
})
|
|
2150
2273
|
]);
|
|
2151
2274
|
return { usdcAddress, minimumPurchase, usdcBalance, currentAllowance };
|
|
@@ -2155,11 +2278,12 @@ function createBillingModule(config) {
|
|
|
2155
2278
|
{
|
|
2156
2279
|
functionName: "topUp",
|
|
2157
2280
|
skipTelemetry,
|
|
2158
|
-
properties: { amount: opts.amount.toString() }
|
|
2281
|
+
properties: { amount: opts.amount.toString(), chain: opts.chain || "ethereum" }
|
|
2159
2282
|
},
|
|
2160
2283
|
async () => {
|
|
2161
2284
|
const targetAccount = opts.account ?? address;
|
|
2162
|
-
const {
|
|
2285
|
+
const { pub, wallet, creditsAddress, envConfig } = resolveChainConfig(opts.chain);
|
|
2286
|
+
const { usdcAddress, currentAllowance } = await module2.getTopUpInfo({ chain: opts.chain });
|
|
2163
2287
|
const executions = [];
|
|
2164
2288
|
if (currentAllowance < opts.amount) {
|
|
2165
2289
|
executions.push({
|
|
@@ -2168,12 +2292,12 @@ function createBillingModule(config) {
|
|
|
2168
2292
|
callData: (0, import_viem5.encodeFunctionData)({
|
|
2169
2293
|
abi: ERC20_default,
|
|
2170
2294
|
functionName: "approve",
|
|
2171
|
-
args: [
|
|
2295
|
+
args: [creditsAddress, opts.amount]
|
|
2172
2296
|
})
|
|
2173
2297
|
});
|
|
2174
2298
|
}
|
|
2175
2299
|
executions.push({
|
|
2176
|
-
target:
|
|
2300
|
+
target: creditsAddress,
|
|
2177
2301
|
value: 0n,
|
|
2178
2302
|
callData: (0, import_viem5.encodeFunctionData)({
|
|
2179
2303
|
abi: USDCCredits_default,
|
|
@@ -2183,9 +2307,9 @@ function createBillingModule(config) {
|
|
|
2183
2307
|
});
|
|
2184
2308
|
const txHash = await executeBatch(
|
|
2185
2309
|
{
|
|
2186
|
-
walletClient,
|
|
2187
|
-
publicClient,
|
|
2188
|
-
environmentConfig,
|
|
2310
|
+
walletClient: wallet,
|
|
2311
|
+
publicClient: pub,
|
|
2312
|
+
environmentConfig: envConfig,
|
|
2189
2313
|
executions,
|
|
2190
2314
|
pendingMessage: "Submitting credit purchase..."
|
|
2191
2315
|
},
|
|
@@ -2285,6 +2409,12 @@ function createBillingModule(config) {
|
|
|
2285
2409
|
},
|
|
2286
2410
|
async purchaseCredits(amountCents, paymentMethodId) {
|
|
2287
2411
|
return billingApi.purchaseCredits(amountCents, paymentMethodId);
|
|
2412
|
+
},
|
|
2413
|
+
hasBaseSupport() {
|
|
2414
|
+
return !!baseUsdcCreditsAddress && !!baseRPCURL;
|
|
2415
|
+
},
|
|
2416
|
+
async redeemCoupon(code) {
|
|
2417
|
+
return billingApi.redeemCoupon(code);
|
|
2288
2418
|
}
|
|
2289
2419
|
};
|
|
2290
2420
|
return module2;
|