git.delta.rocks / unique-network / refs/commits / 71175e37f6f9

difftreelog

feat update MarketV2 contract

Grigoriy Simonov2023-06-16parent: #e1f20e1.patch.diff
in: master

3 files changed

modifiedtests/src/eth/marketplace-v2/Market.soldiffbeforeafterboth
4import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";4import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
5import "@openzeppelin/contracts/token/ERC721/IERC721.sol";5import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
6import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";6import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";
7import { UniqueFungible, CrossAddress as CrossAddressF } from "@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol";
7import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";8import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
8import "./royalty/UniqueRoyaltyHelper.sol";9import "./royalty/UniqueRoyaltyHelper.sol";
910
20 }21 }
2122
22 uint32 public constant version = 0;23 uint32 public constant version = 0;
24 uint32 public constant buildVersion = 1;
23 bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;25 bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
24 bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;26 bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;
25 CollectionHelpers private constant collectionHelpers =27 CollectionHelpers private constant collectionHelpers =
251253
252 IERC721 erc721 = getErc721(collectionId);254 IERC721 erc721 = getErc721(collectionId);
253255
254 if (erc721.getApproved(tokenId) != selfAddress) {256 if (erc721.getApproved(tokenId) != selfAddress || erc721.ownerOf(tokenId) != getAddressFromCrossAccount(order.seller)) {
255 uint32 amount = order.amount;257 uint32 amount = order.amount;
256 order.amount = 0;258 order.amount = 0;
257 emit TokenRevoke(version, order, amount);259 emit TokenRevoke(version, order, amount);
262 }264 }
263 }265 }
266
267 function getAddressFromCrossAccount(CrossAddress memory account) private pure returns (address) {
268 if (account.eth != address(0)) {
269 return account.eth;
270 } else {
271 return address(uint160(account.sub >> 96));
272 }
273 }
274
275 function revokeAdmin(uint32 collectionId, uint32 tokenId) public onlyAdmin {
276 Order memory order = orders[collectionId][tokenId];
277 if (order.price == 0) {
278 revert OrderNotFound();
279 }
280
281 uint32 amount = order.amount;
282 order.amount = 0;
283 emit TokenRevoke(version, order, amount);
284
285 delete orders[collectionId][tokenId];
286 }
264287
265 // ################################################################288 // ################################################################
266 // Buy a token #289 // Buy a token #
329 }352 }
330353
331 function sendMoney(CrossAddress memory to, uint256 money) private {354 function sendMoney(CrossAddress memory to, uint256 money) private {
332 address payable eth;355 address collectionAddress = collectionHelpers.collectionAddress(0);
356
333 if (to.eth != address(0)) {357 UniqueFungible fungible = UniqueFungible(collectionAddress);
358
334 eth = payable(to.eth);359 CrossAddressF memory fromF = CrossAddressF(selfAddress, 0);
335 } else {
336 eth = payable(address(uint160(to.sub >> 96)));360 CrossAddressF memory toF = CrossAddressF(to.eth, to.sub);
337 }361
338 eth.transfer(money);362 fungible.transferFromCross(fromF, toF, money);
339 }363 }
340364
341 function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {365 function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {
modifiedtests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth
42 solPath: '@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol',42 solPath: '@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol',
43 fsPath: `${dirname}/../api/UniqueNFT.sol`,43 fsPath: `${dirname}/../api/UniqueNFT.sol`,
44 },44 },
45 {
46 solPath: '@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol',
47 fsPath: `${dirname}/../api/UniqueFungible.sol`,
48 },
45 {49 {
46 solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',50 solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',
47 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,51 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,
125 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);129 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);
126130
127 const [seller] = await helper.arrange.createAccounts([600n], donor);131 const [seller] = await helper.arrange.createAccounts([600n], donor);
128 const sellerMirror = helper.address.substrateToEth(seller.address);
129 const sellerCross = helper.ethCrossAccount.fromKeyringPair(seller);132 const sellerCross = helper.ethCrossAccount.fromKeyringPair(seller);
130 const result = await collection.methods.mintCross(sellerCross, []).send();133 const result = await collection.methods.mintCross(sellerCross, []).send();
131 const tokenId = result.events.Transfer.returnValues.tokenId;134 const tokenId = result.events.Transfer.returnValues.tokenId;
140 const buyerMirror = helper.address.substrateToEth(buyer.address);143 const buyerMirror = helper.address.substrateToEth(buyer.address);
141 const buyerCross = helper.ethCrossAccount.fromKeyringPair(buyer);144 const buyerCross = helper.ethCrossAccount.fromKeyringPair(buyer);
142 await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, 1n);145 await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, 1n);
143 //TODO: change balance check to helper.balance.getSubstrate when implementation of sendMoney will be fixed in contract
144 const sellerBalance = BigInt(await web3.eth.getBalance(sellerMirror));146 const sellerBalance = BigInt(await helper.balance.getSubstrate(seller.address));
145 await helper.eth.sendEVM(buyer, market.options.address, market.methods.buy(collectionId, tokenId, 1, buyerCross).encodeABI(), PRICE.toString());147 await helper.eth.sendEVM(buyer, market.options.address, market.methods.buy(collectionId, tokenId, 1, buyerCross).encodeABI(), PRICE.toString());
146 const sellerBalanceAfterBuy = BigInt(await web3.eth.getBalance(sellerMirror));148 const sellerBalanceAfterBuy = BigInt(await helper.balance.getSubstrate(seller.address));
147 ownerCross = await collection.methods.ownerOfCross(tokenId).call();149 ownerCross = await collection.methods.ownerOfCross(tokenId).call();
148 expect(ownerCross.eth).to.be.eq(buyerCross.eth);150 expect(ownerCross.eth).to.be.eq(buyerCross.eth);
149 expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(buyerCross.sub, web3));151 expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(buyerCross.sub, web3));
modifiedtests/src/eth/tokenProperties.test.tsdiffbeforeafterboth
561 itEth.ifWithPallets(`[${testCase.mode}] Can't be multiple set/read for non-existent token`, testCase.requiredPallets, async({helper}) => {561 itEth.ifWithPallets(`[${testCase.mode}] Can't be multiple set/read for non-existent token`, testCase.requiredPallets, async({helper}) => {
562 const caller = await helper.eth.createAccountWithBalance(donor);562 const caller = await helper.eth.createAccountWithBalance(donor);
563563
564 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });564 const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));
565 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,565 const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {tokenOwner: true,
566 collectionAdmin: true,566 collectionAdmin: true,
567 mutable: true}}; });567 mutable: true}}));
568568
569 const collection = await helper[testCase.mode].mintCollection(alice, {569 const collection = await helper[testCase.mode].mintCollection(alice, {
570 tokenPrefix: 'ethp',570 tokenPrefix: 'ethp',