diff --git a/packages/stream/aptos/types.ts b/packages/stream/aptos/types.ts index 2572110a..b4fb60fc 100644 --- a/packages/stream/aptos/types.ts +++ b/packages/stream/aptos/types.ts @@ -5,6 +5,7 @@ import BN from "bn.js"; import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils"; import { Stream, StreamType } from "../common/types"; import { getNumberFromBN } from "../common/utils"; +import { normalizeAptosAddress } from "./utils"; export interface ICreateStreamAptosExt { senderWallet: WalletContextState | AptosAccount; @@ -163,10 +164,10 @@ export class Contract implements Stream { this.canceledAt = parseInt(stream.canceled_at); this.end = parseInt(stream.end); this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at); - this.sender = stream.sender; - this.senderTokens = stream.sender; - this.recipient = stream.recipient; - this.recipientTokens = stream.recipient; + this.sender = normalizeAptosAddress(stream.sender); + this.senderTokens = normalizeAptosAddress(stream.sender); + this.recipient = normalizeAptosAddress(stream.recipient); + this.recipientTokens = normalizeAptosAddress(stream.recipient); this.mint = tokenId; this.escrowTokens = ""; this.streamflowTreasury = ""; diff --git a/packages/stream/aptos/utils.ts b/packages/stream/aptos/utils.ts index c5641908..0eea4bf1 100644 --- a/packages/stream/aptos/utils.ts +++ b/packages/stream/aptos/utils.ts @@ -9,3 +9,25 @@ export function extractAptosErrorCode(errorText: string): string | null { return match[2]; } + +function isAddressSpecial(address: string): boolean { + if (address.length === 3) { + return true; + } + return false; +} + +// Per this: https://github.com/aptos-labs/aptos-ts-sdk/blob/main/src/core/accountAddress.ts#L115 +export function normalizeAptosAddress(address: string): string { + if (isAddressSpecial(address)) { + return address; + } + + const length = address.length; + if (length === 64) { + return address; + } + + const missingZeros = 64 - length; + return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2); +}