@intentlayer/sdk 0.1.0 → 0.1.2

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/index.mjs CHANGED
@@ -77,7 +77,7 @@ import {
77
77
  init_constraints,
78
78
  isRecipientAllowed,
79
79
  v2ConstraintsToLeafParams
80
- } from "./chunk-GRBEB2EV.mjs";
80
+ } from "./chunk-BN6IO64L.mjs";
81
81
  import {
82
82
  __esm,
83
83
  __export,
@@ -3590,7 +3590,7 @@ var RelayerRuntime = class {
3590
3590
  *
3591
3591
  * @example
3592
3592
  * ```ts
3593
- * import { GLOBAL_FLAG_NO_BRIDGE } from '@iel/sdk';
3593
+ * import { GLOBAL_FLAG_NO_BRIDGE } from '@intentlayer/sdk';
3594
3594
  *
3595
3595
  * // Enable bridge blocking (invalidates pending intents)
3596
3596
  * const { headerVersion, txHash } = await runtime.updatePolicyGlobalFlags(
@@ -3695,13 +3695,16 @@ var IELCloudClient = class {
3695
3695
  */
3696
3696
  async request(method, path, body) {
3697
3697
  const token = await this.getAuthToken();
3698
+ const headers = {
3699
+ Authorization: `Bearer ${token}`
3700
+ };
3701
+ if (body !== void 0) {
3702
+ headers["Content-Type"] = "application/json";
3703
+ }
3698
3704
  const response = await fetch(`${this.baseUrl}${path}`, {
3699
3705
  method,
3700
- headers: {
3701
- Authorization: `Bearer ${token}`,
3702
- "Content-Type": "application/json"
3703
- },
3704
- body: body ? JSON.stringify(body) : void 0
3706
+ headers,
3707
+ body: body !== void 0 ? JSON.stringify(body) : void 0
3705
3708
  });
3706
3709
  const data = await response.json();
3707
3710
  if (!response.ok) {
@@ -3963,6 +3966,120 @@ var IELCloudClient = class {
3963
3966
  );
3964
3967
  }
3965
3968
  // ══════════════════════════════════════════════════════════════════════════
3969
+ // Request Operations (Policy, AgentWallet, Fund)
3970
+ // ══════════════════════════════════════════════════════════════════════════
3971
+ /**
3972
+ * Create a request (policy, agent_wallet, or fund).
3973
+ * Agents use this to request new permissions from the wallet owner.
3974
+ */
3975
+ async createRequest(body, idempotencyKey) {
3976
+ const token = await this.getAuthToken();
3977
+ const headers = {
3978
+ Authorization: `Bearer ${token}`,
3979
+ "Content-Type": "application/json"
3980
+ };
3981
+ if (idempotencyKey) {
3982
+ headers["Idempotency-Key"] = idempotencyKey;
3983
+ }
3984
+ const response = await fetch(`${this.baseUrl}/v1/requests`, {
3985
+ method: "POST",
3986
+ headers,
3987
+ body: JSON.stringify(body)
3988
+ });
3989
+ const data = await response.json();
3990
+ if (!response.ok) {
3991
+ const error = data;
3992
+ throw new CloudAPIError(
3993
+ response.status,
3994
+ error.code ?? "UNKNOWN_ERROR",
3995
+ error.message ?? "Unknown error",
3996
+ error.details
3997
+ );
3998
+ }
3999
+ return data;
4000
+ }
4001
+ /**
4002
+ * List requests with optional filters.
4003
+ */
4004
+ async listRequests(options) {
4005
+ const params = new URLSearchParams();
4006
+ if (options?.status) params.set("status", options.status);
4007
+ if (options?.type) params.set("type", options.type);
4008
+ if (options?.walletId) params.set("walletId", options.walletId);
4009
+ if (options?.limit) params.set("limit", String(options.limit));
4010
+ if (options?.offset) params.set("offset", String(options.offset));
4011
+ const query = params.toString();
4012
+ return this.request(
4013
+ "GET",
4014
+ `/v1/requests${query ? `?${query}` : ""}`
4015
+ );
4016
+ }
4017
+ /**
4018
+ * Get a request by ID.
4019
+ */
4020
+ async getRequest(requestId) {
4021
+ return this.request("GET", `/v1/requests/${requestId}`);
4022
+ }
4023
+ /**
4024
+ * Get a human-readable summary of a request.
4025
+ */
4026
+ async getRequestSummary(requestId) {
4027
+ return this.request("GET", `/v1/requests/${requestId}/summary`);
4028
+ }
4029
+ /**
4030
+ * Approve a request. Returns the EIP-712 typed data for the owner to sign.
4031
+ * Only callable by owner (API key holder).
4032
+ */
4033
+ async approveRequest(requestId) {
4034
+ return this.request(
4035
+ "POST",
4036
+ `/v1/requests/${requestId}/approve`
4037
+ );
4038
+ }
4039
+ /**
4040
+ * Deny a request with an optional reason.
4041
+ * Only callable by owner (API key holder).
4042
+ */
4043
+ async denyRequest(requestId, reason) {
4044
+ return this.request(
4045
+ "POST",
4046
+ `/v1/requests/${requestId}/deny`,
4047
+ reason ? { reason } : void 0
4048
+ );
4049
+ }
4050
+ /**
4051
+ * Execute an approved request by submitting the owner's EIP-712 signature.
4052
+ * Triggers on-chain execution via the bootstrap pipeline.
4053
+ * Only callable by owner (API key holder).
4054
+ */
4055
+ async executeRequest(requestId, signature, txHash, policyId, walletAddress) {
4056
+ const body = { signature };
4057
+ if (txHash) body.txHash = txHash;
4058
+ if (policyId) body.policyId = policyId;
4059
+ if (walletAddress) body.walletAddress = walletAddress;
4060
+ return this.request(
4061
+ "POST",
4062
+ `/v1/requests/${requestId}/execute`,
4063
+ body
4064
+ );
4065
+ }
4066
+ /**
4067
+ * Compile policy constraints for a policy request.
4068
+ * Returns the final constraints that will be bootstrapped after approval,
4069
+ * along with any warnings about clamped/excluded items.
4070
+ *
4071
+ * Use this to show users exactly what they're approving before signing.
4072
+ *
4073
+ * @param requestId - Policy request ID
4074
+ * @returns Compiled policy with finalConstraints, warnings, and diff
4075
+ */
4076
+ async compilePolicyRequest(requestId) {
4077
+ return this.request(
4078
+ "GET",
4079
+ `/v1/requests/${requestId}/compile-policy`
4080
+ );
4081
+ }
4082
+ // ══════════════════════════════════════════════════════════════════════════
3966
4083
  // Convenience Methods
3967
4084
  // ══════════════════════════════════════════════════════════════════════════
3968
4085
  /**
@@ -5032,7 +5149,7 @@ var CloudRuntimeClient = class {
5032
5149
  const walletData = await this.getWalletData();
5033
5150
  const { buildPolicyBootstrapIntent: buildPolicyBootstrapIntent2, generatePolicyId: generatePolicyId2 } = await import("./policyBootstrapBuilder-RJOUS67N.mjs");
5034
5151
  const { buildRegistryBootstrapIntent: buildRegistryBootstrapIntent2, generateProfileId: generateProfileId2 } = await import("./registryBootstrapBuilder-AUWE7EWJ.mjs");
5035
- const { buildV2ConstraintsFromAgent: buildV2ConstraintsFromAgent3 } = await import("./agentConstraintBuilder-CK56UDUI.mjs");
5152
+ const { buildV2ConstraintsFromAgent: buildV2ConstraintsFromAgent3 } = await import("./agentConstraintBuilder-CWXPHBNY.mjs");
5036
5153
  const v2Result = buildV2ConstraintsFromAgent3(params.constraints);
5037
5154
  const policyId = generatePolicyId2(walletData.walletAddress, params.name);
5038
5155
  const venueProfileId = generateProfileId2(`${walletData.walletAddress}`, `venue_${params.name}`);
@@ -5067,6 +5184,8 @@ var CloudRuntimeClient = class {
5067
5184
  nonce,
5068
5185
  policyId,
5069
5186
  root: v2Result.root,
5187
+ dailyCap: v2Result.dailyCapWei,
5188
+ // Policy-level daily cap (dual-cap: capPerTx in leaf + capPerPeriod here)
5070
5189
  delegate: params.delegate ?? this.runtime.defaultDelegate,
5071
5190
  validFor: 3600,
5072
5191
  // 1 hour validity
@@ -6061,7 +6180,7 @@ async function combinedBootstrap(config, runtime) {
6061
6180
  if (constraints.forbidBridges) {
6062
6181
  globalFlags |= GLOBAL_FLAG_NO_BRIDGE;
6063
6182
  }
6064
- const dailyCap = dailyCapWei ?? (constraints.maxDailyUsd ? parseEther2(String(constraints.maxDailyUsd)) : 0n);
6183
+ const dailyCap = dailyCapWei ?? v2Result.dailyCapWei ?? (constraints.maxDailyUsd ? parseEther2(String(constraints.maxDailyUsd)) : 0n);
6065
6184
  const nonce = await runtime.getNonce(walletAddress);
6066
6185
  const currentTimestamp = await runtime.getCurrentTimestamp();
6067
6186
  const needsVendorHeader = constraints.vendorMembershipRequired && constraints.vendorRegistry;
@@ -6180,7 +6299,7 @@ async function createSubWallet(params, runtime) {
6180
6299
  const walletAddress = await runtime.predictWalletAddress(params.parentWallet, salt);
6181
6300
  const isDeployed = await runtime.isWalletDeployed(walletAddress);
6182
6301
  if (!isDeployed) {
6183
- await runtime.deployWallet(params.parentWallet, salt);
6302
+ await runtime.deployWallet(params.parentWallet, salt, params.agentName);
6184
6303
  }
6185
6304
  const constraintData = buildAgentConstraints(
6186
6305
  params.constraints,
@@ -6212,7 +6331,8 @@ async function createSubWallet(params, runtime) {
6212
6331
  if (params.constraints.forbidBridges && !constraintsRequireV3(params.constraints)) {
6213
6332
  globalFlags |= GLOBAL_FLAG_NO_BRIDGE;
6214
6333
  }
6215
- const dailyCapWei = params.constraints.maxDailyUsd ? parseEther3(String(params.constraints.maxDailyUsd)) : 0n;
6334
+ const capValue = params.constraints.capPerPeriod ?? params.constraints.maxDailyUsd;
6335
+ const dailyCapWei = capValue ? parseEther3(String(capValue)) : 0n;
6216
6336
  const bootstrapIntent = buildMinimalPolicyBootstrapIntent({
6217
6337
  wallet: walletAddress,
6218
6338
  chainId: BigInt(runtime.chainId),
@@ -7481,8 +7601,9 @@ function buildPresetSummary(type, description, constraints) {
7481
7601
  if (constraints.allowedRecipients) {
7482
7602
  summary.recipients = constraints.allowedRecipients.map(formatAddress);
7483
7603
  }
7484
- if (constraints.maxDailyUsd) {
7485
- summary.cap = formatUsd(constraints.maxDailyUsd);
7604
+ const capValue = constraints.capPerPeriod ?? constraints.maxDailyUsd;
7605
+ if (capValue) {
7606
+ summary.cap = formatUsd(capValue);
7486
7607
  summary.period = getPeriodName(constraints.periodCode);
7487
7608
  }
7488
7609
  if (constraints.bucketId) {
@@ -7532,6 +7653,7 @@ var SELECTORS = {
7532
7653
  UNISWAP_EXACT_OUTPUT_SINGLE: "0xdb3e2198"
7533
7654
  };
7534
7655
  function tradingAgent(config) {
7656
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7535
7657
  const venueTargets = [config.swapContract];
7536
7658
  const venueSelectors = [...config.swapSelectors ?? []];
7537
7659
  if (config.treasuryReturn) {
@@ -7542,8 +7664,9 @@ function tradingAgent(config) {
7542
7664
  venueSelectors.push(SELECTORS.TRANSFER);
7543
7665
  }
7544
7666
  return {
7545
- maxDailyUsd: config.maxDailyUsd,
7667
+ capPerPeriod: cap,
7546
7668
  allowedRecipients: config.treasuryReturn ? [config.treasuryReturn] : void 0,
7669
+ allowedAssets: config.tokenContract ? [config.tokenContract] : void 0,
7547
7670
  venueTargets,
7548
7671
  venueSelectors,
7549
7672
  // Multi-op format now supports venue validation:
@@ -7561,9 +7684,11 @@ function paymentAgent(config) {
7561
7684
  venueTargets.push(config.tokenContract);
7562
7685
  venueSelectors.push(SELECTORS.TRANSFER);
7563
7686
  }
7687
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7564
7688
  return {
7565
7689
  allowedRecipients: config.vendors,
7566
- maxDailyUsd: config.maxDailyUsd,
7690
+ allowedAssets: config.tokenContract ? [config.tokenContract] : void 0,
7691
+ capPerPeriod: cap,
7567
7692
  venueTargets,
7568
7693
  venueSelectors,
7569
7694
  requireVenue: true
@@ -7571,6 +7696,9 @@ function paymentAgent(config) {
7571
7696
  };
7572
7697
  }
7573
7698
  function treasuryOps(config) {
7699
+ if (config.tokenContracts && config.tokenContracts.length === 0) {
7700
+ throw new Error("treasuryOps: tokenContracts must not be empty when provided");
7701
+ }
7574
7702
  const venueTargets = [...config.protocolContracts];
7575
7703
  const venueSelectors = [...config.protocolSelectors];
7576
7704
  if (config.treasuryAddresses) {
@@ -7581,14 +7709,16 @@ function treasuryOps(config) {
7581
7709
  venueSelectors.push(SELECTORS.TRANSFER);
7582
7710
  venueSelectors.push(SELECTORS.APPROVE);
7583
7711
  }
7712
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7584
7713
  const protocolCount = config.protocolContracts.length;
7585
7714
  const bridgeStatus = config.allowBridges ? "" : ", NO_BRIDGE";
7586
- const description = `Treasury Ops: ${protocolCount} protocols, ${formatUsd(config.maxDailyUsd)}/day${bridgeStatus}`;
7715
+ const description = `Treasury Ops: ${protocolCount} protocols, ${cap ?? "?"}/day${bridgeStatus}`;
7587
7716
  const constraints = {
7588
7717
  description,
7589
7718
  presetType: "treasuryOps",
7590
- maxDailyUsd: config.maxDailyUsd,
7719
+ capPerPeriod: cap,
7591
7720
  allowedRecipients: config.treasuryAddresses,
7721
+ allowedAssets: config.tokenContracts,
7592
7722
  venueTargets,
7593
7723
  venueSelectors,
7594
7724
  // Multi-op format now supports venue validation:
@@ -7602,6 +7732,9 @@ function treasuryOps(config) {
7602
7732
  return constraints;
7603
7733
  }
7604
7734
  function lendingOps(config) {
7735
+ if (!config.tokenContracts || config.tokenContracts.length === 0) {
7736
+ throw new Error("lendingOps requires at least one token contract");
7737
+ }
7605
7738
  const lendingSelectors = config.lendingSelectors ?? [
7606
7739
  SELECTORS.AAVE_SUPPLY,
7607
7740
  SELECTORS.AAVE_WITHDRAW,
@@ -7615,17 +7748,19 @@ function lendingOps(config) {
7615
7748
  venueSelectors.push(SELECTORS.APPROVE);
7616
7749
  venueSelectors.push(SELECTORS.TRANSFER);
7617
7750
  }
7751
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7618
7752
  const tokenCount = config.tokenContracts?.length ?? 0;
7619
7753
  const bridgeStatus = config.allowBridges ? "" : ", NO_BRIDGE";
7620
- const description = `Lending Ops: ${tokenCount} tokens, ${formatUsd(config.maxDailyUsd)}/day${bridgeStatus}`;
7754
+ const description = `Lending Ops: ${tokenCount} tokens, ${cap ?? "?"}/day${bridgeStatus}`;
7621
7755
  const constraints = {
7622
7756
  description,
7623
7757
  presetType: "lendingOps",
7624
- maxDailyUsd: config.maxDailyUsd,
7758
+ capPerPeriod: cap,
7625
7759
  venueTargets,
7626
7760
  venueSelectors,
7627
7761
  requireVenue: true,
7628
- forbidBridges: !config.allowBridges
7762
+ forbidBridges: !config.allowBridges,
7763
+ allowedAssets: config.tokenContracts
7629
7764
  };
7630
7765
  logPresetSummary(buildPresetSummary("Lending Ops", description, constraints));
7631
7766
  return constraints;
@@ -7633,13 +7768,14 @@ function lendingOps(config) {
7633
7768
  function stablecoinTransfer(config) {
7634
7769
  const venueTargets = [...config.stablecoins];
7635
7770
  const venueSelectors = [SELECTORS.TRANSFER];
7771
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7636
7772
  const recipientCount = config.recipients.length;
7637
7773
  const stablecoinCount = config.stablecoins.length;
7638
- const description = `Stablecoin Transfer: ${recipientCount} recipients, ${stablecoinCount} stablecoins, ${formatUsd(config.maxDailyUsd)}/day`;
7774
+ const description = `Stablecoin Transfer: ${recipientCount} recipients, ${stablecoinCount} stablecoins, ${cap ?? "?"}/day`;
7639
7775
  const constraints = {
7640
7776
  description,
7641
7777
  presetType: "stablecoinTransfer",
7642
- maxDailyUsd: config.maxDailyUsd,
7778
+ capPerPeriod: cap,
7643
7779
  allowedRecipients: config.recipients,
7644
7780
  allowedAssets: config.stablecoins,
7645
7781
  venueTargets,
@@ -7669,15 +7805,15 @@ function payroll(config) {
7669
7805
  venueTargets.push(config.tokenContract);
7670
7806
  venueSelectors.push(SELECTORS.TRANSFER);
7671
7807
  }
7808
+ const cap = config.capPerPeriod ?? config.maxMonthlyUsd;
7672
7809
  const employeeCount = config.employees.length;
7673
- const description = `Payroll: ${employeeCount} employees, ${formatUsd(config.maxMonthlyUsd)}/month`;
7810
+ const description = `Payroll: ${employeeCount} employees, ${cap ?? "?"}/month`;
7674
7811
  const constraints = {
7675
7812
  description,
7676
7813
  presetType: "payroll",
7677
7814
  allowedRecipients: config.employees,
7678
7815
  allowedAssets,
7679
- // Use maxMonthlyUsd directly as the cap value with PERIOD_MONTH30
7680
- maxDailyUsd: config.maxMonthlyUsd,
7816
+ capPerPeriod: cap,
7681
7817
  periodCode: PERIOD_MONTH30,
7682
7818
  periodOffsetMinutes: 0,
7683
7819
  // UTC
@@ -7706,12 +7842,13 @@ function transferOnly(config) {
7706
7842
  venueTargets.push(config.tokenContract);
7707
7843
  venueSelectors.push(SELECTORS.TRANSFER);
7708
7844
  }
7845
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7709
7846
  const recipientCount = config.recipients.length;
7710
- const description = `Transfer Only: ${recipientCount} recipients, ${formatUsd(config.maxDailyUsd)}/day`;
7847
+ const description = `Transfer Only: ${recipientCount} recipients, ${cap ?? "?"}/day`;
7711
7848
  const constraints = {
7712
7849
  description,
7713
7850
  presetType: "transferOnly",
7714
- maxDailyUsd: config.maxDailyUsd,
7851
+ capPerPeriod: cap,
7715
7852
  allowedRecipients: config.recipients,
7716
7853
  allowedAssets,
7717
7854
  venueTargets,
@@ -7729,15 +7866,15 @@ function marketingBucket(config) {
7729
7866
  venueSelectors.push(SELECTORS.TRANSFER);
7730
7867
  }
7731
7868
  const bucketIdHex = config.bucketId.startsWith("0x") && config.bucketId.length === 66 ? config.bucketId : keccak2569(toHex3(config.bucketId));
7869
+ const cap = config.capPerPeriod ?? config.maxMonthlyUsd;
7732
7870
  const recipientCount = config.recipients.length;
7733
7871
  const bucketName = typeof config.bucketId === "string" && !config.bucketId.startsWith("0x") ? config.bucketId : bucketIdHex.slice(0, 10) + "...";
7734
- const description = `Marketing: ${recipientCount} vendors share ${formatUsd(config.maxMonthlyUsd)}/month`;
7872
+ const description = `Marketing: ${recipientCount} vendors share ${cap ?? "?"}/month`;
7735
7873
  const constraints = {
7736
7874
  description,
7737
7875
  presetType: "marketingBucket",
7738
7876
  allowedRecipients: config.recipients,
7739
- // Use maxMonthlyUsd as the cap with PERIOD_MONTH30
7740
- maxDailyUsd: config.maxMonthlyUsd,
7877
+ capPerPeriod: cap,
7741
7878
  periodCode: PERIOD_MONTH30,
7742
7879
  periodOffsetMinutes: 0,
7743
7880
  bucketId: bucketIdHex,
@@ -7757,13 +7894,14 @@ function vendorCard(config) {
7757
7894
  }
7758
7895
  const vendorGroupIdBigint = typeof config.vendorGroupId === "bigint" ? config.vendorGroupId : BigInt(config.vendorGroupId);
7759
7896
  const hasVendorRegistry = config.vendorRegistry && config.vendorProfileId;
7897
+ const cap = config.capPerPeriod ?? config.maxDailyUsd;
7760
7898
  const vendorProof = hasVendorRegistry ? " (with Merkle proof)" : "";
7761
- const description = `Vendor Card: Dynamic vendor list, ${formatUsd(config.maxDailyUsd)}/day${vendorProof}`;
7899
+ const description = `Vendor Card: Dynamic vendor list, ${cap ?? "?"}/day${vendorProof}`;
7762
7900
  const constraints = {
7763
7901
  description,
7764
7902
  presetType: "vendorCard",
7765
7903
  vendorGroupId: vendorGroupIdBigint,
7766
- maxDailyUsd: config.maxDailyUsd,
7904
+ capPerPeriod: cap,
7767
7905
  periodCode: PERIOD_DAILY,
7768
7906
  periodOffsetMinutes: 0,
7769
7907
  venueTargets: venueTargets.length > 0 ? venueTargets : void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentlayer/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript SDK for building, signing, and verifying intents on Intent Layer",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",