@aarc-dev/core
Version:
239 lines • 9.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetTransactionStatus = exports.GetSupportedChains = exports.GetSupportedTokens = exports.IsTokenSupported = exports.getMultiChainBalances = exports.fetchBalances = exports.executeForwardCallData = exports.generateForwardCallData = exports.generateDepositCallData = exports.executeGaslessCallData = exports.generateNonGaslessCallData = exports.generateGaslessCallData = void 0;
const Constants_1 = require("./Constants");
const HttpRequest_1 = require("./HttpRequest");
const Logger_1 = require("./Logger");
const querystring_1 = require("querystring");
const generateGaslessCallData = async (forwardCallDataDto, dappApiKey) => {
try {
const txResponse = await (0, HttpRequest_1.sendRequest)({
url: Constants_1.GENERATE_GASLESS_CALL_DATA_ENDPOINT,
method: HttpRequest_1.HttpMethod.POST,
headers: {
"x-api-key": dappApiKey,
},
body: forwardCallDataDto,
});
Logger_1.Logger.log("body ", JSON.stringify(forwardCallDataDto));
Logger_1.Logger.log("txResponse from server ", JSON.stringify(txResponse.data));
return txResponse;
}
catch (error) {
Logger_1.Logger.error("error while getting consuming forward endpoint");
throw error;
}
};
exports.generateGaslessCallData = generateGaslessCallData;
const generateNonGaslessCallData = async (forwardCallDataDto, dappApiKey) => {
try {
const txResponse = await (0, HttpRequest_1.sendRequest)({
url: Constants_1.GENERATE_NON_GASLESS_CALL_DATA_ENDPOINT,
method: HttpRequest_1.HttpMethod.POST,
headers: {
"x-api-key": dappApiKey,
},
body: forwardCallDataDto,
});
Logger_1.Logger.log("body ", JSON.stringify(forwardCallDataDto));
Logger_1.Logger.log("txResponse from server ", JSON.stringify(txResponse.data));
return txResponse;
}
catch (error) {
Logger_1.Logger.error("error while getting consuming forward endpoint");
throw error;
}
};
exports.generateNonGaslessCallData = generateNonGaslessCallData;
const executeGaslessCallData = async (chainId, forwardCalldataSet, dappApiKey) => {
try {
const txResponse = await (0, HttpRequest_1.sendRequest)({
url: Constants_1.EXECUTE_GASLESS_CALL_DATA_ENDPOINT,
method: HttpRequest_1.HttpMethod.POST,
headers: {
"x-api-key": dappApiKey,
},
body: { chainId, trxList: forwardCalldataSet },
});
Logger_1.Logger.log("txResponse from server ", JSON.stringify(txResponse.data));
return txResponse.data;
}
catch (error) {
Logger_1.Logger.error("error while getting consuming forward endpoint");
throw error;
}
};
exports.executeGaslessCallData = executeGaslessCallData;
const generateDepositCallData = async (depositCallDataDto, dappApiKey) => {
try {
// Convert depositCallDataDto to a query string
const queryString = (0, querystring_1.stringify)(depositCallDataDto);
// Append query string to the endpoint URL
const url = `${Constants_1.GENERATE_DEPOSIT_CALL_DATA_ENDPOINT}?${queryString}`;
const txResponse = await (0, HttpRequest_1.sendRequest)({
url,
method: HttpRequest_1.HttpMethod.GET,
headers: {
"x-api-key": dappApiKey,
},
});
Logger_1.Logger.log("body ", JSON.stringify(depositCallDataDto));
Logger_1.Logger.log("txResponse from server ", JSON.stringify(txResponse.data));
return txResponse;
}
catch (error) {
Logger_1.Logger.error("error while consuming deposit call data endpoint");
throw error;
}
};
exports.generateDepositCallData = generateDepositCallData;
const generateForwardCallData = async (forwardCallDataDto, dappApiKey) => {
try {
const txResponse = await (0, HttpRequest_1.sendRequest)({
url: Constants_1.GENERATE_FORWARD_CALL_DATA_ENDPOINT,
method: HttpRequest_1.HttpMethod.POST,
headers: {
"x-api-key": dappApiKey,
},
body: forwardCallDataDto,
});
Logger_1.Logger.log("body ", JSON.stringify(forwardCallDataDto));
Logger_1.Logger.log("txResponse from server ", JSON.stringify(txResponse.data));
return txResponse.data;
}
catch (error) {
Logger_1.Logger.error("error while getting consuming forward endpoint");
throw error;
}
};
exports.generateForwardCallData = generateForwardCallData;
const executeForwardCallData = async (chainId, forwardCalldataSet, dappApiKey) => {
try {
const txResponse = await (0, HttpRequest_1.sendRequest)({
url: Constants_1.EXECUTE_FORWARD_CALL_DATA_ENDPOINT,
method: HttpRequest_1.HttpMethod.POST,
headers: {
"x-api-key": dappApiKey,
},
body: {
chainId,
trxList: forwardCalldataSet.forwardCallDataResponse,
txIndexes: forwardCalldataSet.txIndexes,
},
});
return txResponse.data;
}
catch (error) {
Logger_1.Logger.error("error while getting consuming forward endpoint");
throw error;
}
};
exports.executeForwardCallData = executeForwardCallData;
/**
* @description this function will return balances of ERC-20, ERC-721 and native tokens
* @param balancesDto
* @returns
*/
const fetchBalances = async (apiKey, chainId, eoaAddress, fetchBalancesOnly = true, tokenAddresses) => {
try {
// Make the API call using the sendRequest function
const response = await (0, HttpRequest_1.sendRequest)({
url: Constants_1.BALANCES_ENDPOINT,
method: HttpRequest_1.HttpMethod.POST,
headers: {
"x-api-key": apiKey,
},
body: {
chainId: String(chainId),
address: eoaAddress,
onlyBalances: fetchBalancesOnly,
tokenAddresses: tokenAddresses,
},
});
Logger_1.Logger.log("Fetching API Response:", response);
return response;
}
catch (error) {
// Handle any errors that may occur during the API request
Logger_1.Logger.error("Error making backend API call:", error);
throw error;
}
};
exports.fetchBalances = fetchBalances;
const getMultiChainBalances = async (apiKey, walletAddress, extendedBalances = false) => {
const response = await fetch(`${Constants_1.MULTI_CHAIN_BALANCES_ENDPOINT}/${walletAddress}/${extendedBalances}`, {
method: "GET",
headers: {
"x-api-key": apiKey,
Accept: "application/json",
"Content-Type": "application/json",
},
});
const json = await response.json();
return json;
};
exports.getMultiChainBalances = getMultiChainBalances;
// Makes a GET request to Aarc APIs for supported token by address and chainId
const IsTokenSupported = async (apiKey, chainId, address) => {
const endPoint = `${Constants_1.IS_TOKEN_SUPPORTED_ENDPOINT}?chainId=${chainId}&address=${address}`;
const response = await fetch(endPoint, {
method: "GET",
headers: {
"x-api-key": apiKey,
Accept: "application/json",
"Content-Type": "application/json",
},
});
const json = await response.json();
return json;
};
exports.IsTokenSupported = IsTokenSupported;
// Makes a GET request to Aarc APIs for supported token by chain
const GetSupportedTokens = async (apiKey, chainId, isShortList = true) => {
const endPoint = `${Constants_1.TOKENS_SUPPORTED_ENDPOINT}?chainId=${chainId}&isShortList=${isShortList}`;
const response = await fetch(endPoint, {
method: "GET",
headers: {
"x-api-key": apiKey,
Accept: "application/json",
"Content-Type": "application/json",
},
});
const json = await response.json();
return json;
};
exports.GetSupportedTokens = GetSupportedTokens;
// Makes a GET request to Aarc APIs for supported chains
const GetSupportedChains = async (apiKey) => {
const endPoint = `${Constants_1.CHAINS_SUPPORTED_ENDPOINT}`;
const response = await fetch(endPoint, {
method: "GET",
headers: {
"x-api-key": apiKey,
Accept: "application/json",
"Content-Type": "application/json",
},
});
const json = await response.json();
return json;
};
exports.GetSupportedChains = GetSupportedChains;
const GetTransactionStatus = async (taskId) => {
try {
const endpoint = `${Constants_1.TRX_STATUS_ENDPOINT + "/" + taskId}`;
const response = await fetch(endpoint, {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
return response.json();
}
catch (error) {
Logger_1.Logger.error("Error getting transaction status:", error);
throw error;
}
};
exports.GetTransactionStatus = GetTransactionStatus;
//# sourceMappingURL=Helper.js.map