@zyfai/sdk 0.4.1 → 0.5.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/dist/index.d.mts CHANGED
@@ -650,6 +650,17 @@ interface WaitForDepositCreditOptions {
650
650
  /** Maximum wait before throwing `DepositCreditTimeoutError`. */
651
651
  timeoutMs?: number;
652
652
  }
653
+ /** Polling overrides for {@link ZyfaiSDK.waitForAgentDepositIntent}. */
654
+ interface WaitForAgentDepositIntentOptions {
655
+ intervalMs?: number;
656
+ timeoutMs?: number;
657
+ }
658
+ /** Options for {@link ZyfaiSDK.waitForAgentDepositHandover}. */
659
+ interface WaitForAgentDepositHandoverOptions extends WaitForAgentDepositIntentOptions {
660
+ /** When true (default), poll through custody credit after intent completes. */
661
+ waitForCredit?: boolean;
662
+ credit?: WaitForDepositCreditOptions;
663
+ }
653
664
  /** Result of {@link ZyfaiSDK.withdrawFunds}. */
654
665
  interface WithdrawResponse {
655
666
  success: boolean;
@@ -2340,6 +2351,27 @@ declare class ZyfaiSDK {
2340
2351
  getAgentDepositIntentStatus(actionId: string): Promise<{
2341
2352
  data: AgentDepositIntentStatus;
2342
2353
  }>;
2354
+ /**
2355
+ * Poll MCP deposit-intent status until the signing page registers the transfer.
2356
+ *
2357
+ * @group Agent management
2358
+ *
2359
+ * @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
2360
+ * @throws When the intent expires before completion
2361
+ */
2362
+ waitForAgentDepositIntent(actionId: string, options?: WaitForAgentDepositIntentOptions): Promise<AgentDepositIntentStatus>;
2363
+ /**
2364
+ * Wait for MCP signing completion, then optionally through custody credit.
2365
+ *
2366
+ * Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
2367
+ * `createAgentDepositIntent`. Start this poll as soon as the user has the link.
2368
+ *
2369
+ * @group Agent management
2370
+ */
2371
+ waitForAgentDepositHandover(actionId: string, chainId: SupportedChainId, options?: WaitForAgentDepositHandoverOptions): Promise<{
2372
+ intent: AgentDepositIntentStatus;
2373
+ credited?: DepositLifecycleResponse;
2374
+ }>;
2343
2375
  /**
2344
2376
  * Mark intent complete after the user signed on zyf.ai (SIWE session).
2345
2377
  *
package/dist/index.d.ts CHANGED
@@ -650,6 +650,17 @@ interface WaitForDepositCreditOptions {
650
650
  /** Maximum wait before throwing `DepositCreditTimeoutError`. */
651
651
  timeoutMs?: number;
652
652
  }
653
+ /** Polling overrides for {@link ZyfaiSDK.waitForAgentDepositIntent}. */
654
+ interface WaitForAgentDepositIntentOptions {
655
+ intervalMs?: number;
656
+ timeoutMs?: number;
657
+ }
658
+ /** Options for {@link ZyfaiSDK.waitForAgentDepositHandover}. */
659
+ interface WaitForAgentDepositHandoverOptions extends WaitForAgentDepositIntentOptions {
660
+ /** When true (default), poll through custody credit after intent completes. */
661
+ waitForCredit?: boolean;
662
+ credit?: WaitForDepositCreditOptions;
663
+ }
653
664
  /** Result of {@link ZyfaiSDK.withdrawFunds}. */
654
665
  interface WithdrawResponse {
655
666
  success: boolean;
@@ -2340,6 +2351,27 @@ declare class ZyfaiSDK {
2340
2351
  getAgentDepositIntentStatus(actionId: string): Promise<{
2341
2352
  data: AgentDepositIntentStatus;
2342
2353
  }>;
2354
+ /**
2355
+ * Poll MCP deposit-intent status until the signing page registers the transfer.
2356
+ *
2357
+ * @group Agent management
2358
+ *
2359
+ * @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
2360
+ * @throws When the intent expires before completion
2361
+ */
2362
+ waitForAgentDepositIntent(actionId: string, options?: WaitForAgentDepositIntentOptions): Promise<AgentDepositIntentStatus>;
2363
+ /**
2364
+ * Wait for MCP signing completion, then optionally through custody credit.
2365
+ *
2366
+ * Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
2367
+ * `createAgentDepositIntent`. Start this poll as soon as the user has the link.
2368
+ *
2369
+ * @group Agent management
2370
+ */
2371
+ waitForAgentDepositHandover(actionId: string, chainId: SupportedChainId, options?: WaitForAgentDepositHandoverOptions): Promise<{
2372
+ intent: AgentDepositIntentStatus;
2373
+ credited?: DepositLifecycleResponse;
2374
+ }>;
2343
2375
  /**
2344
2376
  * Mark intent complete after the user signed on zyf.ai (SIWE session).
2345
2377
  *
package/dist/index.js CHANGED
@@ -680,6 +680,8 @@ var DEPOSIT_CREDIT_TIMEOUT_MS = {
680
680
  };
681
681
  var getDepositCreditIntervalMs = (chainId) => DEPOSIT_CREDIT_INTERVAL_MS[chainId];
682
682
  var getDepositCreditTimeoutMs = (chainId) => DEPOSIT_CREDIT_TIMEOUT_MS[chainId];
683
+ var AGENT_DEPOSIT_INTENT_INTERVAL_MS = 1500;
684
+ var AGENT_DEPOSIT_INTENT_TIMEOUT_MS = 30 * 60 * 1e3;
683
685
  var formatMinPortfolioLabel = (raw, decimals, symbol) => {
684
686
  const base2 = 10n ** BigInt(decimals);
685
687
  const whole = raw / base2;
@@ -1664,6 +1666,12 @@ var DepositCreditTimeoutError = class extends Error {
1664
1666
  this.name = "DepositCreditTimeoutError";
1665
1667
  }
1666
1668
  };
1669
+ var AgentDepositIntentTimeoutError = class extends Error {
1670
+ constructor(actionId) {
1671
+ super(`Timed out waiting for agent deposit intent ${actionId} to complete`);
1672
+ this.name = "AgentDepositIntentTimeoutError";
1673
+ }
1674
+ };
1667
1675
  var MANAGED_ASSETS = ["USDC", "WETH", "EURC", "NVDAc"];
1668
1676
  var _ZyfaiSDK = class _ZyfaiSDK {
1669
1677
  /**
@@ -4982,6 +4990,56 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4982
4990
  ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
4983
4991
  );
4984
4992
  }
4993
+ /**
4994
+ * Poll MCP deposit-intent status until the signing page registers the transfer.
4995
+ *
4996
+ * @group Agent management
4997
+ *
4998
+ * @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
4999
+ * @throws When the intent expires before completion
5000
+ */
5001
+ async waitForAgentDepositIntent(actionId, options) {
5002
+ if (!actionId) {
5003
+ throw new Error("actionId is required");
5004
+ }
5005
+ const intervalMs = options?.intervalMs ?? AGENT_DEPOSIT_INTENT_INTERVAL_MS;
5006
+ const timeoutMs = options?.timeoutMs ?? AGENT_DEPOSIT_INTENT_TIMEOUT_MS;
5007
+ const started = Date.now();
5008
+ while (Date.now() - started < timeoutMs) {
5009
+ const { data } = await this.getAgentDepositIntentStatus(actionId);
5010
+ if (data.status === "completed") {
5011
+ return data;
5012
+ }
5013
+ if (data.status === "expired") {
5014
+ throw new Error(`Agent deposit intent ${actionId} expired`);
5015
+ }
5016
+ if (Date.now() - started >= timeoutMs) {
5017
+ break;
5018
+ }
5019
+ await sleep(intervalMs);
5020
+ }
5021
+ throw new AgentDepositIntentTimeoutError(actionId);
5022
+ }
5023
+ /**
5024
+ * Wait for MCP signing completion, then optionally through custody credit.
5025
+ *
5026
+ * Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
5027
+ * `createAgentDepositIntent`. Start this poll as soon as the user has the link.
5028
+ *
5029
+ * @group Agent management
5030
+ */
5031
+ async waitForAgentDepositHandover(actionId, chainId, options) {
5032
+ const intent = await this.waitForAgentDepositIntent(actionId, options);
5033
+ if (options?.waitForCredit === false || !intent.depositId) {
5034
+ return { intent };
5035
+ }
5036
+ const credited = await this.waitForDepositCredit(
5037
+ intent.depositId,
5038
+ chainId,
5039
+ options?.credit
5040
+ );
5041
+ return { intent, credited };
5042
+ }
4985
5043
  /**
4986
5044
  * Mark intent complete after the user signed on zyf.ai (SIWE session).
4987
5045
  *
package/dist/index.mjs CHANGED
@@ -612,6 +612,8 @@ var DEPOSIT_CREDIT_TIMEOUT_MS = {
612
612
  };
613
613
  var getDepositCreditIntervalMs = (chainId) => DEPOSIT_CREDIT_INTERVAL_MS[chainId];
614
614
  var getDepositCreditTimeoutMs = (chainId) => DEPOSIT_CREDIT_TIMEOUT_MS[chainId];
615
+ var AGENT_DEPOSIT_INTENT_INTERVAL_MS = 1500;
616
+ var AGENT_DEPOSIT_INTENT_TIMEOUT_MS = 30 * 60 * 1e3;
615
617
  var formatMinPortfolioLabel = (raw, decimals, symbol) => {
616
618
  const base2 = 10n ** BigInt(decimals);
617
619
  const whole = raw / base2;
@@ -1616,6 +1618,12 @@ var DepositCreditTimeoutError = class extends Error {
1616
1618
  this.name = "DepositCreditTimeoutError";
1617
1619
  }
1618
1620
  };
1621
+ var AgentDepositIntentTimeoutError = class extends Error {
1622
+ constructor(actionId) {
1623
+ super(`Timed out waiting for agent deposit intent ${actionId} to complete`);
1624
+ this.name = "AgentDepositIntentTimeoutError";
1625
+ }
1626
+ };
1619
1627
  var MANAGED_ASSETS = ["USDC", "WETH", "EURC", "NVDAc"];
1620
1628
  var _ZyfaiSDK = class _ZyfaiSDK {
1621
1629
  /**
@@ -4934,6 +4942,56 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4934
4942
  ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
4935
4943
  );
4936
4944
  }
4945
+ /**
4946
+ * Poll MCP deposit-intent status until the signing page registers the transfer.
4947
+ *
4948
+ * @group Agent management
4949
+ *
4950
+ * @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
4951
+ * @throws When the intent expires before completion
4952
+ */
4953
+ async waitForAgentDepositIntent(actionId, options) {
4954
+ if (!actionId) {
4955
+ throw new Error("actionId is required");
4956
+ }
4957
+ const intervalMs = options?.intervalMs ?? AGENT_DEPOSIT_INTENT_INTERVAL_MS;
4958
+ const timeoutMs = options?.timeoutMs ?? AGENT_DEPOSIT_INTENT_TIMEOUT_MS;
4959
+ const started = Date.now();
4960
+ while (Date.now() - started < timeoutMs) {
4961
+ const { data } = await this.getAgentDepositIntentStatus(actionId);
4962
+ if (data.status === "completed") {
4963
+ return data;
4964
+ }
4965
+ if (data.status === "expired") {
4966
+ throw new Error(`Agent deposit intent ${actionId} expired`);
4967
+ }
4968
+ if (Date.now() - started >= timeoutMs) {
4969
+ break;
4970
+ }
4971
+ await sleep(intervalMs);
4972
+ }
4973
+ throw new AgentDepositIntentTimeoutError(actionId);
4974
+ }
4975
+ /**
4976
+ * Wait for MCP signing completion, then optionally through custody credit.
4977
+ *
4978
+ * Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
4979
+ * `createAgentDepositIntent`. Start this poll as soon as the user has the link.
4980
+ *
4981
+ * @group Agent management
4982
+ */
4983
+ async waitForAgentDepositHandover(actionId, chainId, options) {
4984
+ const intent = await this.waitForAgentDepositIntent(actionId, options);
4985
+ if (options?.waitForCredit === false || !intent.depositId) {
4986
+ return { intent };
4987
+ }
4988
+ const credited = await this.waitForDepositCredit(
4989
+ intent.depositId,
4990
+ chainId,
4991
+ options?.credit
4992
+ );
4993
+ return { intent, credited };
4994
+ }
4937
4995
  /**
4938
4996
  * Mark intent complete after the user signed on zyf.ai (SIWE session).
4939
4997
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript SDK for self-custodial Zyfai yield agents: discover DeFi opportunities and manage deposits, withdrawals, positions, and strategies across Ethereum, Base, and Arbitrum",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",