Skip to content

Commit

Permalink
fixup! Add Coreum native staking via StakeKit
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Jan 22, 2024
1 parent e4858c5 commit bb38691
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ActionRequestDto, TransactionDto } from '@stakekit/api-hooks'
import { add, div, eq, floor, gt, mul, sub } from 'biggystring'
import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'

import { DECIMAL_PRECISION } from '../../../../util/utils'
import { AssetId, ChangeQuote, PositionAllocation, QuoteAllocation, StakePosition } from '../../types'
import { StakePolicyConfig } from '../types'
import {
Expand All @@ -13,7 +14,6 @@ import {
yieldGetSingleYieldBalances,
yieldYieldOpportunity
} from '../util/stakeKitUtils'
import { convertNativeToExchange, DECIMAL_PRECISION } from '../../../../util/utils'
import { StakePolicyAdapter } from './types'

export interface CoreumNativeSkateKitAdapterConfig {
Expand Down Expand Up @@ -119,7 +119,7 @@ export const makeSkateKitAdapter = (policyConfig: StakePolicyConfig<CoreumNative
const unsignedTransactions = await getUnsignedTransactions(actionPendingRes.transactions)

const edgeTxs = unsignedTransactions.map(tx => {
const networkFee = convertNativeToExchange(exchangeDenomMultiplier)(tx.gasEstimate?.amount ?? '0')
const networkFee = mul(exchangeDenomMultiplier, tx.gasEstimate?.amount ?? '0')

const edgeTx: EdgeTransaction = {
blockHeight: 0,
Expand Down Expand Up @@ -171,7 +171,7 @@ export const makeSkateKitAdapter = (policyConfig: StakePolicyConfig<CoreumNative
const unsignedTransactions = await getUnsignedTransactions(actionEnterRes.transactions)

const edgeTxs = unsignedTransactions.map(tx => {
const networkFee = convertNativeToExchange(exchangeDenomMultiplier)(tx.gasEstimate?.amount ?? '0')
const networkFee = mul(exchangeDenomMultiplier, tx.gasEstimate?.amount ?? '0')

const edgeTx: EdgeTransaction = {
blockHeight: 0,
Expand Down Expand Up @@ -235,7 +235,7 @@ export const makeSkateKitAdapter = (policyConfig: StakePolicyConfig<CoreumNative
const unsignedTransactions = await getUnsignedTransactions(actionExitRes.transactions)

const edgeTxs = unsignedTransactions.map(tx => {
const networkFee = convertNativeToExchange(exchangeDenomMultiplier)(tx.gasEstimate?.amount ?? '0')
const networkFee = mul(exchangeDenomMultiplier, tx.gasEstimate?.amount ?? '0')

const edgeTx: EdgeTransaction = {
blockHeight: 0,
Expand Down Expand Up @@ -393,7 +393,10 @@ export const makeSkateKitAdapter = (policyConfig: StakePolicyConfig<CoreumNative

async fetchYieldInfo() {
const yieldRes = await yieldYieldOpportunity(adapterConfig.integrationId)
return { apy: yieldRes.apy * 100 }
const validatorApr = yieldRes.validators.find(validator => validator.address === adapterConfig.preferredValidatorAddress)
if (validatorApr == null) return { apy: 0 }

return { apy: validatorApr.apr * 100 }
}
}

Expand Down

0 comments on commit bb38691

Please sign in to comment.