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

latest changes #9

Merged
merged 1 commit into from
Feb 28, 2024
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
42 changes: 42 additions & 0 deletions packages/foundry/contracts/XocPin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract XocPin is ERC721URIStorage, Ownable {
using SafeERC20 for IERC20;

address public constant XOCOLATL = 0xa411c9Aa00E020e4f88Bc19996d29c5B7ADB4ACf;
address public constant TREASURY = 0x707C5E55277A0C2f598f191b269c9e773516052A;
uint256 public constant MINT_PRICE = 100e18;

uint256 public nextTokenId = 1;

string public baseTokenURI;

constructor(string memory _tokenURI) ERC721("XocPin", "XOCP") Ownable(TREASURY) {
baseTokenURI = _tokenURI;
}

function mint(address to) external {
IERC20(XOCOLATL).safeTransferFrom(msg.sender, TREASURY, MINT_PRICE);
_mint(to, nextTokenId);
nextTokenId++;
}

function setTokenURI(uint256 tokenId, string memory _tokenURI) external onlyOwner {
_setTokenURI(tokenId, _tokenURI);
}

function setBaseTokenURI(string memory _baseTokenURI) external onlyOwner {
baseTokenURI = _baseTokenURI;
emit BatchMetadataUpdate(1, nextTokenId - 1);
}

function _baseURI() internal view override returns (string memory) {
return baseTokenURI;
}
}
20 changes: 0 additions & 20 deletions packages/foundry/contracts/XocoLoco.sol

This file was deleted.

9 changes: 2 additions & 7 deletions packages/foundry/contracts/YourContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ contract YourContract {
mapping(address => uint256) public userGreetingCounter;

// Events: a way to emit log statements from smart contract that can be listened to by external parties
event GreetingChange(
address indexed greetingSetter,
string newGreeting,
bool premium,
uint256 value
);
event GreetingChange(address indexed greetingSetter, string newGreeting, bool premium, uint256 value);

// Constructor: Called once on contract deployment
// Check packages/foundry/deploy/Deploy.s.sol
Expand Down Expand Up @@ -73,7 +68,7 @@ contract YourContract {
* The function can only be called by the owner of the contract as defined by the isOwner modifier
*/
function withdraw() public isOwner {
(bool success, ) = owner.call{value: address(this).balance}("");
(bool success,) = owner.call{value: address(this).balance}("");
require(success, "Failed to send Ether");
}

Expand Down
3 changes: 3 additions & 0 deletions packages/foundry/deployments/137.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"networkName": "Polygon"
}
3 changes: 3 additions & 0 deletions packages/foundry/deployments/31337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"networkName": "default_network"
}
2 changes: 1 addition & 1 deletion packages/foundry/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[profile.default]
solc = "0.8.19"
solc = "0.8.20"
src = 'contracts'
out = 'out'
libs = ['lib']
Expand Down
13 changes: 4 additions & 9 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "../contracts/XocPin.sol";
import "./DeployHelpers.s.sol";

contract DeployScript is ScaffoldETHDeploy {
Expand All @@ -15,15 +15,10 @@ contract DeployScript is ScaffoldETHDeploy {
);
}
vm.startBroadcast(deployerPrivateKey);
YourContract yourContract = new YourContract(
vm.addr(deployerPrivateKey)
);
console.logString(
string.concat(
"YourContract deployed at: ",
vm.toString(address(yourContract))
)
XocPin xocpin = new XocPin(
"https://ipfs.io/ipfs/QmRhakrLp8fzdMp4HDUm3ocFJ51bsBdZXjpZadPh7gYg4P?filename=Familia%20Tier%203.png"
);
console.logString(string.concat("XocPin deployed at: ", vm.toString(address(xocpin))));
vm.stopBroadcast();

/**
Expand Down
11 changes: 2 additions & 9 deletions packages/foundry/script/DeployHelpers.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ contract ScaffoldETHDeploy is Script {
string path;
Deployment[] public deployments;

function setupLocalhostEnv()
internal
returns (uint256 localhostPrivateKey)
{
function setupLocalhostEnv() internal returns (uint256 localhostPrivateKey) {
if (block.chainid == 31337) {
root = vm.projectRoot();
path = string.concat(root, "/localhost.json");
Expand All @@ -44,11 +41,7 @@ contract ScaffoldETHDeploy is Script {
uint256 len = deployments.length;

for (uint256 i = 0; i < len; i++) {
vm.serializeString(
jsonWrite,
vm.toString(deployments[i].addr),
deployments[i].name
);
vm.serializeString(jsonWrite, vm.toString(deployments[i].addr), deployments[i].name);
}

string memory chainName;
Expand Down
99 changes: 22 additions & 77 deletions packages/foundry/script/VerifyAll.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ contract VerifyAll is Script {

function run() external {
string memory root = vm.projectRoot();
string memory path = string.concat(
root,
"/broadcast/Deploy.s.sol/",
vm.toString(block.chainid),
"/run-latest.json"
);
string memory path =
string.concat(root, "/broadcast/Deploy.s.sol/", vm.toString(block.chainid), "/run-latest.json");
string memory content = vm.readFile(path);

while (this.nextTransaction(content)) {
Expand All @@ -41,52 +37,24 @@ contract VerifyAll is Script {
}

function _verifyIfContractDeployment(string memory content) internal {
string memory txType = abi.decode(
vm.parseJson(
content,
searchStr(currTransactionIdx, "transactionType")
),
(string)
);
string memory txType =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "transactionType")), (string));
if (keccak256(bytes(txType)) == keccak256(bytes("CREATE"))) {
_verifyContract(content);
}
}

function _verifyContract(string memory content) internal {
string memory contractName = abi.decode(
vm.parseJson(
content,
searchStr(currTransactionIdx, "contractName")
),
(string)
);
address contractAddr = abi.decode(
vm.parseJson(
content,
searchStr(currTransactionIdx, "contractAddress")
),
(address)
);
bytes memory deployedBytecode = abi.decode(
vm.parseJson(
content,
searchStr(currTransactionIdx, "transaction.data")
),
(bytes)
);
bytes memory compiledBytecode = abi.decode(
vm.parseJson(
_getCompiledBytecode(contractName),
".bytecode.object"
),
(bytes)
);
bytes memory constructorArgs = BytesLib.slice(
deployedBytecode,
compiledBytecode.length,
deployedBytecode.length - compiledBytecode.length
);
string memory contractName =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "contractName")), (string));
address contractAddr =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "contractAddress")), (address));
bytes memory deployedBytecode =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "transaction.data")), (bytes));
bytes memory compiledBytecode =
abi.decode(vm.parseJson(_getCompiledBytecode(contractName), ".bytecode.object"), (bytes));
bytes memory constructorArgs =
BytesLib.slice(deployedBytecode, compiledBytecode.length, deployedBytecode.length - compiledBytecode.length);

string[] memory inputs = new string[](9);
inputs[0] = "forge";
Expand All @@ -102,56 +70,33 @@ contract VerifyAll is Script {
FfiResult memory f = tempVm(address(vm)).tryFfi(inputs);

if (f.stderr.length != 0) {
console.logString(
string.concat(
"Submitting verification for contract: ",
vm.toString(contractAddr)
)
);
console.logString(string.concat("Submitting verification for contract: ", vm.toString(contractAddr)));
console.logString(string(f.stderr));
} else {
console.logString(string(f.stdout));
}
return;
}

function nextTransaction(
string memory content
) external view returns (bool) {
function nextTransaction(string memory content) external view returns (bool) {
try this.getTransactionFromRaw(content, currTransactionIdx) {
return true;
} catch {
return false;
}
}

function _getCompiledBytecode(
string memory contractName
) internal view returns (string memory compiledBytecode) {
function _getCompiledBytecode(string memory contractName) internal view returns (string memory compiledBytecode) {
string memory root = vm.projectRoot();
string memory path = string.concat(
root,
"/out/",
contractName,
".sol/",
contractName,
".json"
);
string memory path = string.concat(root, "/out/", contractName, ".sol/", contractName, ".json");
compiledBytecode = vm.readFile(path);
}

function getTransactionFromRaw(
string memory content,
uint96 idx
) external pure {
function getTransactionFromRaw(string memory content, uint96 idx) external pure {
abi.decode(vm.parseJson(content, searchStr(idx, "hash")), (bytes32));
}

function searchStr(
uint96 idx,
string memory searchKey
) internal pure returns (string memory) {
return
string.concat(".transactions[", vm.toString(idx), "].", searchKey);
function searchStr(uint96 idx, string memory searchKey) internal pure returns (string memory) {
return string.concat(".transactions[", vm.toString(idx), "].", searchKey);
}
}
}
10 changes: 2 additions & 8 deletions packages/foundry/test/YourContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ contract YourContractTest is Test {
}

function testMessageOnDeployment() public view {
require(
keccak256(bytes(yourContract.greeting())) ==
keccak256("Building Unstoppable Apps!!!")
);
require(keccak256(bytes(yourContract.greeting())) == keccak256("Building Unstoppable Apps!!!"));
}

function testSetNewMessage() public {
yourContract.setGreeting("Learn Scaffold-ETH 2! :)");
require(
keccak256(bytes(yourContract.greeting())) ==
keccak256("Learn Scaffold-ETH 2! :)")
);
require(keccak256(bytes(yourContract.greeting())) == keccak256("Learn Scaffold-ETH 2! :)"));
}
}
5 changes: 5 additions & 0 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export const menuLinks: HeaderMenuLink[] = [
href: "/defi",
icon: <BanknotesIcon className="h-4 w-4" />,
},
{
label: "Streams",
href: "/streams",
icon: <BanknotesIcon className="h-4 w-4" />,
},
];

export const HeaderMenuLinks = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/components/index/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const Hero = () => {
Since this is the 1st version, you need to click approve to approve 0.02 wETH that will be used to
buy XOC on Uniswap.
</p>
<h3>Token In: ~0.02 Wrapped Ether</h3>
<h3>Token In: ~0.002 Wrapped Ether</h3>
<h3>Token Out: 100 XOC</h3>
<div className=" mt-12">
<button className="btn mr-5" onClick={() => approve()}>
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/components/index/protocolNumbers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ProtocolNumbers = () => {
const { data: quotedAmountOut } = useContractRead({
address: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",
abi: quoterABI,
functionName: "quoteExactInput",
functionName: "quoteExactOutput",
args: [path, BigInt(1e18).toString()],
watch: true,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/components/streams/SuperTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SupertokensComponent: React.FC = () => {
address: "0xa411c9Aa00E020e4f88Bc19996d29c5B7ADB4ACf",
abi: xocolatlABI,
functionName: "approve",
args: ["0x2c6dAB164dB072a8E2163fc5A547F229dc185C9f", approveAmount],
args: ["0x36d9a149895d905D117C38F3090f4344B76Ec9F4", approveAmount],
});

const { write: upgrade } = useContractWrite({
Expand Down
Loading