@agether/sdk 2.16.0 → 2.16.1
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/cli.js +66 -4
- package/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +66 -4
- package/dist/index.mjs +66 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2557,13 +2557,64 @@ var init_AgetherClient = __esm({
|
|
|
2557
2557
|
return this.agether4337Factory.accountExists(id);
|
|
2558
2558
|
}
|
|
2559
2559
|
// ════════════════════════════════════════════════════════
|
|
2560
|
+
// Token Discovery (for dynamic balance queries)
|
|
2561
|
+
// ════════════════════════════════════════════════════════
|
|
2562
|
+
/**
|
|
2563
|
+
* Discover token addresses from active Morpho Blue positions.
|
|
2564
|
+
* Queries the Morpho GraphQL API for markets involving this agent's account,
|
|
2565
|
+
* then extracts collateral and loan token info.
|
|
2566
|
+
*/
|
|
2567
|
+
async _discoverPositionTokens() {
|
|
2568
|
+
const tokens = {};
|
|
2569
|
+
try {
|
|
2570
|
+
const acctAddr = await this.getAccountAddress();
|
|
2571
|
+
const chainId = this.config.chainId;
|
|
2572
|
+
const query = `{
|
|
2573
|
+
marketPositions(
|
|
2574
|
+
where: { userAddress_in: ["${acctAddr.toLowerCase()}"], chainId_in: [${chainId}] }
|
|
2575
|
+
first: 20
|
|
2576
|
+
) {
|
|
2577
|
+
items {
|
|
2578
|
+
market {
|
|
2579
|
+
collateralAsset { address symbol decimals }
|
|
2580
|
+
loanAsset { address symbol decimals }
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
}`;
|
|
2585
|
+
const resp = await fetch("https://blue-api.morpho.org/graphql", {
|
|
2586
|
+
method: "POST",
|
|
2587
|
+
headers: { "Content-Type": "application/json" },
|
|
2588
|
+
body: JSON.stringify({ query }),
|
|
2589
|
+
signal: AbortSignal.timeout(5e3)
|
|
2590
|
+
});
|
|
2591
|
+
if (!resp.ok) return tokens;
|
|
2592
|
+
const data = await resp.json();
|
|
2593
|
+
const items = data?.data?.marketPositions?.items ?? [];
|
|
2594
|
+
for (const item of items) {
|
|
2595
|
+
const col = item?.market?.collateralAsset;
|
|
2596
|
+
const loan = item?.market?.loanAsset;
|
|
2597
|
+
if (col?.symbol && col?.address) {
|
|
2598
|
+
tokens[col.symbol] = { address: col.address, symbol: col.symbol, decimals: col.decimals ?? 18 };
|
|
2599
|
+
}
|
|
2600
|
+
if (loan?.symbol && loan?.address) {
|
|
2601
|
+
tokens[loan.symbol] = { address: loan.address, symbol: loan.symbol, decimals: loan.decimals ?? 18 };
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
} catch {
|
|
2605
|
+
}
|
|
2606
|
+
return tokens;
|
|
2607
|
+
}
|
|
2608
|
+
// ════════════════════════════════════════════════════════
|
|
2560
2609
|
// Balances
|
|
2561
2610
|
// ════════════════════════════════════════════════════════
|
|
2562
2611
|
/**
|
|
2563
|
-
* Get ETH, USDC, and
|
|
2612
|
+
* Get ETH, USDC, and all token balances for EOA and Safe account.
|
|
2564
2613
|
*
|
|
2565
|
-
*
|
|
2566
|
-
*
|
|
2614
|
+
* Tokens are resolved from:
|
|
2615
|
+
* 1. Built-in registry of well-known tokens (WETH, wstETH, cbETH)
|
|
2616
|
+
* 2. Dynamic discovery from active Morpho positions (loan + collateral tokens)
|
|
2617
|
+
* This ensures tokens like LCAP or any new Morpho market tokens appear in balances.
|
|
2567
2618
|
*/
|
|
2568
2619
|
async getBalances() {
|
|
2569
2620
|
const provider = this.signer.provider;
|
|
@@ -2571,7 +2622,18 @@ var init_AgetherClient = __esm({
|
|
|
2571
2622
|
const usdc = new import_ethers2.Contract(this.config.contracts.usdc, ERC20_ABI, provider);
|
|
2572
2623
|
const ethBal = await provider.getBalance(eoaAddr);
|
|
2573
2624
|
const usdcBal = await usdc.balanceOf(eoaAddr);
|
|
2574
|
-
const knownTokens =
|
|
2625
|
+
const knownTokens = {
|
|
2626
|
+
...KNOWN_TOKENS[this.config.chainId] ?? {}
|
|
2627
|
+
};
|
|
2628
|
+
try {
|
|
2629
|
+
const positions = await this._discoverPositionTokens();
|
|
2630
|
+
for (const [symbol, info] of Object.entries(positions)) {
|
|
2631
|
+
if (!knownTokens[symbol]) {
|
|
2632
|
+
knownTokens[symbol] = info;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
} catch {
|
|
2636
|
+
}
|
|
2575
2637
|
const eoaCollateral = {};
|
|
2576
2638
|
for (const [symbol, info] of Object.entries(knownTokens)) {
|
|
2577
2639
|
try {
|
package/dist/index.d.mts
CHANGED
|
@@ -244,10 +244,18 @@ declare class AgetherClient {
|
|
|
244
244
|
/** Check whether the Safe account has been deployed. */
|
|
245
245
|
accountExists(): Promise<boolean>;
|
|
246
246
|
/**
|
|
247
|
-
*
|
|
247
|
+
* Discover token addresses from active Morpho Blue positions.
|
|
248
|
+
* Queries the Morpho GraphQL API for markets involving this agent's account,
|
|
249
|
+
* then extracts collateral and loan token info.
|
|
250
|
+
*/
|
|
251
|
+
private _discoverPositionTokens;
|
|
252
|
+
/**
|
|
253
|
+
* Get ETH, USDC, and all token balances for EOA and Safe account.
|
|
248
254
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
255
|
+
* Tokens are resolved from:
|
|
256
|
+
* 1. Built-in registry of well-known tokens (WETH, wstETH, cbETH)
|
|
257
|
+
* 2. Dynamic discovery from active Morpho positions (loan + collateral tokens)
|
|
258
|
+
* This ensures tokens like LCAP or any new Morpho market tokens appear in balances.
|
|
251
259
|
*/
|
|
252
260
|
getBalances(): Promise<BalancesResult>;
|
|
253
261
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -244,10 +244,18 @@ declare class AgetherClient {
|
|
|
244
244
|
/** Check whether the Safe account has been deployed. */
|
|
245
245
|
accountExists(): Promise<boolean>;
|
|
246
246
|
/**
|
|
247
|
-
*
|
|
247
|
+
* Discover token addresses from active Morpho Blue positions.
|
|
248
|
+
* Queries the Morpho GraphQL API for markets involving this agent's account,
|
|
249
|
+
* then extracts collateral and loan token info.
|
|
250
|
+
*/
|
|
251
|
+
private _discoverPositionTokens;
|
|
252
|
+
/**
|
|
253
|
+
* Get ETH, USDC, and all token balances for EOA and Safe account.
|
|
248
254
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
255
|
+
* Tokens are resolved from:
|
|
256
|
+
* 1. Built-in registry of well-known tokens (WETH, wstETH, cbETH)
|
|
257
|
+
* 2. Dynamic discovery from active Morpho positions (loan + collateral tokens)
|
|
258
|
+
* This ensures tokens like LCAP or any new Morpho market tokens appear in balances.
|
|
251
259
|
*/
|
|
252
260
|
getBalances(): Promise<BalancesResult>;
|
|
253
261
|
/**
|
package/dist/index.js
CHANGED
|
@@ -619,13 +619,64 @@ var AgetherClient = class _AgetherClient {
|
|
|
619
619
|
return this.agether4337Factory.accountExists(id);
|
|
620
620
|
}
|
|
621
621
|
// ════════════════════════════════════════════════════════
|
|
622
|
+
// Token Discovery (for dynamic balance queries)
|
|
623
|
+
// ════════════════════════════════════════════════════════
|
|
624
|
+
/**
|
|
625
|
+
* Discover token addresses from active Morpho Blue positions.
|
|
626
|
+
* Queries the Morpho GraphQL API for markets involving this agent's account,
|
|
627
|
+
* then extracts collateral and loan token info.
|
|
628
|
+
*/
|
|
629
|
+
async _discoverPositionTokens() {
|
|
630
|
+
const tokens = {};
|
|
631
|
+
try {
|
|
632
|
+
const acctAddr = await this.getAccountAddress();
|
|
633
|
+
const chainId = this.config.chainId;
|
|
634
|
+
const query = `{
|
|
635
|
+
marketPositions(
|
|
636
|
+
where: { userAddress_in: ["${acctAddr.toLowerCase()}"], chainId_in: [${chainId}] }
|
|
637
|
+
first: 20
|
|
638
|
+
) {
|
|
639
|
+
items {
|
|
640
|
+
market {
|
|
641
|
+
collateralAsset { address symbol decimals }
|
|
642
|
+
loanAsset { address symbol decimals }
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}`;
|
|
647
|
+
const resp = await fetch("https://blue-api.morpho.org/graphql", {
|
|
648
|
+
method: "POST",
|
|
649
|
+
headers: { "Content-Type": "application/json" },
|
|
650
|
+
body: JSON.stringify({ query }),
|
|
651
|
+
signal: AbortSignal.timeout(5e3)
|
|
652
|
+
});
|
|
653
|
+
if (!resp.ok) return tokens;
|
|
654
|
+
const data = await resp.json();
|
|
655
|
+
const items = data?.data?.marketPositions?.items ?? [];
|
|
656
|
+
for (const item of items) {
|
|
657
|
+
const col = item?.market?.collateralAsset;
|
|
658
|
+
const loan = item?.market?.loanAsset;
|
|
659
|
+
if (col?.symbol && col?.address) {
|
|
660
|
+
tokens[col.symbol] = { address: col.address, symbol: col.symbol, decimals: col.decimals ?? 18 };
|
|
661
|
+
}
|
|
662
|
+
if (loan?.symbol && loan?.address) {
|
|
663
|
+
tokens[loan.symbol] = { address: loan.address, symbol: loan.symbol, decimals: loan.decimals ?? 18 };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
} catch {
|
|
667
|
+
}
|
|
668
|
+
return tokens;
|
|
669
|
+
}
|
|
670
|
+
// ════════════════════════════════════════════════════════
|
|
622
671
|
// Balances
|
|
623
672
|
// ════════════════════════════════════════════════════════
|
|
624
673
|
/**
|
|
625
|
-
* Get ETH, USDC, and
|
|
674
|
+
* Get ETH, USDC, and all token balances for EOA and Safe account.
|
|
626
675
|
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
676
|
+
* Tokens are resolved from:
|
|
677
|
+
* 1. Built-in registry of well-known tokens (WETH, wstETH, cbETH)
|
|
678
|
+
* 2. Dynamic discovery from active Morpho positions (loan + collateral tokens)
|
|
679
|
+
* This ensures tokens like LCAP or any new Morpho market tokens appear in balances.
|
|
629
680
|
*/
|
|
630
681
|
async getBalances() {
|
|
631
682
|
const provider = this.signer.provider;
|
|
@@ -633,7 +684,18 @@ var AgetherClient = class _AgetherClient {
|
|
|
633
684
|
const usdc = new import_ethers.Contract(this.config.contracts.usdc, ERC20_ABI, provider);
|
|
634
685
|
const ethBal = await provider.getBalance(eoaAddr);
|
|
635
686
|
const usdcBal = await usdc.balanceOf(eoaAddr);
|
|
636
|
-
const knownTokens =
|
|
687
|
+
const knownTokens = {
|
|
688
|
+
...KNOWN_TOKENS[this.config.chainId] ?? {}
|
|
689
|
+
};
|
|
690
|
+
try {
|
|
691
|
+
const positions = await this._discoverPositionTokens();
|
|
692
|
+
for (const [symbol, info] of Object.entries(positions)) {
|
|
693
|
+
if (!knownTokens[symbol]) {
|
|
694
|
+
knownTokens[symbol] = info;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
} catch {
|
|
698
|
+
}
|
|
637
699
|
const eoaCollateral = {};
|
|
638
700
|
for (const [symbol, info] of Object.entries(knownTokens)) {
|
|
639
701
|
try {
|
package/dist/index.mjs
CHANGED
|
@@ -543,13 +543,64 @@ var AgetherClient = class _AgetherClient {
|
|
|
543
543
|
return this.agether4337Factory.accountExists(id);
|
|
544
544
|
}
|
|
545
545
|
// ════════════════════════════════════════════════════════
|
|
546
|
+
// Token Discovery (for dynamic balance queries)
|
|
547
|
+
// ════════════════════════════════════════════════════════
|
|
548
|
+
/**
|
|
549
|
+
* Discover token addresses from active Morpho Blue positions.
|
|
550
|
+
* Queries the Morpho GraphQL API for markets involving this agent's account,
|
|
551
|
+
* then extracts collateral and loan token info.
|
|
552
|
+
*/
|
|
553
|
+
async _discoverPositionTokens() {
|
|
554
|
+
const tokens = {};
|
|
555
|
+
try {
|
|
556
|
+
const acctAddr = await this.getAccountAddress();
|
|
557
|
+
const chainId = this.config.chainId;
|
|
558
|
+
const query = `{
|
|
559
|
+
marketPositions(
|
|
560
|
+
where: { userAddress_in: ["${acctAddr.toLowerCase()}"], chainId_in: [${chainId}] }
|
|
561
|
+
first: 20
|
|
562
|
+
) {
|
|
563
|
+
items {
|
|
564
|
+
market {
|
|
565
|
+
collateralAsset { address symbol decimals }
|
|
566
|
+
loanAsset { address symbol decimals }
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}`;
|
|
571
|
+
const resp = await fetch("https://blue-api.morpho.org/graphql", {
|
|
572
|
+
method: "POST",
|
|
573
|
+
headers: { "Content-Type": "application/json" },
|
|
574
|
+
body: JSON.stringify({ query }),
|
|
575
|
+
signal: AbortSignal.timeout(5e3)
|
|
576
|
+
});
|
|
577
|
+
if (!resp.ok) return tokens;
|
|
578
|
+
const data = await resp.json();
|
|
579
|
+
const items = data?.data?.marketPositions?.items ?? [];
|
|
580
|
+
for (const item of items) {
|
|
581
|
+
const col = item?.market?.collateralAsset;
|
|
582
|
+
const loan = item?.market?.loanAsset;
|
|
583
|
+
if (col?.symbol && col?.address) {
|
|
584
|
+
tokens[col.symbol] = { address: col.address, symbol: col.symbol, decimals: col.decimals ?? 18 };
|
|
585
|
+
}
|
|
586
|
+
if (loan?.symbol && loan?.address) {
|
|
587
|
+
tokens[loan.symbol] = { address: loan.address, symbol: loan.symbol, decimals: loan.decimals ?? 18 };
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
} catch {
|
|
591
|
+
}
|
|
592
|
+
return tokens;
|
|
593
|
+
}
|
|
594
|
+
// ════════════════════════════════════════════════════════
|
|
546
595
|
// Balances
|
|
547
596
|
// ════════════════════════════════════════════════════════
|
|
548
597
|
/**
|
|
549
|
-
* Get ETH, USDC, and
|
|
598
|
+
* Get ETH, USDC, and all token balances for EOA and Safe account.
|
|
550
599
|
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
600
|
+
* Tokens are resolved from:
|
|
601
|
+
* 1. Built-in registry of well-known tokens (WETH, wstETH, cbETH)
|
|
602
|
+
* 2. Dynamic discovery from active Morpho positions (loan + collateral tokens)
|
|
603
|
+
* This ensures tokens like LCAP or any new Morpho market tokens appear in balances.
|
|
553
604
|
*/
|
|
554
605
|
async getBalances() {
|
|
555
606
|
const provider = this.signer.provider;
|
|
@@ -557,7 +608,18 @@ var AgetherClient = class _AgetherClient {
|
|
|
557
608
|
const usdc = new Contract(this.config.contracts.usdc, ERC20_ABI, provider);
|
|
558
609
|
const ethBal = await provider.getBalance(eoaAddr);
|
|
559
610
|
const usdcBal = await usdc.balanceOf(eoaAddr);
|
|
560
|
-
const knownTokens =
|
|
611
|
+
const knownTokens = {
|
|
612
|
+
...KNOWN_TOKENS[this.config.chainId] ?? {}
|
|
613
|
+
};
|
|
614
|
+
try {
|
|
615
|
+
const positions = await this._discoverPositionTokens();
|
|
616
|
+
for (const [symbol, info] of Object.entries(positions)) {
|
|
617
|
+
if (!knownTokens[symbol]) {
|
|
618
|
+
knownTokens[symbol] = info;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
} catch {
|
|
622
|
+
}
|
|
561
623
|
const eoaCollateral = {};
|
|
562
624
|
for (const [symbol, info] of Object.entries(knownTokens)) {
|
|
563
625
|
try {
|