Skip to content

Commit 857a4f9

Browse files
committed
feat: add valuedefi vfarm
1 parent 9fec18f commit 857a4f9

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/providers/BSCDeFi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class BSCDeFi extends AbstractExplorer {
3737
pancakeSwap: new PancakeSwapChef(web3),
3838
ramen: new PancakeSwapCloneChef(web3, '0x97dd424b4628c8d3bd7fcf3a4e974cebba011651', 'pendingCake', 'RAMEN'),
3939
saltSwap: new PancakeSwapCloneChef(web3, '0xB4405445fFAcF2B86BC2bD7D1C874AC739265658', 'pendingSalt', 'SALT'),
40-
slime: new PancakeSwapCloneChef(web3, '0x4B0073A79f2b46Ff5a62fA1458AAc86Ed918C80C', 'pendingReward', 'SLIME')
40+
slime: new PancakeSwapCloneChef(web3, '0x4B0073A79f2b46Ff5a62fA1458AAc86Ed918C80C', 'pendingReward', 'SLIME', 'slimesPerBlock'),
41+
valueDefi: new PancakeSwapCloneChef(web3, '0xd56339F80586c08B7a4E3a68678d16D37237Bd96', 'pendingReward', 'vBSWAP', 'getCurrentRewardPerBlock')
4142
}
4243
}
4344

src/providers/bsc/MasterChef.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,29 @@ class MasterChef {
9696
return await this.contract.methods.poolLength().call()
9797
}
9898

99-
async listStakedPools (walletAddress, tx) {
100-
const poolLength = await this.getPoolLength()
101-
this.totalAllocPoint = await this.contract.methods.totalAllocPoint().call()
102-
99+
async getRewardPerBlock () {
103100
try {
104-
this.rewardPerBlock = await this.contract.methods[this.pendingSymbol.toLowerCase() + 'PerBlock']().call()
101+
return await this.contract.methods[this.pendingSymbol.toLowerCase() + 'PerBlock']().call()
105102
} catch (e) {
106103
try {
107-
this.rewardPerBlock = await this.contract.methods[this.pendingSymbol + 'PerBlock']().call()
104+
return await this.contract.methods[this.pendingSymbol + 'PerBlock']().call()
108105
} catch (e) {
109106
try {
110107
const ABISymbol = this.pendingMethodName.replace('pending', '').toLowerCase()
111-
this.rewardPerBlock = await this.contract.methods[ABISymbol + 'PerBlock']().call()
108+
return await this.contract.methods[ABISymbol + 'PerBlock']().call()
112109
} catch (e) {
113-
this.rewardPerBlock = 0
110+
console.warn('Pending reward method not found. rewardPerYear is not correctly calculated.', this.address)
111+
return 0
114112
}
115113
}
116114
}
115+
}
116+
117+
async listStakedPools (walletAddress, tx) {
118+
const poolLength = await this.getPoolLength()
119+
this.totalAllocPoint = await this.contract.methods.totalAllocPoint().call()
120+
121+
this.rewardPerBlock = await this.getRewardPerBlock()
117122

118123
let pools = []
119124
for (let poolID = 1; poolID < poolLength; poolID++) {

src/providers/bsc/PancakeSwapCloneChef.js

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

66
class PancakeSwapCloneChef extends MasterChef {
7-
constructor (web3, address, pendingMethodName, tokenSymbol) {
7+
constructor (web3, address, pendingMethodName, tokenSymbol, rewardPerBlockName = '') {
88
const ABISymbol = pendingMethodName.replace('pending', '').toLowerCase()
9-
9+
rewardPerBlockName = rewardPerBlockName !== '' ? rewardPerBlockName : ABISymbol + 'PerBlock'
1010
const newChefABI = pancakeSwapABI
1111
.map(replaceABIMap('pendingCake', pendingMethodName))
12-
.map(replaceABIMap('cakePerBlock', ABISymbol + 'PerBlock'))
12+
.map(replaceABIMap('cakePerBlock', rewardPerBlockName))
1313
super(web3, newChefABI, address, pendingMethodName, tokenSymbol)
14+
this.rewardPerBlockName = rewardPerBlockName
15+
}
16+
17+
async getRewardPerBlock () {
18+
try {
19+
return await this.contract.methods[this.rewardPerBlockName]().call()
20+
} catch (e) {
21+
return await MasterChef.prototype.getRewardPerBlock.call(this)
22+
}
1423
}
1524
}
1625

0 commit comments

Comments
 (0)