Skip to content

Commit

Permalink
fix: Incorrectly building trade byte parameters (#2343)
Browse files Browse the repository at this point in the history
* fix: Incorrectly building trade byte parameters

* fix: Get contract name for bids

* feat: Upgrade decentraland-dapps package

---------

Co-authored-by: Gabriel Diaz <[email protected]>
  • Loading branch information
LautaroPetaccio and cyaiox authored Dec 22, 2024
1 parent 94f3ceb commit 38be515
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
8 changes: 4 additions & 4 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dcl-catalyst-commons": "^9.0.1",
"decentraland-connect": "^7.3.2",
"decentraland-crypto-fetch": "^1.0.3",
"decentraland-dapps": "^23.17.0",
"decentraland-dapps": "^23.17.1",
"decentraland-transactions": "^2.18.0",
"decentraland-ui": "^6.12.1",
"ethers": "^5.6.8",
Expand Down
10 changes: 6 additions & 4 deletions webapp/src/modules/bid/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, BigNumber } from 'ethers'
import { Bid, Contract, TradeAssetType, TradeCreation, TradeType } from '@dcl/schemas'
import { Bid, Contract, Network, TradeAssetType, TradeCreation, TradeType } from '@dcl/schemas'
import { BidTrade } from '@dcl/schemas/dist/dapps/bid'
import { AuthorizeActionOptions } from 'decentraland-dapps/dist/containers/withAuthorizedAction'
import { getNetworkProvider, getSigner } from 'decentraland-dapps/dist/lib/eth'
Expand Down Expand Up @@ -104,14 +104,16 @@ export function getAcceptBidAuthorizationOptions(
}

const offchainMarketplaceContract = getContract(ContractName.OffChainMarketplace, bid.chainId)
const targetContractName = bid.network === Network.MATIC ? ContractName.ERC721CollectionV2 : ContractName.ERC721

const authorizeActionOptions = {
targetContractName: ContractName.ERC721CollectionV2,
targetContractLabel: targetContractLabel || ContractName.ERC721CollectionV2,
targetContractName: targetContractName,
targetContractLabel: targetContractLabel || targetContractName,
authorizedAddress: offchainMarketplaceContract.address,
targetContract: {
address: bid.contractAddress,
chainId: bid.chainId,
name: ContractName.ERC721CollectionV2,
name: targetContractName,
network: bid.network
} as Contract,
authorizedContractLabel: offchainMarketplaceContract.name,
Expand Down
14 changes: 7 additions & 7 deletions webapp/src/utils/trades.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,21 @@ describe('when getting the trade signature', () => {
externalChecks: trade.checks.externalChecks?.map(externalCheck => ({
contractAddress: externalCheck.contractAddress,
selector: externalCheck.selector,
value: externalCheck.value,
value: externalCheck.value ? externalCheck.value : '0x',
required: externalCheck.required
}))
},
sent: trade.sent.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueForTradeAsset(asset),
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra))
extra: asset.extra ? asset.extra : '0x'
})),
received: trade.received.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueForTradeAsset(asset),
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra)),
extra: asset.extra ? asset.extra : '0x',
beneficiary: asset.beneficiary
}))
}
Expand Down Expand Up @@ -199,15 +199,15 @@ describe('when getting the trade to accept', () => {
assetType: TradeAssetType.ERC20,
contractAddress: '0x123',
amount: '2',
extra: ''
extra: '0x'
}
],
received: [
{
assetType: TradeAssetType.ERC721,
contractAddress: '0x123',
tokenId: '1',
extra: '',
extra: '0x',
beneficiary: '0x123123'
}
]
Expand Down Expand Up @@ -235,14 +235,14 @@ describe('when getting the trade to accept', () => {
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueForTradeAsset(asset),
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra)),
extra: asset.extra ? asset.extra : '0x',
beneficiary: beneficiaryAddress
})),
received: trade.received.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueForTradeAsset(asset),
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra)),
extra: asset.extra ? asset.extra : '0x',
beneficiary: asset.beneficiary
}))
})
Expand Down
9 changes: 6 additions & 3 deletions webapp/src/utils/trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,24 @@ export function generateTradeValues(trade: Omit<TradeCreation, 'signature'>) {
externalChecks: trade.checks.externalChecks?.map(externalCheck => ({
contractAddress: externalCheck.contractAddress,
selector: externalCheck.selector,
value: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(externalCheck.value)),
// '0x' is the default value for value bytes (0 bytes)
value: externalCheck.value ? externalCheck.value : '0x',
required: externalCheck.required
}))
},
sent: trade.sent.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueForTradeAsset(asset),
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra))
// '0x' is the default value for extra bytes (0 bytes)
extra: asset.extra ? asset.extra : '0x'
})),
received: trade.received.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueForTradeAsset(asset),
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra)),
// '0x' is the default value for extra bytes (0 bytes)
extra: asset.extra ? asset.extra : '0x',
beneficiary: asset.beneficiary
}))
}
Expand Down

0 comments on commit 38be515

Please sign in to comment.