amped-defi 1.0.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/README.md +757 -0
- package/dist/__mocks__/@sodax/sdk.d.ts +24 -0
- package/dist/__mocks__/@sodax/sdk.d.ts.map +1 -0
- package/dist/__mocks__/@sodax/sdk.js +24 -0
- package/dist/__mocks__/@sodax/sdk.js.map +1 -0
- package/dist/__tests__/setup.d.ts +4 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +32 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +281 -0
- package/dist/index.js.map +1 -0
- package/dist/policy/policyEngine.d.ts +119 -0
- package/dist/policy/policyEngine.d.ts.map +1 -0
- package/dist/policy/policyEngine.js +322 -0
- package/dist/policy/policyEngine.js.map +1 -0
- package/dist/providers/spokeProviderFactory.d.ts +38 -0
- package/dist/providers/spokeProviderFactory.d.ts.map +1 -0
- package/dist/providers/spokeProviderFactory.js +212 -0
- package/dist/providers/spokeProviderFactory.js.map +1 -0
- package/dist/sodax/client.d.ts +34 -0
- package/dist/sodax/client.d.ts.map +1 -0
- package/dist/sodax/client.js +99 -0
- package/dist/sodax/client.js.map +1 -0
- package/dist/tools/bridge.d.ts +105 -0
- package/dist/tools/bridge.d.ts.map +1 -0
- package/dist/tools/bridge.js +334 -0
- package/dist/tools/bridge.js.map +1 -0
- package/dist/tools/discovery.d.ts +141 -0
- package/dist/tools/discovery.d.ts.map +1 -0
- package/dist/tools/discovery.js +777 -0
- package/dist/tools/discovery.js.map +1 -0
- package/dist/tools/moneyMarket.d.ts +227 -0
- package/dist/tools/moneyMarket.d.ts.map +1 -0
- package/dist/tools/moneyMarket.js +867 -0
- package/dist/tools/moneyMarket.js.map +1 -0
- package/dist/tools/portfolio.d.ts +43 -0
- package/dist/tools/portfolio.d.ts.map +1 -0
- package/dist/tools/portfolio.js +538 -0
- package/dist/tools/portfolio.js.map +1 -0
- package/dist/tools/swap.d.ts +71 -0
- package/dist/tools/swap.d.ts.map +1 -0
- package/dist/tools/swap.js +762 -0
- package/dist/tools/swap.js.map +1 -0
- package/dist/tools/walletManagement.d.ts +80 -0
- package/dist/tools/walletManagement.d.ts.map +1 -0
- package/dist/tools/walletManagement.js +289 -0
- package/dist/tools/walletManagement.js.map +1 -0
- package/dist/types.d.ts +205 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/errorUtils.d.ts +2 -0
- package/dist/utils/errorUtils.d.ts.map +1 -0
- package/dist/utils/errorUtils.js +19 -0
- package/dist/utils/errorUtils.js.map +1 -0
- package/dist/utils/errors.d.ts +144 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +310 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/positionAggregator.d.ts +122 -0
- package/dist/utils/positionAggregator.d.ts.map +1 -0
- package/dist/utils/positionAggregator.js +377 -0
- package/dist/utils/positionAggregator.js.map +1 -0
- package/dist/utils/priceService.d.ts +45 -0
- package/dist/utils/priceService.d.ts.map +1 -0
- package/dist/utils/priceService.js +108 -0
- package/dist/utils/priceService.js.map +1 -0
- package/dist/utils/sodaxApi.d.ts +92 -0
- package/dist/utils/sodaxApi.d.ts.map +1 -0
- package/dist/utils/sodaxApi.js +143 -0
- package/dist/utils/sodaxApi.js.map +1 -0
- package/dist/utils/tokenResolver.d.ts +54 -0
- package/dist/utils/tokenResolver.d.ts.map +1 -0
- package/dist/utils/tokenResolver.js +252 -0
- package/dist/utils/tokenResolver.js.map +1 -0
- package/dist/wallet/backendConfig.d.ts +37 -0
- package/dist/wallet/backendConfig.d.ts.map +1 -0
- package/dist/wallet/backendConfig.js +125 -0
- package/dist/wallet/backendConfig.js.map +1 -0
- package/dist/wallet/backends/BankrBackend.d.ts +73 -0
- package/dist/wallet/backends/BankrBackend.d.ts.map +1 -0
- package/dist/wallet/backends/BankrBackend.js +315 -0
- package/dist/wallet/backends/BankrBackend.js.map +1 -0
- package/dist/wallet/backends/BankrWalletProvider.d.ts +75 -0
- package/dist/wallet/backends/BankrWalletProvider.d.ts.map +1 -0
- package/dist/wallet/backends/BankrWalletProvider.js +243 -0
- package/dist/wallet/backends/BankrWalletProvider.js.map +1 -0
- package/dist/wallet/backends/EnvBackend.d.ts +50 -0
- package/dist/wallet/backends/EnvBackend.d.ts.map +1 -0
- package/dist/wallet/backends/EnvBackend.js +114 -0
- package/dist/wallet/backends/EnvBackend.js.map +1 -0
- package/dist/wallet/backends/EvmWalletSkillBackend.d.ts +40 -0
- package/dist/wallet/backends/EvmWalletSkillBackend.d.ts.map +1 -0
- package/dist/wallet/backends/EvmWalletSkillBackend.js +81 -0
- package/dist/wallet/backends/EvmWalletSkillBackend.js.map +1 -0
- package/dist/wallet/backends/index.d.ts +10 -0
- package/dist/wallet/backends/index.d.ts.map +1 -0
- package/dist/wallet/backends/index.js +10 -0
- package/dist/wallet/backends/index.js.map +1 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +12 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/providers/AmpedWalletProvider.d.ts +107 -0
- package/dist/wallet/providers/AmpedWalletProvider.d.ts.map +1 -0
- package/dist/wallet/providers/AmpedWalletProvider.js +208 -0
- package/dist/wallet/providers/AmpedWalletProvider.js.map +1 -0
- package/dist/wallet/providers/BankrBackend.d.ts +105 -0
- package/dist/wallet/providers/BankrBackend.d.ts.map +1 -0
- package/dist/wallet/providers/BankrBackend.js +327 -0
- package/dist/wallet/providers/BankrBackend.js.map +1 -0
- package/dist/wallet/providers/LocalKeyBackend.d.ts +62 -0
- package/dist/wallet/providers/LocalKeyBackend.d.ts.map +1 -0
- package/dist/wallet/providers/LocalKeyBackend.js +152 -0
- package/dist/wallet/providers/LocalKeyBackend.js.map +1 -0
- package/dist/wallet/providers/chainConfig.d.ts +209 -0
- package/dist/wallet/providers/chainConfig.d.ts.map +1 -0
- package/dist/wallet/providers/chainConfig.js +175 -0
- package/dist/wallet/providers/chainConfig.js.map +1 -0
- package/dist/wallet/providers/index.d.ts +30 -0
- package/dist/wallet/providers/index.d.ts.map +1 -0
- package/dist/wallet/providers/index.js +32 -0
- package/dist/wallet/providers/index.js.map +1 -0
- package/dist/wallet/providers/types.d.ts +156 -0
- package/dist/wallet/providers/types.d.ts.map +1 -0
- package/dist/wallet/providers/types.js +11 -0
- package/dist/wallet/providers/types.js.map +1 -0
- package/dist/wallet/skillWalletAdapter.d.ts +96 -0
- package/dist/wallet/skillWalletAdapter.d.ts.map +1 -0
- package/dist/wallet/skillWalletAdapter.js +280 -0
- package/dist/wallet/skillWalletAdapter.js.map +1 -0
- package/dist/wallet/types.d.ts +134 -0
- package/dist/wallet/types.d.ts.map +1 -0
- package/dist/wallet/types.js +138 -0
- package/dist/wallet/types.js.map +1 -0
- package/dist/wallet/walletManager.d.ts +111 -0
- package/dist/wallet/walletManager.d.ts.map +1 -0
- package/dist/wallet/walletManager.js +476 -0
- package/dist/wallet/walletManager.js.map +1 -0
- package/dist/wallet/walletRegistry.d.ts +95 -0
- package/dist/wallet/walletRegistry.d.ts.map +1 -0
- package/dist/wallet/walletRegistry.js +184 -0
- package/dist/wallet/walletRegistry.js.map +1 -0
- package/index.js +2 -0
- package/openclaw.plugin.json +37 -0
- package/package.json +69 -0
- package/src/__mocks__/@sodax/sdk.ts +28 -0
- package/src/__tests__/errors.test.ts +238 -0
- package/src/__tests__/policyEngine.test.ts +354 -0
- package/src/__tests__/positionAggregator.test.ts +271 -0
- package/src/__tests__/setup.ts +35 -0
- package/src/__tests__/sodaxApi.test.ts +203 -0
- package/src/__tests__/walletRegistry.test.ts +155 -0
- package/src/index.ts +376 -0
- package/src/policy/policyEngine.ts +389 -0
- package/src/providers/spokeProviderFactory.ts +283 -0
- package/src/sodax/client.ts +113 -0
- package/src/tools/bridge.ts +425 -0
- package/src/tools/discovery.ts +989 -0
- package/src/tools/moneyMarket.ts +1265 -0
- package/src/tools/portfolio.ts +697 -0
- package/src/tools/swap.ts +926 -0
- package/src/tools/walletManagement.ts +359 -0
- package/src/types.ts +228 -0
- package/src/utils/errorUtils.ts +16 -0
- package/src/utils/errors.ts +396 -0
- package/src/utils/positionAggregator.ts +559 -0
- package/src/utils/priceService.ts +153 -0
- package/src/utils/sodaxApi.ts +261 -0
- package/src/utils/tokenResolver.ts +286 -0
- package/src/wallet/backendConfig.ts +151 -0
- package/src/wallet/backends/BankrBackend.ts +399 -0
- package/src/wallet/backends/BankrWalletProvider.ts +329 -0
- package/src/wallet/backends/EnvBackend.ts +149 -0
- package/src/wallet/backends/EvmWalletSkillBackend.ts +110 -0
- package/src/wallet/backends/index.ts +10 -0
- package/src/wallet/index.ts +14 -0
- package/src/wallet/providers/AmpedWalletProvider.ts +267 -0
- package/src/wallet/providers/BankrBackend.ts +407 -0
- package/src/wallet/providers/LocalKeyBackend.ts +184 -0
- package/src/wallet/providers/chainConfig.ts +194 -0
- package/src/wallet/providers/index.ts +62 -0
- package/src/wallet/providers/types.ts +186 -0
- package/src/wallet/skillWalletAdapter.ts +335 -0
- package/src/wallet/types.ts +248 -0
- package/src/wallet/walletManager.ts +561 -0
- package/src/wallet/walletRegistry.ts +216 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Key Backend
|
|
3
|
+
*
|
|
4
|
+
* Wallet backend implementation using local private keys.
|
|
5
|
+
* Compatible with evm-wallet-skill's key storage.
|
|
6
|
+
*
|
|
7
|
+
* Uses viem for transaction signing and submission.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
createPublicClient,
|
|
12
|
+
createWalletClient,
|
|
13
|
+
http,
|
|
14
|
+
type Hash,
|
|
15
|
+
type Address,
|
|
16
|
+
type Chain,
|
|
17
|
+
} from 'viem';
|
|
18
|
+
import { privateKeyToAccount, type PrivateKeyAccount } from 'viem/accounts';
|
|
19
|
+
import type {
|
|
20
|
+
IWalletBackend,
|
|
21
|
+
LocalKeyBackendConfig,
|
|
22
|
+
TransactionRequest,
|
|
23
|
+
TransactionReceipt
|
|
24
|
+
} from './types';
|
|
25
|
+
import { getViemChain, getDefaultRpcUrl, resolveChainId } from './chainConfig';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Local private key wallet backend
|
|
29
|
+
*
|
|
30
|
+
* Signs transactions locally using the provided private key.
|
|
31
|
+
* This is the standard backend for self-custody wallets.
|
|
32
|
+
*/
|
|
33
|
+
export class LocalKeyBackend implements IWalletBackend {
|
|
34
|
+
readonly type = 'localKey' as const;
|
|
35
|
+
|
|
36
|
+
private readonly account: PrivateKeyAccount;
|
|
37
|
+
private readonly walletClient: ReturnType<typeof createWalletClient>;
|
|
38
|
+
private readonly _publicClient: ReturnType<typeof createPublicClient>;
|
|
39
|
+
private readonly chainId: number;
|
|
40
|
+
private readonly chain: Chain;
|
|
41
|
+
|
|
42
|
+
constructor(config: LocalKeyBackendConfig) {
|
|
43
|
+
// Resolve chain configuration
|
|
44
|
+
this.chainId = resolveChainId(config.chainId);
|
|
45
|
+
this.chain = getViemChain(this.chainId);
|
|
46
|
+
|
|
47
|
+
// Get RPC URL (custom or default)
|
|
48
|
+
const rpcUrl = config.rpcUrl || getDefaultRpcUrl(this.chainId);
|
|
49
|
+
|
|
50
|
+
// Create account from private key
|
|
51
|
+
this.account = privateKeyToAccount(config.privateKey);
|
|
52
|
+
|
|
53
|
+
// Create viem clients
|
|
54
|
+
this._publicClient = createPublicClient({
|
|
55
|
+
chain: this.chain,
|
|
56
|
+
transport: http(rpcUrl),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.walletClient = createWalletClient({
|
|
60
|
+
account: this.account,
|
|
61
|
+
chain: this.chain,
|
|
62
|
+
transport: http(rpcUrl),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
console.log(`[LocalKeyBackend] Initialized for chain ${this.chain.name} (${this.chainId})`);
|
|
66
|
+
console.log(`[LocalKeyBackend] Address: ${this.account.address}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the wallet address
|
|
71
|
+
*/
|
|
72
|
+
async getAddress(): Promise<Address> {
|
|
73
|
+
return this.account.address;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Send a transaction
|
|
78
|
+
*
|
|
79
|
+
* Signs locally and submits via RPC.
|
|
80
|
+
*/
|
|
81
|
+
async sendTransaction(tx: TransactionRequest): Promise<Hash> {
|
|
82
|
+
console.log(`[LocalKeyBackend] Sending transaction to ${tx.to}`);
|
|
83
|
+
|
|
84
|
+
// Build transaction params
|
|
85
|
+
const txParams: any = {
|
|
86
|
+
account: this.account,
|
|
87
|
+
chain: this.chain,
|
|
88
|
+
to: tx.to,
|
|
89
|
+
value: tx.value || 0n,
|
|
90
|
+
data: tx.data,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// Add optional gas parameters
|
|
94
|
+
if (tx.gasLimit) txParams.gas = tx.gasLimit;
|
|
95
|
+
if (tx.gasPrice) txParams.gasPrice = tx.gasPrice;
|
|
96
|
+
if (tx.maxFeePerGas) txParams.maxFeePerGas = tx.maxFeePerGas;
|
|
97
|
+
if (tx.maxPriorityFeePerGas) txParams.maxPriorityFeePerGas = tx.maxPriorityFeePerGas;
|
|
98
|
+
if (tx.nonce !== undefined) txParams.nonce = tx.nonce;
|
|
99
|
+
|
|
100
|
+
const hash = await this.walletClient.sendTransaction(txParams);
|
|
101
|
+
|
|
102
|
+
console.log(`[LocalKeyBackend] Transaction sent: ${hash}`);
|
|
103
|
+
return hash;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Wait for transaction confirmation
|
|
108
|
+
*/
|
|
109
|
+
async waitForTransaction(txHash: Hash): Promise<TransactionReceipt> {
|
|
110
|
+
console.log(`[LocalKeyBackend] Waiting for transaction: ${txHash}`);
|
|
111
|
+
|
|
112
|
+
const receipt = await this._publicClient.waitForTransactionReceipt({
|
|
113
|
+
hash: txHash,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
console.log(`[LocalKeyBackend] Transaction confirmed in block ${receipt.blockNumber}`);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
transactionHash: receipt.transactionHash,
|
|
120
|
+
blockNumber: receipt.blockNumber,
|
|
121
|
+
blockHash: receipt.blockHash,
|
|
122
|
+
from: receipt.from,
|
|
123
|
+
to: receipt.to,
|
|
124
|
+
gasUsed: receipt.gasUsed,
|
|
125
|
+
status: receipt.status === 'success' ? 'success' : 'reverted',
|
|
126
|
+
logs: receipt.logs.map((log: any) => ({
|
|
127
|
+
address: log.address,
|
|
128
|
+
topics: [...(log.topics || [])] as `0x${string}`[],
|
|
129
|
+
data: log.data,
|
|
130
|
+
})),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Check if backend is ready
|
|
136
|
+
*
|
|
137
|
+
* For local key backend, we verify RPC connectivity.
|
|
138
|
+
*/
|
|
139
|
+
async isReady(): Promise<boolean> {
|
|
140
|
+
try {
|
|
141
|
+
await this._publicClient.getChainId();
|
|
142
|
+
return true;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error('[LocalKeyBackend] RPC connectivity check failed:', error);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get the chain ID
|
|
151
|
+
*/
|
|
152
|
+
getChainId(): number {
|
|
153
|
+
return this.chainId;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get the public client (for external use)
|
|
158
|
+
*/
|
|
159
|
+
getPublicClient(): ReturnType<typeof createPublicClient> {
|
|
160
|
+
return this._publicClient;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Get the wallet client (for advanced use cases)
|
|
165
|
+
*/
|
|
166
|
+
getWalletClient(): ReturnType<typeof createWalletClient> {
|
|
167
|
+
return this.walletClient;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Create a LocalKeyBackend from configuration
|
|
173
|
+
*/
|
|
174
|
+
export async function createLocalKeyBackend(config: LocalKeyBackendConfig): Promise<LocalKeyBackend> {
|
|
175
|
+
const backend = new LocalKeyBackend(config);
|
|
176
|
+
|
|
177
|
+
// Verify connectivity
|
|
178
|
+
const ready = await backend.isReady();
|
|
179
|
+
if (!ready) {
|
|
180
|
+
console.warn('[LocalKeyBackend] Backend created but RPC connectivity check failed');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return backend;
|
|
184
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain Configuration for Amped Wallet Provider
|
|
3
|
+
*
|
|
4
|
+
* Complete chain configuration for all SODAX-supported EVM chains.
|
|
5
|
+
*
|
|
6
|
+
* Note: We maintain our own chain definitions to avoid viem version
|
|
7
|
+
* mismatches with @sodax/wallet-sdk-core. The SDK's getEvmViemChain()
|
|
8
|
+
* is used as a fallback for future chain additions.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { defineChain, type Chain } from 'viem';
|
|
12
|
+
import {
|
|
13
|
+
mainnet,
|
|
14
|
+
arbitrum,
|
|
15
|
+
optimism,
|
|
16
|
+
base,
|
|
17
|
+
polygon,
|
|
18
|
+
bsc,
|
|
19
|
+
avalanche,
|
|
20
|
+
sonic,
|
|
21
|
+
lightlinkPhoenix,
|
|
22
|
+
} from 'viem/chains';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Chain ID constants matching @sodax/types
|
|
26
|
+
*/
|
|
27
|
+
export const CHAIN_IDS = {
|
|
28
|
+
ETHEREUM: 1,
|
|
29
|
+
ARBITRUM: 42161,
|
|
30
|
+
OPTIMISM: 10,
|
|
31
|
+
BASE: 8453,
|
|
32
|
+
POLYGON: 137,
|
|
33
|
+
BSC: 56,
|
|
34
|
+
AVALANCHE: 43114,
|
|
35
|
+
SONIC: 146,
|
|
36
|
+
LIGHTLINK: 1890,
|
|
37
|
+
HYPEREVM: 999,
|
|
38
|
+
KAIA: 8217,
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* SDK chain ID format mapping (e.g., 'ethereum', '0x2105.base')
|
|
43
|
+
*/
|
|
44
|
+
export const SDK_CHAIN_ID_MAP: Record<string, number> = {
|
|
45
|
+
'ethereum': CHAIN_IDS.ETHEREUM,
|
|
46
|
+
'arbitrum': CHAIN_IDS.ARBITRUM,
|
|
47
|
+
'0xa4b1.arbitrum': CHAIN_IDS.ARBITRUM,
|
|
48
|
+
'optimism': CHAIN_IDS.OPTIMISM,
|
|
49
|
+
'0xa.optimism': CHAIN_IDS.OPTIMISM,
|
|
50
|
+
'base': CHAIN_IDS.BASE,
|
|
51
|
+
'0x2105.base': CHAIN_IDS.BASE,
|
|
52
|
+
'polygon': CHAIN_IDS.POLYGON,
|
|
53
|
+
'0x89.polygon': CHAIN_IDS.POLYGON,
|
|
54
|
+
'bsc': CHAIN_IDS.BSC,
|
|
55
|
+
'0x38.bsc': CHAIN_IDS.BSC,
|
|
56
|
+
'avalanche': CHAIN_IDS.AVALANCHE,
|
|
57
|
+
'avax': CHAIN_IDS.AVALANCHE,
|
|
58
|
+
'0xa86a.avax': CHAIN_IDS.AVALANCHE,
|
|
59
|
+
'sonic': CHAIN_IDS.SONIC,
|
|
60
|
+
'lightlink': CHAIN_IDS.LIGHTLINK,
|
|
61
|
+
'hyperevm': CHAIN_IDS.HYPEREVM,
|
|
62
|
+
'hyper': CHAIN_IDS.HYPEREVM,
|
|
63
|
+
'kaia': CHAIN_IDS.KAIA,
|
|
64
|
+
'0x2019.kaia': CHAIN_IDS.KAIA,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* HyperEVM chain definition
|
|
69
|
+
* Matches @sodax/wallet-sdk-core hyper definition
|
|
70
|
+
*/
|
|
71
|
+
export const hyper = defineChain({
|
|
72
|
+
id: CHAIN_IDS.HYPEREVM,
|
|
73
|
+
name: 'HyperEVM',
|
|
74
|
+
nativeCurrency: { decimals: 18, name: 'HYPE', symbol: 'HYPE' },
|
|
75
|
+
rpcUrls: { default: { http: ['https://rpc.hyperliquid.xyz/evm'] } },
|
|
76
|
+
blockExplorers: { default: { name: 'HyperEVMScan', url: 'https://hyperevmscan.io/' } },
|
|
77
|
+
contracts: { multicall3: { address: '0xcA11bde05977b3631167028862bE2a173976CA11', blockCreated: 13051 } },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Kaia chain definition
|
|
82
|
+
*/
|
|
83
|
+
export const kaia = defineChain({
|
|
84
|
+
id: CHAIN_IDS.KAIA,
|
|
85
|
+
name: 'Kaia',
|
|
86
|
+
nativeCurrency: { decimals: 18, name: 'KAIA', symbol: 'KAIA' },
|
|
87
|
+
rpcUrls: { default: { http: ['https://public-en.node.kaia.io'] } },
|
|
88
|
+
blockExplorers: { default: { name: 'KaiaScan', url: 'https://kaiascan.io/' } },
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Chain configuration by numeric ID
|
|
93
|
+
*/
|
|
94
|
+
const CHAIN_CONFIG: Record<number, Chain> = {
|
|
95
|
+
[CHAIN_IDS.ETHEREUM]: mainnet,
|
|
96
|
+
[CHAIN_IDS.ARBITRUM]: arbitrum,
|
|
97
|
+
[CHAIN_IDS.OPTIMISM]: optimism,
|
|
98
|
+
[CHAIN_IDS.BASE]: base,
|
|
99
|
+
[CHAIN_IDS.POLYGON]: polygon,
|
|
100
|
+
[CHAIN_IDS.BSC]: bsc,
|
|
101
|
+
[CHAIN_IDS.AVALANCHE]: avalanche,
|
|
102
|
+
[CHAIN_IDS.SONIC]: sonic,
|
|
103
|
+
[CHAIN_IDS.LIGHTLINK]: lightlinkPhoenix,
|
|
104
|
+
[CHAIN_IDS.HYPEREVM]: hyper,
|
|
105
|
+
[CHAIN_IDS.KAIA]: kaia,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Default RPC URLs for all supported chains
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* FALLBACK RPC URLs for all supported chains
|
|
113
|
+
* Primary RPCs should come from evm-wallet-skill (chains.js)
|
|
114
|
+
* @see https://github.com/amped-finance/evm-wallet-skill
|
|
115
|
+
*/
|
|
116
|
+
export const DEFAULT_RPC_URLS: Record<number, string> = {
|
|
117
|
+
[CHAIN_IDS.ETHEREUM]: 'https://ethereum.publicnode.com',
|
|
118
|
+
[CHAIN_IDS.ARBITRUM]: 'https://arb1.arbitrum.io/rpc',
|
|
119
|
+
[CHAIN_IDS.OPTIMISM]: 'https://mainnet.optimism.io',
|
|
120
|
+
[CHAIN_IDS.BASE]: 'https://mainnet.base.org',
|
|
121
|
+
[CHAIN_IDS.POLYGON]: 'https://polygon-bor-rpc.publicnode.com',
|
|
122
|
+
[CHAIN_IDS.BSC]: 'https://bsc-dataseed.binance.org',
|
|
123
|
+
[CHAIN_IDS.AVALANCHE]: 'https://api.avax.network/ext/bc/C/rpc',
|
|
124
|
+
[CHAIN_IDS.SONIC]: 'https://rpc.soniclabs.com',
|
|
125
|
+
[CHAIN_IDS.LIGHTLINK]: 'https://replicator.phoenix.lightlink.io/rpc/v1',
|
|
126
|
+
[CHAIN_IDS.HYPEREVM]: 'https://rpc.hyperliquid.xyz/evm',
|
|
127
|
+
[CHAIN_IDS.KAIA]: 'https://public-en.node.kaia.io',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Resolve SDK chain ID format to numeric chain ID
|
|
132
|
+
*/
|
|
133
|
+
export function resolveChainId(sdkChainId: string | number): number {
|
|
134
|
+
if (typeof sdkChainId === 'number') return sdkChainId;
|
|
135
|
+
|
|
136
|
+
const lower = sdkChainId.toLowerCase();
|
|
137
|
+
if (SDK_CHAIN_ID_MAP[lower] !== undefined) return SDK_CHAIN_ID_MAP[lower];
|
|
138
|
+
|
|
139
|
+
if (lower.startsWith('0x')) {
|
|
140
|
+
const parsed = parseInt(lower, 16);
|
|
141
|
+
if (!isNaN(parsed)) return parsed;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const parsed = parseInt(sdkChainId, 10);
|
|
145
|
+
if (!isNaN(parsed)) return parsed;
|
|
146
|
+
|
|
147
|
+
throw new Error(`Unable to resolve chain ID: ${sdkChainId}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get viem Chain configuration for a chain ID
|
|
152
|
+
*/
|
|
153
|
+
export function getViemChain(chainId: string | number): Chain {
|
|
154
|
+
const numericId = resolveChainId(chainId);
|
|
155
|
+
const chain = CHAIN_CONFIG[numericId];
|
|
156
|
+
if (!chain) throw new Error(`Unsupported chain ID: ${chainId} (resolved to ${numericId})`);
|
|
157
|
+
return chain;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get default RPC URL for a chain
|
|
162
|
+
*/
|
|
163
|
+
export function getDefaultRpcUrl(chainId: string | number): string {
|
|
164
|
+
const numericId = resolveChainId(chainId);
|
|
165
|
+
const rpcUrl = DEFAULT_RPC_URLS[numericId];
|
|
166
|
+
if (!rpcUrl) throw new Error(`No default RPC URL for chain ID: ${chainId}`);
|
|
167
|
+
return rpcUrl;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Check if a chain is supported
|
|
172
|
+
*/
|
|
173
|
+
export function isChainSupported(chainId: string | number): boolean {
|
|
174
|
+
try {
|
|
175
|
+
getViemChain(chainId);
|
|
176
|
+
return true;
|
|
177
|
+
} catch {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get all supported chain IDs
|
|
184
|
+
*/
|
|
185
|
+
export function getSupportedChainIds(): number[] {
|
|
186
|
+
return Object.keys(CHAIN_CONFIG).map(Number);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get chain name
|
|
191
|
+
*/
|
|
192
|
+
export function getChainName(chainId: string | number): string {
|
|
193
|
+
return getViemChain(chainId).name;
|
|
194
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Providers
|
|
3
|
+
*
|
|
4
|
+
* Pluggable wallet backend architecture for Amped DeFi plugin.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { AmpedWalletProvider } from './wallet/providers';
|
|
9
|
+
*
|
|
10
|
+
* // Create with local private key (evm-wallet-skill compatible)
|
|
11
|
+
* const provider = await AmpedWalletProvider.fromPrivateKey({
|
|
12
|
+
* privateKey: '0x...',
|
|
13
|
+
* chainId: 'lightlink',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Or create with Bankr backend
|
|
17
|
+
* const bankrProvider = await AmpedWalletProvider.fromBankr({
|
|
18
|
+
* bankrApiUrl: 'https://api.bankr.xyz',
|
|
19
|
+
* bankrApiKey: 'your-api-key',
|
|
20
|
+
* userAddress: '0x...',
|
|
21
|
+
* chainId: 'base',
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// Main provider
|
|
27
|
+
export { AmpedWalletProvider } from './AmpedWalletProvider';
|
|
28
|
+
|
|
29
|
+
// Backends
|
|
30
|
+
export { LocalKeyBackend, createLocalKeyBackend } from './LocalKeyBackend';
|
|
31
|
+
export { BankrBackend, createBankrBackend } from './BankrBackend';
|
|
32
|
+
|
|
33
|
+
// Chain configuration
|
|
34
|
+
export {
|
|
35
|
+
CHAIN_IDS,
|
|
36
|
+
SDK_CHAIN_ID_MAP,
|
|
37
|
+
DEFAULT_RPC_URLS,
|
|
38
|
+
hyper,
|
|
39
|
+
resolveChainId,
|
|
40
|
+
getViemChain,
|
|
41
|
+
getDefaultRpcUrl,
|
|
42
|
+
isChainSupported,
|
|
43
|
+
getSupportedChainIds,
|
|
44
|
+
getChainName,
|
|
45
|
+
} from './chainConfig';
|
|
46
|
+
|
|
47
|
+
// Types
|
|
48
|
+
export type {
|
|
49
|
+
WalletBackendType,
|
|
50
|
+
WalletBackendBaseConfig,
|
|
51
|
+
LocalKeyBackendConfig,
|
|
52
|
+
BankrBackendConfig,
|
|
53
|
+
PrivyBackendConfig,
|
|
54
|
+
SmartWalletBackendConfig,
|
|
55
|
+
WalletBackendConfig,
|
|
56
|
+
TransactionRequest,
|
|
57
|
+
TransactionReceipt,
|
|
58
|
+
IWalletBackend,
|
|
59
|
+
WalletBackendFactory,
|
|
60
|
+
AmpedWalletProviderConfig,
|
|
61
|
+
IAmpedWalletProvider,
|
|
62
|
+
} from './types';
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Provider Types
|
|
3
|
+
*
|
|
4
|
+
* Interfaces for the pluggable wallet backend architecture.
|
|
5
|
+
* Allows the same AmpedWalletProvider to work with:
|
|
6
|
+
* - Local private keys (evm-wallet-skill)
|
|
7
|
+
* - Bankr execution API
|
|
8
|
+
* - Future: Privy, smart contract wallets, etc.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Hash, Address } from 'viem';
|
|
12
|
+
import { createPublicClient } from 'viem';
|
|
13
|
+
import type {
|
|
14
|
+
EvmRawTransaction,
|
|
15
|
+
EvmRawTransactionReceipt,
|
|
16
|
+
IEvmWalletProvider
|
|
17
|
+
} from '@sodax/types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wallet backend type identifiers
|
|
21
|
+
*/
|
|
22
|
+
export type WalletBackendType = 'localKey' | 'bankr' | 'privy' | 'smartWallet';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Base configuration for all backends
|
|
26
|
+
*/
|
|
27
|
+
export interface WalletBackendBaseConfig {
|
|
28
|
+
type: WalletBackendType;
|
|
29
|
+
chainId: string | number;
|
|
30
|
+
rpcUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration for local private key backend
|
|
35
|
+
*/
|
|
36
|
+
export interface LocalKeyBackendConfig extends WalletBackendBaseConfig {
|
|
37
|
+
type: 'localKey';
|
|
38
|
+
privateKey: `0x${string}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for Bankr execution backend
|
|
43
|
+
*/
|
|
44
|
+
export interface BankrBackendConfig extends WalletBackendBaseConfig {
|
|
45
|
+
type: 'bankr';
|
|
46
|
+
bankrApiUrl: string;
|
|
47
|
+
bankrApiKey: string;
|
|
48
|
+
userAddress: Address;
|
|
49
|
+
/** Optional: policy limits for transactions */
|
|
50
|
+
policy?: {
|
|
51
|
+
maxValuePerTx?: bigint;
|
|
52
|
+
maxDailyVolume?: bigint;
|
|
53
|
+
allowedContracts?: Address[];
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Configuration for Privy server wallet backend (future)
|
|
59
|
+
*/
|
|
60
|
+
export interface PrivyBackendConfig extends WalletBackendBaseConfig {
|
|
61
|
+
type: 'privy';
|
|
62
|
+
appId: string;
|
|
63
|
+
appSecret: string;
|
|
64
|
+
walletId: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for smart contract wallet backend (future)
|
|
69
|
+
*/
|
|
70
|
+
export interface SmartWalletBackendConfig extends WalletBackendBaseConfig {
|
|
71
|
+
type: 'smartWallet';
|
|
72
|
+
walletAddress: Address;
|
|
73
|
+
sessionKey: `0x${string}`;
|
|
74
|
+
entryPointAddress: Address;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Union of all backend configurations
|
|
79
|
+
*/
|
|
80
|
+
export type WalletBackendConfig =
|
|
81
|
+
| LocalKeyBackendConfig
|
|
82
|
+
| BankrBackendConfig
|
|
83
|
+
| PrivyBackendConfig
|
|
84
|
+
| SmartWalletBackendConfig;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Transaction request (simplified)
|
|
88
|
+
*/
|
|
89
|
+
export interface TransactionRequest {
|
|
90
|
+
to: Address;
|
|
91
|
+
value?: bigint;
|
|
92
|
+
data?: `0x${string}`;
|
|
93
|
+
gasLimit?: bigint;
|
|
94
|
+
gasPrice?: bigint;
|
|
95
|
+
maxFeePerGas?: bigint;
|
|
96
|
+
maxPriorityFeePerGas?: bigint;
|
|
97
|
+
nonce?: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Transaction receipt (simplified)
|
|
102
|
+
*/
|
|
103
|
+
export interface TransactionReceipt {
|
|
104
|
+
transactionHash: Hash;
|
|
105
|
+
blockNumber: bigint;
|
|
106
|
+
blockHash: Hash;
|
|
107
|
+
from: Address;
|
|
108
|
+
to: Address | null;
|
|
109
|
+
gasUsed: bigint;
|
|
110
|
+
status: 'success' | 'reverted';
|
|
111
|
+
logs: Array<{
|
|
112
|
+
address: Address;
|
|
113
|
+
topics: `0x${string}`[];
|
|
114
|
+
data: `0x${string}`;
|
|
115
|
+
}>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Wallet backend interface
|
|
120
|
+
*
|
|
121
|
+
* All wallet backends must implement this interface.
|
|
122
|
+
* This allows AmpedWalletProvider to delegate to different backends
|
|
123
|
+
* without changing its own implementation.
|
|
124
|
+
*/
|
|
125
|
+
export interface IWalletBackend {
|
|
126
|
+
/** Backend type identifier */
|
|
127
|
+
readonly type: WalletBackendType;
|
|
128
|
+
|
|
129
|
+
/** Get the wallet address */
|
|
130
|
+
getAddress(): Promise<Address>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Send a transaction and return the transaction hash
|
|
134
|
+
* The backend is responsible for signing and submitting the transaction.
|
|
135
|
+
*/
|
|
136
|
+
sendTransaction(tx: TransactionRequest): Promise<Hash>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Wait for a transaction to be confirmed
|
|
140
|
+
* Returns when the transaction is included in a block.
|
|
141
|
+
*/
|
|
142
|
+
waitForTransaction(txHash: Hash): Promise<TransactionReceipt>;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Check if the backend can execute transactions
|
|
146
|
+
* (e.g., Bankr backend may need API connectivity)
|
|
147
|
+
*/
|
|
148
|
+
isReady(): Promise<boolean>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get the numeric chain ID this backend is configured for
|
|
152
|
+
*/
|
|
153
|
+
getChainId(): number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Factory function type for creating backends
|
|
158
|
+
*/
|
|
159
|
+
export type WalletBackendFactory = (config: WalletBackendConfig) => Promise<IWalletBackend>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Amped Wallet Provider configuration
|
|
163
|
+
*/
|
|
164
|
+
export interface AmpedWalletProviderConfig {
|
|
165
|
+
/** Backend configuration */
|
|
166
|
+
backend: WalletBackendConfig;
|
|
167
|
+
/** Optional custom RPC URL (overrides chain default) */
|
|
168
|
+
rpcUrl?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Extended IEvmWalletProvider with Amped-specific methods
|
|
173
|
+
*/
|
|
174
|
+
export interface IAmpedWalletProvider extends IEvmWalletProvider {
|
|
175
|
+
/** Get the underlying backend */
|
|
176
|
+
getBackend(): IWalletBackend;
|
|
177
|
+
|
|
178
|
+
/** Get the backend type */
|
|
179
|
+
getBackendType(): WalletBackendType;
|
|
180
|
+
|
|
181
|
+
/** Check if ready for transactions */
|
|
182
|
+
isReady(): Promise<boolean>;
|
|
183
|
+
|
|
184
|
+
/** Get chain ID */
|
|
185
|
+
getChainId(): number;
|
|
186
|
+
}
|