@owney/sdk 0.7.17 → 0.7.19
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 +56 -12
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +56 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -762,7 +762,7 @@ var isJwtExpired = (token) => {
|
|
|
762
762
|
}
|
|
763
763
|
};
|
|
764
764
|
var memorySessions = /* @__PURE__ */ new Map();
|
|
765
|
-
var isFreshSession = (session) => !!session && !!session.token && !isJwtExpired(session.token);
|
|
765
|
+
var isFreshSession = (session) => !!session && typeof session.isPredeployed === "boolean" && !!session.token && !isJwtExpired(session.token);
|
|
766
766
|
var readLegacySession = (store, address) => {
|
|
767
767
|
if (!store) return null;
|
|
768
768
|
const prefix = legacyKeyPrefix(address);
|
|
@@ -1177,6 +1177,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1177
1177
|
internals.httpClient.setAuthToken(cached.token);
|
|
1178
1178
|
internals.authenticatedUserId = cached.userId;
|
|
1179
1179
|
internals.hasActiveSessionKey = cached.hasActiveSessionKey;
|
|
1180
|
+
internals.isPredeployed = cached.isPredeployed;
|
|
1180
1181
|
return;
|
|
1181
1182
|
}
|
|
1182
1183
|
}
|
|
@@ -1188,7 +1189,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1188
1189
|
writeSession(newAddress, newChainId, {
|
|
1189
1190
|
token: newToken,
|
|
1190
1191
|
userId: internals.authenticatedUserId,
|
|
1191
|
-
hasActiveSessionKey: internals.hasActiveSessionKey
|
|
1192
|
+
hasActiveSessionKey: internals.hasActiveSessionKey,
|
|
1193
|
+
isPredeployed: internals.isPredeployed
|
|
1192
1194
|
});
|
|
1193
1195
|
}
|
|
1194
1196
|
};
|
|
@@ -1639,12 +1641,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1639
1641
|
);
|
|
1640
1642
|
return;
|
|
1641
1643
|
}
|
|
1642
|
-
const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
|
|
1643
1644
|
await this.ensureSessionKey(
|
|
1644
1645
|
ownerAddress,
|
|
1645
1646
|
chainId,
|
|
1646
|
-
wallet.address
|
|
1647
|
-
hasActiveSessionKey
|
|
1647
|
+
wallet.address
|
|
1648
1648
|
);
|
|
1649
1649
|
} catch (error) {
|
|
1650
1650
|
console.warn(
|
|
@@ -1653,7 +1653,17 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1653
1653
|
);
|
|
1654
1654
|
}
|
|
1655
1655
|
}
|
|
1656
|
-
async ensureSessionKey(ownerAddress, chainId, smartWallet
|
|
1656
|
+
async ensureSessionKey(ownerAddress, chainId, smartWallet) {
|
|
1657
|
+
const walletState = await this.readWalletState(ownerAddress);
|
|
1658
|
+
const predeployed = walletState.predeployed;
|
|
1659
|
+
if (predeployed !== false) {
|
|
1660
|
+
debugLog("zyfai:onboard", "skipping manual session key", {
|
|
1661
|
+
chainId,
|
|
1662
|
+
predeployed
|
|
1663
|
+
});
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
const hasActiveSessionKey = walletState.hasActiveSessionKey;
|
|
1657
1667
|
const attemptKey = `${ownerAddress.toLowerCase()}:${chainId}`;
|
|
1658
1668
|
if (this.sessionKeyAttempts.has(attemptKey)) {
|
|
1659
1669
|
debugLog(
|
|
@@ -1746,12 +1756,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1746
1756
|
"zyfai:onboard",
|
|
1747
1757
|
"Safe already has code -> no deploy needed, checking the session key"
|
|
1748
1758
|
);
|
|
1749
|
-
const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
|
|
1750
1759
|
await this.ensureSessionKey(
|
|
1751
1760
|
ownerAddress,
|
|
1752
1761
|
chainId,
|
|
1753
|
-
wallet.address
|
|
1754
|
-
hasActiveSessionKey
|
|
1762
|
+
wallet.address
|
|
1755
1763
|
);
|
|
1756
1764
|
return wallet.address;
|
|
1757
1765
|
}
|
|
@@ -2215,6 +2223,39 @@ function sumWithdrawnAmount(results) {
|
|
|
2215
2223
|
}
|
|
2216
2224
|
|
|
2217
2225
|
// src/lib/helpers/account-apy-helper.ts
|
|
2226
|
+
function balanceForApyScope(balance, chainId, tokenSymbol) {
|
|
2227
|
+
if (!tokenSymbol) {
|
|
2228
|
+
const total = Number(balance.totalBalance);
|
|
2229
|
+
return Number.isFinite(total) && total > 0 ? total : 0;
|
|
2230
|
+
}
|
|
2231
|
+
const normalizedToken = tokenSymbol.toUpperCase();
|
|
2232
|
+
return balance.tokens.reduce((total, token) => {
|
|
2233
|
+
if (Number(token.chainId) !== chainId || String(token.asset).toUpperCase() !== normalizedToken) {
|
|
2234
|
+
return total;
|
|
2235
|
+
}
|
|
2236
|
+
const amount = Number(token.amount);
|
|
2237
|
+
return Number.isFinite(amount) && amount > 0 ? total + amount : total;
|
|
2238
|
+
}, 0);
|
|
2239
|
+
}
|
|
2240
|
+
function aggregateApyHistory(agentApys, agentBalances) {
|
|
2241
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
2242
|
+
for (const [id, accountApy] of Object.entries(agentApys)) {
|
|
2243
|
+
const balance = agentBalances[id] ?? 0;
|
|
2244
|
+
if (!Number.isFinite(balance) || balance <= 0) continue;
|
|
2245
|
+
for (const point of accountApy.history ?? []) {
|
|
2246
|
+
const apy = Number(point.apy);
|
|
2247
|
+
if (!point.date || !Number.isFinite(apy)) continue;
|
|
2248
|
+
const current = byDate.get(point.date) ?? { weightedSum: 0, weight: 0 };
|
|
2249
|
+
current.weightedSum += apy * balance;
|
|
2250
|
+
current.weight += balance;
|
|
2251
|
+
byDate.set(point.date, current);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
return [...byDate.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([date, value]) => ({
|
|
2255
|
+
date,
|
|
2256
|
+
apy: value.weightedSum / value.weight
|
|
2257
|
+
}));
|
|
2258
|
+
}
|
|
2218
2259
|
function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
2219
2260
|
const sums = {};
|
|
2220
2261
|
const weights = {};
|
|
@@ -3885,7 +3926,7 @@ var OwneySDK = class {
|
|
|
3885
3926
|
Promise.all(
|
|
3886
3927
|
entries.map(async ([id, agent]) => {
|
|
3887
3928
|
const b = await this.readAgent(agent, "balances", () => agent.getBalances(state, chainId));
|
|
3888
|
-
return [id,
|
|
3929
|
+
return [id, balanceForApyScope(b, chainId, tokenSymbol)];
|
|
3889
3930
|
})
|
|
3890
3931
|
)
|
|
3891
3932
|
]);
|
|
@@ -3913,10 +3954,12 @@ var OwneySDK = class {
|
|
|
3913
3954
|
}
|
|
3914
3955
|
}
|
|
3915
3956
|
const apyByChainAndAsset = aggregateApyByChainAndAsset(results, balances);
|
|
3957
|
+
const history = aggregateApyHistory(results, balances);
|
|
3916
3958
|
return {
|
|
3917
3959
|
totalApy: String(totalApy),
|
|
3918
3960
|
agentApy: results,
|
|
3919
|
-
apyByChainAndAsset
|
|
3961
|
+
apyByChainAndAsset,
|
|
3962
|
+
history
|
|
3920
3963
|
};
|
|
3921
3964
|
}
|
|
3922
3965
|
/**
|
|
@@ -4369,7 +4412,8 @@ function buildSIWXConfig(deps) {
|
|
|
4369
4412
|
writeSession(address, id, {
|
|
4370
4413
|
token: login.accessToken,
|
|
4371
4414
|
userId: login.userId ?? null,
|
|
4372
|
-
hasActiveSessionKey: Boolean(login.hasActiveSessionKey)
|
|
4415
|
+
hasActiveSessionKey: Boolean(login.hasActiveSessionKey),
|
|
4416
|
+
isPredeployed: login.predeployed
|
|
4373
4417
|
});
|
|
4374
4418
|
const stored = {
|
|
4375
4419
|
data: session.data,
|
package/dist/index.d.cts
CHANGED
|
@@ -296,6 +296,8 @@ interface OwneyAccountApy {
|
|
|
296
296
|
totalApy: string;
|
|
297
297
|
agentApy: Record<AgentId, AccountAgentApy>;
|
|
298
298
|
apyByChainAndAsset: ApyByChainAndAsset;
|
|
299
|
+
/** Daily APY weighted by current balances in the requested chain/asset scope. */
|
|
300
|
+
history?: ApyHistoryPoint[];
|
|
299
301
|
}
|
|
300
302
|
interface AllocationAgentApy {
|
|
301
303
|
/** Account-wide weighted APY for this agent, as a decimal string. */
|
package/dist/index.d.ts
CHANGED
|
@@ -296,6 +296,8 @@ interface OwneyAccountApy {
|
|
|
296
296
|
totalApy: string;
|
|
297
297
|
agentApy: Record<AgentId, AccountAgentApy>;
|
|
298
298
|
apyByChainAndAsset: ApyByChainAndAsset;
|
|
299
|
+
/** Daily APY weighted by current balances in the requested chain/asset scope. */
|
|
300
|
+
history?: ApyHistoryPoint[];
|
|
299
301
|
}
|
|
300
302
|
interface AllocationAgentApy {
|
|
301
303
|
/** Account-wide weighted APY for this agent, as a decimal string. */
|
package/dist/index.js
CHANGED
|
@@ -729,7 +729,7 @@ var isJwtExpired = (token) => {
|
|
|
729
729
|
}
|
|
730
730
|
};
|
|
731
731
|
var memorySessions = /* @__PURE__ */ new Map();
|
|
732
|
-
var isFreshSession = (session) => !!session && !!session.token && !isJwtExpired(session.token);
|
|
732
|
+
var isFreshSession = (session) => !!session && typeof session.isPredeployed === "boolean" && !!session.token && !isJwtExpired(session.token);
|
|
733
733
|
var readLegacySession = (store, address) => {
|
|
734
734
|
if (!store) return null;
|
|
735
735
|
const prefix = legacyKeyPrefix(address);
|
|
@@ -1144,6 +1144,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1144
1144
|
internals.httpClient.setAuthToken(cached.token);
|
|
1145
1145
|
internals.authenticatedUserId = cached.userId;
|
|
1146
1146
|
internals.hasActiveSessionKey = cached.hasActiveSessionKey;
|
|
1147
|
+
internals.isPredeployed = cached.isPredeployed;
|
|
1147
1148
|
return;
|
|
1148
1149
|
}
|
|
1149
1150
|
}
|
|
@@ -1155,7 +1156,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1155
1156
|
writeSession(newAddress, newChainId, {
|
|
1156
1157
|
token: newToken,
|
|
1157
1158
|
userId: internals.authenticatedUserId,
|
|
1158
|
-
hasActiveSessionKey: internals.hasActiveSessionKey
|
|
1159
|
+
hasActiveSessionKey: internals.hasActiveSessionKey,
|
|
1160
|
+
isPredeployed: internals.isPredeployed
|
|
1159
1161
|
});
|
|
1160
1162
|
}
|
|
1161
1163
|
};
|
|
@@ -1606,12 +1608,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1606
1608
|
);
|
|
1607
1609
|
return;
|
|
1608
1610
|
}
|
|
1609
|
-
const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
|
|
1610
1611
|
await this.ensureSessionKey(
|
|
1611
1612
|
ownerAddress,
|
|
1612
1613
|
chainId,
|
|
1613
|
-
wallet.address
|
|
1614
|
-
hasActiveSessionKey
|
|
1614
|
+
wallet.address
|
|
1615
1615
|
);
|
|
1616
1616
|
} catch (error) {
|
|
1617
1617
|
console.warn(
|
|
@@ -1620,7 +1620,17 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1620
1620
|
);
|
|
1621
1621
|
}
|
|
1622
1622
|
}
|
|
1623
|
-
async ensureSessionKey(ownerAddress, chainId, smartWallet
|
|
1623
|
+
async ensureSessionKey(ownerAddress, chainId, smartWallet) {
|
|
1624
|
+
const walletState = await this.readWalletState(ownerAddress);
|
|
1625
|
+
const predeployed = walletState.predeployed;
|
|
1626
|
+
if (predeployed !== false) {
|
|
1627
|
+
debugLog("zyfai:onboard", "skipping manual session key", {
|
|
1628
|
+
chainId,
|
|
1629
|
+
predeployed
|
|
1630
|
+
});
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
const hasActiveSessionKey = walletState.hasActiveSessionKey;
|
|
1624
1634
|
const attemptKey = `${ownerAddress.toLowerCase()}:${chainId}`;
|
|
1625
1635
|
if (this.sessionKeyAttempts.has(attemptKey)) {
|
|
1626
1636
|
debugLog(
|
|
@@ -1713,12 +1723,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1713
1723
|
"zyfai:onboard",
|
|
1714
1724
|
"Safe already has code -> no deploy needed, checking the session key"
|
|
1715
1725
|
);
|
|
1716
|
-
const { hasActiveSessionKey } = await this.readWalletState(ownerAddress);
|
|
1717
1726
|
await this.ensureSessionKey(
|
|
1718
1727
|
ownerAddress,
|
|
1719
1728
|
chainId,
|
|
1720
|
-
wallet.address
|
|
1721
|
-
hasActiveSessionKey
|
|
1729
|
+
wallet.address
|
|
1722
1730
|
);
|
|
1723
1731
|
return wallet.address;
|
|
1724
1732
|
}
|
|
@@ -2182,6 +2190,39 @@ function sumWithdrawnAmount(results) {
|
|
|
2182
2190
|
}
|
|
2183
2191
|
|
|
2184
2192
|
// src/lib/helpers/account-apy-helper.ts
|
|
2193
|
+
function balanceForApyScope(balance, chainId, tokenSymbol) {
|
|
2194
|
+
if (!tokenSymbol) {
|
|
2195
|
+
const total = Number(balance.totalBalance);
|
|
2196
|
+
return Number.isFinite(total) && total > 0 ? total : 0;
|
|
2197
|
+
}
|
|
2198
|
+
const normalizedToken = tokenSymbol.toUpperCase();
|
|
2199
|
+
return balance.tokens.reduce((total, token) => {
|
|
2200
|
+
if (Number(token.chainId) !== chainId || String(token.asset).toUpperCase() !== normalizedToken) {
|
|
2201
|
+
return total;
|
|
2202
|
+
}
|
|
2203
|
+
const amount = Number(token.amount);
|
|
2204
|
+
return Number.isFinite(amount) && amount > 0 ? total + amount : total;
|
|
2205
|
+
}, 0);
|
|
2206
|
+
}
|
|
2207
|
+
function aggregateApyHistory(agentApys, agentBalances) {
|
|
2208
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
2209
|
+
for (const [id, accountApy] of Object.entries(agentApys)) {
|
|
2210
|
+
const balance = agentBalances[id] ?? 0;
|
|
2211
|
+
if (!Number.isFinite(balance) || balance <= 0) continue;
|
|
2212
|
+
for (const point of accountApy.history ?? []) {
|
|
2213
|
+
const apy = Number(point.apy);
|
|
2214
|
+
if (!point.date || !Number.isFinite(apy)) continue;
|
|
2215
|
+
const current = byDate.get(point.date) ?? { weightedSum: 0, weight: 0 };
|
|
2216
|
+
current.weightedSum += apy * balance;
|
|
2217
|
+
current.weight += balance;
|
|
2218
|
+
byDate.set(point.date, current);
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
return [...byDate.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([date, value]) => ({
|
|
2222
|
+
date,
|
|
2223
|
+
apy: value.weightedSum / value.weight
|
|
2224
|
+
}));
|
|
2225
|
+
}
|
|
2185
2226
|
function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
2186
2227
|
const sums = {};
|
|
2187
2228
|
const weights = {};
|
|
@@ -3856,7 +3897,7 @@ var OwneySDK = class {
|
|
|
3856
3897
|
Promise.all(
|
|
3857
3898
|
entries.map(async ([id, agent]) => {
|
|
3858
3899
|
const b = await this.readAgent(agent, "balances", () => agent.getBalances(state, chainId));
|
|
3859
|
-
return [id,
|
|
3900
|
+
return [id, balanceForApyScope(b, chainId, tokenSymbol)];
|
|
3860
3901
|
})
|
|
3861
3902
|
)
|
|
3862
3903
|
]);
|
|
@@ -3884,10 +3925,12 @@ var OwneySDK = class {
|
|
|
3884
3925
|
}
|
|
3885
3926
|
}
|
|
3886
3927
|
const apyByChainAndAsset = aggregateApyByChainAndAsset(results, balances);
|
|
3928
|
+
const history = aggregateApyHistory(results, balances);
|
|
3887
3929
|
return {
|
|
3888
3930
|
totalApy: String(totalApy),
|
|
3889
3931
|
agentApy: results,
|
|
3890
|
-
apyByChainAndAsset
|
|
3932
|
+
apyByChainAndAsset,
|
|
3933
|
+
history
|
|
3891
3934
|
};
|
|
3892
3935
|
}
|
|
3893
3936
|
/**
|
|
@@ -4340,7 +4383,8 @@ function buildSIWXConfig(deps) {
|
|
|
4340
4383
|
writeSession(address, id, {
|
|
4341
4384
|
token: login.accessToken,
|
|
4342
4385
|
userId: login.userId ?? null,
|
|
4343
|
-
hasActiveSessionKey: Boolean(login.hasActiveSessionKey)
|
|
4386
|
+
hasActiveSessionKey: Boolean(login.hasActiveSessionKey),
|
|
4387
|
+
isPredeployed: login.predeployed
|
|
4344
4388
|
});
|
|
4345
4389
|
const stored = {
|
|
4346
4390
|
data: session.data,
|