aftermath-ts-sdk
Version:
Aftermath TypeScript SDK
83 lines (82 loc) • 3.78 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.ReferralVault = void 0;
const caller_1 = require("../../general/utils/caller");
/**
* The `ReferralVault` class provides functionality for querying and managing
* referral information within the Aftermath protocol. It allows you to look
* up the referrer for a given address.
*/
class ReferralVault extends caller_1.Caller {
// =========================================================================
// Constructor
// =========================================================================
/**
* Creates a new instance of `ReferralVault` to interact with referral-related
* features in the Aftermath protocol.
*
* @param config - Optional caller configuration, including Sui network and access token.
* @param Provider - An optional `AftermathApi` provider instance for referral-specific methods.
*/
constructor(config, Provider) {
super(config, "referral-vault");
this.Provider = Provider;
// =========================================================================
// Private Helpers
// =========================================================================
/**
* Internal helper to retrieve the configured `ReferralVault` provider from
* `AftermathApi`, throwing an error if not defined.
*/
this.useProvider = () => {
var _a;
const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.ReferralVault();
if (!provider)
throw new Error("missing AftermathApi Provider");
return provider;
};
}
// =========================================================================
// Inspections
// =========================================================================
/**
* Retrieves the referrer address for a specified referee (user).
*
* @param inputs - An object containing the `referee` Sui address.
* @returns A promise that resolves to either the referrer's `SuiAddress` or the string `"None"` if no referrer exists.
*
* @example
* ```typescript
* const afSdk = new Aftermath("MAINNET");
* await afSdk.init(); // initialize provider
*
* const referralVault = afSdk.ReferralVault();
*
* const referrer = await referralVault.getReferrer({ referee: "0x<user_address>" });
* console.log("Referrer address:", referrer);
* ```
*/
getReferrer(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.fetchApi(`${inputs.referee}/referrer`);
});
}
}
exports.ReferralVault = ReferralVault;
// =========================================================================
// Constants
// =========================================================================
/**
* Contains static configuration relevant to the referral system, if any.
* Currently empty but can be extended for future needs.
*/
ReferralVault.constants = {};