client-aftermath-ts-sdk
Version:
Client Aftermath TypeScript SDK
126 lines (125 loc) • 5.76 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.RouterApi = void 0;
const eventsApiHelpers_1 = require("../../../general/apiHelpers/eventsApiHelpers");
/**
* RouterApi class provides methods for interacting with the Aftermath Router API.
* @class
*/
class RouterApi {
// =========================================================================
// Constructor
// =========================================================================
/**
* Creates an instance of RouterApi.
* @constructor
* @param {AftermathApi} Provider - The Aftermath API instance.
*/
constructor(Provider) {
this.Provider = Provider;
// =========================================================================
// Events
// =========================================================================
// =========================================================================
// Event Types
// =========================================================================
this.routerTradeEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.utils, RouterApi.constants.moduleNames.events, RouterApi.constants.eventNames.routerTrade);
if (!this.Provider.addresses.router)
throw new Error("not all required addresses have been set in provider");
this.addresses = this.Provider.addresses.router;
this.eventTypes = {
routerTrade: this.routerTradeEventType(),
};
this.moveErrors = {
[this.addresses.packages.utils]: {
[RouterApi.constants.moduleNames.protocolFee]: {
/// A non-one-time-witness type has been provided to the `ProtocolFeeConfig`'s `create` function.
1: "Protocol Fee Config Already Created",
/// Occurs when `change_fee` is called more than once during the same Epoch.
2: "Bad Epoch",
/// A user provided a new protocol fees that do not sum to one.
3: "Not Normalized",
},
[RouterApi.constants.moduleNames.router]: {
0: "Not Authorized",
1: "Invalid Coin In",
2: "Invalid Coin Out",
4: "Invalid Previous Swap",
5: "Invalid Slippage",
/// A route is constructed that bypasses one of `begin_router_tx_and_pay_fees` or
/// `end_router_tx_and_pay_fees`.
6: "No Fees Paid",
},
[RouterApi.constants.moduleNames.version]: {
/// A user tries to interact with an old contract.
0: "Invalid Version",
},
[RouterApi.constants.moduleNames.admin]: {
/// Admin has not authorized the calling shared object to acess a permissioned function.
0: "Not Authorized",
/// Admin has already authorized the calling shared object to acess a permissioned function.
1: "Already Authorized",
},
},
};
}
// =========================================================================
// Public Methods
// =========================================================================
// =========================================================================
// Events
// =========================================================================
/**
* Fetches trade events for a given user.
* @param inputs - The inputs for fetching trade events.
* @returns A Promise that resolves with the fetched trade events.
*/
fetchTradeEvents(inputs) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("move to indexer");
// return this.Provider.Events().fetchCastEventsWithCursor<
// RouterTradeEventOnChain,
// RouterTradeEvent
// >({
// cursor: inputs.cursor,
// limit: inputs.limit,
// query: {
// And: [
// {
// Sender: inputs.walletAddress,
// },
// {
// MoveEventType: this.eventTypes.routerTrade,
// },
// ],
// },
// eventFromEventOnChain: RouterApiCasting.routerTradeEventFromOnChain,
// });
});
}
}
exports.RouterApi = RouterApi;
// =========================================================================
// Constants
// =========================================================================
RouterApi.constants = {
moduleNames: {
router: "router",
events: "events",
protocolFee: "protocol_fee",
version: "version",
admin: "admin",
},
eventNames: {
routerTrade: "SwapCompletedEvent",
},
};