fix: with no Amount line, the user's takes the total adds up get lines of their own (closes #659)
When a step this decoder cannot read, an unreadable permit, or a take of Token In with an unknown amount held back the Amount line, the amount the step that sets the input side states, and each later take of Token In added to it, appeared on no line, while other takes kept their own Moved from the sender lines. Those takes now get the same lines, first. The first step's amount gets them only when the user pays that step (a V2 or V3 step with payerIsUser true, a V4 step the user pays some of its input token, or a WRAP_ETH): one paid from the router takes nothing from the wallet. Routes with an Amount line read as before. Model: opus-5-5
This commit was merged in pull request #662.
This commit is contained in:
+29
-8
@@ -1234,9 +1234,11 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
let inputToken = null;
|
||||
let inputAmount = null;
|
||||
let inputEstablished = false;
|
||||
// Whether the user pays the V4 step that set the input side any of
|
||||
// its input currency (see decodeV4Swap()). Only a V4 step can set the
|
||||
// input side with no amount, the one case in which this is read.
|
||||
// Whether the user pays the step that set the input side: a V2 or V3
|
||||
// swap step with `payerIsUser` true, a V4 step the user pays some of
|
||||
// its input currency (see decodeV4Swap()), or a WRAP_ETH, whose ETH
|
||||
// comes from the transaction's value. A step paid from the router
|
||||
// takes nothing from the sender.
|
||||
let inputPaidByUser = false;
|
||||
// The last PERMIT2_PERMIT this decoder read before a step set the
|
||||
// input side, or null (see permitStands after the loop).
|
||||
@@ -1622,6 +1624,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
if (s) {
|
||||
if (!inputEstablished) {
|
||||
setInputOnce(s.tokenIn, s.amountIn);
|
||||
inputPaidByUser = s.payerIsUser;
|
||||
} else if (s.payerIsUser) {
|
||||
addUserPaid(s.tokenIn, s.amountIn);
|
||||
}
|
||||
@@ -1645,6 +1648,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
if (s) {
|
||||
if (!inputEstablished) {
|
||||
setInputOnce(s.tokenIn, s.amountIn);
|
||||
inputPaidByUser = s.payerIsUser;
|
||||
} else if (s.payerIsUser) {
|
||||
addUserPaid(s.tokenIn, s.amountIn);
|
||||
}
|
||||
@@ -1676,6 +1680,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
if (s) {
|
||||
if (!inputEstablished) {
|
||||
setInputOnce(s.tokenIn, s.amountInMax);
|
||||
inputPaidByUser = s.payerIsUser;
|
||||
} else if (s.payerIsUser) {
|
||||
addUserPaid(s.tokenIn, s.amountInMax);
|
||||
}
|
||||
@@ -1771,10 +1776,13 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
} else if (command === "WRAP_ETH") {
|
||||
const w = decodeWrapEth(inputs[i]);
|
||||
if (w) {
|
||||
setInputOnce(
|
||||
"0x0000000000000000000000000000000000000000",
|
||||
w.amount,
|
||||
);
|
||||
if (!inputEstablished) {
|
||||
setInputOnce(
|
||||
"0x0000000000000000000000000000000000000000",
|
||||
w.amount,
|
||||
);
|
||||
inputPaidByUser = true;
|
||||
}
|
||||
addPayee(w.recipient);
|
||||
// CONTRACT_BALANCE wraps all the router's ETH.
|
||||
if (w.amount === CONTRACT_BALANCE) {
|
||||
@@ -2041,6 +2049,11 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
// (see spentUnread()), or a token it does not know.
|
||||
const spentFromSender = [];
|
||||
let total = null;
|
||||
// The takes from the sender that `total` adds up, each a quantity, as
|
||||
// { token, amount }. When there is no Amount line, each gets lines of
|
||||
// its own (see below). The amount of a step that set the input side
|
||||
// and is paid from the router counts in `total` but is not among them.
|
||||
const inTotal = [];
|
||||
// Whether the step that set the input side counts as a take from the
|
||||
// sender, which may get lines of its own. The amount it stated counts
|
||||
// whoever pays it. Stating none, it counts only when the user pays it
|
||||
@@ -2053,6 +2066,9 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
let firstTakeUnstated = null;
|
||||
if (!permitStands || sameAddress(inputToken, permit.token)) {
|
||||
total = inputAmount;
|
||||
if (typeof inputAmount === "bigint" && inputPaidByUser) {
|
||||
inTotal.push({ token: inputToken, amount: inputAmount });
|
||||
}
|
||||
if (hasFirstTake && !present(inputAmount)) {
|
||||
firstTakeUnstated = { token: inputToken, amount: null };
|
||||
}
|
||||
@@ -2071,6 +2087,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
typeof t.amount === "bigint"
|
||||
) {
|
||||
total += t.amount;
|
||||
inTotal.push(t);
|
||||
continue;
|
||||
}
|
||||
spentFromSender.push(t);
|
||||
@@ -2202,7 +2219,9 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
// A null token in `spentFromSender`, a step this decoder did not read
|
||||
// or a token it does not know, and one in `permits`, a permit or
|
||||
// batch it could not read, leave no Amount figure, which may then be
|
||||
// too low.
|
||||
// too low. With no Amount line, each take the total adds up gets
|
||||
// lines of its own, first, so that every amount this decoder read is
|
||||
// shown.
|
||||
if (
|
||||
present(inputAmount) &&
|
||||
spentFromSender.every((s) => present(s.token)) &&
|
||||
@@ -2214,6 +2233,8 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
value: amount.display,
|
||||
rawValue: amount.raw,
|
||||
});
|
||||
} else {
|
||||
spentFromSender.unshift(...inTotal);
|
||||
}
|
||||
|
||||
// What steps take from the sender beyond the Amount line, in the shape
|
||||
|
||||
Reference in New Issue
Block a user