@owney/sdk 0.7.22-beta.2 → 0.7.22-beta.4

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.
@@ -138,7 +138,7 @@ var VaultNotSponsorableError = class extends Error {
138
138
  }
139
139
  };
140
140
  async function resolveVault(ctx) {
141
- const registered = await ctx.api.getVault(ctx.wallet.ownerAddress);
141
+ const registered = await ctx.api.getVault(ctx.wallet.smartAccountAddress);
142
142
  const smartAccount = ctx.wallet.smartAccountAddress;
143
143
  if (!registered.userVaultAddress) {
144
144
  const salt2 = registered.deploymentSalt ?? (await ctx.api.prepare(SURFLIQUID_CHAIN_ID)).salt;
@@ -253,7 +253,7 @@ async function depositSponsored(input) {
253
253
  }
254
254
  async function withdrawSponsored(input) {
255
255
  const { api, chain, wallet, amount } = input;
256
- const registered = await api.getVault(wallet.ownerAddress);
256
+ const registered = await api.getVault(wallet.smartAccountAddress);
257
257
  if (!registered.userVaultAddress) {
258
258
  throw new Error("SurfLiquid has no vault registered for this wallet");
259
259
  }
package/dist/index.cjs CHANGED
@@ -388,7 +388,7 @@ function normalizeSupportedAssets(json, chainId) {
388
388
  function createSurfBroker(options) {
389
389
  const fetchImpl = options.fetchImpl ?? fetch;
390
390
  const now = options.now ?? Date.now;
391
- const base5 = `${options.routingApiBaseUrl.replace(/\/$/, "")}/api/v1/surf`;
391
+ const base4 = `${options.routingApiBaseUrl.replace(/\/$/, "")}/api/v1/surf`;
392
392
  const wallet = options.walletAddress;
393
393
  let session = readSurfSession(options.apiKey, wallet);
394
394
  const vaultMemo = /* @__PURE__ */ new Map();
@@ -407,7 +407,7 @@ function createSurfBroker(options) {
407
407
  if (options.origin) headers["origin"] = options.origin;
408
408
  let response;
409
409
  try {
410
- response = await fetchImpl(`${base5}${path}`, {
410
+ response = await fetchImpl(`${base4}${path}`, {
411
411
  method,
412
412
  headers,
413
413
  body: body === void 0 ? void 0 : JSON.stringify(body),
@@ -526,8 +526,8 @@ var init_surfliquid_broker = __esm({
526
526
  // src/agents/surfliquid/surfliquid.mapper.ts
527
527
  function mapMessage(message) {
528
528
  const action = SURFLIQUID_ACTION_MAP[message.transactionType];
529
- if (!action) return null;
530
- return {
529
+ if (!action) return [];
530
+ const base4 = {
531
531
  agent: "surfliquid",
532
532
  action,
533
533
  date: message.timestamp,
@@ -543,9 +543,27 @@ function mapMessage(message) {
543
543
  ],
544
544
  rebalanceLog: []
545
545
  };
546
+ if (DEPOSIT_TRANSACTION_TYPES.has(message.transactionType) && message.toVault?.name && message.amount != null) {
547
+ return [
548
+ base4,
549
+ {
550
+ ...base4,
551
+ action: "Deposit",
552
+ positions: [
553
+ {
554
+ protocol: SURFLIQUID_PROTOCOL,
555
+ pool: message.toVault.name,
556
+ tokenSymbol: message.token ?? void 0,
557
+ amount: String(message.amount)
558
+ }
559
+ ]
560
+ }
561
+ ];
562
+ }
563
+ return [base4];
546
564
  }
547
565
  function mapHistory(result, _chainId) {
548
- const data = result.messages.map(mapMessage).filter((entry) => entry !== null);
566
+ const data = result.messages.flatMap(mapMessage);
549
567
  const hasMore = result.page < result.pages;
550
568
  return {
551
569
  data,
@@ -620,11 +638,17 @@ function mapUserProfile2(vault, address) {
620
638
  protocols: ["SurfLiquid"]
621
639
  };
622
640
  }
623
- var APY_WINDOW_KEY;
641
+ var SURFLIQUID_PROTOCOL, DEPOSIT_TRANSACTION_TYPES, APY_WINDOW_KEY;
624
642
  var init_surfliquid_mapper = __esm({
625
643
  "src/agents/surfliquid/surfliquid.mapper.ts"() {
626
644
  "use strict";
627
645
  init_surfliquid_constants();
646
+ SURFLIQUID_PROTOCOL = "Morpho";
647
+ DEPOSIT_TRANSACTION_TYPES = /* @__PURE__ */ new Set([
648
+ "INITIAL_DEPOSIT",
649
+ "DEPOSIT",
650
+ "USER_DEPOSIT"
651
+ ]);
628
652
  APY_WINDOW_KEY = {
629
653
  "7D": "apy7d",
630
654
  "14D": "apy14d",
@@ -736,7 +760,7 @@ var init_surfliquid_calls = __esm({
736
760
 
737
761
  // src/agents/surfliquid/surfliquid.sponsorship.ts
738
762
  async function resolveVault(ctx) {
739
- const registered = await ctx.api.getVault(ctx.wallet.ownerAddress);
763
+ const registered = await ctx.api.getVault(ctx.wallet.smartAccountAddress);
740
764
  const smartAccount = ctx.wallet.smartAccountAddress;
741
765
  if (!registered.userVaultAddress) {
742
766
  const salt2 = registered.deploymentSalt ?? (await ctx.api.prepare(SURFLIQUID_CHAIN_ID)).salt;
@@ -851,7 +875,7 @@ async function depositSponsored(input) {
851
875
  }
852
876
  async function withdrawSponsored(input) {
853
877
  const { api, chain, wallet, amount } = input;
854
- const registered = await api.getVault(wallet.ownerAddress);
878
+ const registered = await api.getVault(wallet.smartAccountAddress);
855
879
  if (!registered.userVaultAddress) {
856
880
  throw new Error("SurfLiquid has no vault registered for this wallet");
857
881
  }
@@ -1053,10 +1077,11 @@ function pinAccount(provider, address) {
1053
1077
  };
1054
1078
  }
1055
1079
  async function createSponsoredWallet(input) {
1056
- const entryPoint = { address: import_account_abstraction.entryPoint08Address, version: "0.8" };
1057
- const account = await (0, import_accounts.toSimpleSmartAccount)({
1080
+ const entryPoint = { address: import_account_abstraction.entryPoint07Address, version: "0.7" };
1081
+ const account = await (0, import_accounts.toSafeSmartAccount)({
1058
1082
  client: publicClientFor(input.rpcUrl),
1059
- owner: pinAccount(input.provider, input.ownerAddress),
1083
+ owners: [pinAccount(input.provider, input.ownerAddress)],
1084
+ version: "1.4.1",
1060
1085
  entryPoint
1061
1086
  });
1062
1087
  const bundlerTransport = (0, import_viem9.http)(sponsorProxyUrl(input.routingApiBaseUrl), {
@@ -1088,6 +1113,20 @@ async function createSponsoredWallet(input) {
1088
1113
  primaryType: typedData.primaryType,
1089
1114
  message: typedData.message
1090
1115
  }),
1116
+ // The smart account signs (ERC-1271), not the EOA: SurfLiquid's SIWE session must
1117
+ // be the vault owner, which is the smart account. Safe wraps this as a SafeMessage
1118
+ // EIP-712 signature the deployed account verifies via isValidSignature.
1119
+ signMessage: (message) => account.signMessage({ message }),
1120
+ // Deploy-on-connect: the account is counterfactual until its first userOp, but SIWE
1121
+ // (isValidSignature) needs on-chain code. A no-op self-call carries the factory
1122
+ // initCode and deploys it. Idempotency is the caller's (it checks isDeployed first).
1123
+ deployAccount: async () => {
1124
+ const userOpHash = await smartAccountClient.sendUserOperation({
1125
+ calls: [{ to: account.address, value: 0n, data: "0x" }]
1126
+ });
1127
+ const receipt = await smartAccountClient.waitForUserOperationReceipt({ hash: userOpHash });
1128
+ return receipt.receipt.transactionHash;
1129
+ },
1091
1130
  sendCalls: async (calls) => {
1092
1131
  const userOpHash = await smartAccountClient.sendUserOperation({
1093
1132
  calls: calls.map((c) => ({ to: c.to, data: c.data, value: 0n }))
@@ -1142,12 +1181,10 @@ function toOwneyError(error) {
1142
1181
  }
1143
1182
  return new OwneyError("SPONSORSHIP_UNAVAILABLE", message, void 0, AGENT_ID2);
1144
1183
  }
1145
- var import_viem10, import_chains3, AGENT_ID2, WALLET_REJECTED_CODE, DISCOVERY_WALLET2, HISTORY_DEFAULT_LIMIT, APY_WINDOW_KEY2, SurfLiquidAgent;
1184
+ var AGENT_ID2, WALLET_REJECTED_CODE, DISCOVERY_WALLET2, HISTORY_DEFAULT_LIMIT, APY_WINDOW_KEY2, SurfLiquidAgent;
1146
1185
  var init_surfliquid_agent = __esm({
1147
1186
  "src/agents/surfliquid/surfliquid.agent.ts"() {
1148
1187
  "use strict";
1149
- import_viem10 = require("viem");
1150
- import_chains3 = require("viem/chains");
1151
1188
  init_errors();
1152
1189
  init_surfliquid_constants();
1153
1190
  init_surfliquid_broker();
@@ -1174,6 +1211,9 @@ var init_surfliquid_agent = __esm({
1174
1211
  supportedAssets = SURFLIQUID_SUPPORTED_ASSETS;
1175
1212
  broker = null;
1176
1213
  brokerWallet = null;
1214
+ // The SurfLiquid session and every keyed read run on the smart account (the vault
1215
+ // owner), not the EOA — set by connect(), consumed by the reads below.
1216
+ smartAccountAddress = null;
1177
1217
  // Dedicated instance for the anonymous "0x" asset probe — never shares a slot
1178
1218
  // with the user's broker, so discovery can never evict or overwrite a session.
1179
1219
  discoveryBroker = null;
@@ -1195,17 +1235,22 @@ var init_surfliquid_agent = __esm({
1195
1235
  return this.broker;
1196
1236
  }
1197
1237
  async connect(state, shouldForce = false) {
1198
- const broker = this.brokerFor(state.walletAddress);
1199
- if (!shouldForce && broker.hasSession()) return broker;
1238
+ if (!shouldForce && this.broker && this.smartAccountAddress && this.broker.hasSession()) {
1239
+ return this.broker;
1240
+ }
1200
1241
  if (this.connectPromise) return this.connectPromise;
1201
1242
  this.connectPromise = (async () => {
1243
+ const wallet = await this.sponsoredWallet(state);
1244
+ const smartAccountAddress = wallet.smartAccountAddress;
1245
+ this.smartAccountAddress = smartAccountAddress;
1246
+ const broker = this.brokerFor(smartAccountAddress);
1247
+ if (!shouldForce && broker.hasSession()) return broker;
1248
+ const { createSponsoredChain: createSponsoredChain2 } = await Promise.resolve().then(() => (init_surfliquid_smart_account(), surfliquid_smart_account_exports));
1249
+ if (!await createSponsoredChain2(this.config.rpcUrl).isDeployed(smartAccountAddress)) {
1250
+ await wallet.deployAccount();
1251
+ }
1202
1252
  const message = await broker.nonce();
1203
- const walletClient = (0, import_viem10.createWalletClient)({
1204
- account: state.walletAddress,
1205
- chain: import_chains3.base,
1206
- transport: (0, import_viem10.custom)(state.provider)
1207
- });
1208
- const signature = await walletClient.signMessage({ account: state.walletAddress, message });
1253
+ const signature = await wallet.signMessage(message);
1209
1254
  await broker.login(message, signature);
1210
1255
  return broker;
1211
1256
  })();
@@ -1215,6 +1260,10 @@ var init_surfliquid_agent = __esm({
1215
1260
  this.connectPromise = null;
1216
1261
  }
1217
1262
  }
1263
+ /** The SurfLiquid-facing wallet address: the smart account once connected, else the EOA. */
1264
+ surfWallet(state) {
1265
+ return this.smartAccountAddress ?? state.walletAddress;
1266
+ }
1218
1267
  /** A 401 can only surface before any signature (SurfLiquid is never called between sign and submit). */
1219
1268
  async withSession(state, run) {
1220
1269
  try {
@@ -1245,6 +1294,7 @@ var init_surfliquid_agent = __esm({
1245
1294
  this.broker?.clearSession();
1246
1295
  this.broker = null;
1247
1296
  this.brokerWallet = null;
1297
+ this.smartAccountAddress = null;
1248
1298
  }
1249
1299
  async activateAgent(state, _chainId) {
1250
1300
  await this.connect(state);
@@ -1306,7 +1356,7 @@ var init_surfliquid_agent = __esm({
1306
1356
  // --- IAgent: portfolio reads ---
1307
1357
  async vault(state) {
1308
1358
  const broker = await this.connect(state);
1309
- return this.withSession(state, () => broker.getVault(state.walletAddress));
1359
+ return this.withSession(state, () => broker.getVault(this.surfWallet(state)));
1310
1360
  }
1311
1361
  async getBalances(state, chainId) {
1312
1362
  const vault = await this.vault(state);
@@ -1327,7 +1377,7 @@ var init_surfliquid_agent = __esm({
1327
1377
  const limit = options?.limit ?? HISTORY_DEFAULT_LIMIT;
1328
1378
  const result = await this.withSession(
1329
1379
  state,
1330
- () => broker.getAgentMessages(state.walletAddress, page, limit, options?.fromDate, options?.toDate)
1380
+ () => broker.getAgentMessages(this.surfWallet(state), page, limit, options?.fromDate, options?.toDate)
1331
1381
  );
1332
1382
  return mapHistory(result, chainId);
1333
1383
  }
@@ -3566,8 +3616,8 @@ function aggregateApyByChainAndAsset(agentApys, agentBalances) {
3566
3616
  }
3567
3617
 
3568
3618
  // src/client.ts
3569
- var import_viem11 = require("viem");
3570
- var import_chains4 = require("viem/chains");
3619
+ var import_viem10 = require("viem");
3620
+ var import_chains3 = require("viem/chains");
3571
3621
 
3572
3622
  // src/lib/sponsored-deposit.ts
3573
3623
  init_errors();
@@ -3577,10 +3627,10 @@ init_transfer_auth();
3577
3627
  init_errors();
3578
3628
  var ROUTING_API_BASE_URL3 = "https://owney-routing-api-243946518160.europe-west4.run.app";
3579
3629
  async function postSponsorTransferAuth(input) {
3580
- const base5 = input.baseUrl ?? ROUTING_API_BASE_URL3;
3630
+ const base4 = input.baseUrl ?? ROUTING_API_BASE_URL3;
3581
3631
  let res;
3582
3632
  try {
3583
- res = await fetch(`${base5}/api/v1/sponsor/erc20-transfer-auth`, {
3633
+ res = await fetch(`${base4}/api/v1/sponsor/erc20-transfer-auth`, {
3584
3634
  method: "POST",
3585
3635
  headers: {
3586
3636
  "content-type": "application/json",
@@ -3617,10 +3667,10 @@ async function postSponsorTransferAuth(input) {
3617
3667
  return parsed.data;
3618
3668
  }
3619
3669
  async function postSponsorPermit2Transfer(input) {
3620
- const base5 = input.baseUrl ?? ROUTING_API_BASE_URL3;
3670
+ const base4 = input.baseUrl ?? ROUTING_API_BASE_URL3;
3621
3671
  let res;
3622
3672
  try {
3623
- res = await fetch(`${base5}/api/v1/sponsor/permit2-transfer`, {
3673
+ res = await fetch(`${base4}/api/v1/sponsor/permit2-transfer`, {
3624
3674
  method: "POST",
3625
3675
  headers: {
3626
3676
  "content-type": "application/json",
@@ -3655,11 +3705,11 @@ async function postSponsorPermit2Transfer(input) {
3655
3705
  return parsed.data;
3656
3706
  }
3657
3707
  async function getSponsorRelayerAddress(input) {
3658
- const base5 = input.baseUrl ?? ROUTING_API_BASE_URL3;
3708
+ const base4 = input.baseUrl ?? ROUTING_API_BASE_URL3;
3659
3709
  let res;
3660
3710
  try {
3661
3711
  res = await fetch(
3662
- `${base5}/api/v1/sponsor/relayer-address?chainId=${input.chainId}`,
3712
+ `${base4}/api/v1/sponsor/relayer-address?chainId=${input.chainId}`,
3663
3713
  {
3664
3714
  headers: { "x-owney-api-key": input.apiKey }
3665
3715
  }
@@ -4086,9 +4136,9 @@ var SPONSORED_USDC_BY_CHAIN = {
4086
4136
  1: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
4087
4137
  };
4088
4138
  var VIEM_CHAIN2 = {
4089
- 8453: import_chains4.base,
4090
- 42161: import_chains4.arbitrum,
4091
- 1: import_chains4.mainnet
4139
+ 8453: import_chains3.base,
4140
+ 42161: import_chains3.arbitrum,
4141
+ 1: import_chains3.mainnet
4092
4142
  };
4093
4143
  var SPONSORED_WETH_BY_CHAIN = {
4094
4144
  8453: "0x4200000000000000000000000000000000000006",
@@ -4245,14 +4295,14 @@ var OwneySDK = class {
4245
4295
  // Casts work around viem's chain-narrowed Client vs the generic
4246
4296
  // PublicClient/WalletClient param types — structurally identical at
4247
4297
  // runtime, but the two share a name TS treats as unrelated.
4248
- getPublicClient: (cid) => (0, import_viem11.createPublicClient)({
4298
+ getPublicClient: (cid) => (0, import_viem10.createPublicClient)({
4249
4299
  chain: VIEM_CHAIN2[cid],
4250
- transport: (0, import_viem11.custom)(provider)
4300
+ transport: (0, import_viem10.custom)(provider)
4251
4301
  }),
4252
- getWalletClient: (cid) => (0, import_viem11.createWalletClient)({
4302
+ getWalletClient: (cid) => (0, import_viem10.createWalletClient)({
4253
4303
  account: owner,
4254
4304
  chain: VIEM_CHAIN2[cid],
4255
- transport: (0, import_viem11.custom)(provider)
4305
+ transport: (0, import_viem10.custom)(provider)
4256
4306
  })
4257
4307
  });
4258
4308
  if (!onApproved) this.cachedSponsoredCallback = callback;
@@ -4298,14 +4348,14 @@ var OwneySDK = class {
4298
4348
  // Casts work around viem's chain-narrowed Client vs the generic
4299
4349
  // PublicClient/WalletClient param types — structurally identical at
4300
4350
  // runtime, but the two share a name TS treats as unrelated.
4301
- getPublicClient: (cid) => (0, import_viem11.createPublicClient)({
4351
+ getPublicClient: (cid) => (0, import_viem10.createPublicClient)({
4302
4352
  chain: VIEM_CHAIN2[cid],
4303
- transport: (0, import_viem11.custom)(provider)
4353
+ transport: (0, import_viem10.custom)(provider)
4304
4354
  }),
4305
- getWalletClient: (cid) => (0, import_viem11.createWalletClient)({
4355
+ getWalletClient: (cid) => (0, import_viem10.createWalletClient)({
4306
4356
  account: owner,
4307
4357
  chain: VIEM_CHAIN2[cid],
4308
- transport: (0, import_viem11.custom)(provider)
4358
+ transport: (0, import_viem10.custom)(provider)
4309
4359
  })
4310
4360
  });
4311
4361
  if (!onApproved) this.cachedWethSponsoredCallback = callback;
@@ -5424,10 +5474,10 @@ var OwneySDK = class {
5424
5474
  );
5425
5475
  }
5426
5476
  const provider = this.requireConnectedProvider();
5427
- const wallet = (0, import_viem11.createWalletClient)({
5477
+ const wallet = (0, import_viem10.createWalletClient)({
5428
5478
  account: state.walletAddress,
5429
5479
  chain: VIEM_CHAIN2[chainId],
5430
- transport: (0, import_viem11.custom)(provider)
5480
+ transport: (0, import_viem10.custom)(provider)
5431
5481
  });
5432
5482
  const hash = await wallet.writeContract({
5433
5483
  address: token,
@@ -5437,9 +5487,9 @@ var OwneySDK = class {
5437
5487
  account: state.walletAddress,
5438
5488
  chain: VIEM_CHAIN2[chainId]
5439
5489
  });
5440
- const publicClient = (0, import_viem11.createPublicClient)({
5490
+ const publicClient = (0, import_viem10.createPublicClient)({
5441
5491
  chain: VIEM_CHAIN2[chainId],
5442
- transport: (0, import_viem11.custom)(provider)
5492
+ transport: (0, import_viem10.custom)(provider)
5443
5493
  });
5444
5494
  const receipt = await publicClient.waitForTransactionReceipt({
5445
5495
  hash,
@@ -5555,7 +5605,7 @@ init_errors();
5555
5605
  init_debug();
5556
5606
 
5557
5607
  // src/agents/zyfai/zyfai.siwx.ts
5558
- var import_viem12 = require("viem");
5608
+ var import_viem11 = require("viem");
5559
5609
  var import_siwe = require("siwe");
5560
5610
  var import_sdk2 = require("@zyfai/sdk");
5561
5611
 
@@ -5682,7 +5732,7 @@ function buildSIWXConfig(deps) {
5682
5732
  issuedAt,
5683
5733
  toString() {
5684
5734
  return new import_siwe.SiweMessage({
5685
- address: (0, import_viem12.getAddress)(accountAddress),
5735
+ address: (0, import_viem11.getAddress)(accountAddress),
5686
5736
  chainId: numericChainId(chainId),
5687
5737
  domain,
5688
5738
  uri,
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-E54CPWXF.js");
3039
+ const { SurfLiquidAgent } = await import("./surfliquid.agent-ZTIK54MW.js");
3040
3040
  return new SurfLiquidAgent({
3041
3041
  apiKey: this.apiKey,
3042
3042
  routingApiBaseUrl: this.routingApiBaseUrl
@@ -13,13 +13,9 @@ import {
13
13
  readStuckBalance,
14
14
  sweepStuckBalance,
15
15
  withdrawSponsored
16
- } from "./chunk-5W56YOBO.js";
16
+ } from "./chunk-T5YJVIQG.js";
17
17
  import "./chunk-AURO3C3R.js";
18
18
 
19
- // src/agents/surfliquid/surfliquid.agent.ts
20
- import { createWalletClient, custom } from "viem";
21
- import { base } from "viem/chains";
22
-
23
19
  // src/agents/surfliquid/surfliquid.session-store.ts
24
20
  var KEY_PREFIX = "owney.surfliquid.session";
25
21
  var EXPIRY_SKEW_MS = 3e4;
@@ -146,7 +142,7 @@ function normalizeSupportedAssets(json, chainId) {
146
142
  function createSurfBroker(options) {
147
143
  const fetchImpl = options.fetchImpl ?? fetch;
148
144
  const now = options.now ?? Date.now;
149
- const base2 = `${options.routingApiBaseUrl.replace(/\/$/, "")}/api/v1/surf`;
145
+ const base = `${options.routingApiBaseUrl.replace(/\/$/, "")}/api/v1/surf`;
150
146
  const wallet = options.walletAddress;
151
147
  let session = readSurfSession(options.apiKey, wallet);
152
148
  const vaultMemo = /* @__PURE__ */ new Map();
@@ -165,7 +161,7 @@ function createSurfBroker(options) {
165
161
  if (options.origin) headers["origin"] = options.origin;
166
162
  let response;
167
163
  try {
168
- response = await fetchImpl(`${base2}${path}`, {
164
+ response = await fetchImpl(`${base}${path}`, {
169
165
  method,
170
166
  headers,
171
167
  body: body === void 0 ? void 0 : JSON.stringify(body),
@@ -261,10 +257,16 @@ function createSurfBroker(options) {
261
257
  }
262
258
 
263
259
  // src/agents/surfliquid/surfliquid.mapper.ts
260
+ var SURFLIQUID_PROTOCOL = "Morpho";
261
+ var DEPOSIT_TRANSACTION_TYPES = /* @__PURE__ */ new Set([
262
+ "INITIAL_DEPOSIT",
263
+ "DEPOSIT",
264
+ "USER_DEPOSIT"
265
+ ]);
264
266
  function mapMessage(message) {
265
267
  const action = SURFLIQUID_ACTION_MAP[message.transactionType];
266
- if (!action) return null;
267
- return {
268
+ if (!action) return [];
269
+ const base = {
268
270
  agent: "surfliquid",
269
271
  action,
270
272
  date: message.timestamp,
@@ -280,9 +282,27 @@ function mapMessage(message) {
280
282
  ],
281
283
  rebalanceLog: []
282
284
  };
285
+ if (DEPOSIT_TRANSACTION_TYPES.has(message.transactionType) && message.toVault?.name && message.amount != null) {
286
+ return [
287
+ base,
288
+ {
289
+ ...base,
290
+ action: "Deposit",
291
+ positions: [
292
+ {
293
+ protocol: SURFLIQUID_PROTOCOL,
294
+ pool: message.toVault.name,
295
+ tokenSymbol: message.token ?? void 0,
296
+ amount: String(message.amount)
297
+ }
298
+ ]
299
+ }
300
+ ];
301
+ }
302
+ return [base];
283
303
  }
284
304
  function mapHistory(result, _chainId) {
285
- const data = result.messages.map(mapMessage).filter((entry) => entry !== null);
305
+ const data = result.messages.flatMap(mapMessage);
286
306
  const hasMore = result.page < result.pages;
287
307
  return {
288
308
  data,
@@ -478,6 +498,9 @@ var SurfLiquidAgent = class {
478
498
  supportedAssets = SURFLIQUID_SUPPORTED_ASSETS;
479
499
  broker = null;
480
500
  brokerWallet = null;
501
+ // The SurfLiquid session and every keyed read run on the smart account (the vault
502
+ // owner), not the EOA — set by connect(), consumed by the reads below.
503
+ smartAccountAddress = null;
481
504
  // Dedicated instance for the anonymous "0x" asset probe — never shares a slot
482
505
  // with the user's broker, so discovery can never evict or overwrite a session.
483
506
  discoveryBroker = null;
@@ -499,17 +522,22 @@ var SurfLiquidAgent = class {
499
522
  return this.broker;
500
523
  }
501
524
  async connect(state, shouldForce = false) {
502
- const broker = this.brokerFor(state.walletAddress);
503
- if (!shouldForce && broker.hasSession()) return broker;
525
+ if (!shouldForce && this.broker && this.smartAccountAddress && this.broker.hasSession()) {
526
+ return this.broker;
527
+ }
504
528
  if (this.connectPromise) return this.connectPromise;
505
529
  this.connectPromise = (async () => {
530
+ const wallet = await this.sponsoredWallet(state);
531
+ const smartAccountAddress = wallet.smartAccountAddress;
532
+ this.smartAccountAddress = smartAccountAddress;
533
+ const broker = this.brokerFor(smartAccountAddress);
534
+ if (!shouldForce && broker.hasSession()) return broker;
535
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
536
+ if (!await createSponsoredChain(this.config.rpcUrl).isDeployed(smartAccountAddress)) {
537
+ await wallet.deployAccount();
538
+ }
506
539
  const message = await broker.nonce();
507
- const walletClient = createWalletClient({
508
- account: state.walletAddress,
509
- chain: base,
510
- transport: custom(state.provider)
511
- });
512
- const signature = await walletClient.signMessage({ account: state.walletAddress, message });
540
+ const signature = await wallet.signMessage(message);
513
541
  await broker.login(message, signature);
514
542
  return broker;
515
543
  })();
@@ -519,6 +547,10 @@ var SurfLiquidAgent = class {
519
547
  this.connectPromise = null;
520
548
  }
521
549
  }
550
+ /** The SurfLiquid-facing wallet address: the smart account once connected, else the EOA. */
551
+ surfWallet(state) {
552
+ return this.smartAccountAddress ?? state.walletAddress;
553
+ }
522
554
  /** A 401 can only surface before any signature (SurfLiquid is never called between sign and submit). */
523
555
  async withSession(state, run) {
524
556
  try {
@@ -535,7 +567,7 @@ var SurfLiquidAgent = class {
535
567
  }
536
568
  }
537
569
  async sponsoredWallet(state) {
538
- const { createSponsoredWallet } = await import("./surfliquid.smart-account-O6YPCQT3.js");
570
+ const { createSponsoredWallet } = await import("./surfliquid.smart-account-YV3PLZ72.js");
539
571
  return createSponsoredWallet({
540
572
  provider: state.provider,
541
573
  ownerAddress: state.walletAddress,
@@ -549,6 +581,7 @@ var SurfLiquidAgent = class {
549
581
  this.broker?.clearSession();
550
582
  this.broker = null;
551
583
  this.brokerWallet = null;
584
+ this.smartAccountAddress = null;
552
585
  }
553
586
  async activateAgent(state, _chainId) {
554
587
  await this.connect(state);
@@ -557,7 +590,7 @@ var SurfLiquidAgent = class {
557
590
  async deposit(state, _chainId, amount, _asset, _depositCallback) {
558
591
  const broker = await this.connect(state);
559
592
  const wallet = await this.sponsoredWallet(state);
560
- const { createSponsoredChain } = await import("./surfliquid.smart-account-O6YPCQT3.js");
593
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
561
594
  try {
562
595
  const { txHash, vault } = await this.withSession(
563
596
  state,
@@ -572,7 +605,7 @@ var SurfLiquidAgent = class {
572
605
  async withdraw(state, _chainId, _token, amount) {
573
606
  const broker = await this.connect(state);
574
607
  const wallet = await this.sponsoredWallet(state);
575
- const { createSponsoredChain } = await import("./surfliquid.smart-account-O6YPCQT3.js");
608
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
576
609
  try {
577
610
  const result = await this.withSession(
578
611
  state,
@@ -592,14 +625,14 @@ var SurfLiquidAgent = class {
592
625
  /** Funds a prior withdrawal's sweep left in the smart account (never reached the EOA). No session needed — pure read. */
593
626
  async getStuckBalance(state) {
594
627
  const wallet = await this.sponsoredWallet(state);
595
- const { createSponsoredChain } = await import("./surfliquid.smart-account-O6YPCQT3.js");
628
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
596
629
  const amount = await readStuckBalance({ chain: createSponsoredChain(this.config.rpcUrl), wallet });
597
630
  return { amount: amount.toString(), smartAccountAddress: wallet.smartAccountAddress };
598
631
  }
599
632
  /** Sweep the stranded balance to the owner's EOA — one sponsored userOp, one signature. */
600
633
  async recoverStuckBalance(state) {
601
634
  const wallet = await this.sponsoredWallet(state);
602
- const { createSponsoredChain } = await import("./surfliquid.smart-account-O6YPCQT3.js");
635
+ const { createSponsoredChain } = await import("./surfliquid.smart-account-YV3PLZ72.js");
603
636
  try {
604
637
  const { txHash, amount } = await sweepStuckBalance({ chain: createSponsoredChain(this.config.rpcUrl), wallet });
605
638
  return { txHash, type: "full", amount: amount.toString() };
@@ -610,7 +643,7 @@ var SurfLiquidAgent = class {
610
643
  // --- IAgent: portfolio reads ---
611
644
  async vault(state) {
612
645
  const broker = await this.connect(state);
613
- return this.withSession(state, () => broker.getVault(state.walletAddress));
646
+ return this.withSession(state, () => broker.getVault(this.surfWallet(state)));
614
647
  }
615
648
  async getBalances(state, chainId) {
616
649
  const vault = await this.vault(state);
@@ -631,7 +664,7 @@ var SurfLiquidAgent = class {
631
664
  const limit = options?.limit ?? HISTORY_DEFAULT_LIMIT;
632
665
  const result = await this.withSession(
633
666
  state,
634
- () => broker.getAgentMessages(state.walletAddress, page, limit, options?.fromDate, options?.toDate)
667
+ () => broker.getAgentMessages(this.surfWallet(state), page, limit, options?.fromDate, options?.toDate)
635
668
  );
636
669
  return mapHistory(result, chainId);
637
670
  }
@@ -6,14 +6,14 @@ import {
6
6
  SURFLIQUID_VAULT_ABI,
7
7
  SubmittedError,
8
8
  USDC_ABI
9
- } from "./chunk-5W56YOBO.js";
9
+ } from "./chunk-T5YJVIQG.js";
10
10
  import {
11
11
  readTokenMeta
12
12
  } from "./chunk-AURO3C3R.js";
13
13
 
14
14
  // src/agents/surfliquid/surfliquid.smart-account.ts
15
15
  import { createSmartAccountClient } from "permissionless";
16
- import { toSimpleSmartAccount } from "permissionless/accounts";
16
+ import { toSafeSmartAccount } from "permissionless/accounts";
17
17
  import { createPimlicoClient } from "permissionless/clients/pimlico";
18
18
  import {
19
19
  createPublicClient,
@@ -21,7 +21,7 @@ import {
21
21
  custom,
22
22
  http
23
23
  } from "viem";
24
- import { entryPoint08Address } from "viem/account-abstraction";
24
+ import { entryPoint07Address } from "viem/account-abstraction";
25
25
  import { base } from "viem/chains";
26
26
  var sponsorProxyUrl = (routingApiBaseUrl) => `${routingApiBaseUrl.replace(/\/$/, "")}/api/v1/sponsor/pimlico-rpc/${SURFLIQUID_CHAIN_ID}`;
27
27
  function publicClientFor(rpcUrl) {
@@ -77,10 +77,11 @@ function pinAccount(provider, address) {
77
77
  };
78
78
  }
79
79
  async function createSponsoredWallet(input) {
80
- const entryPoint = { address: entryPoint08Address, version: "0.8" };
81
- const account = await toSimpleSmartAccount({
80
+ const entryPoint = { address: entryPoint07Address, version: "0.7" };
81
+ const account = await toSafeSmartAccount({
82
82
  client: publicClientFor(input.rpcUrl),
83
- owner: pinAccount(input.provider, input.ownerAddress),
83
+ owners: [pinAccount(input.provider, input.ownerAddress)],
84
+ version: "1.4.1",
84
85
  entryPoint
85
86
  });
86
87
  const bundlerTransport = http(sponsorProxyUrl(input.routingApiBaseUrl), {
@@ -112,6 +113,20 @@ async function createSponsoredWallet(input) {
112
113
  primaryType: typedData.primaryType,
113
114
  message: typedData.message
114
115
  }),
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.
119
+ 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
+ },
115
130
  sendCalls: async (calls) => {
116
131
  const userOpHash = await smartAccountClient.sendUserOperation({
117
132
  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.2",
3
+ "version": "0.7.22-beta.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",