Skip to content

Commit

Permalink
fix swap transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
grkamil committed Feb 23, 2021
1 parent 8884a12 commit eedda35
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 50 deletions.
19 changes: 8 additions & 11 deletions src/Minter/SDK/MinterCoins/MinterBuySwapPoolTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,40 @@
*/
class MinterBuySwapPoolTx extends MinterCoinTx implements MinterTxInterface
{
public $coinToBuy;
public $coinToSell;
public $coins;
public $valueToBuy;
public $maximumValueToSell;

const TYPE = 24;

/**
* MinterBuySwapPoolTx constructor.
* @param $coinToBuy
* @param $coins
* @param $valueToBuy
* @param $coinToSell
* @param $maximumValueToSell
*/
public function __construct($coinToBuy, $valueToBuy, $coinToSell, $maximumValueToSell)
public function __construct($coins, $valueToBuy, $maximumValueToSell)
{
$this->coinToBuy = $coinToBuy;
$this->coinToSell = $coinToSell;
$this->coins = $coins;
$this->valueToBuy = $valueToBuy;
$this->maximumValueToSell = $maximumValueToSell;
}

public function encodeData(): array
{
return [
$this->coinToBuy,
$this->coins,
MinterConverter::convertToPip($this->valueToBuy),
$this->coinToSell,
MinterConverter::convertToPip($this->maximumValueToSell)
];
}

public function decodeData()
{
$this->coinToBuy = hexdec($this->coinToBuy);
$this->valueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->valueToBuy));
$this->coinToSell = hexdec($this->coinToSell);
$this->maximumValueToSell = MinterConverter::convertToBase(Helper::hexDecode($this->maximumValueToSell));
$this->coins = array_map(function ($value) {
return hexdec($value);
}, $this->coins);
}
}
21 changes: 9 additions & 12 deletions src/Minter/SDK/MinterCoins/MinterSellAllSwapPoolTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@
*/
class MinterSellAllSwapPoolTx extends MinterCoinTx implements MinterTxInterface
{
public $coinToBuy;
public $coinToSell;
public $coins;
public $minimumValueToBuy;

const TYPE = 25;

/**
* MinterSellAllSwapPoolTx constructor.
* @param $coinToSell
* @param $coinToBuy
* @param $minimumValueToBuy
* @param array $coins
* @param $minimumValueToBuy
*/
public function __construct($coinToSell, $coinToBuy, $minimumValueToBuy)
public function __construct(array $coins, $minimumValueToBuy)
{
$this->coinToBuy = $coinToBuy;
$this->coinToSell = $coinToSell;
$this->coins = $coins;
$this->minimumValueToBuy = $minimumValueToBuy;
}

Expand All @@ -40,16 +37,16 @@ public function __construct($coinToSell, $coinToBuy, $minimumValueToBuy)
public function encodeData(): array
{
return [
$this->coinToSell,
$this->coinToBuy,
$this->coins,
MinterConverter::convertToPip($this->minimumValueToBuy)
];
}

public function decodeData()
{
$this->coinToSell = hexdec($this->coinToSell);
$this->coinToBuy = hexdec($this->coinToBuy);
$this->minimumValueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->minimumValueToBuy));
$this->coins = array_map(function ($value) {
return hexdec($value);
}, $this->coins);
}
}
23 changes: 10 additions & 13 deletions src/Minter/SDK/MinterCoins/MinterSellSwapPoolTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@
*/
class MinterSellSwapPoolTx extends MinterCoinTx implements MinterTxInterface
{
public $coinToBuy;
public $coinToSell;
public $coins;
public $valueToSell;
public $minimumValueToBuy;

const TYPE = 23;

/**
* MinterSellSwapPoolTx constructor.
* @param $coinToSell
* @param $valueToSell
* @param $coinToBuy
* @param $minimumValueToBuy
* @param array $coins
* @param $valueToSell
* @param $minimumValueToBuy
*/
public function __construct($coinToSell, $valueToSell, $coinToBuy, $minimumValueToBuy)
public function __construct(array $coins, $valueToSell, $minimumValueToBuy)
{
$this->coinToBuy = $coinToBuy;
$this->coinToSell = $coinToSell;
$this->coins = $coins;
$this->valueToSell = $valueToSell;
$this->minimumValueToBuy = $minimumValueToBuy;
}
Expand All @@ -43,18 +40,18 @@ public function __construct($coinToSell, $valueToSell, $coinToBuy, $minimumValue
public function encodeData(): array
{
return [
$this->coinToSell,
$this->coins,
MinterConverter::convertToPip($this->valueToSell),
$this->coinToBuy,
MinterConverter::convertToPip($this->minimumValueToBuy)
];
}

public function decodeData()
{
$this->coinToSell = hexdec($this->coinToSell);
$this->valueToSell = MinterConverter::convertToBase(Helper::hexDecode($this->valueToSell));
$this->coinToBuy = hexdec($this->coinToBuy);
$this->minimumValueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->minimumValueToBuy));
$this->coins = array_map(function ($value) {
return hexdec($value);
}, $this->coins);
}
}
15 changes: 14 additions & 1 deletion src/Minter/SDK/MinterTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@

use InvalidArgumentException;
use Minter\Contracts\MinterTxInterface;
use Minter\SDK\MinterCoins\MinterAddLiquidityTx;
use Minter\SDK\MinterCoins\MinterBurnTokenTx;
use Minter\SDK\MinterCoins\MinterBuyCoinTx;
use Minter\SDK\MinterCoins\MinterBuySwapPoolTx;
use Minter\SDK\MinterCoins\MinterCreateSwapPoolTx;
use Minter\SDK\MinterCoins\MinterCreateTokenTx;
use Minter\SDK\MinterCoins\MinterEditCoinOwnerTx;
use Minter\SDK\MinterCoins\MinterCreateCoinTx;
use Minter\SDK\MinterCoins\MinterCreateMultisigTx;
use Minter\SDK\MinterCoins\MinterDeclareCandidacyTx;
use Minter\SDK\MinterCoins\MinterDelegateTx;
use Minter\SDK\MinterCoins\MinterEditCandidateTx;
use Minter\SDK\MinterCoins\MinterMintTokenTx;
use Minter\SDK\MinterCoins\MinterMoveStakeTx;
use Minter\SDK\MinterCoins\MinterMultiSendTx;
use Minter\SDK\MinterCoins\MinterPriceCommissionTx;
use Minter\SDK\MinterCoins\MinterPriceVoteTx;
use Minter\SDK\MinterCoins\MinterRecreateCoinTx;
use Minter\SDK\MinterCoins\MinterRecreateTokenTx;
use Minter\SDK\MinterCoins\MinterRedeemCheckTx;
use Minter\SDK\MinterCoins\MinterRemoveLiquidityTx;
use Minter\SDK\MinterCoins\MinterSellAllCoinTx;
use Minter\SDK\MinterCoins\MinterSellAllSwapPoolTx;
use Minter\SDK\MinterCoins\MinterSellCoinTx;
use Minter\SDK\MinterCoins\MinterSellSwapPoolTx;
use Minter\SDK\MinterCoins\MinterSendCoinTx;
use Minter\SDK\MinterCoins\MinterSetCandidateOffTx;
use Minter\SDK\MinterCoins\MinterSetCandidateOnTx;
Expand Down Expand Up @@ -350,7 +363,7 @@ public function getSignatureData(): MinterSignature
}

/**
* @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx
* @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx|MinterSellSwapPoolTx|MinterSellAllSwapPoolTx|MinterBuySwapPoolTx|MinterPriceVoteTx|MinterPriceCommissionTx|MinterCreateTokenTx|MinterRecreateTokenTx|MinterCreateSwapPoolTx|MinterBurnTokenTx|MinterMintTokenTx|MinterAddLiquidityTx|MinterMoveStakeTx|MinterRemoveLiquidityTx
*/
public function getData(): MinterTxInterface
{
Expand Down
7 changes: 3 additions & 4 deletions tests/MinterBuySwapPoolTxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class MinterBuySwapPoolTxTest extends TestCase
/**
* Predefined valid signature
*/
const VALID_SIGNATURE = '0xf8670e0201801897d6018829a2241af62c0000808a010f0cf064dd59200000808001b845f8431ba06f309b5ebb47042147c0e6481e186bdd06d6e883b680c7f282495efb75e83423a076aa9b5da356f9075604c0f6e20ac64832b1df885fdbe28010cc006b38c48d8d';
const VALID_SIGNATURE = '0xf8680e0201801898d7c202038829a2241af62c00008a010f0cf064dd59200000808001b845f8431ca0d77c1c580754c5143abb5a3ad3f5e892ebd36e7f9f44b7da2734ffff6c2e9611a022034256303ee750a9b32b148e60c6fff34665b5854f1a9770f7ab4a8a26cc00';

/**
* Test to decode data for MinterBuySwapPoolTx
Expand All @@ -34,9 +34,8 @@ public function testDecode(): void
$this->assertSame($validTx->getGasCoin(), $tx->getGasCoin());
$this->assertSame($validTx->getGasPrice(), $tx->getGasPrice());
$this->assertSame($validTx->getChainID(), $tx->getChainID());
$this->assertSame($validTx->getData()->coinToBuy, $tx->getData()->coinToBuy);
$this->assertSame($validTx->getData()->coins, $tx->getData()->coins);
$this->assertSame($validTx->getData()->valueToBuy, $tx->getData()->valueToBuy);
$this->assertSame($validTx->getData()->coinToSell, $tx->getData()->coinToSell);
$this->assertSame($validTx->getData()->maximumValueToSell, $tx->getData()->maximumValueToSell);
$this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress());
}
Expand All @@ -55,7 +54,7 @@ public function testSign(): void
*/
private function makeTransaction(): MinterTx
{
$data = new MinterBuySwapPoolTx(1, '3', 0, '5000');
$data = new MinterBuySwapPoolTx([2, 3], '3', '5000');
return (new MinterTx(14, $data))->setChainID(MinterTx::TESTNET_CHAIN_ID);
}
}
9 changes: 4 additions & 5 deletions tests/MinterSellAllSwapPoolTxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ class MinterSellAllSwapPoolTxTest extends TestCase
/**
* Predefined valid signature
*/
const VALID_SIGNATURE = '0xf85d10020180198dcc018089056bc75e2d63100000808001b845f8431ca0e50537db70ed7263094cfaee22c69545c0c41e9efedef521c0ecce3a4f33ade6a03e71cde08a52561136584bc14707b3c01e618513b01a96b9865b44ff0395fc7a';
const VALID_SIGNATURE = '0xf85f10020180198fcec301040589056bc75e2d63100000808001b845f8431ca095651bdd2afa8964213f7bc064898b0edeb67fa39f3a0c71b52934f6463412afa0604ced9ff973bf1de6b252c9582982780cf1de4fd2b2e3814bfa8185d10bd6f5';

/**
* Test to decode data for MinterSellAllSwapPoolTx
*/
public function testDecode(): void
{
$tx = MinterTx::decode(self::VALID_SIGNATURE);
$tx = MinterTx::decode(self::VALID_SIGNATURE);
$validTx = $this->makeTransaction();

$this->assertSame($validTx->getNonce(), $tx->getNonce());
$this->assertSame($validTx->getGasCoin(), $tx->getGasCoin());
$this->assertSame($validTx->getGasPrice(), $tx->getGasPrice());
$this->assertSame($validTx->getChainID(), $tx->getChainID());
$this->assertSame($validTx->getData()->coinToBuy, $tx->getData()->coinToBuy);
$this->assertSame($validTx->getData()->coinToSell, $tx->getData()->coinToSell);
$this->assertSame($validTx->getData()->coins, $tx->getData()->coins);
$this->assertSame($validTx->getData()->minimumValueToBuy, $tx->getData()->minimumValueToBuy);
$this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress());
}
Expand All @@ -54,7 +53,7 @@ public function testSign(): void
*/
private function makeTransaction(): MinterTx
{
$data = new MinterSellAllSwapPoolTx(1, 0, '100');
$data = new MinterSellAllSwapPoolTx([1, 4, 5], '100');
return (new MinterTx(16, $data))->setChainID(MinterTx::TESTNET_CHAIN_ID);
}
}
7 changes: 3 additions & 4 deletions tests/MinterSellSwapPoolTxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class MinterSellSwapPoolTxTest extends TestCase
/**
* Predefined valid signature
*/
const VALID_SIGNATURE = '0xf866050201801796d5018901158e460913d0000080881bc16d674ec80000808001b845f8431ba09e7c9adca770f8bdb6822d447c656dd0203ae97d0284153be7d6bfc8e07c4456a03cbe6a6db71cecacd5ee149c6c518b0d61b763a9265b5f2847fd150124571ccc';
const VALID_SIGNATURE = '0xf867050201801797d6c201028901158e460913d00000881bc16d674ec80000808001b845f8431ba01ba1d7c9c05993e6d92d4db8cb24b32c9a28f61286464e41ffcaf86551f97a79a042dcd34363bd981676541b8e8f88b8bbbfcbf0746db2017be73f378afbf045c2';

/**
* Test to decode data for MinterSellSwapPoolTx
Expand All @@ -34,9 +34,8 @@ public function testDecode(): void
$this->assertSame($validTx->getGasCoin(), $tx->getGasCoin());
$this->assertSame($validTx->getGasPrice(), $tx->getGasPrice());
$this->assertSame($validTx->getChainID(), $tx->getChainID());
$this->assertSame($validTx->getData()->coinToSell, $tx->getData()->coinToSell);
$this->assertSame($validTx->getData()->coins, $tx->getData()->coins);
$this->assertSame($validTx->getData()->valueToSell, $tx->getData()->valueToSell);
$this->assertSame($validTx->getData()->coinToBuy, $tx->getData()->coinToBuy);
$this->assertSame($validTx->getData()->minimumValueToBuy, $tx->getData()->minimumValueToBuy);
$this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress());
}
Expand All @@ -55,7 +54,7 @@ public function testSign(): void
*/
private function makeTransaction(): MinterTx
{
$data = new MinterSellSwapPoolTx(1, '20', 0, '2');
$data = new MinterSellSwapPoolTx([1, 2], '20', '2');
return (new MinterTx(5, $data))->setChainID(MinterTx::TESTNET_CHAIN_ID);
}
}

0 comments on commit eedda35

Please sign in to comment.