@owney/sdk 0.7.34 → 0.7.35
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 +104 -3
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +104 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2628,6 +2628,35 @@ function mergeDailyEarnings(series) {
|
|
|
2628
2628
|
|
|
2629
2629
|
// src/lib/routing-api.ts
|
|
2630
2630
|
var ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
2631
|
+
async function fetchApyIncentives(apiKey, input, baseUrl = ROUTING_API_BASE_URL) {
|
|
2632
|
+
const query = new URLSearchParams({
|
|
2633
|
+
walletAddress: input.walletAddress,
|
|
2634
|
+
agentId: input.agentId,
|
|
2635
|
+
chainId: String(input.chainId),
|
|
2636
|
+
asset: input.asset.toUpperCase(),
|
|
2637
|
+
from: input.from,
|
|
2638
|
+
to: input.to
|
|
2639
|
+
});
|
|
2640
|
+
try {
|
|
2641
|
+
const response = await fetch(`${baseUrl}/api/v1/apy-incentives?${query}`, {
|
|
2642
|
+
headers: {
|
|
2643
|
+
Accept: "application/json",
|
|
2644
|
+
"x-owney-api-key": apiKey
|
|
2645
|
+
}
|
|
2646
|
+
});
|
|
2647
|
+
if (!response.ok) return [];
|
|
2648
|
+
const body = await response.json();
|
|
2649
|
+
if (!body.success || !Array.isArray(body.data)) return [];
|
|
2650
|
+
return body.data.filter(
|
|
2651
|
+
(item) => item && typeof item.date === "string" && item.source === "merkl" && typeof item.opportunityId === "string" && Array.isArray(item.campaignIds) && Number.isFinite(item.apr) && Number.isFinite(item.apyContribution)
|
|
2652
|
+
);
|
|
2653
|
+
} catch (error) {
|
|
2654
|
+
debugLog("owney-sdk", "APY incentives unavailable; using native APY", {
|
|
2655
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2656
|
+
});
|
|
2657
|
+
return [];
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2631
2660
|
async function fetchOrgAgentConfig(apiKey, baseUrl = ROUTING_API_BASE_URL) {
|
|
2632
2661
|
const url = `${baseUrl}/api/v1/agent/org-config`;
|
|
2633
2662
|
try {
|
|
@@ -4316,9 +4345,40 @@ function aggregateApyHistory(agentApys) {
|
|
|
4316
4345
|
const total = points.reduce((sum, p) => sum + p.historicalBalance.amount, 0);
|
|
4317
4346
|
if (total <= 0 || !Number.isFinite(total)) return [];
|
|
4318
4347
|
const apy = points.reduce((sum, p) => sum + p.apy * (p.historicalBalance.amount / total), 0);
|
|
4319
|
-
|
|
4348
|
+
if (!Number.isFinite(apy)) return [];
|
|
4349
|
+
const incentives = aggregateIncentives(points, total);
|
|
4350
|
+
return [{ date, apy, ...incentives.length > 0 ? { incentives } : {} }];
|
|
4320
4351
|
});
|
|
4321
4352
|
}
|
|
4353
|
+
function incentiveKey(incentive) {
|
|
4354
|
+
return JSON.stringify([
|
|
4355
|
+
incentive.source,
|
|
4356
|
+
incentive.agentId,
|
|
4357
|
+
incentive.opportunityId,
|
|
4358
|
+
[...incentive.campaignIds].sort()
|
|
4359
|
+
]);
|
|
4360
|
+
}
|
|
4361
|
+
function aggregateIncentives(points, totalBalance) {
|
|
4362
|
+
const byProgram = /* @__PURE__ */ new Map();
|
|
4363
|
+
for (const point of points) {
|
|
4364
|
+
const weight = point.historicalBalance.amount / totalBalance;
|
|
4365
|
+
for (const incentive of point.incentives ?? []) {
|
|
4366
|
+
if (!Number.isFinite(incentive.apr) || !Number.isFinite(incentive.apyContribution)) continue;
|
|
4367
|
+
const key2 = incentiveKey(incentive);
|
|
4368
|
+
const existing = byProgram.get(key2);
|
|
4369
|
+
if (existing) {
|
|
4370
|
+
existing.apyContribution += incentive.apyContribution * weight;
|
|
4371
|
+
} else {
|
|
4372
|
+
byProgram.set(key2, {
|
|
4373
|
+
...incentive,
|
|
4374
|
+
campaignIds: [...incentive.campaignIds],
|
|
4375
|
+
apyContribution: incentive.apyContribution * weight
|
|
4376
|
+
});
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
}
|
|
4380
|
+
return [...byProgram.values()];
|
|
4381
|
+
}
|
|
4322
4382
|
function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
4323
4383
|
const sums = {};
|
|
4324
4384
|
const weights = {};
|
|
@@ -7211,12 +7271,18 @@ var OwneySDK = class {
|
|
|
7211
7271
|
const scopeChainId = scope === "all" ? null : scope;
|
|
7212
7272
|
if (agentId) {
|
|
7213
7273
|
const agent = this.getAgent(agentId);
|
|
7214
|
-
|
|
7274
|
+
const accountApy = await this.readAgent(
|
|
7215
7275
|
agent,
|
|
7216
7276
|
"accountApy",
|
|
7217
7277
|
() => agent.getAccountApy(state, chainId, days, tokenSymbol, scopeChainId),
|
|
7218
7278
|
{ days, tokenSymbol, scopeChainId }
|
|
7219
7279
|
);
|
|
7280
|
+
return this.enrichApyHistory(
|
|
7281
|
+
accountApy,
|
|
7282
|
+
agentId,
|
|
7283
|
+
scopeChainId === null ? void 0 : scopeChainId ?? chainId,
|
|
7284
|
+
tokenSymbol
|
|
7285
|
+
);
|
|
7220
7286
|
}
|
|
7221
7287
|
const activeAgents = this.getActiveAgents();
|
|
7222
7288
|
const entries = [...activeAgents.entries()];
|
|
@@ -7251,7 +7317,12 @@ var OwneySDK = class {
|
|
|
7251
7317
|
]);
|
|
7252
7318
|
const results = {};
|
|
7253
7319
|
for (const [id, apy] of apyResults) {
|
|
7254
|
-
results[id] =
|
|
7320
|
+
results[id] = await this.enrichApyHistory(
|
|
7321
|
+
apy,
|
|
7322
|
+
id,
|
|
7323
|
+
scopeChainId === null ? void 0 : scopeChainId ?? chainId,
|
|
7324
|
+
tokenSymbol
|
|
7325
|
+
);
|
|
7255
7326
|
}
|
|
7256
7327
|
const balances = {};
|
|
7257
7328
|
for (const [id, bal] of balanceResults) {
|
|
@@ -7281,6 +7352,36 @@ var OwneySDK = class {
|
|
|
7281
7352
|
history
|
|
7282
7353
|
};
|
|
7283
7354
|
}
|
|
7355
|
+
async enrichApyHistory(accountApy, agentId, chainId, tokenSymbol) {
|
|
7356
|
+
const history = accountApy.history;
|
|
7357
|
+
if (agentId !== "zyfai" || chainId === void 0 || !tokenSymbol || !history?.length) return accountApy;
|
|
7358
|
+
const incentives = await fetchApyIncentives(
|
|
7359
|
+
this.apiKey,
|
|
7360
|
+
{
|
|
7361
|
+
walletAddress: accountApy.walletAddress,
|
|
7362
|
+
agentId,
|
|
7363
|
+
chainId,
|
|
7364
|
+
asset: tokenSymbol,
|
|
7365
|
+
from: history[0].date,
|
|
7366
|
+
to: history[history.length - 1].date
|
|
7367
|
+
},
|
|
7368
|
+
this.routingApiBaseUrl
|
|
7369
|
+
);
|
|
7370
|
+
if (incentives.length === 0) return accountApy;
|
|
7371
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
7372
|
+
for (const { date, ...incentive } of incentives) {
|
|
7373
|
+
const entries = byDate.get(date) ?? [];
|
|
7374
|
+
entries.push(incentive);
|
|
7375
|
+
byDate.set(date, entries);
|
|
7376
|
+
}
|
|
7377
|
+
return {
|
|
7378
|
+
...accountApy,
|
|
7379
|
+
history: history.map((point) => {
|
|
7380
|
+
const pointIncentives = byDate.get(point.date);
|
|
7381
|
+
return pointIncentives?.length ? { ...point, incentives: pointIncentives } : point;
|
|
7382
|
+
})
|
|
7383
|
+
};
|
|
7384
|
+
}
|
|
7284
7385
|
/**
|
|
7285
7386
|
* Get transaction history for a specific agent, or all agents.
|
|
7286
7387
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -715,17 +715,31 @@ interface OwneyEarnings {
|
|
|
715
715
|
agentEarnings: Record<AgentId, AgentEarnings>;
|
|
716
716
|
}
|
|
717
717
|
type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
|
|
718
|
+
/** One external reward program contributing percentage points to a day. */
|
|
719
|
+
interface ApyIncentive {
|
|
720
|
+
source: "merkl";
|
|
721
|
+
agentId: AgentId;
|
|
722
|
+
opportunityId: string;
|
|
723
|
+
/** All on-chain campaigns represented by the opportunity APR that day. */
|
|
724
|
+
campaignIds: string[];
|
|
725
|
+
/** Source APR before portfolio weighting, expressed as a percentage. */
|
|
726
|
+
apr: number;
|
|
727
|
+
/** Percentage points to add to this point's native/provider `apy`. */
|
|
728
|
+
apyContribution: number;
|
|
729
|
+
}
|
|
718
730
|
/** A single day's net APY for the connected account, as a percentage number. */
|
|
719
731
|
interface ApyHistoryPoint {
|
|
720
732
|
/** ISO date string for the day, e.g. "2026-06-20". */
|
|
721
733
|
date: string;
|
|
722
|
-
/**
|
|
734
|
+
/** Native/provider net APY. External incentives are deliberately excluded. */
|
|
723
735
|
apy: number;
|
|
724
736
|
/** Balance on this date, in the explicitly named unit; never today's balance. */
|
|
725
737
|
historicalBalance?: {
|
|
726
738
|
amount: number;
|
|
727
739
|
unit: string;
|
|
728
740
|
};
|
|
741
|
+
/** Best-effort external rewards. Absent when none apply or cannot be read. */
|
|
742
|
+
incentives?: ApyIncentive[];
|
|
729
743
|
}
|
|
730
744
|
/**
|
|
731
745
|
* What the APY chart's chain/asset menus are allowed to offer, and how far
|
|
@@ -1848,6 +1862,7 @@ declare class OwneySDK {
|
|
|
1848
1862
|
agentId?: AgentId;
|
|
1849
1863
|
}): Promise<SavedPoolSelection>;
|
|
1850
1864
|
getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
|
|
1865
|
+
private enrichApyHistory;
|
|
1851
1866
|
/**
|
|
1852
1867
|
* Get transaction history for a specific agent, or all agents.
|
|
1853
1868
|
*
|
|
@@ -2006,4 +2021,4 @@ type StoredOrder = {
|
|
|
2006
2021
|
*/
|
|
2007
2022
|
declare function listOrders(now?: number): StoredOrder[];
|
|
2008
2023
|
|
|
2009
|
-
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SavedPoolSelection, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, switchWalletConnectChain, updateWithdrawSwap };
|
|
2024
|
+
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type ApyIncentive, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SavedPoolSelection, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, switchWalletConnectChain, updateWithdrawSwap };
|
package/dist/index.d.ts
CHANGED
|
@@ -715,17 +715,31 @@ interface OwneyEarnings {
|
|
|
715
715
|
agentEarnings: Record<AgentId, AgentEarnings>;
|
|
716
716
|
}
|
|
717
717
|
type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
|
|
718
|
+
/** One external reward program contributing percentage points to a day. */
|
|
719
|
+
interface ApyIncentive {
|
|
720
|
+
source: "merkl";
|
|
721
|
+
agentId: AgentId;
|
|
722
|
+
opportunityId: string;
|
|
723
|
+
/** All on-chain campaigns represented by the opportunity APR that day. */
|
|
724
|
+
campaignIds: string[];
|
|
725
|
+
/** Source APR before portfolio weighting, expressed as a percentage. */
|
|
726
|
+
apr: number;
|
|
727
|
+
/** Percentage points to add to this point's native/provider `apy`. */
|
|
728
|
+
apyContribution: number;
|
|
729
|
+
}
|
|
718
730
|
/** A single day's net APY for the connected account, as a percentage number. */
|
|
719
731
|
interface ApyHistoryPoint {
|
|
720
732
|
/** ISO date string for the day, e.g. "2026-06-20". */
|
|
721
733
|
date: string;
|
|
722
|
-
/**
|
|
734
|
+
/** Native/provider net APY. External incentives are deliberately excluded. */
|
|
723
735
|
apy: number;
|
|
724
736
|
/** Balance on this date, in the explicitly named unit; never today's balance. */
|
|
725
737
|
historicalBalance?: {
|
|
726
738
|
amount: number;
|
|
727
739
|
unit: string;
|
|
728
740
|
};
|
|
741
|
+
/** Best-effort external rewards. Absent when none apply or cannot be read. */
|
|
742
|
+
incentives?: ApyIncentive[];
|
|
729
743
|
}
|
|
730
744
|
/**
|
|
731
745
|
* What the APY chart's chain/asset menus are allowed to offer, and how far
|
|
@@ -1848,6 +1862,7 @@ declare class OwneySDK {
|
|
|
1848
1862
|
agentId?: AgentId;
|
|
1849
1863
|
}): Promise<SavedPoolSelection>;
|
|
1850
1864
|
getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
|
|
1865
|
+
private enrichApyHistory;
|
|
1851
1866
|
/**
|
|
1852
1867
|
* Get transaction history for a specific agent, or all agents.
|
|
1853
1868
|
*
|
|
@@ -2006,4 +2021,4 @@ type StoredOrder = {
|
|
|
2006
2021
|
*/
|
|
2007
2022
|
declare function listOrders(now?: number): StoredOrder[];
|
|
2008
2023
|
|
|
2009
|
-
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SavedPoolSelection, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, switchWalletConnectChain, updateWithdrawSwap };
|
|
2024
|
+
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type ApyIncentive, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SavedPoolSelection, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, switchWalletConnectChain, updateWithdrawSwap };
|
package/dist/index.js
CHANGED
|
@@ -2587,6 +2587,35 @@ function mergeDailyEarnings(series) {
|
|
|
2587
2587
|
|
|
2588
2588
|
// src/lib/routing-api.ts
|
|
2589
2589
|
var ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
2590
|
+
async function fetchApyIncentives(apiKey, input, baseUrl = ROUTING_API_BASE_URL) {
|
|
2591
|
+
const query = new URLSearchParams({
|
|
2592
|
+
walletAddress: input.walletAddress,
|
|
2593
|
+
agentId: input.agentId,
|
|
2594
|
+
chainId: String(input.chainId),
|
|
2595
|
+
asset: input.asset.toUpperCase(),
|
|
2596
|
+
from: input.from,
|
|
2597
|
+
to: input.to
|
|
2598
|
+
});
|
|
2599
|
+
try {
|
|
2600
|
+
const response = await fetch(`${baseUrl}/api/v1/apy-incentives?${query}`, {
|
|
2601
|
+
headers: {
|
|
2602
|
+
Accept: "application/json",
|
|
2603
|
+
"x-owney-api-key": apiKey
|
|
2604
|
+
}
|
|
2605
|
+
});
|
|
2606
|
+
if (!response.ok) return [];
|
|
2607
|
+
const body = await response.json();
|
|
2608
|
+
if (!body.success || !Array.isArray(body.data)) return [];
|
|
2609
|
+
return body.data.filter(
|
|
2610
|
+
(item) => item && typeof item.date === "string" && item.source === "merkl" && typeof item.opportunityId === "string" && Array.isArray(item.campaignIds) && Number.isFinite(item.apr) && Number.isFinite(item.apyContribution)
|
|
2611
|
+
);
|
|
2612
|
+
} catch (error) {
|
|
2613
|
+
debugLog("owney-sdk", "APY incentives unavailable; using native APY", {
|
|
2614
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2615
|
+
});
|
|
2616
|
+
return [];
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2590
2619
|
async function fetchOrgAgentConfig(apiKey, baseUrl = ROUTING_API_BASE_URL) {
|
|
2591
2620
|
const url = `${baseUrl}/api/v1/agent/org-config`;
|
|
2592
2621
|
try {
|
|
@@ -4290,9 +4319,40 @@ function aggregateApyHistory(agentApys) {
|
|
|
4290
4319
|
const total = points.reduce((sum, p) => sum + p.historicalBalance.amount, 0);
|
|
4291
4320
|
if (total <= 0 || !Number.isFinite(total)) return [];
|
|
4292
4321
|
const apy = points.reduce((sum, p) => sum + p.apy * (p.historicalBalance.amount / total), 0);
|
|
4293
|
-
|
|
4322
|
+
if (!Number.isFinite(apy)) return [];
|
|
4323
|
+
const incentives = aggregateIncentives(points, total);
|
|
4324
|
+
return [{ date, apy, ...incentives.length > 0 ? { incentives } : {} }];
|
|
4294
4325
|
});
|
|
4295
4326
|
}
|
|
4327
|
+
function incentiveKey(incentive) {
|
|
4328
|
+
return JSON.stringify([
|
|
4329
|
+
incentive.source,
|
|
4330
|
+
incentive.agentId,
|
|
4331
|
+
incentive.opportunityId,
|
|
4332
|
+
[...incentive.campaignIds].sort()
|
|
4333
|
+
]);
|
|
4334
|
+
}
|
|
4335
|
+
function aggregateIncentives(points, totalBalance) {
|
|
4336
|
+
const byProgram = /* @__PURE__ */ new Map();
|
|
4337
|
+
for (const point of points) {
|
|
4338
|
+
const weight = point.historicalBalance.amount / totalBalance;
|
|
4339
|
+
for (const incentive of point.incentives ?? []) {
|
|
4340
|
+
if (!Number.isFinite(incentive.apr) || !Number.isFinite(incentive.apyContribution)) continue;
|
|
4341
|
+
const key2 = incentiveKey(incentive);
|
|
4342
|
+
const existing = byProgram.get(key2);
|
|
4343
|
+
if (existing) {
|
|
4344
|
+
existing.apyContribution += incentive.apyContribution * weight;
|
|
4345
|
+
} else {
|
|
4346
|
+
byProgram.set(key2, {
|
|
4347
|
+
...incentive,
|
|
4348
|
+
campaignIds: [...incentive.campaignIds],
|
|
4349
|
+
apyContribution: incentive.apyContribution * weight
|
|
4350
|
+
});
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
return [...byProgram.values()];
|
|
4355
|
+
}
|
|
4296
4356
|
function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
4297
4357
|
const sums = {};
|
|
4298
4358
|
const weights = {};
|
|
@@ -7191,12 +7251,18 @@ var OwneySDK = class {
|
|
|
7191
7251
|
const scopeChainId = scope === "all" ? null : scope;
|
|
7192
7252
|
if (agentId) {
|
|
7193
7253
|
const agent = this.getAgent(agentId);
|
|
7194
|
-
|
|
7254
|
+
const accountApy = await this.readAgent(
|
|
7195
7255
|
agent,
|
|
7196
7256
|
"accountApy",
|
|
7197
7257
|
() => agent.getAccountApy(state, chainId, days, tokenSymbol, scopeChainId),
|
|
7198
7258
|
{ days, tokenSymbol, scopeChainId }
|
|
7199
7259
|
);
|
|
7260
|
+
return this.enrichApyHistory(
|
|
7261
|
+
accountApy,
|
|
7262
|
+
agentId,
|
|
7263
|
+
scopeChainId === null ? void 0 : scopeChainId ?? chainId,
|
|
7264
|
+
tokenSymbol
|
|
7265
|
+
);
|
|
7200
7266
|
}
|
|
7201
7267
|
const activeAgents = this.getActiveAgents();
|
|
7202
7268
|
const entries = [...activeAgents.entries()];
|
|
@@ -7231,7 +7297,12 @@ var OwneySDK = class {
|
|
|
7231
7297
|
]);
|
|
7232
7298
|
const results = {};
|
|
7233
7299
|
for (const [id, apy] of apyResults) {
|
|
7234
|
-
results[id] =
|
|
7300
|
+
results[id] = await this.enrichApyHistory(
|
|
7301
|
+
apy,
|
|
7302
|
+
id,
|
|
7303
|
+
scopeChainId === null ? void 0 : scopeChainId ?? chainId,
|
|
7304
|
+
tokenSymbol
|
|
7305
|
+
);
|
|
7235
7306
|
}
|
|
7236
7307
|
const balances = {};
|
|
7237
7308
|
for (const [id, bal] of balanceResults) {
|
|
@@ -7261,6 +7332,36 @@ var OwneySDK = class {
|
|
|
7261
7332
|
history
|
|
7262
7333
|
};
|
|
7263
7334
|
}
|
|
7335
|
+
async enrichApyHistory(accountApy, agentId, chainId, tokenSymbol) {
|
|
7336
|
+
const history = accountApy.history;
|
|
7337
|
+
if (agentId !== "zyfai" || chainId === void 0 || !tokenSymbol || !history?.length) return accountApy;
|
|
7338
|
+
const incentives = await fetchApyIncentives(
|
|
7339
|
+
this.apiKey,
|
|
7340
|
+
{
|
|
7341
|
+
walletAddress: accountApy.walletAddress,
|
|
7342
|
+
agentId,
|
|
7343
|
+
chainId,
|
|
7344
|
+
asset: tokenSymbol,
|
|
7345
|
+
from: history[0].date,
|
|
7346
|
+
to: history[history.length - 1].date
|
|
7347
|
+
},
|
|
7348
|
+
this.routingApiBaseUrl
|
|
7349
|
+
);
|
|
7350
|
+
if (incentives.length === 0) return accountApy;
|
|
7351
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
7352
|
+
for (const { date, ...incentive } of incentives) {
|
|
7353
|
+
const entries = byDate.get(date) ?? [];
|
|
7354
|
+
entries.push(incentive);
|
|
7355
|
+
byDate.set(date, entries);
|
|
7356
|
+
}
|
|
7357
|
+
return {
|
|
7358
|
+
...accountApy,
|
|
7359
|
+
history: history.map((point) => {
|
|
7360
|
+
const pointIncentives = byDate.get(point.date);
|
|
7361
|
+
return pointIncentives?.length ? { ...point, incentives: pointIncentives } : point;
|
|
7362
|
+
})
|
|
7363
|
+
};
|
|
7364
|
+
}
|
|
7264
7365
|
/**
|
|
7265
7366
|
* Get transaction history for a specific agent, or all agents.
|
|
7266
7367
|
*
|