Skip to content

Commit

Permalink
Mainnet (#31)
Browse files Browse the repository at this point in the history
* [mainnet] change paths and add mainnet

* [mainnet] set mainnet url
  • Loading branch information
Cast0001 authored Nov 3, 2023
1 parent f329c0b commit 12e0ad7
Show file tree
Hide file tree
Showing 30 changed files with 67 additions and 76 deletions.
2 changes: 1 addition & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import configs from './src/utils/configs'


// For every netwrok we have same gql shema, so we can use just Mainnet here
const urls = configs[Network.Holesky].api // TODO replace on Mainnet
const urls = configs[Network.Mainnet].api

// https://the-guild.dev/graphql/codegen/plugins/typescript/typescript
const typesConfig = {
Expand Down
10 changes: 8 additions & 2 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
export * as backend from './backend'
export * as subgraph from './subgraph'
import * as backend from './backend'
import * as subgraph from './subgraph'


export default {
backend,
subgraph,
}
2 changes: 1 addition & 1 deletion src/methods/osToken/requests/getOsTokenAPY/calculateAPY.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigDecimal } from '../../../../utils'
import { OsTokenSnapshotsQueryPayload } from '../../../../graphql/subgraph/osToken'
import type { OsTokenSnapshotsQueryPayload } from '../../../../graphql/subgraph/osToken'


type CalculateApyInput = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apiUrls } from '../../../../utils'
import { subgraph } from '../../../../graphql'
import graphql from '../../../../graphql'


export type FetchOsTokenSnapshotsInput = {
Expand All @@ -9,7 +9,7 @@ export type FetchOsTokenSnapshotsInput = {
const fetchOsTokenSnapshots = async (input: FetchOsTokenSnapshotsInput) => {
const { options } = input

const data = await subgraph.osToken.fetchOsTokenSnapshotsQuery({
const data = await graphql.subgraph.osToken.fetchOsTokenSnapshotsQuery({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
first: 14,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subgraph } from '../../../../graphql'
import graphql from '../../../../graphql'
import { apiUrls } from '../../../../utils'


Expand All @@ -11,7 +11,7 @@ type GetOsTokenPositionSharesInput = {
const getOsTokenPositionShares = async (values: GetOsTokenPositionSharesInput) => {
const { options, vaultAddress, userAddress } = values

const result = await subgraph.osToken.fetchOsTokenPositionsQuery({
const result = await graphql.subgraph.osToken.fetchOsTokenPositionsQuery({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
vaultAddress,
Expand Down
8 changes: 3 additions & 5 deletions src/methods/utils/getSwiseUsdPrice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { backend } from '../../graphql'
import { apiUrls } from '../../utils'
import graphql from '../../graphql'


type GetSwiseUsdPriceInput = {
Expand All @@ -9,10 +9,8 @@ type GetSwiseUsdPriceInput = {
const getSwiseUsdPrice = async (input: GetSwiseUsdPriceInput) => {
const { options } = input

const data = await backend.swise.fetchSwiseStatsQuery({
// TODO remove when mainnet backend will be ready
url: 'https://testnet-api.stakewise.io/graphql',
// url: apiUrls.getBackendUrl(options),
const data = await graphql.backend.swise.fetchSwiseStatsQuery({
url: apiUrls.getBackendUrl(options),
})

return data?.swiseStats?.price || '0'
Expand Down
6 changes: 3 additions & 3 deletions src/methods/utils/getTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransactionsQueryVariables } from '../../graphql/subgraph/transactions'
import type { TransactionsQueryVariables } from '../../graphql/subgraph/transactions'
import { apiUrls, validateArgs } from '../../utils'
import { subgraph } from '../../graphql'
import graphql from '../../graphql'


type GetTransactionsInput = {
Expand All @@ -13,7 +13,7 @@ const getTransactions = async (input: GetTransactionsInput) => {

validateArgs.string({ hash })

const data = await subgraph.transactions.fetchTransactionsQuery({
const data = await graphql.subgraph.transactions.fetchTransactionsQuery({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
where: {
Expand Down
6 changes: 3 additions & 3 deletions src/methods/vault/requests/getDaySnapshots/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DaySnapshotsQueryVariables } from '../../../../graphql/subgraph/daySnapshots'
import type { DaySnapshotsQueryVariables } from '../../../../graphql/subgraph/daySnapshots'
import { apiUrls, validateArgs } from '../../../../utils'
import modifyDaySnapshots from './modifyDaySnapshots'
import { ModifiedDaySnapshots } from './types'
import { subgraph } from '../../../../graphql'
import graphql from '../../../../graphql'


type GetDaySnapshotsInput = {
Expand All @@ -17,7 +17,7 @@ const getDaySnapshots = async (input: GetDaySnapshotsInput) => {
validateArgs.address({ vaultAddress })
validateArgs.number({ unixStartOfDay })

const data = await subgraph.daySnapshots.fetchDaySnapshotsQuery<ModifiedDaySnapshots>({
const data = await graphql.subgraph.daySnapshots.fetchDaySnapshotsQuery<ModifiedDaySnapshots>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
where: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DaySnapshotsQueryPayload } from '../../../../graphql/subgraph/daySnapshots'
import type { DaySnapshotsQueryPayload } from '../../../../graphql/subgraph/daySnapshots'
import modifyDaySnapshots, { modifyDaySnapshot } from './modifyDaySnapshots'


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatEther } from 'ethers'

import { ModifiedDaySnapshots } from './types'
import { DaySnapshotsQueryPayload } from '../../../../graphql/subgraph/daySnapshots'
import type { DaySnapshotsQueryPayload } from '../../../../graphql/subgraph/daySnapshots'


export const modifyDaySnapshot = (daySnapshot: Omit<DaySnapshotsQueryPayload['daySnapshots'][number], 'date'>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subgraph } from '../../../../graphql'
import graphql from '../../../../graphql'
import { apiUrls } from '../../../../utils'


Expand All @@ -11,7 +11,7 @@ export type FetchExitQueuePositionsInput = {
const fetchExitQueuePositions = async (values: FetchExitQueuePositionsInput) => {
const { options, vaultAddress, userAddress } = values

const data = await subgraph.exitQueue.fetchExitQueueQuery({
const data = await graphql.subgraph.exitQueue.fetchExitQueueQuery({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
vault: vaultAddress.toLowerCase(),
Expand Down
4 changes: 2 additions & 2 deletions src/methods/vault/requests/getHarvestParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apiUrls, validateArgs } from '../../../utils'
import { subgraph } from '../../../graphql'
import graphql from '../../../graphql'


type GetHarvestParamsInput = {
Expand All @@ -12,7 +12,7 @@ const getHarvestParams = async (values: GetHarvestParamsInput) => {

validateArgs.address({ vaultAddress })

const result = await subgraph.vault.fetchHarvestParamsQuery({
const result = await graphql.subgraph.vault.fetchHarvestParamsQuery({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
address: vaultAddress.toLowerCase(),
Expand Down
5 changes: 3 additions & 2 deletions src/methods/vault/requests/getMaxWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const getMaxWithdraw = async (values: GetMaxWithdrawInput) => {
.minus(lockedAssets)
.divide(constants.blockchain.amount1)
.decimals(18)
.toString()

return maxWithdrawAssets.gt(0)
? parseEther(maxWithdrawAssets.toString())
return Number(maxWithdrawAssets) > 0
? parseEther(maxWithdrawAssets)
: 0n
}

Expand Down
4 changes: 2 additions & 2 deletions src/methods/vault/requests/getStakerActions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AllocatorActionsQueryVariables, AllocatorActionsQueryPayload } fro
import { AllocatorActionType, apiUrls, validateArgs } from '../../../../utils'
import modifyStakerActions from './modifyStakerActions'
import { ModifiedStakerActions } from './types'
import { subgraph } from '../../../../graphql'
import graphql from '../../../../graphql'


type GetStakerActionsInput = {
Expand Down Expand Up @@ -38,7 +38,7 @@ const getStakerActions = async (input: GetStakerActionsInput) => {
})
}

const data = await subgraph.allocatorActions.fetchAllocatorActionsQuery<ModifiedStakerActions>({
const data = await graphql.subgraph.allocatorActions.fetchAllocatorActionsQuery<ModifiedStakerActions>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
skip,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatEther } from 'ethers'

import { AllocatorActionsQueryPayload } from '../../../../graphql/subgraph/allocatorActions'
import type { AllocatorActionsQueryPayload } from '../../../../graphql/subgraph/allocatorActions'
import { Network, configs } from '../../../../utils'
import { ModifiedStakerActions } from './types'

Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/requests/getStakerActions/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AllocatorActionsQueryPayload } from '../../../../graphql/subgraph/allocatorActions'
import type { AllocatorActionsQueryPayload } from '../../../../graphql/subgraph/allocatorActions'


type AllocatorActionsPayload = Pick<AllocatorActionsQueryPayload['allocatorActions'][number], 'id' | 'actionType' | 'assets'>
Expand Down
6 changes: 3 additions & 3 deletions src/methods/vault/requests/getUserRewards/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UserRewardsQueryVariables } from '../../../../graphql/backend/vault'
import type { UserRewardsQueryVariables } from '../../../../graphql/backend/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import modifyUserRewards from './modifyUserRewards'
import { backend } from '../../../../graphql'
import graphql from '../../../../graphql'
import { ModifyUserReward } from './types'


Expand All @@ -18,7 +18,7 @@ const getUserRewards = async (input: GetUserRewardsInput) => {
validateArgs.address({ vaultAddress, userAddress })
validateArgs.string({ dateFrom })

const data = await backend.vault.fetchUserRewardsQuery<ModifyUserReward>({
const data = await graphql.backend.vault.fetchUserRewardsQuery<ModifyUserReward>({
url: apiUrls.getBackendUrl(options),
variables: {
vaultAddress: vaultAddress.toLowerCase(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserRewardsQueryPayload } from '../../../../graphql/backend/vault'
import type { UserRewardsQueryPayload } from '../../../../graphql/backend/vault'
import modifyUserRewards, { modifyUserReward } from './modifyUserRewards'


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatEther } from 'ethers'

import { ModifyUserReward } from './types'
import { UserRewardsQueryPayload } from '../../../../graphql/backend/vault'
import type { UserRewardsQueryPayload } from '../../../../graphql/backend/vault'


export const modifyUserReward = (reward: Omit<UserRewardsQueryPayload['userRewards'][number], 'date'>) => {
Expand Down
6 changes: 3 additions & 3 deletions src/methods/vault/requests/getValidators/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { VaultValidatorsQueryVariables, VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'
import type { VaultValidatorsQueryVariables, VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import type { ModifiedValidators } from './types'
import modifyValidators from './modifyValidators'
import { backend } from '../../../../graphql'
import graphql from '../../../../graphql'


type GetValidatorsInput = {
Expand All @@ -15,7 +15,7 @@ const getValidators = async (input: GetValidatorsInput) => {

validateArgs.address({ vaultAddress })

const data = await backend.vault.fetchVaultValidatorsQuery<ModifiedValidators>({
const data = await graphql.backend.vault.fetchVaultValidatorsQuery<ModifiedValidators>({
url: apiUrls.getBackendUrl(options),
variables: { address: vaultAddress.toLowerCase() },
modifyResult: (data: VaultValidatorsQueryPayload) => modifyValidators({ data, network: options.network }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatEther } from 'ethers'

import { VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'
import type { VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'
import { Network, configs } from '../../../../utils'
import modifyValidators from './modifyValidators'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatEther } from 'ethers'

import type { ModifiedValidators } from './types'
import { Network, configs } from '../../../../utils'
import { VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'
import type { VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'


type ModifyValidatorsInput = {
Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/requests/getValidators/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'
import type { VaultValidatorsQueryPayload } from '../../../../graphql/backend/vault'

// earned: string, createdAt: string, publicKey: string, apy: string
type AllocatorActionsPayload = Pick<VaultValidatorsQueryPayload['vaults'][number]['validators'][number], 'apy' | 'publicKey' | 'earned'>
Expand Down
6 changes: 3 additions & 3 deletions src/methods/vault/requests/getVault/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VaultQueryVariables, VaultQueryPayload } from '../../../../graphql/subgraph/vault'
import type { VaultQueryVariables, VaultQueryPayload } from '../../../../graphql/subgraph/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import { subgraph } from '../../../../graphql'
import graphql from '../../../../graphql'
import { ModifiedVault } from './types'
import modifyVault from './modifyVault'

Expand All @@ -20,7 +20,7 @@ const getVault = async (input: GetVaultInput): Promise<GetVaultOutput> => {

validateArgs.address({ vaultAddress })

const data = await subgraph.vault.fetchVaultQuery<ModifiedVault>({
const data = await graphql.subgraph.vault.fetchVaultQuery<ModifiedVault>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
address: vaultAddress.toLowerCase(),
Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/requests/getVault/modifyVault.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MaxUint256 } from 'ethers'

import modifyVault from './modifyVault'
import { Network, configs } from '../../../../utils'
import { VaultQueryPayload } from '../../../../graphql/subgraph/vault'
import type { VaultQueryPayload } from '../../../../graphql/subgraph/vault'


const network = Network.Goerli
Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/requests/getVault/modifyVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatEther, getAddress, MaxUint256 } from 'ethers'

import { ModifiedVault } from './types'
import { Network, configs } from '../../../../utils'
import { VaultQueryPayload } from '../../../../graphql/subgraph/vault'
import type { VaultQueryPayload } from '../../../../graphql/subgraph/vault'


type ModifyVaultInput = {
Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/requests/getVault/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VaultQueryPayload } from '../../../../graphql/subgraph/vault'
import type { VaultQueryPayload } from '../../../../graphql/subgraph/vault'


export type ModifiedVault = Omit<
Expand Down
7 changes: 0 additions & 7 deletions src/utils/BigDecimal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,4 @@ describe('BigDecimal', () => {
decimal.plus(25.5)
expect(decimal.toString()).toBe('125.5')
})

it('should correctly compare values with gt', () => {
const decimal = new BigDecimal(100)
expect(decimal.gt(50)).toBe(true)
expect(decimal.gt(100)).toBe(false)
expect(decimal.gt(150)).toBe(false)
})
})
5 changes: 0 additions & 5 deletions src/utils/BigDecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class BigDecimal {
return this
}

// TODO remove ?
gt(value: number) {
return this.#value.gt(value)
}

toString() {
return String(this.#value)
}
Expand Down
Loading

0 comments on commit 12e0ad7

Please sign in to comment.