Skip to content

Commit

Permalink
feat: add valuedefi vfarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Coac committed Mar 27, 2021
1 parent 9fec18f commit 857a4f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/providers/BSCDeFi.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class BSCDeFi extends AbstractExplorer {
pancakeSwap: new PancakeSwapChef(web3),
ramen: new PancakeSwapCloneChef(web3, '0x97dd424b4628c8d3bd7fcf3a4e974cebba011651', 'pendingCake', 'RAMEN'),
saltSwap: new PancakeSwapCloneChef(web3, '0xB4405445fFAcF2B86BC2bD7D1C874AC739265658', 'pendingSalt', 'SALT'),
slime: new PancakeSwapCloneChef(web3, '0x4B0073A79f2b46Ff5a62fA1458AAc86Ed918C80C', 'pendingReward', 'SLIME')
slime: new PancakeSwapCloneChef(web3, '0x4B0073A79f2b46Ff5a62fA1458AAc86Ed918C80C', 'pendingReward', 'SLIME', 'slimesPerBlock'),
valueDefi: new PancakeSwapCloneChef(web3, '0xd56339F80586c08B7a4E3a68678d16D37237Bd96', 'pendingReward', 'vBSWAP', 'getCurrentRewardPerBlock')
}
}

Expand Down
21 changes: 13 additions & 8 deletions src/providers/bsc/MasterChef.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,29 @@ class MasterChef {
return await this.contract.methods.poolLength().call()
}

async listStakedPools (walletAddress, tx) {
const poolLength = await this.getPoolLength()
this.totalAllocPoint = await this.contract.methods.totalAllocPoint().call()

async getRewardPerBlock () {
try {
this.rewardPerBlock = await this.contract.methods[this.pendingSymbol.toLowerCase() + 'PerBlock']().call()
return await this.contract.methods[this.pendingSymbol.toLowerCase() + 'PerBlock']().call()
} catch (e) {
try {
this.rewardPerBlock = await this.contract.methods[this.pendingSymbol + 'PerBlock']().call()
return await this.contract.methods[this.pendingSymbol + 'PerBlock']().call()
} catch (e) {
try {
const ABISymbol = this.pendingMethodName.replace('pending', '').toLowerCase()
this.rewardPerBlock = await this.contract.methods[ABISymbol + 'PerBlock']().call()
return await this.contract.methods[ABISymbol + 'PerBlock']().call()
} catch (e) {
this.rewardPerBlock = 0
console.warn('Pending reward method not found. rewardPerYear is not correctly calculated.', this.address)
return 0
}
}
}
}

async listStakedPools (walletAddress, tx) {
const poolLength = await this.getPoolLength()
this.totalAllocPoint = await this.contract.methods.totalAllocPoint().call()

this.rewardPerBlock = await this.getRewardPerBlock()

let pools = []
for (let poolID = 1; poolID < poolLength; poolID++) {
Expand Down
15 changes: 12 additions & 3 deletions src/providers/bsc/PancakeSwapCloneChef.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ const MasterChef = require('./MasterChef')
const pancakeSwapABI = require('../resources/abis/pancakeSwap.json')

class PancakeSwapCloneChef extends MasterChef {
constructor (web3, address, pendingMethodName, tokenSymbol) {
constructor (web3, address, pendingMethodName, tokenSymbol, rewardPerBlockName = '') {
const ABISymbol = pendingMethodName.replace('pending', '').toLowerCase()

rewardPerBlockName = rewardPerBlockName !== '' ? rewardPerBlockName : ABISymbol + 'PerBlock'
const newChefABI = pancakeSwapABI
.map(replaceABIMap('pendingCake', pendingMethodName))
.map(replaceABIMap('cakePerBlock', ABISymbol + 'PerBlock'))
.map(replaceABIMap('cakePerBlock', rewardPerBlockName))
super(web3, newChefABI, address, pendingMethodName, tokenSymbol)
this.rewardPerBlockName = rewardPerBlockName
}

async getRewardPerBlock () {
try {
return await this.contract.methods[this.rewardPerBlockName]().call()
} catch (e) {
return await MasterChef.prototype.getRewardPerBlock.call(this)
}
}
}

Expand Down

0 comments on commit 857a4f9

Please sign in to comment.