@abstraxn/node-client
Version:
Node Client that comminucates with indexer service to fetch necessary details for the Smart Account
126 lines • 5.72 kB
JavaScript
;
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _NodeClient_txServiceBaseUrl;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const HttpRequests_1 = require("./utils/HttpRequests");
class NodeClient {
constructor({ txServiceUrl }) {
_NodeClient_txServiceBaseUrl.set(this, void 0);
__classPrivateFieldSet(this, _NodeClient_txServiceBaseUrl, (0, utils_1.getTxServiceBaseUrl)(txServiceUrl), "f");
}
/**
*
* @returns The list of Network info
*/
async getAllSupportedChains() {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/chains/`,
method: HttpRequests_1.HttpMethod.Get,
});
}
/**
*
* @param chainId
* @description thie function will return the chain detail base on supplied { chainId }
* @returns
*/
async getChainById(chainId) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/chains/${chainId}`,
method: HttpRequests_1.HttpMethod.Get,
});
}
/**
*
* @param chainId
* @description this function will return token price base on supplied {chainId}
* @returns
*/
async getTokenPricesByChainId(chainId) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/chains/chainId/${chainId}/price`,
method: HttpRequests_1.HttpMethod.Get,
});
}
async getAllTokens() {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/tokens/`,
method: HttpRequests_1.HttpMethod.Get,
});
}
async getTokensByChainId(chainId) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/tokens/chainId/${chainId}`,
method: HttpRequests_1.HttpMethod.Get,
});
}
async getTokenByChainIdAndAddress(tokenByChainIdAndAddressDto) {
const { chainId, tokenAddress } = tokenByChainIdAndAddressDto;
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/tokens/chainId/${chainId}/address/${tokenAddress}`,
method: HttpRequests_1.HttpMethod.Get,
});
}
async getSmartAccountsByOwner(smartAccountByOwnerDto) {
const { chainId, owner, index } = smartAccountByOwnerDto;
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/smart-accounts/chainId/${chainId}/owner/${owner}/index/${index}`,
method: HttpRequests_1.HttpMethod.Get,
});
}
async getAllTokenBalances(balancesDto) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/smart-accounts/balances`,
method: HttpRequests_1.HttpMethod.Post,
body: balancesDto,
});
}
async getTotalBalanceInUsd(balancesDto) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/smart-accounts/balance`,
method: HttpRequests_1.HttpMethod.Post,
body: balancesDto,
});
}
/**
*
* @param origin
* @description this function will return the signature for your domain
* @returns
*/
async whitelistUrl(origin) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/whitelist`,
method: HttpRequests_1.HttpMethod.Post,
body: {
origin,
},
});
}
getTransactionByAddress(chainId, address) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/transactions/chainId/${chainId}/address/${address}`,
method: HttpRequests_1.HttpMethod.Get,
});
}
getTransactionByHash(txHash) {
return (0, HttpRequests_1.sendRequest)({
url: `${__classPrivateFieldGet(this, _NodeClient_txServiceBaseUrl, "f")}/transactions/txHash/${txHash}`,
method: HttpRequests_1.HttpMethod.Get,
});
}
}
_NodeClient_txServiceBaseUrl = new WeakMap();
exports.default = NodeClient;
//# sourceMappingURL=NodeClient.js.map