-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🦨🍎 ↣ Attempting (and failing) to add support for Magic [#1]
- Loading branch information
1 parent
ab7b72c
commit 9356d8c
Showing
32 changed files
with
18,358 additions
and
2,426 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: test | ||
|
||
on: workflow_dispatch | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge build | ||
run: | | ||
forge --version | ||
forge build --sizes | ||
id: build | ||
|
||
- name: Run Forge tests | ||
run: | | ||
forge test -vvv | ||
id: test |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[submodule "DataVis ARVR"] | ||
path = DataVis ARVR | ||
url = https://github.com/Call-For-Code/UnityStarterKit | ||
[submodule "thirdweb-contracts/lib/forge-std"] | ||
path = thirdweb-contracts/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std.git | ||
[submodule "container/lib/forge-std"] | ||
path = container/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std.git |
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,53 @@ | ||
// SDPX-License-Identifier: MIT | ||
pragma solidity ^0.8.11; | ||
// Merge with `Spaceship.sol` -> this is just a slightly more advanced version for a test component on the frontend | ||
|
||
// Import thirdweb contracts | ||
import "@thirdweb-dev/contracts/drop/DropErc1155.sol"; // For the NFTs (include 721 later) | ||
import "@thirdweb-dev/contracts/token/TokenERC20.sol"; // ERC-20 contrac | ||
|
||
// OpenZeppelin Guards | ||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; | ||
|
||
contract Mining is ReentrancyGuard, ERC1155Holder { | ||
// Store edition drop & token contract [addresses] here | ||
DropERC1155 public immutable spaceshipNftCollection; // Jumping UFO game component (flying between points) | ||
TokenERC20 public immutable rewardsToken; | ||
|
||
// Set the rewards token and nft collection addresses | ||
constructor(DropERC1155 spaceshipContractAddress, TokenERC20 gemsContractAddress) { | ||
spaceshipNftCollection = spaceshipContractAddress; | ||
rewardsToken = gemsContractAddress; | ||
} | ||
|
||
// Mapping player address to their current tools/resources | ||
struct MapValue { | ||
bool isData; // True when the NFT is staked | ||
uint256 value; // TokenID that is being staked by the user | ||
} | ||
|
||
mapping(address => MapValue) public playerSpaceship; // Players have no spaceship by default - they need to stake one to use it. `tokenId` of the spaceship is the multiplier for the reward (i.e. more advanced ships will increase the reward) | ||
mapping(address => MapValue) public playerLastUpdate; // Map address to last time stake/withdrew/claim transaction. Default -> player has no `lastTime` -> no mapping | ||
|
||
// Stake functionality | ||
function stake(uint256 _tokenId) external nonReentrant { | ||
require(spaceshipNftCollection.balanceOf(msg.sender, _toeknId) >= 1, "You need at least 1 spaceship of correct type to stake"); | ||
|
||
if (playerSpaceship[msg.sender].isData) { // If user already has a spaceship, send it back to them | ||
|
||
} | ||
} | ||
|
||
// Calculate rewards the player is owed | ||
function calculateRewards(address _player) public view returns (uint256 _rewards) { // 20,000,000/block | block.timestamp & playerLastUpdate | ||
if (!playerLastUpdate[_player].isData || !playerSpaceship[_player].isData) { // If player has no spaceship and has never been paid out | ||
return 0; | ||
} | ||
|
||
uint256 timeDifference = block.timestamp - playerLastUpdate[_player].value; // Used to calculate the rewards owed to the player | ||
uint256 rewards = timeDifference * 10_000_000_000_000 * (playerSpaceship[_player].value + 1); // Equation/algo to calculate rewards owed based on tokenId | ||
|
||
return rewards; | ||
} | ||
} |
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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@thirdweb-dev/contracts/base/ERC1155LazyMint.sol"; | ||
|
||
contract Spaceship is ERC1155LazyMint { | ||
constructor( | ||
string memory _name, | ||
string memory _symbol | ||
) ERC1155LazyMint(_name, _symbol, msg.sender, 0) { } // 0 Royalty amount | ||
|
||
function burn( // Sort of like a crafting function -> https://github.com/Signal-K/sytizen/commit/39da03aec3e9bf14dd33125487f0cfe6ec58290d | ||
address _owner, // Burning gen 1 = gen 2. Then we can add "recipes" ^^ | ||
uint256 _tokenId, | ||
uint256 _amount | ||
) external override { | ||
address caller = msg.sender; | ||
require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved Caller"); | ||
require(balanceOf[_owner][_tokenId] >= _amount, "Not enough tokens owned"); | ||
|
||
_burn(_owner, _tokenId, _amount); | ||
|
||
if(_tokenId == 0) { // If base spaceship model | ||
_mint(_owner, 1, 1, ""); // id: 1 (2nd model), quantity: 1, address "" | ||
} | ||
} | ||
} |
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,21 @@ | ||
{ | ||
"name": "auth", | ||
"version": "1.0.0", | ||
"description": "Star Sailors webapp auth using Moralis/mm && Magic.link", | ||
"main": "index.js", | ||
"repository": "https://github.com/signal-k/sytizen", | ||
"author": "Liam Arbuckle, Signal Kinetics PTY LTD", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@magic-sdk/admin": "^1.4.1", | ||
"body-parser": "^1.20.1", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.0.3", | ||
"express": "^4.18.2", | ||
"react-moralis": "^1.4.2", | ||
"redux": "^4.2.0", | ||
"redux-logger": "^3.0.6", | ||
"redux-thunk": "^2.4.1", | ||
"stripe": "^10.15.0" | ||
} | ||
} |
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,94 @@ | ||
require("dotenv").config(); // enables loading .env vars | ||
const express = require("express"); | ||
const app = express(); | ||
const path = require("path"); | ||
const cors = require("cors"); | ||
const bodyParser = require("body-parser"); | ||
app.use(bodyParser.json()); | ||
|
||
// Import, then initiate Magic instance for server-side methods | ||
const { Magic } = require("@magic-sdk/admin"); | ||
const magic = new Magic(process.env.MAGIC_SECRET_KEY); | ||
|
||
// Import & initiate Stripe instance | ||
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY); | ||
|
||
// Allow requests from client-side | ||
app.use(cors({ origin: process.env.CLIENT_URL })); | ||
|
||
// Route to validate the user's DID token | ||
app.post("/login", async (req, res) => { | ||
try { | ||
const didToken = req.headers.authorization.substr(7); | ||
await magic.token.validate(didToken); | ||
res.status(200).json({ authenticated: true }); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}); | ||
|
||
// Add the user to your list of customers | ||
// Then create a PaymentIntent to track the customer's payment cycle | ||
app.post("/create-payment-intent", async (req, res) => { | ||
const { email } = req.body; | ||
|
||
const paymentIntent = await stripe.customers | ||
.create({ | ||
email, | ||
}) | ||
.then((customer) => | ||
stripe.paymentIntents | ||
.create({ | ||
amount: 50000, // Replace this constant with the price of your service | ||
currency: "usd", | ||
customer: customer.id, | ||
}) | ||
.catch((error) => console.log("error: ", error)) | ||
); | ||
|
||
res.send({ | ||
clientSecret: paymentIntent.client_secret, | ||
customer: paymentIntent.customer, | ||
}); | ||
}); | ||
|
||
// Update the customer's info to reflect that they've | ||
// paid for lifetime access to your Premium Content | ||
app.post("/update-customer", async (req, res) => { | ||
const { customerID } = req.body; | ||
|
||
const customer = await stripe.customers.update(customerID, { | ||
metadata: { lifetimeAccess: true }, | ||
}); | ||
|
||
res.send({ | ||
customer, | ||
}); | ||
}); | ||
|
||
// Collect the customer's information to help validate | ||
// that they've paid for lifetime access | ||
app.post("/validate-customer", async (req, res) => { | ||
const { email } = req.body; | ||
|
||
const customer = await stripe.customers.list({ | ||
limit: 1, | ||
email, | ||
}); | ||
|
||
res.send({ | ||
customer: customer.data, | ||
}); | ||
}); | ||
|
||
/* For heroku deployment */ | ||
if (process.env.NODE_ENV === "production") { | ||
app.use(express.static("client/build")); | ||
app.get("*", (req, res) => { | ||
res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); | ||
}); | ||
} | ||
|
||
const listener = app.listen(process.env.PORT || 8080, function () { | ||
console.log("Listening on port " + listener.address().port); | ||
}); |
Oops, something went wrong.