Skip to content

Instantly share code, notes, and snippets.

@ss-sonic
Created December 18, 2020 19:07
Show Gist options
  • Select an option

  • Save ss-sonic/c22f720291952f8bffb95a6027185454 to your computer and use it in GitHub Desktop.

Select an option

Save ss-sonic/c22f720291952f8bffb95a6027185454 to your computer and use it in GitHub Desktop.
check if Web3 is available to react app
window.ethereum
check if locked
check which network it is in by chain id - [80001, 80001, 80001, 80001]
web3.getAccount()
Four chain
Four staking contract for each chain
Each staking contract will have 3 pool
They will take a staking token and give a reward token
staking_pools = [
{ poolAddress: 0x1F1dF48698E98884257A1d88d9cfA7B6CD3Eb014,
chain: matic,
chainId: 80001,
stakingToken: 0xe7b6f39423F7272CC7eF63C2336E1C5A029EaD33,
baseURL: "someurl",
},
{ poolAddress: 0x1F1dF48698E98884257A1d88d9cfA7B6CD3Eb014,
chain: ethereum,
chainId: 1,
stakingToken: 0xe7b6f39423F7272CC7eF63C2336E1C5A029EaD33,
baseURL: "someurl",
},
{ poolAddress: 0x1F1dF48698E98884257A1d88d9cfA7B6CD3Eb014,
chain: xdai,
chainId: 5000,
stakingToken: 0xe7b6f39423F7272CC7eF63C2336E1C5A029EaD33,
baseURL: "someurl",
},
{
poolAddress: 0x1F1dF48698E98884257A1d88d9cfA7B6CD3Eb014,
chain: matic,
chainId: 5001,
stakingToken: 0xe7b6f39423F7272CC7eF63C2336E1C5A029EaD33,
baseURL: "someurl",
}
]
web3wrapper
xdaiClient
maticClient
ethClient
bscClient
price_feed = {
matic: {},
xdai: {},
eth: {},
bsc: {}
}
load staking token contract for that pool and forward user to add liqiuidity if there is none
user added liquidity from third party flatform
tokenContract = await web3.eth.Contract(tokenAbi, stakingToken)
poolContract = await web3.eth.Contract(poolABI, poolAddress)
check balance of staking token
sb = tokenContract.methods.balanceOf(accounts[3])
if (sb>0){
move to deposit
}
else{
show that button
}
DEPOSIT
allowance = tokenContract.methods.allowance(accounts[3], poolAddress)
if(allowance>0){
pool.methods.stake('10000000')
}else{
tokenContract.methods.approve(poolAddress, MAXINT256)
}
check if deposited
WITHDRAW
bal = poolContract.methods.balanceOf(accounts[3])
if bal>0{
poolContract.methods.exit({from: accounts[3]})
}
rate = poolContract.methods.rewardRate()
pendingToken = poolContract.methods.earned()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment