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

Feat/add local mint feature #22

Merged
merged 8 commits into from
Nov 30, 2023
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "apps/contracts/lib/openzeppelin-contracts-upgradeable"]
path = apps/contracts/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "apps/contracts/lib/ERC721A"]
path = apps/contracts/lib/ERC721A
url = https://github.com/chiru-labs/ERC721A
3 changes: 3 additions & 0 deletions apps/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ out/
!/broadcast
/broadcast/*/1337/
/broadcast/*/5/
/broadcast/*/84531
/broadcast/multi

/broadcast/**/dry-run/

deployments/1337
Expand Down
1 change: 1 addition & 0 deletions apps/contracts/deployments/5/LocalDistributor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0x104Ac7B3d7774BB726e8567415B9B8Dad46B451C"}
2 changes: 1 addition & 1 deletion apps/contracts/deployments/5/Map.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"0x39Bd51dF4995C9eC14a16c15e4D832B3dd42D339"}
{"address":"0x197aE2Bb1218F4B8a68993B21B71CE4179F06ce8"}
2 changes: 1 addition & 1 deletion apps/contracts/deployments/5/StateTile.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"address":"0x1837faFcbc3E53479E05bAd424a2d477cbc94836"}
{"address":"0x7Eb19f94888Bd09fF6405521eC74eb1156379a6C"}
1 change: 1 addition & 0 deletions apps/contracts/deployments/84531/AccountProxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0x55266d75D1a14E4572138116aF39863Ed6596E7F"}
1 change: 1 addition & 0 deletions apps/contracts/deployments/84531/ERC6551Registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0x000000006551c19487814612e58FE06813775758"}
1 change: 1 addition & 0 deletions apps/contracts/deployments/84531/LocalDistributor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0x18dedD852B675DA7a13C6bE6dB8d26Cda16569D3"}
1 change: 1 addition & 0 deletions apps/contracts/deployments/84531/Map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0xD4a574A343cC6b140916D7f9c3E00517D041a75D"}
1 change: 1 addition & 0 deletions apps/contracts/deployments/84531/StateTile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0x12f7FA1d560446f19D4f74c65412Fcd1dD41bDCc"}
2 changes: 2 additions & 0 deletions apps/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ fs_permissions = [

[etherscan]
goerli = { key = "${API_KEY_ETHERSCAN}" }
base_goerli = { key = "${API_KEY_BASESCAN}" }

[rpc_endpoints]
local = "http://localhost:8545"
goerli = "https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_GOERLI_API_KEY}"
base_goerli = "https://base-goerli.g.alchemy.com/v2/${ALCHEMY_GOERLI_API_KEY}"


# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions apps/contracts/lib/ERC721A
Submodule ERC721A added at 184359
2 changes: 1 addition & 1 deletion apps/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"test": "forge test",
"chain": "rm -rf ./data && docker-compose up",
"deploy:local": "forge compile && forge script MapScript -s 'deployMapLocal()' --broadcast",
"deploy:local": "forge compile --force && forge script MapScript -s 'deployMapLocal()' --broadcast",
"deploy:testnets": "forge script MapScript -s 'deployMapTestnets()' --broadcast --verify",
"build": "forge compile"
}
Expand Down
3 changes: 2 additions & 1 deletion apps/contracts/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ tokenbound/=lib/contracts/src/
multicall-authenticated/=lib/contracts/lib/multicall-authenticated/src
prb-test/=lib/prb-test/src/
solidity-stringutils/=lib/solidity-stringutils/
@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts
@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts
ERC721A/=lib/ERC721A/contracts/
3 changes: 2 additions & 1 deletion apps/contracts/script/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ contract BaseScript is Script {

enum DeployementChain {
Anvil,
Goerli
Goerli,
BaseGoerli
}
string internal constant TEST_MNEMONIC =
"test test test test test test test test test test test junk";
Expand Down
146 changes: 146 additions & 0 deletions apps/contracts/script/Map.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {RecordTileFactoryConfig} from "../src/RecordTileFactory.sol";
import {NoCheckVerifier} from "../src/verifiers/NoCheckVerifier.sol";
import {UUPSProxy} from "../src/UUPSProxy.sol";
import {StateBeacon} from "../src/StateBeacon.sol";
import {LocalDistributor, LocalTokenConfig, TokenConfig} from "../src/examples/LocalDistributor.sol";

contract MapScript is BaseScript {
DeployementChain[] internal _deploymentChains;

function setUp() public {
forks[DeployementChain.Anvil] = "local";
forks[DeployementChain.Goerli] = "goerli";
forks[DeployementChain.BaseGoerli] = "base_goerli";
}

function deployMapLocal() public setEnvDeploy(Cycle.Local) {
Expand All @@ -26,10 +28,20 @@ contract MapScript is BaseScript {

function deployMapTestnets() public setEnvDeploy(Cycle.Testnet) {
_deploymentChains.push(DeployementChain.Goerli);
_deploymentChains.push(DeployementChain.BaseGoerli);

_deployMap(_deploymentChains);
}

function deployLocalTokensTestnets(
address distributor
) public setEnvDeploy(Cycle.Testnet) {
_deploymentChains.push(DeployementChain.Goerli);
// _deploymentChains.push(DeployementChain.BaseGoerli);

_deployLocalTokens(_deploymentChains, LocalDistributor(distributor));
}

function _deployMap(
DeployementChain[] memory targetChains
) internal broadcastOn(targetChains) returns (Map map, address state) {
Expand Down Expand Up @@ -62,12 +74,146 @@ contract MapScript is BaseScript {
)
);

LocalDistributor distributor = new LocalDistributor(map);

state = map.createState(
address(verifier),
"ipfs://bafkreia4evyfxkoz3vek6m4ewuof6bkpjykgt4ff5prsku2vab2xq43724"
);

_saveImplementations(address(distributor), "LocalDistributor");
_saveImplementations(address(map), "Map");
_saveImplementations(state, "StateTile");
}

function _deployLocalTokens(
DeployementChain[] memory targetChains,
LocalDistributor distributor
) internal broadcastOn(targetChains) {
LocalTokenConfig[]
memory localTokenDistribution = new LocalTokenConfig[](7);

// localTokenDistribution[0] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Barcelona",
// "LCTBC",
// "ipfs://bafkreiaxjhdgbdg7mekbsd4wd6z4y3ux2tto5qnqqwgepqzkjvvt7jdxei"
// ),
// "sp3"
// );
// localTokenDistribution[1] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Cape Town",
// "LCTCT",
// "ipfs://bafkreifmcmsp6qhaohapi4em3bf5wbbd7nwgsw3lte4tv45zkxn5lnph5e"
// ),
// "k3v"
// );
// localTokenDistribution[2] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Edinburgh",
// "LCTED",
// "ipfs://bafkreicloqi5w3jxnfi3frat56gnzin3ozbvyib7uczlczhkm4g7zjtu4q"
// ),
// "gcvw"
// );
// localTokenDistribution[3] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Mexico City",
// "LCTMC",
// "ipfs://bafkreiawp5pskf6zezf265ijbc75dfuj7ajzyr2jz4egltn7gkrqiip5bu"
// ),
// "9g3"
// );
// localTokenDistribution[4] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Milan",
// "LCTMN",
// "ipfs://bafkreibp5ojhp7zqe6vkqiatkukvtahqah4tgy5nw5fthsiwatlqfdxmpq"
// ),
// "u0n"
// );
// localTokenDistribution[5] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Moscow",
// "LCTMS",
// "ipfs://bafkreif7ysl4izlga5vp3illmbvsuaz6db5p3y7wec3e26mwgplmldhj5e"
// ),
// "ucf"
// );
// localTokenDistribution[6] = LocalTokenConfig(
// TokenConfig(
// "Local Token: Mumbai",
// "LCTMB",
// "ipfs://bafkreietcuajxjcm2yh36vnzim3ifdk35pbv62qdvnpa73uzu5pp2ppw2y"
// ),
// "te7"
// );
// localTokenDistribution[7] = LocalTokenConfig(
// TokenConfig(
// "Local Token: New Delhi",
// "LCTND",
// "ipfs://bafkreigsktrnvathnvk27q47fsznywwdzikbzs76qdsbm7o6yrrs6jkwze"
// ),
// "ttnf"
// );
localTokenDistribution[0] = LocalTokenConfig(
TokenConfig(
"Local Token: San Fransisco",
"LCTSF",
"ipfs://bafkreicvq7caeijnspzwuvfrureqkcfbi6cugr7yts7ukijs3y4wq73oce"
),
"9q8y"
);
localTokenDistribution[1] = LocalTokenConfig(
TokenConfig(
"Local Token: Sao Paulo",
"LCTSP",
"ipfs://bafkreifpunciicszzg5l7r274w4xfxxwalncceysn7rbur4d6oa2e5aw5a"
),
"6gyc"
);
localTokenDistribution[2] = LocalTokenConfig(
TokenConfig(
"Local Token: Singapore",
"LCTSG",
"ipfs://bafkreielm6rofgn7vyopwrkscxqm7bqgopzr7yudfpytcjzgm6thizdn54"
),
"w21z"
);
localTokenDistribution[3] = LocalTokenConfig(
TokenConfig(
"Local Token: Sydney",
"LCTSY",
"ipfs://bafkreiflrfzf6xpumsxktqbwad3opygmpxxmafcnvocnbg5umaufkzxpru"
),
"r3gx"
);
localTokenDistribution[4] = LocalTokenConfig(
TokenConfig(
"Local Token: Titanic",
"LCTTN",
"ipfs://bafkreigun75442p3zdx7rxno3gwkmimkorxzmfo6rn6endyjp5rnalawda"
),
"dzkw"
);
localTokenDistribution[5] = LocalTokenConfig(
TokenConfig(
"Local Token: Tokyo",
"LCTTK",
"ipfs://bafkreib6dvmns2he6vtfb4ftqsicms4tmugls7ea6o4g7xuaymaxdi2rje"
),
"xn7"
);
localTokenDistribution[6] = LocalTokenConfig(
TokenConfig(
"Local Token: Tunis",
"LCTTK",
"ipfs://bafkreigllmtmt5see77ah7rij5rrgyuz6qin6o5mdysrs3h2g3rpztwb7i"
),
"snx"
);

distributor.distribute(localTokenDistribution);
}
}
16 changes: 10 additions & 6 deletions apps/contracts/src/Map.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ contract Map is
_stateBeacon = stateBeacon;
}

modifier onlyValidAccount(address account) {
if (tx.origin != msg.sender || account != msg.sender)
revert accountNotSender();
_;
}

function move(
address account,
address state,
Expand All @@ -73,6 +67,16 @@ contract Map is
StateTile(state).move(account, geohash, data);
}

function createRecord(address account, string memory geohash) external {
require(msg.sender == account, "Map: account not sender");
require(
GeohashLogic.isValidGeohash(geohash, _minPrecision, _maxPrecision),
"Map: invalid geohash"
);

_createRecord(account, geohash);
}

function createState(
address verifier,
string memory baseURI
Expand Down
47 changes: 47 additions & 0 deletions apps/contracts/src/examples/LocalDistributor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {Map} from "../Map.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {TokenConfig, LocalERC721} from "./LocalERC721.sol";

struct LocalTokenConfig {
TokenConfig config;
string geohash;
}

contract LocalDistributor is Ownable {
Map internal _map;

event LocalTokenDistribution(
string geohash,
address tokenAddress,
string tokenURI
);

constructor(Map map) {
_map = map;
}

function distribute(
LocalTokenConfig[] memory localTokenDistribution
) public onlyOwner {
for (uint256 i = 0; i < localTokenDistribution.length; i++) {
LocalTokenConfig memory localTokenConfig = localTokenDistribution[
i
];

LocalERC721 localERC721 = new LocalERC721(
localTokenConfig.config,
localTokenConfig.geohash,
_map
);

emit LocalTokenDistribution(
localTokenConfig.geohash,
address(localERC721),
localTokenConfig.config.uri
);
}
}
}
42 changes: 42 additions & 0 deletions apps/contracts/src/examples/LocalERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {Map} from "../Map.sol";
import {Localized} from "../extensions/Localized.sol";
import {ERC721A} from "ERC721A/ERC721A.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

struct TokenConfig {
string name;
string symbol;
string uri;
}

contract LocalERC721 is ERC721A, Localized, Ownable {
string public uri;

constructor(
TokenConfig memory config,
string memory geohash,
Map map
) Localized(map, geohash) ERC721A(config.name, config.symbol) {
uri = config.uri;
}

function mint(
Localized.LocalCaller memory caller
) public onlyLocalAccount(caller) {
_safeMint(caller.localAccount, 1);
}

/**
* @notice Allows the owner to set the drop URI.
*/
function setUri(string memory _tokenURI) public onlyOwner {
uri = _tokenURI;
}

function tokenURI(uint256) public view override returns (string memory) {
return uri;
}
}
Loading