List of EOS accounts who are staking my account's CPU and/or NET bandwidth - eos

is there a way to determine exactly what accounts have staked EOS to my contract, and the amount of EOS each such staker has staked to CPU and NET?
I know that the cleos command
$ cleos system listbw <my-contract-account>
will list the accounts which my-contract-account has staked; I'm looking for the reverse of this: given a contract, who out there in the wild world of EOS has staked me?

Use EOSPark, look under "stake detail"->"staked by others". This option can be found below the token listings.

Related

Performing an atomic swap in solidity with a disposable smart-contract

I want to perform an atomic token swap without a pre-deployed smart-contract and I am wondering how to do that in Solidity.
The most common approach to do atomic swaps between tokenA and tokenB is the P2-SC-2P (Peer-to-Smart-contract-to-Peer) approach:
deploy a token swap smart-contract
alice deposits tokenA in the smart-contract
bob deposits tokenB in the smart-contract and receives tokenA in exchange
I want to get rid of step 1 to have a truly P2P mechanism. The main idea would be that Alice signs a transactions that transfers X tokenA to the person propagating the transaction, only if that person transfers Y tokenB to Alice in return.
Is it even possible to implement something like this?
Technically speaking, my first thought was to have Alice sign a transaction that deploys a smart-contract would take care of making the atomic swap between the signer and the caller before self-destructing.
I am not a good Solidity dev (to say the least) so here is the pseudo Solidity code I had in mind that could perform the atomic swap without requiring a pre-deployed smart-contract:
contract AtomicSwap {
sellerSignedApprovalTx = "<RawSignedTxData>"
constructor() public {
buyer = caller
seller = verifySignature(sellerSignedApprovalTx)
TokenB.approve(buyer,sellerSignedApprovalTx.askPrice)
delegateCall(sellerSignedApprovalTx.data)
safeTransferFrom(TokenB,buyer,seller,sellerSignerApprovalTx.askPrice)
safeTransferFrom(TokenA,seller,buyer,sellerSignerApprovalTx.tokenAmount)
selfdestruct()
}
}
As you can see, the idea is that the smart-contract has only 1 use: it performs the swap and then self-destructs (hence the notion of "disposable" smart-contract).
What do you think? Is this even technically possible?
If yes, would it work a bit like my pseudo code or am I completely off?
I got the answer to my question via another channel: it's not recommendable to use this technique because the seller needs to sign the transaction for execution without knowing the contract address which will be executing the trade. So it would be like writing a blank check and comes with many security issues.

EOS. Unexpected amount descreasing after generate raw (unsigned) transaction, sign it and broadcast

Account on jungle testnet.
I. Here is attempt to send 95 EOS and also powerup and buy ram while balance is 102 EOS at attempt moment. As result: got error which is about enough amount.
Picture with balance
Transaction content:
{"transaction":{"expiration":"2022-05-16T09:42:23.349+00:00","ref_block_num":140806677,"ref_block_prefix":3316434404,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"eosio","name":"powerup","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio","getData":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getName":"powerup"},{"account":"eosio.token","name":"transfer","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a203256b96a4e6bd6f07e0e000000000004454f530000000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio.token","getData":"10420835aa96949a203256b96a4e6bd6f07e0e000000000004454f530000000000","getName":"transfer"}],"transaction_extensions":[],"signatures":[],"context_free_data":[],"getRefBlockPrefix":3316434404,"getMaxNetUsageWords":0,"getMaxCpuUsageMs":0,"getDelaySec":0,"getContextFreeActions":[],"getActions":[{"account":"eosio","name":"powerup","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio","getData":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getName":"powerup"},{"account":"eosio.token","name":"transfer","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a203256b96a4e6bd6f07e0e000000000004454f530000000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio.token","getData":"10420835aa96949a203256b96a4e6bd6f07e0e000000000004454f530000000000","getName":"transfer"}],"getTransactionExtensions":[],"getExpiration":1652694143349,"getRefBlockNum":140806677},"chainId":"2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840"}
When I tried send, I have got error:
Can't broadcast transaction #hex {"signatures":["SIG_K1_Jw6ws6tJWRpy93ySXzv6B8QTotgLadfoaLULPMrSwG8m4skYCi5nVnMBm1RC6qEmUT2fAWqKka37CALgbYVnzEJpF5hdep"],"compression":"none","packed_context_free_data":"","packed_trx":"7f1c8262158ae4c5acc500000000040000000000ea3055000000a0eaab38ad0210420835aa96949a00000000a8ed323210420835aa96949a00000000a8ed32323410420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f530000000000a6823403ea3055000000572d3ccdcd0210420835aa96949a00000000a8ed323210420835aa96949a00000000a8ed32322110420835aa96949a203256b96a4e6bd6f07e0e000000000004454f5300000000000000000000ea3055000000a0eaab38ad0210420835aa96949a00000000a8ed323210420835aa96949a00000000a8ed32323410420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f530000000000a6823403ea3055000000572d3ccdcd0210420835aa96949a00000000a8ed323210420835aa96949a00000000a8ed32322110420835aa96949a203256b96a4e6bd6f07e0e000000000004454f53000000000000"}.
com.unitedtraders.luna.crypto.spi.exception.BlockchainDataProviderException: Cannot send eos transaction. Response: ChainError(code=500, message=Internal Service Error, error=Error(code=3050003, name=eosio_assert_message_exception, what=eosio_assert_message assertion failure, details=[Details(message=assertion failure with message: overdrawn balance, method=eosio_assert), Details(message=pending console output: , method=exec_one)])).
II. Here is attempt to send 30 EOS and also powerup and buy ram while balance is 102 EOS at attempt moment. As result: decreasing amount is about 60 EOS.
This attempt is successful.
But balance decreased in unexpected amount:
before sending it was 102 EOS
after sending it was 41.9996 EOS.
Seems like x2 decreasing (transferring is 30, powerup fee is 0.0002).
Transaction content:
{"transaction":{"expiration":"2022-05-16T11:02:44.414+00:00","ref_block_num":140816318,"ref_block_prefix":1732454216,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"eosio","name":"powerup","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio","getData":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getName":"powerup"},{"account":"eosio.token","name":"transfer","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a203256b96a4e6bd6e09304000000000004454f530000000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio.token","getData":"10420835aa96949a203256b96a4e6bd6e09304000000000004454f530000000000","getName":"transfer"}],"transaction_extensions":[],"signatures":[],"context_free_data":[],"getRefBlockPrefix":1732454216,"getMaxNetUsageWords":0,"getMaxCpuUsageMs":0,"getDelaySec":0,"getContextFreeActions":[],"getActions":[{"account":"eosio","name":"powerup","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio","getData":"10420835aa96949a10420835aa96949a010000005825450000000000267d000000000000102700000000000004454f5300000000","getName":"powerup"},{"account":"eosio.token","name":"transfer","authorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"data":"10420835aa96949a203256b96a4e6bd6e09304000000000004454f530000000000","getAuthorization":[{"actor":"needhelp1111","permission":"active","getActor":"needhelp1111","getPermission":"active"}],"getAccount":"eosio.token","getData":"10420835aa96949a203256b96a4e6bd6e09304000000000004454f530000000000","getName":"transfer"}],"getTransactionExtensions":[],"getExpiration":1652698964414,"getRefBlockNum":140816318},"chainId":"2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840"}
Can anybody explain what's going wrong and why sending amount is 30, but decreasing amount is 60?
Thx in advance)
Problem was in serialization/deserialization part.
Used library creates in DTOs separated field with getter naming pattern (for example, there is field 'account' and also there is field 'getAccount' near).
When raw (unsigned) transaction was serialized, it had created json field also for "getter" field. And when raw transaction was deserialized, jackson library had merged field data and "getter" data, thus there were duplicates.
You can see duplicates in raw transactions in topic start post ("account" and "getAccount", "data" and "getData", etc.).
On mainnet this entailed double sending, but on testnet it was just, something like, "double spending and one sending".
We have used next fix on deserialization step:
val objectMapper: ObjectMapper = objectMapper
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)

Block OpenSea trading

Is there a way to avoid trading NFTs on standard marketplaces like OpenSea without breaking the erc721 standard?
If so, how would you go about it?
It is about an NFT that is something like a voucher that can be used 5 times. Over 5 years, once per year. I would like to prevent that someone unknowingly buys a redeemed voucher (for the current year).
You can include checks in your transfer function.
Keep a global map counter with token IDs pointing to the number of transactions per token
mapping(uint256=> uint256) private _tokenTx;
Now, in your transfer function you can use the NFT id, check in the map to see if it's lower than 5, if it is, you fail the tx, otherwise you continue and increase the number
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
**require(_tokenTx[tokenId] <6, "ERC721: can\'t transfer more than 5 times");**
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
**_tokenTx[tokenId] = _tokenTx[tokenId]+1;**
emit Transfer(from, to, tokenId);
}
As for filtering exchanges transfers, you can either keep a dynamic list with the addresses they use, or block the approval processes altogether.
The first keeps the standard better but is harder and more expensive to keep up, the second one is a bit more aggressive but will work for all popular exchanges out there
Or, if you're using an external link to redirect buyers/traders to the text file that lists the voucher code, all you have to do is replace the voucher code(s) with a message saying that all the vouchers have been redeemed and then save the file. That way, the next time the NFT gets traded and they unlock the link, they'll see the message.
I sure as hell ain't going to waste my time trying to figure out all that coding nonesense...lol.

web3js Uniswap handle event log data

I am building a scraper to get all Swap data from Uniswap using web3js.
So far I subscribe to the log and filter topics by Swap() event.
then I decode the data and get amount0In, amount1In, amount0Out, amount1Out.
My problem is in the swapExactETHForTokensSupportingFeeOnTransferTokens() function.
Normally a swap has token0 in and token1 out, but this function gives me values for 3 of the 4 and I can not seem to understand how to handle that. eventually what I want is to know what they spend, what they got and what I need to update the new reserves of that pair.
If someone has the understanding of the Uniswap RouterV2 contract swap functions, I would like to get some pointers on how to handle the data to get my calculations right.
I found the solution here ethereum.stackexchange Anyone with the same question gets a very detailed answer there.
some contracts actually transfers to recipient specified amount of tokens minus 10% (5% tax fee and 5% liquidity fee) 208940457743532637 - 10% = 188046411969179375 and emits Transfer event. Then, PancakePair _swap function emits Swap event with base value of Amount0Out 208940457743532637
Amount0In is greater than zero because the token contract returns part of tokens as a liquidity pair on Pancake Swap.

Is it safe to read the ethereum smart contract balance directly to calculate the transfer of assets to users?

I have contract, through which users can trade on DEX.
Like this:
// transfer asset A from msg.sender
ERC20(AToken).transferFrom(msg.sender, address(this), amount);
// do trade A to B
... trade logic here
// get balance of asset B after trade
// asset B after trade gets to this contract address
uint256 returnAmount = ERC20(BToken).balanceOf(address(this));
// transfer asset B to msg.sender
ERC20(BToken).transfer(msg.sender, returnAmount);
I wonder about returnAmount, is this logic safe?
Transactions in ethereum are performed either completely or not performed at all, and also in order of priority.
But I’m still wondering if there could be such a case when returnAmount shows incorrectly, for example, contract get the balance after the transaction of another user?
Transactions in ETH are executed one by one, other transactions can not interfere to execution of a transaction when it's running by EVM.