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

Multi VRGDA via Libraries & Structs #13

Closed
wants to merge 33 commits into from
Closed

Multi VRGDA via Libraries & Structs #13

wants to merge 33 commits into from

Conversation

saucepoint
Copy link

@saucepoint saucepoint commented Sep 6, 2022

Closes #12


Creation & usage of multiple VRGDAs occur via structs and libraries.

This offers wonderful ergonomics because the structs and libraries hide all of parameters & math that power the VRGDAs:

    using LinearVRGDALib for LinearVRGDAx;
    using LogisticVRGDALib for LogisticVRGDAx;

    // define 2 VRGDAs to price the resources
    LinearVRGDAx internal linearAuction = LinearVRGDALib.createLinearVRGDA(1e18, 0.2e18, 1e18);
    LogisticVRGDAx internal logAuction = LogisticVRGDALib.createLogisticVRGDA(1e18, 0.2e18, 1000e18, 1000e18);

    // purchase resources according to VRGDAs
    function buyResources(uint256 amountA, uint256 amountB) public payable {
        int256 timeSinceStart = toWadUnsafe(block.timestamp - startTime);

        // use linear VRGDA to price resource A
        uint256 pricePerA = linearAuction.getVRGDAPrice(timeSinceStart, resourceASold);

        // use logistic VRGDA to price resource B
        uint256 pricePerB = logAuction.getVRGDAPrice(timeSinceStart, resourceBSold);

        ....
    }

Yep! We can have two independent VRGDAs, that rely on different function families, all in the same contract 🤓


  • Support Multiple VRGDAs in a single contract
  • Example implementation (MultiNFT.sol)
  • Preliminary tests
  • Library + Struct-based LinearVRGDA
  • Library + Struct-based LogisticVRGDA
  • Library + Struct-based LogisticToLinearVRGDA
  • Testing of the new implementation against existing tests

Tangentially relevant gif

multi21

@transmissions11
Copy link
Owner

really appreciate the PR!

agree there needs to be some changes on the devex of hooking up to multiple VRGDAs.

i'm not sure a stateful solution like this is the way to go about it tho, i was more thinking of just abstracting things out into a lib (effectively like how we did it in Monaco)

#12

@saucepoint
Copy link
Author

i see -- will stare at the code a bit more and play around to see how multiple VRGDAs could interact with a lib

saucepoint and others added 22 commits September 6, 2022 17:23
Libraried VRGDA + Support Multi VRGDA
* ✨ LogisticToLinearVRGDA

* 📝 Typo

* merge in master, remove base files as originally intended

* example implementation of a composite VRGDA

* conversion of logisticToLinear NFT to use library

* contract based logisticToLinear replaced with composite VRGDA in examples

* convert mock contract to use library; add fixes to log2lin lib

* add 1 wad for log2lin to follow the logistic behavior

* snapshot

Co-authored-by: t11s <greenfeatherhelp@gmail.com>
@saucepoint saucepoint changed the title Multi VRGDA Multi VRGDA via Libraries & Structs Sep 8, 2022
@saucepoint
Copy link
Author

Letting this marinate a bit, my fork feels a little too opinionated. Gonna close the PR and will likely just maintain a repo for multi VRGDAs

@saucepoint saucepoint closed this Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

♻️ Separate VRGDA logic into libs
2 participants