Skip to content

Commit

Permalink
Merge pull request #7 from muhammedshahinshapottayil/Rainmaker
Browse files Browse the repository at this point in the history
Rainmaker
  • Loading branch information
muhammedshahinshapottayil authored Jul 31, 2024
2 parents d560016 + 4635803 commit a299df8
Show file tree
Hide file tree
Showing 17 changed files with 1,119 additions and 882 deletions.
60 changes: 49 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# Optimistic SVG NFTs
## A Project of the Encode Expert Solidity Bootcamp

![208145278-3d7783d3-de17-4b55-95b6-99e40fbe8fcd](https://github.com/damianmarti/loogies/assets/466652/ee2b1f9c-e30c-485b-862b-faaaaf95296b)

This repo shows how to set up an SVG NFT contract so that other NFTs can use it in their SVG code. This leads to an easy composition of SVG NFTs. More information at [ERC-4883: Composable SVG NFT](https://eips.ethereum.org/EIPS/eip-4883)

Take a look at `SVGNFT.sol`. It describes an SVG NFT that is defined by three parameters: color, chubbiness, and mouthLength randomly generated at mint.

It exposes a function:

```function renderTokenById(uint256 id) public view returns (string memory)```

It returns the relevant SVG that can be embedded in other SVG code for rendering.

<h4 align="center">
<a href="https://optimistic.loogies.io">Website</a>
</h4>


## Bootcamp topics utilized:

- gas optimization
- assembly
- proxy pattern
- advanced tooling (Foundry)
- implementing Scaffold-ETH 2 (partner workshop)

## Team Members (group 3, Discord handles):

- `lostDecade`
- `Muhammed Shahinsha Pottayil`
- `yassin7254`
- `Rainmaker`

Built using Scaffold-ETH 2

# 🏗 Scaffold-ETH 2

<h4 align="center">
Expand All @@ -7,7 +44,7 @@

🧪 An open-source, up-to-date toolkit for building decentralized applications (dapps) on the Ethereum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts.

⚙️ Built using NextJS, RainbowKit, Foundry, Wagmi, Viem, and Typescript.
⚙️ Built using NextJS, RainbowKit, foundry, Wagmi, Viem, and Typescript.

-**Contract Hot Reload**: Your frontend auto-adapts to your smart contract as you edit it.
- 🪝 **[Custom hooks](https://docs.scaffoldeth.io/hooks/)**: Collection of React hooks wrapper around [wagmi](https://wagmi.sh/) to simplify interactions with smart contracts with typescript autocompletion.
Expand All @@ -29,11 +66,12 @@ Before you begin, you need to install the following tools:

To get started with Scaffold-ETH 2, follow the steps below:

1. Install dependencies if it was skipped in CLI:
1. Clone this repo & install dependencies

```
cd my-dapp-example
yarn install
git clone https://github.com/scaffold-eth/scaffold-eth-2.git
cd scaffold-eth-2
yarn
```

2. Run a local network in the first terminal:
Expand All @@ -42,15 +80,15 @@ yarn install
yarn chain
```

This command starts a local Ethereum network using Foundry. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in `packages/foundry/foundry.toml`.
This command starts a local Ethereum network using foundry. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in `foundry.toml`.

3. On a second terminal, deploy the test contract:
3. In a second terminal, deploy the test contract:

```
yarn deploy
```

This command deploys a test smart contract to the local network. The contract is located in `packages/foundry/contracts` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/foundry/script` to deploy the contract to the network. You can also customize the deploy script.
This command deploys a test smart contract to the local network. The contract is located in `packages/foundry/contracts` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/foundry/deploy` to deploy the contract to the network. You can also customize the deploy script.

4. On a third terminal, start your NextJS app:

Expand All @@ -60,12 +98,12 @@ yarn start

Visit your app on: `http://localhost:3000`. You can interact with your smart contract using the `Debug Contracts` page. You can tweak the app config in `packages/nextjs/scaffold.config.ts`.

Run smart contract test with `yarn foundry:test`
**What's next**:

- Edit your smart contract `YourContract.sol` in `packages/foundry/contracts`
- Edit your frontend homepage at `packages/nextjs/app/page.tsx`. For guidance on [routing](https://nextjs.org/docs/app/building-your-application/routing/defining-routes) and configuring [pages/layouts](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts) checkout the Next.js documentation.
- Edit your deployment scripts in `packages/foundry/script`

- Edit your deployment scripts in `packages/foundry/deploy`
- Edit your smart contract test in: `packages/foundry/test`. To run test use `yarn foundry:test`

## Documentation

Expand All @@ -77,4 +115,4 @@ To know more about its features, check out our [website](https://scaffoldeth.io)

We welcome contributions to Scaffold-ETH 2!

Please see [CONTRIBUTING.MD](https://github.com/scaffold-eth/scaffold-eth-2/blob/main/CONTRIBUTING.md) for more information and guidelines for contributing to Scaffold-ETH 2.
Please see [CONTRIBUTING.MD](https://github.com/scaffold-eth/scaffold-eth-2/blob/main/CONTRIBUTING.md) for more information and guidelines for contributing to Scaffold-ETH 2.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "se-2",
"name": "optimistic_svg_nfts",
"version": "0.0.1",
"private": true,
"workspaces": {
"packages": [
"packages/*"
Expand Down Expand Up @@ -34,8 +33,8 @@
"verify": "yarn workspace @se-2/foundry verify"
},
"devDependencies": {
"husky": "~8.0.3",
"lint-staged": "~13.2.2"
"husky": "9.1.4",
"lint-staged": "15.2.7"
},
"packageManager": "yarn@3.2.3",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/foundry/contracts/Calculator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
pragma solidity 0.8.26;

import "@openzeppelin/contracts/proxy/utils/Initializable.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/foundry/contracts/CalculatorV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
pragma solidity 0.8.26;

import "@openzeppelin/contracts/proxy/utils/Initializable.sol";

Expand Down
47 changes: 22 additions & 25 deletions packages/foundry/contracts/HexStrings.sol
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library HexStrings {
bytes16 private constant ALPHABET = "0123456789abcdef";

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";

assembly {
let pos := add(buffer, 34)
let end := add(pos, mul(length, 2))
let remaining := value
pragma solidity 0.8.26;

for {
library HexStrings {
bytes16 private constant ALPHABET = "0123456789abcdef";

} lt(pos, end) {
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";

} {
mstore8(sub(end, 1), byte(mod(remaining, 16), ALPHABET))
remaining := div(remaining, 16)
end := sub(end, 1)
}
}
assembly {
let pos := add(buffer, 34)
let end := add(pos, mul(length, 2))
let remaining := value

return string(buffer);
for { } lt(pos, end) { } {
mstore8(sub(end, 1), byte(mod(remaining, 16), ALPHABET))
remaining := div(remaining, 16)
end := sub(end, 1)
}
}

return string(buffer);
}
}
Loading

0 comments on commit a299df8

Please sign in to comment.