Skip to content

Commit

Permalink
Michiel/add akash portfolio (#541)
Browse files Browse the repository at this point in the history
* first steps

* Integrate validators feature for akashv0

* Simplify extending Cosmos logic

* Remove unused imports

* Uncomment networks

* Enable portfolio for Akash

* Commnet livepeer mainnet network

* Commnet livepeer mainnet network

* fix validators expected returns

* apply code review

* use proper reducers

* add gas prices

* fix totalstake and delegation in general

* fix api_url

* correct staking denom to cosmossdk default for now

* add also default stake gas price

Co-authored-by: Bitcoinera <[email protected]>
  • Loading branch information
michielmulders and Bitcoinera authored Mar 31, 2020
1 parent f0c7924 commit 79070b5
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
17 changes: 17 additions & 0 deletions data/network-capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ const getNetworkCapabilities = {
action_deposit: false,
action_vote: false,
action_proposal: false
},
"akash-testnet": {
feature_session: true,
feature_explore: true,
feature_portfolio: true,
feature_validators: true,
feature_proposals: false,
feature_activity: false,
feature_explorer: false,
action_send: false,
action_claim_rewards: false,
action_delegate: false,
action_redelegate: false,
action_undelegate: false,
action_deposit: false,
action_vote: false,
action_proposal: false
}
}

Expand Down
7 changes: 6 additions & 1 deletion data/network-fees.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ const emoneyGasEstimates = {
ClaimRewardsTx: 550000
}

const akashGasEstimates = {
default: 200000
}

const networkGasEstimatesDictionary = {
"cosmos-hub-mainnet": cosmosGasEstimates,
"cosmos-hub-testnet": cosmosGasEstimates,
"terra-mainnet": terraGasEstimates,
"terra-testnet": terraGasEstimates,
"emoney-mainnet": emoneyGasEstimates,
"emoney-testnet": emoneyGasEstimates
"emoney-testnet": emoneyGasEstimates,
"akash-testnet": akashGasEstimates
}

module.exports = {getNetworkTransactionGasEstimates}
23 changes: 22 additions & 1 deletion data/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,28 @@ module.exports = [
enabled: false,
icon: 'https://app.lunie.io/img/networks/polkadot-testnet.png',
slug: 'kusama'
}
},
{
id: 'akash-testnet',
title: 'Akash Testnet',
chain_id: 'devnet',
api_url: 'http://95.179.133.80:8080',
rpc_url: 'wss://95.179.133.80:26657/websocket',
bech32_prefix: 'akash',
address_prefix: 'akash',
address_creator: 'cosmos',
ledger_app: 'cosmos',
network_type: 'cosmos',
source_class_name: 'source/akashV0-source',
block_listener_class_name: 'block-listeners/cosmos-node-subscription',
testnet: true,
...getNetworkCapabilities[`akash-testnet`],
default: false,
stakingDenom: 'STAKE',
enabled: false,
icon: 'https://app.lunie.io/img/networks/akash-testnet.png',
slug: 'akash-testnet'
},
// {
// id: 'livepeer-mainnet',
// title: 'Livepeer',
Expand Down
29 changes: 29 additions & 0 deletions lib/reducers/akashV0-reducers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const terraV3Reducers = require('./terraV3-reducers')

function blockReducer(networkId, block, transactions) {
return {
networkId,
height: block.block.header.height,
chainId: block.block.header.chain_id,
hash: block.block_id.hash,
time: block.block.header.time,
transactions,
proposer_address: block.block.header.proposer_address
}
}

function delegationReducer(delegation, validator) {
const delegationCoin = terraV3Reducers.coinReducer(delegation.balance)
return {
validatorAddress: delegation.validator_address,
delegatorAddress: delegation.delegator_address,
validator,
amount: delegationCoin.amount
}
}

module.exports = {
...terraV3Reducers,
blockReducer,
delegationReducer
}
48 changes: 48 additions & 0 deletions lib/source/akashV0-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const TerraV3API = require('./terraV3-source')
const CosmosV0API = require('./cosmosV0-source')

const gasPrices = [
{
denom: 'stake',
price: '0.01'
},
{
denom: 'akash',
price: '0.01'
}
]

class AkashV0API extends TerraV3API {
setReducers() {
this.reducers = require('../reducers/akashV0-reducers')
this.gasPrices = gasPrices
}

async getBlockByHeightV2(blockHeight) {
let block, transactions
if (blockHeight) {
const response = await Promise.all([
this.getRetry(`blocks/${blockHeight}`),
this.getTransactionsByHeight(blockHeight)
])
block = response[0]
transactions = response[1]
} else {
block = await this.getRetry(`blocks/latest`)
transactions = await this.getTransactionsV2ByHeight(
block.block.header.height
)
}
return this.reducers.blockReducer(this.networkId, block, transactions)
}

async getAllValidators(height) {
return CosmosV0API.prototype.getAllValidators.call(this, height)
}

async getExpectedReturns(validator) {
return CosmosV0API.prototype.getExpectedReturns.call(this, validator)
}
}

module.exports = AkashV0API

0 comments on commit 79070b5

Please sign in to comment.