@owney/sdk 0.4.1 → 0.4.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 +51 -7
- package/dist/index.js +51 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -768,6 +768,39 @@ async function fetchAgentKeys(apiKey) {
|
|
|
768
768
|
return json.data;
|
|
769
769
|
}
|
|
770
770
|
|
|
771
|
+
// src/lib/health-report.ts
|
|
772
|
+
var ROUTING_API_BASE_URL2 = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
773
|
+
async function reportAgentFailure(apiKey, agentType, errorCode) {
|
|
774
|
+
try {
|
|
775
|
+
await fetch(`${ROUTING_API_BASE_URL2}/api/v1/agent/health-report`, {
|
|
776
|
+
method: "POST",
|
|
777
|
+
headers: {
|
|
778
|
+
"Content-Type": "application/json",
|
|
779
|
+
"x-owney-api-key": apiKey
|
|
780
|
+
},
|
|
781
|
+
body: JSON.stringify({
|
|
782
|
+
agent_type: agentType,
|
|
783
|
+
error_code: errorCode,
|
|
784
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
785
|
+
})
|
|
786
|
+
});
|
|
787
|
+
} catch (err) {
|
|
788
|
+
console.warn(
|
|
789
|
+
`[owney-sdk] health-report failed for agent "${agentType}":`,
|
|
790
|
+
err instanceof Error ? err.message : err
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
async function withFailureReporting(apiKey, agentType, fn) {
|
|
795
|
+
try {
|
|
796
|
+
return await fn();
|
|
797
|
+
} catch (err) {
|
|
798
|
+
const errorCode = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
799
|
+
void reportAgentFailure(apiKey, agentType, errorCode);
|
|
800
|
+
throw err;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
771
804
|
// src/lib/helpers/withdraw-helper.ts
|
|
772
805
|
var import_viem = require("viem");
|
|
773
806
|
function projectAgentBalancesForAsset(agents, aggregated, chainId, asset, decimals) {
|
|
@@ -1159,7 +1192,11 @@ var OwneySDK = class {
|
|
|
1159
1192
|
const agent = this.getAgent(agentId);
|
|
1160
1193
|
this.validateAssetSupport(agent, chainId, asset);
|
|
1161
1194
|
await this.validateMinDepositAmount(agent, state, chainId, asset, amount);
|
|
1162
|
-
return
|
|
1195
|
+
return withFailureReporting(
|
|
1196
|
+
this.apiKey,
|
|
1197
|
+
agent.id,
|
|
1198
|
+
() => agent.deposit(state, chainId, amount, depositCallback)
|
|
1199
|
+
);
|
|
1163
1200
|
}
|
|
1164
1201
|
const totalAmount = BigInt(amount);
|
|
1165
1202
|
const eligibleAgents = this.getEligibleAgents(chainId, asset, {
|
|
@@ -1189,11 +1226,10 @@ var OwneySDK = class {
|
|
|
1189
1226
|
}
|
|
1190
1227
|
const agentResults = {};
|
|
1191
1228
|
for (const { agent, amount: agentAmount } of agentAmounts) {
|
|
1192
|
-
agentResults[agent.id] = await
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
agentAmount,
|
|
1196
|
-
depositCallback
|
|
1229
|
+
agentResults[agent.id] = await withFailureReporting(
|
|
1230
|
+
this.apiKey,
|
|
1231
|
+
agent.id,
|
|
1232
|
+
() => agent.deposit(state, chainId, agentAmount, depositCallback)
|
|
1197
1233
|
);
|
|
1198
1234
|
}
|
|
1199
1235
|
return { agentResults };
|
|
@@ -1324,7 +1360,11 @@ var OwneySDK = class {
|
|
|
1324
1360
|
if (agentId) {
|
|
1325
1361
|
const agent = this.getAgent(agentId);
|
|
1326
1362
|
this.validateAssetSupport(agent, chainId, asset);
|
|
1327
|
-
return
|
|
1363
|
+
return withFailureReporting(
|
|
1364
|
+
this.apiKey,
|
|
1365
|
+
agent.id,
|
|
1366
|
+
() => agent.withdraw(state, chainId, token, amount)
|
|
1367
|
+
);
|
|
1328
1368
|
}
|
|
1329
1369
|
const eligibleAgents = this.getEligibleAgents(chainId, asset);
|
|
1330
1370
|
if (!amount) {
|
|
@@ -1336,6 +1376,8 @@ var OwneySDK = class {
|
|
|
1336
1376
|
} catch (err) {
|
|
1337
1377
|
console.error(`withdraw failed for agent "${agent.id}":`, err);
|
|
1338
1378
|
agentErrors2[agent.id] = err instanceof Error ? err.message : String(err);
|
|
1379
|
+
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
1380
|
+
void reportAgentFailure(this.apiKey, agent.id, code);
|
|
1339
1381
|
}
|
|
1340
1382
|
}
|
|
1341
1383
|
if (Object.keys(results2).length === 0) {
|
|
@@ -1407,6 +1449,8 @@ var OwneySDK = class {
|
|
|
1407
1449
|
} catch (err) {
|
|
1408
1450
|
console.error(`withdraw failed for agent "${p.agent.id}":`, err);
|
|
1409
1451
|
agentErrors[p.agent.id] = err instanceof Error ? err.message : String(err);
|
|
1452
|
+
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
1453
|
+
void reportAgentFailure(this.apiKey, p.agent.id, code);
|
|
1410
1454
|
const failedAmount = p.planned;
|
|
1411
1455
|
p.planned = 0n;
|
|
1412
1456
|
redistributeShare(plans, i, failedAmount);
|
package/dist/index.js
CHANGED
|
@@ -737,6 +737,39 @@ async function fetchAgentKeys(apiKey) {
|
|
|
737
737
|
return json.data;
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
+
// src/lib/health-report.ts
|
|
741
|
+
var ROUTING_API_BASE_URL2 = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
742
|
+
async function reportAgentFailure(apiKey, agentType, errorCode) {
|
|
743
|
+
try {
|
|
744
|
+
await fetch(`${ROUTING_API_BASE_URL2}/api/v1/agent/health-report`, {
|
|
745
|
+
method: "POST",
|
|
746
|
+
headers: {
|
|
747
|
+
"Content-Type": "application/json",
|
|
748
|
+
"x-owney-api-key": apiKey
|
|
749
|
+
},
|
|
750
|
+
body: JSON.stringify({
|
|
751
|
+
agent_type: agentType,
|
|
752
|
+
error_code: errorCode,
|
|
753
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
754
|
+
})
|
|
755
|
+
});
|
|
756
|
+
} catch (err) {
|
|
757
|
+
console.warn(
|
|
758
|
+
`[owney-sdk] health-report failed for agent "${agentType}":`,
|
|
759
|
+
err instanceof Error ? err.message : err
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
async function withFailureReporting(apiKey, agentType, fn) {
|
|
764
|
+
try {
|
|
765
|
+
return await fn();
|
|
766
|
+
} catch (err) {
|
|
767
|
+
const errorCode = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
768
|
+
void reportAgentFailure(apiKey, agentType, errorCode);
|
|
769
|
+
throw err;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
740
773
|
// src/lib/helpers/withdraw-helper.ts
|
|
741
774
|
import { parseUnits } from "viem";
|
|
742
775
|
function projectAgentBalancesForAsset(agents, aggregated, chainId, asset, decimals) {
|
|
@@ -1128,7 +1161,11 @@ var OwneySDK = class {
|
|
|
1128
1161
|
const agent = this.getAgent(agentId);
|
|
1129
1162
|
this.validateAssetSupport(agent, chainId, asset);
|
|
1130
1163
|
await this.validateMinDepositAmount(agent, state, chainId, asset, amount);
|
|
1131
|
-
return
|
|
1164
|
+
return withFailureReporting(
|
|
1165
|
+
this.apiKey,
|
|
1166
|
+
agent.id,
|
|
1167
|
+
() => agent.deposit(state, chainId, amount, depositCallback)
|
|
1168
|
+
);
|
|
1132
1169
|
}
|
|
1133
1170
|
const totalAmount = BigInt(amount);
|
|
1134
1171
|
const eligibleAgents = this.getEligibleAgents(chainId, asset, {
|
|
@@ -1158,11 +1195,10 @@ var OwneySDK = class {
|
|
|
1158
1195
|
}
|
|
1159
1196
|
const agentResults = {};
|
|
1160
1197
|
for (const { agent, amount: agentAmount } of agentAmounts) {
|
|
1161
|
-
agentResults[agent.id] = await
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
agentAmount,
|
|
1165
|
-
depositCallback
|
|
1198
|
+
agentResults[agent.id] = await withFailureReporting(
|
|
1199
|
+
this.apiKey,
|
|
1200
|
+
agent.id,
|
|
1201
|
+
() => agent.deposit(state, chainId, agentAmount, depositCallback)
|
|
1166
1202
|
);
|
|
1167
1203
|
}
|
|
1168
1204
|
return { agentResults };
|
|
@@ -1293,7 +1329,11 @@ var OwneySDK = class {
|
|
|
1293
1329
|
if (agentId) {
|
|
1294
1330
|
const agent = this.getAgent(agentId);
|
|
1295
1331
|
this.validateAssetSupport(agent, chainId, asset);
|
|
1296
|
-
return
|
|
1332
|
+
return withFailureReporting(
|
|
1333
|
+
this.apiKey,
|
|
1334
|
+
agent.id,
|
|
1335
|
+
() => agent.withdraw(state, chainId, token, amount)
|
|
1336
|
+
);
|
|
1297
1337
|
}
|
|
1298
1338
|
const eligibleAgents = this.getEligibleAgents(chainId, asset);
|
|
1299
1339
|
if (!amount) {
|
|
@@ -1305,6 +1345,8 @@ var OwneySDK = class {
|
|
|
1305
1345
|
} catch (err) {
|
|
1306
1346
|
console.error(`withdraw failed for agent "${agent.id}":`, err);
|
|
1307
1347
|
agentErrors2[agent.id] = err instanceof Error ? err.message : String(err);
|
|
1348
|
+
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
1349
|
+
void reportAgentFailure(this.apiKey, agent.id, code);
|
|
1308
1350
|
}
|
|
1309
1351
|
}
|
|
1310
1352
|
if (Object.keys(results2).length === 0) {
|
|
@@ -1376,6 +1418,8 @@ var OwneySDK = class {
|
|
|
1376
1418
|
} catch (err) {
|
|
1377
1419
|
console.error(`withdraw failed for agent "${p.agent.id}":`, err);
|
|
1378
1420
|
agentErrors[p.agent.id] = err instanceof Error ? err.message : String(err);
|
|
1421
|
+
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
1422
|
+
void reportAgentFailure(this.apiKey, p.agent.id, code);
|
|
1379
1423
|
const failedAmount = p.planned;
|
|
1380
1424
|
p.planned = 0n;
|
|
1381
1425
|
redistributeShare(plans, i, failedAmount);
|