Compare commits
2
Commits
3add1a158b
...
f2059261f0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2059261f0 | ||
|
|
ec6b6b57a3 |
No files matched your search
@@ -2281,6 +2281,8 @@ view would leave a wallet one click from deletion.
|
|||||||
- Endpoint URL input + "Save" button. "Save" asks the URL for `/stats`
|
- Endpoint URL input + "Save" button. "Save" asks the URL for `/stats`
|
||||||
and saves the URL only if that request succeeds. The request carries
|
and saves the URL only if that request succeeds. The request carries
|
||||||
no user data and is made whether or not "Use Blockscout" is ticked.
|
no user data and is made whether or not "Use Blockscout" is ticked.
|
||||||
|
- If the network changes before either "Save" stores its URL, the URL is not
|
||||||
|
saved and a flash message says so
|
||||||
- Etherscan:
|
- Etherscan:
|
||||||
- "Check recipients on Etherscan" checkbox, unticked until the user
|
- "Check recipients on Etherscan" checkbox, unticked until the user
|
||||||
ticks it
|
ticks it
|
||||||
@@ -3477,83 +3479,89 @@ Currently supported:
|
|||||||
of any amount but `OPEN_DELTA` pays that amount, and a `SETTLE` of
|
of any amount but `OPEN_DELTA` pays that amount, and a `SETTLE` of
|
||||||
`OPEN_DELTA` or a `SETTLE_ALL` pays what the step owes, as above. So a V4 step
|
`OPEN_DELTA` or a `SETTLE_ALL` pays what the step owes, as above. So a V4 step
|
||||||
that swaps 400 USDT, with a `SETTLE` of 5,000 USDT paid by the user and the
|
that swaps 400 USDT, with a `SETTLE` of 5,000 USDT paid by the user and the
|
||||||
rest taken to another address, reads `5000.0000 USDT`. A later step paid from
|
rest taken to another address, reads `5000.0000 USDT`. A later step that pays
|
||||||
the router spends what the router holds and takes nothing, and so does a V2
|
an ERC-20 token from the router takes none of that token from the user's
|
||||||
exact-in whose `amountIn` is `ALREADY_PAID`. A later take of `Token In` is
|
wallet. A V2 exact-in whose `amountIn` is `ALREADY_PAID` takes nothing either.
|
||||||
added to the total while both are quantities: a V3 exact-in of 600 USDT and a
|
A V4 `SETTLE` of ETH paid from the router still takes from the user's wallet,
|
||||||
V2 exact-in of 400 USDT, both paid by the user, read `1000.0000 USDT`. When
|
since the router holds the transaction's value. When the decoder does not know
|
||||||
the decoder does not know a take's amount, the total is not known and there is
|
the amount of such a `SETTLE`, as for `CONTRACT_BALANCE`, that `SETTLE` counts
|
||||||
no `Amount` line. A `PERMIT2_PERMIT` names `Token In` only when its amount,
|
as a later step's take. When an earlier step left ETH in the router, that ETH
|
||||||
`Unlimited` included, stands as the `Amount` figure in place of the total,
|
may pay part of a `SETTLE` of ETH paid from the router. That `SETTLE` then
|
||||||
which it does only in the plain shape of Uniswap's own routes: it comes before
|
gets lines of its own, with `Up to` before its amount. A later take of
|
||||||
the step that sets the input side, it is the only `PERMIT2_PERMIT` in the
|
`Token In` that only the user's wallet pays is added to the total while both
|
||||||
transaction and there is no `PERMIT2_PERMIT_BATCH`, its spender is the router,
|
are quantities: a V3 exact-in of 600 USDT and a V2 exact-in of 400 USDT, both
|
||||||
the router may not let it fail, no step before it takes its token, a
|
paid by the user, read `1000.0000 USDT`. When the decoder does not know a
|
||||||
`PERMIT2_TRANSFER_FROM` of it included, or a token the decoder does not know,
|
take's amount, the total is not known and there is no `Amount` line. A
|
||||||
and the decoder reads every step after it in full. Permit2 then lets the
|
`PERMIT2_PERMIT` names `Token In` only when its amount, `Unlimited` included,
|
||||||
router take no more of the token than that amount, so the permit covers every
|
stands as the `Amount` figure in place of the total, which it does only in the
|
||||||
take of it. A step before the permit takes under whatever allowance the router
|
plain shape of Uniswap's own routes: it comes before the step that sets the
|
||||||
already had, so it may take more than the permit's amount, which would then
|
input side, it is the only `PERMIT2_PERMIT` in the transaction and there is no
|
||||||
read lower than what leaves the user's wallet: a `PERMIT2_TRANSFER_FROM` of
|
`PERMIT2_PERMIT_BATCH`, its spender is the router, the router may not let it
|
||||||
2,000 USDT into the router, then a permit of 600 USDT to the router and a V3
|
fail, no step before it takes its token, a `PERMIT2_TRANSFER_FROM` of it
|
||||||
exact-in of 2,000 USDT paid from the router, read `Amount 2000.0000 USDT`. A
|
included, or a token the decoder does not know, and the decoder reads every
|
||||||
later permit or batch may raise what Permit2 lets the router take, and so may
|
step after it in full. Permit2 then lets the router take no more of the token
|
||||||
a step the decoder does not read in full: a command the decoder does not read
|
than that amount, so the permit covers every take of it. A step before the
|
||||||
(listed at the end of this section), a step whose input it cannot read, in
|
permit takes under whatever allowance the router already had, so it may take
|
||||||
whole or in part, and a step it fails on. Every other `PERMIT2_PERMIT`, before
|
more than the permit's amount, which would then read lower than what leaves
|
||||||
the step that sets the input side or after it, leaves `Token In` and the
|
the user's wallet: a `PERMIT2_TRANSFER_FROM` of 2,000 USDT into the router,
|
||||||
`Amount` line as they read with no permit, unless it lets a spender other than
|
then a permit of 600 USDT to the router and a V3 exact-in of 2,000 USDT paid
|
||||||
the router take `Token In` (see below): a permit of 5,000 DAI to another
|
from the router, read `Amount 2000.0000 USDT`. A later permit or batch may
|
||||||
address and then a V3 exact-in of 600 USDT read `Swap USDT → USDC` with
|
raise what Permit2 lets the router take, and so may a step the decoder does
|
||||||
`Amount 600.0000 USDT`, and so do that exact-in and then a permit of 5,000 DAI
|
not read in full: a command the decoder does not read (listed at the end of
|
||||||
to the router. A permit on the zero address never stands as the `Amount`
|
this section), a step whose input it cannot read, in whole or in part, and a
|
||||||
figure, because Permit2 has no allowance of ETH. When a permit's amount stands
|
step it fails on. Every other `PERMIT2_PERMIT`, before the step that sets the
|
||||||
and the step that sets the input side spends a token other than the permit's,
|
input side or after it, leaves `Token In` and the `Amount` line as they read
|
||||||
or one the decoder does not know, that step's amount gets lines of its own,
|
with no permit, unless it lets a spender other than the router take `Token In`
|
||||||
unless it states no amount and the user pays it none of its input token. Each
|
(see below): a permit of 5,000 DAI to another address and then a V3 exact-in
|
||||||
take the total does not count gives three lines after the `Amount` line (after
|
of 600 USDT read `Swap USDT → USDC` with `Amount 600.0000 USDT`, and so do
|
||||||
`Token In` when there is none): one of a token other than `Token In`; one of
|
that exact-in and then a permit of 5,000 DAI to the router. A permit on the
|
||||||
`Token In` after an amount that is not a quantity (a V4 open delta,
|
zero address never stands as the `Amount` figure, because Permit2 has no
|
||||||
`ALREADY_PAID`, which keep their wording on the `Amount` line, or no stated
|
allowance of ETH. When a permit's amount stands and the step that sets the
|
||||||
amount, as of a V4 exact-out step); and one whose amount the decoder does not
|
input side spends a token other than the permit's, or one the decoder does not
|
||||||
know. When there is no `Amount` line, each take the total counts gets them
|
know, that step's amount gets lines of its own, unless it states no amount and
|
||||||
too, so that every amount the decoder reads is shown: the amount the step that
|
the user pays it none of its input token. Each take the total does not count
|
||||||
sets the input side states, when it is a quantity and the user pays that step
|
gives three lines after the `Amount` line (after `Token In` when there is
|
||||||
(a V2 or V3 step whose `payerIsUser` is true, a V4 step the user pays some of
|
none): one of a token other than `Token In`; one of `Token In` after an amount
|
||||||
its input token, or a `WRAP_ETH`, whose ETH comes from the transaction's
|
that is not a quantity (a V4 open delta, `ALREADY_PAID`, which keep their
|
||||||
value), and each later take of `Token In` added to it. A step that sets the
|
wording on the `Amount` line, or no stated amount, as of a V4 exact-out step);
|
||||||
input side and is paid from the router takes nothing from the user's wallet
|
an ETH take whose line reads `Up to` (see above); and one whose amount the
|
||||||
and gets none. A `PERMIT2_PERMIT` the decoder cannot read, then V3 exact-ins
|
decoder does not know. When there is no `Amount` line, each take the total
|
||||||
of 600 USDT and 400 DAI paid by the user, give lines for both amounts. When
|
counts gets them too, so that every amount the decoder reads is shown: the
|
||||||
the step that sets the input side states no amount, the user pays it some of
|
amount the step that sets the input side states, when it is a quantity and the
|
||||||
its input token, and there is no `Amount` line, that step gets them too
|
user pays that step (a V2 or V3 step whose `payerIsUser` is true, a V4 step
|
||||||
whenever another take's lines give a figure, or a `PERMIT2_TRANSFER_FROM` of
|
the user pays some of its input token, or a `WRAP_ETH`, whose ETH comes from
|
||||||
its token gives one, on the lines below or, into the router, on its `Paid to`
|
the transaction's value), and each later take of `Token In` added to it. A
|
||||||
line, so that figure cannot read as all that leaves. When it states no amount
|
step that sets the input side gets none when the user pays it none of its
|
||||||
and the user pays it none of its input token, as when the router pays it, that
|
input token. A `PERMIT2_PERMIT` the decoder cannot read, then V3 exact-ins of
|
||||||
step takes none of that token from the user's wallet and never gets them, with
|
600 USDT and 400 DAI paid by the user, give lines for both amounts. When the
|
||||||
a permit or without. They come in step order, except that the step that sets
|
step that sets the input side states no amount, the user pays it some of its
|
||||||
the input side comes first when it has them, followed, when there is no
|
input token, and there is no `Amount` line, that step gets them too whenever
|
||||||
`Amount` line, by the other takes the total counts: `Moved from the sender`,
|
another take's lines give a figure, or a `PERMIT2_TRANSFER_FROM` of its token
|
||||||
its amount, worded as the `Amount` line words one, or
|
gives one, on the lines below or, into the router, on its `Paid to` line, so
|
||||||
`Unknown (could not be decoded)` when the decoder does not know it;
|
that figure cannot read as all that leaves. When it states no amount and the
|
||||||
`Token moved`, giving the token's address as the `Token In` line does; and
|
user pays it none of its input token, that step never gets them, with a permit
|
||||||
`Moved to`, which reads `The swap step that spends it`. A token the decoder
|
or without. They come in step order, except that the step that sets the input
|
||||||
does not know gives the `Moved from the sender` line alone. A step may also
|
side comes first when it has them, followed, when there is no `Amount` line,
|
||||||
take from the user's wallet what the decoder did not read: a V4 step whose
|
by the other takes the total counts: `Moved from the sender`, its amount,
|
||||||
input or one of whose `SETTLE`s or `SETTLE_ALL`s it cannot read, which the
|
worded as the `Amount` line words one, or `Unknown (could not be decoded)`
|
||||||
router still runs; a V2 or V3 exact-in or exact-out step or a
|
when the decoder does not know it; `Token moved`, giving the token's address
|
||||||
`PERMIT2_TRANSFER_FROM` whose input it cannot read, such as a V3 step whose
|
as the `Token In` line does; and `Moved to`, which reads
|
||||||
path is shorter than one token address or has bytes after its last hop; every
|
`The swap step that spends it`. A token the decoder does not know gives the
|
||||||
`PERMIT2_TRANSFER_FROM_BATCH`; every `EXECUTE_SUB_PLAN`, wherever it stands;
|
`Moved from the sender` line alone. A step may also take from the user's
|
||||||
and every step it fails on. Each such step gives one `Moved from the sender`
|
wallet what the decoder did not read: a V4 step whose input or one of whose
|
||||||
line among those, reading `Unknown (could not be decoded)`. That line, or any
|
`SETTLE`s or `SETTLE_ALL`s it cannot read, which the router still runs; a V2
|
||||||
line for a token the decoder does not know, leaves no `Amount` line, whose
|
or V3 exact-in or exact-out step or a `PERMIT2_TRANSFER_FROM` whose input it
|
||||||
figure might be too low, and such a step before a `PERMIT2_PERMIT` keeps the
|
cannot read, such as a V3 step whose path is shorter than one token address or
|
||||||
permit's amount from standing. Then each `PERMIT2_TRANSFER_FROM` but one into
|
has bytes after its last hop; every `PERMIT2_TRANSFER_FROM_BATCH`; every
|
||||||
the router, in step order, gives three lines: `Moved from the sender`, the
|
`EXECUTE_SUB_PLAN`, wherever it stands; and every step it fails on. Each such
|
||||||
amount it moves, for example `1000000.0000 USDT`; `Token moved`, giving the
|
step gives one `Moved from the sender` line among those, reading
|
||||||
token's address as the `Token In` line does; and `Moved to`, which reads
|
`Unknown (could not be decoded)`. That line, or any line for a token the
|
||||||
|
decoder does not know, leaves no `Amount` line, whose figure might be too low,
|
||||||
|
and such a step before a `PERMIT2_PERMIT` keeps the permit's amount from
|
||||||
|
standing. Then each `PERMIT2_TRANSFER_FROM` but one into the router, in step
|
||||||
|
order, gives three lines: `Moved from the sender`, the amount it moves, for
|
||||||
|
example `1000000.0000 USDT`; `Token moved`, giving the token's address as the
|
||||||
|
`Token In` line does; and `Moved to`, which reads
|
||||||
`The V2 pair the next swap spends` for a hop and `The sender` for `address(1)`
|
`The V2 pair the next swap spends` for a hop and `The sender` for `address(1)`
|
||||||
on every router but `UniversalRouterV1`, and otherwise gives the address. A
|
on every router but `UniversalRouterV1`, and otherwise gives the address. A
|
||||||
move into the router needs none of them, because its `Paid to` line and
|
move into the router needs none of them, because its `Paid to` line and
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ let ctx;
|
|||||||
let versionClickCount = 0;
|
let versionClickCount = 0;
|
||||||
let versionClickTimer = null;
|
let versionClickTimer = null;
|
||||||
|
|
||||||
|
// The network that Settings was last drawn for. A follow of a switch saved
|
||||||
|
// elsewhere sets `state` to the new network first. Settings is drawn again only
|
||||||
|
// once the follow's write returns. So both "Save" buttons take this network,
|
||||||
|
// not the one in `state`.
|
||||||
|
let shownNetwork = null;
|
||||||
|
|
||||||
// One row per site origin, however many addresses it appears under, each with
|
// One row per site origin, however many addresses it appears under, each with
|
||||||
// an [x] that hands it to onRemove.
|
// an [x] that hands it to onRemove.
|
||||||
function renderSiteList(containerId, origins, onRemove) {
|
function renderSiteList(containerId, origins, onRemove) {
|
||||||
@@ -199,6 +205,7 @@ function renderWalletListSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
|
shownNetwork = currentNetwork();
|
||||||
$("settings-rpc").value = state.rpcUrl;
|
$("settings-rpc").value = state.rpcUrl;
|
||||||
$("settings-blockscout").value = state.blockscoutUrl;
|
$("settings-blockscout").value = state.blockscoutUrl;
|
||||||
$("settings-network").value = state.networkId;
|
$("settings-network").value = state.networkId;
|
||||||
@@ -306,6 +313,7 @@ function showNewSettings() {
|
|||||||
state.checkRecipientsOnEtherscan;
|
state.checkRecipientsOnEtherscan;
|
||||||
if (state.currentView === "settings") {
|
if (state.currentView === "settings") {
|
||||||
markViewRendered("settings");
|
markViewRendered("settings");
|
||||||
|
shownNetwork = currentNetwork();
|
||||||
$("settings-network").value = state.networkId;
|
$("settings-network").value = state.networkId;
|
||||||
$("settings-rpc").value = state.rpcUrl;
|
$("settings-rpc").value = state.rpcUrl;
|
||||||
$("settings-blockscout").value = state.blockscoutUrl;
|
$("settings-blockscout").value = state.blockscoutUrl;
|
||||||
@@ -319,6 +327,28 @@ function showNewSettings() {
|
|||||||
updateDebugBanner(state.currentView);
|
updateDebugBanner(state.currentView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves `url` as `field` ("rpcUrl" or "blockscoutUrl") of the network
|
||||||
|
// `networkId`, the one that Settings showed when the user tapped "Save". The
|
||||||
|
// URL is set in `state` inside the save, holding the lock. So the page cannot
|
||||||
|
// follow a switch saved elsewhere (followStoredSettings() in
|
||||||
|
// src/popup/index.js) between setting the URL and writing it. If the active
|
||||||
|
// network is no longer `networkId`, on this page or in the stored record,
|
||||||
|
// nothing is saved. The flash message then says that the network changed.
|
||||||
|
async function saveEndpoint(field, url, networkId) {
|
||||||
|
let refused = false;
|
||||||
|
await saveState((stored) => {
|
||||||
|
refused =
|
||||||
|
state.networkId !== networkId || stored.networkId !== networkId;
|
||||||
|
if (refused) return false;
|
||||||
|
state[field] = url;
|
||||||
|
});
|
||||||
|
if (refused) {
|
||||||
|
showFlash("The URL was not saved because the network changed.");
|
||||||
|
} else {
|
||||||
|
showFlash("Saved.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function init(_ctx) {
|
function init(_ctx) {
|
||||||
ctx = _ctx;
|
ctx = _ctx;
|
||||||
deleteWallet.init(ctx);
|
deleteWallet.init(ctx);
|
||||||
@@ -330,6 +360,8 @@ function init(_ctx) {
|
|||||||
showFlash("Please enter an RPC URL.");
|
showFlash("Please enter an RPC URL.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// The URL is for the network that Settings shows when "Save" is tapped.
|
||||||
|
const net = shownNetwork;
|
||||||
showFlash("Testing endpoint...");
|
showFlash("Testing endpoint...");
|
||||||
try {
|
try {
|
||||||
const resp = await debugFetch(url, {
|
const resp = await debugFetch(url, {
|
||||||
@@ -348,7 +380,6 @@ function init(_ctx) {
|
|||||||
showFlash("Endpoint returned an error.");
|
showFlash("Endpoint returned an error.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const net = currentNetwork();
|
|
||||||
if (json.result !== net.chainId) {
|
if (json.result !== net.chainId) {
|
||||||
showFlash("Wrong network: expected " + net.name + ".");
|
showFlash("Wrong network: expected " + net.name + ".");
|
||||||
return;
|
return;
|
||||||
@@ -364,9 +395,7 @@ function init(_ctx) {
|
|||||||
showFlash("Could not reach endpoint.");
|
showFlash("Could not reach endpoint.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.rpcUrl = url;
|
await saveEndpoint("rpcUrl", url, net.id);
|
||||||
await saveState();
|
|
||||||
showFlash("Saved.");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("btn-save-blockscout").addEventListener("click", async () => {
|
$("btn-save-blockscout").addEventListener("click", async () => {
|
||||||
@@ -375,6 +404,7 @@ function init(_ctx) {
|
|||||||
showFlash("Please enter a Blockscout API URL.");
|
showFlash("Please enter a Blockscout API URL.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const net = shownNetwork;
|
||||||
showFlash("Testing endpoint...");
|
showFlash("Testing endpoint...");
|
||||||
try {
|
try {
|
||||||
const resp = await debugFetch(url + "/stats");
|
const resp = await debugFetch(url + "/stats");
|
||||||
@@ -389,9 +419,7 @@ function init(_ctx) {
|
|||||||
showFlash("Could not reach endpoint.");
|
showFlash("Could not reach endpoint.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.blockscoutUrl = url;
|
await saveEndpoint("blockscoutUrl", url, net.id);
|
||||||
await saveState();
|
|
||||||
showFlash("Saved.");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Each change is made inside the save, holding the lock. So
|
// Each change is made inside the save, holding the lock. So
|
||||||
|
|||||||
+78
-23
@@ -1240,9 +1240,10 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
let inputEstablished = false;
|
let inputEstablished = false;
|
||||||
// Whether the user pays the step that set the input side: a V2 or V3
|
// 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
|
// swap step with `payerIsUser` true, a V4 step the user pays some of
|
||||||
// its input currency (see decodeV4Swap()), or a WRAP_ETH, whose ETH
|
// its input currency (see paidByUser in the loop), or a WRAP_ETH,
|
||||||
// comes from the transaction's value. A step paid from the router
|
// whose ETH comes from the transaction's value. A step that pays an
|
||||||
// takes nothing from the sender.
|
// ERC-20 token from the router takes none of that token from the
|
||||||
|
// sender.
|
||||||
let inputPaidByUser = false;
|
let inputPaidByUser = false;
|
||||||
// The last PERMIT2_PERMIT this decoder read before a step set the
|
// The last PERMIT2_PERMIT this decoder read before a step set the
|
||||||
// input side, or null (see permitStands after the loop).
|
// input side, or null (see permitStands after the loop).
|
||||||
@@ -1338,7 +1339,9 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
// What the steps take from the sender beyond the amount of the step
|
// What the steps take from the sender beyond the amount of the step
|
||||||
// that sets the input side, as { token, amount }, in step order.
|
// that sets the input side, as { token, amount }, in step order.
|
||||||
// After the loop each joins the Amount line or gets lines of its own
|
// After the loop each joins the Amount line or gets lines of its own
|
||||||
// (see permitStands).
|
// (see permitStands). A take with `atMost` set may take less than
|
||||||
|
// `amount`: it never joins the Amount line, and its line reads
|
||||||
|
// "Up to" and the amount.
|
||||||
const userPaid = [];
|
const userPaid = [];
|
||||||
// A swap step the user pays for (`payerIsUser` true) takes `amount`
|
// A swap step the user pays for (`payerIsUser` true) takes `amount`
|
||||||
// of `token` from the sender. A V2 exact-in of ALREADY_PAID takes
|
// of `token` from the sender. A V2 exact-in of ALREADY_PAID takes
|
||||||
@@ -1815,6 +1818,41 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
} else if (command === "V4_SWAP") {
|
} else if (command === "V4_SWAP") {
|
||||||
const v4 = decodeV4Swap(inputs[i]);
|
const v4 = decodeV4Swap(inputs[i]);
|
||||||
const inputSetBefore = inputEstablished;
|
const inputSetBefore = inputEstablished;
|
||||||
|
// V4Router pays a SETTLE of ETH from the router's own
|
||||||
|
// ETH, whichever payer the SETTLE names. The router holds
|
||||||
|
// the transaction's value, and any ETH an earlier step
|
||||||
|
// left it (see heldByRouter). So the user also pays a
|
||||||
|
// SETTLE of ETH that names the router as payer. The user
|
||||||
|
// pays all of its amount when the router holds no other
|
||||||
|
// ETH, and up to its amount otherwise. CONTRACT_BALANCE
|
||||||
|
// pays all the router holds, an amount the calldata does
|
||||||
|
// not state.
|
||||||
|
const routerHeldEth = heldByRouter.has(
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
);
|
||||||
|
const ethFromRouter = (v4?.settledFromRouter ?? [])
|
||||||
|
.filter(
|
||||||
|
(s) =>
|
||||||
|
s.currency ===
|
||||||
|
"0x0000000000000000000000000000000000000000",
|
||||||
|
)
|
||||||
|
.map((s) => ({
|
||||||
|
currency: s.currency,
|
||||||
|
amount:
|
||||||
|
s.amount === CONTRACT_BALANCE ? null : s.amount,
|
||||||
|
}));
|
||||||
|
// What the user pays the step: what decodeV4Swap() says,
|
||||||
|
// and the ETH of each SETTLE from the router of a known
|
||||||
|
// amount when the router holds no other ETH.
|
||||||
|
const paidByUser = v4
|
||||||
|
? v4.paidByUser.concat(
|
||||||
|
routerHeldEth
|
||||||
|
? []
|
||||||
|
: ethFromRouter.filter((s) =>
|
||||||
|
present(s.amount),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: [];
|
||||||
if (v4) {
|
if (v4) {
|
||||||
// Each SETTLE paid from the router spends the amount
|
// Each SETTLE paid from the router spends the amount
|
||||||
// decodeV4Swap() says it pays.
|
// decodeV4Swap() says it pays.
|
||||||
@@ -1845,10 +1883,10 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
commandNames[i] += " (could not be decoded)";
|
commandNames[i] += " (could not be decoded)";
|
||||||
}
|
}
|
||||||
// The step's amount, if it sets the input side: what the
|
// The step's amount, if it sets the input side: what the
|
||||||
// user pays it of its input currency (see
|
// user pays it of its input currency, or, when the user
|
||||||
// decodeV4Swap()), or, when the user pays none of it,
|
// pays none of it, what its swap actions spend of it,
|
||||||
// what its swap actions spend of it, whoever pays that.
|
// whoever pays that.
|
||||||
const paidIn = v4?.paidByUser.find(
|
const paidIn = paidByUser.find(
|
||||||
(p) => p.currency === v4.tokenIn,
|
(p) => p.currency === v4.tokenIn,
|
||||||
);
|
);
|
||||||
const amountIn = paidIn ? paidIn.amount : v4?.amountIn;
|
const amountIn = paidIn ? paidIn.amount : v4?.amountIn;
|
||||||
@@ -1902,11 +1940,25 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
// router still runs it.
|
// router still runs it.
|
||||||
const setInputHere = inputEstablished && !inputSetBefore;
|
const setInputHere = inputEstablished && !inputSetBefore;
|
||||||
if (setInputHere) inputPaidByUser = paidIn !== undefined;
|
if (setInputHere) inputPaidByUser = paidIn !== undefined;
|
||||||
if (v4) {
|
for (const p of paidByUser) {
|
||||||
for (const p of v4.paidByUser) {
|
|
||||||
if (setInputHere && p === paidIn) continue;
|
if (setInputHere && p === paidIn) continue;
|
||||||
addUserPaid(p.currency, p.amount);
|
addUserPaid(p.currency, p.amount);
|
||||||
}
|
}
|
||||||
|
// A SETTLE of ETH from the router that `paidByUser` leaves
|
||||||
|
// out is a take of its own, even on the step that sets
|
||||||
|
// the input side. Either this decoder does not know its
|
||||||
|
// amount, or ETH an earlier step left in the router may
|
||||||
|
// pay part of that amount (see userPaid).
|
||||||
|
for (const p of ethFromRouter) {
|
||||||
|
if (!present(p.amount)) {
|
||||||
|
addUserPaid(p.currency, null);
|
||||||
|
} else if (routerHeldEth) {
|
||||||
|
userPaid.push({
|
||||||
|
token: p.currency,
|
||||||
|
amount: p.amount,
|
||||||
|
atMost: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!v4 || v4.settleUnread) {
|
if (!v4 || v4.settleUnread) {
|
||||||
spentUnread();
|
spentUnread();
|
||||||
@@ -2013,10 +2065,10 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
// The total is what the steps take of Token In: the amount of the
|
// The total is what the steps take of Token In: the amount of the
|
||||||
// step that set the input side, with each later take of that token
|
// step that set the input side, with each later take of that token
|
||||||
// added to it while both are quantities. A take that cannot be added,
|
// added to it while both are quantities. A take that cannot be added,
|
||||||
// being of another token or coming after an amount that is not a
|
// being of another token, coming after an amount that is not a
|
||||||
// quantity (a V4 open delta, ALREADY_PAID, or none stated), gets
|
// quantity (a V4 open delta, ALREADY_PAID, or none stated), or having
|
||||||
// lines of its own. One whose amount is not known also leaves the
|
// `atMost` set, gets lines of its own. One whose amount is not known
|
||||||
// total unknown, with no figure.
|
// also leaves the total unknown, with no figure.
|
||||||
//
|
//
|
||||||
// A PERMIT2_PERMIT names Token In only when its amount stands as the
|
// A PERMIT2_PERMIT names Token In only when its amount stands as the
|
||||||
// Amount figure in place of the total, which it does only in the
|
// Amount figure in place of the total, which it does only in the
|
||||||
@@ -2060,14 +2112,14 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
let total = null;
|
let total = null;
|
||||||
// The takes from the sender that `total` adds up, each a quantity, as
|
// 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
|
// { 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
|
// its own (see below). The amount of the step that set the input side
|
||||||
// and is paid from the router counts in `total` but is not among them.
|
// counts in `total` whoever pays that step. That amount is among them
|
||||||
|
// only when the user pays the step (see inputPaidByUser).
|
||||||
const inTotal = [];
|
const inTotal = [];
|
||||||
// Whether the step that set the input side counts as a take from the
|
// 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
|
// 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
|
// whoever pays it. Stating none, it counts only when the user pays it
|
||||||
// some of its input token: paid from the router, it takes nothing
|
// some of its input token.
|
||||||
// from the sender.
|
|
||||||
const hasFirstTake =
|
const hasFirstTake =
|
||||||
inputEstablished && (present(inputAmount) || inputPaidByUser);
|
inputEstablished && (present(inputAmount) || inputPaidByUser);
|
||||||
// The take of the step that set the input side, when the total
|
// The take of the step that set the input side, when the total
|
||||||
@@ -2093,7 +2145,8 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
if (
|
if (
|
||||||
ofTokenIn &&
|
ofTokenIn &&
|
||||||
typeof total === "bigint" &&
|
typeof total === "bigint" &&
|
||||||
typeof t.amount === "bigint"
|
typeof t.amount === "bigint" &&
|
||||||
|
!t.atMost
|
||||||
) {
|
) {
|
||||||
total += t.amount;
|
total += t.amount;
|
||||||
inTotal.push(t);
|
inTotal.push(t);
|
||||||
@@ -2196,8 +2249,9 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
// V2's already-paid zero, neither of which is a quantity at all (see
|
// V2's already-paid zero, neither of which is a quantity at all (see
|
||||||
// OPEN_DELTA and ALREADY_PAID), and an unbounded permit. Those two
|
// OPEN_DELTA and ALREADY_PAID), and an unbounded permit. Those two
|
||||||
// tests come first — the sentinels are not bigints and cannot be
|
// tests come first — the sentinels are not bigints and cannot be
|
||||||
// compared with one.
|
// compared with one. `atMost` marks an amount that is only the most a
|
||||||
const spentText = (amount, info) => {
|
// take may be (see userPaid).
|
||||||
|
const spentText = (amount, info, atMost) => {
|
||||||
if (amount === OPEN_DELTA) {
|
if (amount === OPEN_DELTA) {
|
||||||
return { raw: OPEN_DELTA_AMOUNT, display: OPEN_DELTA_AMOUNT };
|
return { raw: OPEN_DELTA_AMOUNT, display: OPEN_DELTA_AMOUNT };
|
||||||
}
|
}
|
||||||
@@ -2210,7 +2264,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
if (amount >= MAX_UINT160) {
|
if (amount >= MAX_UINT160) {
|
||||||
return { raw: "Unlimited", display: "Unlimited" };
|
return { raw: "Unlimited", display: "Unlimited" };
|
||||||
}
|
}
|
||||||
if (hasV2OrV3ExactOut) {
|
if (hasV2OrV3ExactOut || atMost) {
|
||||||
// A V2 or V3 exact-out swap spends at most this figure,
|
// A V2 or V3 exact-out swap spends at most this figure,
|
||||||
// whichever steps gave it (an amountInMax, the WRAP_ETH of a
|
// whichever steps gave it (an amountInMax, the WRAP_ETH of a
|
||||||
// swap paid in ETH, a permit, or several steps' total), so it
|
// swap paid in ETH, a permit, or several steps' total), so it
|
||||||
@@ -2270,7 +2324,8 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
details.push({
|
details.push({
|
||||||
label: "Moved from the sender",
|
label: "Moved from the sender",
|
||||||
value: present(s.amount)
|
value: present(s.amount)
|
||||||
? spentText(s.amount, tokenInfo(s.token, sources)).display
|
? spentText(s.amount, tokenInfo(s.token, sources), s.atMost)
|
||||||
|
.display
|
||||||
: UNDECODED_CURRENCY,
|
: UNDECODED_CURRENCY,
|
||||||
});
|
});
|
||||||
if (present(s.token)) {
|
if (present(s.token)) {
|
||||||
|
|||||||
@@ -253,6 +253,271 @@ test("a switch back in Settings after a follow whose write failed is stored", as
|
|||||||
expect(told.at(-1).chainId).toBe(NETWORKS.mainnet.chainId);
|
expect(told.at(-1).chainId).toBe(NETWORKS.mainnet.chainId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The user saves an endpoint URL in Settings on Ethereum Mainnet. Before the
|
||||||
|
// URL is stored, the background saves a switch to Sepolia. Another write holds
|
||||||
|
// the lock, so the popup's follow of that switch and the URL's save both wait
|
||||||
|
// for the lock. Either may take it first. The URL is stored for neither
|
||||||
|
// network. The flash message says that the network changed.
|
||||||
|
test.each([
|
||||||
|
{ button: "btn-save-rpc", field: "settings-rpc", first: "follow" },
|
||||||
|
{ button: "btn-save-rpc", field: "settings-rpc", first: "save" },
|
||||||
|
{
|
||||||
|
button: "btn-save-blockscout",
|
||||||
|
field: "settings-blockscout",
|
||||||
|
first: "follow",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
button: "btn-save-blockscout",
|
||||||
|
field: "settings-blockscout",
|
||||||
|
first: "save",
|
||||||
|
},
|
||||||
|
])(
|
||||||
|
"$button saves nothing when the network changes before the URL is stored ($first first)",
|
||||||
|
async ({ button, field, first }) => {
|
||||||
|
const page = await bootOnAddress();
|
||||||
|
await page.click("btn-settings");
|
||||||
|
// This answer passes both endpoint checks. The RPC check reads
|
||||||
|
// Ethereum Mainnet's chain id from it. The Blockscout check reads `ok`.
|
||||||
|
globalThis.fetch.mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ result: NETWORKS.mainnet.chainId }),
|
||||||
|
});
|
||||||
|
const url = "https://own-node.example.invalid";
|
||||||
|
|
||||||
|
let releaseLock;
|
||||||
|
const lockHeld = navigator.locks.request(
|
||||||
|
"autistmask",
|
||||||
|
() =>
|
||||||
|
new Promise((resolve) => {
|
||||||
|
releaseLock = resolve;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
// The click handler runs until its save waits for the lock.
|
||||||
|
const tapSave = async () => {
|
||||||
|
page.node(field).value = url;
|
||||||
|
const saving = page.node(button).listeners.click.map((fn) => fn());
|
||||||
|
await page.settle();
|
||||||
|
return saving;
|
||||||
|
};
|
||||||
|
let saving;
|
||||||
|
if (first === "save") saving = await tapSave();
|
||||||
|
await backgroundSwitch(page, "sepolia");
|
||||||
|
if (first === "follow") saving = await tapSave();
|
||||||
|
releaseLock();
|
||||||
|
await lockHeld;
|
||||||
|
await Promise.all(saving);
|
||||||
|
await page.settle();
|
||||||
|
|
||||||
|
const { state } = require("../src/shared/state");
|
||||||
|
expect(state.networkId).toBe("sepolia");
|
||||||
|
expect(JSON.stringify(page.storage.read("autistmask"))).not.toContain(
|
||||||
|
url,
|
||||||
|
);
|
||||||
|
expect(page.text("flash-msg")).toBe(
|
||||||
|
"The URL was not saved because the network changed.",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// The popup's follow of the background's switch to Sepolia has set `state` to
|
||||||
|
// Sepolia. The follow's write has not returned yet, so Settings still shows
|
||||||
|
// Ethereum Mainnet. The user taps "Save" there. The URL is for Ethereum
|
||||||
|
// Mainnet, so the save stores the URL for neither network.
|
||||||
|
test.each([
|
||||||
|
{ button: "btn-save-rpc", field: "settings-rpc" },
|
||||||
|
{ button: "btn-save-blockscout", field: "settings-blockscout" },
|
||||||
|
])(
|
||||||
|
"$button saves nothing when tapped while the follow's write waits",
|
||||||
|
async ({ button, field }) => {
|
||||||
|
const page = await bootOnAddress();
|
||||||
|
await page.click("btn-settings");
|
||||||
|
// This answer passes both endpoint checks on Ethereum Mainnet.
|
||||||
|
globalThis.fetch.mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ result: NETWORKS.mainnet.chainId }),
|
||||||
|
});
|
||||||
|
const url = "https://own-node.example.invalid";
|
||||||
|
|
||||||
|
const { set } = page.storage.local;
|
||||||
|
const write = set.getMockImplementation();
|
||||||
|
let releaseWrite;
|
||||||
|
const writeHeld = new Promise((resolve) => {
|
||||||
|
releaseWrite = resolve;
|
||||||
|
});
|
||||||
|
// The background's write lands; the next, the follow's, waits.
|
||||||
|
set.mockImplementationOnce(write).mockImplementationOnce(
|
||||||
|
async (items) => {
|
||||||
|
await writeHeld;
|
||||||
|
await write(items);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await backgroundSwitch(page, "sepolia");
|
||||||
|
const { state } = require("../src/shared/state");
|
||||||
|
expect(state.networkId).toBe("sepolia");
|
||||||
|
expect(page.value("settings-network")).toBe("mainnet");
|
||||||
|
|
||||||
|
page.node(field).value = url;
|
||||||
|
const saving = page.node(button).listeners.click.map((fn) => fn());
|
||||||
|
await page.settle();
|
||||||
|
releaseWrite();
|
||||||
|
await Promise.all(saving);
|
||||||
|
await page.settle();
|
||||||
|
|
||||||
|
expect(JSON.stringify(page.storage.read("autistmask"))).not.toContain(
|
||||||
|
url,
|
||||||
|
);
|
||||||
|
expect(page.text("flash-msg")).toBe(
|
||||||
|
"The URL was not saved because the network changed.",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// The user taps the RPC "Save" on Ethereum Mainnet. While the check waits for
|
||||||
|
// the node's answer, the popup follows the background's switch to Sepolia. The
|
||||||
|
// node answers with Sepolia's chain id. So the check refuses the node for
|
||||||
|
// Ethereum Mainnet, and nothing is stored.
|
||||||
|
test("the RPC check compares the answer with the network at the tap", async () => {
|
||||||
|
const page = await bootOnAddress();
|
||||||
|
await page.click("btn-settings");
|
||||||
|
let answer;
|
||||||
|
globalThis.fetch.mockReturnValue(
|
||||||
|
new Promise((resolve) => {
|
||||||
|
answer = resolve;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const url = "https://sepolia-node.example.invalid";
|
||||||
|
|
||||||
|
page.node("settings-rpc").value = url;
|
||||||
|
const saving = page.node("btn-save-rpc").listeners.click.map((fn) => fn());
|
||||||
|
await page.settle();
|
||||||
|
await backgroundSwitch(page, "sepolia");
|
||||||
|
const { state } = require("../src/shared/state");
|
||||||
|
expect(state.networkId).toBe("sepolia");
|
||||||
|
answer({ json: async () => ({ result: NETWORKS.sepolia.chainId }) });
|
||||||
|
await Promise.all(saving);
|
||||||
|
await page.settle();
|
||||||
|
|
||||||
|
expect(JSON.stringify(page.storage.read("autistmask"))).not.toContain(url);
|
||||||
|
expect(page.text("flash-msg")).toBe(
|
||||||
|
"Wrong network: expected Ethereum Mainnet.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// The user taps the Blockscout "Save" on Ethereum Mainnet. While the check
|
||||||
|
// waits for Blockscout's answer, the popup follows the background's switch to
|
||||||
|
// Sepolia. The URL is for Ethereum Mainnet, so nothing is stored.
|
||||||
|
test("the Blockscout save is for the network at the tap", async () => {
|
||||||
|
const page = await bootOnAddress();
|
||||||
|
await page.click("btn-settings");
|
||||||
|
let answer;
|
||||||
|
globalThis.fetch.mockReturnValue(
|
||||||
|
new Promise((resolve) => {
|
||||||
|
answer = resolve;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const url = "https://own-explorer.example.invalid/api/v2";
|
||||||
|
|
||||||
|
page.node("settings-blockscout").value = url;
|
||||||
|
const saving = page
|
||||||
|
.node("btn-save-blockscout")
|
||||||
|
.listeners.click.map((fn) => fn());
|
||||||
|
await page.settle();
|
||||||
|
await backgroundSwitch(page, "sepolia");
|
||||||
|
expect(page.value("settings-network")).toBe("sepolia");
|
||||||
|
answer({ ok: true });
|
||||||
|
await Promise.all(saving);
|
||||||
|
await page.settle();
|
||||||
|
|
||||||
|
expect(JSON.stringify(page.storage.read("autistmask"))).not.toContain(url);
|
||||||
|
expect(page.text("flash-msg")).toBe(
|
||||||
|
"The URL was not saved because the network changed.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Settings is open when the network changes to Sepolia. The popup follows the
|
||||||
|
// background's switch, or the user picks Sepolia in the network selector. Each
|
||||||
|
// "Save" after the switch stores its URL for Sepolia.
|
||||||
|
test.each([
|
||||||
|
["a follow", (page) => backgroundSwitch(page, "sepolia")],
|
||||||
|
[
|
||||||
|
"the network selector",
|
||||||
|
async (page) => {
|
||||||
|
const select = page.node("settings-network");
|
||||||
|
select.value = "sepolia";
|
||||||
|
for (const fn of select.listeners.change) await fn();
|
||||||
|
await page.settle();
|
||||||
|
},
|
||||||
|
],
|
||||||
|
])(
|
||||||
|
"after a switch to Sepolia by %s, Settings saves each URL for Sepolia",
|
||||||
|
async (_how, switchToSepolia) => {
|
||||||
|
const page = await bootOnAddress();
|
||||||
|
await page.click("btn-settings");
|
||||||
|
await switchToSepolia(page);
|
||||||
|
// This answer passes both endpoint checks on Sepolia. The RPC check
|
||||||
|
// reads Sepolia's chain id from it. The Blockscout check reads `ok`.
|
||||||
|
globalThis.fetch.mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ result: NETWORKS.sepolia.chainId }),
|
||||||
|
});
|
||||||
|
const rpcUrl = "https://own-node.example.invalid";
|
||||||
|
const blockscoutUrl = "https://own-explorer.example.invalid/api/v2";
|
||||||
|
|
||||||
|
page.node("settings-rpc").value = rpcUrl;
|
||||||
|
await page.click("btn-save-rpc");
|
||||||
|
expect(page.text("flash-msg")).toBe("Saved.");
|
||||||
|
page.node("settings-blockscout").value = blockscoutUrl;
|
||||||
|
await page.click("btn-save-blockscout");
|
||||||
|
expect(page.text("flash-msg")).toBe("Saved.");
|
||||||
|
|
||||||
|
const stored = page.storage.read("autistmask");
|
||||||
|
expect(stored.networkId).toBe("sepolia");
|
||||||
|
expect(stored.rpcUrl).toBe(rpcUrl);
|
||||||
|
expect(stored.blockscoutUrl).toBe(blockscoutUrl);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// The user picks Sepolia in Settings, but the switch's write fails. The page is
|
||||||
|
// then on Sepolia, while Settings was last drawn for Ethereum Mainnet. A "Save"
|
||||||
|
// after the failed switch stores nothing for either network.
|
||||||
|
test.each([
|
||||||
|
{ button: "btn-save-rpc", field: "settings-rpc" },
|
||||||
|
{ button: "btn-save-blockscout", field: "settings-blockscout" },
|
||||||
|
])(
|
||||||
|
"$button saves nothing after a switch in Settings whose write failed",
|
||||||
|
async ({ button, field }) => {
|
||||||
|
const page = await bootOnAddress();
|
||||||
|
await page.click("btn-settings");
|
||||||
|
page.storage.local.set.mockRejectedValueOnce(
|
||||||
|
new Error("quota exceeded"),
|
||||||
|
);
|
||||||
|
const select = page.node("settings-network");
|
||||||
|
select.value = "sepolia";
|
||||||
|
for (const fn of select.listeners.change) {
|
||||||
|
await expect(fn()).rejects.toThrow("quota exceeded");
|
||||||
|
}
|
||||||
|
await page.settle();
|
||||||
|
const { state } = require("../src/shared/state");
|
||||||
|
expect(state.networkId).toBe("sepolia");
|
||||||
|
// This answer passes both endpoint checks on Ethereum Mainnet.
|
||||||
|
globalThis.fetch.mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ result: NETWORKS.mainnet.chainId }),
|
||||||
|
});
|
||||||
|
const url = "https://own-node.example.invalid";
|
||||||
|
|
||||||
|
page.node(field).value = url;
|
||||||
|
await page.click(button);
|
||||||
|
|
||||||
|
expect(JSON.stringify(page.storage.read("autistmask"))).not.toContain(
|
||||||
|
url,
|
||||||
|
);
|
||||||
|
expect(page.text("flash-msg")).toBe(
|
||||||
|
"The URL was not saved because the network changed.",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Such as one a newer build wrote, which this build cannot read. Nothing reads
|
// Such as one a newer build wrote, which this build cannot read. Nothing reads
|
||||||
// or writes the stored record for it: the popup's next save finds it, as
|
// or writes the stored record for it: the popup's next save finds it, as
|
||||||
// before.
|
// before.
|
||||||
|
|||||||
@@ -3439,6 +3439,129 @@ describe("uniswap decoder", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://git.eeqj.de/sneak/AutistMask/issues/682 — V4 pays a SETTLE
|
||||||
|
// of ETH from the router's own ETH, whichever payer the SETTLE names,
|
||||||
|
// and the router holds the transaction's value. On next at 36b2002 a
|
||||||
|
// SETTLE of 1 ETH that names the router as payer gave no ETH line.
|
||||||
|
describe("a V4 SETTLE of ETH that names the router as payer", () => {
|
||||||
|
const ONE_ETH = 1000000000000000000n;
|
||||||
|
// A V4 swap of `amount` of ETH for USDC. The SETTLE names the
|
||||||
|
// router as payer.
|
||||||
|
const v4EthFromRouter = (amount) =>
|
||||||
|
encodeV4Swap(
|
||||||
|
new Uint8Array([
|
||||||
|
V4_SWAP_EXACT_IN_SINGLE_ID,
|
||||||
|
V4_SETTLE_ID,
|
||||||
|
V4_TAKE_ALL_ID,
|
||||||
|
]),
|
||||||
|
[
|
||||||
|
encodeV4ExactInSingle(ZERO_ADDR, USDC_ADDR, amount, 1n),
|
||||||
|
settle(ZERO_ADDR, amount, false),
|
||||||
|
encodeV4TakeAll(USDC_ADDR, 1n),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
test("after a V3 exact-in of 600 USDT, shows the 1 ETH moved from the sender", () => {
|
||||||
|
const result = decodeSteps(
|
||||||
|
[0x00, 0x10],
|
||||||
|
[V3_600, v4EthFromRouter(ONE_ETH)],
|
||||||
|
);
|
||||||
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
|
["Amount", "600.0000 USDT"],
|
||||||
|
["Moved from the sender", "1.0000 ETH"],
|
||||||
|
["Token moved", "ETH"],
|
||||||
|
["Moved to", "The swap step that spends it"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// The UNWRAP_WETH leaves ETH in the router. The SETTLE may spend
|
||||||
|
// that ETH before the transaction's value.
|
||||||
|
test("after an UNWRAP_WETH into the router, shows at most 1 ETH moved from the sender", () => {
|
||||||
|
const result = decodeSteps(
|
||||||
|
[0x00, 0x0c, 0x10],
|
||||||
|
[
|
||||||
|
encodeV3SwapExactIn(ROUTER_ADDR, USDT_600, 1n, [
|
||||||
|
USDT_ADDR,
|
||||||
|
WETH_ADDR,
|
||||||
|
]),
|
||||||
|
encodeWrapEth(ROUTER_ADDR, 0n), // UNWRAP_WETH, same encoding
|
||||||
|
v4EthFromRouter(ONE_ETH),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
|
["Amount", "600.0000 USDT"],
|
||||||
|
["Moved from the sender", "Up to 1.0000 ETH"],
|
||||||
|
["Token moved", "ETH"],
|
||||||
|
["Moved to", "The swap step that spends it"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("after a WRAP_ETH of 0.5 ETH, adds the SETTLE's 0.5 ETH to the Amount line", () => {
|
||||||
|
const result = decodeSteps(
|
||||||
|
[0x0b, 0x10],
|
||||||
|
[
|
||||||
|
encodeWrapEth(ROUTER_ADDR, ONE_ETH / 2n),
|
||||||
|
v4EthFromRouter(ONE_ETH / 2n),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
|
["Amount", "1.0000 ETH"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// The WRAP_ETH sets Token In to ETH, and the UNWRAP_WETH leaves
|
||||||
|
// ETH in the router. The SETTLE may spend that ETH before the
|
||||||
|
// transaction's value, so its 1 ETH never joins the Amount line.
|
||||||
|
test("after a WRAP_ETH and an UNWRAP_WETH into the router, keeps the Amount line and shows at most 1 ETH moved from the sender", () => {
|
||||||
|
const result = decodeSteps(
|
||||||
|
[0x0b, 0x0c, 0x10],
|
||||||
|
[
|
||||||
|
encodeWrapEth(ROUTER_ADDR, ONE_ETH / 2n),
|
||||||
|
encodeWrapEth(ROUTER_ADDR, 0n), // UNWRAP_WETH, same encoding
|
||||||
|
v4EthFromRouter(ONE_ETH),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
|
["Amount", "0.5000 ETH"],
|
||||||
|
["Moved from the sender", "Up to 1.0000 ETH"],
|
||||||
|
["Token moved", "ETH"],
|
||||||
|
["Moved to", "The swap step that spends it"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// A SETTLE of CONTRACT_BALANCE pays all the router holds, an
|
||||||
|
// amount the calldata does not state.
|
||||||
|
test("of CONTRACT_BALANCE, on the step that sets the input side, shows an unknown amount moved from the sender", () => {
|
||||||
|
const result = decodeSteps(
|
||||||
|
[0x10],
|
||||||
|
[
|
||||||
|
encodeV4Swap(
|
||||||
|
new Uint8Array([
|
||||||
|
V4_SWAP_EXACT_IN_SINGLE_ID,
|
||||||
|
V4_SETTLE_ID,
|
||||||
|
V4_TAKE_ALL_ID,
|
||||||
|
]),
|
||||||
|
[
|
||||||
|
encodeV4ExactInSingle(
|
||||||
|
ZERO_ADDR,
|
||||||
|
USDC_ADDR,
|
||||||
|
ONE_ETH,
|
||||||
|
1n,
|
||||||
|
),
|
||||||
|
settle(ZERO_ADDR, 2n ** 255n, false), // CONTRACT_BALANCE
|
||||||
|
encodeV4TakeAll(USDC_ADDR, 1n),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
|
["Moved from the sender", UNDECODED],
|
||||||
|
["Token moved", "ETH"],
|
||||||
|
["Moved to", "The swap step that spends it"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://git.eeqj.de/sneak/AutistMask/issues/359 — the output half, in
|
// https://git.eeqj.de/sneak/AutistMask/issues/359 — the output half, in
|
||||||
|
|||||||
@@ -1661,9 +1661,18 @@ describe("any token left in the router is not received", () => {
|
|||||||
),
|
),
|
||||||
min: "1990.0000 USDC",
|
min: "1990.0000 USDC",
|
||||||
},
|
},
|
||||||
{
|
])("$kind reads as a swap paid to the user", ({ data, min }) => {
|
||||||
kind: "a swap paying WETH to the router, an UNWRAP_WETH into the router, then a V4 swap settling all the ETH from the router",
|
const result = decode(data);
|
||||||
data: execute(
|
expect(labels(result)).toEqual(PAID_TO_USER);
|
||||||
|
expect(detail(result, "Min. received").value).toBe(min);
|
||||||
|
});
|
||||||
|
|
||||||
|
// https://git.eeqj.de/sneak/AutistMask/issues/682 — the SETTLE spends all
|
||||||
|
// the router's ETH, the transaction's value included, so the sender pays
|
||||||
|
// an amount the calldata does not state.
|
||||||
|
test("a swap paying WETH to the router, an UNWRAP_WETH into the router, then a V4 swap settling all the ETH from the router reads as a swap paid to the user", () => {
|
||||||
|
const result = decode(
|
||||||
|
execute(
|
||||||
swapToWeth(ADDRESS_THIS),
|
swapToWeth(ADDRESS_THIS),
|
||||||
unwrapWeth(ADDRESS_THIS),
|
unwrapWeth(ADDRESS_THIS),
|
||||||
v4Swap(
|
v4Swap(
|
||||||
@@ -1672,12 +1681,23 @@ describe("any token left in the router is not received", () => {
|
|||||||
takeAll(USDC),
|
takeAll(USDC),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
min: "1990.0000 USDC",
|
);
|
||||||
},
|
expect(labels(result)).toEqual([
|
||||||
])("$kind reads as a swap paid to the user", ({ data, min }) => {
|
"Protocol",
|
||||||
const result = decode(data);
|
"Token In",
|
||||||
expect(labels(result)).toEqual(PAID_TO_USER);
|
"Amount",
|
||||||
expect(detail(result, "Min. received").value).toBe(min);
|
"Moved from the sender",
|
||||||
|
"Token moved",
|
||||||
|
"Moved to",
|
||||||
|
"Token Out",
|
||||||
|
"Min. received",
|
||||||
|
"Steps",
|
||||||
|
"Deadline",
|
||||||
|
]);
|
||||||
|
expect(detail(result, "Moved from the sender").value).toBe(
|
||||||
|
"Unknown (could not be decoded)",
|
||||||
|
);
|
||||||
|
expect(detail(result, "Min. received").value).toBe("1990.0000 USDC");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user