-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ec477f
commit 728b2f9
Showing
8 changed files
with
329 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getDelegatedStakingActivities, getNumberOfDelegators } from "../internal/staking"; | ||
import { HexInput } from "../types"; | ||
import { GetDelegatedStakingActivitiesQuery, GetNumberOfDelegatorsQuery } from "../types/generated/operations"; | ||
import { AptosConfig } from "./aptos_config"; | ||
|
||
/** | ||
* A class to query all `Staking` related queries on Aptos. | ||
*/ | ||
export class Staking { | ||
readonly config: AptosConfig; | ||
|
||
constructor(config: AptosConfig) { | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Queries current number of delegators in a pool | ||
* | ||
* @returns GetNumberOfDelegatorsQuery response type | ||
*/ | ||
async getNumberOfDelegators(args: { poolAddress: HexInput }): Promise<GetNumberOfDelegatorsQuery> { | ||
const numDelegators = await getNumberOfDelegators({ aptosConfig: this.config, ...args }); | ||
return numDelegators; | ||
} | ||
|
||
/** | ||
* Queries delegated staking activities | ||
* | ||
* @param delegatorAddress Delegator address | ||
* @param poolAddress Pool address | ||
* @returns GetDelegatedStakingActivitiesQuery response type | ||
*/ | ||
async getDelegatedStakingActivities(args: { | ||
delegatorAddress: HexInput; | ||
poolAddress: HexInput; | ||
}): Promise<GetDelegatedStakingActivitiesQuery> { | ||
const delegatedStakingActivities = await getDelegatedStakingActivities({ aptosConfig: this.config, ...args }); | ||
return delegatedStakingActivities; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/internal/queries/getDelegatedStakingActivities.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
query getDelegatedStakingActivities($delegatorAddress: String, $poolAddress: String) { | ||
delegated_staking_activities( | ||
where: { delegator_address: { _eq: $delegatorAddress }, pool_address: { _eq: $poolAddress } } | ||
) { | ||
amount | ||
delegator_address | ||
event_index | ||
event_type | ||
pool_address | ||
transaction_version | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query getNumberOfDelegators($poolAddress: String) { | ||
num_active_delegator_per_pool( | ||
where: { pool_address: { _eq: $poolAddress }, num_active_delegator: { _gt: "0" } } | ||
distinct_on: pool_address | ||
) { | ||
num_active_delegator | ||
pool_address | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/** | ||
* This file contains the underlying implementations for exposed API surface in | ||
* the {@link api/staking}. By moving the methods out into a separate file, | ||
* other namespaces and processes can access these methods without depending on the entire | ||
* faucet namespace and without having a dependency cycle error. | ||
*/ | ||
|
||
import { AptosConfig } from "../api/aptos_config"; | ||
import { Hex } from "../core"; | ||
import { HexInput } from "../types"; | ||
import { GetDelegatedStakingActivitiesQuery, GetNumberOfDelegatorsQuery } from "../types/generated/operations"; | ||
import { GetDelegatedStakingActivities, GetNumberOfDelegators } from "../types/generated/queries"; | ||
import { queryIndexer } from "./general"; | ||
|
||
export async function getNumberOfDelegators(args: { | ||
aptosConfig: AptosConfig; | ||
poolAddress: HexInput; | ||
}): Promise<GetNumberOfDelegatorsQuery> { | ||
const { aptosConfig, poolAddress } = args; | ||
const address = Hex.fromHexInput({ hexInput: poolAddress }).toString(); | ||
const query = { | ||
query: GetNumberOfDelegators, | ||
variables: { poolAddress: address }, | ||
}; | ||
return queryIndexer({ aptosConfig, query }); | ||
} | ||
|
||
export async function getDelegatedStakingActivities(args: { | ||
aptosConfig: AptosConfig; | ||
delegatorAddress: HexInput; | ||
poolAddress: HexInput; | ||
}): Promise<GetDelegatedStakingActivitiesQuery> { | ||
const { aptosConfig, delegatorAddress, poolAddress } = args; | ||
const query = { | ||
query: GetDelegatedStakingActivities, | ||
variables: { | ||
delegatorAddress: Hex.fromHexInput({ hexInput: delegatorAddress }).toString(), | ||
poolAddress: Hex.fromHexInput({ hexInput: poolAddress }).toString(), | ||
}, | ||
}; | ||
return queryIndexer({ aptosConfig, query }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.