client-aftermath-ts-sdk
Version:
Client Aftermath TypeScript SDK
141 lines (140 loc) • 6.11 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dca = void 0;
const caller_1 = require("../../general/utils/caller");
class Dca extends caller_1.Caller {
// =========================================================================
// Constructor
// =========================================================================
constructor(config) {
super(config, "dca");
}
// =========================================================================
// Class Objects
// =========================================================================
/**
* Fetches the API for dollar cost averaging orders list.
* @deprecated please use `getActiveDcaOrders` and `getPastDcaOrders` instead
*/
getAllDcaOrders(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi("orders", inputs);
});
}
/**
* Fetches the API for dollar cost averaging active orders list.
* @async
* @param { ApiDCAsOwnedBody } inputs - An object containing the walletAddress.
* @returns { Promise<DcaOrderObject[]> } A promise that resolves to object with array of fetched events for active dca's.
*/
getActiveDcaOrders(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi("active", inputs);
});
}
/**
* Fetches the API for dollar cost averaging past orders list.
* @async
* @param { ApiDCAsOwnedBody } inputs - An object containing the walletAddress.
* @returns { Promise<DcaOrderObject[]> } A promise that resolves to object with array of fetched events for past dca's.
*/
getPastDcaOrders(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi("past", inputs);
});
}
// =========================================================================
// Transactions
// =========================================================================
/**
* Fetches the API transaction for creating DCA order.
* @param { ApiDcaTransactionForCreateOrderBody } inputs - The inputs for the transaction.
* @returns { Promise<Transaction> } A promise that resolves with the API transaction.
*/
getCreateDcaOrderTx(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApiTransaction("transactions/create-order", inputs);
});
}
/**
* Fetches the API for canceling DCA order.
* @param inputs - The inputs for the transaction.
* @returns { Promise<boolean> } A promise that resolves with transaction execution status.
*/
closeDcaOrder(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi(`cancel`, inputs);
});
}
// =========================================================================
// Interactions
// =========================================================================
/**
* Method for getting the cancellation dca order message to sign.
* @param inputs - The inputs for the message.
* @returns Message to sign.
*/
closeDcaOrdersMessageToSign(inputs) {
return {
action: "CANCEL_DCA_ORDERS",
order_object_ids: inputs.orderIds,
};
}
// =========================================================================
// Interactions - Deprecated
// =========================================================================
/**
* Method for getting the creation user message to sign.
* @param inputs - The inputs for the message.
* @returns Message to sign.
* @deprecated please use method from `userData` package instead
*/
createUserAccountMessageToSign() {
return {
action: "CREATE_DCA_ACCOUNT",
};
}
// =========================================================================
// User Public Key
// =========================================================================
/**
* Fetches the API for users public key.
* @async
* @param { ApiDCAsOwnedBody } inputs - An object containing the walletAddress.
* @returns { Promise<string | undefined> } A promise that resolves users public key.
* @deprecated please use method `getUserPublicKey` from `userData` package instead
*/
getUserPublicKey(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi(`user/get`, inputs);
});
}
/**
* Fetches the API to create users public key.
* @async
* @param { ApiDcaCreateUserBody } inputs - The inputs for creating users public key on BE side.
* @returns { Promise<boolean> } A promise that resolves to result if user pk has been created.
* @deprecated please use method `createUserPublicKey` from `userData` package instead
*/
createUserPublicKey(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi(`/user/add`, inputs);
});
}
}
exports.Dca = Dca;
// =========================================================================
// Constants
// =========================================================================
Dca.constants = {
gasAmount: BigInt(50000000),
};