|
1 | 1 | import type { Chain, Network } from "@wormhole-foundation/sdk-base";
|
2 |
| -import { amount, encoding, finality, guardians, toChain as toChainName } from "@wormhole-foundation/sdk-base"; |
| 2 | +import { |
| 3 | + amount, |
| 4 | + encoding, |
| 5 | + finality, |
| 6 | + guardians, |
| 7 | + toChain as toChainName, |
| 8 | +} from "@wormhole-foundation/sdk-base"; |
3 | 9 | import type {
|
4 | 10 | AttestationId,
|
5 | 11 | AutomaticTokenBridge,
|
@@ -167,9 +173,20 @@ export class TokenTransfer<N extends Network = Network>
|
167 | 173 | let from = { chain: vaa.emitterChain, address: vaa.emitterAddress };
|
168 | 174 | let { token, to } = vaa.payload;
|
169 | 175 |
|
| 176 | + let nativeAddress: NativeAddress<Chain>; |
| 177 | + if (token.chain === from.chain) { |
| 178 | + nativeAddress = await wh.getTokenNativeAddress(from.chain, token.chain, token.address); |
| 179 | + } else { |
| 180 | + const fromChain = await wh.getChain(from.chain); |
| 181 | + const tb = await fromChain.getTokenBridge(); |
| 182 | + const wrapped = await tb.getWrappedAsset(token); |
| 183 | + nativeAddress = toNative(from.chain, wrapped.toString()); |
| 184 | + } |
| 185 | + |
| 186 | + const decimals = await wh.getDecimals(from.chain, nativeAddress); |
170 | 187 | const scaledAmount = amount.scale(
|
171 |
| - amount.fromBaseUnits(token.amount, TokenTransfer.MAX_DECIMALS), |
172 |
| - await wh.getDecimals(token.chain, token.address), |
| 188 | + amount.fromBaseUnits(token.amount, Math.min(decimals, TokenTransfer.MAX_DECIMALS)), |
| 189 | + decimals, |
173 | 190 | );
|
174 | 191 |
|
175 | 192 | let nativeGasAmount: bigint = 0n;
|
|
0 commit comments