How ERC20 token set tax mount when buy/sell on Pancake Swap? - solidity

I created ERC20 (just basic with Openzepplin), I can add liquid to Pancake. Buy, what I need is:
When users buy token on Pancake, I need to transfer 3% amount BNB to Owner Address.
When users sell token on Pancake, I need to transfer 3% amount Token to Owner Address.
I've research and found that: in function _transfer, we can detect from/to is pancake pair address, then we know client is buying or selling. Buy I dont know how to transfer tax to another address (ex Owner address).
Thank you.

You can make the transfer function to payable and write your logic in to transfer the percentage.

Related

what's the purpose of the approve function in erc 20

I'm new in solidity and erc20, so I read ERC20 description on the openzeppelin and find this function which isn't clear for me.
approve(spender, amount)
What's the purpose of allowing to the spender spend my token, instead of send my tokens to the spender directly?
You can change the approved amount or revoke it altogether (only the unspent amount). But you cannot take back an already sent transfer.
A common use case for the approve() function is trading on a DEX (decentralized exchange). You approve the DEX contract address to spend your USDT tokens for example. And when you want to buy an XYZ token (against USDT), the DEX simply pulls the already approved USDT from your address and sends you the XYZ tokens.
Approve is a function used to give permission the spender can be anyone an exchange or EOA to withdraw as many times from your token contract up to the _value.
You can check this reference here
As others said, Approve function can give permission to the spender to pulls the amount of token in your address. It can be used in: DEX (decentralized exchange) or in Custody services.
In custody services, after you approve the custody provider to take your token, whenever your wallet receives token, the custody provider is able to transfer your token into some internal wallets and keep them save for you. (It's just like how the traditional banks work)

Vesting via Cardano smart contract fails if receiver wallet is empty

Assume vesting code block in Plutus playground. Simply, if receiver wallet has some ADA, the contract works normally. But in case of an empty receiver wallet, transaction will fail because sending money from script to wallet needs an amount of fee and this fee should be paid by receiver. Any modification for such problem?
That's not a problem, that's the way smart contracts works in cardano, even that's the way everything works on blockchain. When an address sends money to another, the source address should pay for the fees. That logic applies to any blockchain (as I know).
So, in smart contracts is the same. If a wallet wants to retrieve (not receive as you said) money from a validator script, then should pay for the fees. This is because the wallet wants those funds, therefore it should submit a transaction in the blockchain, that implies to pay the fees for it.
In blockchain, every user/wallet/addres that submit a transaction to the network, should pay fees.

Is it possible to attach/mirror a balance to a Bank Account? xero

Is it possible to attach a balance to a Bank Account?
Our product has a bank balance and we process payments that have to be sent back to Xero. I don't understand how to best present our bank balance in Xero or even if it makes sense to do this.
Currently I automatically create an expense account using the API and associate all payments we create in Xero with that. This isn't ideal because we'd like to show the current balance of funds the customer has in our product. Also, the account the user has with us isn't really an expense account it's more of a bank account.
When I create a bank account in Xero, I can't figure out how to associate an existing balance. Any guidance on best practices here would be appreciated.
Is it possible to attach a balance to a Bank Account? Our clients have a balance of funds with us very similar to a bank balance. How can I make that balance show up in Xero and have that account be used for Payments I create using only the API?
You can set the conversion balance for a bank account using the Setup endpoint:
https://developer.xero.com/documentation/api-guides/conversions
That will let you provide the initial balance via the API; the balance from that point is maintained via requests against the BankTransactions endpoint with the appropriate types:
https://developer.xero.com/documentation/api/types#BankTransactionTypes

How users currency accounts address are updated during currency trading on Exchanges like Coinbase and Binance?

My naive understanding behind how currency trading works on Exchanges like Binance and Coinbase is each users are provided with unique address and when the respective currencies trade happens on exchanges like Binance or Coinbase, both the parties accounts get's updated live on blockchain.
To elaborate more, In case of ETH/BTC trading, let's say, Mr Foo wants to trade his ETH with Mr Bar's BTC on Binance exchange. Binance will provide both of them with unique address respectively to their currency. So when the ETH/BTC trade take place, Mr Foo will receive the BTC on his newly generated unique BTC address and Mr Foo's ETH account will be deducted . On the other side, Mr Bar's BTC account will be deducted and Ether account is updated with newly received ether.
I'm really confuse regarding whether these currency trading on exchanges execute live on Blockchain? Recently during Bitcoin and Ethereum network congestion, I did BTC/ETH trading on HITBTC, the process happened instantaneously, but I've to wait for hours during withdrawal process. Also Hitbtc seems to be using same Ethereum account (0x65e2c5175e2e618f48e70343b14c31b280e42d90) to transfer fund during withdraw request for multiple users. It seems that these exchanges are using the same address for serving multiple users.
Could somebody explain how users accounts are updated during currency trading on exchanges like Coinbase and Binance? Does trading immediately happens live on blockchain? Or Exchanges only shows the users with fake trading balances until it's withdrawn? Do the Exchanges use same address to accept deposits from multiple users?
Thank you for your time.
Check out this thread for a brief explanation of Coinbase's order management.
Answer on the reddit thread, supposedly from a coinbase insider.
In addition, my comment above was just based on intuition and my general knowledge of the way brokers work.
Brokers
Brokers tend to match orders first since they are in the business of exchanging, not investing. Meaning they make their most consistent revenue from fees generated by facilitating customer orders, not by investing in the securities or assets that they help to buy/sell.
Sometimes in order to fulfill an order the broker will go long or short a particular asset class, in this case bitcoin or ethereum, etc. If this happens the broker is exposed to fluctuations in the price of that asset against the asset they are trying to grow (cash).
Now, since Coinbase is heavily involved in crypto it might be part of their strategy to hold Bitcoin or Ethereum inventory, but I would doubt it would figure much since that would undermine public trust in their institution as an impartial exchange. No one really likes to hear their broker bet against them, it tends to engender resentment.
Technicals
Coinbase is setup as a software wallet, meaning you have an account, with the private keys stored on their server. So it is possible for them to facilitate some of the trading between bitcoin accounts without ever having to match orders with an account holder outside their system.
Meaning, they can collect/match/fill the orders in batches and then submit those batches to bitcoin miners. This would allow them to quickly "fulfill" your order, and then send you verification once it has been posted to the blockchain.
Further Reading
Although it is not specifically geared towards crypto exchanges there is an excellent book on the subject of how markets actually function.
Market Microstructure in Practice

Multiple payment methods, multiple currencies solution

We need a website where users can deposit funds to their accounts, transfer funds from one user's account to other user's account, withdraw funds. We are looking for reliable solution so that users can use several payment methods to deposit/withdraw funds and optionally use multiple currencies (so funds can be converted from one currency to another). This part of website should be similar to payments part of freelancer.com and similar websites. It means that user1 can deposit funds using PayPal, then user1 transfers part of these funds to user2 and user2 can withdraw these funds (deposited by user1 using PayPal) to user2's MoneyBookers account. Can anyone suggest solution for this? Does that mean that we need to have sufficient amounts on both PayPal and MoneyBookers or there's a way to transfer funds from our PayPal account to our MoneyBookers account (without commission) in order to process user2's withdrawal request. Does anyone know what freelancer.com and similar websites use to implement this? We plan to integrate with payoneer.com later as well.
The only way I know to transfer money between PayPal and Moneybookers directly would be to use a Moneybookers Mastercard and deposit with that on PayPal.
The other way (PayPal to MB) is not possible directly, you will need to make a PayPal payment to a third-party (your company), that then makes an automated deposit on Moneybookers. This is possible with their API.