/**
*
* Pricecaster Service Utility Library.
*
* Copyright 2022 C3 LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
///
import algosdk from 'algosdk';
type ContractInfo = {
schema: {
globalInts: number;
globalBytes: number;
localInts: number;
localBytes: number;
};
approvalProgramFile: string;
clearStateProgramFile: string;
compiledApproval: {
bytes: Uint8Array;
hash: string;
};
compiledClearState: {
bytes: Uint8Array;
hash: string;
};
appId: number;
};
export declare const PRICECASTER_CI: ContractInfo;
export type PriceSlotData = {
asaId: number;
normalizedPrice: bigint;
pythPrice: bigint;
confidence: bigint;
exponent: number;
priceEMA: bigint;
confEMA: bigint;
attTime: bigint;
pubTime: bigint;
prevPubTime: bigint;
prevPrice: bigint;
prevConf: bigint;
};
export type AsaIdSlot = {
asaid: number;
slot: number;
};
export type SystemSlotInfo = {
entryCount: number;
flags: number;
};
type SignCallback = (arg0: string, arg1: algosdk.Transaction) => any;
export interface IPriceCasterApiClient {
getPrices(): Promise;
}
export declare class PriceCasterApiClient implements IPriceCasterApiClient {
private baseUrl;
constructor(url: string, port?: number);
getPrices(): Promise;
}
export declare class PricecasterLib {
readonly algodClient?: algosdk.Algodv2 | undefined;
private minFee;
private dumpFailedTx;
private dumpFailedTxDirectory;
constructor(algodClient?: algosdk.Algodv2 | undefined);
/** Set the file dumping feature on failed group transactions
* @param {boolean} f Set to true to enable function, false to disable.
*/
enableDumpFailedTx(f: boolean): void;
/** Set the file dumping feature output directory
* @param {string} dir The output directory.
*/
setDumpFailedTxDirectory(dir: string): void;
/** Sets a contract approval program filename
* @param {string} contract The contract info to set
* @param {string} filename New file name to use.
*/
setApprovalProgramFile(pcci: ContractInfo, filename: string): void;
/** Sets a contract clear state program filename
* @param {string} contract The contract info to set
* @param {string} filename New file name to use.
*/
setClearStateProgramFile(pcci: ContractInfo, filename: string): void;
/** Sets approval program bytes and hash
* @param {string} contract The contract info to set
* @param {*} bytes Compiled program bytes
* @param {string} hash Compiled program hash
*/
setCompiledApprovalProgram(pcci: ContractInfo, bytes: Uint8Array, hash: string): void;
/** Sets compiled clear state contract bytes and hash
* @param {string} contract The contract info to set
* @param {*} bytes Compiled program bytes
* @param {string} hash Compiled program hash
*/
setCompiledClearStateProgram(pcci: ContractInfo, bytes: Uint8Array, hash: string): void;
/**
* Set Application Id for a contract.
* @param {number} applicationId application id
* @returns {void}
*/
setAppId(pcci: ContractInfo, applicationId: number): void;
/**
* Get the Application id for a specific contract
* @returns The requested application Id
*/
getAppId(pcci: ContractInfo): number;
/**
* Get minimum fee to pay for transactions.
* @return {Number} minimum transaction fee
*/
minTransactionFee(): number;
/**
* Internal function.
* Read application local state related to the account.
* @param {String} accountAddr account to retrieve local state
* @return {Array} an array containing all the {key: value} pairs of the local state
*/
readLocalState(accountAddr: string, pcci: ContractInfo): Promise;
/**
* Internal function.
* Read application global state.
* @return {Array} an array containing all the {key: value} pairs of the global state
* @returns {void}
*/
readGlobalState(pcci: ContractInfo): Promise;
/**
* Print local state of accountAddr on stdout.
* @param {String} accountAddr account to retrieve local state
* @returns {void}
*/
printLocalState(accountAddr: string, pcci: ContractInfo): Promise;
/**
* Print application global state on stdout.
* @returns {void}
*/
printGlobalState(pcci: ContractInfo): Promise;
/**
* Internal function.
* Read application local state variable related to accountAddr.
* @param {String} accountAddr account to retrieve local state
* @param {String} key variable key to get the value associated
* @return {String/Number} it returns the value associated to the key that could be an address, a number or a
* base64 string containing a ByteArray
*/
readLocalStateByKey(accountAddr: string, key: string, pcci: ContractInfo): Promise;
/**
* Internal function.
* Read application global state variable.
* @param {String} key variable key to get the value associated
* @return {String/Number} it returns the value associated to the key that could be an address,
* a number or a base64 string containing a ByteArray
*/
readGlobalStateByKey(key: string, pcci: ContractInfo, disableParseAddress?: boolean): Promise;
/**
* Compile program that programFilename contains.
* @param {String} programBytes Array of program bytes
* @return {String} base64 string containing the compiled program
*/
compileProgram(programBytes: Uint8Array | string): Promise<{
bytes: Uint8Array;
hash: any;
}>;
/**
* Compile clear state program.
*/
compileClearProgram(pcci: ContractInfo): Promise;
/**
* Compile approval program.
*/
compileApprovalProgram(pcci: ContractInfo, tmplReplace?: [string, string][]): Promise;
/**
* Helper function to retrieve the application id from a createApp transaction response.
* @param {Object} txResponse object containig the transactionResponse of the createApp call
* @return {Number} application id of the created application
*/
appIdFromCreateAppResponse(txResponse: any): any;
/**
* Helper function to retrieve the asset id id from a createApp transaction response.
* @param {Object} txResponse object containig the transactionResponse of the createApp call
* @return {Number} asset id of the created asset
*/
assetIdFromCreateAppResponse(txResponse: any): any;
/**
* Create an application based on the default approval and clearState programs or based on the specified files.
* @param {String} sender account used to sign the createApp transaction
* @param {Function} signCallback callback with prototype signCallback(sender, tx) used to sign transactions
* @param {Tuple[]} tmplReplace Array of tuples specifying template replacements in output TEAL.
* @return {String} transaction id of the created application
*/
createApp(sender: string, pcci: ContractInfo, appArgs: Uint8Array[], signCallback: SignCallback, tmplReplace?: [string, string][], skipCompile?: any, fee?: number): Promise;
/**
* Create the Pricekeeper application based on the default approval and clearState programs or based on the specified files.
* @param {String} sender account used to sign the createApp transaction
* @param {String} wormholeCore The application id of the Wormhole Core program associated.
* @param {boolean} testMode Set to true to enable test mode (ignore transaction format and VAA checks)
* @param {boolean} disableMerkleVerification Set to true to disable merkle root verification
* @param {Function} signCallback callback with prototype signCallback(sender, tx) used to sign transactions
* @return {String} transaction id of the created application
*/
createPricecasterApp(creatorAddr: string, operatorAddr: string, quantAddr: string, wormholeCore: number, testMode: boolean, disableMerkleVerification: boolean, signCallback: SignCallback, fee?: number): Promise;
/**
* Internal function.
* Call application specifying args and accounts.
* @param {String} sender caller address
* @param {Array} appArgs array of arguments to pass to application call
* @param {Array} appAccounts array of accounts to pass to application call
* @param {Function} signCallback callback with prototype signCallback(sender, tx) used to sign transactions
* @return {String} transaction id of the transaction
*/
callApp(sender: string, pcci: ContractInfo, appArgs: Uint8Array[], appAccounts: string[], signCallback: SignCallback): Promise;
/**
* ClearState sender. Remove all the sender associated local data.
* @param {String} sender account to ClearState
* @param {Function} signCallback callback with prototype signCallback(sender, tx) used to sign transactions
* @return {[String]} transaction id of one of the transactions of the group
*/
clearApp(sender: string, signCallback: SignCallback, pcci: ContractInfo): Promise;
/**
* Permanent delete the application.
* @param {String} sender owner account
* @param {Function} signCallback callback with prototype signCallback(sender, tx) used to sign transactions
* @param {Function} applicationId use this application id instead of the one set
* @return {String} transaction id of one of the transactions of the group
*/
deleteApp(sender: string, signCallback: SignCallback, pcci: ContractInfo): Promise;
/**
* Helper function to wait until transaction txId is included in a block/round.
* @param {String} txId transaction id to wait for
* @return {VOID} VOID
*/
waitForConfirmation(txId: string): Promise;
/**
* Helper function to wait until transaction txId is included in a block/round
* and returns the transaction response associated to the transaction.
* @param {String} txId transaction id to get transaction response
* @return {Object} returns an object containing response information
*/
waitForTransactionResponse(txId: string): Promise;
/**
* Pricecaster.: Generate store price transaction.
*
* @param {*} sender The sender account (typically the VAA verification stateless program)
* @param {*} merkleRoot The merkle root of the VAA payload. For test mode, this can be supplied with an empty buffer.
* @param {*} asaIdSlots An array of objects of entries (asaid, slot) for each attestation contained in the VAA to publish.
* The slot will be used to store the price and must be mantained by caller.
* @param {*} payload The Pyth price update payload.
* @param {*} suggestedParams The network suggested params, get with algosdk getTransactionParams call.
* @param {*} budget: The computation budget to provide for the main loop.
*/
makePriceStoreTx(sender: string, merkleRoot: Buffer, asaIdSlots: AsaIdSlot[], payload: Buffer, suggestedParams: algosdk.SuggestedParams, budget: number): algosdk.Transaction;
/**
* Allocates a new price slot.
*
* @param sender The sender account.
* @param asaid The ASA ID to be assigned to the new slot.
* @param suggestedParams The transaction params.
* @returns
*/
makeAllocSlotTx(sender: string, asaid: number, suggestedParams: algosdk.SuggestedParams): algosdk.Transaction;
/**
* Resets the contract to zero.
*
* @param sender The sender account.
* @param suggestedParams The transaction params.
* @returns
*/
makeResetTx(sender: string, suggestedParams: algosdk.SuggestedParams): algosdk.Transaction;
/**
* Set configuration flags.
*
* @param sender The sender account.
* @param flags A value with the flags. The LSB is used.
* @param suggestedParams The transaction params.
* @returns
*/
makeSetFlagsTx(sender: string, flags: number, suggestedParams: algosdk.SuggestedParams): algosdk.Transaction;
/**
* Fetch the global store blob space
* @returns Buffer with the entire global store
*/
fetchGlobalSpace(): Promise;
/**
* Read a global space slot by index.
* @param slot The slot index
* @returns The slot information in a buffer
*/
readSlot(slot: number): Promise;
/**
* Read the Pricecaster contract system slot.
* @returns The system slot information
*/
readSystemSlot(): Promise;
/**
* Read and parse a price slot.
* @param slot The slot number.
* @returns Parsed price data stored in the slot.
*/
readParsePriceSlot(slot: number): Promise;
parseSlotBuffer(dataBuf: Buffer): PriceSlotData;
/**
* Fetch the global state and parse price information from the valid slots.
*/
readParseGlobalState(): Promise;
/**
* Extract Merkle root hash from Pyth payload VAA.
*
* @param The Pyth Price Service update data.
* @returns The merkle root hash
*
*/
extractVaaMerkleRoot(pythData: Buffer): {
vaa: Buffer;
merkleRoot: Buffer;
};
/**
* Extracs the price updates block from Pyth data.
*
* @param pythData The Pyth Price service data.
* @returns The price updates block containing the price information and merkle paths.
*/
extractPriceUpdatesBlock(pythData: Buffer): Buffer;
/**
* Read the global state core id
*/
readCoreId(): Promise;
/**
* Read the global state operator address
*/
readOperatorAddress(): Promise;
/**
* Read the global state quant address
*/
readQuantAddress(): Promise;
}
export {};
//# sourceMappingURL=pricecaster.d.ts.map