Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2801 from ManfredKarrer/restrict-new-accounts
Add check for account age to apply restrictions
- Loading branch information
Showing
32 changed files
with
527 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.core.offer; | ||
|
||
import bisq.core.payment.payload.PaymentMethod; | ||
import bisq.core.trade.Trade; | ||
|
||
import org.bitcoinj.core.Coin; | ||
|
||
public class OfferRestrictions { | ||
public static Coin TOLERATED_SMALL_TRADE_AMOUNT = Coin.parseCoin("0.01"); | ||
|
||
public static boolean isOfferRisky(Offer offer) { | ||
return offer != null && | ||
offer.isBuyOffer() && | ||
PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) && | ||
isMinTradeAmountRisky(offer); | ||
} | ||
|
||
public static boolean isSellOfferRisky(Offer offer) { | ||
return offer != null && | ||
PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) && | ||
isMinTradeAmountRisky(offer); | ||
} | ||
|
||
public static boolean isTradeRisky(Trade trade) { | ||
if (trade == null) | ||
return false; | ||
|
||
Offer offer = trade.getOffer(); | ||
return offer != null && | ||
PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) && | ||
trade.getTradeAmount() != null && | ||
isAmountRisky(trade.getTradeAmount()); | ||
} | ||
|
||
public static boolean isMinTradeAmountRisky(Offer offer) { | ||
return isAmountRisky(offer.getMinAmount()); | ||
} | ||
|
||
public static boolean isAmountRisky(Coin amount) { | ||
return amount.isGreaterThan(TOLERATED_SMALL_TRADE_AMOUNT); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
core/src/main/java/bisq/core/payment/AccountAgeRestrictions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.core.payment; | ||
|
||
import bisq.core.offer.Offer; | ||
import bisq.core.offer.OfferPayload; | ||
import bisq.core.offer.OfferRestrictions; | ||
import bisq.core.payment.payload.PaymentMethod; | ||
import bisq.core.trade.Trade; | ||
|
||
import bisq.common.util.Utilities; | ||
|
||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class AccountAgeRestrictions { | ||
public static final long SAFE_ACCOUNT_AGE_DATE = Utilities.getUTCDate(2019, GregorianCalendar.MARCH, 15).getTime(); | ||
|
||
public static boolean isMakersAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, Offer offer) { | ||
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getMakersAccountAge(offer, new Date()); | ||
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE; | ||
} | ||
|
||
public static boolean isTradePeersAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, Trade trade) { | ||
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getTradingPeersAccountAge(trade); | ||
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE; | ||
} | ||
|
||
public static boolean isMyAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, PaymentAccount myPaymentAccount) { | ||
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload()); | ||
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE; | ||
} | ||
|
||
public static long getMyTradeLimitAtCreateOffer(AccountAgeWitnessService accountAgeWitnessService, | ||
PaymentAccount paymentAccount, | ||
String currencyCode, | ||
OfferPayload.Direction direction) { | ||
if (direction == OfferPayload.Direction.BUY && | ||
PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) && | ||
AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) { | ||
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value; | ||
} else { | ||
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode); | ||
} | ||
} | ||
|
||
public static long getMyTradeLimitAtTakeOffer(AccountAgeWitnessService accountAgeWitnessService, | ||
PaymentAccount paymentAccount, | ||
Offer offer, | ||
String currencyCode, | ||
OfferPayload.Direction direction) { | ||
if (direction == OfferPayload.Direction.BUY && PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) && | ||
AccountAgeRestrictions.isMakersAccountAgeImmature(accountAgeWitnessService, offer)) { | ||
// Taker is seller | ||
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value; | ||
} else if (direction == OfferPayload.Direction.SELL && PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) && | ||
AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) { | ||
// Taker is buyer | ||
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value; | ||
} else { | ||
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.