mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 02:46:28 +00:00
Reward robots for counterpart slashed bonds
This commit is contained in:
parent
78b4d1fcec
commit
ce25a6b3c7
@ -93,6 +93,9 @@ MIN_FLAT_ROUTING_FEE_LIMIT_REWARD = 2
|
||||
|
||||
# Reward tip. Reward for every finished trade in the referral program (Satoshis)
|
||||
REWARD_TIP = 100
|
||||
# Fraction rewarded to user from the slashed bond of a counterpart.
|
||||
# It should not be close to 1, or could be exploited by an attacker trading with himself to DDOS the LN node.
|
||||
SLASHED_BOND_REWARD_SPLIT = 0.5
|
||||
|
||||
# Username for HTLCs escrows
|
||||
ESCROW_USERNAME = 'admin'
|
||||
|
@ -106,6 +106,9 @@ class UserProfileAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
||||
"is_referred",
|
||||
"telegram_enabled",
|
||||
"total_contracts",
|
||||
"pending_rewards",
|
||||
"earned_rewards",
|
||||
"claimed_rewards",
|
||||
"platform_rating",
|
||||
"total_ratings",
|
||||
"avg_rating",
|
||||
|
@ -244,6 +244,8 @@ class Logics:
|
||||
pass
|
||||
order.status = Order.Status.EXP
|
||||
order.save()
|
||||
# Reward taker with part of the maker bond
|
||||
cls.add_slashed_rewards(order.maker_bond, order.taker.profile)
|
||||
return True
|
||||
|
||||
# If maker is buyer, settle the taker's bond order goes back to public
|
||||
@ -254,10 +256,13 @@ class Logics:
|
||||
cls.cancel_escrow(order)
|
||||
except:
|
||||
pass
|
||||
taker_bond = order.taker_bond
|
||||
order.taker = None
|
||||
order.taker_bond = None
|
||||
order.trade_escrow = None
|
||||
cls.publish_order(order)
|
||||
# Reward maker with part of the taker bond
|
||||
cls.add_slashed_rewards(taker_bond, order.maker.profile)
|
||||
return True
|
||||
|
||||
elif order.status == Order.Status.WFI:
|
||||
@ -272,16 +277,21 @@ class Logics:
|
||||
cls.return_escrow(order)
|
||||
order.status = Order.Status.EXP
|
||||
order.save()
|
||||
# Reward taker with part of the maker bond
|
||||
cls.add_slashed_rewards(order.maker_bond, order.taker.profile)
|
||||
return True
|
||||
|
||||
# If maker is seller settle the taker's bond, order goes back to public
|
||||
else:
|
||||
cls.settle_bond(order.taker_bond)
|
||||
cls.return_escrow(order)
|
||||
taker_bond = order.taker_bond
|
||||
order.taker = None
|
||||
order.taker_bond = None
|
||||
order.trade_escrow = None
|
||||
cls.publish_order(order)
|
||||
# Reward maker with part of the taker bond
|
||||
cls.add_slashed_rewards(taker_bond, order.maker.profile)
|
||||
return True
|
||||
|
||||
elif order.status in [Order.Status.CHA, Order.Status.FSE]:
|
||||
@ -310,9 +320,9 @@ class Logics:
|
||||
@classmethod
|
||||
def open_dispute(cls, order, user=None):
|
||||
|
||||
# Always settle escro and bonds during a dispute. Disputes
|
||||
# Always settle escrow and bonds during a dispute. Disputes
|
||||
# can take long to resolve, it might trigger force closure
|
||||
# for unresolve HTLCs) Dispute winner will have to submit a
|
||||
# for unresolved HTLCs) Dispute winner will have to submit a
|
||||
# new invoice for value of escrow + bond.
|
||||
|
||||
if not order.trade_escrow.status == LNPayment.Status.SETLED:
|
||||
@ -578,16 +588,15 @@ class Logics:
|
||||
|
||||
# 4.a) When maker cancel after bond (before escrow)
|
||||
"""The order into cancelled status if maker cancels."""
|
||||
elif (order.status in [
|
||||
Order.Status.PUB, Order.Status.TAK, Order.Status.WF2,
|
||||
Order.Status.WFE
|
||||
] and order.maker == user):
|
||||
elif (order.status in [Order.Status.TAK, Order.Status.WF2,Order.Status.WFE] and order.maker == user):
|
||||
# Settle the maker bond (Maker loses the bond for canceling an ongoing trade)
|
||||
valid = cls.settle_bond(order.maker_bond)
|
||||
cls.return_bond(order.taker_bond) # returns taker bond
|
||||
if valid:
|
||||
order.status = Order.Status.UCA
|
||||
order.save()
|
||||
# Reward taker with part of the maker bond
|
||||
cls.add_slashed_rewards(order.maker_bond, order.taker.profile)
|
||||
return True, None
|
||||
|
||||
# 4.b) When taker cancel after bond (before escrow)
|
||||
@ -599,6 +608,8 @@ class Logics:
|
||||
if valid:
|
||||
order.taker = None
|
||||
cls.publish_order(order)
|
||||
# Reward maker with part of the taker bond
|
||||
cls.add_slashed_rewards(order.taker_bond, order.maker.profile)
|
||||
return True, None
|
||||
|
||||
# 5) When trade collateral has been posted (after escrow)
|
||||
@ -1042,7 +1053,7 @@ class Logics:
|
||||
|
||||
# Add referral rewards (safe)
|
||||
try:
|
||||
Logics.add_rewards(order)
|
||||
cls.add_rewards(order)
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -1112,6 +1123,19 @@ class Logics:
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def add_slashed_rewards(cls, bond, profile):
|
||||
'''
|
||||
When a bond is slashed due to overtime, rewards the user that was waiting.
|
||||
If participants of the order were referred, the reward is given to the referees.
|
||||
'''
|
||||
reward_fraction = float(config('SLASHED_BOND_REWARD_SPLIT'))
|
||||
reward = int(bond.num_satoshis*reward_fraction)
|
||||
profile.earned_rewards += reward
|
||||
profile.save()
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def withdraw_rewards(cls, user, invoice):
|
||||
|
||||
|
@ -634,12 +634,24 @@ bottomBarDesktop =()=>{
|
||||
<ListItemIcon size="small">
|
||||
<PercentIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primaryTypographyProps={{fontSize: '14px'}}
|
||||
secondaryTypographyProps={{fontSize: '12px'}}
|
||||
secondary="Trading fees">
|
||||
{(this.state.maker_fee*100).toFixed(3)}% <small>(maker)</small> | {(this.state.taker_fee*100).toFixed(3)}% <small>(taker)</small>
|
||||
</ListItemText>
|
||||
<Grid container xs={12}>
|
||||
<Grid item xs={6}>
|
||||
<ListItemText
|
||||
primaryTypographyProps={{fontSize: '14px'}}
|
||||
secondaryTypographyProps={{fontSize: '12px'}}
|
||||
secondary="Maker fee">
|
||||
{(this.state.maker_fee*100).toFixed(3)}%
|
||||
</ListItemText>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<ListItemText
|
||||
primaryTypographyProps={{fontSize: '14px'}}
|
||||
secondaryTypographyProps={{fontSize: '12px'}}
|
||||
secondary="Taker fee">
|
||||
{(this.state.taker_fee*100).toFixed(3)}%
|
||||
</ListItemText>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ListItem>
|
||||
</List>
|
||||
|
||||
|
@ -38,7 +38,7 @@ export default class InfoDialog extends Component {
|
||||
<Typography component="h4" variant="h4">What is <i>RoboSats</i>?</Typography>
|
||||
<Typography component="body2" variant="body2">
|
||||
<p>It is a BTC/FIAT peer-to-peer exchange over lightning. It simplifies
|
||||
matchmaking and minimizes the need of trust. RoboSats focuses in privacy and speed.</p>
|
||||
matchmaking and minimizes the need for entrust. RoboSats focuses in privacy and speed.</p>
|
||||
<img
|
||||
width='100%'
|
||||
src={window.location.origin +'/static/assets/images/robosats_0.1.0_banner.png'}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user