Skip to content

Instantly share code, notes, and snippets.

@bartubozkurt
Created February 2, 2023 11:15
Show Gist options
  • Save bartubozkurt/d16da6b292e739bb916406620a12c4a8 to your computer and use it in GitHub Desktop.
Save bartubozkurt/d16da6b292e739bb916406620a12c4a8 to your computer and use it in GitHub Desktop.
address bob = 0x237C8Aea434dE4784d23d145069c6D0Bef629A19 // Give Me Ether
IERC20 token;
uint N = 3 ether
uint M = 1 ether
/* 👩 Alice, 👨 Bob */
/* Bad */
/* FROM | 🕛 | ORDER   | BLOCK | GAS */
/* 👩 | 0s | 1 | N | 100,000 */ token.approve(bob,N);
/* 👩 | 20s | 2 | N+1 | 100,000 */ token.approve(bob,M);
/* 👨 | 21s | 3 | N+1 | 50,000 */ token.transferFrom(bob,N); // Failed
/* 👨 | 60s | 4 | N+2 | 50,000 */ token.transferFrom(bob,M);
/* Better */
/* FROM | 🕛 | ORDER   | BLOCK | GAS */
/* 👩 | 0s | 1 | N | 100,000 */ token.approve(bob,N);
/* 👩 | 20s | 3 | N+1 | 100,000 */ token.approve(bob,M);
/* 👨 | 21s | 2 | N+1 | 500,000 */ token.transferFrom(bob,N); // Sucess
/* 👨 | 60s | 4 | N+2 | 50,000 */ token.transferFrom(bob,M);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment