Skip to content

Commit 5509e20

Browse files
authored
fix: reward per year for pcs clone (#22)
* feat: add pcs reward per year * refactor: move lp class to file * fix: ignore failed transactions * fix: reward per year calculation
1 parent 5400f84 commit 5509e20

File tree

5 files changed

+45
-36
lines changed

5 files changed

+45
-36
lines changed

src/providers/BSCDeFi.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ class BSCDeFi {
2121

2222
this.defiPlatforms = {
2323
acryptos: new PancakeSwapCloneChef(web3, '0x96c8390BA28eB083A784280227C37b853bc408B7', 'pendingSushi', 'ACS'),
24-
alpaca: new PancakeSwapCloneChef(web3, '0xA625AB01B08ce023B2a342Dbb12a16f2C8489A8F', 'pendingAlpaca'),
24+
alpaca: new PancakeSwapCloneChef(web3, '0xA625AB01B08ce023B2a342Dbb12a16f2C8489A8F', 'pendingAlpaca', 'ALPACA'),
2525
apeSwap: new PancakeSwapCloneChef(web3, '0x5c8D727b265DBAfaba67E050f2f739cAeEB4A6F9', 'pendingCake', 'BANANA'),
2626
autoFarm: new AutoFarmChef(web3),
2727
bVault: new BVaultChef(web3),
2828
cafeSwap: new PancakeSwapCloneChef(web3, '0xc772955c33088a97D56d0BBf473d05267bC4feBB', 'pendingCake', 'BREW'),
29-
coralFarm: new PancakeSwapCloneChef(web3, '0x713e34640ef300a0B178a9688458BbA8b1FA35A7', 'pendingCrl'),
30-
goose: new PancakeSwapCloneChef(web3, '0xe70E9185F5ea7Ba3C5d63705784D8563017f2E57', 'pendingEgg'),
29+
coralFarm: new PancakeSwapCloneChef(web3, '0x713e34640ef300a0B178a9688458BbA8b1FA35A7', 'pendingCrl', 'CRL'),
30+
goose: new PancakeSwapCloneChef(web3, '0xe70E9185F5ea7Ba3C5d63705784D8563017f2E57', 'pendingEgg', 'EGG'),
3131
kebab: new PancakeSwapCloneChef(web3, '0x76FCeffFcf5325c6156cA89639b17464ea833ECd', 'pendingCake', 'KEBAB'),
3232
midasGold: new MidasGoldChef(web3),
3333
pancakeSwap: new PancakeSwapChef(web3),
3434
ramen: new PancakeSwapCloneChef(web3, '0x97dd424b4628c8d3bd7fcf3a4e974cebba011651', 'pendingCake', 'RAMEN'),
35-
saltSwap: new PancakeSwapCloneChef(web3, '0xB4405445fFAcF2B86BC2bD7D1C874AC739265658', 'pendingSalt'),
35+
saltSwap: new PancakeSwapCloneChef(web3, '0xB4405445fFAcF2B86BC2bD7D1C874AC739265658', 'pendingSalt', 'SALT'),
3636
slime: new PancakeSwapCloneChef(web3, '0x4B0073A79f2b46Ff5a62fA1458AAc86Ed918C80C', 'pendingReward', 'SLIME')
3737
}
3838
}

src/providers/bsc/AutoFarmChef.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const Web3 = require('web3')
21
const MasterChef = require('./MasterChef')
32

43
// Auto
@@ -7,21 +6,13 @@ const autoFarmAddress = '0x0895196562C7868C5Be92459FaE7f877ED450452'
76

87
class AutoFarmChef extends MasterChef {
98
constructor (web3) {
10-
super(web3, autoFarmChefABI, autoFarmAddress)
9+
super(web3, autoFarmChefABI, autoFarmAddress, 'pendingAUTO')
1110
this.contract = new web3.eth.Contract(autoFarmChefABI, autoFarmAddress)
1211
}
1312

1413
async getStakedLPAmount (poolID, walletAddress) {
1514
return await this.contract.methods.stakedWantTokens(poolID, walletAddress).call()
1615
}
17-
18-
async getPendingReward (poolID, walletAddress) {
19-
const pendingReward = await this.contract.methods.pendingAUTO(poolID, walletAddress).call()
20-
21-
return {
22-
AUTO: parseFloat(Web3.utils.fromWei(pendingReward))
23-
}
24-
}
2516
}
2617

2718
module.exports = AutoFarmChef

src/providers/bsc/MasterChef.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ const LiquidityPool = require('./LiquidityPool')
77
const InputDataDecoder = require('ethereum-input-data-decoder')
88

99
class MasterChef {
10-
constructor (web3, chefABI, address, pendingMethodName, pendingSymbol = '') {
10+
constructor (web3, chefABI, address, pendingMethodName = 'pendingCake', pendingSymbol = '') {
1111
this.web3 = web3
1212
this.address = address
1313
this.contract = new web3.eth.Contract(chefABI, address)
1414
this.decoder = new InputDataDecoder(chefABI)
1515
this.pendingMethodName = pendingMethodName
16+
1617
this.pendingSymbol = pendingSymbol
18+
if (this.pendingSymbol === '') {
19+
this.pendingSymbol = this.pendingMethodName.replace('pending', '').toUpperCase()
20+
}
1721
}
1822

1923
lpTransactions (walletTx, poolID) {
@@ -52,14 +56,8 @@ class MasterChef {
5256

5357
async getPendingReward (poolID, walletAddress) {
5458
const pendingReward = await this.contract.methods[this.pendingMethodName](poolID, walletAddress).call()
55-
56-
let tokenName = this.pendingSymbol
57-
if (tokenName === '') {
58-
tokenName = this.pendingMethodName.replace('pending', '').toUpperCase()
59-
}
60-
6159
const rewards = {}
62-
rewards[tokenName] = parseFloat(Web3.utils.fromWei(pendingReward))
60+
rewards[this.pendingSymbol] = parseFloat(Web3.utils.fromWei(pendingReward))
6361
return rewards
6462
}
6563

@@ -86,7 +84,8 @@ class MasterChef {
8684

8785
const poolRewardPerBlock = Web3.utils.fromWei(BigNumber(allocPoint).dividedBy(this.totalAllocPoint).multipliedBy(this.rewardPerBlock).integerValue().toFixed())
8886
const userPoolRewardPerBlock = poolRewardPerBlock * pool.share(lpTokenAmount)
89-
const rewardPerYear = userPoolRewardPerBlock * 3600 * 24 * 365 / 3
87+
const rewardPerYear = {}
88+
rewardPerYear[this.pendingSymbol] = userPoolRewardPerBlock * 3600 * 24 * 365 / 3
9089

9190
return {
9291
poolID, lpTokenAmount, totalDeposited, pendingReward, tokens, rewardPerYear, lpAddress, lpTransactions
@@ -102,9 +101,18 @@ class MasterChef {
102101
this.totalAllocPoint = await this.contract.methods.totalAllocPoint().call()
103102

104103
try {
105-
this.rewardPerBlock = await this.contract.methods.cakePerBlock().call() // TODO change reward per block
104+
this.rewardPerBlock = await this.contract.methods[this.pendingSymbol.toLowerCase() + 'PerBlock']().call()
106105
} catch (e) {
107-
this.rewardPerBlock = 0
106+
try {
107+
this.rewardPerBlock = await this.contract.methods[this.pendingSymbol + 'PerBlock']().call()
108+
} catch (e) {
109+
try {
110+
const ABISymbol = this.pendingMethodName.replace('pending', '').toLowerCase()
111+
this.rewardPerBlock = await this.contract.methods[ABISymbol + 'PerBlock']().call()
112+
} catch (e) {
113+
this.rewardPerBlock = 0
114+
}
115+
}
108116
}
109117

110118
let pools = []

src/providers/bsc/PancakeSwapCloneChef.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ const MasterChef = require('./MasterChef')
44
const pancakeSwapABI = require('../resources/abis/pancakeSwap.json')
55

66
class PancakeSwapCloneChef extends MasterChef {
7-
constructor (web3, address, pendingMethodName, tokenSymbol = '') {
8-
const newChefABI = pancakeSwapABI.map(method => {
9-
if (method.name !== 'pendingCake') {
10-
return method
11-
}
12-
const newMethod = { ...method }
13-
newMethod.name = pendingMethodName
14-
return newMethod
15-
})
16-
super(web3, newChefABI, address, pendingMethodName)
7+
constructor (web3, address, pendingMethodName, tokenSymbol) {
8+
const ABISymbol = pendingMethodName.replace('pending', '').toLowerCase()
9+
10+
const newChefABI = pancakeSwapABI
11+
.map(replaceABIMap('pendingCake', pendingMethodName))
12+
.map(replaceABIMap('cakePerBlock', ABISymbol + 'PerBlock'))
13+
super(web3, newChefABI, address, pendingMethodName, tokenSymbol)
14+
}
15+
}
16+
17+
function replaceABIMap (methodToReplace, newMethodName) {
18+
return method => {
19+
if (method.name !== methodToReplace) {
20+
return method
21+
}
22+
const newMethod = { ...method }
23+
newMethod.name = newMethodName
24+
return newMethod
1725
}
1826
}
1927

src/providers/bsc/Token.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const tokenABI = require('../resources/abis/token.json')
2+
const Web3 = require('web3')
23

34
class Token {
45
constructor (web3, address) {
@@ -9,6 +10,7 @@ class Token {
910
async init () {
1011
this.symbol = await this.contract.methods.symbol().call()
1112
this.decimals = await this.contract.methods.decimals().call()
13+
this.totalSupply = Web3.utils.fromWei(await this.contract.methods.totalSupply().call())
1214
return this
1315
}
1416

@@ -19,7 +21,7 @@ class Token {
1921
}
2022

2123
share (lpTokenAmount) {
22-
return 0 // TODO implement this
24+
return lpTokenAmount / this.totalSupply // TODO might not be correct
2325
}
2426
}
2527

0 commit comments

Comments
 (0)