git.delta.rocks / unique-network / refs/commits / 1913bf6018fe

difftreelog

Merge pull request #954 from UniqueNetwork/feature/update_market_v2_contract

Yaroslav Bolyukin2023-06-29parents: #ef738f7 #54a7967.patch.diff
in: master

4 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -47,6 +47,7 @@
     "testEthNesting": "yarn _test './**/eth/nesting/**/*.*test.ts'",
     "testEthFractionalizer": "yarn _test './**/eth/fractionalizer/**/*.*test.ts'",
     "testEthMarketplace": "yarn _test './**/eth/marketplace/**/*.*test.ts'",
+    "testEthMarket": "yarn _test './**/eth/marketplace-v2/**/*.*test.ts'",
     "testSub": "yarn _test './**/sub/**/*.*test.ts'",
     "testSubNesting": "yarn _test './**/sub/nesting/**/*.*test.ts'",
     "testEvent": "yarn _test ./src/check-event/*.*test.ts",
modifiedtests/src/eth/marketplace-v2/Market.soldiffbeforeafterboth
1// SPDX-License-Identifier: UNLICENSED1// SPDX-License-Identifier: UNLICENSED
2pragma solidity 0.8.17;2pragma solidity 0.8.17;
33
4import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
4import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";5import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
5import "@openzeppelin/contracts/token/ERC721/IERC721.sol";6import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
7import "@openzeppelin/contracts/access/Ownable.sol";
6import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";8import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";
9import { UniqueFungible, CrossAddress as CrossAddressF } from "@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol";
7import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";10import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
8import "./royalty/UniqueRoyaltyHelper.sol";11import "./royalty/UniqueRoyaltyHelper.sol";
912
10contract Market {13contract Market is Ownable, ReentrancyGuard {
11 using ERC165Checker for address;14 using ERC165Checker for address;
1215
13 struct Order {16 struct Order {
20 }23 }
2124
22 uint32 public constant version = 0;25 uint32 public constant version = 0;
26 uint32 public constant buildVersion = 3;
23 bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;27 bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
24 bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;28 bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;
25 CollectionHelpers private constant collectionHelpers =29 CollectionHelpers private constant collectionHelpers =
29 uint32 private idCount = 1;33 uint32 private idCount = 1;
30 uint32 public marketFee;34 uint32 public marketFee;
31 uint64 public ctime;35 uint64 public ctime;
32 address selfAddress;
33 address public ownerAddress;36 address public ownerAddress;
34 mapping(address => bool) public admins;37 mapping(address => bool) public admins;
3538
55 error OrderNotFound();58 error OrderNotFound();
56 error TooManyAmountRequested();59 error TooManyAmountRequested();
57 error NotEnoughMoneyError();60 error NotEnoughMoneyError();
61 error InvalidRoyaltiesError(uint256 totalRoyalty);
58 error FailTransferToken(string reason);62 error FailTransferToken(string reason);
59
60 modifier onlyOwner() {
61 require(msg.sender == ownerAddress, "Only owner can");
62 _;
63 }
6463
65 modifier onlyAdmin() {64 modifier onlyAdmin() {
66 require(msg.sender == ownerAddress || admins[msg.sender], "Only admin can");65 require(msg.sender == this.owner() || admins[msg.sender], "Only admin can");
67 _;66 _;
68 }67 }
6968
83 marketFee = fee;82 marketFee = fee;
84 ctime = timestamp;83 ctime = timestamp;
8584
86 if (marketFee == 0 || marketFee >= 100) {85 if (marketFee >= 100) {
87 revert InvalidMarketFee();86 revert InvalidMarketFee();
88 }87 }
89
90 ownerAddress = msg.sender;
91 selfAddress = address(this);
92 }88 }
89
90 /**
91 * Fallback that allows this contract to receive native token.
92 * We need this for self-sponsoring
93 */
94 fallback() external payable {}
95
96 /**
97 * Receive also allows this contract to receive native token.
98 * We need this for self-sponsoring
99 */
100 receive() external payable {}
93101
94 function getErc721(uint32 collectionId) private view returns (IERC721) {102 function getErc721(uint32 collectionId) private view returns (IERC721) {
95 address collectionAddress = collectionHelpers.collectionAddress(103 address collectionAddress = collectionHelpers.collectionAddress(
112 return IERC721(collectionAddress);120 return IERC721(collectionAddress);
113 }121 }
114122
115 // ################################################################123 /**
116 // Set new contract owner #124 * Add new admin. Only owner or an existing admin can add admins.
117 // ################################################################125 *
118126 * @param admin: Address of a new admin to add
119 function setOwner() public onlyOwner {127 */
120 ownerAddress = msg.sender;
121 }
122
123 // ################################################################
124 // Add new admin #
125 // ################################################################
126
127 function addAdmin(address admin) public onlyAdmin {128 function addAdmin(address admin) public onlyAdmin {
128 admins[admin] = true;129 admins[admin] = true;
129 }130 }
130131
131 // ################################################################132 /**
132 // Remove admin #133 * Remove an admin. Only owner or an existing admin can remove admins.
133 // ################################################################134 *
134135 * @param admin: Address of a new admin to add
136 */
135 function removeAdmin(address admin) public onlyAdmin {137 function removeAdmin(address admin) public onlyAdmin {
136 delete admins[admin];138 delete admins[admin];
137 }139 }
138140
139 // ################################################################141 /**
140 // Place a token for sale #142 * Place an NFT or RFT token for sale. It must be pre-approved for transfers by this contract address.
141 // ################################################################143 *
142144 * @param collectionId: ID of the token collection
145 * @param tokenId: ID of the token
146 * @param price: Price (with proper network currency decimals)
147 * @param amount: Number of token fractions to list (must always be 1 for NFT)
148 * @param seller: The seller cross-address (the beneficiary account to receive payment, may be different from transaction sender)
149 */
143 function put(150 function put(
144 uint32 collectionId,151 uint32 collectionId,
145 uint32 tokenId,152 uint32 tokenId,
164 revert SellerIsNotOwner();171 revert SellerIsNotOwner();
165 }172 }
166173
167 if (erc721.getApproved(tokenId) != selfAddress) {174 if (erc721.getApproved(tokenId) != address(this)) {
168 revert TokenIsNotApproved();175 revert TokenIsNotApproved();
169 }176 }
170177
183 emit TokenIsUpForSale(version, order);190 emit TokenIsUpForSale(version, order);
184 }191 }
185192
186 // ################################################################193 /**
187 // Get order #194 * Get information about the listed token order
188 // ################################################################195 *
189196 * @param collectionId: ID of the token collection
197 * @param tokenId: ID of the token
198 * @return The order information
199 */
190 function getOrder(200 function getOrder(
191 uint32 collectionId,201 uint32 collectionId,
192 uint32 tokenId202 uint32 tokenId
193 ) external view returns (Order memory) {203 ) external view returns (Order memory) {
194 return orders[collectionId][tokenId];204 return orders[collectionId][tokenId];
195 }205 }
196206
197 // ################################################################207 /**
198 // Revoke the token from the sale #208 * Revoke the token from the sale. Only the original lister can use this method.
199 // ################################################################209 *
200210 * @param collectionId: ID of the token collection
211 * @param tokenId: ID of the token
212 * @param amount: Number of token fractions to de-list (must always be 1 for NFT)
213 */
201 function revoke(214 function revoke(
202 uint32 collectionId,215 uint32 collectionId,
203 uint32 tokenId,216 uint32 tokenId,
239 emit TokenRevoke(version, order, amount);252 emit TokenRevoke(version, order, amount);
240 }253 }
241254
242 // ################################################################255 /**
243 // Check approved #256 * Test if the token is still approved to be transferred by this contract and delete the order if not.
244 // ################################################################257 *
245258 * @param collectionId: ID of the token collection
259 * @param tokenId: ID of the token
260 */
246 function checkApproved(uint32 collectionId, uint32 tokenId) public onlyAdmin {261 function checkApproved(uint32 collectionId, uint32 tokenId) public onlyAdmin {
247 Order memory order = orders[collectionId][tokenId];262 Order memory order = orders[collectionId][tokenId];
248 if (order.price == 0) {263 if (order.price == 0) {
251266
252 IERC721 erc721 = getErc721(collectionId);267 IERC721 erc721 = getErc721(collectionId);
253268
254 if (erc721.getApproved(tokenId) != selfAddress) {269 if (erc721.getApproved(tokenId) != address(this) || erc721.ownerOf(tokenId) != getAddressFromCrossAccount(order.seller)) {
255 uint32 amount = order.amount;270 uint32 amount = order.amount;
256 order.amount = 0;271 order.amount = 0;
257 emit TokenRevoke(version, order, amount);272 emit TokenRevoke(version, order, amount);
262 }277 }
263 }278 }
264279
265 // ################################################################280 function getAddressFromCrossAccount(CrossAddress memory account) private pure returns (address) {
266 // Buy a token #281 if (account.eth != address(0)) {
267 // ################################################################282 return account.eth;
268283 } else {
284 return address(uint160(account.sub >> 96));
285 }
286 }
287
288 /**
289 * Revoke the token from the sale. Only the contract admin can use this method.
290 *
291 * @param collectionId: ID of the token collection
292 * @param tokenId: ID of the token
293 */
294 function revokeAdmin(uint32 collectionId, uint32 tokenId) public onlyAdmin {
295 Order memory order = orders[collectionId][tokenId];
296 if (order.price == 0) {
297 revert OrderNotFound();
298 }
299
300 uint32 amount = order.amount;
301 order.amount = 0;
302 emit TokenRevoke(version, order, amount);
303
304 delete orders[collectionId][tokenId];
305 }
306
307 /**
308 * Buy a token (partially for an RFT).
309 *
310 * @param collectionId: ID of the token collection
311 * @param tokenId: ID of the token
312 * @param amount: Number of token fractions to buy (must always be 1 for NFT)
313 * @param buyer: Cross-address of the buyer, eth part must be equal to the transaction signer address
314 */
269 function buy(315 function buy(
270 uint32 collectionId,316 uint32 collectionId,
271 uint32 tokenId,317 uint32 tokenId,
272 uint32 amount,318 uint32 amount,
273 CrossAddress memory buyer319 CrossAddress memory buyer
274 ) public payable validCrossAddress(buyer.eth, buyer.sub) {320 ) public payable validCrossAddress(buyer.eth, buyer.sub) nonReentrant {
275 if (msg.value == 0) {321 if (msg.value == 0) {
276 revert InvalidArgument("msg.value must not be zero");322 revert InvalidArgument("msg.value must not be zero");
277 }323 }
296 }342 }
297343
298 IERC721 erc721 = getErc721(order.collectionId);344 IERC721 erc721 = getErc721(order.collectionId);
299 if (erc721.getApproved(tokenId) != selfAddress) {345 if (erc721.getApproved(tokenId) != address(this)) {
300 revert TokenIsNotApproved();346 revert TokenIsNotApproved();
301 }347 }
302348
316 order.tokenId362 order.tokenId
317 );363 );
318364
319 (uint256 totalRoyalty, RoyaltyAmount[] memory royalties) = sendRoyalties(collectionAddress, tokenId, totalValue);365 (uint256 totalRoyalty, RoyaltyAmount[] memory royalties) = sendRoyalties(collectionAddress, tokenId, totalValue - feeValue);
366
367 if (totalRoyalty >= totalValue - feeValue) {
368 revert InvalidRoyaltiesError(totalRoyalty);
369 }
320370
321 sendMoney(order.seller, totalValue - feeValue - totalRoyalty);371 sendMoney(order.seller, totalValue - feeValue - totalRoyalty);
322372
323 if (msg.value > totalValue) {373 if (msg.value > totalValue) {
324 // todo, send money to signer or buyer ?
325 payable(msg.sender).transfer(msg.value - totalValue);374 sendMoney(buyer, msg.value - totalValue);
326 }375 }
327376
328 emit TokenIsPurchased(version, order, amount, buyer, royalties);377 emit TokenIsPurchased(version, order, amount, buyer, royalties);
329 }378 }
330379
331 function sendMoney(CrossAddress memory to, uint256 money) private {380 function sendMoney(CrossAddress memory to, uint256 money) private {
332 address payable eth;381 address collectionAddress = collectionHelpers.collectionAddress(0);
382
333 if (to.eth != address(0)) {383 UniqueFungible fungible = UniqueFungible(collectionAddress);
384
334 eth = payable(to.eth);385 CrossAddressF memory fromF = CrossAddressF(address(this), 0);
335 } else {
336 eth = payable(address(uint160(to.sub >> 96)));386 CrossAddressF memory toF = CrossAddressF(to.eth, to.sub);
337 }387
338 eth.transfer(money);388 fungible.transferFromCross(fromF, toF, money);
339 }389 }
340390
341 function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {391 function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {
355 }405 }
356406
357 function withdraw(address transferTo) public onlyOwner {407 function withdraw(address transferTo) public onlyOwner {
358 uint256 balance = selfAddress.balance;408 uint256 balance = address(this).balance;
359409
360 if (balance > 0) {410 if (balance > 0) {
361 payable(transferTo).transfer(balance);411 payable(transferTo).transfer(balance);
modifiedtests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth
--- a/tests/src/eth/marketplace-v2/marketplace.test.ts
+++ b/tests/src/eth/marketplace-v2/marketplace.test.ts
@@ -16,13 +16,15 @@
 
 import {IKeyringPair} from '@polkadot/types/types';
 import {readFile} from 'fs/promises';
-import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util';
+import {EthUniqueHelper, SponsoringMode, itEth, usingEthPlaygrounds} from '../util';
 import {makeNames} from '../../util';
 import {expect} from 'chai';
 import Web3 from 'web3';
 
 const {dirname} = makeNames(import.meta.url);
 
+const MARKET_FEE = 1;
+
 describe('Market V2 Contract', () => {
   let donor: IKeyringPair;
 
@@ -43,10 +45,26 @@
           fsPath: `${dirname}/../api/UniqueNFT.sol`,
         },
         {
+          solPath: '@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol',
+          fsPath: `${dirname}/../api/UniqueFungible.sol`,
+        },
+        {
           solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',
           fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,
         },
         {
+          solPath: '@openzeppelin/contracts/access/Ownable.sol',
+          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/access/Ownable.sol`,
+        },
+        {
+          solPath: '@openzeppelin/contracts/utils/Context.sol',
+          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/Context.sol`,
+        },
+        {
+          solPath: '@openzeppelin/contracts/security/ReentrancyGuard.sol',
+          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol`,
+        },
+        {
           solPath: '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol',
           fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol`,
         },
@@ -72,7 +90,7 @@
         },
       ],
       15000000,
-      [1, 0],
+      [MARKET_FEE, 0],
     );
   }
 
@@ -90,63 +108,135 @@
   });
 
   itEth('Put + Buy [eth]', async ({helper}) => {
-    const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);
+    const ONE_TOKEN = helper.balance.getOneTokenNominal();
+    const PRICE = 2n * ONE_TOKEN;  // 2 UNQ
+    const marketOwner = await helper.eth.createAccountWithBalance(donor, 60000n);
     const market = await deployMarket(helper, marketOwner);
+    const contractHelpers = helper.ethNativeContract.contractHelpers(marketOwner);
+
+    // Set external sponsoring
+    await contractHelpers.methods.setSponsor(market.options.address, marketOwner).send({from: marketOwner});
+    await contractHelpers.methods.confirmSponsorship(market.options.address).send({from: marketOwner});
 
+    // Configure sponsoring
+    await contractHelpers.methods.setSponsoringMode(market.options.address, SponsoringMode.Generous).send({from: marketOwner});
+    await contractHelpers.methods.setSponsoringRateLimit(market.options.address, 0).send({from: marketOwner});
+
     const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');
-    const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);
+    const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner, true);
+
+    // Set collection sponsoring
+    await collection.methods.setCollectionSponsor(marketOwner).send({from: marketOwner});
+    await collection.methods.confirmCollectionSponsorship().send({from: marketOwner});
 
-    const sellerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);
+    const sellerCross = helper.ethCrossAccount.createAccount();
     const result = await collection.methods.mintCross(sellerCross, []).send();
     const tokenId = result.events.Transfer.returnValues.tokenId;
     await collection.methods.approve(market.options.address, tokenId).send({from: sellerCross.eth});
 
-    const putResult = await market.methods.put(collectionId, tokenId, 1, 1, sellerCross).send({from: sellerCross.eth});
+    // Seller has no funds at all, his transactions are sponsored
+    const sellerBalance = await helper.balance.getEthereum(sellerCross.eth);
+    expect(sellerBalance).to.be.eq(0n);
+
+    const putResult = await market.methods.put(collectionId, tokenId, PRICE.toString(), 1, sellerCross).send({
+      from: sellerCross.eth, gasLimit: 1_000_000,
+    });
     expect(putResult.events.TokenIsUpForSale).is.not.undefined;
+
+    // Seller balance are still 0
+    const sellerBalanceAfter = await helper.balance.getEthereum(sellerCross.eth);
+    expect(sellerBalanceAfter).to.be.eq(0n);
+
     let ownerCross = await collection.methods.ownerOfCross(tokenId).call();
     expect(ownerCross.eth).to.be.eq(sellerCross.eth);
     expect(ownerCross.sub).to.be.eq(sellerCross.sub);
 
-    const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);
-    const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: 1});
+    const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 10n);
+
+    // Buyer has only 10 UNQ
+    const buyerBalance = await helper.balance.getEthereum(buyerCross.eth);
+    expect(buyerBalance).to.be.eq(10n * ONE_TOKEN);
+
+    const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: PRICE.toString(), gasLimit: 1_000_000});
     expect(buyResult.events.TokenIsPurchased).is.not.undefined;
+
+    // Buyer pays only value, transaction use sponsoring
+    const buyerBalanceAfter = await helper.balance.getEthereum(buyerCross.eth);
+    expect(buyerBalanceAfter).to.be.eq(10n * ONE_TOKEN - PRICE);
+
     ownerCross = await collection.methods.ownerOfCross(tokenId).call();
     expect(ownerCross.eth).to.be.eq(buyerCross.eth);
     expect(ownerCross.sub).to.be.eq(buyerCross.sub);
   });
 
   itEth('Put + Buy [sub]', async ({helper}) => {
-    const PRICE = 1n;
+    const ONE_TOKEN = helper.balance.getOneTokenNominal();
+    const PRICE = 2n * ONE_TOKEN;  // 2 UNQ
     const web3 = helper.getWeb3();
     const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);
     const market = await deployMarket(helper, marketOwner);
+    const contractHelpers = helper.ethNativeContract.contractHelpers(marketOwner);
+
+    // Set self sponsoring from contract balance
+    await contractHelpers.methods.selfSponsoredEnable(market.options.address).send({from: marketOwner});
+    await helper.eth.transferBalanceFromSubstrate(donor, market.options.address, 10n);
+
+    // Configure sponsoring
+    await contractHelpers.methods.setSponsoringMode(market.options.address, SponsoringMode.Generous).send({from: marketOwner});
+    await contractHelpers.methods.setSponsoringRateLimit(market.options.address, 0).send({from: marketOwner});
 
     const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');
-    const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);
+    const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner, true);
+
+    // Set collection sponsoring
+    await collection.methods.setCollectionSponsor(marketOwner).send({from: marketOwner});
+    await collection.methods.confirmCollectionSponsorship().send({from: marketOwner});
 
-    const [seller] = await helper.arrange.createAccounts([600n], donor);
-    const sellerMirror = helper.address.substrateToEth(seller.address);
+    const seller = helper.util.fromSeed(`//Market-seller-${(new Date()).getTime()}`);
     const sellerCross = helper.ethCrossAccount.fromKeyringPair(seller);
+
+    // Seller has no funds at all, his transactions are sponsored
+    {
+      const sellerBalance = await helper.balance.getSubstrate(seller.address);
+      expect(sellerBalance).to.be.eq(0n);
+    }
+
     const result = await collection.methods.mintCross(sellerCross, []).send();
     const tokenId = result.events.Transfer.returnValues.tokenId;
-    await helper.nft.approveToken(seller, collectionId, tokenId, {Ethereum: market.options.address}, 1n);
+    await helper.nft.approveToken(seller, collectionId, tokenId, {Ethereum: market.options.address});
 
     await helper.eth.sendEVM(seller, market.options.address, market.methods.put(collectionId, tokenId, PRICE, 1, sellerCross).encodeABI(), '0');
+    // Seller balance is still zero
+    {
+      const sellerBalance = await helper.balance.getSubstrate(seller.address);
+      expect(sellerBalance).to.be.eq(0n);
+    }
     let ownerCross = await collection.methods.ownerOfCross(tokenId).call();
     expect(ownerCross.eth).to.be.eq(sellerCross.eth);
     expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(sellerCross.sub, web3));
 
     const [buyer] = await helper.arrange.createAccounts([600n], donor);
+    // Buyer has only expected balance
+    {
+      const buyerBalance = await helper.balance.getSubstrate(buyer.address);
+      expect(buyerBalance).to.be.eq(600n * ONE_TOKEN);
+    }
     const buyerMirror = helper.address.substrateToEth(buyer.address);
     const buyerCross = helper.ethCrossAccount.fromKeyringPair(buyer);
-    await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, 1n);
-    //TODO: change balance check to helper.balance.getSubstrate when implementation of sendMoney will be fixed in contract
-    const sellerBalance = BigInt(await web3.eth.getBalance(sellerMirror));
+    await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, PRICE, false);
+
+    const buyerBalanceBefore = await helper.balance.getSubstrate(buyer.address);
     await helper.eth.sendEVM(buyer, market.options.address, market.methods.buy(collectionId, tokenId, 1, buyerCross).encodeABI(), PRICE.toString());
-    const sellerBalanceAfterBuy = BigInt(await web3.eth.getBalance(sellerMirror));
+    const buyerBalanceAfter = await helper.balance.getSubstrate(buyer.address);
+    // Buyer balance not changed: transaction is sponsored
+    expect(buyerBalanceBefore).to.be.eq(buyerBalanceAfter);
+
+    const sellerBalanceAfterBuy = BigInt(await helper.balance.getSubstrate(seller.address));
     ownerCross = await collection.methods.ownerOfCross(tokenId).call();
     expect(ownerCross.eth).to.be.eq(buyerCross.eth);
     expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(buyerCross.sub, web3));
-    expect(sellerBalance + PRICE).to.be.equal(sellerBalanceAfterBuy);
+
+    // Seller got only PRICE - MARKET_FEE
+    expect(sellerBalanceAfterBuy).to.be.eq(PRICE * BigInt(100 - MARKET_FEE) / 100n);
   });
 });
modifiedtests/src/eth/tokenProperties.test.tsdiffbeforeafterboth
--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -561,10 +561,10 @@
     itEth.ifWithPallets(`[${testCase.mode}] Can't be multiple set/read for non-existent token`, testCase.requiredPallets, async({helper}) => {
       const caller = await helper.eth.createAccountWithBalance(donor);
 
-      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
-      const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
+      const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));
+      const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {tokenOwner: true,
         collectionAdmin: true,
-        mutable: true}}; });
+        mutable: true}}));
 
       const collection = await helper[testCase.mode].mintCollection(alice, {
         tokenPrefix: 'ethp',