This repo uses SmartPy CLI to compile and unit test the core xtznftswap contract used by https://xtznftswap.xyz and its vanity equivalent https://tezosnft.trade.
To run tests be sure to have SmartPy CLI installed globally on your machine. After that you can use npm to run the tests with npm run test
. Output for each test can be be found in compile/
after running. Inspect the log.html
file to visually see each step of the test and validate that things like Tezos balances of each account and internal contract storage are exactly what you expect.
Tests are ran automatically on every push to main and every push to a pull requested branch. This is to ensure we never merge broken code in main
and never create a broken Github Release.
To run tests be sure to have SmartPy CLI installed globally on your machine. After that you can use npm to compile down the main contract using npm run compile
. Output can be be found in compile/
after running.
Bump the number in package.json
accordingly in a pull request, get that merged, then run the release.yml
Github Action. This will create a new Github Release automatically.
The front end needs to always batch together two+ transactions.
Adds the proposal to the storage. Tezos tokens will be held custodialy until accept_trade
or cancel_trade
is called.
// for each token to trade
fa2Contract.methods.update_operators([{
add_operator: {
owner: account.address,
operator: contract.address,
token_id: token.id
}
}])
// just one call after all that
// see tests for expected parameters
xtznftswapContract.methods.propose_trade(...)
Causes FA2 tokens and tezos to swap parties according to the proposal.
// for each token to trade
fa2Contract.methods.update_operators([{
add_operator: {
owner: account.address,
operator: contract.address,
token_id: token.id
}
}])
// just one call to accept
xtznftswapContract.methods.accept_trade()
Invalidates the trade proposal forever. Returns all tezos held custodially.
// just one call to cancel
xtznftswapContract.methods.cancel_trade(...)
// for each token you are no longer trading, for security purposes
fa2Contract.methods.update_operators([{
remove_operator: {
owner: account.address,
operator: contract.address,
token_id: token.id
}
}])
Operators for an FA2 compliant token are not reset upon transfer.
This has fallout. If someone were to transfer/sell their token away, then buy it back, any operators they previously had set would come back to life. It's what I call the Orderbook Enigma because in the orderbook context, this means any valid trades you proposed are now active again unless manually cancelled. Be very wary of this and use remove_operator
upon cancelling or accepting a trade.
Use the following mainnet and testnet contract to understand the Storage layout and interaction available publicly on chain.