@heyanon/sdk 2.3.2 → 2.3.4
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/adapter/misc.d.ts +35 -0
- package/dist/adapter/transformers/toResult.d.ts +24 -0
- package/dist/adapter/types.d.ts +123 -7
- package/dist/blockchain/constants/chains.d.ts +93 -0
- package/dist/blockchain/constants/types.d.ts +33 -0
- package/dist/blockchain/evm/constants/chains.d.ts +56 -0
- package/dist/blockchain/evm/constants/misc.d.ts +69 -0
- package/dist/blockchain/evm/constants/weth9.d.ts +76 -1
- package/dist/blockchain/evm/types.d.ts +273 -0
- package/dist/blockchain/evm/utils/checkToApprove.d.ts +86 -0
- package/dist/blockchain/evm/utils/getChainFromName.d.ts +81 -0
- package/dist/blockchain/evm/utils/getChainName.d.ts +114 -0
- package/dist/blockchain/evm/utils/getUnwrapData.d.ts +114 -0
- package/dist/blockchain/evm/utils/getWrapAddress.d.ts +147 -0
- package/dist/blockchain/evm/utils/getWrapData.d.ts +189 -0
- package/dist/blockchain/evm/utils/getWrappedNative.d.ts +198 -0
- package/dist/blockchain/evm/utils/isEvmChain.d.ts +183 -0
- package/dist/blockchain/evm/utils/isNativeAddress.d.ts +221 -0
- package/dist/blockchain/evm/utils/isNativeAddress.test.d.ts +1 -0
- package/dist/blockchain/solana/types.d.ts +291 -0
- package/dist/blockchain/solana/utils/buildV0Transaction.d.ts +184 -0
- package/dist/blockchain/solana/utils/toPublicKey.d.ts +194 -0
- package/dist/blockchain/ton/types.d.ts +410 -0
- package/dist/index.js +83 -26
- package/dist/index.mjs +84 -28
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/is-address.d.ts +7 -0
- package/dist/utils/is-address.spec.d.ts +1 -0
- package/dist/utils/retry.d.ts +218 -0
- package/dist/utils/sleep.d.ts +239 -0
- package/dist/utils/stringify.d.ts +235 -0
- package/dist/utils/stringify.spec.d.ts +1 -0
- package/package.json +2 -1
package/dist/adapter/misc.d.ts
CHANGED
|
@@ -1,14 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags for categorizing different types of adapters in the ecosystem
|
|
3
|
+
* @enum AdapterTag
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Using in adapter configuration
|
|
7
|
+
* const swapAdapter: AdapterExport = {
|
|
8
|
+
* tags: [AdapterTag.DEX, AdapterTag.LP],
|
|
9
|
+
* // ... other properties
|
|
10
|
+
* };
|
|
11
|
+
*
|
|
12
|
+
* // Filtering adapters by tag
|
|
13
|
+
* const dexAdapters = adapters.filter(adapter =>
|
|
14
|
+
* adapter.tags.includes(AdapterTag.DEX)
|
|
15
|
+
* );
|
|
16
|
+
*
|
|
17
|
+
* // Multiple tags for complex protocols
|
|
18
|
+
* const compoundAdapter = {
|
|
19
|
+
* tags: [AdapterTag.LENDING, AdapterTag.FARM],
|
|
20
|
+
* // ... other properties
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
1
24
|
export declare enum AdapterTag {
|
|
25
|
+
/** Automated Liquidity Management protocols */
|
|
2
26
|
ALM = "ALM",
|
|
27
|
+
/** Staking protocols and validators */
|
|
3
28
|
STAKE = "Stake",
|
|
29
|
+
/** Lending and borrowing protocols */
|
|
4
30
|
LENDING = "Lending",
|
|
31
|
+
/** Yield farming and liquidity mining */
|
|
5
32
|
FARM = "Farm",
|
|
33
|
+
/** Perpetual trading and derivatives */
|
|
6
34
|
PERPETUALS = "Perpetuals",
|
|
35
|
+
/** Cross-chain bridges */
|
|
7
36
|
BRIDGE = "Bridge",
|
|
37
|
+
/** Limit order protocols */
|
|
8
38
|
LIMIT_ORDER = "Limit orders",
|
|
39
|
+
/** Decentralized exchanges */
|
|
9
40
|
DEX = "DEX",
|
|
41
|
+
/** Liquidity provision protocols */
|
|
10
42
|
LP = "LP",
|
|
43
|
+
/** Gaming and GameFi protocols */
|
|
11
44
|
GAMES = "Games",
|
|
45
|
+
/** Centralized exchange integrations */
|
|
12
46
|
CEX = "CEX",
|
|
47
|
+
/** Token launchpads and IDO platforms */
|
|
13
48
|
LAUNCHPAD = "Launchpad"
|
|
14
49
|
}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
import { FunctionReturn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms data into a standardized FunctionReturn format
|
|
4
|
+
* @param data - The data to transform (string, object, or array)
|
|
5
|
+
* @param error - Whether this represents an error state (default: false)
|
|
6
|
+
* @returns Standardized function result with success status and formatted data
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Success case with string data
|
|
10
|
+
* const result = toResult("Transaction completed");
|
|
11
|
+
* // { success: true, data: "Transaction completed" }
|
|
12
|
+
*
|
|
13
|
+
* // Success case with object data
|
|
14
|
+
* const result = toResult({ hash: "0x123", amount: "100" });
|
|
15
|
+
* // { success: true, data: '{"hash":"0x123","amount":"100"}' }
|
|
16
|
+
*
|
|
17
|
+
* // Error case
|
|
18
|
+
* const result = toResult("Network timeout", true);
|
|
19
|
+
* // { success: false, data: "ERROR: Network timeout" }
|
|
20
|
+
*
|
|
21
|
+
* // Error case with object
|
|
22
|
+
* const result = toResult({ code: 404, message: "Not found" }, true);
|
|
23
|
+
* // { success: false, data: 'ERROR: {"code":404,"message":"Not found"}' }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
2
26
|
export declare function toResult(data: string | Object | Array<any>, error?: boolean): FunctionReturn;
|
package/dist/adapter/types.d.ts
CHANGED
|
@@ -6,59 +6,175 @@ import { AdapterTag } from './misc';
|
|
|
6
6
|
import { Address as TonAddress } from '@ton/ton';
|
|
7
7
|
import { DeployContractProps } from '../blockchain/evm/types';
|
|
8
8
|
import { Exchange, exchanges } from 'ccxt';
|
|
9
|
+
/**
|
|
10
|
+
* Result of adapter function execution
|
|
11
|
+
* @interface FunctionReturn
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const result: FunctionReturn = {
|
|
15
|
+
* success: true,
|
|
16
|
+
* data: "Transaction hash: 0x123..."
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
9
20
|
export interface FunctionReturn {
|
|
21
|
+
/** Success status of the operation */
|
|
10
22
|
readonly success: boolean;
|
|
23
|
+
/** Result data as string */
|
|
11
24
|
readonly data: string;
|
|
12
25
|
}
|
|
13
26
|
type SignTypedDataParameters = Omit<ViemSignTypedDataParameters, 'account'>;
|
|
27
|
+
/**
|
|
28
|
+
* Options for working with EVM blockchains
|
|
29
|
+
* @interface EvmFunctionOptions
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const evmOptions: EvmFunctionOptions = {
|
|
33
|
+
* getAddress: async () => "0x742d35Cc6634C0532925a3b8D4C2CA1c1DfF0bE8",
|
|
34
|
+
* getProvider: (chainId) => new PublicClient({ chain: { id: chainId } }),
|
|
35
|
+
* sendTransactions: async (props) => ({ success: true, hash: "0x..." }),
|
|
36
|
+
* deployContracts: async (props) => ["0x123..."]
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
14
40
|
export interface EvmFunctionOptions {
|
|
41
|
+
/** Get wallet address */
|
|
15
42
|
readonly getAddress: () => Promise<Address>;
|
|
43
|
+
/** Get provider for specified chain */
|
|
16
44
|
readonly getProvider: (chainId: number) => PublicClient;
|
|
45
|
+
/** Send transactions */
|
|
17
46
|
readonly sendTransactions: (props: EVM.types.SendTransactionProps) => Promise<EVM.types.TransactionReturn>;
|
|
47
|
+
/** Deploy smart contracts */
|
|
18
48
|
readonly deployContracts: (props: DeployContractProps) => Promise<Address[]>;
|
|
49
|
+
/** Sign messages (optional) */
|
|
19
50
|
readonly signMessages?: (messages: Hex[]) => Promise<SignMessageReturnType[]>;
|
|
51
|
+
/** Sign typed data (optional) */
|
|
20
52
|
readonly signTypedDatas?: (args: SignTypedDataParameters[]) => Promise<SignTypedDataReturnType[]>;
|
|
21
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Options for working with Solana blockchain
|
|
56
|
+
* @interface SolanaFunctionOptions
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const solanaOptions: SolanaFunctionOptions = {
|
|
60
|
+
* getConnection: () => new Connection("https://api.mainnet-beta.solana.com"),
|
|
61
|
+
* getPublicKey: async () => new PublicKey("11111111111111111111111111111112"),
|
|
62
|
+
* sendTransactions: async (props) => ({ success: true, signature: "5VT..." })
|
|
63
|
+
* };
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
22
66
|
export interface SolanaFunctionOptions {
|
|
67
|
+
/** Get Solana connection */
|
|
23
68
|
readonly getConnection: () => Connection;
|
|
69
|
+
/** Get wallet public key */
|
|
24
70
|
readonly getPublicKey: () => Promise<PublicKey>;
|
|
71
|
+
/** Send transactions */
|
|
25
72
|
readonly sendTransactions: (props: Solana.types.SendTransactionProps) => Promise<Solana.types.TransactionReturn>;
|
|
73
|
+
/** Sign transactions (optional) */
|
|
26
74
|
readonly signTransactions?: (transactions: Solana.types.SignTransactionProps[]) => Promise<(SolanaTransaction | SolanaVersionedTransaction)[]>;
|
|
27
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Options for working with TON blockchain
|
|
78
|
+
* @interface TonFunctionOptions
|
|
79
|
+
*/
|
|
28
80
|
export interface TonFunctionOptions {
|
|
81
|
+
/** Get wallet address */
|
|
29
82
|
readonly getAddress: () => Promise<TonAddress>;
|
|
83
|
+
/** Get TON client */
|
|
30
84
|
readonly getClient: () => Promise<TON.types.Client>;
|
|
85
|
+
/** Send transactions */
|
|
31
86
|
readonly sendTransactions: (props: TON.types.SendTransactionProps) => Promise<TON.types.TransactionReturn>;
|
|
32
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* User token information
|
|
90
|
+
* @interface UserToken
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const usdcToken: UserToken = {
|
|
94
|
+
* chain: Chain.Ethereum,
|
|
95
|
+
* name: "USD Coin",
|
|
96
|
+
* symbol: "USDC",
|
|
97
|
+
* address: "0xA0b86a33E6417e4681831442Ff7Bd6c25b5d9C7a",
|
|
98
|
+
* decimals: 6
|
|
99
|
+
* };
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
33
102
|
export interface UserToken {
|
|
103
|
+
/** Blockchain network of the token */
|
|
34
104
|
readonly chain: Chain;
|
|
105
|
+
/** Token name */
|
|
35
106
|
readonly name: string;
|
|
107
|
+
/** Token symbol */
|
|
36
108
|
readonly symbol: string;
|
|
109
|
+
/** Token contract address */
|
|
37
110
|
readonly address: string;
|
|
111
|
+
/** Number of decimal places */
|
|
38
112
|
readonly decimals: number;
|
|
39
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Complete set of function options for all supported blockchains and utilities
|
|
116
|
+
* @interface FunctionOptions
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const options: FunctionOptions = {
|
|
120
|
+
* evm: evmOptions,
|
|
121
|
+
* solana: solanaOptions,
|
|
122
|
+
* ton: tonOptions,
|
|
123
|
+
* notify: async (message, type) => console.log(`${type}: ${message}`),
|
|
124
|
+
* getRecipient: async (type) => "recipient_address",
|
|
125
|
+
* getUserTokens: async () => [usdcToken],
|
|
126
|
+
* getCcxtExchange: async (name) => new exchanges[name](),
|
|
127
|
+
* addUserToken: async (token) => token
|
|
128
|
+
* };
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
40
131
|
export interface FunctionOptions {
|
|
132
|
+
/** EVM blockchain options */
|
|
41
133
|
readonly evm: EvmFunctionOptions;
|
|
134
|
+
/** Solana blockchain options */
|
|
42
135
|
readonly solana: SolanaFunctionOptions;
|
|
136
|
+
/** TON blockchain options */
|
|
43
137
|
readonly ton: TonFunctionOptions;
|
|
138
|
+
/** Send notification to user */
|
|
44
139
|
readonly notify: (message: string, type?: 'alert' | 'regular') => Promise<void>;
|
|
140
|
+
/** Get recipient address for specific wallet type */
|
|
45
141
|
readonly getRecipient: (type: WalletType) => Promise<string>;
|
|
142
|
+
/** Get user's token list */
|
|
46
143
|
readonly getUserTokens: () => Promise<UserToken[]>;
|
|
144
|
+
/** Get CCXT exchange instance */
|
|
47
145
|
readonly getCcxtExchange: (name: keyof typeof exchanges) => Promise<Exchange>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
solanaAddresses: string[];
|
|
51
|
-
tonAddresses: string[];
|
|
52
|
-
}) => Promise<{
|
|
53
|
-
[key: string]: string;
|
|
54
|
-
}>;
|
|
146
|
+
/** Add token to user's token list */
|
|
147
|
+
readonly addUserToken: (token: UserToken) => Promise<UserToken>;
|
|
55
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Adapter export with configuration and functions
|
|
151
|
+
* @interface AdapterExport
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const myAdapter: AdapterExport = {
|
|
155
|
+
* chains: [Chain.Ethereum, Chain.Polygon],
|
|
156
|
+
* tags: [AdapterTag.DeFi, AdapterTag.DEX],
|
|
157
|
+
* description: "Swap tokens on decentralized exchanges",
|
|
158
|
+
* functions: {
|
|
159
|
+
* swap: async (args, options) => ({ success: true, data: "Swap completed" })
|
|
160
|
+
* },
|
|
161
|
+
* executableFunctions: ["swap"],
|
|
162
|
+
* tools: [{ type: "function", function: { name: "swap", description: "..." } }]
|
|
163
|
+
* };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
56
166
|
export interface AdapterExport {
|
|
167
|
+
/** Supported blockchain networks */
|
|
57
168
|
readonly chains: Chain[];
|
|
169
|
+
/** Adapter tags for categorization */
|
|
58
170
|
readonly tags: AdapterTag[];
|
|
171
|
+
/** Adapter description */
|
|
59
172
|
readonly description: string;
|
|
173
|
+
/** Available adapter functions */
|
|
60
174
|
readonly functions: Record<string, (args: any, options: FunctionOptions) => Promise<FunctionReturn>>;
|
|
175
|
+
/** List of executable functions */
|
|
61
176
|
readonly executableFunctions: string[];
|
|
177
|
+
/** Tools for OpenAI integration */
|
|
62
178
|
readonly tools: OpenAI.Chat.Completions.ChatCompletionTool[];
|
|
63
179
|
}
|
|
64
180
|
export {};
|
|
@@ -1,22 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported blockchain networks in the SDK
|
|
3
|
+
* @enum Chain
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Using chain in token configuration
|
|
7
|
+
* const token: UserToken = {
|
|
8
|
+
* chain: Chain.ETHEREUM,
|
|
9
|
+
* name: "USD Coin",
|
|
10
|
+
* symbol: "USDC",
|
|
11
|
+
* address: "0xA0b86a33E6417e4681831442Ff7Bd6c25b5d9C7a",
|
|
12
|
+
* decimals: 6
|
|
13
|
+
* };
|
|
14
|
+
*
|
|
15
|
+
* // Checking if chain is EVM compatible
|
|
16
|
+
* const isEvm = chain !== Chain.SOLANA && chain !== Chain.TON;
|
|
17
|
+
*
|
|
18
|
+
* // Using in adapter configuration
|
|
19
|
+
* const adapter: AdapterExport = {
|
|
20
|
+
* chains: [Chain.ETHEREUM, Chain.POLYGON, Chain.BSC],
|
|
21
|
+
* // ... other properties
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
1
25
|
export declare enum Chain {
|
|
26
|
+
/** Ethereum mainnet */
|
|
2
27
|
ETHEREUM = "ethereum",
|
|
28
|
+
/** Optimism Layer 2 */
|
|
3
29
|
OPTIMISM = "optimism",
|
|
30
|
+
/** Binance Smart Chain */
|
|
4
31
|
BSC = "bsc",
|
|
32
|
+
/** Gnosis Chain (formerly xDai) */
|
|
5
33
|
GNOSIS = "gnosis",
|
|
34
|
+
/** Polygon (Matic) */
|
|
6
35
|
POLYGON = "polygon",
|
|
36
|
+
/** Sonic blockchain */
|
|
7
37
|
SONIC = "sonic",
|
|
38
|
+
/** zkSync Era */
|
|
8
39
|
ZKSYNC = "zksync",
|
|
40
|
+
/** Metis Andromeda */
|
|
9
41
|
METIS = "metis",
|
|
42
|
+
/** Kava EVM */
|
|
10
43
|
KAVA_EVM = "kava_evm",
|
|
44
|
+
/** Base Layer 2 */
|
|
11
45
|
BASE = "base",
|
|
46
|
+
/** Avalanche C-Chain */
|
|
12
47
|
AVALANCHE = "avalanche",
|
|
48
|
+
/** Arbitrum One */
|
|
13
49
|
ARBITRUM = "arbitrum",
|
|
50
|
+
/** Scroll Layer 2 */
|
|
14
51
|
SCROLL = "scroll",
|
|
52
|
+
/** Solana blockchain */
|
|
15
53
|
SOLANA = "solana",
|
|
54
|
+
/** The Open Network (TON) */
|
|
16
55
|
TON = "ton",
|
|
56
|
+
/** HyperEVM blockchain */
|
|
17
57
|
HYPEREVM = "hyperevm",
|
|
58
|
+
/** Plasma blockchain */
|
|
18
59
|
PLASMA = "plasma"
|
|
19
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Type representing EVM-compatible chains (excludes Solana and TON)
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* function processEvmChain(chain: EvmChain) {
|
|
66
|
+
* // This function only accepts EVM chains
|
|
67
|
+
* console.log(`Processing EVM chain: ${chain}`);
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* processEvmChain(Chain.ETHEREUM); // ✅ Valid
|
|
71
|
+
* processEvmChain(Chain.POLYGON); // ✅ Valid
|
|
72
|
+
* processEvmChain(Chain.SOLANA); // ❌ TypeScript error
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
20
75
|
export type EvmChain = Exclude<Chain, Chain.SOLANA | Chain.TON>;
|
|
76
|
+
/**
|
|
77
|
+
* Array containing all supported blockchain chains
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Get all available chains
|
|
81
|
+
* console.log(`Supported chains: ${allChains.length}`);
|
|
82
|
+
*
|
|
83
|
+
* // Check if a chain is supported
|
|
84
|
+
* const isSupported = allChains.includes(Chain.ETHEREUM);
|
|
85
|
+
*
|
|
86
|
+
* // Iterate through all chains
|
|
87
|
+
* allChains.forEach(chain => {
|
|
88
|
+
* console.log(`Chain: ${chain}`);
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
21
92
|
export declare const allChains: Chain[];
|
|
93
|
+
/**
|
|
94
|
+
* Array containing only EVM-compatible chains (excludes Solana and TON)
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Get all EVM chains
|
|
98
|
+
* console.log(`EVM chains: ${allEvmChains.length}`);
|
|
99
|
+
*
|
|
100
|
+
* // Filter tokens by EVM chains
|
|
101
|
+
* const evmTokens = tokens.filter(token =>
|
|
102
|
+
* allEvmChains.includes(token.chain as EvmChain)
|
|
103
|
+
* );
|
|
104
|
+
*
|
|
105
|
+
* // Create EVM-specific configuration
|
|
106
|
+
* const evmConfig = {
|
|
107
|
+
* supportedChains: allEvmChains,
|
|
108
|
+
* rpcEndpoints: allEvmChains.map(chain => ({
|
|
109
|
+
* chain,
|
|
110
|
+
* url: getRpcUrl(chain)
|
|
111
|
+
* }))
|
|
112
|
+
* };
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
22
115
|
export declare const allEvmChains: (Chain.ETHEREUM | Chain.OPTIMISM | Chain.BSC | Chain.GNOSIS | Chain.POLYGON | Chain.SONIC | Chain.ZKSYNC | Chain.METIS | Chain.KAVA_EVM | Chain.BASE | Chain.AVALANCHE | Chain.ARBITRUM | Chain.SCROLL | Chain.HYPEREVM | Chain.PLASMA)[];
|
|
@@ -1,5 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of supported wallet architectures
|
|
3
|
+
* @enum WalletType
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Getting recipient address for specific wallet type
|
|
7
|
+
* const evmRecipient = await options.getRecipient(WalletType.EVM);
|
|
8
|
+
* // Returns: "0x742d35Cc6634C0532925a3b8D4C2CA1c1DfF0bE8"
|
|
9
|
+
*
|
|
10
|
+
* const solanaRecipient = await options.getRecipient(WalletType.SOLANA);
|
|
11
|
+
* // Returns: "11111111111111111111111111111112"
|
|
12
|
+
*
|
|
13
|
+
* const tonRecipient = await options.getRecipient(WalletType.TON);
|
|
14
|
+
* // Returns: "EQD4FPq-PRDieyQKkizFTRtSDyucUIqrj0v_zXJmqaDp6_0t"
|
|
15
|
+
*
|
|
16
|
+
* // Mapping chain to wallet type
|
|
17
|
+
* function getWalletType(chain: Chain): WalletType {
|
|
18
|
+
* if (chain === Chain.SOLANA) return WalletType.SOLANA;
|
|
19
|
+
* if (chain === Chain.TON) return WalletType.TON;
|
|
20
|
+
* return WalletType.EVM; // All other chains are EVM-compatible
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Using in adapter functions
|
|
24
|
+
* async function sendToUser(amount: string, chain: Chain) {
|
|
25
|
+
* const walletType = getWalletType(chain);
|
|
26
|
+
* const recipient = await options.getRecipient(walletType);
|
|
27
|
+
* // ... send logic
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
1
31
|
export declare enum WalletType {
|
|
32
|
+
/** Ethereum Virtual Machine compatible wallets (MetaMask, WalletConnect, etc.) */
|
|
2
33
|
EVM = "evm",
|
|
34
|
+
/** Solana wallets (Phantom, Solflare, etc.) */
|
|
3
35
|
SOLANA = "solana",
|
|
36
|
+
/** The Open Network wallets (Tonkeeper, TON Wallet, etc.) */
|
|
4
37
|
TON = "ton"
|
|
5
38
|
}
|
|
@@ -1,17 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping of EVM chain names to their corresponding chain IDs
|
|
3
|
+
* @constant ChainIds
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Get chain ID for specific network
|
|
7
|
+
* const ethereumId = ChainIds[Chain.ETHEREUM]; // 1
|
|
8
|
+
* const polygonId = ChainIds[Chain.POLYGON]; // 137
|
|
9
|
+
* const baseId = ChainIds[Chain.BASE]; // 8453
|
|
10
|
+
*
|
|
11
|
+
* // Use in RPC provider configuration
|
|
12
|
+
* const provider = new PublicClient({
|
|
13
|
+
* chain: {
|
|
14
|
+
* id: ChainIds[Chain.ETHEREUM],
|
|
15
|
+
* name: 'Ethereum',
|
|
16
|
+
* network: 'ethereum'
|
|
17
|
+
* }
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Validate chain ID from wallet
|
|
21
|
+
* function isValidChain(chainId: number): boolean {
|
|
22
|
+
* return Object.values(ChainIds).includes(chainId);
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Get chain name from ID
|
|
26
|
+
* function getChainFromId(chainId: number): EvmChain | undefined {
|
|
27
|
+
* return Object.entries(ChainIds).find(
|
|
28
|
+
* ([_, id]) => id === chainId
|
|
29
|
+
* )?.[0] as EvmChain;
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Switch wallet to specific chain
|
|
33
|
+
* async function switchToChain(chain: EvmChain) {
|
|
34
|
+
* const chainId = ChainIds[chain];
|
|
35
|
+
* await window.ethereum.request({
|
|
36
|
+
* method: 'wallet_switchEthereumChain',
|
|
37
|
+
* params: [{ chainId: `0x${chainId.toString(16)}` }]
|
|
38
|
+
* });
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
1
42
|
export declare const ChainIds: {
|
|
43
|
+
/** Ethereum Mainnet - Chain ID: 1 */
|
|
2
44
|
ethereum: number;
|
|
45
|
+
/** Optimism - Chain ID: 10 */
|
|
3
46
|
optimism: number;
|
|
47
|
+
/** Binance Smart Chain - Chain ID: 56 */
|
|
4
48
|
bsc: number;
|
|
49
|
+
/** Gnosis Chain - Chain ID: 100 */
|
|
5
50
|
gnosis: number;
|
|
51
|
+
/** Polygon - Chain ID: 137 */
|
|
6
52
|
polygon: number;
|
|
53
|
+
/** Sonic - Chain ID: 146 */
|
|
7
54
|
sonic: number;
|
|
55
|
+
/** zkSync Era - Chain ID: 324 */
|
|
8
56
|
zksync: number;
|
|
57
|
+
/** Metis Andromeda - Chain ID: 1088 */
|
|
9
58
|
metis: number;
|
|
59
|
+
/** Kava EVM - Chain ID: 2222 */
|
|
10
60
|
kava_evm: number;
|
|
61
|
+
/** Base - Chain ID: 8453 */
|
|
11
62
|
base: number;
|
|
63
|
+
/** Avalanche C-Chain - Chain ID: 43114 */
|
|
12
64
|
avalanche: number;
|
|
65
|
+
/** Arbitrum One - Chain ID: 42161 */
|
|
13
66
|
arbitrum: number;
|
|
67
|
+
/** Scroll - Chain ID: 534352 */
|
|
14
68
|
scroll: number;
|
|
69
|
+
/** HyperEVM - Chain ID: 999 */
|
|
15
70
|
hyperevm: number;
|
|
71
|
+
/** Plasma - Chain ID: 9745 */
|
|
16
72
|
plasma: number;
|
|
17
73
|
};
|
|
@@ -1,2 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Special address representing native tokens (ETH, BNB, MATIC, etc.) in EVM chains
|
|
3
|
+
* @constant NATIVE_ADDRESS
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Check if token is native currency
|
|
7
|
+
* function isNativeToken(tokenAddress: string): boolean {
|
|
8
|
+
* return tokenAddress.toLowerCase() === NATIVE_ADDRESS.toLowerCase();
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* // Use in token swap configuration
|
|
12
|
+
* const swapConfig = {
|
|
13
|
+
* fromToken: NATIVE_ADDRESS, // ETH on Ethereum
|
|
14
|
+
* toToken: '0xA0b86a33E6417e4681831442Ff7Bd6c25b5d9C7a', // USDC
|
|
15
|
+
* amount: '1000000000000000000' // 1 ETH
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* // Handle native vs ERC20 transfers differently
|
|
19
|
+
* async function transferToken(to: string, amount: string, tokenAddress: string) {
|
|
20
|
+
* if (tokenAddress === NATIVE_ADDRESS) {
|
|
21
|
+
* // Send native ETH
|
|
22
|
+
* return await sendTransaction({ to, value: amount });
|
|
23
|
+
* } else {
|
|
24
|
+
* // Send ERC20 token
|
|
25
|
+
* return await sendERC20Transfer(tokenAddress, to, amount);
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // Filter native tokens from token list
|
|
30
|
+
* const erc20Tokens = tokens.filter(token =>
|
|
31
|
+
* token.address !== NATIVE_ADDRESS
|
|
32
|
+
* );
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
1
35
|
export declare const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
36
|
+
/**
|
|
37
|
+
* Dead address used for burning tokens or as a null destination
|
|
38
|
+
* @constant DEAD_ADDRESS
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Burn tokens by sending to dead address
|
|
42
|
+
* async function burnTokens(tokenAddress: string, amount: string) {
|
|
43
|
+
* return await sendERC20Transfer(tokenAddress, DEAD_ADDRESS, amount);
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* // Check if address is a burn address
|
|
47
|
+
* function isBurnAddress(address: string): boolean {
|
|
48
|
+
* return address.toLowerCase() === DEAD_ADDRESS.toLowerCase() ||
|
|
49
|
+
* address === '0x0000000000000000000000000000000000000000';
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // Calculate circulating supply excluding burned tokens
|
|
53
|
+
* async function getCirculatingSupply(tokenAddress: string) {
|
|
54
|
+
* const totalSupply = await getTotalSupply(tokenAddress);
|
|
55
|
+
* const burnedBalance = await getTokenBalance(tokenAddress, DEAD_ADDRESS);
|
|
56
|
+
* return totalSupply - burnedBalance;
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* // Use in deflationary token mechanics
|
|
60
|
+
* const burnTransaction = {
|
|
61
|
+
* to: DEAD_ADDRESS,
|
|
62
|
+
* value: '0',
|
|
63
|
+
* data: encodeFunctionData({
|
|
64
|
+
* abi: erc20Abi,
|
|
65
|
+
* functionName: 'transfer',
|
|
66
|
+
* args: [DEAD_ADDRESS, burnAmount]
|
|
67
|
+
* })
|
|
68
|
+
* };
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
2
71
|
export declare const DEAD_ADDRESS = "0x000000000000000000000000000000000000dEaD";
|
|
@@ -1,21 +1,96 @@
|
|
|
1
1
|
import { Token } from '@real-wagmi/sdk';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Mapping of EVM chains to their respective wrapped native token contracts (WETH9-like implementations)
|
|
4
|
+
* @constant WETH9
|
|
5
|
+
* @description Each chain has its own wrapped version of the native currency that follows the WETH9 standard
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Get wrapped native token for specific chain
|
|
9
|
+
* const wethOnEthereum = WETH9[Chain.ETHEREUM]; // WETH
|
|
10
|
+
* const wbnbOnBsc = WETH9[Chain.BSC]; // WBNB
|
|
11
|
+
* const wmaticOnPolygon = WETH9[Chain.POLYGON]; // WPOL
|
|
12
|
+
*
|
|
13
|
+
* // Wrap native currency to ERC20
|
|
14
|
+
* async function wrapNativeToken(chain: EvmChain, amount: string) {
|
|
15
|
+
* const wrappedToken = WETH9[chain];
|
|
16
|
+
* const wrapData = await getWrapData(chain, amount);
|
|
17
|
+
*
|
|
18
|
+
* return await options.evm.sendTransactions({
|
|
19
|
+
* transactions: [{
|
|
20
|
+
* to: wrappedToken.address,
|
|
21
|
+
* value: amount,
|
|
22
|
+
* data: wrapData
|
|
23
|
+
* }]
|
|
24
|
+
* });
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Unwrap ERC20 back to native currency
|
|
28
|
+
* async function unwrapToken(chain: EvmChain, amount: string) {
|
|
29
|
+
* const wrappedToken = WETH9[chain];
|
|
30
|
+
* const unwrapData = await getUnwrapData(chain, amount);
|
|
31
|
+
*
|
|
32
|
+
* return await options.evm.sendTransactions({
|
|
33
|
+
* transactions: [{
|
|
34
|
+
* to: wrappedToken.address,
|
|
35
|
+
* value: '0',
|
|
36
|
+
* data: unwrapData
|
|
37
|
+
* }]
|
|
38
|
+
* });
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Get wrapped token info for trading
|
|
42
|
+
* function getWrappedTokenInfo(chain: EvmChain) {
|
|
43
|
+
* const token = WETH9[chain];
|
|
44
|
+
* return {
|
|
45
|
+
* address: token.address,
|
|
46
|
+
* symbol: token.symbol,
|
|
47
|
+
* decimals: token.decimals,
|
|
48
|
+
* name: token.name
|
|
49
|
+
* };
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // Check if address is a wrapped native token
|
|
53
|
+
* function isWrappedNative(chain: EvmChain, tokenAddress: string): boolean {
|
|
54
|
+
* return WETH9[chain].address.toLowerCase() === tokenAddress.toLowerCase();
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // Use in DEX operations
|
|
58
|
+
* const swapConfig = {
|
|
59
|
+
* fromToken: NATIVE_ADDRESS, // Native ETH
|
|
60
|
+
* toToken: WETH9[Chain.ETHEREUM].address, // Wrapped ETH
|
|
61
|
+
* amount: parseEther('1')
|
|
62
|
+
* };
|
|
63
|
+
* ```
|
|
4
64
|
*/
|
|
5
65
|
export declare const WETH9: {
|
|
66
|
+
/** Wrapped Ether (WETH) on Ethereum */
|
|
6
67
|
ethereum: Token;
|
|
68
|
+
/** Wrapped Ether (WETH) on Optimism */
|
|
7
69
|
optimism: Token;
|
|
70
|
+
/** Wrapped BNB (WBNB) on Binance Smart Chain */
|
|
8
71
|
bsc: Token;
|
|
72
|
+
/** Wrapped POL (WPOL) on Polygon */
|
|
9
73
|
polygon: Token;
|
|
74
|
+
/** Wrapped Ether (WETH) on zkSync Era */
|
|
10
75
|
zksync: Token;
|
|
76
|
+
/** Wrapped KAVA (WKAVA) on Kava EVM */
|
|
11
77
|
kava_evm: Token;
|
|
78
|
+
/** Wrapped AVAX (WAVAX) on Avalanche */
|
|
12
79
|
avalanche: Token;
|
|
80
|
+
/** Wrapped Ether (WETH) on Arbitrum */
|
|
13
81
|
arbitrum: Token;
|
|
82
|
+
/** Wrapped METIS (WMETIS) on Metis */
|
|
14
83
|
metis: Token;
|
|
84
|
+
/** Wrapped Ether (WETH) on Base */
|
|
15
85
|
base: Token;
|
|
86
|
+
/** Wrapped S (WS) on Sonic */
|
|
16
87
|
sonic: Token;
|
|
88
|
+
/** Wrapped Ether (WETH) on Scroll */
|
|
17
89
|
scroll: Token;
|
|
90
|
+
/** Wrapped xDAI (WXDAI) on Gnosis Chain */
|
|
18
91
|
gnosis: Token;
|
|
92
|
+
/** Wrapped HYPE (WHYPE) on HyperEVM */
|
|
19
93
|
hyperevm: Token;
|
|
94
|
+
/** Wrapped XPL (WXPL) on Plasma */
|
|
20
95
|
plasma: Token;
|
|
21
96
|
};
|