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

"jj" CLI #7

Merged
merged 5 commits into from
May 22, 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
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
.PHONY: clean generate regenerate test docs redocs forge

build: forge bin/trailmix
build: forge bin/trailmix bin/jj

rebuild: clean generate build

bin/trailmix:
mkdir -p bin
go build -o bin/trailmix ./trailmix

bin/jj: bindings/JackpotJunction/JackpotJunction.go
mkdir -p bin
go build -o bin/jj ./jj

bindings/JackpotJunction/JackpotJunction.go: forge
mkdir -p bindings/JackpotJunction
seer evm generate --package JackpotJunction --output bindings/JackpotJunction/JackpotJunction.go --foundry out/JackpotJunction.sol/JackpotJunction.json --cli --struct JackpotJunction

test:
forge test -vvv

clean:
rm -rf out/*
rm stamper/TokenboundERC20.go stamper/BindingERC721.go
rm -rf out/* bin/*

forge:
forge build
Expand Down
5,056 changes: 5,056 additions & 0 deletions bindings/JackpotJunction/JackpotJunction.go

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,39 @@ module github.com/moonstream-to/degen-trail

go 1.21.5

require github.com/spf13/cobra v1.8.0
require (
github.com/ethereum/go-ethereum v1.14.3
github.com/spf13/cobra v1.8.0
golang.org/x/term v0.20.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/tools v0.20.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
191 changes: 191 additions & 0 deletions go.sum

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions jj/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package main

import (
"os"

"github.com/spf13/cobra"

"github.com/moonstream-to/degen-trail/bindings/JackpotJunction"
"github.com/moonstream-to/degen-trail/jj/version"
)

func CreateRootCommand() *cobra.Command {
// rootCmd represents the base command when called without any subcommands
rootCmd := &cobra.Command{
Use: "jj",
Short: "jj: The Jackpot Junction CLI",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

completionCmd := CreateCompletionCommand(rootCmd)
versionCmd := CreateVersionCommand()
contractCmd := JackpotJunction.CreateJackpotJunctionCommand()
contractCmd.Use = "contract"
rootCmd.AddCommand(completionCmd, versionCmd, contractCmd)

// By default, cobra Command objects write to stderr. We have to forcibly set them to output to
// stdout.
rootCmd.SetOut(os.Stdout)

return rootCmd
}

func CreateCompletionCommand(rootCmd *cobra.Command) *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generate shell completion scripts for jj",
Long: `Generate shell completion scripts for jj.

The command for each shell will print a completion script to stdout. You can source this script to get
completions in your current shell session. You can add this script to the completion directory for your
shell to get completions for all future sessions.

For example, to activate bash completions in your current shell:
$ . <(jj completion bash)

To add jj completions for all bash sessions:
$ jj completion bash > /etc/bash_completion.d/jj_completions`,
}

bashCompletionCmd := &cobra.Command{
Use: "bash",
Short: "bash completions for jj",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(cmd.OutOrStdout())
},
}

zshCompletionCmd := &cobra.Command{
Use: "zsh",
Short: "zsh completions for jj",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenZshCompletion(cmd.OutOrStdout())
},
}

fishCompletionCmd := &cobra.Command{
Use: "fish",
Short: "fish completions for jj",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenFishCompletion(cmd.OutOrStdout(), true)
},
}

powershellCompletionCmd := &cobra.Command{
Use: "powershell",
Short: "powershell completions for jj",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenPowerShellCompletion(cmd.OutOrStdout())
},
}

completionCmd.AddCommand(bashCompletionCmd, zshCompletionCmd, fishCompletionCmd, powershellCompletionCmd)

return completionCmd
}

func CreateVersionCommand() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version of jj that you are currently using",
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(version.JJVersion)
},
}

return versionCmd
}
15 changes: 15 additions & 0 deletions jj/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"
"os"
)

func main() {
command := CreateRootCommand()
err := command.Execute()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
3 changes: 3 additions & 0 deletions jj/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var JJVersion string = "0.0.1"
10 changes: 9 additions & 1 deletion src/JackpotJunction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract JackpotJunction is ERC1155, ReentrancyGuard {
}
}

receive() external payable {}

function genera(uint256 poolID) public pure returns (uint256 itemType, uint256 terrainType, uint256 tier) {
tier = poolID / 28;
terrainType = (poolID % 28) / 4;
Expand Down Expand Up @@ -114,7 +116,7 @@ contract JackpotJunction is ERC1155, ReentrancyGuard {
emit Roll(msg.sender);
}

function _entropy(address degenerate) internal virtual view returns (uint256) {
function _entropy(address degenerate) internal view virtual returns (uint256) {
return uint256(blockhash(LastRollBlock[degenerate]));
}

Expand Down Expand Up @@ -169,9 +171,14 @@ contract JackpotJunction is ERC1155, ReentrancyGuard {
emit Award(msg.sender, _outcome, value);
}

function _clearRoll() internal {
LastRollBlock[msg.sender] = 0;
}

function accept() external nonReentrant returns (uint256, uint256, uint256) {
(uint256 entropy, uint256 _outcome, uint256 value) = outcome(msg.sender, false);
_award(_outcome, value);
_clearRoll();
return (entropy, _outcome, value);
}

Expand Down Expand Up @@ -241,6 +248,7 @@ contract JackpotJunction is ERC1155, ReentrancyGuard {

(uint256 entropy, uint256 _outcome, uint256 value) = outcome(msg.sender, bonus);
_award(_outcome, value);
_clearRoll();
return (entropy, _outcome, value);
}

Expand Down
40 changes: 22 additions & 18 deletions src/nfts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,36 @@ contract DegenTrailNFT is ERC721, ERC721Enumerable, PlayerBandit {
stats[tokenID] = DegenTrailStats(kind, speed, fight, repair, recovery);
}

function _metadataName(uint256 tokenID, DegenTrailStats memory stat) internal virtual view returns (string memory) {
function _metadataName(uint256 tokenID, DegenTrailStats memory stat)
internal
view
virtual
returns (string memory)
{
return string(abi.encodePacked(tokenID));
}

function _metadataKind(uint256 kind) internal virtual view returns (string memory) {
function _metadataKind(uint256 kind) internal view virtual returns (string memory) {
return string(abi.encodePacked(kind));
}

function metadataJSONBytes(uint256 tokenID) public view returns (bytes memory) {
DegenTrailStats memory stat = stats[tokenID];
return
abi.encodePacked(
'{"name": "',
_metadataName(tokenID, stat),
'","kind":',
_metadataKind(stat.kind),
',"speed":',
stat.speed,
',"fight":',
stat.fight,
',"repair":',
stat.repair,
',"recovery":',
stat.recovery,
"}"
);
return abi.encodePacked(
'{"name": "',
_metadataName(tokenID, stat),
'","kind":',
_metadataKind(stat.kind),
',"speed":',
stat.speed,
',"fight":',
stat.fight,
',"repair":',
stat.repair,
',"recovery":',
stat.recovery,
"}"
);
}

function metadataJSON(uint256 tokenID) external view returns (string memory) {
Expand Down
Loading
Loading