@owney/sdk 0.7.16-beta.2 → 0.7.16-beta.3

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.
@@ -3195,6 +3228,7 @@ var YieldseekerAgent = class {
3195
3228
  });
3196
3229
  return mapYieldseekerHistory(contexts, {
3197
3230
  limit: options?.limit ?? 10,
3231
+ ownerAddress: state.walletAddress,
3198
3232
  ...options?.fromDate ? { fromDate: options.fromDate } : {},
3199
3233
  ...options?.toDate ? { toDate: options.toDate } : {}
3200
3234
  });
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.
@@ -3174,6 +3207,7 @@ var YieldseekerAgent = class {
3174
3207
  });
3175
3208
  return mapYieldseekerHistory(contexts, {
3176
3209
  limit: options?.limit ?? 10,
3210
+ ownerAddress: state.walletAddress,
3177
3211
  ...options?.fromDate ? { fromDate: options.fromDate } : {},
3178
3212
  ...options?.toDate ? { toDate: options.toDate } : {}
3179
3213
  });
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.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",