@owney/sdk 0.7.16-beta.2 → 0.7.16-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.
package/dist/index.cjs CHANGED
@@ -2825,6 +2825,7 @@ function transactionHashes(details) {
2825
2825
  ).filter((value, index, all) => all.indexOf(value) === index);
2826
2826
  }
2827
2827
  function actionEntry(action) {
2828
+ if (action.actionType.toLowerCase().includes("withdraw")) return void 0;
2828
2829
  return {
2829
2830
  agent: "yieldseeker",
2830
2831
  action: actionType(action.actionType),
@@ -2840,11 +2841,27 @@ function actionEntry(action) {
2840
2841
  rebalanceLog: []
2841
2842
  };
2842
2843
  }
2843
- function movementEntry(movement, wallet, agent, asset) {
2844
- const isDeposit = movement.toAddress.toLowerCase() === wallet.walletAddress.toLowerCase();
2844
+ function movementEntry(movement, wallet, agent, asset, ownerAddress, vaultAddresses) {
2845
+ const from = movement.fromAddress.toLowerCase();
2846
+ const to = movement.toAddress.toLowerCase();
2847
+ const owner = ownerAddress.toLowerCase();
2848
+ const agentWallet = wallet.walletAddress.toLowerCase();
2849
+ const baseAsset = agent.assetAddress.toLowerCase();
2850
+ if (movement.chainId !== agent.chainId || movement.assetAddress.toLowerCase() !== baseAsset) {
2851
+ return void 0;
2852
+ }
2853
+ let action;
2854
+ if (from === owner && to === agentWallet) {
2855
+ action = "Top up";
2856
+ } else if (from === agentWallet && to === owner) {
2857
+ action = "Withdraw";
2858
+ } else if (from === agentWallet && vaultAddresses.has(to)) {
2859
+ action = "Deposit";
2860
+ }
2861
+ if (!action) return void 0;
2845
2862
  return {
2846
2863
  agent: "yieldseeker",
2847
- action: isDeposit ? "Deposit" : "Withdraw",
2864
+ action,
2848
2865
  date: movement.blockDate,
2849
2866
  oldApy: null,
2850
2867
  newApy: null,
@@ -2864,19 +2881,35 @@ function movementEntry(movement, wallet, agent, asset) {
2864
2881
  };
2865
2882
  }
2866
2883
  function mapYieldseekerHistory(contexts, options) {
2867
- const entries = contexts.flatMap((context) => [
2868
- ...(context.actions ?? []).map(actionEntry),
2869
- ...(context.historic?.movements ?? []).map(
2870
- (movement) => movementEntry(movement, context.wallet, context.agent, context.asset)
2871
- )
2872
- ]);
2884
+ const entries = contexts.flatMap((context) => {
2885
+ const vaultAddresses = new Set(
2886
+ context.positions.map(
2887
+ (position2) => position2.yieldOption.address.toLowerCase()
2888
+ )
2889
+ );
2890
+ return [
2891
+ ...(context.historic?.movements ?? []).map(
2892
+ (movement) => movementEntry(
2893
+ movement,
2894
+ context.wallet,
2895
+ context.agent,
2896
+ context.asset,
2897
+ options.ownerAddress,
2898
+ vaultAddresses
2899
+ )
2900
+ ),
2901
+ ...(context.actions ?? []).map(actionEntry)
2902
+ ].filter((entry) => entry !== void 0);
2903
+ });
2873
2904
  const filtered = entries.filter(
2874
2905
  (entry) => (!options.fromDate || entry.date >= options.fromDate) && (!options.toDate || entry.date <= options.toDate)
2875
- ).filter(
2876
- (entry, index, all) => all.findIndex(
2877
- (candidate) => candidate.action === entry.action && candidate.date === entry.date && candidate.transactions[0]?.txHashes[0] === entry.transactions[0]?.txHashes[0]
2878
- ) === index
2879
- ).sort((left, right) => right.date.localeCompare(left.date));
2906
+ ).filter((entry, index, all) => {
2907
+ const transactionHash = entry.transactions[0]?.txHashes[0];
2908
+ if (!transactionHash) return true;
2909
+ return all.findIndex(
2910
+ (candidate) => candidate.action === entry.action && candidate.transactions[0]?.txHashes[0] === transactionHash
2911
+ ) === index;
2912
+ }).sort((left, right) => right.date.localeCompare(left.date));
2880
2913
  return {
2881
2914
  data: filtered.slice(0, options.limit),
2882
2915
  // v1 returns the whole action/movement collection and defines no cursor.
@@ -2923,6 +2956,18 @@ function mapYieldseekerAgentApy(options, days) {
2923
2956
 
2924
2957
  // src/agents/yieldseeker/yieldseeker.agent.ts
2925
2958
  var OWNEY_AGENT_NAME = "owney";
2959
+ var YIELDSEEKER_USERNAME_PREFIX = "owney_";
2960
+ var YIELDSEEKER_USERNAME_RANDOM_LENGTH = 14;
2961
+ var YIELDSEEKER_USERNAME_CREATE_ATTEMPTS = 3;
2962
+ function generateYieldseekerUsername() {
2963
+ const suffix = globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, YIELDSEEKER_USERNAME_RANDOM_LENGTH).toLowerCase();
2964
+ return `${YIELDSEEKER_USERNAME_PREFIX}${suffix}`;
2965
+ }
2966
+ function isUsernameConflict(error) {
2967
+ if (!(error instanceof YieldseekerApiError)) return false;
2968
+ const code = error.providerCode.toUpperCase();
2969
+ return code.includes("USERNAME") && (code.includes("TAKEN") || code.includes("EXIST") || code.includes("UNAVAILABLE") || code.includes("IN_USE"));
2970
+ }
2926
2971
  var YIELDSEEKER_AGENT_WALLET_ABI = [
2927
2972
  {
2928
2973
  type: "function",
@@ -3195,6 +3240,7 @@ var YieldseekerAgent = class {
3195
3240
  });
3196
3241
  return mapYieldseekerHistory(contexts, {
3197
3242
  limit: options?.limit ?? 10,
3243
+ ownerAddress: state.walletAddress,
3198
3244
  ...options?.fromDate ? { fromDate: options.fromDate } : {},
3199
3245
  ...options?.toDate ? { toDate: options.toDate } : {}
3200
3246
  });
@@ -3261,21 +3307,26 @@ var YieldseekerAgent = class {
3261
3307
  throw this.mapApiError(error);
3262
3308
  }
3263
3309
  let created;
3264
- try {
3265
- created = await this.providerRequest(
3266
- state,
3267
- chainId,
3268
- "/users",
3269
- {
3270
- method: "POST",
3271
- body: {
3272
- walletAddress,
3273
- username: `owney-${walletAddress.slice(2).toLowerCase()}`
3310
+ for (let attempt = 0; attempt < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS; attempt += 1) {
3311
+ try {
3312
+ created = await this.providerRequest(
3313
+ state,
3314
+ chainId,
3315
+ "/users",
3316
+ {
3317
+ method: "POST",
3318
+ body: {
3319
+ walletAddress,
3320
+ username: generateYieldseekerUsername()
3321
+ }
3274
3322
  }
3275
- }
3276
- );
3277
- } catch (createError) {
3278
- throw this.mapApiError(createError);
3323
+ );
3324
+ break;
3325
+ } catch (createError) {
3326
+ const canRetry = isUsernameConflict(createError) && attempt + 1 < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS;
3327
+ if (canRetry) continue;
3328
+ throw this.mapApiError(createError);
3329
+ }
3279
3330
  }
3280
3331
  user = created?.user ?? null;
3281
3332
  }
package/dist/index.js CHANGED
@@ -2804,6 +2804,7 @@ function transactionHashes(details) {
2804
2804
  ).filter((value, index, all) => all.indexOf(value) === index);
2805
2805
  }
2806
2806
  function actionEntry(action) {
2807
+ if (action.actionType.toLowerCase().includes("withdraw")) return void 0;
2807
2808
  return {
2808
2809
  agent: "yieldseeker",
2809
2810
  action: actionType(action.actionType),
@@ -2819,11 +2820,27 @@ function actionEntry(action) {
2819
2820
  rebalanceLog: []
2820
2821
  };
2821
2822
  }
2822
- function movementEntry(movement, wallet, agent, asset) {
2823
- const isDeposit = movement.toAddress.toLowerCase() === wallet.walletAddress.toLowerCase();
2823
+ function movementEntry(movement, wallet, agent, asset, ownerAddress, vaultAddresses) {
2824
+ const from = movement.fromAddress.toLowerCase();
2825
+ const to = movement.toAddress.toLowerCase();
2826
+ const owner = ownerAddress.toLowerCase();
2827
+ const agentWallet = wallet.walletAddress.toLowerCase();
2828
+ const baseAsset = agent.assetAddress.toLowerCase();
2829
+ if (movement.chainId !== agent.chainId || movement.assetAddress.toLowerCase() !== baseAsset) {
2830
+ return void 0;
2831
+ }
2832
+ let action;
2833
+ if (from === owner && to === agentWallet) {
2834
+ action = "Top up";
2835
+ } else if (from === agentWallet && to === owner) {
2836
+ action = "Withdraw";
2837
+ } else if (from === agentWallet && vaultAddresses.has(to)) {
2838
+ action = "Deposit";
2839
+ }
2840
+ if (!action) return void 0;
2824
2841
  return {
2825
2842
  agent: "yieldseeker",
2826
- action: isDeposit ? "Deposit" : "Withdraw",
2843
+ action,
2827
2844
  date: movement.blockDate,
2828
2845
  oldApy: null,
2829
2846
  newApy: null,
@@ -2843,19 +2860,35 @@ function movementEntry(movement, wallet, agent, asset) {
2843
2860
  };
2844
2861
  }
2845
2862
  function mapYieldseekerHistory(contexts, options) {
2846
- const entries = contexts.flatMap((context) => [
2847
- ...(context.actions ?? []).map(actionEntry),
2848
- ...(context.historic?.movements ?? []).map(
2849
- (movement) => movementEntry(movement, context.wallet, context.agent, context.asset)
2850
- )
2851
- ]);
2863
+ const entries = contexts.flatMap((context) => {
2864
+ const vaultAddresses = new Set(
2865
+ context.positions.map(
2866
+ (position2) => position2.yieldOption.address.toLowerCase()
2867
+ )
2868
+ );
2869
+ return [
2870
+ ...(context.historic?.movements ?? []).map(
2871
+ (movement) => movementEntry(
2872
+ movement,
2873
+ context.wallet,
2874
+ context.agent,
2875
+ context.asset,
2876
+ options.ownerAddress,
2877
+ vaultAddresses
2878
+ )
2879
+ ),
2880
+ ...(context.actions ?? []).map(actionEntry)
2881
+ ].filter((entry) => entry !== void 0);
2882
+ });
2852
2883
  const filtered = entries.filter(
2853
2884
  (entry) => (!options.fromDate || entry.date >= options.fromDate) && (!options.toDate || entry.date <= options.toDate)
2854
- ).filter(
2855
- (entry, index, all) => all.findIndex(
2856
- (candidate) => candidate.action === entry.action && candidate.date === entry.date && candidate.transactions[0]?.txHashes[0] === entry.transactions[0]?.txHashes[0]
2857
- ) === index
2858
- ).sort((left, right) => right.date.localeCompare(left.date));
2885
+ ).filter((entry, index, all) => {
2886
+ const transactionHash = entry.transactions[0]?.txHashes[0];
2887
+ if (!transactionHash) return true;
2888
+ return all.findIndex(
2889
+ (candidate) => candidate.action === entry.action && candidate.transactions[0]?.txHashes[0] === transactionHash
2890
+ ) === index;
2891
+ }).sort((left, right) => right.date.localeCompare(left.date));
2859
2892
  return {
2860
2893
  data: filtered.slice(0, options.limit),
2861
2894
  // v1 returns the whole action/movement collection and defines no cursor.
@@ -2902,6 +2935,18 @@ function mapYieldseekerAgentApy(options, days) {
2902
2935
 
2903
2936
  // src/agents/yieldseeker/yieldseeker.agent.ts
2904
2937
  var OWNEY_AGENT_NAME = "owney";
2938
+ var YIELDSEEKER_USERNAME_PREFIX = "owney_";
2939
+ var YIELDSEEKER_USERNAME_RANDOM_LENGTH = 14;
2940
+ var YIELDSEEKER_USERNAME_CREATE_ATTEMPTS = 3;
2941
+ function generateYieldseekerUsername() {
2942
+ const suffix = globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, YIELDSEEKER_USERNAME_RANDOM_LENGTH).toLowerCase();
2943
+ return `${YIELDSEEKER_USERNAME_PREFIX}${suffix}`;
2944
+ }
2945
+ function isUsernameConflict(error) {
2946
+ if (!(error instanceof YieldseekerApiError)) return false;
2947
+ const code = error.providerCode.toUpperCase();
2948
+ return code.includes("USERNAME") && (code.includes("TAKEN") || code.includes("EXIST") || code.includes("UNAVAILABLE") || code.includes("IN_USE"));
2949
+ }
2905
2950
  var YIELDSEEKER_AGENT_WALLET_ABI = [
2906
2951
  {
2907
2952
  type: "function",
@@ -3174,6 +3219,7 @@ var YieldseekerAgent = class {
3174
3219
  });
3175
3220
  return mapYieldseekerHistory(contexts, {
3176
3221
  limit: options?.limit ?? 10,
3222
+ ownerAddress: state.walletAddress,
3177
3223
  ...options?.fromDate ? { fromDate: options.fromDate } : {},
3178
3224
  ...options?.toDate ? { toDate: options.toDate } : {}
3179
3225
  });
@@ -3240,21 +3286,26 @@ var YieldseekerAgent = class {
3240
3286
  throw this.mapApiError(error);
3241
3287
  }
3242
3288
  let created;
3243
- try {
3244
- created = await this.providerRequest(
3245
- state,
3246
- chainId,
3247
- "/users",
3248
- {
3249
- method: "POST",
3250
- body: {
3251
- walletAddress,
3252
- username: `owney-${walletAddress.slice(2).toLowerCase()}`
3289
+ for (let attempt = 0; attempt < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS; attempt += 1) {
3290
+ try {
3291
+ created = await this.providerRequest(
3292
+ state,
3293
+ chainId,
3294
+ "/users",
3295
+ {
3296
+ method: "POST",
3297
+ body: {
3298
+ walletAddress,
3299
+ username: generateYieldseekerUsername()
3300
+ }
3253
3301
  }
3254
- }
3255
- );
3256
- } catch (createError) {
3257
- throw this.mapApiError(createError);
3302
+ );
3303
+ break;
3304
+ } catch (createError) {
3305
+ const canRetry = isUsernameConflict(createError) && attempt + 1 < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS;
3306
+ if (canRetry) continue;
3307
+ throw this.mapApiError(createError);
3308
+ }
3258
3309
  }
3259
3310
  user = created?.user ?? null;
3260
3311
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.16-beta.2",
3
+ "version": "0.7.16-beta.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",