account for network fees in sales without platform fees (no buffer)

pull/3/head
lalanza808 5 years ago
parent 0aa4bdf94f
commit 5d0118c4e2

@ -13,7 +13,7 @@ class CreateItemForm(forms.ModelForm):
help_texts = { help_texts = {
'name': 'Use a succinct name for your item. Don\'t be spammy or obscene.', 'name': 'Use a succinct name for your item. Don\'t be spammy or obscene.',
'description': 'Describe the condition of the item and any important information. Try to refrain from sharing personally identifiable information like phone numbers or social media links.', 'description': 'Describe the condition of the item and any important information. Try to refrain from sharing personally identifiable information like phone numbers or social media links.',
'whereabouts': 'A simple pointer to your general region - a nearby ZIP code or capital city would be perfect.', 'whereabouts': 'A simple pointer to your general region - a nearby capital city and your state would be perfect.',
'ask_price_xmr': 'How many moneroj do you want for your item?', 'ask_price_xmr': 'How many moneroj do you want for your item?',
'payout_address': 'A Monero wallet address where funds will be sent after sale is confirmed.', 'payout_address': 'A Monero wallet address where funds will be sent after sale is confirmed.',
} }

@ -0,0 +1,23 @@
# Generated by Django 2.2.8 on 2020-01-13 21:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sales', '0003_itemsale_sale_cancelled'),
]
operations = [
migrations.AddField(
model_name='itemsale',
name='network_fee_xmr',
field=models.FloatField(default=0.0),
),
migrations.AddField(
model_name='itemsale',
name='seller_payout_transaction',
field=models.CharField(blank=True, max_length=150),
),
]

@ -12,6 +12,8 @@ class ItemSale(models.Model):
escrow_account_index = models.IntegerField() escrow_account_index = models.IntegerField()
agreed_price_xmr = models.FloatField() agreed_price_xmr = models.FloatField()
platform_fee_xmr = models.FloatField() platform_fee_xmr = models.FloatField()
network_fee_xmr = models.FloatField(default=0.0)
seller_payout_transaction = models.CharField(max_length=150, blank=True)
expected_payment_xmr = models.FloatField() expected_payment_xmr = models.FloatField()
received_payment_xmr = models.FloatField(default=0.0) received_payment_xmr = models.FloatField(default=0.0)
escrow_period_days = models.PositiveSmallIntegerField(default=settings.ESCROW_PERIOD_DAYS) escrow_period_days = models.PositiveSmallIntegerField(default=settings.ESCROW_PERIOD_DAYS)

@ -122,7 +122,7 @@ def poll_for_buyer_escrow_payments():
sale.save() sale.save()
@periodic_task(crontab(minute='*/5')) @periodic_task(crontab(minute='*'))
def pay_sellers_on_sold_items(): def pay_sellers_on_sold_items():
aw = AuctionWallet() aw = AuctionWallet()
if aw.connected is False: if aw.connected is False:
@ -134,12 +134,22 @@ def pay_sellers_on_sold_items():
# Take platform fees from the sale - the 50:50 split between buyer/seller # Take platform fees from the sale - the 50:50 split between buyer/seller
sale_total = sale.agreed_price_xmr - sale.platform_fee_xmr sale_total = sale.agreed_price_xmr - sale.platform_fee_xmr
sale_account = aw.wallet.accounts[sale.escrow_account_index] sale_account = aw.wallet.accounts[sale.escrow_account_index]
logger.info(f'[INFO] Sending {sale_total} XMR from wallet account #{sale.escrow_account_index} to item owner\'s payout address for sale #{sale.id}.')
if sale_account.balances()[1] > Decimal(sale.agreed_price_xmr): if sale_account.balances()[1] >= Decimal(sale.agreed_price_xmr):
try: try:
sale_account.transfer( # Construct a transaction so we can get current fee and subtract from the total
sale.item.payout_address, sale_total _tx = sale_account.transfer(
sale.item.payout_address, Decimal(.01), relay=False
) )
new_total = sale_total - float(_tx[0].fee)
logger.info(f'[INFO] Sending {new_total} XMR from wallet account #{sale.escrow_account_index} to item owner\'s payout address for sale #{sale.id}.')
# Make the transaction with network fee removed
tx = sale_account.transfer(
sale.item.payout_address, new_total, relay=True
)
sale.network_fee_xmr = _tx[0].fee
sale.seller_payout_transaction = tx[0]
sale.seller_paid = True sale.seller_paid = True
sale.escrow_complete = True sale.escrow_complete = True
sale.save() sale.save()
@ -175,9 +185,13 @@ def pay_platform_on_sold_items():
sale_account = aw.wallet.accounts[sale.escrow_account_index] sale_account = aw.wallet.accounts[sale.escrow_account_index]
bal = sale_account.balances()[1] bal = sale_account.balances()[1]
if bal >= 0: if bal >= 0:
logger.info(f'[INFO] Getting platform fees of {bal} XMR')
try: try:
sale_account.sweep_all(aof) if settings.PLATFORM_FEE_PERCENT > 0:
logger.info(f'[INFO] Getting platform fees of {bal} XMR')
sale_account.sweep_all(aof)
else:
logging.info('No platform fees are set - proceeding without taking fees.')
sale.platform_paid = True sale.platform_paid = True
sale.sale_finalized = True sale.sale_finalized = True
sale.save() sale.save()

@ -35,6 +35,9 @@ def get_sale(request, sale_id):
address_qr = qrcode_make(qr_uri).save(_address_qr) address_qr = qrcode_make(qr_uri).save(_address_qr)
total_seller_payout = sale.agreed_price_xmr - sale.platform_fee_xmr total_seller_payout = sale.agreed_price_xmr - sale.platform_fee_xmr
if sale.network_fee_xmr:
total_seller_payout = total_seller_payout - sale.network_fee_xmr
context = { context = {
'sale': sale, 'sale': sale,
'qrcode': b64encode(_address_qr.getvalue()).decode(), 'qrcode': b64encode(_address_qr.getvalue()).decode(),

@ -116,11 +116,13 @@
{% elif sale.item_received %} {% elif sale.item_received %}
<p class="sale-info">Hey {{ sale.item.owner.username }},</p> <p class="sale-info">Hey {{ sale.item.owner.username }},</p>
<p class="sale-info">The buyer confirmed receipt of their shipment which means things worked out. It's time for you to get paid!</p> <p class="sale-info">The buyer confirmed receipt of their shipment which means things worked out. It's time for you to get paid!</p>
<p class="sale-info">Your payout address provided during item creation will be paid the accepted bid amount out of the escrow wallet.</p> <p class="sale-info">Your payout address provided during item creation will be paid the accepted bid amount out of the escrow wallet. <strong>Please note, transaction fees will come out of the payout total.</strong></p>
<p class="sale-info"><strong>Accepted Bid (XMR)</strong>: {{ sale.bid.bid_price_xmr }}</p> <p class="sale-info"><strong>Accepted Bid (XMR)</strong>: {{ sale.bid.bid_price_xmr }}</p>
<p class="sale-info"><strong>Platform Fee (XMR)</strong>: {{ sale.platform_fee_xmr }}</p> <p class="sale-info"><strong>Platform Fee (XMR)</strong>: {{ sale.platform_fee_xmr }}</p>
<p class="sale-info"><strong>Network Fee (XMR)</strong>: {{ sale.network_fee_xmr }}</p>
<p class="sale-info"><strong>Total Payout (XMR)</strong>: {{ total_seller_payout }}</p> <p class="sale-info"><strong>Total Payout (XMR)</strong>: {{ total_seller_payout }}</p>
<p class="sale-info"><strong>Payout Address</strong>: {{ sale.item.payout_address }}</p> <p class="sale-info"><strong>Payout Address</strong>: {{ sale.item.payout_address }}</p>
<p class="sale-info"><strong>Payout Transaction ID</strong>: {{ sale.seller_payout_transaction }}</p>
<br> <br>
<p class="sale-info">If you found the site useful and had a good experience, please consider donating to the developer address provided at the bottom of the page.</p> <p class="sale-info">If you found the site useful and had a good experience, please consider donating to the developer address provided at the bottom of the page.</p>
<p class="sale-info">Thanks for using {{ site_meta.name }}!</p> <p class="sale-info">Thanks for using {{ site_meta.name }}!</p>

@ -1,6 +1,6 @@
Congratulations {{ sale.item.owner }}, Congratulations {{ sale.item.owner }},
The sale of your item, "{{ sale.item.name }}" (#{{ sale.item.id }}), has concluded. The agreed upon bid price has been transferred to the payout address provided when posting the item. The sale of your item, "{{ sale.item.name }}" (#{{ sale.item.id }}), has concluded. The agreed upon bid price minus any network fees has been transferred to the payout address provided when posting the item.
In a few more minutes post-processing will complete, the platform will receive it's fees, and the sale, item, and bids will all be removed from the system. If your fees were waived, please consider donating to the development fund. The address is at the bottom of the {{ site_name }} site pages. In a few more minutes post-processing will complete, the platform will receive it's fees, and the sale, item, and bids will all be removed from the system. If your fees were waived, please consider donating to the development fund. The address is at the bottom of the {{ site_name }} site pages.