Skip to content

Commit

Permalink
Add 'quantity_by_price' argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Sep 6, 2024
1 parent 619419a commit 43e545a
Show file tree
Hide file tree
Showing 25 changed files with 1,895 additions and 1,604 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS fairminters (
asset_longname TEXT,
description TEXT,
price INTEGER,
quantity_by_price INTEGER,
hard_cap INTEGER,
burn_payment BOOL,
max_mint_per_tx INTEGER,
Expand Down
11 changes: 10 additions & 1 deletion counterparty-core/counterpartycore/lib/messages/fairmint.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def validate(
if quantity > config.MAX_INT:
problems.append("quantity exceeds maximum allowed value")
return problems
paid_quantity = (D(str(quantity)) / D(str(fairminter["quantity_by_price"]))) * D(
str(fairminter["price"])
)
paid_quantity = int(paid_quantity)
if paid_quantity <= 0:
problems.append("Quantity to low for the price")
# check id we don't exceed the hard cap
if fairminter["hard_cap"] > 0 and asset_supply + quantity > fairminter["hard_cap"]:
problems.append("asset supply quantity exceeds hard cap")
Expand Down Expand Up @@ -185,7 +191,10 @@ def parse(db, tx, message):
# we determine how many assets we need to send
# and the price paid by the user
if fairminter["price"] > 0:
paid_quantity = quantity * fairminter["price"]
paid_quantity = (D(str(quantity)) / D(str(fairminter["quantity_by_price"]))) * D(
str(fairminter["price"])
)
paid_quantity = int(paid_quantity)
earn_quantity = quantity
else:
paid_quantity = 0
Expand Down
18 changes: 16 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/fairminter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialise(db):
asset_longname TEXT,
description TEXT,
price INTEGER,
quantity_by_price INTEGER,
hard_cap INTEGER,
burn_payment BOOL,
max_mint_per_tx INTEGER,
Expand Down Expand Up @@ -63,6 +64,7 @@ def validate(
asset,
asset_parent="",
price=0,
quantity_by_price=1,
max_mint_per_tx=0,
hard_cap=0,
premint_quantity=0,
Expand All @@ -82,6 +84,7 @@ def validate(
# check integer parameters
for param_name, param_value in {
"price": price,
"quantity_by_price": quantity_by_price,
"max_mint_per_tx": max_mint_per_tx,
"hard_cap": hard_cap,
"premint_quantity": premint_quantity,
Expand All @@ -97,6 +100,8 @@ def validate(
problems.append(f"`{param_name}` must be >= 0.")
elif param_value > config.MAX_INT:
problems.append(f"`{param_name}` exceeds maximum value")
if quantity_by_price < 1:
problems.append("quantity_by_price must be >= 1")
# check boolean parameters
for param_name, param_value in {
"burn_payment": burn_payment,
Expand Down Expand Up @@ -184,6 +189,7 @@ def compose(
asset,
asset_parent="",
price=0,
quantity_by_price=1,
max_mint_per_tx=0,
hard_cap=0,
premint_quantity=0,
Expand All @@ -205,6 +211,7 @@ def compose(
asset,
asset_parent,
price,
quantity_by_price,
max_mint_per_tx,
hard_cap,
premint_quantity,
Expand Down Expand Up @@ -236,6 +243,7 @@ def compose(
asset,
asset_parent,
price,
quantity_by_price,
max_mint_per_tx,
hard_cap,
premint_quantity,
Expand Down Expand Up @@ -263,6 +271,7 @@ def unpack(message, return_dict=False):
asset,
asset_parent,
price,
quantity_by_price,
max_mint_per_tx,
hard_cap,
premint_quantity,
Expand All @@ -275,9 +284,9 @@ def unpack(message, return_dict=False):
lock_description,
lock_quantity,
divisible,
) = data_content[0:15]
) = data_content[0:16]
# The description is placed last to be able to contain `|`.
description = "|".join(data_content[15:]) if len(data_content) > 15 else ""
description = "|".join(data_content[16:]) if len(data_content) > 16 else ""

minted_asset_commission = D(minted_asset_commission_int) / D(1e8)

Expand All @@ -286,6 +295,7 @@ def unpack(message, return_dict=False):
"asset": asset,
"asset_parent": asset_parent,
"price": int(price),
"quantity_by_price": int(quantity_by_price),
"max_mint_per_tx": int(max_mint_per_tx),
"hard_cap": int(hard_cap),
"premint_quantity": int(premint_quantity),
Expand All @@ -305,6 +315,7 @@ def unpack(message, return_dict=False):
asset,
asset_parent,
int(price),
int(quantity_by_price),
int(max_mint_per_tx),
int(hard_cap),
int(premint_quantity),
Expand All @@ -328,6 +339,7 @@ def parse(db, tx, message):
asset,
asset_parent,
price,
quantity_by_price,
max_mint_per_tx,
hard_cap,
premint_quantity,
Expand All @@ -349,6 +361,7 @@ def parse(db, tx, message):
asset,
asset_parent,
price,
quantity_by_price,
max_mint_per_tx,
hard_cap,
premint_quantity,
Expand Down Expand Up @@ -424,6 +437,7 @@ def parse(db, tx, message):
"asset_longname": asset_longname,
"description": description,
"price": price,
"quantity_by_price": quantity_by_price,
"hard_cap": hard_cap,
"burn_payment": burn_payment,
"max_mint_per_tx": max_mint_per_tx,
Expand Down
2 changes: 2 additions & 0 deletions counterparty-core/counterpartycore/lib/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,7 @@ def compose_fairminter(
asset: str,
asset_parent: str = "",
price: int = 0,
quantity_by_price: int = 1,

Check warning

Code scanning / pylint

Unused argument 'quantity_by_price'. Warning

Unused argument 'quantity_by_price'.
max_mint_per_tx: int = 0,
hard_cap: int = 0,
premint_quantity: int = 0,
Expand All @@ -1827,6 +1828,7 @@ def compose_fairminter(
:param asset: The asset to issue (e.g. MYASSET)
:param asset_parent: The parent asset of the asset to issue
:param price: The price in XCP of the asset to issue
:param quantity_by_price: The quantity of asset to mint per `price` paid
:param max_mint_per_tx: Amount minted if price is equal to 0; otherwise, maximum amount of asset that can be minted in a single transaction; if 0, there is no limit
:param hard_cap: The maximum amount of asset that can be minted; if 0 there is no limit
:param premint_quantity: Amount of asset to be minted when the sale starts, if 0, no premint; preminted assets are sent to the source of the transaction
Expand Down
Loading

0 comments on commit 43e545a

Please sign in to comment.