@owney/sdk 0.7.22-beta.5 → 0.7.22-beta.6

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.
@@ -251,8 +251,20 @@ async function depositSponsored(input) {
251
251
  }
252
252
  return { txHash, vault };
253
253
  }
254
+ var PROCEEDS_POLL_ATTEMPTS = 6;
255
+ var PROCEEDS_POLL_INTERVAL_MS = 1500;
256
+ var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
257
+ async function awaitProceeds(chain, smartAccount, sleep) {
258
+ for (let attempt = 0; attempt < PROCEEDS_POLL_ATTEMPTS; attempt += 1) {
259
+ const balance = await chain.usdcBalanceOf(smartAccount);
260
+ if (balance > 0n) return balance;
261
+ if (attempt < PROCEEDS_POLL_ATTEMPTS - 1) await sleep(PROCEEDS_POLL_INTERVAL_MS);
262
+ }
263
+ return 0n;
264
+ }
254
265
  async function withdrawSponsored(input) {
255
266
  const { api, chain, wallet, amount } = input;
267
+ const sleep = input.sleep ?? defaultSleep;
256
268
  const registered = await api.getVault(wallet.smartAccountAddress);
257
269
  if (!registered.userVaultAddress) {
258
270
  throw new Error("SurfLiquid has no vault registered for this wallet");
@@ -272,7 +284,7 @@ async function withdrawSponsored(input) {
272
284
  return { txHash: sweepHash, amount: stranded.toString() };
273
285
  }
274
286
  try {
275
- const proceeds = await chain.usdcBalanceOf(wallet.smartAccountAddress);
287
+ const proceeds = await awaitProceeds(chain, wallet.smartAccountAddress, sleep);
276
288
  if (proceeds === 0n) return { txHash: withdrawHash, amount: "0" };
277
289
  const sweepHash = await wallet.sendCalls(
278
290
  buildSweepCalls({ owner: wallet.ownerAddress, amount: proceeds })
package/dist/index.cjs CHANGED
@@ -884,8 +884,17 @@ async function depositSponsored(input) {
884
884
  }
885
885
  return { txHash, vault };
886
886
  }
887
+ async function awaitProceeds(chain, smartAccount, sleep) {
888
+ for (let attempt = 0; attempt < PROCEEDS_POLL_ATTEMPTS; attempt += 1) {
889
+ const balance = await chain.usdcBalanceOf(smartAccount);
890
+ if (balance > 0n) return balance;
891
+ if (attempt < PROCEEDS_POLL_ATTEMPTS - 1) await sleep(PROCEEDS_POLL_INTERVAL_MS);
892
+ }
893
+ return 0n;
894
+ }
887
895
  async function withdrawSponsored(input) {
888
896
  const { api, chain, wallet, amount } = input;
897
+ const sleep = input.sleep ?? defaultSleep;
889
898
  const registered = await api.getVault(wallet.smartAccountAddress);
890
899
  if (!registered.userVaultAddress) {
891
900
  throw new Error("SurfLiquid has no vault registered for this wallet");
@@ -905,7 +914,7 @@ async function withdrawSponsored(input) {
905
914
  return { txHash: sweepHash, amount: stranded.toString() };
906
915
  }
907
916
  try {
908
- const proceeds = await chain.usdcBalanceOf(wallet.smartAccountAddress);
917
+ const proceeds = await awaitProceeds(chain, wallet.smartAccountAddress, sleep);
909
918
  if (proceeds === 0n) return { txHash: withdrawHash, amount: "0" };
910
919
  const sweepHash = await wallet.sendCalls(
911
920
  buildSweepCalls({ owner: wallet.ownerAddress, amount: proceeds })
@@ -917,7 +926,7 @@ async function withdrawSponsored(input) {
917
926
  );
918
927
  }
919
928
  }
920
- var import_viem8, SubmittedError, VaultNotSponsorableError;
929
+ var import_viem8, SubmittedError, VaultNotSponsorableError, PROCEEDS_POLL_ATTEMPTS, PROCEEDS_POLL_INTERVAL_MS, defaultSleep;
921
930
  var init_surfliquid_sponsorship = __esm({
922
931
  "src/agents/surfliquid/surfliquid.sponsorship.ts"() {
923
932
  "use strict";
@@ -939,6 +948,9 @@ var init_surfliquid_sponsorship = __esm({
939
948
  this.name = "VaultNotSponsorableError";
940
949
  }
941
950
  };
951
+ PROCEEDS_POLL_ATTEMPTS = 6;
952
+ PROCEEDS_POLL_INTERVAL_MS = 1500;
953
+ defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
942
954
  }
943
955
  });
944
956
 
@@ -1125,19 +1137,10 @@ async function createSponsoredWallet(input) {
1125
1137
  message: typedData.message
1126
1138
  }),
1127
1139
  // The smart account signs (ERC-1271), not the EOA: SurfLiquid's SIWE session must
1128
- // be the vault owner, which is the smart account. Safe wraps this as a SafeMessage
1129
- // EIP-712 signature the deployed account verifies via isValidSignature.
1140
+ // be the vault owner, which is the smart account. While the account is still
1141
+ // counterfactual, Safe/permissionless wraps this as an EIP-6492 signature SurfLiquid
1142
+ // accepts; the first deposit's userOp deploys the account via its initCode.
1130
1143
  signMessage: (message) => account.signMessage({ message }),
1131
- // Deploy-on-connect: the account is counterfactual until its first userOp, but SIWE
1132
- // (isValidSignature) needs on-chain code. A no-op self-call carries the factory
1133
- // initCode and deploys it. Idempotency is the caller's (it checks isDeployed first).
1134
- deployAccount: async () => {
1135
- const userOpHash = await smartAccountClient.sendUserOperation({
1136
- calls: [{ to: account.address, value: 0n, data: "0x" }]
1137
- });
1138
- const receipt = await smartAccountClient.waitForUserOperationReceipt({ hash: userOpHash });
1139
- return receipt.receipt.transactionHash;
1140
- },
1141
1144
  sendCalls: async (calls) => {
1142
1145
  const userOpHash = await smartAccountClient.sendUserOperation({
1143
1146
  calls: calls.map((c) => ({ to: c.to, data: c.data, value: 0n }))
@@ -1256,10 +1259,6 @@ var init_surfliquid_agent = __esm({
1256
1259
  this.smartAccountAddress = smartAccountAddress;
1257
1260
  const broker = this.brokerFor(smartAccountAddress);
1258
1261
  if (!shouldForce && broker.hasSession()) return broker;
1259
- const { createSponsoredChain: createSponsoredChain2 } = await Promise.resolve().then(() => (init_surfliquid_smart_account(), surfliquid_smart_account_exports));
1260
- if (!await createSponsoredChain2(this.config.rpcUrl).isDeployed(smartAccountAddress)) {
1261
- await wallet.deployAccount();
1262
- }
1263
1262
  const message = await broker.nonce();
1264
1263
  const signature = await wallet.signMessage(message);
1265
1264
  await broker.login(message, signature);
@@ -1307,10 +1306,10 @@ var init_surfliquid_agent = __esm({
1307
1306
  this.brokerWallet = null;
1308
1307
  this.smartAccountAddress = null;
1309
1308
  }
1310
- // The SDK orchestrator already marks the agent active and sets the chain. SurfLiquid
1311
- // establishes its session lazily — on the first read of a deployed account, or on
1312
- // deposit — so merely connecting a wallet never prompts for a signature.
1313
- async activateAgent(_state, _chainId) {
1309
+ // One signature on connect: SIWE the counterfactual smart account (EIP-6492). The
1310
+ // account isn't deployed and no funds move — the first deposit's userOp deploys it.
1311
+ async activateAgent(state, _chainId) {
1312
+ await this.connect(state);
1314
1313
  }
1315
1314
  /** A counterfactual account owns no vault and can't be a SIWE signer yet — reads answer empty. */
1316
1315
  async isSmartAccountDeployed(state) {
package/dist/index.js CHANGED
@@ -3036,7 +3036,7 @@ var OwneySDK = class {
3036
3036
  }
3037
3037
  if (agentId === "surfliquid") {
3038
3038
  if (!key2) return null;
3039
- const { SurfLiquidAgent } = await import("./surfliquid.agent-YC4VDPPF.js");
3039
+ const { SurfLiquidAgent } = await import("./surfliquid.agent-2XTX6I4E.js");
3040
3040
  return new SurfLiquidAgent({
3041
3041
  apiKey: this.apiKey,
3042
3042
  routingApiBaseUrl: this.routingApiBaseUrl
@@ -13,7 +13,7 @@ import {
13
13
  readStuckBalance,
14
14
  sweepStuckBalance,
15
15
  withdrawSponsored
16
- } from "./chunk-T5YJVIQG.js";
16
+ } from "./chunk-CWGCQLB2.js";
17
17
  import "./chunk-AURO3C3R.js";
18
18
 
19
19
  // src/agents/surfliquid/surfliquid.session-store.ts
@@ -543,10 +543,6 @@ var SurfLiquidAgent = class {
543
543
  this.smartAccountAddress = smartAccountAddress;
544
544
  const broker = this.brokerFor(smartAccountAddress);
545
545
  if (!shouldForce && broker.hasSession()) return broker;
546
- const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
547
- if (!await createSponsoredChain(this.config.rpcUrl).isDeployed(smartAccountAddress)) {
548
- await wallet.deployAccount();
549
- }
550
546
  const message = await broker.nonce();
551
547
  const signature = await wallet.signMessage(message);
552
548
  await broker.login(message, signature);
@@ -578,7 +574,7 @@ var SurfLiquidAgent = class {
578
574
  }
579
575
  }
580
576
  async sponsoredWallet(state) {
581
- const { createSponsoredWallet } = await import("./surfliquid.smart-account-YV3PLZ72.js");
577
+ const { createSponsoredWallet } = await import("./surfliquid.smart-account-JHW6VYLJ.js");
582
578
  return createSponsoredWallet({
583
579
  provider: state.provider,
584
580
  ownerAddress: state.walletAddress,
@@ -594,17 +590,17 @@ var SurfLiquidAgent = class {
594
590
  this.brokerWallet = null;
595
591
  this.smartAccountAddress = null;
596
592
  }
597
- // The SDK orchestrator already marks the agent active and sets the chain. SurfLiquid
598
- // establishes its session lazily — on the first read of a deployed account, or on
599
- // deposit — so merely connecting a wallet never prompts for a signature.
600
- async activateAgent(_state, _chainId) {
593
+ // One signature on connect: SIWE the counterfactual smart account (EIP-6492). The
594
+ // account isn't deployed and no funds move — the first deposit's userOp deploys it.
595
+ async activateAgent(state, _chainId) {
596
+ await this.connect(state);
601
597
  }
602
598
  /** A counterfactual account owns no vault and can't be a SIWE signer yet — reads answer empty. */
603
599
  async isSmartAccountDeployed(state) {
604
600
  if (this.broker?.hasSession()) return true;
605
601
  const wallet = await this.sponsoredWallet(state);
606
602
  this.smartAccountAddress = wallet.smartAccountAddress;
607
- const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
603
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-JHW6VYLJ.js");
608
604
  return createSponsoredChain(this.config.rpcUrl).isDeployed(
609
605
  wallet.smartAccountAddress
610
606
  );
@@ -613,7 +609,7 @@ var SurfLiquidAgent = class {
613
609
  async deposit(state, _chainId, amount, _asset, _depositCallback) {
614
610
  const broker = await this.connect(state);
615
611
  const wallet = await this.sponsoredWallet(state);
616
- const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
612
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-JHW6VYLJ.js");
617
613
  try {
618
614
  const { txHash, vault } = await this.withSession(
619
615
  state,
@@ -628,7 +624,7 @@ var SurfLiquidAgent = class {
628
624
  async withdraw(state, _chainId, _token, amount) {
629
625
  const broker = await this.connect(state);
630
626
  const wallet = await this.sponsoredWallet(state);
631
- const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
627
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-JHW6VYLJ.js");
632
628
  try {
633
629
  const result = await this.withSession(
634
630
  state,
@@ -648,14 +644,14 @@ var SurfLiquidAgent = class {
648
644
  /** Funds a prior withdrawal's sweep left in the smart account (never reached the EOA). No session needed — pure read. */
649
645
  async getStuckBalance(state) {
650
646
  const wallet = await this.sponsoredWallet(state);
651
- const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
647
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-JHW6VYLJ.js");
652
648
  const amount = await readStuckBalance({ chain: createSponsoredChain(this.config.rpcUrl), wallet });
653
649
  return { amount: amount.toString(), smartAccountAddress: wallet.smartAccountAddress };
654
650
  }
655
651
  /** Sweep the stranded balance to the owner's EOA — one sponsored userOp, one signature. */
656
652
  async recoverStuckBalance(state) {
657
653
  const wallet = await this.sponsoredWallet(state);
658
- const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
654
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-JHW6VYLJ.js");
659
655
  try {
660
656
  const { txHash, amount } = await sweepStuckBalance({ chain: createSponsoredChain(this.config.rpcUrl), wallet });
661
657
  return { txHash, type: "full", amount: amount.toString() };
@@ -6,7 +6,7 @@ import {
6
6
  SURFLIQUID_VAULT_ABI,
7
7
  SubmittedError,
8
8
  USDC_ABI
9
- } from "./chunk-T5YJVIQG.js";
9
+ } from "./chunk-CWGCQLB2.js";
10
10
  import {
11
11
  readTokenMeta
12
12
  } from "./chunk-AURO3C3R.js";
@@ -114,19 +114,10 @@ async function createSponsoredWallet(input) {
114
114
  message: typedData.message
115
115
  }),
116
116
  // The smart account signs (ERC-1271), not the EOA: SurfLiquid's SIWE session must
117
- // be the vault owner, which is the smart account. Safe wraps this as a SafeMessage
118
- // EIP-712 signature the deployed account verifies via isValidSignature.
117
+ // be the vault owner, which is the smart account. While the account is still
118
+ // counterfactual, Safe/permissionless wraps this as an EIP-6492 signature SurfLiquid
119
+ // accepts; the first deposit's userOp deploys the account via its initCode.
119
120
  signMessage: (message) => account.signMessage({ message }),
120
- // Deploy-on-connect: the account is counterfactual until its first userOp, but SIWE
121
- // (isValidSignature) needs on-chain code. A no-op self-call carries the factory
122
- // initCode and deploys it. Idempotency is the caller's (it checks isDeployed first).
123
- deployAccount: async () => {
124
- const userOpHash = await smartAccountClient.sendUserOperation({
125
- calls: [{ to: account.address, value: 0n, data: "0x" }]
126
- });
127
- const receipt = await smartAccountClient.waitForUserOperationReceipt({ hash: userOpHash });
128
- return receipt.receipt.transactionHash;
129
- },
130
121
  sendCalls: async (calls) => {
131
122
  const userOpHash = await smartAccountClient.sendUserOperation({
132
123
  calls: calls.map((c) => ({ to: c.to, data: c.data, value: 0n }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.22-beta.5",
3
+ "version": "0.7.22-beta.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",