Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize Batch Swap Tutorial #1056

Merged
merged 1 commit into from
Jan 6, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="termynal" data-termynal>
<span data-ty="input">npx hardhat compile</span>
<span data-ty>Compiled 6 Solidity files successfully (evm target: paris).</span>
<span data-ty="input"> </span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="termynal" data-termynal>
<span data-ty="input">npx hardhat run --network moonbase scripts/deploy.js</span>
<span data-ty>SimpleDex deployed to 0xA467EB6C80D4Dae4c45C5d31Ead341c34cdD1b5e</span>
<span data-ty="input"> </span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="termynal" data-termynal>
<span data-ty="input">npx hardhat run --network moonbase scripts/swap.js</span>
<span data-ty>Approve and swap demo tokens for dev tokens: 0x56cd9777f10e76b5b98a9ff57f7db44c5c847a615955202148e56aa6221168d6</span>
<span data-ty>Dex 0x462830eC426E617D8DB8e3c36de34d85A7b60a2 has a balance of: 500.2 DTOKS</span>
<span data-ty>Account Oxf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac has a balance of: 499.8 DTOKs</span>
<span data-ty="input"> </span>
</div>
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions tutorials/eth-api/batch-approve-swap.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ To compile the contracts, we'll go ahead and run the following Hardhat command:
npx hardhat compile
```

![Compile contracts](/images/tutorials/eth-api/batch-approve-swap/batch-1.webp)
--8<-- 'code/tutorials/eth-api/batch-approve-swap/terminal/compile.md'

After compilation, an `artifacts` directory is created: it holds the bytecode and metadata of the contract, which are `.json` files. It’s a good idea to add this directory to the `.gitignore` file.

Expand Down Expand Up @@ -190,7 +190,7 @@ npx hardhat run --network moonbase scripts/deploy.js
!!! note
If you want to run the script in a standalone fashion using `node <script>`, you'll need to require the Hardhat Runtime Environment explicitly using `const hre = require('hardhat');` in the `deploy.js` file.

![Deploy contracts](/images/tutorials/eth-api/batch-approve-swap/batch-2.webp)
--8<-- 'code/tutorials/eth-api/batch-approve-swap/terminal/deploy.md'

After a few seconds, the contract will be deployed, and you should see the address in the terminal. We'll need to use the address in the following sections to interact with the contract, so make sure you save it.

Expand Down Expand Up @@ -337,7 +337,7 @@ In the terminal, you should see the following items:
- The DEX's DTOK balance after the batch approval and swap
- Your account's DTOK balance after the batch approval and swap

![Swap tokens](/images/tutorials/eth-api/batch-approve-swap/batch-3.webp)
--8<-- 'code/tutorials/eth-api/batch-approve-swap/terminal/swap.md'

And that's it! You've successfully used the batch precompile contract to batch an approval and swap into a single transaction, allowing for the approval amount to be the exact swap amount.

Expand Down