@owney/sdk 0.2.11 → 0.2.12
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 +22 -38
- package/dist/index.js +22 -38
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -128,15 +128,6 @@ function hexToDecimal(hex, decimals = 6) {
|
|
|
128
128
|
const remainder = parsed % divisor;
|
|
129
129
|
return Number(whole) + Number(remainder) / Number(divisor);
|
|
130
130
|
}
|
|
131
|
-
function normalizeDecimalPlace(value, decimals = 6) {
|
|
132
|
-
const parsed = BigInt(value);
|
|
133
|
-
if (decimals <= 0)
|
|
134
|
-
return Number(parsed);
|
|
135
|
-
const divisor = BigInt(10 ** decimals);
|
|
136
|
-
const whole = parsed / divisor;
|
|
137
|
-
const remainder = parsed % divisor;
|
|
138
|
-
return Number(whole) + Number(remainder) / Number(divisor);
|
|
139
|
-
}
|
|
140
131
|
var DayFilterMapping = {
|
|
141
132
|
"30D": 30,
|
|
142
133
|
"14D": 14,
|
|
@@ -162,34 +153,25 @@ var CHAIN_ID_TO_NAME = {
|
|
|
162
153
|
8453: "BASE",
|
|
163
154
|
42161: "ARBITRUM"
|
|
164
155
|
};
|
|
165
|
-
|
|
166
|
-
BASE: 8453,
|
|
167
|
-
ARBITRUM: 42161
|
|
168
|
-
};
|
|
169
|
-
function mapBalances(raw, chainId, smartWallet) {
|
|
156
|
+
function mapBalances(raw, _chainId, smartWallet) {
|
|
170
157
|
const portfolio = raw.portfolio;
|
|
171
|
-
const
|
|
172
|
-
for (const p of portfolio.positions || []) {
|
|
173
|
-
const symbol = p.token_symbol || "USDC";
|
|
174
|
-
const positionChainId = (p.chain ? CHAIN_NAME_TO_ID[p.chain.toUpperCase()] : void 0) ?? chainId;
|
|
175
|
-
const key = `${symbol}:${positionChainId}`;
|
|
176
|
-
const current = tokenMap.get(key);
|
|
177
|
-
tokenMap.set(key, {
|
|
178
|
-
symbol,
|
|
179
|
-
chainId: positionChainId,
|
|
180
|
-
amount: (current?.amount ?? 0) + normalizeDecimalPlace(p.underlyingAmount || "0")
|
|
181
|
-
});
|
|
182
|
-
}
|
|
158
|
+
const portfolioByChain = portfolio.portfolioByChain ?? {};
|
|
183
159
|
let totalBalance = 0;
|
|
184
160
|
const tokens = [];
|
|
185
|
-
for (const [,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
161
|
+
for (const [chainIdKey, tokensBySymbol] of Object.entries(portfolioByChain)) {
|
|
162
|
+
const positionChainId = Number(chainIdKey);
|
|
163
|
+
for (const [symbol, { balance, decimals }] of Object.entries(
|
|
164
|
+
tokensBySymbol ?? {}
|
|
165
|
+
)) {
|
|
166
|
+
const amount = hexToDecimal(balance || "0", decimals);
|
|
167
|
+
totalBalance += amount;
|
|
168
|
+
tokens.push({
|
|
169
|
+
chain: CHAIN_ID_TO_NAME[positionChainId] ?? "BASE",
|
|
170
|
+
chainId: positionChainId,
|
|
171
|
+
asset: symbol,
|
|
172
|
+
amount: String(amount)
|
|
173
|
+
});
|
|
174
|
+
}
|
|
193
175
|
}
|
|
194
176
|
return {
|
|
195
177
|
smartWallet,
|
|
@@ -215,7 +197,7 @@ function mapApyHistory(raw) {
|
|
|
215
197
|
weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0
|
|
216
198
|
};
|
|
217
199
|
}
|
|
218
|
-
function mapHistory(raw) {
|
|
200
|
+
function mapHistory(raw, chainId) {
|
|
219
201
|
const actionMap = {
|
|
220
202
|
"Deposit to protocol": "Deposit",
|
|
221
203
|
"Top up wallet": "Top up",
|
|
@@ -224,7 +206,7 @@ function mapHistory(raw) {
|
|
|
224
206
|
};
|
|
225
207
|
return {
|
|
226
208
|
total: raw.total,
|
|
227
|
-
data: raw.data.map((entry) => {
|
|
209
|
+
data: raw.data.filter((d) => d.chainId === chainId).map((entry) => {
|
|
228
210
|
const rawLog = entry.rebalanceLog;
|
|
229
211
|
const positions = entry.positions ?? [];
|
|
230
212
|
let rebalanceLog = [];
|
|
@@ -257,7 +239,9 @@ function mapHistory(raw) {
|
|
|
257
239
|
txHashes: entry.transactionHash ? [entry.transactionHash] : [],
|
|
258
240
|
chainId: entry.chainId,
|
|
259
241
|
tokenSymbol: entry?.positions?.[0]?.token_symbol,
|
|
260
|
-
amount: String(
|
|
242
|
+
amount: String(
|
|
243
|
+
hexToDecimal(entry?.positions?.[0]?.amount || "0x")
|
|
244
|
+
)
|
|
261
245
|
}
|
|
262
246
|
],
|
|
263
247
|
rebalanceLog
|
|
@@ -483,7 +467,7 @@ var ZyfaiAgent = class {
|
|
|
483
467
|
async getHistory(state, chainId, options) {
|
|
484
468
|
const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
|
|
485
469
|
const raw = await this.sdk.getHistory(smartWallet, validChainId, options);
|
|
486
|
-
return mapHistory(raw);
|
|
470
|
+
return mapHistory(raw, validChainId);
|
|
487
471
|
}
|
|
488
472
|
// --- IAgent: Agent control ---
|
|
489
473
|
async pause(state, chainId) {
|
package/dist/index.js
CHANGED
|
@@ -98,15 +98,6 @@ function hexToDecimal(hex, decimals = 6) {
|
|
|
98
98
|
const remainder = parsed % divisor;
|
|
99
99
|
return Number(whole) + Number(remainder) / Number(divisor);
|
|
100
100
|
}
|
|
101
|
-
function normalizeDecimalPlace(value, decimals = 6) {
|
|
102
|
-
const parsed = BigInt(value);
|
|
103
|
-
if (decimals <= 0)
|
|
104
|
-
return Number(parsed);
|
|
105
|
-
const divisor = BigInt(10 ** decimals);
|
|
106
|
-
const whole = parsed / divisor;
|
|
107
|
-
const remainder = parsed % divisor;
|
|
108
|
-
return Number(whole) + Number(remainder) / Number(divisor);
|
|
109
|
-
}
|
|
110
101
|
var DayFilterMapping = {
|
|
111
102
|
"30D": 30,
|
|
112
103
|
"14D": 14,
|
|
@@ -132,34 +123,25 @@ var CHAIN_ID_TO_NAME = {
|
|
|
132
123
|
8453: "BASE",
|
|
133
124
|
42161: "ARBITRUM"
|
|
134
125
|
};
|
|
135
|
-
|
|
136
|
-
BASE: 8453,
|
|
137
|
-
ARBITRUM: 42161
|
|
138
|
-
};
|
|
139
|
-
function mapBalances(raw, chainId, smartWallet) {
|
|
126
|
+
function mapBalances(raw, _chainId, smartWallet) {
|
|
140
127
|
const portfolio = raw.portfolio;
|
|
141
|
-
const
|
|
142
|
-
for (const p of portfolio.positions || []) {
|
|
143
|
-
const symbol = p.token_symbol || "USDC";
|
|
144
|
-
const positionChainId = (p.chain ? CHAIN_NAME_TO_ID[p.chain.toUpperCase()] : void 0) ?? chainId;
|
|
145
|
-
const key = `${symbol}:${positionChainId}`;
|
|
146
|
-
const current = tokenMap.get(key);
|
|
147
|
-
tokenMap.set(key, {
|
|
148
|
-
symbol,
|
|
149
|
-
chainId: positionChainId,
|
|
150
|
-
amount: (current?.amount ?? 0) + normalizeDecimalPlace(p.underlyingAmount || "0")
|
|
151
|
-
});
|
|
152
|
-
}
|
|
128
|
+
const portfolioByChain = portfolio.portfolioByChain ?? {};
|
|
153
129
|
let totalBalance = 0;
|
|
154
130
|
const tokens = [];
|
|
155
|
-
for (const [,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
131
|
+
for (const [chainIdKey, tokensBySymbol] of Object.entries(portfolioByChain)) {
|
|
132
|
+
const positionChainId = Number(chainIdKey);
|
|
133
|
+
for (const [symbol, { balance, decimals }] of Object.entries(
|
|
134
|
+
tokensBySymbol ?? {}
|
|
135
|
+
)) {
|
|
136
|
+
const amount = hexToDecimal(balance || "0", decimals);
|
|
137
|
+
totalBalance += amount;
|
|
138
|
+
tokens.push({
|
|
139
|
+
chain: CHAIN_ID_TO_NAME[positionChainId] ?? "BASE",
|
|
140
|
+
chainId: positionChainId,
|
|
141
|
+
asset: symbol,
|
|
142
|
+
amount: String(amount)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
163
145
|
}
|
|
164
146
|
return {
|
|
165
147
|
smartWallet,
|
|
@@ -185,7 +167,7 @@ function mapApyHistory(raw) {
|
|
|
185
167
|
weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0
|
|
186
168
|
};
|
|
187
169
|
}
|
|
188
|
-
function mapHistory(raw) {
|
|
170
|
+
function mapHistory(raw, chainId) {
|
|
189
171
|
const actionMap = {
|
|
190
172
|
"Deposit to protocol": "Deposit",
|
|
191
173
|
"Top up wallet": "Top up",
|
|
@@ -194,7 +176,7 @@ function mapHistory(raw) {
|
|
|
194
176
|
};
|
|
195
177
|
return {
|
|
196
178
|
total: raw.total,
|
|
197
|
-
data: raw.data.map((entry) => {
|
|
179
|
+
data: raw.data.filter((d) => d.chainId === chainId).map((entry) => {
|
|
198
180
|
const rawLog = entry.rebalanceLog;
|
|
199
181
|
const positions = entry.positions ?? [];
|
|
200
182
|
let rebalanceLog = [];
|
|
@@ -227,7 +209,9 @@ function mapHistory(raw) {
|
|
|
227
209
|
txHashes: entry.transactionHash ? [entry.transactionHash] : [],
|
|
228
210
|
chainId: entry.chainId,
|
|
229
211
|
tokenSymbol: entry?.positions?.[0]?.token_symbol,
|
|
230
|
-
amount: String(
|
|
212
|
+
amount: String(
|
|
213
|
+
hexToDecimal(entry?.positions?.[0]?.amount || "0x")
|
|
214
|
+
)
|
|
231
215
|
}
|
|
232
216
|
],
|
|
233
217
|
rebalanceLog
|
|
@@ -453,7 +437,7 @@ var ZyfaiAgent = class {
|
|
|
453
437
|
async getHistory(state, chainId, options) {
|
|
454
438
|
const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
|
|
455
439
|
const raw = await this.sdk.getHistory(smartWallet, validChainId, options);
|
|
456
|
-
return mapHistory(raw);
|
|
440
|
+
return mapHistory(raw, validChainId);
|
|
457
441
|
}
|
|
458
442
|
// --- IAgent: Agent control ---
|
|
459
443
|
async pause(state, chainId) {
|