Esempio n. 1
0
        public void Hash()
        {
            Order order = new Order
            {
                MakerAddress        = EthereumAddress.ZeroAddress,
                TakerAddress        = EthereumAddress.ZeroAddress,
                FeeRecipientAddress = EthereumAddress.ZeroAddress,
                SenderAddress       = EthereumAddress.ZeroAddress,
                MakerAssetAmount    = 1,
                TakerAssetAmount    = 1,
                MakerFee            = 1,
                TakerFee            = 1,
                Salt           = 1,
                ExpirationTime = new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc),
                MakerAsset     = ERC20Asset.Create(EthereumAddress.ZeroAddress),
                TakerAsset     = ERC20Asset.Create(EthereumAddress.ZeroAddress)
            };

            byte[] hash = order.Hash(EthereumAddress.ZeroAddress);

            byte[] expectedHash = "0xd81bf9ae7657b4fc194c63e3ed26153f05032ed0173df4069ddf619f0b26c888"
                                  .HexToByteArray();

            CollectionAssert.AreEqual(expectedHash, hash);
        }
Esempio n. 2
0
        public async Task ExchangeTokensViaSender()
        {
            EthereumAddress  exchangeAddress = (EthereumAddress)ExchangeAddress;
            ExchangeContract exchange        = new ExchangeContract(RpcURL, exchangeAddress, new Account(SenderPrivateKey));
            Order            order           = new Order
            {
                MakerAddress        = (EthereumAddress)MakerAddress,
                TakerAddress        = (EthereumAddress)TakerAddress,
                SenderAddress       = exchange.CallerAccount.Address,
                FeeRecipientAddress = exchange.CallerAccount.Address,
                MakerFee            = 10,
                TakerFee            = 10,
                MakerAssetAmount    = 100,
                TakerAssetAmount    = 100,
                MakerAsset          = ERC20Asset.Create((EthereumAddress)MakerTokenAddress),
                TakerAsset          = ERC20Asset.Create((EthereumAddress)TakerTokenAddress),
                ExpirationTime      = DateTime.UtcNow + new TimeSpan(1, 0, 0),
                Salt = Random.GenerateSalt()
            };

            byte[]      makerSignature = order.Sign(exchangeAddress, MakerPrivateKey);
            Transaction tx             = ExchangeContract.FillOrderGet0xTx(order, order.TakerAssetAmount, makerSignature);

            byte[] takerSignature = tx.Sign(exchangeAddress, TakerPrivateKey);

            string hash = await exchange.FillOrderAsync(
                order,
                order.TakerAssetAmount,
                makerSignature,
                takerSignature,
                tx.Salt,
                new TxParameters(1000000));
        }
Esempio n. 3
0
        public async Task CancelOrder()
        {
            EthereumAddress  exchangeAddress  = (EthereumAddress)ExchangeAddress;
            ExchangeContract exchangeContract = new ExchangeContract(RpcURL, exchangeAddress, new Account(MakerPrivateKey));

            Order order = new Order
            {
                MakerAddress        = (EthereumAddress)MakerAddress,
                TakerAddress        = (EthereumAddress)TakerAddress,
                SenderAddress       = EthereumAddress.ZeroAddress,
                FeeRecipientAddress = (EthereumAddress)(Web3.GetAddressFromPrivateKey(SenderPrivateKey)),
                MakerFee            = 10,
                TakerFee            = 10,
                MakerAssetAmount    = 100,
                TakerAssetAmount    = 100,
                MakerAsset          = ERC20Asset.Create((EthereumAddress)MakerTokenAddress),
                TakerAsset          = ERC20Asset.Create((EthereumAddress)TakerTokenAddress),
                ExpirationTime      = DateTime.UtcNow + new TimeSpan(1, 0, 0),
                Salt = Random.GenerateSalt()
            };

            await exchangeContract.CancelOrderAsync(order, new TxParameters(1000000));
        }
Esempio n. 4
0
        public void VerifySignature()
        {
            Order order = new Order
            {
                MakerAddress        = EthereumAddress.ZeroAddress,
                TakerAddress        = EthereumAddress.ZeroAddress,
                FeeRecipientAddress = EthereumAddress.ZeroAddress,
                SenderAddress       = EthereumAddress.ZeroAddress,
                MakerAssetAmount    = 1,
                TakerAssetAmount    = 1,
                MakerFee            = 1,
                TakerFee            = 1,
                Salt           = 1,
                ExpirationTime = new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc),
                MakerAsset     = ERC20Asset.Create(EthereumAddress.ZeroAddress),
                TakerAsset     = ERC20Asset.Create(EthereumAddress.ZeroAddress)
            };

            byte[] signature = order.Sign(EthereumAddress.ZeroAddress, Constants.TestPrivateKey);
            bool   valid     = order.VerifySignature(EthereumAddress.ZeroAddress,
                                                     (EthereumAddress)Constants.TestEthereumAddress, signature);

            Assert.IsTrue(valid);
        }
Esempio n. 5
0
        public async Task ExchangeTokens()
        {
            EthereumAddress  exchangeAddress = (EthereumAddress)ExchangeAddress;
            ExchangeContract exchange        = new ExchangeContract(RpcURL, exchangeAddress, new Account(TakerPrivateKey));
            Order            order           = new Order
            {
                MakerAddress        = (EthereumAddress)MakerAddress,
                TakerAddress        = (EthereumAddress)TakerAddress,
                SenderAddress       = (EthereumAddress)TakerAddress,
                FeeRecipientAddress = (EthereumAddress)(Web3.GetAddressFromPrivateKey(SenderPrivateKey)),
                MakerFee            = 10,
                TakerFee            = 10,
                MakerAssetAmount    = 100,
                TakerAssetAmount    = 100,
                MakerAsset          = ERC20Asset.Create((EthereumAddress)MakerTokenAddress),
                TakerAsset          = ERC20Asset.Create((EthereumAddress)TakerTokenAddress),
                ExpirationTime      = DateTime.UtcNow + new TimeSpan(1, 0, 0),
                Salt = Random.GenerateSalt()
            };

            byte[] signature = order.Sign(exchangeAddress, MakerPrivateKey);

            await exchange.FillOrderAsync(order, order.TakerAssetAmount, signature, new TxParameters(1000000));
        }
Esempio n. 6
0
        public void FillOrderExecTxCallData()
        {
            // We use invalid data just because we want to test encoding of tx data
            // for executeTransaction

            Order order = new Order
            {
                SenderAddress       = EthereumAddress.ZeroAddress,
                MakerAddress        = EthereumAddress.ZeroAddress,
                TakerAddress        = EthereumAddress.ZeroAddress,
                FeeRecipientAddress = EthereumAddress.ZeroAddress,
                MakerAssetAmount    = 0,
                TakerAssetAmount    = 0,
                MakerFee            = 0,
                TakerFee            = 0,
                ExpirationTime      = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                Salt       = 0,
                MakerAsset = ERC20Asset.Create(EthereumAddress.ZeroAddress),
                TakerAsset = ERC20Asset.Create(EthereumAddress.ZeroAddress)
            };

            BigInteger takerAssetFillAmount = 0;

            byte[] signature = new byte[1];

            CallData callData = ExchangeContract.FillOrderCallData(order, takerAssetFillAmount, signature,
                                                                   signature, 0, EthereumAddress.ZeroAddress, new Web3());

            byte[] expectedTxData = ("0xbfc8bfce00000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000008000000000000000000000000000" +
                                     "000000000000000000000000000000000003a0000000000000000000000000" +
                                     "00000000000000000000000000000000000002e4b4be83d500000000000000" +
                                     "00000000000000000000000000000000000000000000000060000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "0000000000000000000000000000000000000000000000000002a000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000180000000000000000000000000000000000000000000000000" +
                                     "00000000000001e00000000000000000000000000000000000000000000000" +
                                     "000000000000000024f47261b0000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "000000000000000000000024f47261b0000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000100000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000000000000000000000000000000000000000" +
                                     "00000000000000000000000000010000000000000000000000000000000000" +
                                     "000000000000000000000000000000").HexToByteArray();

            CollectionAssert.AreEqual(expectedTxData, callData.TxData);
        }
Esempio n. 7
0
        public void AssetUtilCreateERC20AssetData()
        {
            ERC20Asset asset = AssetUtil.Create <ERC20Asset>(_testERC20AssetData);

            Assert.AreEqual(_testAddress, asset.TokenAddress);
        }
Esempio n. 8
0
        public void ERC20AssetCreationFromAssetData()
        {
            ERC20Asset asset = ERC20Asset.Create(_testERC20AssetData);

            Assert.AreEqual(_testAddress, asset.TokenAddress);
        }
Esempio n. 9
0
 public void ERC20AssetDataEncoding()
 {
     byte[] assetData         = ERC20Asset.Create(_testAddress).AssetData;
     byte[] expectedAssetData = _testERC20AssetData;
     CollectionAssert.AreEqual(_testERC20AssetData, assetData);
 }