@t2000/engine 0.5.9 → 0.5.10
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.d.ts +6 -1
- package/dist/index.js +83 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -92,6 +92,8 @@ interface ToolContext {
|
|
|
92
92
|
walletAddress?: string;
|
|
93
93
|
suiRpcUrl?: string;
|
|
94
94
|
serverPositions?: ServerPositionData;
|
|
95
|
+
/** Fresh on-chain position reader — bypasses MCP caching. If provided, read tools prefer this. */
|
|
96
|
+
positionFetcher?: (address: string) => Promise<ServerPositionData>;
|
|
95
97
|
signal?: AbortSignal;
|
|
96
98
|
}
|
|
97
99
|
interface ServerPositionData {
|
|
@@ -138,6 +140,8 @@ interface EngineConfig {
|
|
|
138
140
|
walletAddress?: string;
|
|
139
141
|
suiRpcUrl?: string;
|
|
140
142
|
serverPositions?: ServerPositionData;
|
|
143
|
+
/** Fresh on-chain position reader — called per tool invocation, bypasses MCP caching. */
|
|
144
|
+
positionFetcher?: (address: string) => Promise<ServerPositionData>;
|
|
141
145
|
tools?: Tool[];
|
|
142
146
|
systemPrompt?: string;
|
|
143
147
|
model?: string;
|
|
@@ -248,6 +252,7 @@ declare class QueryEngine {
|
|
|
248
252
|
private readonly walletAddress;
|
|
249
253
|
private readonly suiRpcUrl;
|
|
250
254
|
private serverPositions;
|
|
255
|
+
private readonly positionFetcher;
|
|
251
256
|
private readonly txMutex;
|
|
252
257
|
private readonly costTracker;
|
|
253
258
|
private messages;
|
|
@@ -788,12 +793,12 @@ declare const balanceCheckTool: Tool<{}, {
|
|
|
788
793
|
declare const savingsInfoTool: Tool<{}, SavingsResult>;
|
|
789
794
|
|
|
790
795
|
declare const healthCheckTool: Tool<{}, {
|
|
791
|
-
status: string;
|
|
792
796
|
healthFactor: number;
|
|
793
797
|
supplied: number;
|
|
794
798
|
borrowed: number;
|
|
795
799
|
maxBorrow: number;
|
|
796
800
|
liquidationThreshold: number;
|
|
801
|
+
status: string;
|
|
797
802
|
}>;
|
|
798
803
|
|
|
799
804
|
declare const ratesInfoTool: Tool<{}, _t2000_sdk.RatesResult>;
|
package/dist/index.js
CHANGED
|
@@ -555,11 +555,21 @@ var balanceCheckTool = buildTool({
|
|
|
555
555
|
});
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
558
|
+
let savings;
|
|
559
|
+
let debt;
|
|
560
|
+
let pendingRewardsUsd;
|
|
561
|
+
if (context.positionFetcher && context.walletAddress) {
|
|
562
|
+
const sp = await context.positionFetcher(context.walletAddress);
|
|
563
|
+
savings = sp.savings;
|
|
564
|
+
debt = sp.borrows;
|
|
565
|
+
pendingRewardsUsd = sp.pendingRewards;
|
|
566
|
+
} else {
|
|
567
|
+
const posEntries = transformPositions(positions);
|
|
568
|
+
const rewardEntries = transformRewards(rewards);
|
|
569
|
+
savings = posEntries.filter((p) => p.type === "supply").reduce((sum, p) => sum + p.valueUsd, 0);
|
|
570
|
+
debt = posEntries.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.valueUsd, 0);
|
|
571
|
+
pendingRewardsUsd = rewardEntries.reduce((sum, r) => sum + r.valueUsd, 0);
|
|
572
|
+
}
|
|
563
573
|
const bal = {
|
|
564
574
|
available: availableUsd,
|
|
565
575
|
savings,
|
|
@@ -683,6 +693,47 @@ async function fetchProtocolStats(manager, opts) {
|
|
|
683
693
|
}
|
|
684
694
|
|
|
685
695
|
// src/tools/savings.ts
|
|
696
|
+
function buildSavingsFromPositions(sp) {
|
|
697
|
+
const positions = [
|
|
698
|
+
...sp.supplies.map((s) => ({
|
|
699
|
+
protocol: s.protocol,
|
|
700
|
+
type: "supply",
|
|
701
|
+
symbol: s.asset,
|
|
702
|
+
amount: s.amount,
|
|
703
|
+
valueUsd: s.amountUsd,
|
|
704
|
+
apy: s.apy,
|
|
705
|
+
liquidationThreshold: 0
|
|
706
|
+
})),
|
|
707
|
+
...sp.borrows_detail.map((b) => ({
|
|
708
|
+
protocol: b.protocol,
|
|
709
|
+
type: "borrow",
|
|
710
|
+
symbol: b.asset,
|
|
711
|
+
amount: b.amount,
|
|
712
|
+
valueUsd: b.amountUsd,
|
|
713
|
+
apy: b.apy,
|
|
714
|
+
liquidationThreshold: 0
|
|
715
|
+
}))
|
|
716
|
+
];
|
|
717
|
+
const supplied = sp.savings;
|
|
718
|
+
const weightedApy = supplied > 0 ? sp.savingsRate : 0;
|
|
719
|
+
const dailyEarning = supplied * weightedApy / 365;
|
|
720
|
+
return {
|
|
721
|
+
positions,
|
|
722
|
+
earnings: {
|
|
723
|
+
totalYieldEarned: 0,
|
|
724
|
+
currentApy: weightedApy,
|
|
725
|
+
dailyEarning,
|
|
726
|
+
supplied
|
|
727
|
+
},
|
|
728
|
+
fundStatus: {
|
|
729
|
+
supplied,
|
|
730
|
+
apy: weightedApy,
|
|
731
|
+
earnedToday: dailyEarning,
|
|
732
|
+
earnedAllTime: 0,
|
|
733
|
+
projectedMonthly: dailyEarning * 30
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
}
|
|
686
737
|
var savingsInfoTool = buildTool({
|
|
687
738
|
name: "savings_info",
|
|
688
739
|
description: "Get detailed savings positions and earnings: current deposits by protocol, APY, total yield earned, daily earning rate, and projected monthly returns.",
|
|
@@ -690,6 +741,10 @@ var savingsInfoTool = buildTool({
|
|
|
690
741
|
jsonSchema: { type: "object", properties: {}, required: [] },
|
|
691
742
|
isReadOnly: true,
|
|
692
743
|
async call(_input, context) {
|
|
744
|
+
if (context.positionFetcher && context.walletAddress) {
|
|
745
|
+
const sp = await context.positionFetcher(context.walletAddress);
|
|
746
|
+
return { data: buildSavingsFromPositions(sp) };
|
|
747
|
+
}
|
|
693
748
|
if (hasNaviMcp(context)) {
|
|
694
749
|
const savings = await fetchSavings(
|
|
695
750
|
getMcpManager(context),
|
|
@@ -745,6 +800,23 @@ var healthCheckTool = buildTool({
|
|
|
745
800
|
jsonSchema: { type: "object", properties: {}, required: [] },
|
|
746
801
|
isReadOnly: true,
|
|
747
802
|
async call(_input, context) {
|
|
803
|
+
if (context.positionFetcher && context.walletAddress) {
|
|
804
|
+
const sp = await context.positionFetcher(context.walletAddress);
|
|
805
|
+
const hfVal = sp.healthFactor ?? (sp.borrows > 0 ? 0 : Infinity);
|
|
806
|
+
const status2 = hfStatus(hfVal);
|
|
807
|
+
const displayHf = Number.isFinite(hfVal) ? hfVal.toFixed(2) : "\u221E";
|
|
808
|
+
return {
|
|
809
|
+
data: {
|
|
810
|
+
healthFactor: hfVal,
|
|
811
|
+
supplied: sp.savings,
|
|
812
|
+
borrowed: sp.borrows,
|
|
813
|
+
maxBorrow: sp.maxBorrow,
|
|
814
|
+
liquidationThreshold: 0,
|
|
815
|
+
status: status2
|
|
816
|
+
},
|
|
817
|
+
displayText: `Health Factor: ${displayHf} (${status2})`
|
|
818
|
+
};
|
|
819
|
+
}
|
|
748
820
|
if (hasNaviMcp(context)) {
|
|
749
821
|
const hf2 = await fetchHealthFactor(
|
|
750
822
|
getMcpManager(context),
|
|
@@ -1865,6 +1937,7 @@ var QueryEngine = class {
|
|
|
1865
1937
|
walletAddress;
|
|
1866
1938
|
suiRpcUrl;
|
|
1867
1939
|
serverPositions;
|
|
1940
|
+
positionFetcher;
|
|
1868
1941
|
txMutex = new TxMutex();
|
|
1869
1942
|
costTracker;
|
|
1870
1943
|
messages = [];
|
|
@@ -1876,6 +1949,7 @@ var QueryEngine = class {
|
|
|
1876
1949
|
this.walletAddress = config.walletAddress;
|
|
1877
1950
|
this.suiRpcUrl = config.suiRpcUrl;
|
|
1878
1951
|
this.serverPositions = config.serverPositions;
|
|
1952
|
+
this.positionFetcher = config.positionFetcher;
|
|
1879
1953
|
this.model = config.model;
|
|
1880
1954
|
this.maxTurns = config.maxTurns ?? DEFAULT_MAX_TURNS;
|
|
1881
1955
|
this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
@@ -1950,6 +2024,9 @@ var QueryEngine = class {
|
|
|
1950
2024
|
yield { type: "turn_complete", stopReason: "end_turn" };
|
|
1951
2025
|
return;
|
|
1952
2026
|
}
|
|
2027
|
+
if (this.mcpManager && typeof this.mcpManager.cache?.invalidate === "function") {
|
|
2028
|
+
this.mcpManager.cache.invalidate();
|
|
2029
|
+
}
|
|
1953
2030
|
yield* this.agentLoop(null, signal, false);
|
|
1954
2031
|
}
|
|
1955
2032
|
interrupt() {
|
|
@@ -1987,6 +2064,7 @@ var QueryEngine = class {
|
|
|
1987
2064
|
walletAddress: this.walletAddress,
|
|
1988
2065
|
suiRpcUrl: this.suiRpcUrl,
|
|
1989
2066
|
serverPositions: this.serverPositions,
|
|
2067
|
+
positionFetcher: this.positionFetcher,
|
|
1990
2068
|
signal
|
|
1991
2069
|
};
|
|
1992
2070
|
let turns = 0;
|