Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a Balancer API provider to fetch pool state for join txs; #97

Merged
merged 20 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ typechain-types
cache
artifacts

#IDE
.idea
22 changes: 22 additions & 0 deletions src/data/providers/balancer-api-provider/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export class BalancerApiClient {
subgraphUrl: string;
chainId: number;
constructor(subgraphUrl: string, chainId: number) {
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved
this.subgraphUrl = subgraphUrl;
this.chainId = chainId;
}

async fetch(operationName: string, query: any, variables: any) {
const requestQuery = {
operationName,
query,
variables,
};
const response = await fetch(this.subgraphUrl, {
method: 'post',
body: JSON.stringify(requestQuery),
headers: { 'Content-Type': 'application/json', ChainId: this.chainId.toString() },
});
return response.json();
}
}
16 changes: 16 additions & 0 deletions src/data/providers/balancer-api-provider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { JoinData } from "./modules/join";
import { BalancerApiClient } from "./client";

export default class BalancerApi {

balancerApiClient: BalancerApiClient;
joinData: JoinData;


constructor(balancerApiUrl: string, chainId: number){
this.balancerApiClient = new BalancerApiClient(balancerApiUrl, chainId);
this.joinData = new JoinData(this.balancerApiClient);
}


}
88 changes: 88 additions & 0 deletions src/data/providers/balancer-api-provider/modules/join/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { BalancerApiClient } from '../../client';
import { PoolState } from './types';

export class JoinData {
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved
readonly poolStateQuery = `query GetPool($id: String!){
poolGetPool(id:$id) {
id
address
name
type
version
... on GqlPoolWeighted {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
... on GqlPoolStable {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
... on GqlPoolPhantomStable {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
... on GqlPoolGyro {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
... on GqlPoolLiquidityBootstrapping {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
... on GqlPoolElement {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
... on GqlPoolLiquidityBootstrapping {
tokens {
... on GqlPoolTokenBase {
address
decimals
index
}
}
}
}
}`;

constructor(private readonly balancerApiClient: BalancerApiClient) {}

async fetchPoolState(id: string): Promise<PoolState> {
const {
data: { poolGetPool },
} = await this.balancerApiClient.fetch('GetPool', this.poolStateQuery, {
id,
});
return poolGetPool;
}
}
14 changes: 14 additions & 0 deletions src/data/providers/balancer-api-provider/modules/join/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Address } from "viem";
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved

export type PoolState = {
id: Address;
address: Address;
type: string;
version: string;
tokens: {
address: Address;
decimals: number;
index: number;
};
}[];

Loading