@agether/sdk 2.4.0 → 2.6.0
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 +250 -100
- package/dist/index.d.mts +95 -22
- package/dist/index.d.ts +95 -22
- package/dist/index.js +249 -99
- package/dist/index.mjs +249 -99
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -347,6 +347,12 @@ interface FundResult {
|
|
|
347
347
|
amount: string;
|
|
348
348
|
agentAccount: string;
|
|
349
349
|
}
|
|
350
|
+
interface WithdrawFromAccountResult {
|
|
351
|
+
tx: string;
|
|
352
|
+
token: string;
|
|
353
|
+
amount: string;
|
|
354
|
+
destination: string;
|
|
355
|
+
}
|
|
350
356
|
interface SupplyAssetResult {
|
|
351
357
|
tx: string;
|
|
352
358
|
amount: string;
|
|
@@ -394,6 +400,8 @@ declare class MorphoClient {
|
|
|
394
400
|
private validationModule;
|
|
395
401
|
private _accountAddress?;
|
|
396
402
|
private _marketCache;
|
|
403
|
+
/** Dynamic token registry: symbol (uppercase) → { address, symbol, decimals } */
|
|
404
|
+
private _tokenCache;
|
|
397
405
|
private _discoveredMarkets?;
|
|
398
406
|
private _discoveredAt;
|
|
399
407
|
constructor(config: MorphoClientConfig);
|
|
@@ -430,6 +438,21 @@ declare class MorphoClient {
|
|
|
430
438
|
getBalances(): Promise<BalancesResult>;
|
|
431
439
|
/** Transfer USDC from EOA to AgentAccount. */
|
|
432
440
|
fundAccount(usdcAmount: string): Promise<FundResult>;
|
|
441
|
+
/**
|
|
442
|
+
* Withdraw (transfer) a token from AgentAccount to EOA.
|
|
443
|
+
* Executes an ERC-20 transfer via Safe UserOp.
|
|
444
|
+
*
|
|
445
|
+
* @param tokenSymbol - Token to withdraw (e.g. 'USDC', 'WETH', 'wstETH')
|
|
446
|
+
* @param amount - Amount to withdraw (human-readable, e.g. '100' for 100 USDC, or 'all')
|
|
447
|
+
*/
|
|
448
|
+
withdrawToken(tokenSymbol: string, amount: string): Promise<WithdrawFromAccountResult>;
|
|
449
|
+
/**
|
|
450
|
+
* Withdraw ETH from AgentAccount to EOA.
|
|
451
|
+
* Executes a native ETH transfer via Safe UserOp.
|
|
452
|
+
*
|
|
453
|
+
* @param amount - ETH amount (e.g. '0.01' or 'all')
|
|
454
|
+
*/
|
|
455
|
+
withdrawEth(amount: string): Promise<WithdrawFromAccountResult>;
|
|
433
456
|
/**
|
|
434
457
|
* Fetch USDC borrow markets on Base from Morpho API.
|
|
435
458
|
* Caches results for 5 minutes.
|
|
@@ -662,6 +685,20 @@ declare class MorphoClient {
|
|
|
662
685
|
private _findActiveMarket;
|
|
663
686
|
/** Find the first market where the agent has a supply (lending) position. */
|
|
664
687
|
private _findActiveSupplyMarket;
|
|
688
|
+
/**
|
|
689
|
+
* Resolve a token symbol or address to { address, symbol, decimals }.
|
|
690
|
+
*
|
|
691
|
+
* Uses the dynamic `_tokenCache` populated by `getMarkets()` from the
|
|
692
|
+
* Morpho GraphQL API — no hardcoded token list needed.
|
|
693
|
+
*
|
|
694
|
+
* @param symbolOrAddress - e.g. 'WETH', 'wstETH', or '0x4200...'
|
|
695
|
+
*/
|
|
696
|
+
private _resolveToken;
|
|
697
|
+
/**
|
|
698
|
+
* Get all discovered collateral tokens (for balance iteration, etc.).
|
|
699
|
+
* Returns unique tokens from the Morpho API market discovery.
|
|
700
|
+
*/
|
|
701
|
+
private _getDiscoveredTokens;
|
|
665
702
|
/**
|
|
666
703
|
* Compute net deposited amounts per market using Morpho GraphQL API.
|
|
667
704
|
*
|
|
@@ -692,9 +729,14 @@ declare class MorphoClient {
|
|
|
692
729
|
* Auto-Draw: When autoDraw is enabled and USDC balance is insufficient,
|
|
693
730
|
* the client automatically borrows from Morpho Blue before paying.
|
|
694
731
|
*
|
|
695
|
-
*
|
|
696
|
-
* yield
|
|
697
|
-
*
|
|
732
|
+
* Auto-Yield: When autoYield is enabled, the client first tries to cover
|
|
733
|
+
* the deficit from earned supply yield (principal untouched) before borrowing.
|
|
734
|
+
*
|
|
735
|
+
* Waterfall when both enabled: balance → yield → borrow
|
|
736
|
+
*
|
|
737
|
+
* Spending Limits: Optional daily spending cap (dailySpendLimitUsdc) with
|
|
738
|
+
* persistent state via onSpendingUpdate callback. The caller (e.g. plugin)
|
|
739
|
+
* is responsible for persisting and restoring state via initialSpendingState.
|
|
698
740
|
*
|
|
699
741
|
* Chain support: Base (8453), Base Sepolia (84532), Ethereum (1).
|
|
700
742
|
*/
|
|
@@ -717,21 +759,43 @@ interface X402BaseConfig {
|
|
|
717
759
|
* Default: false
|
|
718
760
|
*/
|
|
719
761
|
autoDraw?: boolean;
|
|
762
|
+
/**
|
|
763
|
+
* Auto-yield: when USDC is insufficient, try to cover the deficit from
|
|
764
|
+
* earned supply yield BEFORE borrowing. Withdraws only the yield portion
|
|
765
|
+
* (principal stays intact). Works independently or combined with autoDraw.
|
|
766
|
+
*
|
|
767
|
+
* Waterfall when both enabled: balance → yield → borrow
|
|
768
|
+
* Default: false
|
|
769
|
+
*/
|
|
770
|
+
autoYield?: boolean;
|
|
720
771
|
/**
|
|
721
772
|
* Daily spending limit in USDC (e.g. '100' for $100/day).
|
|
722
773
|
* Tracks cumulative daily borrows and rejects auto-draw if exceeded.
|
|
723
774
|
*/
|
|
724
775
|
dailySpendLimitUsdc?: string;
|
|
725
|
-
/**
|
|
726
|
-
* When true, auto-calculates the daily spending limit based on
|
|
727
|
-
* theoretical yield of deposited collateral. Overrides dailySpendLimitUsdc.
|
|
728
|
-
*/
|
|
729
|
-
yieldLimitedSpending?: boolean;
|
|
730
776
|
/**
|
|
731
777
|
* Safety margin: borrow this much extra beyond what's needed (in USDC, e.g. '1').
|
|
732
778
|
* Helps avoid rounding issues. Default: '0.5'
|
|
733
779
|
*/
|
|
734
780
|
autoDrawBuffer?: string;
|
|
781
|
+
/**
|
|
782
|
+
* Pre-loaded spending state from a previous session.
|
|
783
|
+
* Pass this to resume the daily spending tracker after a restart.
|
|
784
|
+
* If the date doesn't match today, it's ignored (fresh day).
|
|
785
|
+
*/
|
|
786
|
+
initialSpendingState?: {
|
|
787
|
+
date: string;
|
|
788
|
+
totalBorrowed: string;
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Called after every auto-draw borrow so the caller can persist the
|
|
792
|
+
* updated spending state (e.g. to a cache file). Receives the full
|
|
793
|
+
* SpendingTracker with the current date and cumulative amount.
|
|
794
|
+
*/
|
|
795
|
+
onSpendingUpdate?: (state: {
|
|
796
|
+
date: string;
|
|
797
|
+
totalBorrowed: string;
|
|
798
|
+
}) => void;
|
|
735
799
|
/**
|
|
736
800
|
* ERC-7579 validator module address (e.g. Agether8004ValidationModule).
|
|
737
801
|
* Required for Safe7579 smart wallets so that `isValidSignature` calls
|
|
@@ -774,8 +838,10 @@ interface X402Response<T = unknown> {
|
|
|
774
838
|
txHash?: string;
|
|
775
839
|
};
|
|
776
840
|
autoDrawInfo?: {
|
|
777
|
-
borrowed
|
|
778
|
-
borrowTx
|
|
841
|
+
borrowed?: string;
|
|
842
|
+
borrowTx?: string;
|
|
843
|
+
yieldWithdrawn?: string;
|
|
844
|
+
yieldTx?: string;
|
|
779
845
|
reason: string;
|
|
780
846
|
};
|
|
781
847
|
}
|
|
@@ -812,15 +878,23 @@ declare class X402Client {
|
|
|
812
878
|
/** Get remaining daily spending allowance in USDC (human-readable) */
|
|
813
879
|
getRemainingDailyAllowance(): string;
|
|
814
880
|
/**
|
|
815
|
-
* Pay with auto-
|
|
881
|
+
* Pay with auto-funding: Make an x402 request with automatic USDC sourcing.
|
|
816
882
|
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
883
|
+
* Uses a **plan-then-execute** approach: all reads happen first, and if the
|
|
884
|
+
* full deficit can't be covered the method fails with NO side-effects
|
|
885
|
+
* (no yield withdrawn, no USDC borrowed).
|
|
886
|
+
*
|
|
887
|
+
* Waterfall (when both autoYield + autoDraw enabled):
|
|
888
|
+
* 1. Check USDC balance on AgentAccount
|
|
889
|
+
* 2. Probe the URL to discover payment amount (if 402)
|
|
890
|
+
* 3. If insufficient USDC — PLANNING PHASE (read-only):
|
|
891
|
+
* a. Calculate total available yield across supply positions
|
|
892
|
+
* b. Calculate max borrowable from Morpho markets
|
|
893
|
+
* c. Verify yield + borrow can cover full deficit — if not, fail immediately
|
|
894
|
+
* 4. EXECUTION PHASE (only if plan is feasible):
|
|
895
|
+
* a. Withdraw needed yield from supply positions
|
|
896
|
+
* b. Borrow remaining deficit from Morpho
|
|
897
|
+
* 5. Proceed with x402 payment
|
|
824
898
|
*/
|
|
825
899
|
payWithAutoDraw<T = unknown>(url: string, opts?: RequestInit & {
|
|
826
900
|
morphoClient?: any;
|
|
@@ -834,11 +908,10 @@ declare class X402Client {
|
|
|
834
908
|
private _probePaymentAmount;
|
|
835
909
|
/** Reset spending tracker if it's a new day */
|
|
836
910
|
private _resetTrackerIfNewDay;
|
|
837
|
-
/** Track a new spending amount */
|
|
911
|
+
/** Track a new spending amount and notify the caller for persistence */
|
|
838
912
|
private _trackSpending;
|
|
839
913
|
/**
|
|
840
|
-
* Check if a borrow amount is within spending
|
|
841
|
-
* Considers both fixed daily limits and yield-limited spending.
|
|
914
|
+
* Check if a borrow amount is within the fixed daily spending limit.
|
|
842
915
|
*/
|
|
843
916
|
private _checkSpendingLimit;
|
|
844
917
|
}
|
|
@@ -1211,4 +1284,4 @@ declare function getDefaultConfig(chainId: ChainId): AgetherConfig;
|
|
|
1211
1284
|
*/
|
|
1212
1285
|
declare function createConfig(chainId: ChainId, options?: Partial<AgetherConfig>): AgetherConfig;
|
|
1213
1286
|
|
|
1214
|
-
export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, type FundResult, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
|
|
1287
|
+
export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, type FundResult, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
|
package/dist/index.d.ts
CHANGED
|
@@ -347,6 +347,12 @@ interface FundResult {
|
|
|
347
347
|
amount: string;
|
|
348
348
|
agentAccount: string;
|
|
349
349
|
}
|
|
350
|
+
interface WithdrawFromAccountResult {
|
|
351
|
+
tx: string;
|
|
352
|
+
token: string;
|
|
353
|
+
amount: string;
|
|
354
|
+
destination: string;
|
|
355
|
+
}
|
|
350
356
|
interface SupplyAssetResult {
|
|
351
357
|
tx: string;
|
|
352
358
|
amount: string;
|
|
@@ -394,6 +400,8 @@ declare class MorphoClient {
|
|
|
394
400
|
private validationModule;
|
|
395
401
|
private _accountAddress?;
|
|
396
402
|
private _marketCache;
|
|
403
|
+
/** Dynamic token registry: symbol (uppercase) → { address, symbol, decimals } */
|
|
404
|
+
private _tokenCache;
|
|
397
405
|
private _discoveredMarkets?;
|
|
398
406
|
private _discoveredAt;
|
|
399
407
|
constructor(config: MorphoClientConfig);
|
|
@@ -430,6 +438,21 @@ declare class MorphoClient {
|
|
|
430
438
|
getBalances(): Promise<BalancesResult>;
|
|
431
439
|
/** Transfer USDC from EOA to AgentAccount. */
|
|
432
440
|
fundAccount(usdcAmount: string): Promise<FundResult>;
|
|
441
|
+
/**
|
|
442
|
+
* Withdraw (transfer) a token from AgentAccount to EOA.
|
|
443
|
+
* Executes an ERC-20 transfer via Safe UserOp.
|
|
444
|
+
*
|
|
445
|
+
* @param tokenSymbol - Token to withdraw (e.g. 'USDC', 'WETH', 'wstETH')
|
|
446
|
+
* @param amount - Amount to withdraw (human-readable, e.g. '100' for 100 USDC, or 'all')
|
|
447
|
+
*/
|
|
448
|
+
withdrawToken(tokenSymbol: string, amount: string): Promise<WithdrawFromAccountResult>;
|
|
449
|
+
/**
|
|
450
|
+
* Withdraw ETH from AgentAccount to EOA.
|
|
451
|
+
* Executes a native ETH transfer via Safe UserOp.
|
|
452
|
+
*
|
|
453
|
+
* @param amount - ETH amount (e.g. '0.01' or 'all')
|
|
454
|
+
*/
|
|
455
|
+
withdrawEth(amount: string): Promise<WithdrawFromAccountResult>;
|
|
433
456
|
/**
|
|
434
457
|
* Fetch USDC borrow markets on Base from Morpho API.
|
|
435
458
|
* Caches results for 5 minutes.
|
|
@@ -662,6 +685,20 @@ declare class MorphoClient {
|
|
|
662
685
|
private _findActiveMarket;
|
|
663
686
|
/** Find the first market where the agent has a supply (lending) position. */
|
|
664
687
|
private _findActiveSupplyMarket;
|
|
688
|
+
/**
|
|
689
|
+
* Resolve a token symbol or address to { address, symbol, decimals }.
|
|
690
|
+
*
|
|
691
|
+
* Uses the dynamic `_tokenCache` populated by `getMarkets()` from the
|
|
692
|
+
* Morpho GraphQL API — no hardcoded token list needed.
|
|
693
|
+
*
|
|
694
|
+
* @param symbolOrAddress - e.g. 'WETH', 'wstETH', or '0x4200...'
|
|
695
|
+
*/
|
|
696
|
+
private _resolveToken;
|
|
697
|
+
/**
|
|
698
|
+
* Get all discovered collateral tokens (for balance iteration, etc.).
|
|
699
|
+
* Returns unique tokens from the Morpho API market discovery.
|
|
700
|
+
*/
|
|
701
|
+
private _getDiscoveredTokens;
|
|
665
702
|
/**
|
|
666
703
|
* Compute net deposited amounts per market using Morpho GraphQL API.
|
|
667
704
|
*
|
|
@@ -692,9 +729,14 @@ declare class MorphoClient {
|
|
|
692
729
|
* Auto-Draw: When autoDraw is enabled and USDC balance is insufficient,
|
|
693
730
|
* the client automatically borrows from Morpho Blue before paying.
|
|
694
731
|
*
|
|
695
|
-
*
|
|
696
|
-
* yield
|
|
697
|
-
*
|
|
732
|
+
* Auto-Yield: When autoYield is enabled, the client first tries to cover
|
|
733
|
+
* the deficit from earned supply yield (principal untouched) before borrowing.
|
|
734
|
+
*
|
|
735
|
+
* Waterfall when both enabled: balance → yield → borrow
|
|
736
|
+
*
|
|
737
|
+
* Spending Limits: Optional daily spending cap (dailySpendLimitUsdc) with
|
|
738
|
+
* persistent state via onSpendingUpdate callback. The caller (e.g. plugin)
|
|
739
|
+
* is responsible for persisting and restoring state via initialSpendingState.
|
|
698
740
|
*
|
|
699
741
|
* Chain support: Base (8453), Base Sepolia (84532), Ethereum (1).
|
|
700
742
|
*/
|
|
@@ -717,21 +759,43 @@ interface X402BaseConfig {
|
|
|
717
759
|
* Default: false
|
|
718
760
|
*/
|
|
719
761
|
autoDraw?: boolean;
|
|
762
|
+
/**
|
|
763
|
+
* Auto-yield: when USDC is insufficient, try to cover the deficit from
|
|
764
|
+
* earned supply yield BEFORE borrowing. Withdraws only the yield portion
|
|
765
|
+
* (principal stays intact). Works independently or combined with autoDraw.
|
|
766
|
+
*
|
|
767
|
+
* Waterfall when both enabled: balance → yield → borrow
|
|
768
|
+
* Default: false
|
|
769
|
+
*/
|
|
770
|
+
autoYield?: boolean;
|
|
720
771
|
/**
|
|
721
772
|
* Daily spending limit in USDC (e.g. '100' for $100/day).
|
|
722
773
|
* Tracks cumulative daily borrows and rejects auto-draw if exceeded.
|
|
723
774
|
*/
|
|
724
775
|
dailySpendLimitUsdc?: string;
|
|
725
|
-
/**
|
|
726
|
-
* When true, auto-calculates the daily spending limit based on
|
|
727
|
-
* theoretical yield of deposited collateral. Overrides dailySpendLimitUsdc.
|
|
728
|
-
*/
|
|
729
|
-
yieldLimitedSpending?: boolean;
|
|
730
776
|
/**
|
|
731
777
|
* Safety margin: borrow this much extra beyond what's needed (in USDC, e.g. '1').
|
|
732
778
|
* Helps avoid rounding issues. Default: '0.5'
|
|
733
779
|
*/
|
|
734
780
|
autoDrawBuffer?: string;
|
|
781
|
+
/**
|
|
782
|
+
* Pre-loaded spending state from a previous session.
|
|
783
|
+
* Pass this to resume the daily spending tracker after a restart.
|
|
784
|
+
* If the date doesn't match today, it's ignored (fresh day).
|
|
785
|
+
*/
|
|
786
|
+
initialSpendingState?: {
|
|
787
|
+
date: string;
|
|
788
|
+
totalBorrowed: string;
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Called after every auto-draw borrow so the caller can persist the
|
|
792
|
+
* updated spending state (e.g. to a cache file). Receives the full
|
|
793
|
+
* SpendingTracker with the current date and cumulative amount.
|
|
794
|
+
*/
|
|
795
|
+
onSpendingUpdate?: (state: {
|
|
796
|
+
date: string;
|
|
797
|
+
totalBorrowed: string;
|
|
798
|
+
}) => void;
|
|
735
799
|
/**
|
|
736
800
|
* ERC-7579 validator module address (e.g. Agether8004ValidationModule).
|
|
737
801
|
* Required for Safe7579 smart wallets so that `isValidSignature` calls
|
|
@@ -774,8 +838,10 @@ interface X402Response<T = unknown> {
|
|
|
774
838
|
txHash?: string;
|
|
775
839
|
};
|
|
776
840
|
autoDrawInfo?: {
|
|
777
|
-
borrowed
|
|
778
|
-
borrowTx
|
|
841
|
+
borrowed?: string;
|
|
842
|
+
borrowTx?: string;
|
|
843
|
+
yieldWithdrawn?: string;
|
|
844
|
+
yieldTx?: string;
|
|
779
845
|
reason: string;
|
|
780
846
|
};
|
|
781
847
|
}
|
|
@@ -812,15 +878,23 @@ declare class X402Client {
|
|
|
812
878
|
/** Get remaining daily spending allowance in USDC (human-readable) */
|
|
813
879
|
getRemainingDailyAllowance(): string;
|
|
814
880
|
/**
|
|
815
|
-
* Pay with auto-
|
|
881
|
+
* Pay with auto-funding: Make an x402 request with automatic USDC sourcing.
|
|
816
882
|
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
883
|
+
* Uses a **plan-then-execute** approach: all reads happen first, and if the
|
|
884
|
+
* full deficit can't be covered the method fails with NO side-effects
|
|
885
|
+
* (no yield withdrawn, no USDC borrowed).
|
|
886
|
+
*
|
|
887
|
+
* Waterfall (when both autoYield + autoDraw enabled):
|
|
888
|
+
* 1. Check USDC balance on AgentAccount
|
|
889
|
+
* 2. Probe the URL to discover payment amount (if 402)
|
|
890
|
+
* 3. If insufficient USDC — PLANNING PHASE (read-only):
|
|
891
|
+
* a. Calculate total available yield across supply positions
|
|
892
|
+
* b. Calculate max borrowable from Morpho markets
|
|
893
|
+
* c. Verify yield + borrow can cover full deficit — if not, fail immediately
|
|
894
|
+
* 4. EXECUTION PHASE (only if plan is feasible):
|
|
895
|
+
* a. Withdraw needed yield from supply positions
|
|
896
|
+
* b. Borrow remaining deficit from Morpho
|
|
897
|
+
* 5. Proceed with x402 payment
|
|
824
898
|
*/
|
|
825
899
|
payWithAutoDraw<T = unknown>(url: string, opts?: RequestInit & {
|
|
826
900
|
morphoClient?: any;
|
|
@@ -834,11 +908,10 @@ declare class X402Client {
|
|
|
834
908
|
private _probePaymentAmount;
|
|
835
909
|
/** Reset spending tracker if it's a new day */
|
|
836
910
|
private _resetTrackerIfNewDay;
|
|
837
|
-
/** Track a new spending amount */
|
|
911
|
+
/** Track a new spending amount and notify the caller for persistence */
|
|
838
912
|
private _trackSpending;
|
|
839
913
|
/**
|
|
840
|
-
* Check if a borrow amount is within spending
|
|
841
|
-
* Considers both fixed daily limits and yield-limited spending.
|
|
914
|
+
* Check if a borrow amount is within the fixed daily spending limit.
|
|
842
915
|
*/
|
|
843
916
|
private _checkSpendingLimit;
|
|
844
917
|
}
|
|
@@ -1211,4 +1284,4 @@ declare function getDefaultConfig(chainId: ChainId): AgetherConfig;
|
|
|
1211
1284
|
*/
|
|
1212
1285
|
declare function createConfig(chainId: ChainId, options?: Partial<AgetherConfig>): AgetherConfig;
|
|
1213
1286
|
|
|
1214
|
-
export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, type FundResult, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
|
|
1287
|
+
export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, type FundResult, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
|