Skip to content

Commit

Permalink
added asymmetric fee support
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Dec 6, 2023
1 parent 3583f93 commit 4868119
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/WavesKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,15 @@ public function setMatcherSettings( $settings = null )
if( $config['percent']['type'] !== 'spending' )
return false;

$this->matcherPairMinFees[$pair] = $config['percent']['minFee'] / 100;
if( $config['percent']['minFeeInWaves'] !== $this->matcherBaseFee )
$this->matcherPairMinFeesInWaves[$pair] = $config['percent']['minFeeInWaves'];
$minFeeAB = isset( $config['percent']['amount']['minFee'] ) ? $config['percent']['amount']['minFee'] : $config['percent']['minFee'];
$minFeeBA = isset( $config['percent']['price']['minFee'] ) ? $config['percent']['price']['minFee'] : $config['percent']['minFee'];
$minFeeInWavesAB = isset( $config['percent']['amount']['minFeeInWaves'] ) ? $config['percent']['amount']['minFeeInWaves'] : $config['percent']['minFeeInWaves'];
$minFeeInWavesBA = isset( $config['percent']['price']['minFeeInWaves'] ) ? $config['percent']['price']['minFeeInWaves'] : $config['percent']['minFeeInWaves'];

$this->matcherPairMinFees[$pair][1] = $minFeeAB / 100;
$this->matcherPairMinFees[$pair][0] = $minFeeBA / 100;
$this->matcherPairMinFeesInWaves[$pair][1] = $minFeeInWavesAB;
$this->matcherPairMinFeesInWaves[$pair][0] = $minFeeInWavesBA;
}

return true;
Expand Down Expand Up @@ -920,17 +926,18 @@ public function setMatcherFee( $order, $discount = true )
$priceAsset = $this->assetId( $order['assetPair']['priceAsset'] );
$mainAsset = $isSell ? $amountAsset : $priceAsset;
$pair = $amountAsset . '-' . $priceAsset;
$direction = $isSell ? 1 : 0;

if( !isset( $this->matcherBaseFee ) && !$this->setMatcherSettings() )
return false;

if( isset( $this->matcherPairMinFees[$pair] ) )
if( isset( $this->matcherPairMinFees[$pair][$direction] ) )
{
$rate = $this->matcherRates[$mainAsset];
$amount = $isSell ? $order['amount'] : ( $order['amount'] * $order['price'] / 100000000 );

$matcherBaseFee = isset( $this->matcherPairMinFeesInWaves[$pair] ) ? $this->matcherPairMinFeesInWaves[$pair] : $this->matcherBaseFee;
$fee = $amount * $this->matcherPairMinFees[$pair];
$matcherBaseFee = $this->matcherPairMinFeesInWaves[$pair][$direction];
$fee = $amount * $this->matcherPairMinFees[$pair][$direction];
$fee /= $rate;
if( $fee < $matcherBaseFee )
$fee = $matcherBaseFee;
Expand Down

0 comments on commit 4868119

Please sign in to comment.