origami_defi 1.8.0
DeFi library for Dojo based games.
Gradual Dutch Auctions (GDA) enable efficient sales of assets without relying on liquid markets. GDAs offer a novel solution for selling both non-fungible tokens (NFTs) and fungible tokens through discrete and continuous mechanisms.
Discrete GDAs are perfect for selling NFTs in integer quantities. They offer an efficient way to conduct bulk purchases through a sequence of Dutch auctions.
The process involves holding virtual Dutch auctions for each token, allowing for efficient clearing of batches. Price decay is exponential, controlled by a decay constant, and the starting price increases by a fixed scale factor.
Calculations can be made efficiently for purchasing a batch of auctions, following a given price function.
Continuous GDAs offer a mechanism for selling fungible tokens, allowing for constant rate emissions over time.
The process works by incrementally making more assets available for sale, splitting sales into an infinite sequence of auctions. Various price functions, including exponential decay, can be applied.
It's possible to compute the purchase price for any quantity of tokens gas-efficiently, using specific mathematical expressions.
Add the crate from the scarbs.xyz registry, with the fixed package that provides its Fixed type:
scarb add origami_defi@1.8.0
scarb add fixed@0.4.0
Values are signed Q32.32 fixed-point numbers (fixed::Fixed): the range is [-2^31, 2^31) and the resolution is 2^-32. Only the inputs and the result have to fit: the intermediate products are kept wide. The remaining domain limits are documented on each function (# Domain).
The DiscreteGDA structure represents a Gradual Dutch Auction using discrete time steps. Here's how you can use it:
let gda = DiscreteGDA {
sold: FixedTrait::from_int(0),
initial_price: FixedTrait::from_int(100),
scale_factor: FixedTrait::from_ratio(11, 10), // 1.1
decay_constant: FixedTrait::from_ratio(1, 2), // 0.5
};
Calculating the Purchase Price
You can calculate the purchase price for a specific quantity at a given time using the purchase_price method.
let time_since_start = FixedTrait::from_int(2); // 2 days since the start
let quantity = FixedTrait::from_int(5); // Quantity to purchase
let price = gda.purchase_price(time_since_start, quantity);
The ContinuousGDA structure represents a Gradual Dutch Auction using continuous time steps.
let gda = ContinuousGDA {
initial_price: FixedTrait::from_int(1000),
emission_rate: ONE,
decay_constant: FixedTrait::from_ratio(1, 2),
};
Calculating the Purchase Price
Just like with the discrete version, you can calculate the purchase price for a specific quantity at a given time using the purchase_price method.
let time_since_last = FixedTrait::from_int(1); // 1 day since the last purchase
let quantity = FixedTrait::from_int(3); // Quantity to purchase
let price = gda.purchase_price(time_since_last, quantity);
These examples demonstrate how to create instances of the DiscreteGDA and ContinuousGDA structures, and how to utilize their purchase_price methods to calculate the price for purchasing specific quantities at given times.
The imports of these examples (the fixed package builds the Fixed values):
use fixed::{FixedTrait, ONE};
use origami_defi::auction::gda::{ContinuousGDA, ContinuousGDATrait, DiscreteGDA, DiscreteGDATrait};
GDAs present a powerful tool for selling both fungible and non-fungible tokens in various contexts. They offer efficient, flexible solutions for asset sales, opening doors to innovative applications beyond traditional markets.
Variable Rate GDAs (VRGDAs) enable the selling of tokens according to a custom schedule, raising or lowering prices based on the sales pace. VRGDA is a generalization of the GDA mechanism.
The LinearVRGDA struct represents a linear auction where the price decays based on the target price, decay constant, and per-time-unit rate.
let auction = LinearVRGDA {
target_price: FixedTrait::from_ratio(6942, 100), // 69.42
decay_constant: FixedTrait::from_ratio(31, 100), // 0.31
target_units_per_time: FixedTrait::from_int(2),
};
Calculating Target Sale Time
let target_sale_time = auction.get_target_sale_time(sold_quantity);
Calculating VRGDA Price
let price = auction.get_vrgda_price(time_since_start, sold_quantity);
The LogisticVRGDA struct represents an auction where the price decays according to a logistic function, based on the target price, decay constant, max sellable quantity, and time scale.
let auction = LogisticVRGDA {
target_price: FixedTrait::from_ratio(6942, 100), // 69.42
decay_constant: FixedTrait::from_ratio(31, 100), // 0.31
max_sellable: FixedTrait::from_int(6392),
time_scale: FixedTrait::from_ratio(23, 10000), // 0.0023
};
Calculating Target Sale Time
let target_sale_time = auction.get_target_sale_time(sold_quantity);
Calculating VRGDA Price
let price = auction.get_vrgda_price(time_since_start, sold_quantity);
Make sure to import the required dependencies at the beginning of your Cairo file:
use fixed::{Fixed, FixedTrait};
use origami_defi::auction::vrgda::{LinearVRGDA, LogisticVRGDA, VRGDATargetTimeTrait, VRGDATrait};
Every example of this README is compiled by tests/readme.cairo.
These examples show you how to create instances of both LinearVRGDA and LogisticVRGDA and how to use their methods to calculate the target sale time and VRGDA price.
VRGDAs offer a flexible way to issue NFTs on nearly any schedule, enabling seamless purchases at any time.
Version 1.8.0
Uploaded 12 hours ago
License MIT
Size 8.2 KB
Run the following command in your project dir
scarb add origami_defi@1.8.0
Or add the following line to your Scarb.toml
origami_defi = "1.8.0"