Skip to content

Commit

Permalink
Fix staking claimable value (#209)
Browse files Browse the repository at this point in the history
* Fix staking claimable value

* Update yarn.lock
  • Loading branch information
apporc authored Sep 10, 2024
1 parent 5767681 commit 63b31f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1741,10 +1741,10 @@ ajv@^8.0.1:
require-from-string "^2.0.2"
uri-js "^4.2.2"

anchor-link-browser-transport@^3.2.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/anchor-link-browser-transport/-/anchor-link-browser-transport-3.3.0.tgz#ffb4f0e41cc2b900a714be3969e322491110b4f9"
integrity sha512-0pHuBtxtzdT4hkbtMVfjT0ksAfWvmTwyzldxI32I2oo4j3jsao7IfqCf/Oew5DqMOr9ZSDYQiwbPxt8QhU1zOQ==
anchor-link-browser-transport@^3.2.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/anchor-link-browser-transport/-/anchor-link-browser-transport-3.6.1.tgz#8e112f00f2322f466bb69a93008976df1021b9c8"
integrity sha512-lrV+qpXVN28VyAK3nKTXKvBQNLdKcwqTM92iBBnZVqulPFhhNAVAqDeLgq78zd9Pl4m9Cdq27hlSC1wcMyr63w==
dependencies:
tslib "^2.0.3"

Expand Down

0 comments on commit 63b31f1

Please sign in to comment.