Skip to content

Commit

Permalink
Portal - EVM wrapped tokens 'to' address change
Browse files Browse the repository at this point in the history
Wormhole wrapped tokens are burned by the bridge when transferred out from a
chain, thus the `to` argument in the wrapped token contract's `Transfer` event is the
EVM zero-address. However wormhole wrapped tokens are never double-wrapped, so
they should be included in the volume when they're not being sent back to their
origination chain where they'd be included in the withdrawal volume when unlocked. This
change is consistent with DefiLlama's volume calculation methodology of not double
counting token transfers in the volume.
  • Loading branch information
kev1n-peters committed Sep 30, 2023
1 parent 1670d7b commit ab77be3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/adapters/portal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ const portalNativeAndWrappedTransfersFromHashes = async (chain: Chain, hashes: s
// for deposits there will be a `LogMessagePublished` event
const logMessagePublished = tryParseLog(log, logMessagePublishedIface);
if (logMessagePublished) {
const payload = Buffer.from(logMessagePublished.args.payload.slice(2), "hex");
// only care about token transfer message types (payload ID = 1 or 3)
const payloadID = parseInt(logMessagePublished.args.payload.slice(0, 4));
const payloadID = payload.readUint8(0);
if (!(payloadID === 1 || payloadID === 3)) {
return results;
}
Expand All @@ -142,9 +143,21 @@ const portalNativeAndWrappedTransfersFromHashes = async (chain: Chain, hashes: s
const transfer = tryParseLog(previousLog, transferIface);
// lock or burn
let to = "";
let isDeposit = true;
if (transfer && (transfer.args.to === tokenBridge || transfer.args.to === ethers.constants.AddressZero)) {
amount = transfer.args.value;
to = transfer.args.to;
if (to === ethers.constants.AddressZero) {
// if this is a wrapped token being burned and not being sent to its origin chain,
// then it should be included in the volume by fixing the to address
// https://docs.wormhole.com/wormhole/explore-wormhole/vaa#token-transfer
const originChain = payload.readUint16BE(65);
const toChain = payload.readUInt16BE(99);
if (toChain !== originChain) {
to = tokenBridge;
isDeposit = false;
}
}
} else {
const deposit = tryParseLog(previousLog, depositIface);
// lock
Expand All @@ -161,7 +174,7 @@ const portalNativeAndWrappedTransfersFromHashes = async (chain: Chain, hashes: s
to,
token: previousLog.address,
amount,
isDeposit: true,
isDeposit,
});
return results;
}
Expand Down Expand Up @@ -291,7 +304,7 @@ const constructParams = (chain: string) => {
// only able to get from subgraph, Etherscan API, etc.
// skipped for chains without available API
// TODO: change this when the token bridge emits the `TransferRedeemed` event
if (chain !== "klaytn") {
if (chain !== "klaytn" && chain !== "base" && chain !== "moonbeam") {
await getLock();
const txs = await getTxsBlockRangeEtherscan(chain, tokenBridge, fromBlock, toBlock, {
includeSignatures: completeTransferSigs,
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/portal/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ const testAvalanche = async () => {
blockNumber,
txHash: "0x3841246c0c1f4aa9190cdacddcd3eac6d8bf10562fc2e2b4615484e0694394e6",
from: "0x31eeE3D36b30E26e733B9e11f112c2cb87AbF618",
to: "0x0000000000000000000000000000000000000000",
to: "0x0e082F06FF657D94310cB8cE8B0D9a04541d8052",
token: "0xDfDA518A1612030536bD77Fd67eAcbe90dDC52Ab",
amount: ethers.BigNumber.from("14000000000000000000"),
isDeposit: true,
isDeposit: false,
},
event
);
Expand Down

0 comments on commit ab77be3

Please sign in to comment.