Skip to content

Commit

Permalink
Fix staking claimable value
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Sep 9, 2024
1 parent 5767681 commit 2d75ad6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/abi-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export class REXDeposit extends Struct {
@Struct.field('asset') amount!: Asset
}

@Struct.type('mvfrsavings')
export class MVFRSAVINGS extends Struct {
@Struct.field('name') owner!: Name
@Struct.field('asset') rex!: Asset
}

@Struct.type('rexwithdraw')
export class REXWithdraw extends Struct {
@Struct.field('name') owner!: Name
Expand Down
18 changes: 14 additions & 4 deletions src/pages/earn/index.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
import type {Readable, Writable} from 'svelte/store'
import {derived, writable, get} from 'svelte/store'
import {AnyAction, Asset, Int128} from 'anchor-link'
import {AnyAction, Asset, Int128, Int64} from 'anchor-link'
import {currentAccount} from '~/store'
import {activeBlockchain, activeSession} from '~/store'
import type {Token} from '~/stores/tokens'
import {systemTokenKey, tokens} from '~/stores/tokens'
import {balances} from '~/stores/balances'
import {REXDeposit, REXWithdraw, REXBUYREX, REXSELLREX} from '~/abi-types'
import {REXDeposit, MVFRSAVINGS, REXWithdraw, REXBUYREX, REXSELLREX} from '~/abi-types'
import type {FormTransaction} from '~/ui-types'
import {rexIsAvailable} from '~/lib/rex'
Expand Down Expand Up @@ -130,16 +130,26 @@
let matured = defaultZero
let apy = ''
const fiveYearsFromNow = new Date().getTime() + 1000 * 60 * 60 * 24 * 365 * 5
const now = new Date()
if ($stateREX && $stateREX.value) {
const annualReward = 31250000
const totalStaked = Number($stateREX.total_lendable.value)
apy = ((annualReward / totalStaked) * 100).toFixed(2)
if ($currentAccount && $currentAccount.rex_info) {
total = convertRexToEos($currentAccount.rex_info.rex_balance.value)
const claimableBuckets = $currentAccount.rex_info.rex_maturities.filter(
(maturity) => +new Date(maturity.first!.toString()) < +now
)
let claimable = claimableBuckets.reduce(
(acc, r) => acc.adding(r.second!),
Int64.from(0)
)
matured = convertRexToEos(
Asset.fromUnits(
$currentAccount.rex_info.matured_rex,
$currentAccount.rex_info.matured_rex.adding(claimable),
$currentAccount.rex_info.rex_balance.symbol
).value
)
Expand Down Expand Up @@ -278,7 +288,7 @@
authorization: [$activeSession!.auth],
account: 'eosio',
name: 'mvfrsavings',
data: REXWithdraw.from({
data: MVFRSAVINGS.from({
owner: $activeSession!.auth.actor,
amount: rexAmount,
}),
Expand Down

0 comments on commit 2d75ad6

Please sign in to comment.