Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full EL Reward Support + Search for Validators via WithdrawalCredentials/Address #255

Merged
merged 22 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/components/dashboard/dashboard.component.html
D13ce marked this conversation as resolved.
Show resolved Hide resolved
D13ce marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<div class="grid">
<ion-label class="income-title">
<span
tooltip="Today's consensus and execution reward income. Note that this is counted in beaconchain days, a beaconchain day starts at 2 PM UTC. "
tooltip="Today's consensus and execution reward income. Note that this is counted in beaconchain days, a beaconchain day starts might start mid day depending on the network. "
trigger="click"
hideDelayAfterClick="5000"
>Today</span
Expand Down
37 changes: 24 additions & 13 deletions src/app/components/dashboard/dashboard.component.ts
D13ce marked this conversation as resolved.
Show resolved Hide resolved
D13ce marked this conversation as resolved.
Show resolved Hide resolved
D13ce marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,10 @@ export class DashboardComponent implements OnInit {
this.storage.setBooleanSetting('rank_percent_mode', this.rankPercentMode)
}

private getChartToolTipCaption(timestamp: number, genesisTs: number, dataGroupLength: number) {
private getChartToolTipCaption(timestamp: number, genesisTs: number, slotTime: number, slotsPerEpoch: number, dataGroupLength: number) {
const dateToEpoch = (ts: number): number => {
const slot = Math.floor((ts / 1000 - genesisTs) / 12)
const epoch = Math.floor(slot / 32)
const slot = Math.floor((ts / 1000 - genesisTs) / slotTime)
const epoch = Math.floor(slot / slotsPerEpoch)
return Math.max(0, epoch)
}

Expand Down Expand Up @@ -590,7 +590,13 @@ export class DashboardComponent implements OnInit {
shared: true,
formatter: (tooltip) => {
// date and epoch
let text = this.getChartToolTipCaption(tooltip.chart.hoverPoints[0].x, network.genesisTs, tooltip.chart.hoverPoints[0].dataGroup.length)
let text = this.getChartToolTipCaption(
tooltip.chart.hoverPoints[0].x,
network.genesisTs,
network.slotsTime,
network.slotPerEpoch,
tooltip.chart.hoverPoints[0].dataGroup.length
)

// summary
for (let i = 0; i < tooltip.chart.hoverPoints.length; i++) {
Expand Down Expand Up @@ -663,14 +669,17 @@ export class DashboardComponent implements OnInit {
const network = this.api.getNetwork()

const getValueString = (value: BigNumber, type: RewardType): string => {
let text = `${value.toFixed(5)} ` + this.unit.getNetworkDefaultUnit(type).display
let text
if (type == 'cons') {
text = `${value.toFixed(5)} ` + this.unit.getNetworkDefaultUnit(type).display
if (!this.unit.isDefaultCurrency(this.unit.pref.Cons)) {
text += ` (${this.unit.convertToPref(value, this.unit.getNetworkDefaultCurrency(type), type)})`
}
} else if (type == 'exec') {
// Gnosis: All values provided by the API are in the CL currency, including the el rewards
text = `${this.unit.convertCLtoEL(value).toFixed(5)} ` + this.unit.getNetworkDefaultUnit(type).display
if (!this.unit.isDefaultCurrency(this.unit.pref.Exec)) {
text += ` (${this.unit.convertToPref(value, this.unit.getNetworkDefaultCurrency(type), type)})`
text += ` (${this.unit.convertToPref(this.unit.convertCLtoEL(value), this.unit.getNetworkDefaultCurrency(type), type)})`
}
}

Expand Down Expand Up @@ -719,10 +728,16 @@ export class DashboardComponent implements OnInit {
shared: true,
formatter: (tooltip) => {
// date and epoch
let text = this.getChartToolTipCaption(tooltip.chart.hoverPoints[0].x, network.genesisTs, tooltip.chart.hoverPoints[0].dataGroup.length)
let text = this.getChartToolTipCaption(
tooltip.chart.hoverPoints[0].x,
network.genesisTs,
network.slotsTime,
network.slotPerEpoch,
tooltip.chart.hoverPoints[0].dataGroup.length
)

// income
const consAndExecSameCurrency = this.unit.hasSameCLAndELCurrency()
// Gnosis: All values provided by the API are in the CL currency, including the el rewards which is why we can simply add them for total
let total = new BigNumber(0)
for (let i = 0; i < tooltip.chart.hoverPoints.length; i++) {
const type = tooltip.chart.hoverPoints[i].series.name == 'Execution' ? 'exec' : 'cons'
Expand All @@ -732,11 +747,7 @@ export class DashboardComponent implements OnInit {
tooltip.chart.hoverPoints[i].series.name
}: ${getValueString(value, type)}</b><br/>`

if (!consAndExecSameCurrency && type == 'exec') {
total = total.plus(this.unit.convertELtoCL(value))
} else {
total = total.plus(value)
}
total = total.plus(value)
}

// add total if hovered point contains rewards for both EL and CL
Expand Down
2 changes: 2 additions & 0 deletions src/app/models/StorageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface ApiNetwork {
genesisTs: number
elCurrency: NetworkMainCurrency
clCurrency: NetworkMainCurrency
slotPerEpoch: number
D13ce marked this conversation as resolved.
Show resolved Hide resolved
slotsTime: number
D13ce marked this conversation as resolved.
Show resolved Hide resolved
name: string
}

Expand Down
1 change: 1 addition & 0 deletions src/app/requests/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export class ValidatorViaWithdrawalAddress extends APIRequest<ETH1ValidatorRespo
constructor(ethAddress: string) {
super()
this.resource += ethAddress.replace(/\s/g, '')
this.resource += '?limit=300'
}
}

Expand Down
35 changes: 30 additions & 5 deletions src/app/services/unitconv.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,18 @@ export class UnitconvService {
return 'ETHER'
}

public convertELtoCL(cl: BigNumber) {
public convertELtoCL(el: BigNumber) {
if (this.hasSameCLAndELCurrency()) {
return el
}
return el.multipliedBy(this.lastPrice.mGNOXDAI)
}

public convertCLtoEL(cl: BigNumber) {
if (this.hasSameCLAndELCurrency()) {
return cl
}
return cl.multipliedBy(this.lastPrice.mGNOXDAI)
return cl.dividedBy(this.pref.Cons.unit.value).dividedBy(this.lastPrice.mGNOXDAI)
}

public getFiatCurrency(type: RewardType) {
Expand Down Expand Up @@ -241,9 +248,18 @@ export class UnitconvService {
}

private triggerPropertyChange() {
if (this.isDefaultCurrency(this.pref.Cons)) {
if (this.isDefaultCurrency(this.pref.Cons) && UnitconvService.currencyPipe.Cons == null) {
this.pref.Cons = this.createCurrency(this.getNetworkDefaultCurrency(this.pref.Cons), 'cons')
this.pref.Exec = this.createCurrency(this.getNetworkDefaultCurrency(this.pref.Cons), 'exec')
if (this.hasSameCLAndELCurrency()) {
this.pref.Exec = this.createCurrency(this.getNetworkDefaultCurrency(this.pref.Cons), 'exec')
} else {
this.pref.Exec = this.createCurrency(this.getNetworkDefaultCurrency(this.pref.Exec), 'exec')
}
if (this.api.isGnosis()) {
UnitconvService.currencyPipe.Exec = this.getNetworkDefaultCurrency(this.pref.Cons)
this.lastPrice.Exec = this.lastPrice.mGNOXDAI.dividedBy(32)
}

this.pref.RPL = this.createCurrency(this.getNetworkDefaultCurrency(this.pref.RPL), 'rpl')
return
}
Expand All @@ -263,22 +279,29 @@ export class UnitconvService {
throw new Error('Unsupported reward type')
}

public switchCurrencyPipe() {
private switchConsPipe() {
if (this.isDefaultCurrency(this.pref.Cons)) {
if (UnitconvService.currencyPipe.Cons == null) return
this.pref.Cons = this.createCurrency(UnitconvService.currencyPipe.Cons, 'cons')
} else {
UnitconvService.currencyPipe.Cons = this.pref.Cons.value
this.pref.Cons = this.createCurrency(this.getNetworkDefaultCurrency('cons'), 'cons')
}
}

private switchExecPipe() {
if (this.isDefaultCurrency(this.pref.Exec)) {
if (UnitconvService.currencyPipe.Exec == null) return
this.pref.Exec = this.createCurrency(UnitconvService.currencyPipe.Exec, 'exec')
} else {
UnitconvService.currencyPipe.Exec = this.pref.Exec.value
this.pref.Exec = this.createCurrency(this.getNetworkDefaultCurrency('exec'), 'exec')
}
}

public switchCurrencyPipe() {
this.switchConsPipe()
this.switchExecPipe()

this.pref.RPL = this.createCurrency(this.pref.Cons.value, 'rpl')
}
Expand Down Expand Up @@ -401,6 +424,8 @@ export class UnitconvService {
this.lastPrice.mGNOXDAI = this.lastPrice.Exec.dividedBy(this.lastPrice.Cons)
}

console.log('skipFetchingMGNOtoDAIPrice', skipFetchingMGNOtoDAIPrice, this.lastPrice.mGNOXDAI.toString())

this.triggerPropertyChange()
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/tab-validators/tab-validators.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(search)="searchEvent($event)"
(ionClear)="cancelSearch()"
(ionCancel)="cancelSearch()"
placeholder="Public Key / Index / Address"
placeholder="Public Key / Index / Address / Cred"
animated>
</ion-searchbar>

Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/EthereumUnits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class Unit {
public static RETH = new Unit('RETH', new BigNumber('1'), 2)
public static DAI_GNO_HELPER = new Unit('dummy', new BigNumber(1), 5, 'DAI-GNO')

public static XDAI = new Unit('DAI', new BigNumber('1'), 3, 'XXX-DAI', 'xDAI')
public static XDAI = new Unit('DAI', new BigNumber('1'), 4, 'XXX-DAI', 'xDAI')
public static GNO = new Unit('GNO', new BigNumber('0.03125'), 5, 'XXX-GNO', 'GNO')
public static MGNO = new Unit('mGNO', new BigNumber('1'), 5, 'XXX-GNO', 'mGNO')

Expand Down
14 changes: 14 additions & 0 deletions src/app/utils/NetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1606824023,
clCurrency: NetworkMainCurrency.ETH,
elCurrency: NetworkMainCurrency.ETH,
slotPerEpoch: 32,
slotsTime: 12,
name: 'Ethereum',
},
{
Expand All @@ -47,6 +49,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1638993340,
clCurrency: NetworkMainCurrency.GNO,
elCurrency: NetworkMainCurrency.xDAI,
slotPerEpoch: 16,
slotsTime: 5,
name: 'Gnosis',
},
{
Expand All @@ -61,6 +65,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1616508000,
clCurrency: NetworkMainCurrency.ETH,
elCurrency: NetworkMainCurrency.ETH,
slotPerEpoch: 32,
slotsTime: 12,
name: 'Ethereum',
},
{
Expand All @@ -75,6 +81,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1655733600,
clCurrency: NetworkMainCurrency.ETH,
elCurrency: NetworkMainCurrency.ETH,
slotPerEpoch: 32,
slotsTime: 12,
name: 'Ethereum',
},
{
Expand All @@ -89,6 +97,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1695902400,
clCurrency: NetworkMainCurrency.ETH,
elCurrency: NetworkMainCurrency.ETH,
slotPerEpoch: 32,
slotsTime: 12,
name: 'Ethereum',
},
{
Expand All @@ -103,6 +113,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1606824023,
clCurrency: NetworkMainCurrency.ETH,
elCurrency: NetworkMainCurrency.ETH,
slotPerEpoch: 32,
slotsTime: 12,
name: 'Ethereum',
},
{
Expand All @@ -117,6 +129,8 @@ export const MAP: ApiNetwork[] = [
genesisTs: 1606824023,
clCurrency: NetworkMainCurrency.ETH,
elCurrency: NetworkMainCurrency.ETH,
slotPerEpoch: 32,
slotsTime: 12,
name: 'Ethereum',
},
]
Expand Down