@agether/sdk 2.6.0 → 2.7.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.
Files changed (37) hide show
  1. package/README.md +39 -27
  2. package/dist/cli.js +49 -33
  3. package/dist/index.d.mts +43 -19
  4. package/dist/index.d.ts +43 -19
  5. package/dist/index.js +60 -29
  6. package/dist/index.mjs +57 -29
  7. package/package.json +2 -2
  8. package/dist/cli.d.ts +0 -27
  9. package/dist/cli.d.ts.map +0 -1
  10. package/dist/clients/AgentIdentityClient.d.ts +0 -188
  11. package/dist/clients/AgentIdentityClient.d.ts.map +0 -1
  12. package/dist/clients/AgentIdentityClient.js +0 -337
  13. package/dist/clients/AgetherClient.d.ts +0 -74
  14. package/dist/clients/AgetherClient.d.ts.map +0 -1
  15. package/dist/clients/AgetherClient.js +0 -172
  16. package/dist/clients/MorphoClient.d.ts +0 -482
  17. package/dist/clients/MorphoClient.d.ts.map +0 -1
  18. package/dist/clients/MorphoClient.js +0 -1717
  19. package/dist/clients/ScoringClient.d.ts +0 -89
  20. package/dist/clients/ScoringClient.d.ts.map +0 -1
  21. package/dist/clients/ScoringClient.js +0 -93
  22. package/dist/clients/X402Client.d.ts +0 -168
  23. package/dist/clients/X402Client.d.ts.map +0 -1
  24. package/dist/clients/X402Client.js +0 -378
  25. package/dist/index.d.ts.map +0 -1
  26. package/dist/types/index.d.ts +0 -132
  27. package/dist/types/index.d.ts.map +0 -1
  28. package/dist/types/index.js +0 -46
  29. package/dist/utils/abis.d.ts +0 -29
  30. package/dist/utils/abis.d.ts.map +0 -1
  31. package/dist/utils/abis.js +0 -139
  32. package/dist/utils/config.d.ts +0 -36
  33. package/dist/utils/config.d.ts.map +0 -1
  34. package/dist/utils/config.js +0 -168
  35. package/dist/utils/format.d.ts +0 -44
  36. package/dist/utils/format.d.ts.map +0 -1
  37. package/dist/utils/format.js +0 -75
@@ -1,139 +0,0 @@
1
- /**
2
- * Contract ABIs (minimal for SDK)
3
- *
4
- * Architecture (v2 — Safe + Safe7579):
5
- * - Agether4337Factory (deploys Safe proxies with modules)
6
- * - Agether8004ValidationModule (ownership + KYA + module lock)
7
- * - AgetherHookMultiplexer (admin-managed hooks)
8
- * - Agether8004Scorer (oracle-based credit scores)
9
- * - ValidationRegistry (KYA code validation)
10
- * - ERC-8004 IdentityRegistry
11
- * - Morpho Blue (direct overcollateralized lending)
12
- * - EntryPoint v0.7 (ERC-4337 UserOp submission)
13
- */
14
- // ── ERC-8004 Identity Registry ──
15
- export const IDENTITY_REGISTRY_ABI = [
16
- 'function ownerOf(uint256 agentId) view returns (address)',
17
- 'function balanceOf(address owner) view returns (uint256)',
18
- 'function totalSupply() view returns (uint256)',
19
- 'function exists(uint256 agentId) view returns (bool)',
20
- 'function register() returns (uint256 agentId)',
21
- 'event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)',
22
- ];
23
- // ── Agether4337Factory (v2 — replaces old AccountFactory) ──
24
- export const AGETHER_4337_FACTORY_ABI = [
25
- 'function getAccount(uint256 agentId) view returns (address)',
26
- 'function accountExists(uint256 agentId) view returns (bool)',
27
- 'function totalAccounts() view returns (uint256)',
28
- 'function getAgentId(address account) view returns (uint256)',
29
- 'function getAgentIdByIndex(uint256 index) view returns (uint256)',
30
- 'function getAllAgentIds() view returns (uint256[])',
31
- 'function createAccount(uint256 agentId) returns (address safeAccount)',
32
- 'function identityRegistry() view returns (address)',
33
- 'function validationModule() view returns (address)',
34
- 'function hookMultiplexer() view returns (address)',
35
- 'function safeSingleton() view returns (address)',
36
- 'function safe7579() view returns (address)',
37
- 'function bootstrap() view returns (address)',
38
- 'event AccountCreated(uint256 indexed agentId, address indexed safeAccount, address indexed owner)',
39
- ];
40
- // ── Backward compat aliases ──
41
- export const SAFE_AGENT_FACTORY_ABI = AGETHER_4337_FACTORY_ABI;
42
- export const ACCOUNT_FACTORY_ABI = AGETHER_4337_FACTORY_ABI;
43
- // ── Agether8004ValidationModule (v2 — replaces AgentAccount + KYA Hook) ──
44
- export const AGETHER_8004_VALIDATION_MODULE_ABI = [
45
- // View
46
- 'function getConfig(address account) view returns (address registry, uint256 agentId)',
47
- 'function getOwner(address account) view returns (address)',
48
- 'function isInstalled(address account) view returns (bool)',
49
- 'function isKYAApproved(address account) view returns (bool)',
50
- 'function validationRegistry() view returns (address)',
51
- 'function owner() view returns (address)',
52
- // Admin (via TimelockController)
53
- 'function setValidationRegistry(address registry_)',
54
- ];
55
- // ── Backward compat alias ──
56
- export const ERC8004_VALIDATION_MODULE_ABI = AGETHER_8004_VALIDATION_MODULE_ABI;
57
- // ── AgetherHookMultiplexer (v2) ──
58
- export const AGETHER_HOOK_MULTIPLEXER_ABI = [
59
- 'function getHooks() view returns (address[])',
60
- 'function hookCount() view returns (uint256)',
61
- 'function owner() view returns (address)',
62
- 'function addHook(address hook)',
63
- 'function removeHook(address hook)',
64
- ];
65
- // ── Backward compat alias ──
66
- export const HOOK_MULTIPLEXER_ABI = AGETHER_HOOK_MULTIPLEXER_ABI;
67
- // ── Agether8004Scorer (oracle-based scoring) ──
68
- export const AGETHER_8004_SCORER_ABI = [
69
- 'function getCreditScore(uint256 agentId) view returns (uint256)',
70
- 'function getAttestation(uint256 agentId) view returns (tuple(uint256 score, uint256 timestamp, address signer))',
71
- 'function isScoreFresh(uint256 agentId) view returns (bool fresh, uint256 age)',
72
- 'function isEligible(uint256 agentId, uint256 minScore) view returns (bool eligible, uint256 currentScore)',
73
- 'function oracleSigner() view returns (address)',
74
- 'function submitScore(uint256 agentId, uint256 score_, uint256 timestamp_, bytes signature)',
75
- 'function setOracleSigner(address signer_)',
76
- 'event ScoreUpdated(uint256 indexed agentId, uint256 score, uint256 timestamp, address signer)',
77
- ];
78
- // ── Backward compat alias ──
79
- export const AGENT_REPUTATION_ABI = AGETHER_8004_SCORER_ABI;
80
- // ── Validation Registry (KYA) ──
81
- export const VALIDATION_REGISTRY_ABI = [
82
- 'function isAgentCodeApproved(uint256 agentId) view returns (bool)',
83
- 'function isAgentCodeApprovedForTag(uint256 agentId, string tag) view returns (bool)',
84
- 'function getAgentValidations(uint256 agentId) view returns (bytes32[])',
85
- 'function getValidation(bytes32 requestHash) view returns (tuple(address validatorAddress, uint256 agentId, string requestURI, uint8 response, string responseURI, bytes32 responseHash, string tag, uint256 requestedAt, uint256 respondedAt, bool hasResponse))',
86
- ];
87
- // ── Morpho Blue (direct lending protocol) ──
88
- export const MORPHO_BLUE_ABI = [
89
- // Supply & Withdraw (lending side)
90
- 'function supply(tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) returns (uint256 assetsSupplied, uint256 sharesSupplied)',
91
- 'function withdraw(tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn)',
92
- // Collateral
93
- 'function supplyCollateral(tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, address onBehalf, bytes data)',
94
- 'function withdrawCollateral(tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, address onBehalf, address receiver)',
95
- // Borrow & Repay
96
- 'function borrow(tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) returns (uint256 assetsBorrowed, uint256 sharesBorrowed)',
97
- 'function repay(tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) returns (uint256 assetsRepaid, uint256 sharesRepaid)',
98
- // Authorization
99
- 'function setAuthorization(address authorized, bool newIsAuthorized)',
100
- 'function isAuthorized(address authorizer, address authorized) view returns (bool)',
101
- // Views
102
- 'function position(bytes32 id, address user) view returns (uint256 supplyShares, uint128 borrowShares, uint128 collateral)',
103
- 'function market(bytes32 id) view returns (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee)',
104
- 'function idToMarketParams(bytes32 id) view returns (tuple(address loanToken, address collateralToken, address oracle, address irm, uint256 lltv))',
105
- // Events (for yield tracking via eth_getLogs — no indexer needed)
106
- 'event Supply(bytes32 indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares)',
107
- 'event Withdraw(bytes32 indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 assets, uint256 shares)',
108
- ];
109
- // ── ERC-20 ──
110
- export const ERC20_ABI = [
111
- 'function balanceOf(address account) view returns (uint256)',
112
- 'function allowance(address owner, address spender) view returns (uint256)',
113
- 'function approve(address spender, uint256 amount) returns (bool)',
114
- 'function transfer(address to, uint256 amount) returns (bool)',
115
- 'function transferFrom(address from, address to, uint256 amount) returns (bool)',
116
- 'function decimals() view returns (uint8)',
117
- 'function symbol() view returns (string)',
118
- 'function name() view returns (string)',
119
- ];
120
- // ── EntryPoint v0.7 (ERC-4337) ──
121
- export const ENTRYPOINT_V07_ABI = [
122
- 'function handleOps(tuple(address sender, uint256 nonce, bytes initCode, bytes callData, bytes32 accountGasLimits, uint256 preVerificationGas, bytes32 gasFees, bytes paymasterAndData, bytes signature)[] ops, address payable beneficiary)',
123
- 'function getUserOpHash(tuple(address sender, uint256 nonce, bytes initCode, bytes callData, bytes32 accountGasLimits, uint256 preVerificationGas, bytes32 gasFees, bytes paymasterAndData, bytes signature) userOp) view returns (bytes32)',
124
- 'function getNonce(address sender, uint192 key) view returns (uint256 nonce)',
125
- 'function balanceOf(address account) view returns (uint256)',
126
- 'function depositTo(address account) payable',
127
- 'event UserOperationEvent(bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed)',
128
- 'event UserOperationRevertReason(bytes32 indexed userOpHash, address indexed sender, uint256 nonce, bytes revertReason)',
129
- ];
130
- // ── Safe7579 Account Interface (execute via fallback handler) ──
131
- export const SAFE7579_ACCOUNT_ABI = [
132
- // ERC-7579 execution (called via UserOp through Safe7579 fallback)
133
- 'function execute(bytes32 mode, bytes executionCalldata) payable',
134
- 'function executeFromExecutor(bytes32 mode, bytes executionCalldata) payable returns (bytes[])',
135
- // ERC-7579 module queries
136
- 'function isModuleInstalled(uint256 moduleTypeId, address module, bytes additionalContext) view returns (bool)',
137
- // EIP-1271
138
- 'function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)',
139
- ];
@@ -1,36 +0,0 @@
1
- /**
2
- * Network configurations
3
- *
4
- * Contract architecture (v2 — Safe + Safe7579):
5
- * - Agether4337Factory + Safe proxy (4337-only smart wallets)
6
- * - Agether8004ValidationModule (ownership + KYA + module lock)
7
- * - AgetherHookMultiplexer (admin-managed hooks)
8
- * - Agether8004Scorer (oracle-based scoring)
9
- * - ValidationRegistry (KYA code validation)
10
- * - ERC-8004 IdentityRegistry
11
- * - Morpho Blue (direct overcollateralized lending)
12
- *
13
- * All contract addresses are baked in — agents only need to specify chainId.
14
- */
15
- import { AgetherConfig, ChainId, ContractAddresses } from '../types';
16
- /**
17
- * Get default config for a chain — includes all addresses, RPC, and scoring endpoint.
18
- */
19
- export declare function getDefaultConfig(chainId: ChainId): AgetherConfig;
20
- /**
21
- * Create custom config (override any defaults)
22
- */
23
- export declare function createConfig(chainId: ChainId, options?: Partial<AgetherConfig>): AgetherConfig;
24
- /**
25
- * Get USDC address for chain
26
- */
27
- export declare function getUSDCAddress(chainId: ChainId): string;
28
- /**
29
- * Get Morpho Blue address for chain
30
- */
31
- export declare function getMorphoBlueAddress(chainId: ChainId): string;
32
- /**
33
- * Get all contract addresses for a chain
34
- */
35
- export declare function getContractAddresses(chainId: ChainId): ContractAddresses;
36
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAsHrE;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAOhE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC/B,aAAa,CAUf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAExE"}
@@ -1,168 +0,0 @@
1
- /**
2
- * Network configurations
3
- *
4
- * Contract architecture (v2 — Safe + Safe7579):
5
- * - Agether4337Factory + Safe proxy (4337-only smart wallets)
6
- * - Agether8004ValidationModule (ownership + KYA + module lock)
7
- * - AgetherHookMultiplexer (admin-managed hooks)
8
- * - Agether8004Scorer (oracle-based scoring)
9
- * - ValidationRegistry (KYA code validation)
10
- * - ERC-8004 IdentityRegistry
11
- * - Morpho Blue (direct overcollateralized lending)
12
- *
13
- * All contract addresses are baked in — agents only need to specify chainId.
14
- */
15
- import { ChainId } from '../types';
16
- // Zero address placeholder for networks without deployments
17
- const ZERO = '0x0000000000000000000000000000000000000000';
18
- // Well-known cross-chain addresses
19
- const ENTRYPOINT_V07 = '0x0000000071727De22E5E9d8BAf0edAc6f37da032';
20
- const ERC8004_IDENTITY_REGISTRY = '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432';
21
- const ERC8004_IDENTITY_REGISTRY_TESTNET = '0x8004A818BFB912233c491871b3d84c89A494BD9e';
22
- const MORPHO_BLUE = '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb';
23
- // Safe infrastructure (same addresses across chains)
24
- const SAFE_SINGLETON = '0x41675C099F32341bf84BFc5382aF534df5C7461a';
25
- const SAFE_PROXY_FACTORY = '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67';
26
- const SAFE7579 = '0x7579EE8307284F293B1927136486880611F20002';
27
- // Contract addresses per network
28
- const CONTRACT_ADDRESSES = {
29
- [ChainId.Ethereum]: {
30
- safeSingleton: SAFE_SINGLETON,
31
- safeProxyFactory: SAFE_PROXY_FACTORY,
32
- safe7579: SAFE7579,
33
- entryPoint: ENTRYPOINT_V07,
34
- agether4337Factory: ZERO,
35
- agether7579Bootstrap: ZERO,
36
- erc8004ValidationModule: ZERO,
37
- agetherHookMultiplexer: ZERO,
38
- validationRegistry: ZERO,
39
- agether8004Scorer: ZERO,
40
- timelockController: ZERO,
41
- usdc: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
42
- identityRegistry: ERC8004_IDENTITY_REGISTRY,
43
- morphoBlue: MORPHO_BLUE,
44
- },
45
- [ChainId.Base]: {
46
- safeSingleton: SAFE_SINGLETON,
47
- safeProxyFactory: SAFE_PROXY_FACTORY,
48
- safe7579: SAFE7579,
49
- entryPoint: ENTRYPOINT_V07,
50
- agether4337Factory: '0x67DE66D07ff3dba0092C21f070f8a0f53D657BC3',
51
- agether7579Bootstrap: '0xCc83AA714c05B7141B21a17e80EB21bD09652b27',
52
- erc8004ValidationModule: '0xde896C58163b5f6cAC5B16C1b0109843f26106F6',
53
- agetherHookMultiplexer: '0x4AB6DaD0f7360fa8d8c75889A5c206B65d7CbeDb',
54
- validationRegistry: ZERO,
55
- agether8004Scorer: '0x56c7D35A976fac67b1993b66b861fCA32f59104F',
56
- timelockController: '0xc600e7AAB8a230326C714CE66f356fdf6aC021d8',
57
- usdc: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
58
- identityRegistry: ERC8004_IDENTITY_REGISTRY,
59
- morphoBlue: MORPHO_BLUE,
60
- },
61
- [ChainId.BaseSepolia]: {
62
- safeSingleton: SAFE_SINGLETON,
63
- safeProxyFactory: SAFE_PROXY_FACTORY,
64
- safe7579: SAFE7579,
65
- entryPoint: ENTRYPOINT_V07,
66
- agether4337Factory: ZERO,
67
- agether7579Bootstrap: ZERO,
68
- erc8004ValidationModule: ZERO,
69
- agetherHookMultiplexer: ZERO,
70
- validationRegistry: ZERO,
71
- agether8004Scorer: ZERO,
72
- timelockController: ZERO,
73
- usdc: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
74
- identityRegistry: ERC8004_IDENTITY_REGISTRY_TESTNET,
75
- morphoBlue: ZERO,
76
- },
77
- [ChainId.Sepolia]: {
78
- safeSingleton: SAFE_SINGLETON,
79
- safeProxyFactory: SAFE_PROXY_FACTORY,
80
- safe7579: SAFE7579,
81
- entryPoint: ENTRYPOINT_V07,
82
- agether4337Factory: ZERO,
83
- agether7579Bootstrap: ZERO,
84
- erc8004ValidationModule: ZERO,
85
- agetherHookMultiplexer: ZERO,
86
- validationRegistry: ZERO,
87
- agether8004Scorer: ZERO,
88
- timelockController: ZERO,
89
- usdc: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
90
- identityRegistry: ERC8004_IDENTITY_REGISTRY_TESTNET,
91
- morphoBlue: ZERO,
92
- },
93
- [ChainId.Hardhat]: {
94
- safeSingleton: SAFE_SINGLETON,
95
- safeProxyFactory: SAFE_PROXY_FACTORY,
96
- safe7579: SAFE7579,
97
- entryPoint: ENTRYPOINT_V07,
98
- agether4337Factory: ZERO,
99
- agether7579Bootstrap: ZERO,
100
- erc8004ValidationModule: ZERO,
101
- agetherHookMultiplexer: ZERO,
102
- validationRegistry: ZERO,
103
- agether8004Scorer: ZERO,
104
- timelockController: ZERO,
105
- usdc: '0x56d4d6aEe0278c5Df2FA23Ecb32eC146C9446FDf',
106
- identityRegistry: ERC8004_IDENTITY_REGISTRY,
107
- morphoBlue: ZERO,
108
- },
109
- };
110
- // Default RPC URLs
111
- const RPC_URLS = {
112
- [ChainId.Ethereum]: 'https://ethereum-rpc.publicnode.com',
113
- [ChainId.Base]: 'https://base-rpc.publicnode.com',
114
- [ChainId.BaseSepolia]: 'https://sepolia.base.org',
115
- [ChainId.Sepolia]: 'https://rpc.sepolia.org',
116
- [ChainId.Hardhat]: 'http://127.0.0.1:8545',
117
- };
118
- // Scoring service endpoints
119
- const SCORING_ENDPOINTS = {
120
- [ChainId.Ethereum]: 'https://scoring.agether.ai/v1',
121
- [ChainId.Base]: 'http://95.179.189.214:3001',
122
- [ChainId.BaseSepolia]: 'http://95.179.189.214:3001',
123
- [ChainId.Sepolia]: 'https://scoring-testnet.agether.ai/v1',
124
- [ChainId.Hardhat]: 'http://127.0.0.1:3001',
125
- };
126
- /**
127
- * Get default config for a chain — includes all addresses, RPC, and scoring endpoint.
128
- */
129
- export function getDefaultConfig(chainId) {
130
- return {
131
- chainId,
132
- rpcUrl: RPC_URLS[chainId],
133
- contracts: CONTRACT_ADDRESSES[chainId],
134
- scoringEndpoint: SCORING_ENDPOINTS[chainId],
135
- };
136
- }
137
- /**
138
- * Create custom config (override any defaults)
139
- */
140
- export function createConfig(chainId, options) {
141
- const defaultConfig = getDefaultConfig(chainId);
142
- return {
143
- ...defaultConfig,
144
- ...options,
145
- contracts: {
146
- ...defaultConfig.contracts,
147
- ...options?.contracts,
148
- },
149
- };
150
- }
151
- /**
152
- * Get USDC address for chain
153
- */
154
- export function getUSDCAddress(chainId) {
155
- return CONTRACT_ADDRESSES[chainId].usdc;
156
- }
157
- /**
158
- * Get Morpho Blue address for chain
159
- */
160
- export function getMorphoBlueAddress(chainId) {
161
- return CONTRACT_ADDRESSES[chainId].morphoBlue;
162
- }
163
- /**
164
- * Get all contract addresses for a chain
165
- */
166
- export function getContractAddresses(chainId) {
167
- return CONTRACT_ADDRESSES[chainId];
168
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * Formatting utilities
3
- */
4
- /**
5
- * Parse units (e.g., "100" USDC -> 100000000n)
6
- */
7
- export declare function parseUnits(value: string, decimals?: number): bigint;
8
- /**
9
- * Format units (e.g., 100000000n -> "100.00" USDC)
10
- */
11
- export declare function formatUnits(value: bigint, decimals?: number): string;
12
- /**
13
- * Format USD value
14
- */
15
- export declare function formatUSD(value: bigint, decimals?: number): string;
16
- /**
17
- * Format percentage
18
- */
19
- export declare function formatPercent(bps: number): string;
20
- /**
21
- * Format APR from basis points
22
- */
23
- export declare function formatAPR(bps: bigint): string;
24
- /**
25
- * Calculate health factor display
26
- */
27
- export declare function formatHealthFactor(factor: bigint): string;
28
- /**
29
- * Format address (truncate)
30
- */
31
- export declare function formatAddress(address: string): string;
32
- /**
33
- * Format timestamp to date
34
- */
35
- export declare function formatTimestamp(timestamp: bigint): string;
36
- /**
37
- * Convert basis points to decimal rate
38
- */
39
- export declare function bpsToRate(bps: bigint): number;
40
- /**
41
- * Convert decimal rate to basis points
42
- */
43
- export declare function rateToBps(rate: number): bigint;
44
- //# sourceMappingURL=format.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAItE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAKvE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAMrE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
@@ -1,75 +0,0 @@
1
- /**
2
- * Formatting utilities
3
- */
4
- /**
5
- * Parse units (e.g., "100" USDC -> 100000000n)
6
- */
7
- export function parseUnits(value, decimals = 6) {
8
- const [integer, fraction = ''] = value.split('.');
9
- const paddedFraction = fraction.padEnd(decimals, '0').slice(0, decimals);
10
- return BigInt(integer + paddedFraction);
11
- }
12
- /**
13
- * Format units (e.g., 100000000n -> "100.00" USDC)
14
- */
15
- export function formatUnits(value, decimals = 6) {
16
- const str = value.toString().padStart(decimals + 1, '0');
17
- const integer = str.slice(0, -decimals) || '0';
18
- const fraction = str.slice(-decimals);
19
- return `${integer}.${fraction}`;
20
- }
21
- /**
22
- * Format USD value
23
- */
24
- export function formatUSD(value, decimals = 6) {
25
- const num = Number(formatUnits(value, decimals));
26
- return new Intl.NumberFormat('en-US', {
27
- style: 'currency',
28
- currency: 'USD',
29
- }).format(num);
30
- }
31
- /**
32
- * Format percentage
33
- */
34
- export function formatPercent(bps) {
35
- return `${(bps / 100).toFixed(2)}%`;
36
- }
37
- /**
38
- * Format APR from basis points
39
- */
40
- export function formatAPR(bps) {
41
- return formatPercent(Number(bps));
42
- }
43
- /**
44
- * Calculate health factor display
45
- */
46
- export function formatHealthFactor(factor) {
47
- const num = Number(factor) / 1e18;
48
- if (num >= 100)
49
- return '∞';
50
- return num.toFixed(2);
51
- }
52
- /**
53
- * Format address (truncate)
54
- */
55
- export function formatAddress(address) {
56
- return `${address.slice(0, 6)}...${address.slice(-4)}`;
57
- }
58
- /**
59
- * Format timestamp to date
60
- */
61
- export function formatTimestamp(timestamp) {
62
- return new Date(Number(timestamp) * 1000).toISOString();
63
- }
64
- /**
65
- * Convert basis points to decimal rate
66
- */
67
- export function bpsToRate(bps) {
68
- return Number(bps) / 10000;
69
- }
70
- /**
71
- * Convert decimal rate to basis points
72
- */
73
- export function rateToBps(rate) {
74
- return BigInt(Math.round(rate * 10000));
75
- }