Skip to content

Commit

Permalink
[SDK-CORE] Added FlowOperator Query and its Entity (#1396)
Browse files Browse the repository at this point in the history
* Added, account token settings and query required for Permission and Allowance feature (Dashboard).

* fixed review comments

* fixed lint issue

* added flowOperator as filter option

* change entity name

* fix getRelevantAddressesFromResultCore

* undo sdk-redux version

---------

Co-authored-by: Kaspar Kallas <kaspar@superfluid.finance>
  • Loading branch information
msoni89 and kasparkallas authored May 15, 2023
1 parent 81b5e89 commit 719b259
Show file tree
Hide file tree
Showing 8 changed files with 1,458 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

### Added
- Subgraph query support for `FlowOperator`

## [0.6.5] - 2023-05-12

### Fixed
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from "./subgraph/entities/streamPeriod/streamPeriod";
export * from "./subgraph/entities/token/token";
export * from "./subgraph/entities/tokenStatistic/tokenStatistic";
export * from "./subgraph/entities/tokenStatisticLog/tokenStatisticLog";
export * from "./subgraph/entities/flowOperator/flowOperators";

export * from "./subgraph/events/events";
export * from "./subgraph/events/flowUpdatedEvent";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
query flowOperators(
$first: Int = 10
$orderBy: FlowOperator_orderBy = id
$orderDirection: OrderDirection = asc
$skip: Int = 0
$where: FlowOperator_filter = {}
$block: Block_height
) {
flowOperators(
first: $first
orderBy: $orderBy
orderDirection: $orderDirection
skip: $skip
where: $where
block: $block
) {
id
createdAtTimestamp
createdAtBlockNumber
updatedAtBlockNumber
updatedAtTimestamp
flowOperator
sender {
id
}
token {
id
}
flowRateAllowanceRemaining
permissions
allowance
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
Address,
BigNumber,
BlockNumber,
Timestamp,
} from "../../mappedSubgraphTypes";
import {
FlowOperator_Filter,
FlowOperator_OrderBy,
} from "../../schema.generated";
import {
RelevantAddressesIntermediate,
SubgraphListQuery,
SubgraphQueryHandler,
} from "../../subgraphQueryHandler";

import {
FlowOperatorsDocument,
FlowOperatorsQuery,
FlowOperatorsQueryVariables,
} from "./flowOperators.generated";

export interface FlowOperator {
id: string;
createdAtBlockNumber: BlockNumber;
createdAtTimestamp: Timestamp;
updatedAtBlockNumber: BlockNumber;
updatedAtTimestamp: Timestamp;
flowOperator: Address;
sender: Address;
token: Address;
flowRateAllowanceRemaining: BigNumber;
allowance: BigNumber;
permissions: number;
}

export type FlowOperatorListQuery = SubgraphListQuery<
FlowOperator_Filter,
FlowOperator_OrderBy
>;

export class FlowOperatorQueryHandler extends SubgraphQueryHandler<
FlowOperator,
FlowOperatorListQuery,
FlowOperatorsQuery,
FlowOperatorsQueryVariables
> {
getAddressFieldKeysFromFilter = (): {
accountKeys: (keyof FlowOperator_Filter)[];
tokenKeys: (keyof FlowOperator_Filter)[];
} => ({
accountKeys: ["sender", "flowOperator"],
tokenKeys: ["token"],
});

getRelevantAddressesFromResultCore = (
result: FlowOperator
): RelevantAddressesIntermediate => ({
accounts: [result.sender, result.flowOperator],
tokens: [result.token],
});

mapFromSubgraphResponse = (response: FlowOperatorsQuery): FlowOperator[] =>
response.flowOperators.map((x) => ({
...x,
sender: x.sender.id,
token: x.token.id,
createdAtTimestamp: Number(x.createdAtTimestamp),
createdAtBlockNumber: Number(x.createdAtBlockNumber),
updatedAtTimestamp: Number(x.updatedAtTimestamp),
updatedAtBlockNumber: Number(x.updatedAtBlockNumber),
}));
requestDocument = FlowOperatorsDocument;
}
Loading

0 comments on commit 719b259

Please sign in to comment.