Skip to content

Commit 8c8b0f9

Browse files
EvgenKorAllFi
andauthored
Tron support (#9)
* Adding TronClient * Refactoring, removing PolkadotClient * TronClient implementation * Fixing type * Using EVM ABI for Tron * Retrying RCP requests * Getting block number * Validate native address routine * Minor fix * Moving tx estimation and signing to the single routine, fix issue with gas multiplier * Drop unneeded import * Making routine `networkType` and `SupportedNetwork` enum as a private identities * Optional field in config: `gasMultiplier` (for EVM networks only) * Fixed typos, removed default values for critical parameters * Update src/networks/tron/client.ts Co-authored-by: Alexander Filippov <aleksander.fill@gmail.com> * Added Nile testnet support * Renaming package to `zkbob-support-js` --------- Co-authored-by: Alexander Filippov <aleksander.fill@gmail.com>
1 parent c788496 commit 8c8b0f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2092
-1321
lines changed

lib/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import { Client } from './networks/client';
12
export { Client } from './networks/client';
23
export { EthereumClient } from './networks/evm';
3-
export { PolkadotClient } from './networks/polkadot';
4+
export { TronClient } from './networks/tron';
5+
export interface Config {
6+
transactionUrl: string;
7+
gasMultiplier?: number;
8+
}
9+
export declare class ClientFactory {
10+
static createClient(chainId: number, rpcUrl: string, mnemonic: string, config: Config): Client;
11+
}

lib/index.js

Lines changed: 58 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networks/client.d.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,33 @@ import { TxFee } from './transaction';
33
export declare type AccountId = number | string;
44
export declare abstract class Client {
55
transactionUrl: string;
6+
abstract haltClient(): void;
7+
getChainId(): Promise<number>;
8+
abstract getBlockNumber(): Promise<number>;
9+
abstract getTokenName(tokenAddress: string): Promise<string>;
10+
abstract decimals(tokenAddress: string): Promise<number>;
11+
abstract baseUnit(): string;
12+
abstract toBaseUnit(humanAmount: string): bigint;
13+
abstract fromBaseUnit(baseAmount: bigint): string;
14+
abstract toBaseTokenUnit(tokenAddress: string, humanAmount: string): Promise<bigint>;
15+
abstract fromBaseTokenUnit(tokenAddress: string, baseAmount: bigint): Promise<string>;
16+
abstract validateAddress(address: string): boolean;
17+
getTransactionUrl(hash: string): string;
618
abstract getAddress(): Promise<string>;
719
getPublicKey(): Promise<string>;
8-
getChainId(): Promise<number>;
9-
/**
10-
* Get native coin balance.
11-
*/
12-
abstract getBalance(): Promise<string>;
13-
getTokenBalance(tokenAddress: string): Promise<string>;
14-
getTokenNonce(tokenAddress: string): Promise<string>;
15-
getTokenName(tokenAddress: string): Promise<string>;
16-
/**
17-
* Transfer native coin.
18-
* @param to destination address
19-
* @param amount as base unit
20-
*/
21-
abstract transfer(to: string, amount: string): Promise<string>;
22-
transferToken(tokenAddress: string, to: string, amount: string): Promise<string>;
23-
mint(tokenAddres: string, amount: string): Promise<string>;
24-
approve(tokenAddress: string, spender: string, amount: string): Promise<string>;
25-
increaseAllowance(tokenAddress: string, spender: string, additionalAmount: string): Promise<string>;
20+
abstract getBalance(): Promise<bigint>;
21+
abstract getTokenBalance(tokenAddress: string): Promise<bigint>;
22+
getTokenNonce(tokenAddress: string): Promise<number>;
2623
allowance(tokenAddress: string, spender: string): Promise<bigint>;
27-
getDirectDepositContract(poolAddress: string): Promise<string>;
28-
directDeposit(poolAddress: string, amount: string, zkAddress: string): Promise<string>;
29-
getTransactionUrl(hash: string): string;
30-
decimals(tokenAddress: string): Promise<number>;
31-
/**
32-
* Convert human-readable representation of coin to smallest non-divisible (base) representation.
33-
* @param amount
34-
*/
35-
abstract toBaseUnit(tokenAddress: string, amount: string): Promise<string>;
36-
/**
37-
* Convert coin represented with smallest non-divisible units to a human-readable representation.
38-
* @param amount
39-
*/
40-
abstract fromBaseUnit(tokenAddress: string, amount: string): Promise<string>;
41-
/**
42-
* Get estimated transaction fee.
43-
*/
44-
estimateTxFee(): Promise<TxFee>;
24+
estimateTxFee(txObject?: any): Promise<TxFee>;
25+
sendTransaction(to: string, amount: bigint, data: string, selector?: string): Promise<string>;
26+
abstract transfer(to: string, amount: bigint): Promise<string>;
27+
abstract transferToken(tokenAddress: string, to: string, amount: bigint): Promise<string>;
28+
approve(tokenAddress: string, spender: string, amount: bigint): Promise<string>;
29+
increaseAllowance(tokenAddress: string, spender: string, additionalAmount: bigint): Promise<string>;
30+
mint(tokenAddres: string, amount: bigint): Promise<string>;
4531
sign(data: string): Promise<string>;
4632
signTypedData(data: any): Promise<string>;
47-
sendTransaction(to: string, amount: bigint, data: string): Promise<string>;
33+
getDirectDepositContract(poolAddress: string): Promise<string>;
34+
directDeposit(poolAddress: string, amount: bigint, zkAddress: string): Promise<string>;
4835
}

lib/networks/client.js

Lines changed: 19 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/networks/client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)