Skip to content

Commit a24aba9

Browse files
authored
Fixed conversion within base units (#7)
* Fixed toBaseUnit/fromBaseUnit * BaseAmount edge cases
1 parent 2d8a8e2 commit a24aba9

File tree

14 files changed

+113
-63
lines changed

14 files changed

+113
-63
lines changed

lib/networks/client.d.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TxFee } from './transaction';
22
/** Account number or address */
3-
export type AccountId = number | string;
3+
export declare type AccountId = number | string;
44
export declare abstract class Client {
55
transactionUrl: string;
66
abstract getAddress(): Promise<string>;
@@ -27,20 +27,17 @@ export declare abstract class Client {
2727
getDirectDepositContract(poolAddress: string): Promise<string>;
2828
directDeposit(poolAddress: string, amount: string, zkAddress: string): Promise<string>;
2929
getTransactionUrl(hash: string): string;
30-
/**
31-
*
32-
*/
33-
updateState(): Promise<void>;
30+
decimals(tokenAddress: string): Promise<number>;
3431
/**
3532
* Convert human-readable representation of coin to smallest non-divisible (base) representation.
3633
* @param amount
3734
*/
38-
abstract toBaseUnit(amount: string): string;
35+
abstract toBaseUnit(tokenAddress: string, amount: string): Promise<string>;
3936
/**
4037
* Convert coin represented with smallest non-divisible units to a human-readable representation.
4138
* @param amount
4239
*/
43-
abstract fromBaseUnit(amount: string): string;
40+
abstract fromBaseUnit(tokenAddress: string, amount: string): Promise<string>;
4441
/**
4542
* Get estimated transaction fee.
4643
*/

lib/networks/client.js

Lines changed: 1 addition & 4 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.

lib/networks/evm/client.d.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export declare class EthereumClient extends Client {
1111
private pool;
1212
private dd;
1313
private ddContractAddresses;
14+
private tokenDecimals;
1415
gasMultiplier: number;
1516
constructor(provider: provider, config?: Config);
1617
getChainId(): Promise<number>;
@@ -20,16 +21,18 @@ export declare class EthereumClient extends Client {
2021
getTokenNonce(tokenAddress: string): Promise<string>;
2122
getTokenName(tokenAddress: string): Promise<string>;
2223
transfer(to: string, amount: string): Promise<string>;
24+
decimals(tokenAddress: string): Promise<number>;
2325
/**
24-
* Converts ether to Wei.
25-
* @param amount in Ether
26+
* Converts a token amount to the minimum supported resolution
27+
* Resolution depends on token's `decimal` property
28+
* @param amount in Ether\tokens
2629
*/
27-
toBaseUnit(amount: string): string;
30+
toBaseUnit(tokenAddress: string, amount: string): Promise<string>;
2831
/**
29-
* Converts Wei to ether.
30-
* @param amount in Wei
32+
* Converts token native amount to the humah-readable representations
33+
* @param amount in minimum supported units
3134
*/
32-
fromBaseUnit(amount: string): string;
35+
fromBaseUnit(tokenAddress: string, amount: string): Promise<string>;
3336
estimateTxFee(): Promise<TxFee>;
3437
mint(minterAddress: string, amount: string): Promise<string>;
3538
transferToken(tokenAddress: string, to: string, amount: string): Promise<string>;

lib/networks/evm/client.js

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

0 commit comments

Comments
 (0)