toucan-sdk
Version:
A JavaScript SDK for Toucan Protocol. Works in the web browser and Node.js.
152 lines (148 loc) • 6.55 kB
TypeScript
/**
The OffsetHelper's purpose is to simplify the carbon offsetting process.
Copyright (C) 2022 Toucan Labs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Client } from "@urql/core";
import { IToucanCarbonOffsets } from "../typechain";
import { Network, PoolSymbol } from "../types";
import { AggregationsMethod, AllTCO2TokensMethod, BridgedBatchTokensMethod, CustomQueryMethod, PoolContentsMethod, ProjectByIdMethod, RedeemsMethod, TCO2TokenByFullSymbolMethod, TCO2TokenByIdMethod, UserBatchesMethod, UserRedeemsMethod, UserRetirementsMethod } from "../types/methods";
import { INetworkTokenAddresses } from "../utils/addresses";
/**
* @class ContractInteractions
* @description This class helps query Toucan or Toucan-related subgraphs
*/
declare class SubgraphInteractions {
network: Network;
addresses: INetworkTokenAddresses;
TCO2: IToucanCarbonOffsets | undefined;
graphClient: Client;
/**
*
* @param network network that you want to work on
*/
constructor(network: Network);
/**
*
* Note: It's very important that whenever you change the gql query of any existent
* methods, you also change the return type of the method (in types/methods.ts) to
* match it.
*
*/
/**
*
* @description fetches the batches of a user
* @param walletAddress address of user to query for
* @returns an array of BatchTokens (they contain different properties of the Batch)
*/
fetchUserBatches: UserBatchesMethod;
/**
*
* @description fetches properties of a TCO2
* @param id id of the TCO2 to query for; the id happens to be the same as the address e.g.: "0x004090eef602e024b2a6cb7f0c1edda992382994"
* @returns a TCO2Detail object with properties of the TCO2 (name, address, etc)
*/
fetchTCO2TokenById: TCO2TokenByIdMethod;
/**
*
* @description fetches properties of a TCO2
* @param symbol full symbol of the TCO2 to query for e.g.: "TCO2-VCS-1718-2013"
* @returns a TCO2Detail object with properties of the TCO2 (name, address, etc)
*/
fetchTCO2TokenByFullSymbol: TCO2TokenByFullSymbolMethod;
/**
*
* @description fetches TCO2Details of all TCO2s
* @returns an array of TCO2Detail objects with properties of the TCO2s (name, address, etc)
*/
fetchAllTCO2Tokens: AllTCO2TokensMethod;
/**
*
* @description fetches data about BatchTokens that have been bridged
* @returns an array of BatchTokens containing different properties like id, serialNumber or quantity
*/
fetchBridgedBatchTokens: BridgedBatchTokensMethod;
/**
*
* @description fetches retirements made by a user
* @param walletAddress address of the user/wallet to query for
* @param first how many retirements you want fetched; defaults to 100
* @param skip how many (if any) retirements you want skipped; defaults to 0
* @returns an array of objects containing properties of the retirements like id, creationTx, amount and more
*/
fetchUserRetirements: UserRetirementsMethod;
/**
*
* @description fetches redeems of a given pool
* @param pool symbol of pool to fetch for
* @param first how many redeems you want fetched; defaults to 100
* @param skip how many (if any) redeems you want skipped; defaults to 0
* @returns an array of objects with properties of the redeems like id, amount, timestamp and more
*/
fetchRedeems: RedeemsMethod;
/**
*
* @description fetches redeems of a given pool and user
* @param walletAddress address of the user/wallet to query for
* @param pool symbol of pool to fetch for
* @param first how many redeems you want fetched; defaults to 100
* @param skip how many (if any) redeems you want skipped; defaults to 0
* @returns an array of objects with properties of the redeems like id, amount, timestamp and more
*/
fetchUserRedeems: UserRedeemsMethod;
/**
*
* @description fetches TCO2 tokens that are part of the given pool
* @param pool symbol of the pool to fetch for
* @param first how many TCO2 tokens you want fetched; defaults to 1000
* @param skip how many (if any) retirements you want skipped; defaults to 0
* @returns an array of objects representing TCO2 tokens and containing properties like name, amount, methodology and more
*/
fetchPoolContents: PoolContentsMethod;
/**
*
* @description fetches a project by its id
* @param id id of the project to fetch; e.g.: "10"
* @returns an object with properties of the Project like projectId, region, standard and more
*/
fetchProjectById: ProjectByIdMethod;
/**
*
* @description fetch all aggregations (including, for example, tco2TotalRetired or totalCarbonBridged)
* @returns an array of Aggregation objects containing properties like id, key, value
*/
fetchAggregations: AggregationsMethod;
/**
*
* @description if pre-made queries to Toucan's Subgraph don't fit all your needs; use this for custom queries
* @param query a gql formated GraphQL query
* @param params any parameters you may want to pass to the query
* @returns all data fetched from query; you can use generics to declare what type to expect (if you're a fan of TS)
*/
fetchCustomQuery: CustomQueryMethod;
private extractPriceInUSD;
private fetchTokenPrice;
fetchTokenPriceOnDex: (pool: PoolSymbol) => Promise<{
price: number | null;
url: string | null;
liquidityUSD: number | null;
volumeUSD: number | null;
}>;
/**
*
* @description gets the contract of a pool token based on the symbol
* @param pool symbol of the pool (token) to use
* @returns a ethers.contract to interact with the pool
*/
private getPoolAddress;
}
export default SubgraphInteractions;