What contract to query for getting user's staking rewards info for Pancakeswap Auto CAKE pool? - smartcontracts

I managed already to write code interacting with Auto CAKE pool contract in order to get user balance. This can be done by interacting with bsc smart contract 0xa80240Eb5d7E05d3F250cF000eEc0891d00b51CC and calling userInfo function.
Hoewever, this function does not return the current balance but it returns the " cakeAtLastUserAction", which is the total number of CAKE deposited in this contract by the user. It doesn't include the CAKE rewards generated in-between.
What contract should be queried to get the number of CAKE rewards generated for a user with the Pancakeswap AutoCAKE pool?

Related

How to reserve specific range of token IDs for whitelisted sale in solidity smart contract

Hello I am writing a erc721a solidity smart contract of a nft collection.
And I want to do whitelisted sale and public sale at the same time. So I wonder how can I reserve token IDs #1 to #100 for whitelisted sale and token ID #101 to last token ID for public sale..
Please can someone help me in this case. Thanks :D

How to airdrop NFTs to specific NFT owners?

I want to understand how can we give free ERC721 or ERC20 tokens to specific NFT owner addresses. For example Bored Ape yacht club created an ERC20 coin with a pre-defined amount which can be claimed only from the owners of the BAYC NFTs. I tried to find out an answer in their smart contracts, but I couldn't find their ERC20 coin contract therefore I can't figure out how the restrict the distribution of coins.
In my project I want to create 2 ERC721 smart contracts and all owners of NFTs from the first contract should be able to mint for free NFTs from the second smart contract. If you are an owner of an NFT from smart contract 1 you can claim free NFT from smart contract 2. Can you provide me with some resources or ideas where I can learn how to achieve that
You can, in the second smart contract, check whether the caller of the mint function is a token holder of the first smart contract or not.
function mint() external {
require(IERC721(_firstToken).balanceOf(msg.sender) > 0, 'should be a holder of the first token');
_mint();
}
You can import ERC721 interface from openzeppelin library, or just cut&paste from EIP-721.
There must be some restrictions on how many nftTwo tokens can be minted per single nftOne token. Otherwise, you will be exploited and users will be able to mint an unlimited amount of nftTwo tokens.
IERC721 public nftOne;
uint public nftTwoMaxMintCount;
mapping(uint => uint) public nftTwoMints;
function mintNftTwo(uint nftOneTokenId) external {
// Only the owner of nftOne token can execute mint
require(msg.sender == nftOne.ownerOf(nftOneTokenId), "not the owner of nftOne token");
// The number of allowed nftTwo token mints is limited by nftTwoMaxMintCount
require(nftTwoMints[nftOneTokenId] <= nftTwoMaxMintCount, "nftTwo token mints overflow");
// Increment the number of minted nftTwo tokens per nftOne token id
nftTwoMints[nftOneTokenId] += 1;
// Execute mint
_mintNftTwo();
}
Please check OpenZeppelin's implementation of the ERC721 and read their docs for more details.

transfer ERC20 on behalf of token owner after a payment of ether occurs

I have the following scenario:
I have a contract to generate a limited amount of erc20 tokens. User A buys X amount of this token. Then user A wants to sell some of his tokens, for X amount of ether, then user B wants to buy tokens of user A, how can I automatically transfer tokens from user A to user B when the transfer of ether from user B to user A has been successful be transfer?
Do I need a second contract to handle this kind of operation?
You may have two options,
Play around with Escrow SmartContracts (Like Openzeppelin) and modify it as per your need.
Use ERC20 Approve(spender,amount) on User B, to get allowance for your contract to spend on behalf of B. (spender : Your contract address)
Run a web3 script to listen on events to catch the corresponding transaction of sending ether from B->A ,
once the ether is transferred, you can place a function call to smart contract to spend the token from B to A
In your ERC20 Contract implementation, you can have a mapping of address -> eth, where the eth represents the selling price each user has set up.
Now, when a user "sells" their token, they can allow the same contract to transfer X amount of tokens from their balance which they want to sell.
And to sell, you can create a payable function that receives ether, and via parameter a seller address. This function will dynamically ( using the address received on the mapping we created at the beginning ) transfer X tokens to the buyer, using that seller's token price and the amount of ether received.
For example: If 1TKs = 0.5ETH, and the buyer sends 2eth, the contract will transfer 4TKS.
Recomendation.
Usually, the token contract and the seller/buyer functions are done in different contracts for security reasons, for example having the actual token, and the token shop separated on different contracts.
Disclaimer.
This is the simplest implementation I could think of, but it will accomplish your requirements.

Reason provided by the contract: "ERC20: transfer amount exceeds allowance"

I'm new to solidity and I wanted to develop a subscription contract where a user can subscribe to a merchants plan and pay. But I'm unable to subscribe function and transfer the token to merchant.
I'm using open zeppelin ERC20 standard token to transfer.
IERC20 token = IERC20(plans[planId].token);
token.transferFrom(
payable(msg.sender),
payable(plan.merchant),
plan.amount
);
I don't know why but this keeps giving me allowance error even though I have increased the allowance of the user.
Since you're invoking the token.transferFrom() from the subscription contract, the token owner needs to increaseAllowance() for the subscription contract to manipulate their tokens.
Example:
Your subscription contract is deployed on address 0x123.
Token address is 0x456, and it has 18 decimals.
The user needs to execute increaseAllowance(0x123, 500 * 1e18) on the token contract in order to increase the allowance by 500 tokens.
Mind the subscription contract address as the first param, and the decimals as the second param (so the actual value passed to the second param is 500000000000000000000 because it includes the decimals as units as well).

Getting token and contract information using Nethereum

I am looking at this staking contract (pancake swap):
0x73feaa1ee314f8c655e354234017be2193c9e24e
and it's token (cake):
0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82
you can find a summary here:
https://bscscan.com/token/0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82?a=0x73feaa1ee314f8c655e354234017be2193c9e24e
On bscscan, I can get the following information:
price of token $12.54
market cap $2.9b
supply 231m
holders 137k
balance 88m (cake)
With nethereum, when I call:
web3.Eth.GetBalance.SendRequestAsync
I get:
with staking contract address: 479430015101300880
with token address: 3459819507903896496
and I'm not sure what the units are, nor how to map this to the information from bscscan.
I'm trying to get both the token value, but also what is the balance in the contract and I can't seem to find a way to do this.
so I looked at the nethereum playground and found an example dealing with ERC20 tokens, but when I put my addresses in it, the output is 0 and absolutely no error message, etc.