@citizenwallet/sdk
Version:
An sdk to easily work with citizen wallet.
136 lines • 4.97 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommunityConfig = void 0;
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
class CommunityConfig {
constructor(config) {
this.config = config;
}
get primaryToken() {
return this.config.tokens[`${this.config.community.primary_token.chain_id}:${this.config.community.primary_token.address}`];
}
get primaryNetwork() {
return this.config.chains[`${this.primaryToken.chain_id}`];
}
get primaryRPCUrl() {
const accountConfig = this.primaryAccountConfig;
return `${this.primaryNetwork.node.url}/v1/rpc/${accountConfig.paymaster_address}`;
}
getToken(tokenAddress) {
if (!tokenAddress) {
return this.primaryToken;
}
return this.config.tokens[`${this.primaryNetwork.id}:${tokenAddress}`];
}
getPlugins(tokenAddress, _chainId) {
let chainId = _chainId;
if (!chainId) {
chainId = this.primaryNetwork.id;
}
return this.config.plugins?.filter((plugin) => plugin.token_address === tokenAddress &&
(plugin.token_chain_id ? plugin.token_chain_id === chainId : true));
}
getActionPlugin(name, _tokenAddress, _chainId) {
let chainId = _chainId;
if (!chainId) {
chainId = this.primaryNetwork.id;
}
let tokenAddress = _tokenAddress;
if (!tokenAddress) {
tokenAddress = this.primaryToken.address;
}
return this.config.plugins?.find((plugin) => plugin.action === name &&
(plugin.token_address ? plugin.token_address === tokenAddress : true) &&
(plugin.token_chain_id ? plugin.token_chain_id === chainId : true));
}
getRPCUrl(accountFactoryAddress) {
if (!accountFactoryAddress) {
return this.primaryRPCUrl;
}
const accountConfig = this.config.accounts[`${this.primaryNetwork.id}:${accountFactoryAddress}`];
return `${this.primaryNetwork.node.url}/v1/rpc/${accountConfig.paymaster_address}`;
}
get primaryAccountConfig() {
return this.config.accounts[`${this.primaryNetwork.id}:${this.config.community.primary_account_factory.address}`];
}
getAccountConfig(accountFactoryAddress) {
if (!accountFactoryAddress) {
return this.primaryAccountConfig;
}
return this.config.accounts[`${this.primaryNetwork.id}:${accountFactoryAddress}`];
}
get primarySessionConfig() {
if (!this.config.sessions ||
!this.config.community.primary_session_manager) {
throw new Error("No sessions found");
}
return this.config.sessions[`${this.primaryNetwork.id}:${this.config.community.primary_session_manager.address}`];
}
get primaryCardConfig() {
if (!this.config.cards || !this.config.community.primary_card_manager) {
throw new Error("No cards found");
}
return this.config.cards[`${this.primaryNetwork.id}:${this.config.community.primary_card_manager.address}`];
}
get primaryClassicCardConfig() {
if (!this.config.cards || !this.config.community.primary_card_manager) {
throw new Error("No cards found");
}
return this.config.cards[`${this.primaryNetwork.id}:${this.config.community.primary_card_manager.address}`];
}
get primarySafeCardConfig() {
if (!this.config.cards || !this.config.community.primary_card_manager) {
throw new Error("No cards found");
}
return this.config.cards[`${this.primaryNetwork.id}:${this.config.community.primary_card_manager.address}`];
}
communityUrl(baseDomain) {
const { custom_domain, alias } = this.config.community;
if (custom_domain && !custom_domain.endsWith(baseDomain)) {
return `https://${custom_domain}`;
}
return `https://${alias}.${baseDomain}`;
}
get explorer() {
return this.config.scan;
}
get community() {
return this.config.community;
}
get tokens() {
return this.config.tokens;
}
get scan() {
return this.config.scan;
}
get accounts() {
return this.config.accounts;
}
get sessions() {
return this.config.sessions;
}
get cards() {
return this.config.cards;
}
get chains() {
return this.config.chains;
}
get ipfs() {
return this.config.ipfs;
}
get plugins() {
return this.config.plugins;
}
get configLocation() {
return this.config.config_location;
}
get version() {
return this.config.version;
}
}
exports.CommunityConfig = CommunityConfig;
//# sourceMappingURL=index.js.map