Skip to content

Commit 37c5d06

Browse files
committed
Aptos: Fix redeem method and fetching native decimals (#639)
1 parent bc7a83a commit 37c5d06

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

connect/src/protocols/tokenBridge/tokenTransfer.ts

+13
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ export namespace TokenTransfer {
644644
}
645645

646646
const dstToken = await TokenTransfer.lookupDestinationToken(srcChain, dstChain, transfer.token);
647+
// TODO: this is a hack to get the aptos native gas token decimals
648+
// which requires us to pass in a token address in canonical form
649+
// but the `dstToken.address` here is in universal form
650+
if (dstChain.chain === "Aptos" && dstToken.chain === "Aptos") {
651+
const dstTb = await dstChain.getTokenBridge();
652+
const wrappedNative = await dstTb.getWrappedNative();
653+
if (
654+
dstToken.address.toString() ===
655+
(await dstTb.getTokenUniversalAddress(wrappedNative)).toString()
656+
) {
657+
dstToken.address = wrappedNative;
658+
}
659+
}
647660
const dstDecimals = await dstChain.getDecimals(dstToken.address);
648661
const dstAmountReceivable = amount.scale(srcAmountTruncated, dstDecimals);
649662

platforms/aptos/protocols/tokenBridge/src/tokenBridge.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ export class AptosTokenBridge<N extends Network, C extends AptosChains>
298298
return typeInfo
299299
? [
300300
typeInfo.account_address,
301-
encoding.hex.decode(typeInfo.module_name),
302-
encoding.hex.decode(typeInfo.struct_name),
301+
String.fromCharCode(...encoding.hex.decode(typeInfo.module_name)),
302+
String.fromCharCode(...encoding.hex.decode(typeInfo.struct_name)),
303303
].join(APTOS_SEPARATOR)
304304
: null;
305305
} catch {

0 commit comments

Comments
 (0)