Skip to content

Commit

Permalink
fix doTransfers when feeside is NONE
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenynacu committed Jun 16, 2021
1 parent f62e271 commit 37f28e8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
3 changes: 3 additions & 0 deletions exchange-v2/contracts/RaribleTransferManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ abstract contract RaribleTransferManager is OwnableUpgradeable, ITransferManager
} else if (feeSide == LibFeeSide.FeeSide.TAKE) {
totalTakeValue = doTransfersWithFees(fill.takeValue, rightOrder.maker, rightOrderData, leftOrderData, takeMatch, makeMatch, TO_MAKER);
transferPayouts(makeMatch, fill.makeValue, leftOrder.maker, rightOrderData.payouts, TO_TAKER);
} else {
transferPayouts(makeMatch, fill.makeValue, leftOrder.maker, rightOrderData.payouts, TO_TAKER);
transferPayouts(takeMatch, fill.takeValue, rightOrder.maker, leftOrderData.payouts, TO_MAKER);
}
}

Expand Down
3 changes: 2 additions & 1 deletion exchange-v2/test-exchangev2-rarible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ truffle test \
./test/contracts/v2/TransferProxyTest.sol \
./test/contracts/v2/RaribleTransferManagerTest.sol \
./test/contracts/v2/TestRoyaltiesRegistry.sol \
./test/contracts/tokens/TestERC721WithRoyaltyV1OwnableUpgradeable.sol
./test/contracts/tokens/TestERC721WithRoyaltyV1OwnableUpgradeable.sol \
--compile-all
3 changes: 2 additions & 1 deletion exchange-v2/test-rarible-transfer-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ truffle test \
./test/contracts/tokens/TestERC1155WithRoyaltiesV1.sol \
./test/contracts/tokens/TestERC1155WithRoyaltiesV2.sol \
./test/contracts/tokens/TestERC721WithRoyaltiesV1_InterfaceError.sol \
./test/contracts/tokens/TestERC1155WithRoyaltiesV2_InterfaceError.sol
./test/contracts/tokens/TestERC1155WithRoyaltiesV2_InterfaceError.sol \
--compile-all



36 changes: 28 additions & 8 deletions exchange-v2/test/v2/RaribleManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
assert.equal(await erc1155.balanceOf(accounts[2], erc1155TokenId1), 3);
})

async function prepareETH_1155Orders(t2Amount = 10) {
async function prepareETH_1155Orders(t2Amount = 10) {
await erc1155.mint(accounts[2], erc1155TokenId1, t2Amount);
await erc1155.setApprovalForAll(transferProxy.address, true, {from: accounts[2]});

Expand All @@ -106,7 +106,27 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
return { left, right }
}

it("Transfer from ERC721 to ERC1155, (buyerFee3%, sallerFee3% = 6%) of ERC1155 transfer to community, orders dataType == V1", async () => {
it("Transfer from ERC721 to ERC721", async () => {
const { left, right } = await prepare721_721Orders()

await testing.checkDoTransfers(left.makeAsset.assetType, left.takeAsset.assetType, [1, 1], left, right);

assert.equal(await erc721.ownerOf(erc721TokenId1), accounts[2]);
assert.equal(await erc721.ownerOf(erc721TokenId0), accounts[1]);
})

async function prepare721_721Orders() {
await erc721.mint(accounts[1], erc721TokenId1);
await erc721.mint(accounts[2], erc721TokenId0);
await erc721.setApprovalForAll(transferProxy.address, true, {from: accounts[1]});
await erc721.setApprovalForAll(transferProxy.address, true, {from: accounts[2]});
let data = await encDataV1([ [], []]);
const left = Order(accounts[1], Asset(ERC721, enc(erc721.address, erc721TokenId1), 1), ZERO, Asset(ERC721, enc(erc721.address, erc721TokenId0), 1), 1, 0, 0, ORDER_DATA_V1, data);
const right = Order(accounts[2], Asset(ERC721, enc(erc721.address, erc721TokenId0), 1), ZERO, Asset(ERC721, enc(erc721.address, erc721TokenId1), 1), 1, 0, 0, ORDER_DATA_V1, data);
return { left, right }
}

it("Transfer from ERC721 to ERC1155, (buyerFee3%, sallerFee3% = 6%) of ERC1155 transfer to community, orders dataType == V1", async () => {
const { left, right } = await prepare721_1155Orders(110)

await testing.checkDoTransfers(left.makeAsset.assetType, left.takeAsset.assetType, [1, 100], left, right);
Expand Down Expand Up @@ -190,7 +210,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
assert.equal(await erc1155.balanceOf(protocol, erc1155TokenId1), 6);
})

async function prepare1155O_721rders(t2Amount = 105) {
async function prepare1155O_721rders(t2Amount = 105) {
await erc1155.mint(accounts[1], erc1155TokenId1, t2Amount);
await erc721.mint(accounts[2], erc721TokenId1);
await erc1155.setApprovalForAll(transferProxy.address, true, {from: accounts[1]});
Expand All @@ -201,7 +221,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
return { left, right }
}

it("Transfer from ERC20 to ERC1155, protocol fee 6% (buyerFee3%, sallerFee3%)", async () => {
it("Transfer from ERC20 to ERC1155, protocol fee 6% (buyerFee3%, sallerFee3%)", async () => {
const { left, right } = await prepare20_1155Orders(105, 10)

await testing.checkDoTransfers(left.makeAsset.assetType, left.takeAsset.assetType, [100, 7], left, right);
Expand All @@ -213,7 +233,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
assert.equal(await t1.balanceOf(protocol), 6);
})

async function prepare20_1155Orders(t1Amount = 105, t2Amount = 10) {
async function prepare20_1155Orders(t1Amount = 105, t2Amount = 10) {
await t1.mint(accounts[1], t1Amount);
await erc1155.mint(accounts[2], erc1155TokenId1, t2Amount);
await t1.approve(erc20TransferProxy.address, 10000000, { from: accounts[1] });
Expand All @@ -236,7 +256,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
assert.equal(await t1.balanceOf(protocol), 6);
})

async function prepare1155_20Orders(t1Amount = 10, t2Amount = 105) {
async function prepare1155_20Orders(t1Amount = 10, t2Amount = 105) {
await erc1155.mint(accounts[3], erc1155TokenId2, t1Amount);
await t1.mint(accounts[4], t2Amount);
await erc1155.setApprovalForAll(transferProxy.address, true, {from: accounts[3]});
Expand Down Expand Up @@ -371,7 +391,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
return { left, right }
}

it("Transfer from ERC1155(RoyaltiesV1) to ERC20, protocol fee 6% (buyerFee3%, sallerFee3%)", async () => {
it("Transfer from ERC1155(RoyaltiesV1) to ERC20, protocol fee 6% (buyerFee3%, sallerFee3%)", async () => {
const { left, right } = await prepare1155V1_20Orders(8, 105)

await testing.checkDoTransfers(left.makeAsset.assetType, left.takeAsset.assetType, [5, 100], left, right);
Expand Down Expand Up @@ -444,7 +464,7 @@ contract("RaribleTransferManagerTest:doTransferTest()", accounts => {
assert.equal(await erc1155V2.balanceOf(accounts[1], erc1155TokenId1), 3);
})

async function prepareETH_1155V2Orders(t2Amount = 10) {
async function prepareETH_1155V2Orders(t2Amount = 10) {
await erc1155V2.mint(accounts[1], erc1155TokenId1, [], t2Amount);
await erc1155V2.setApprovalForAll(transferProxy.address, true, {from: accounts[1]});
await royaltiesRegistry.setRoyaltiesByToken(erc1155V2.address, [[accounts[2], 1000], [accounts[3], 500]]); //set royalties by token
Expand Down

0 comments on commit 37f28e8

Please sign in to comment.