difftreelog
feat update MarketV2 contract
in: master
3 files changed
tests/src/eth/marketplace-v2/Market.soldiffbeforeafterboth--- a/tests/src/eth/marketplace-v2/Market.sol
+++ b/tests/src/eth/marketplace-v2/Market.sol
@@ -4,6 +4,7 @@
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";
+import { UniqueFungible, CrossAddress as CrossAddressF } from "@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol";
import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
import "./royalty/UniqueRoyaltyHelper.sol";
@@ -20,6 +21,7 @@
}
uint32 public constant version = 0;
+ uint32 public constant buildVersion = 1;
bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;
CollectionHelpers private constant collectionHelpers =
@@ -251,7 +253,7 @@
IERC721 erc721 = getErc721(collectionId);
- if (erc721.getApproved(tokenId) != selfAddress) {
+ if (erc721.getApproved(tokenId) != selfAddress || erc721.ownerOf(tokenId) != getAddressFromCrossAccount(order.seller)) {
uint32 amount = order.amount;
order.amount = 0;
emit TokenRevoke(version, order, amount);
@@ -262,6 +264,27 @@
}
}
+ function getAddressFromCrossAccount(CrossAddress memory account) private pure returns (address) {
+ if (account.eth != address(0)) {
+ return account.eth;
+ } else {
+ return address(uint160(account.sub >> 96));
+ }
+ }
+
+ function revokeAdmin(uint32 collectionId, uint32 tokenId) public onlyAdmin {
+ Order memory order = orders[collectionId][tokenId];
+ if (order.price == 0) {
+ revert OrderNotFound();
+ }
+
+ uint32 amount = order.amount;
+ order.amount = 0;
+ emit TokenRevoke(version, order, amount);
+
+ delete orders[collectionId][tokenId];
+ }
+
// ################################################################
// Buy a token #
// ################################################################
@@ -329,13 +352,14 @@
}
function sendMoney(CrossAddress memory to, uint256 money) private {
- address payable eth;
- if (to.eth != address(0)) {
- eth = payable(to.eth);
- } else {
- eth = payable(address(uint160(to.sub >> 96)));
- }
- eth.transfer(money);
+ address collectionAddress = collectionHelpers.collectionAddress(0);
+
+ UniqueFungible fungible = UniqueFungible(collectionAddress);
+
+ CrossAddressF memory fromF = CrossAddressF(selfAddress, 0);
+ CrossAddressF memory toF = CrossAddressF(to.eth, to.sub);
+
+ fungible.transferFromCross(fromF, toF, money);
}
function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {
tests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth42 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);126130127 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 contract144 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));tests/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',