This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
tests: add univ3 svg generation test (#1292)
<!--- Please provide a general summary of your changes in the title above --> <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: 1d Adds Mock UniswapV3 contracts that allow querying a dynamically generated on-chain SVG representing a position. The values are mocked, and due to some issues, the base64 encoding of the image crashes with a stack underflow error (tbd). However, the encoding of the rest takes ~27M steps Also added a way to do library linking in the python kakarot scripts ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves #<Issue number> ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - - - <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1292) <!-- Reviewable:end -->
Showing
18 changed files
with
1,082 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
[submodule "solidity_contracts/lib/forge-std"] | ||
path = solidity_contracts/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
branch = v1.3.0 | ||
[submodule "solidity_contracts/lib/kakarot-lib"] | ||
path = solidity_contracts/lib/kakarot-lib | ||
url = https://github.com/kkrt-labs/kakarot-lib | ||
[submodule "solidity_contracts/lib/v3-core"] | ||
path = solidity_contracts/lib/v3-core | ||
url = https://github.com/Uniswap/v3-core | ||
[submodule "solidity_contracts/lib/openzeppelin"] | ||
path = solidity_contracts/lib/openzeppelin | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "solidity_contracts/lib/base64-sol"] | ||
path = solidity_contracts/lib/base64-sol | ||
url = https://github.com/Brechtpd/base64 |
This file contains 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 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 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
Submodule base64-sol
added at
dcbf85
Submodule openzeppelin
added at
8e0296
This file contains 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 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,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity =0.7.6; | ||
|
||
library HexStrings { | ||
bytes16 internal constant ALPHABET = "0123456789abcdef"; | ||
|
||
/// @notice Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. | ||
/// @dev Credit to Open Zeppelin under MIT license https://github.com/OpenZeppelin/openzeppelin-contracts/blob/243adff49ce1700e0ecb99fe522fb16cff1d1ddc/contracts/utils/Strings.sol#L55 | ||
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { | ||
bytes memory buffer = new bytes(2 * length + 2); | ||
buffer[0] = "0"; | ||
buffer[1] = "x"; | ||
for (uint256 i = 2 * length + 1; i > 1; --i) { | ||
buffer[i] = ALPHABET[value & 0xf]; | ||
value >>= 4; | ||
} | ||
require(value == 0, "Strings: hex length insufficient"); | ||
return string(buffer); | ||
} | ||
|
||
function toHexStringNoPrefix(uint256 value, uint256 length) internal pure returns (string memory) { | ||
bytes memory buffer = new bytes(2 * length); | ||
for (uint256 i = buffer.length; i > 0; i--) { | ||
buffer[i - 1] = ALPHABET[value & 0xf]; | ||
value >>= 4; | ||
} | ||
return string(buffer); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,38 @@ | ||
pragma solidity >=0.7.0; | ||
pragma abicoder v2; | ||
|
||
import "openzeppelin/token/ERC721/ERC721.sol"; | ||
import "./NFTDescriptor.sol"; | ||
|
||
contract UniswapV3NFTManager is ERC721 { | ||
constructor() ERC721("UniswapV3 NFT Positions", "UNIV3") {} | ||
|
||
function tokenURI(uint256 tokenId) public view override returns (string memory) { | ||
return _mockTokenUri(tokenId); | ||
} | ||
|
||
function tokenURIExternal(uint256 tokenId) external returns (string memory) { | ||
return _mockTokenUri(tokenId); | ||
} | ||
|
||
function _mockTokenUri(uint256 tokenId) internal view returns (string memory) { | ||
NFTDescriptor.ConstructTokenURIParams memory params = NFTDescriptor.ConstructTokenURIParams({ | ||
tokenId: tokenId, | ||
quoteTokenAddress: address(0xabcdef), | ||
baseTokenAddress: address(0x123456), | ||
quoteTokenSymbol: "ETH", | ||
baseTokenSymbol: "USDC", | ||
quoteTokenDecimals: 18, | ||
baseTokenDecimals: 6, | ||
flipRatio: false, | ||
tickLower: -887272, | ||
tickUpper: 887272, | ||
tickCurrent: 387272, | ||
tickSpacing: 1000, | ||
fee: 3000, | ||
poolAddress: address(0xc0de) | ||
}); | ||
|
||
return NFTDescriptor.constructTokenURI(params); | ||
} | ||
} |
This file contains 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 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 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,20 @@ | ||
import pytest | ||
import pytest_asyncio | ||
|
||
from kakarot_scripts.utils.kakarot import deploy | ||
|
||
|
||
@pytest_asyncio.fixture(scope="module") | ||
async def univ3_position(owner): | ||
return await deploy( | ||
"UniswapV3", | ||
"UniswapV3NFTManager", | ||
caller_eoa=owner.starknet_contract, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio(scope="session") | ||
@pytest.mark.xfail(reason="Rendering the SVG takes too many steps") | ||
class TestUniswapV3Rendering: | ||
async def test_should_render_position(self, univ3_position): | ||
await univ3_position.tokenURIExternal(1) |
This file contains 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 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 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