feat(nft-swap): nft swap PoC and multi standalone swap contracts v2#7
feat(nft-swap): nft swap PoC and multi standalone swap contracts v2#7
Conversation
…ade-v2 # Conflicts: # contracts/EtomicSwapV2.sol # test/EtomicSwapV2.js
shamardy
left a comment
There was a problem hiding this comment.
Thanks for the PR! Mid sprint review!
| require(params.taker != address(0), "Taker must not be zero address"); | ||
| require( | ||
| params.tokenAddress != address(0), | ||
| "Token must not be zero address" | ||
| ); | ||
| require( | ||
| msg.sender == params.tokenAddress, | ||
| "Token address does not match sender" | ||
| ); | ||
| require(operator == from, "Operator must be the sender"); | ||
| require(value > 0, "Value must be greater than 0"); | ||
| require( | ||
| makerPayments[params.id].state == MakerPaymentState.Uninitialized, | ||
| "Maker ERC1155 payment must be Uninitialized" | ||
| ); | ||
| require(!isContract(params.taker), "Taker cannot be a contract"); |
There was a problem hiding this comment.
Order of requires is changed from ETH/ERC20 contract, shouldn't
require(
makerPayments[params.id].state == MakerPaymentState.Uninitialized,
"Maker ERC1155 payment must be Uninitialized"
);be first?
…initialized before the rest of the checks in on...Received funcs
r2st
left a comment
There was a problem hiding this comment.
Can Erc721 and Erc1155 functions be combined ? That will reduce the code size.
"amount" can be zero for Erc721 and greater than zero for Erc1155
Hmmm good idea. Im just thinking about compromise between the deploy cost (on our side) and gas cost for each function (on taker/maker sides). The explicit separation of erc721 and erc1155 functions offers clear distinction and type safety, reducing the chance of incorrect token transfer. But I will do gas cost checks for combined function versions, so we can decide. |
added combined spend NFT call here dffa69e Spend combined ERC721 Gas used: 77669 Spend separate ERC721 Gas used: 74022 gas usage increased by ~3000. this gas cost is kinda significant. I would like to stick with separate function implementation. Because even if we combine
By above ^ I mean that we need to deploy contract once, while users do swaps constantly. But Im curious about @shamardy opinion. What do you think? |
Agree that gas increase is significant, having 4 contracts is fine (4 because there is also the ERC20-ERC20 or Taker Coin <-> Maker Coin normal contract done by Artem). Deployment cost will increase for sure but I don't see a way around it. But I think the below:
is not entirely right, basically a contract is for locking and spending or refunding if we do it as above it we will duplicate code across contracts, we should have contracts for: so for instance for erc20-erc20 swap, the maker will use one contract and the taker will use another, the taker will extract the secret from one contract and use this secret in the other one. BTW, did you consider having 2 contracts, one for maker for any coin/token/NFT and another for taker for the same, maybe this will not pass the contract size since we will not duplicate some of the structs. P.S. Maybe we should take a look at The Diamond Standard (EIP-2535) ref: |
ohh, exactly!!! we could just call different contracts for each side. This should work!
nope, I wanted to group swap contracts by assets types:
The approach above ^ avoids calling different swap addresses. I thought that it will be bad if two etomic swap contracts will be involved in swap process. But now I see that there is actually no problem with involving two contracts.
thanks to such grouping in komodefi swap impl we easily can understand by maker/taker asset type which etomic contract we should call in maker and taker operations. Of course it also avoids code duplication.
Very interesting pattern. Also I think that while diamond standard reduces the total number of contracts, the initial deployment still could be gas-intensive due to the setup of multiple facets. Well maybe slightly cheaper, than 4 contracts deployment. For me the actual main benefit from Diamond usage is the high degree of flexibility for upgrades and changes to the etomic swap contract logic. The open question: do we really need this upgrade opportunity? We usually dont do a lot of changes in swap contracts. This is my the initial answer for Diamond Standard. However I would like to study this contracts creation pattern more. |
This is also a drawback of the pattern, as a contract issuer/deployer can change the code of a contract after it has been used by users. This modification removes the trustless feature of a smart contract. The upgradeability features of diamonds are offered so that during development, alpha, or beta stages, you can still change the code easily. However, once the contract is production/stable release ready, upgradeability should be disabled. This is why diamonds provide a feature to make a contract immutable at a later time.
This is what I am leaning towards too, but I thought we should consider any possibilities before setting anything in stone. Making contracts simpler is also good for security audits and checks, a benefit of the etomic swap contract is that it's simple and doesn't have a lot of layers or complex logic that can hide vulnerabilities. P.S. As agreed on DM, we will not do any more reviews for this PR until we decide on the approach to follow during the next sprint. |
f40a2be to
d2de9a5
Compare
32e555a to
a1b4d29
Compare
|
Staring from d2de9a5 commit (Create maker taker contracts, test script for MakerV2 TakerV2) the implementation approach was changed to Multi Standalone Etomic Swap contracts The two strategies were proposed previously (see #7 (comment)):
|
|
@laruh I guess we can now remove |
shamardy
left a comment
There was a problem hiding this comment.
LGTM! Only one question!
Yep, we dont need them for prod, but I decided to keep old contracts for dev/test processes, eg to quickly compile contracts for sepolia/geth tests if necessary |
This commit introduces the following key changes related to issue #900: - Implement standalone NFT maker swap contract (EtomicSwapMakerNftV2) - Add komodefi-proxy support for NFT feature, enabling HTTP GET requests Additional changes include: - Implement Multi Standalone Etomic Swap contracts approach - Add support for EtomicSwapTakerV2 contract - Enhance security with checks for malicious token_uri links - Make clear_all parameter optional in clear_nft_db RPC (default: false) - Implement Sepolia testnet support for testing This change adopts the new Etomic swap implementation approach as discussed in GLEECBTC/etomic-swap#7 (comment)
This commit introduces the following key changes related to issue #900: - Implement standalone NFT maker swap contract (EtomicSwapMakerNftV2) - Add komodefi-proxy support for NFT feature, enabling HTTP GET requests Additional changes include: - Implement Multi Standalone Etomic Swap contracts approach - Add support for EtomicSwapTakerV2 contract - Enhance security with checks for malicious token_uri links - Make clear_all parameter optional in clear_nft_db RPC (default: false) - Implement Sepolia testnet support for testing This change adopts the new Etomic swap implementation approach as discussed in GLEECBTC/etomic-swap#7 (comment)
This commit introduces the following key changes related to issue #900: - Implement standalone NFT maker swap contract (EtomicSwapMakerNftV2) - Add komodefi-proxy support for NFT feature, enabling HTTP GET requests Additional changes include: - Implement Multi Standalone Etomic Swap contracts approach - Add support for EtomicSwapTakerV2 contract - Enhance security with checks for malicious token_uri links - Make clear_all parameter optional in clear_nft_db RPC (default: false) - Implement Sepolia testnet support for testing This change adopts the new Etomic swap implementation approach as discussed in GLEECBTC/etomic-swap#7 (comment)
No description provided.