@owney/sdk 0.5.0 → 0.5.1-beta.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.cjs CHANGED
@@ -177,10 +177,27 @@ function mapBalances(raw, _chainId, smartWallet) {
177
177
  });
178
178
  }
179
179
  }
180
+ const positions = (portfolio.positions ?? []).map((p) => ({
181
+ chain: p.chain ?? "",
182
+ protocol: p.protocol_name ?? p.protocol_id ?? "",
183
+ protocolId: p.protocol_id,
184
+ pool: p.pool,
185
+ asset: p.token_symbol ?? "",
186
+ // Position amount is hex-encoded base units (like the token balances
187
+ // above). Supported assets (USDC/USDT) are 6-decimal — hexToDecimal's
188
+ // default — so no per-token decimals lookup is needed.
189
+ amount: String(hexToDecimal(p.amount || "0")),
190
+ apy: p.pool_apy,
191
+ tvl: p.pool_tvl,
192
+ // PositionSlot has no `liquidity` field yet; Zyfai will add it. Narrow
193
+ // structural read keeps it undefined today and auto-populates later.
194
+ liquidity: p.liquidity
195
+ }));
180
196
  return {
181
197
  smartWallet,
182
198
  totalBalance: String(totalBalance),
183
- tokens
199
+ tokens,
200
+ positions
184
201
  };
185
202
  }
186
203
  function sumTokenValues(tokens) {
@@ -1972,12 +1989,13 @@ var OwneySDK = class {
1972
1989
  const chainId = this.requireChainId();
1973
1990
  const activeAgents = this.getActiveAgents();
1974
1991
  const balances = {};
1992
+ const positionsByAgent = {};
1975
1993
  let totalBalance = 0;
1976
1994
  const entries = [...activeAgents.entries()];
1977
1995
  const balanceResults = await Promise.allSettled(
1978
1996
  entries.map(async ([id, agent]) => {
1979
1997
  const b = await agent.getBalances(state, chainId);
1980
- return [id, Number(b.totalBalance)];
1998
+ return [id, Number(b.totalBalance), b.positions ?? []];
1981
1999
  })
1982
2000
  );
1983
2001
  let successCount = 0;
@@ -1986,8 +2004,9 @@ var OwneySDK = class {
1986
2004
  const settledResult = balanceResults[i];
1987
2005
  const [agentId] = entries[i];
1988
2006
  if (settledResult.status === "fulfilled") {
1989
- const [id, bal] = settledResult.value;
2007
+ const [id, bal, agentPositions] = settledResult.value;
1990
2008
  balances[id] = bal;
2009
+ positionsByAgent[id] = agentPositions;
1991
2010
  totalBalance += bal;
1992
2011
  successCount += 1;
1993
2012
  } else {
@@ -2021,7 +2040,8 @@ var OwneySDK = class {
2021
2040
  }
2022
2041
  }
2023
2042
  return {
2024
- agentAllocation: allocation
2043
+ agentAllocation: allocation,
2044
+ agentPositions: positionsByAgent
2025
2045
  };
2026
2046
  }
2027
2047
  };
package/dist/index.d.cts CHANGED
@@ -128,10 +128,29 @@ interface OwneyToken {
128
128
  asset: OwneySupportedTokens;
129
129
  amount: string;
130
130
  }
131
+ interface OwneyPosition {
132
+ /** Raw chain identifier as returned by the agent (chain id or name); not coerced. */
133
+ chain: string;
134
+ protocol: string;
135
+ protocolId?: string;
136
+ pool?: string;
137
+ asset: string;
138
+ amount: string;
139
+ apy?: number;
140
+ tvl?: number;
141
+ /** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
142
+ * response later; undefined until then. */
143
+ liquidity?: number;
144
+ }
131
145
  interface AgentBalance {
132
146
  smartWallet?: `0x${string}`;
133
147
  totalBalance: string;
134
148
  tokens: OwneyToken[];
149
+ /**
150
+ * Per-protocol/pool positions when the agent's portfolio payload includes
151
+ * them (zyfai). Omitted for agents that don't expose positions (sail).
152
+ */
153
+ positions?: OwneyPosition[];
135
154
  }
136
155
  interface OwneyBalances {
137
156
  totalBalance: string;
@@ -223,6 +242,8 @@ interface OwneyAgentApy {
223
242
  }
224
243
  interface OwneyAgentAllocation {
225
244
  agentAllocation: Record<AgentId, number>;
245
+ /** Per-agent positions. Empty array for agents that don't expose positions. */
246
+ agentPositions: Record<AgentId, OwneyPosition[]>;
226
247
  }
227
248
 
228
249
  declare class OwneySDK {
@@ -442,4 +463,4 @@ type OwneySIWXConfig = {
442
463
  */
443
464
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
444
465
 
445
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
466
+ export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
package/dist/index.d.ts CHANGED
@@ -128,10 +128,29 @@ interface OwneyToken {
128
128
  asset: OwneySupportedTokens;
129
129
  amount: string;
130
130
  }
131
+ interface OwneyPosition {
132
+ /** Raw chain identifier as returned by the agent (chain id or name); not coerced. */
133
+ chain: string;
134
+ protocol: string;
135
+ protocolId?: string;
136
+ pool?: string;
137
+ asset: string;
138
+ amount: string;
139
+ apy?: number;
140
+ tvl?: number;
141
+ /** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
142
+ * response later; undefined until then. */
143
+ liquidity?: number;
144
+ }
131
145
  interface AgentBalance {
132
146
  smartWallet?: `0x${string}`;
133
147
  totalBalance: string;
134
148
  tokens: OwneyToken[];
149
+ /**
150
+ * Per-protocol/pool positions when the agent's portfolio payload includes
151
+ * them (zyfai). Omitted for agents that don't expose positions (sail).
152
+ */
153
+ positions?: OwneyPosition[];
135
154
  }
136
155
  interface OwneyBalances {
137
156
  totalBalance: string;
@@ -223,6 +242,8 @@ interface OwneyAgentApy {
223
242
  }
224
243
  interface OwneyAgentAllocation {
225
244
  agentAllocation: Record<AgentId, number>;
245
+ /** Per-agent positions. Empty array for agents that don't expose positions. */
246
+ agentPositions: Record<AgentId, OwneyPosition[]>;
226
247
  }
227
248
 
228
249
  declare class OwneySDK {
@@ -442,4 +463,4 @@ type OwneySIWXConfig = {
442
463
  */
443
464
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
444
465
 
445
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
466
+ export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
package/dist/index.js CHANGED
@@ -145,10 +145,27 @@ function mapBalances(raw, _chainId, smartWallet) {
145
145
  });
146
146
  }
147
147
  }
148
+ const positions = (portfolio.positions ?? []).map((p) => ({
149
+ chain: p.chain ?? "",
150
+ protocol: p.protocol_name ?? p.protocol_id ?? "",
151
+ protocolId: p.protocol_id,
152
+ pool: p.pool,
153
+ asset: p.token_symbol ?? "",
154
+ // Position amount is hex-encoded base units (like the token balances
155
+ // above). Supported assets (USDC/USDT) are 6-decimal — hexToDecimal's
156
+ // default — so no per-token decimals lookup is needed.
157
+ amount: String(hexToDecimal(p.amount || "0")),
158
+ apy: p.pool_apy,
159
+ tvl: p.pool_tvl,
160
+ // PositionSlot has no `liquidity` field yet; Zyfai will add it. Narrow
161
+ // structural read keeps it undefined today and auto-populates later.
162
+ liquidity: p.liquidity
163
+ }));
148
164
  return {
149
165
  smartWallet,
150
166
  totalBalance: String(totalBalance),
151
- tokens
167
+ tokens,
168
+ positions
152
169
  };
153
170
  }
154
171
  function sumTokenValues(tokens) {
@@ -1944,12 +1961,13 @@ var OwneySDK = class {
1944
1961
  const chainId = this.requireChainId();
1945
1962
  const activeAgents = this.getActiveAgents();
1946
1963
  const balances = {};
1964
+ const positionsByAgent = {};
1947
1965
  let totalBalance = 0;
1948
1966
  const entries = [...activeAgents.entries()];
1949
1967
  const balanceResults = await Promise.allSettled(
1950
1968
  entries.map(async ([id, agent]) => {
1951
1969
  const b = await agent.getBalances(state, chainId);
1952
- return [id, Number(b.totalBalance)];
1970
+ return [id, Number(b.totalBalance), b.positions ?? []];
1953
1971
  })
1954
1972
  );
1955
1973
  let successCount = 0;
@@ -1958,8 +1976,9 @@ var OwneySDK = class {
1958
1976
  const settledResult = balanceResults[i];
1959
1977
  const [agentId] = entries[i];
1960
1978
  if (settledResult.status === "fulfilled") {
1961
- const [id, bal] = settledResult.value;
1979
+ const [id, bal, agentPositions] = settledResult.value;
1962
1980
  balances[id] = bal;
1981
+ positionsByAgent[id] = agentPositions;
1963
1982
  totalBalance += bal;
1964
1983
  successCount += 1;
1965
1984
  } else {
@@ -1993,7 +2012,8 @@ var OwneySDK = class {
1993
2012
  }
1994
2013
  }
1995
2014
  return {
1996
- agentAllocation: allocation
2015
+ agentAllocation: allocation,
2016
+ agentPositions: positionsByAgent
1997
2017
  };
1998
2018
  }
1999
2019
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.5.1-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",