File tree 3 files changed +29
-3
lines changed
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -86,15 +86,21 @@ export class RouteTransferRequest<N extends Network> {
86
86
params : {
87
87
source : TokenId < FC > ;
88
88
destination : TokenId < TC > ;
89
+ sourceDecimals ?: number ;
90
+ destinationDecimals ?: number ;
89
91
} ,
90
92
fromChain ?: ChainContext < N , FC > ,
91
93
toChain ?: ChainContext < N , TC > ,
92
94
) {
93
95
fromChain = fromChain ?? wh . getChain ( params . source . chain ) ;
94
96
toChain = toChain ?? wh . getChain ( params . destination . chain ) ;
95
97
96
- const sourceDetails = await getTokenDetails ( fromChain , params . source ) ;
97
- const destDetails = await getTokenDetails ( toChain , params . destination ) ;
98
+ const sourceDetails = await getTokenDetails ( fromChain , params . source , params . sourceDecimals ) ;
99
+ const destDetails = await getTokenDetails (
100
+ toChain ,
101
+ params . destination ,
102
+ params . destinationDecimals ,
103
+ ) ;
98
104
99
105
const rtr = new RouteTransferRequest ( fromChain , toChain , sourceDetails , destDetails ) ;
100
106
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export function tokenAddresses(tokens: TokenId[]): string[] {
31
31
export async function getTokenDetails < N extends Network > (
32
32
chain : ChainContext < N > ,
33
33
token : TokenId ,
34
+ decimals ?: number ,
34
35
) : Promise < TokenDetails > {
35
36
const address = canonicalAddress ( token ) ;
36
37
@@ -40,7 +41,7 @@ export async function getTokenDetails<N extends Network>(
40
41
41
42
const symbol = details ? details . symbol : undefined ;
42
43
const wrapped = isNative ( token . address ) ? await chain . getNativeWrappedTokenId ( ) : undefined ;
43
- const decimals = Number ( await chain . getDecimals ( token . address ) ) ;
44
+ decimals = decimals ?? ( await chain . getDecimals ( token . address ) ) ;
44
45
45
46
return {
46
47
id : token ,
Original file line number Diff line number Diff line change @@ -63,6 +63,25 @@ export function isTokenId<C extends Chain>(thing: any): thing is TokenId<C> {
63
63
) ;
64
64
}
65
65
66
+ /**
67
+ * An UnattestedTokenId is used to represent a token that has not yet been attested / created
68
+ *
69
+ * @interface UnattestedTokenId
70
+ */
71
+ export type UnattestedTokenId < C extends Chain = Chain > = TokenId < C > & {
72
+ isUnattested : true ;
73
+ decimals : number ; // expected decimals for the token
74
+ originalTokenId : TokenId ;
75
+ } ;
76
+ export function isUnattestedTokenId < C extends Chain > ( thing : any ) : thing is UnattestedTokenId < C > {
77
+ return (
78
+ isTokenId ( thing ) &&
79
+ ( < UnattestedTokenId < C > > thing ) . isUnattested === true &&
80
+ ( < UnattestedTokenId < C > > thing ) . decimals !== undefined &&
81
+ ( < UnattestedTokenId < C > > thing ) . originalTokenId !== undefined
82
+ ) ;
83
+ }
84
+
66
85
export function isSameToken ( a : TokenId , b : TokenId ) : boolean {
67
86
if ( a . chain !== b . chain ) return false ;
68
87
if ( isNative ( a . address ) && isNative ( b . address ) ) return true ;
You can’t perform that action at this time.
0 commit comments