|
| 1 | +import algosdk, { Algodv2, Transaction } from "algosdk"; |
| 2 | +import { OrderType, PutTriggerOrderParams, PutRecurringOrderParams } from "./types"; |
| 3 | +import { SupportedNetwork } from "../util/commonTypes"; |
| 4 | +import TinymanBaseClient from "../util/client/base/baseClient"; |
| 5 | +declare class OrderingClient extends TinymanBaseClient<number | null, algosdk.Address | null> { |
| 6 | + registryAppId: number; |
| 7 | + registryApplicationAddress: string; |
| 8 | + vaultAppId: number; |
| 9 | + vaultApplicationAddress: string; |
| 10 | + routerAppId: number; |
| 11 | + routerApplicationAddress: string; |
| 12 | + userAddress: string; |
| 13 | + private constructor(); |
| 14 | + private static getRegistryEntryBoxName; |
| 15 | + private static getOrderApplicationId; |
| 16 | + /** |
| 17 | + * Initializes the OrderingClient by fetching the personal app id from global state. |
| 18 | + * Until the user creates an application, the app id will be set as null |
| 19 | + */ |
| 20 | + static initializeOrderingClient(algod: Algodv2, network: SupportedNetwork, userAddress: string): Promise<OrderingClient>; |
| 21 | + /** |
| 22 | + * Compares the contracts between the user's order app and the latest available contract. |
| 23 | + * |
| 24 | + * @returns A boolean indicating if the order app needs to be updated. |
| 25 | + */ |
| 26 | + shouldUpdateOrderingApp(): Promise<boolean>; |
| 27 | + /** |
| 28 | + * Prepares transactions to update the ordering app using the latest contracts. |
| 29 | + * @returns A promise that resolves the transaction array. |
| 30 | + */ |
| 31 | + prepareUpdateOrderingAppTransactions(): Promise<Transaction[]>; |
| 32 | + calculateCreateOrderAppMinBalanceIncreaseAmount(): bigint; |
| 33 | + /** |
| 34 | + * Prepares transactions to create the order app for a user. |
| 35 | + * @param userAddress - The address of the user. |
| 36 | + * @returns A promise that resolves the transaction array. |
| 37 | + */ |
| 38 | + prepareCreateOrderAppTransactions(userAddress: string): Promise<algosdk.Transaction[]>; |
| 39 | + checkOrderAppAvailability(orderAppId?: number): Promise<void>; |
| 40 | + getPutTriggerOrderTransactionFee({ assetInId, assetOutId, type }: { |
| 41 | + assetInId: number; |
| 42 | + assetOutId: number; |
| 43 | + type: OrderType; |
| 44 | + }): Promise<bigint>; |
| 45 | + /** |
| 46 | + * Prepares an array of transactions to place a limit order. |
| 47 | + * |
| 48 | + * @param {PutTriggerOrderParams} params - The parameters for the put order operation. |
| 49 | + * @param params.assetInId - The ID of the input asset. |
| 50 | + * @param params.assetOutId - The ID of the output asset. |
| 51 | + * @param params.assetInAmount - The amount of the input asset in base units. |
| 52 | + * @param params.assetOutAmount - The amount of the output asset in base units. |
| 53 | + * @param params.isPartialAllowed - Whether partial fills are allowed. |
| 54 | + * @param params.duration - The duration of the order in seconds. |
| 55 | + * @param [params.orderAppId] - (Optional) The application ID for the order. |
| 56 | + * @returns A promise that resolves the transaction array. |
| 57 | + */ |
| 58 | + preparePutTriggerOrderTransactions({ assetInId, assetOutId, assetInAmount, assetOutAmount, isPartialAllowed, duration }: PutTriggerOrderParams): Promise<algosdk.Transaction[]>; |
| 59 | + /** |
| 60 | + * Prepares an array of transactions to place a recurring order. |
| 61 | + * |
| 62 | + * @param {PutRecurringOrderParams} params - The parameters for the recurring order. |
| 63 | + * @param params.amount - The amount per order to be used for the recurring order. |
| 64 | + * @param params.assetId - The ID of the asset being used for the order. |
| 65 | + * @param params.targetAssetId - The ID of the target asset for the order. |
| 66 | + * @param params.targetRecurrence - The number of times the order should recur. |
| 67 | + * @param params.interval - The interval between each recurrence in seconds. |
| 68 | + * @param params.maxTargetPrice - (Optional) The maximum price per unit of the target asset to be accepted. |
| 69 | + * @param params.minTargetPrice - (Optional) The minimum price per unit of the target asset to be accepted. |
| 70 | + * @returns A promise that resolves the transaction array. |
| 71 | + */ |
| 72 | + preparePutRecurringOrderTransactions({ amount, assetId, targetAssetId, targetRecurrence, interval, maxTargetPrice, minTargetPrice }: PutRecurringOrderParams): Promise<algosdk.Transaction[]>; |
| 73 | + /** |
| 74 | + * Prepares an array of transactions to cancel an order. |
| 75 | + * |
| 76 | + * @param orderId - The ID of the order to cancel. |
| 77 | + * @param type - The type of the order to cancel. |
| 78 | + * @returns A promise that resolves the transaction array. |
| 79 | + */ |
| 80 | + prepareCancelOrderTransactions(orderId: number, type: OrderType): Promise<algosdk.Transaction[]>; |
| 81 | + /** |
| 82 | + * Prepares an array of transactions to claim the collected target amount for an order. |
| 83 | + * @param orderId - The ID of the order for which to claim the collected target amount. |
| 84 | + * @param type - The type of the order (OrderType.Trigger or OrderType.Recurring). |
| 85 | + * @returns A promise that resolves the transaction array. |
| 86 | + */ |
| 87 | + prepareClaimCollectedTargetAmount(orderId: number, type: OrderType): Promise<algosdk.Transaction[]>; |
| 88 | + /** |
| 89 | + * Gets the platform fee rate based on the provided tiny power from the global state. |
| 90 | + * |
| 91 | + * @param tinyPower - The tiny power to check against the threshold. |
| 92 | + * @returns The platform fee rate. |
| 93 | + */ |
| 94 | + getPlatformFeeRate(tinyPower: number | null): Promise<bigint>; |
| 95 | + private getOrderCount; |
| 96 | + private getOrderBoxName; |
| 97 | + private getRegistryEntryBoxName; |
| 98 | + private prepareOrderAppAssetOptInTransaction; |
| 99 | + private prepareOrderAppAssetOptinTransactionsIfNeeded; |
| 100 | + private getAssetsToOptInToOrderingClient; |
| 101 | + private getLatestOrderAppVersion; |
| 102 | + private getAppVersionBoxName; |
| 103 | +} |
| 104 | +export { OrderingClient }; |
0 commit comments