@agether/sdk 1.1.0 → 1.2.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 +295 -5
- package/dist/index.d.mts +194 -1
- package/dist/index.d.ts +194 -1
- package/dist/index.js +429 -17
- package/dist/index.mjs +427 -16
- package/package.json +1 -1
- package/dist/cli.d.mts +0 -2
- package/dist/cli.d.ts +0 -19
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.mjs +0 -0
- package/dist/clients/AgentIdentityClient.d.ts +0 -163
- package/dist/clients/AgentIdentityClient.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.js +0 -293
- package/dist/clients/AgetherClient.d.ts +0 -101
- package/dist/clients/AgetherClient.d.ts.map +0 -1
- package/dist/clients/AgetherClient.js +0 -272
- package/dist/clients/ScoringClient.d.ts +0 -138
- package/dist/clients/ScoringClient.d.ts.map +0 -1
- package/dist/clients/ScoringClient.js +0 -135
- package/dist/clients/VaultClient.d.ts +0 -62
- package/dist/clients/VaultClient.d.ts.map +0 -1
- package/dist/clients/VaultClient.js +0 -157
- package/dist/clients/WalletClient.d.ts +0 -73
- package/dist/clients/WalletClient.d.ts.map +0 -1
- package/dist/clients/WalletClient.js +0 -174
- package/dist/clients/X402Client.d.ts +0 -61
- package/dist/clients/X402Client.d.ts.map +0 -1
- package/dist/clients/X402Client.js +0 -303
- package/dist/index.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -220
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -52
- package/dist/utils/abis.d.ts +0 -21
- package/dist/utils/abis.d.ts.map +0 -1
- package/dist/utils/abis.js +0 -134
- package/dist/utils/config.d.ts +0 -31
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -117
- package/dist/utils/format.d.ts +0 -44
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js +0 -75
package/dist/index.d.ts
CHANGED
|
@@ -729,6 +729,10 @@ interface X402Config {
|
|
|
729
729
|
backendUrl: string;
|
|
730
730
|
agentId?: string;
|
|
731
731
|
accountAddress?: string;
|
|
732
|
+
/** Auto-borrow from Morpho credit line when USDC balance is insufficient for payment */
|
|
733
|
+
autoDraw?: boolean;
|
|
734
|
+
/** MorphoCredit contract address (required for autoDraw) */
|
|
735
|
+
morphoCreditAddress?: string;
|
|
732
736
|
}
|
|
733
737
|
interface X402Response<T = unknown> {
|
|
734
738
|
success: boolean;
|
|
@@ -761,9 +765,198 @@ declare class X402Client {
|
|
|
761
765
|
private request;
|
|
762
766
|
private parsePaymentRequired;
|
|
763
767
|
private buildPaymentPayload;
|
|
768
|
+
private static readonly MORPHO_DRAW_ABI;
|
|
769
|
+
private static readonly AGENT_ACCOUNT_EXEC_ABI;
|
|
770
|
+
private static readonly ERC20_BALANCE_ABI;
|
|
771
|
+
private static readonly AUTO_DRAW_COLLATERALS;
|
|
772
|
+
private ensureBalance;
|
|
764
773
|
private riskCheck;
|
|
765
774
|
}
|
|
766
775
|
|
|
776
|
+
/**
|
|
777
|
+
* MorphoCreditClient — SDK client for Morpho-backed overcollateralized credit
|
|
778
|
+
*
|
|
779
|
+
* Covers all 9 flows:
|
|
780
|
+
* 1. Registration (via AgentIdentityClient) + existing 8004 detection
|
|
781
|
+
* 2. Deposit collateral + borrow in one call
|
|
782
|
+
* 3. Deposit collateral only (no borrow)
|
|
783
|
+
* 4. Sponsor agent by agentId + borrow
|
|
784
|
+
* 5. Sponsor agent by agentId, no borrow
|
|
785
|
+
* 6. Sponsor agent by address + borrow
|
|
786
|
+
* 7. Sponsor agent by address, no borrow
|
|
787
|
+
* 8. Borrow against existing collateral (for x402 payments)
|
|
788
|
+
* 9. (Handled by X402Client.autoDraw)
|
|
789
|
+
*/
|
|
790
|
+
interface MorphoCreditConfig {
|
|
791
|
+
/** Private key for signing */
|
|
792
|
+
privateKey: string;
|
|
793
|
+
/** Base RPC URL */
|
|
794
|
+
rpcUrl: string;
|
|
795
|
+
/** Agent's ERC-8004 ID */
|
|
796
|
+
agentId: string | bigint;
|
|
797
|
+
/** Contract addresses */
|
|
798
|
+
contracts: {
|
|
799
|
+
morphoCredit: string;
|
|
800
|
+
accountFactory: string;
|
|
801
|
+
usdc: string;
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
interface CollateralToken {
|
|
805
|
+
symbol: string;
|
|
806
|
+
address: string;
|
|
807
|
+
decimals: number;
|
|
808
|
+
}
|
|
809
|
+
interface MorphoPosition {
|
|
810
|
+
token: string;
|
|
811
|
+
collateralAmount: bigint;
|
|
812
|
+
borrowedAmount: bigint;
|
|
813
|
+
borrowShares: bigint;
|
|
814
|
+
isActive: boolean;
|
|
815
|
+
}
|
|
816
|
+
interface DepositResult {
|
|
817
|
+
tx: string;
|
|
818
|
+
amount: bigint;
|
|
819
|
+
token: string;
|
|
820
|
+
agentAccount: string;
|
|
821
|
+
totalCollateral: bigint;
|
|
822
|
+
}
|
|
823
|
+
interface BorrowResult {
|
|
824
|
+
tx: string;
|
|
825
|
+
amount: bigint;
|
|
826
|
+
agentAccount: string;
|
|
827
|
+
totalDebt: bigint;
|
|
828
|
+
collateralToken: string;
|
|
829
|
+
}
|
|
830
|
+
interface DepositAndBorrowResult {
|
|
831
|
+
depositTx: string;
|
|
832
|
+
borrowTx: string;
|
|
833
|
+
collateral: {
|
|
834
|
+
amount: bigint;
|
|
835
|
+
token: string;
|
|
836
|
+
};
|
|
837
|
+
borrowed: bigint;
|
|
838
|
+
agentAccount: string;
|
|
839
|
+
totalDebt: bigint;
|
|
840
|
+
}
|
|
841
|
+
interface SponsorResult {
|
|
842
|
+
depositTx: string;
|
|
843
|
+
borrowTx?: string;
|
|
844
|
+
targetAccount: string;
|
|
845
|
+
targetAgentId?: string;
|
|
846
|
+
collateral: {
|
|
847
|
+
amount: bigint;
|
|
848
|
+
token: string;
|
|
849
|
+
};
|
|
850
|
+
borrowed?: bigint;
|
|
851
|
+
totalCollateral: bigint;
|
|
852
|
+
totalDebt: bigint;
|
|
853
|
+
}
|
|
854
|
+
interface RepayResult {
|
|
855
|
+
tx: string;
|
|
856
|
+
amount: bigint;
|
|
857
|
+
remainingDebt: bigint;
|
|
858
|
+
}
|
|
859
|
+
interface WithdrawResult {
|
|
860
|
+
tx: string;
|
|
861
|
+
amount: bigint;
|
|
862
|
+
token: string;
|
|
863
|
+
destination: string;
|
|
864
|
+
remainingCollateral: bigint;
|
|
865
|
+
}
|
|
866
|
+
declare class MorphoCreditClient {
|
|
867
|
+
private signer;
|
|
868
|
+
private config;
|
|
869
|
+
private morpho;
|
|
870
|
+
private factory;
|
|
871
|
+
private accountAddress?;
|
|
872
|
+
private collaterals;
|
|
873
|
+
constructor(config: MorphoCreditConfig, collaterals?: Record<string, CollateralToken>);
|
|
874
|
+
private resolveToken;
|
|
875
|
+
/**
|
|
876
|
+
* Get the AgentAccount address for the configured agentId.
|
|
877
|
+
*/
|
|
878
|
+
getAccountAddress(): Promise<string>;
|
|
879
|
+
/**
|
|
880
|
+
* Get the AgentAccount address for any agentId.
|
|
881
|
+
*/
|
|
882
|
+
getAccountForAgent(agentId: string | bigint): Promise<string>;
|
|
883
|
+
private ensureCreditProvider;
|
|
884
|
+
private approveAndDeposit;
|
|
885
|
+
private executeBorrow;
|
|
886
|
+
/**
|
|
887
|
+
* Deposit collateral from EOA into Morpho for own AgentAccount.
|
|
888
|
+
* Does NOT borrow — use `borrow()` or `depositAndBorrow()` for that.
|
|
889
|
+
*
|
|
890
|
+
* @param tokenSymbol - Collateral token (WETH, wstETH, cbETH)
|
|
891
|
+
* @param amount - Human-readable amount (e.g. "0.05")
|
|
892
|
+
*/
|
|
893
|
+
deposit(tokenSymbol: string, amount: string): Promise<DepositResult>;
|
|
894
|
+
/**
|
|
895
|
+
* Deposit collateral AND borrow USDC in a single SDK call.
|
|
896
|
+
* USDC lands in the AgentAccount.
|
|
897
|
+
*
|
|
898
|
+
* @param tokenSymbol - Collateral token (WETH, wstETH, cbETH)
|
|
899
|
+
* @param collateralAmount - Human-readable collateral amount (e.g. "0.05")
|
|
900
|
+
* @param borrowAmount - Human-readable USDC amount to borrow (e.g. "50")
|
|
901
|
+
*/
|
|
902
|
+
depositAndBorrow(tokenSymbol: string, collateralAmount: string, borrowAmount: string): Promise<DepositAndBorrowResult>;
|
|
903
|
+
/**
|
|
904
|
+
* Borrow USDC against already-deposited collateral.
|
|
905
|
+
* Auto-detects which collateral token has a position.
|
|
906
|
+
* USDC lands in AgentAccount — ready for x402 payments.
|
|
907
|
+
*
|
|
908
|
+
* @param amount - Human-readable USDC amount (e.g. "100")
|
|
909
|
+
*/
|
|
910
|
+
borrow(amount: string): Promise<BorrowResult>;
|
|
911
|
+
/**
|
|
912
|
+
* Deposit collateral for another agent. Caller pays from their wallet.
|
|
913
|
+
* Optionally borrow USDC for the agent (only works if caller owns the AgentAccount).
|
|
914
|
+
*
|
|
915
|
+
* Supports both agentId lookup and direct address.
|
|
916
|
+
*
|
|
917
|
+
* @param target - `{ agentId: "17676" }` or `{ address: "0x..." }`
|
|
918
|
+
* @param tokenSymbol - Collateral token
|
|
919
|
+
* @param amount - Human-readable collateral amount
|
|
920
|
+
* @param borrowAmount - Optional: USDC to borrow (only if caller is owner)
|
|
921
|
+
*/
|
|
922
|
+
sponsor(target: {
|
|
923
|
+
agentId: string | bigint;
|
|
924
|
+
} | {
|
|
925
|
+
address: string;
|
|
926
|
+
}, tokenSymbol: string, amount: string, borrowAmount?: string): Promise<SponsorResult>;
|
|
927
|
+
/**
|
|
928
|
+
* Repay borrowed USDC from AgentAccount back to Morpho.
|
|
929
|
+
*
|
|
930
|
+
* @param amount - Human-readable USDC amount (e.g. "50")
|
|
931
|
+
*/
|
|
932
|
+
repay(amount: string): Promise<RepayResult>;
|
|
933
|
+
/**
|
|
934
|
+
* Withdraw collateral from Morpho back to EOA.
|
|
935
|
+
*
|
|
936
|
+
* @param tokenSymbol - Collateral token
|
|
937
|
+
* @param amount - Human-readable amount or "all"
|
|
938
|
+
*/
|
|
939
|
+
withdraw(tokenSymbol: string, amount: string): Promise<WithdrawResult>;
|
|
940
|
+
/**
|
|
941
|
+
* Get position for a specific collateral token.
|
|
942
|
+
*/
|
|
943
|
+
getPosition(tokenSymbol: string): Promise<MorphoPosition>;
|
|
944
|
+
/**
|
|
945
|
+
* Get all active positions across all collateral tokens.
|
|
946
|
+
*/
|
|
947
|
+
getAllPositions(): Promise<MorphoPosition[]>;
|
|
948
|
+
/**
|
|
949
|
+
* Get total debt across all positions.
|
|
950
|
+
*/
|
|
951
|
+
getTotalDebt(): Promise<bigint>;
|
|
952
|
+
/**
|
|
953
|
+
* Get USDC balance in the AgentAccount.
|
|
954
|
+
*/
|
|
955
|
+
getAccountUSDC(): Promise<bigint>;
|
|
956
|
+
/** Get the wallet (signer) address */
|
|
957
|
+
getAddress(): string;
|
|
958
|
+
}
|
|
959
|
+
|
|
767
960
|
/**
|
|
768
961
|
* WalletClient - SDK for AgentAccount (smart wallet) operations (v2)
|
|
769
962
|
*
|
|
@@ -930,4 +1123,4 @@ declare const VALIDATION_REGISTRY_ABI: string[];
|
|
|
930
1123
|
declare const MORPHO_CREDIT_ABI: string[];
|
|
931
1124
|
declare const ERC20_ABI: string[];
|
|
932
1125
|
|
|
933
|
-
export { ACCOUNT_FACTORY_ABI, AGENT_ACCOUNT_ABI, AGENT_REPUTATION_ABI, AgentIdentityClient, type AgentIdentityClientOptions, type AgentReputation, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type BayesianScore, CREDIT_PROVIDER_ABI, ChainId, type ContractAddresses, type CreditApplication, type CreditAppliedEvent, type CreditApprovedEvent, type CreditDrawnEvent, type CreditInfo, type CreditLine, CreditNotActiveError, type CreditRejectedEvent, type CreditRepaidEvent, CreditStatus, type DrawRequest, ERC20_ABI, type GraduationStatus, IDENTITY_REGISTRY_ABI, InsufficientCreditError, type LPPosition, LP_VAULT_ABI, type LoanPosition, MORPHO_CREDIT_ABI, type MorphoMarketParams, type PaymentProof, type PaymentRequirements, type ProviderStatus, REPUTATION_CREDIT_ABI, type RepayRequest, type RiskCheckResponse, type RiskFactor, type ScoreExplanation, type ScoredLimitPreview, ScoringClient, type ScoringContext, ScoringRejectedError, type ScoringRequest, type ScoringResult, type TransactionResult, VALIDATION_REGISTRY_ABI, VaultClient, type VaultClientOptions, type VaultStats, WalletClient, type WalletClientConfig, type WalletInfo, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, getUSDCAddress, parseUnits, rateToBps };
|
|
1126
|
+
export { ACCOUNT_FACTORY_ABI, AGENT_ACCOUNT_ABI, AGENT_REPUTATION_ABI, AgentIdentityClient, type AgentIdentityClientOptions, type AgentReputation, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type BayesianScore, type BorrowResult, CREDIT_PROVIDER_ABI, ChainId, type CollateralToken, type ContractAddresses, type CreditApplication, type CreditAppliedEvent, type CreditApprovedEvent, type CreditDrawnEvent, type CreditInfo, type CreditLine, CreditNotActiveError, type CreditRejectedEvent, type CreditRepaidEvent, CreditStatus, type DepositAndBorrowResult, type DepositResult, type DrawRequest, ERC20_ABI, type GraduationStatus, IDENTITY_REGISTRY_ABI, InsufficientCreditError, type LPPosition, LP_VAULT_ABI, type LoanPosition, MORPHO_CREDIT_ABI, MorphoCreditClient, type MorphoCreditConfig, type MorphoMarketParams, type MorphoPosition, type PaymentProof, type PaymentRequirements, type ProviderStatus, REPUTATION_CREDIT_ABI, type RepayRequest, type RepayResult, type RiskCheckResponse, type RiskFactor, type ScoreExplanation, type ScoredLimitPreview, ScoringClient, type ScoringContext, ScoringRejectedError, type ScoringRequest, type ScoringResult, type SponsorResult, type TransactionResult, VALIDATION_REGISTRY_ABI, VaultClient, type VaultClientOptions, type VaultStats, WalletClient, type WalletClientConfig, type WalletInfo, type WithdrawResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, getUSDCAddress, parseUnits, rateToBps };
|