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

Add "Quickstart" instructions to README #32

Open
zeuslawyer opened this issue Apr 29, 2022 · 7 comments
Open

Add "Quickstart" instructions to README #32

zeuslawyer opened this issue Apr 29, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@zeuslawyer
Copy link

In addition to Quickstart, may be useful to outline the project structure.

Happy to do this with a little help from you @aschlosberg .

@ARR4N
Copy link
Collaborator

ARR4N commented May 13, 2022

Thank you and yes please! I added a Getting Started to the primary README but would love some help with other parts you suggest. Feel free to send PRs (and I'll turn notifications back on so I don't miss them like I did with this Issue, sorry).

@caffeinum
Copy link

@aschlosberg should Getting started section also feature npm package?

I would also add sections about how to use some of the libraries. I am having trouble with effectively integrating PRNG and NextShuffler. I can add examples and READMEs if you help me to figure it out, etc: #47

@ARR4N
Copy link
Collaborator

ARR4N commented Jul 19, 2022

Thanks @caffeinum I'll reply directly to #47 re that usage. I'm having coffee with @zeuslawyer this week so will see where things stand with the Quickstart.

@ARR4N ARR4N added the enhancement New feature or request label Jul 19, 2022
@caffeinum
Copy link

caffeinum commented Jul 26, 2022

@aschlosberg

Is this the correct usage of PRNG.Source?

(P.S. Nevermind the predictability issues, the risk was calculated but man I am bad at math)

contract NextShufflerLazyInit is NextShuffler {
    using PRNG for PRNG.Source;

    uint256[2] private _nextShufflerSourceStore;

    bool private _isRandomnessSourceSet;

    constructor () NextShuffler(1337) {}

    function _setRandomnessSource(bytes32 seed) internal {
        require(
            !isRandomnessSourceSet(),
            "Can't change source after seed has been set"
        );

        PRNG.Source src = PRNG.newSource(seed);

        src.store(_nextShufflerSourceStore);

        _isRandomnessSourceSet = true;
    }

    function _load() internal view returns (PRNG.Source) {
        return PRNG.loadSource(_nextShufflerSourceStore);
    }

    function _store(PRNG.Source _src) internal {
        _src.store(_nextShufflerSourceStore);
    }
}

and then:

contract MetaverseBaseNFT is ERC1155, NextShufflerLazyInit {

    function mint() {
        // ...

        PRNG.Source rndSource = _load();

        for (uint256 i = 0; i < amount; i++) {
            tokenOffset = _next(rndSource);

            // token id is fetched from the random offset
            tokenId = _tokenOffset2TokenId(tokenOffset);

            _mint(to, tokenId, 1, "");
        }

        _store(rndSource);

       // ...
    }
}

https://github.com/buildship-dev/nft-contracts/blob/6a133c70e17297643da213f5bbf0e954aa224d86/contracts/MetaverseBaseNFT_ERC1155.sol#L449

@ARR4N
Copy link
Collaborator

ARR4N commented Nov 15, 2022

Sorry @caffeinum, I don't know how I missed these. I'm sure it's too late, but in general yes that's how it works although I still recommend not storing the value (I'm considering deprecating that anyway).

@caffeinum
Copy link

@aschlosberg it was late, yeah, we've released that already! https://etherscan.io/address/0xde95471123ce8bd81ad8e7ba553e019da110b654#code

it worked out nice, because of the low gas it was one of the only moments in history where you could have had random ERC1155 mint! But we still got a pushback from a community because the gas cost to mint was 500k+ per token

I needed to store the value to make sure I predictably generate all of IDs, without leaving any of them out

@ARR4N
Copy link
Collaborator

ARR4N commented Feb 28, 2023

I've set up phone notifications so I shouldn't miss tags again!

I'm glad it worked out well! We've also had issues with the high gas and @cxkoda has since implemented a MWC equivalent that's good for "fun" things that don't require a CSPRNG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants