Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reservoir0x/relay-protocol-sdk",
"version": "0.0.52",
"version": "0.0.53",
"description": "Relay protocol SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getDecodedWithdrawalId,
getDecodedWithdrawalCurrency,
getDecodedWithdrawalAmount,
getDecodedWithdrawalRecipient,
} from "./messages/v2.1/depository-withdrawal";

import {
Expand Down Expand Up @@ -97,6 +98,7 @@ export {
getDecodedWithdrawalId,
getDecodedWithdrawalCurrency,
getDecodedWithdrawalAmount,
getDecodedWithdrawalRecipient,

// SolverRefund
SolverRefundMessage,
Expand Down
76 changes: 71 additions & 5 deletions src/messages/v2.1/depository-withdrawal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,16 +789,16 @@ export const getDecodedWithdrawalCurrency = (
}
};

const decodeERC20TransferAmount = (data: string) => {
const decodeERC20TransferParams = (data: string) => {
// ERC20 / TRC20 `transfer(address,uint256)` selector is 0xa9059cbb
const TRANSFER_SELECTOR = "0xa9059cbb";
if (data.toLowerCase().startsWith(TRANSFER_SELECTOR.toLowerCase())) {
const paramsData = ("0x" + data.slice(TRANSFER_SELECTOR.length)) as Hex;
const [amount] = decodeAbiParameters(
const params = decodeAbiParameters(
parseAbiParameters(["address", "uint256"]),
paramsData
);
return amount;
return params;
} else {
throw new Error(`Unsupported function call data: ${data}`);
}
Expand All @@ -813,7 +813,8 @@ export const getDecodedWithdrawalAmount = (
if (firstCall.data === "0x") {
return firstCall.value;
} else {
return decodeERC20TransferAmount(firstCall.data);
const [, amount] = decodeERC20TransferParams(firstCall.data);
return amount.toString();
}
}

Expand All @@ -822,7 +823,8 @@ export const getDecodedWithdrawalAmount = (
if (firstCall.data === "0x") {
return firstCall.value;
} else {
return decodeERC20TransferAmount(firstCall.data);
const [, amount] = decodeERC20TransferParams(firstCall.data);
return amount.toString();
}
}

Expand Down Expand Up @@ -859,3 +861,67 @@ export const getDecodedWithdrawalAmount = (
throw new Error("Unsupported vm type");
}
};

export const getDecodedWithdrawalRecipient = (
decodedWithdrawal: DecodedWithdrawal
): string => {
switch (decodedWithdrawal.vmType) {
case "ethereum-vm": {
const firstCall = decodedWithdrawal.withdrawal.calls[0];
if (firstCall.data === "0x") {
return firstCall.to;
} else {
const [to] = decodeERC20TransferParams(firstCall.data);
return to;
}
}

case "tron-vm": {
const firstCall = decodedWithdrawal.withdrawal.calls[0];
if (firstCall.data === "0x") {
return firstCall.to;
} else {
const [to] = decodeERC20TransferParams(firstCall.data);
return to;
}
}

case "solana-vm": {
return decodedWithdrawal.withdrawal.recipient;
}

case "sui-vm": {
return decodedWithdrawal.withdrawal.recipient;
}

case "bitcoin-vm": {
try {
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
const tx = psbt.extractTransaction(false);
if (tx.outs.length === 0) {
throw new Error("Transaction has no outputs");
}
// Extract address from the first output
const firstOutput = tx.outs[0];
const address = bitcoin.address.fromOutputScript(
firstOutput.script,
bitcoin.networks.bitcoin
);
return address;
} catch (error) {
throw new Error(
`Failed to decode PSBT: ${
error instanceof Error ? error.message : String(error)
}`
);
}
}

case "hyperliquid-vm": {
return decodedWithdrawal.withdrawal.parameters.destination;
}

default:
throw new Error("Unsupported vm type");
}
};