-
Notifications
You must be signed in to change notification settings - Fork 59
fix agentTokenV3._autoswap() uniswap invalidTo error #154
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,6 @@ artifacts/ | |
| deployments | ||
| fireblocks_secret.key | ||
| .cursor/ | ||
| env* | ||
| env* | ||
|
|
||
| lib/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; | ||
| import "../pool/IUniswapV2Router02.sol"; | ||
|
|
||
| interface IAgentTaxForToken { | ||
| function depositTax(address tokenAddress, uint256 amount) external; | ||
| } | ||
|
|
||
| /** | ||
| * @title TaxAccountingAdapter | ||
| * @notice Pulls agent tokens from the AgentToken contract, swaps to `pairToken` via Uniswap V2 | ||
| * with `to = address(this)` so the pool's INVALID_TO check is satisfied (recipient is not token0/token1). | ||
| * Deposits the *actual* `pairToken` received into AgentTax via `depositTax(agentToken, received)`. | ||
| */ | ||
| contract TaxAccountingAdapter is ReentrancyGuard { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| event TaxSwapDeposited( | ||
| address indexed agentToken, | ||
| address indexed taxRecipient, | ||
| uint256 received | ||
| ); | ||
|
|
||
| /** | ||
| * @param agentToken Agent ERC20 (same as `path[0]`). Tokens are pulled from `agentToken` address (the contract's own balance). | ||
| * @param pairToken Quote token (e.g. VIRTUAL). | ||
| * @param taxRecipient AgentTax (or compatible) — `depositTax` pulls `pairToken` from this adapter. | ||
| * @param router Uniswap V2 compatible router. | ||
| * @param swapAmount Amount of agent token to pull and pass to the router (fee-on-transfer: actual balance used after pull). | ||
| * @param deadline Router deadline. | ||
| */ | ||
| function swapTaxAndDeposit( | ||
| address agentToken, | ||
| address pairToken, | ||
| address taxRecipient, | ||
| address router, | ||
| uint256 swapAmount, | ||
| uint256 deadline | ||
| ) external nonReentrant { | ||
| require(swapAmount > 0, "TaxAccountingAdapter: zero swap"); | ||
| require(deadline >= block.timestamp, "TaxAccountingAdapter: expired"); | ||
| require( | ||
| taxRecipient != address(0) && router != address(0), | ||
| "TaxAccountingAdapter: zero address" | ||
| ); | ||
|
|
||
| IERC20(agentToken).safeTransferFrom(agentToken, address(this), swapAmount); | ||
|
|
||
| uint256 swapIn = IERC20(agentToken).balanceOf(address(this)); | ||
| require(swapIn > 0, "TaxAccountingAdapter: zero in"); | ||
|
|
||
| IERC20(agentToken).forceApprove(router, swapIn); | ||
|
|
||
| address[] memory path = new address[](2); | ||
| path[0] = agentToken; | ||
| path[1] = pairToken; | ||
|
|
||
| uint256 balBefore = IERC20(pairToken).balanceOf(address(this)); | ||
|
|
||
| IUniswapV2Router02(router).swapExactTokensForTokensSupportingFeeOnTransferTokens( | ||
| swapIn, | ||
| 0, | ||
| path, | ||
| address(this), | ||
| deadline | ||
| ); | ||
|
|
||
| uint256 received = IERC20(pairToken).balanceOf(address(this)) - balBefore; | ||
| if (received > 0) { | ||
| IERC20(pairToken).forceApprove(taxRecipient, received); | ||
| IAgentTaxForToken(taxRecipient).depositTax(agentToken, received); | ||
| emit TaxSwapDeposited(agentToken, taxRecipient, received); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.