diff --git a/src/adapters/mochi-pay.ts b/src/adapters/mochi-pay.ts index db062e5d..4a5965f8 100644 --- a/src/adapters/mochi-pay.ts +++ b/src/adapters/mochi-pay.ts @@ -369,6 +369,17 @@ class MochiPay extends Fetcher { ) } + async listGlobalEarningVault(profileId: string): Promise { + const { data: res, ok } = await this.jsonFetch( + `${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/syndicates/earning-vaults/global`, + ) + let data = [] + if (ok) { + data = res as any + } + return data + } + async getTradeRounds(profileId: string, vaultId: string): Promise { return await this.jsonFetch( `${MOCHI_PAY_API_BASE_URL}/profiles/${profileId}/syndicates/earning-vaults/${vaultId}/trade-rounds`, diff --git a/src/commands/vault/info/processor.ts b/src/commands/vault/info/processor.ts index 37df7e6b..a62eb213 100644 --- a/src/commands/vault/info/processor.ts +++ b/src/commands/vault/info/processor.ts @@ -184,7 +184,7 @@ function composeTradesDescription({ description: string trades: any[] total: number -}) { +}): string { // Discord embed description is limited to 4096 characters const MAX_CHARS = 4096 const closeTrades = trades?.length @@ -273,8 +273,9 @@ export async function runGetVaultDetail({ } throw new APIError({ curl, error, description: log, status }) } - - const creator = await getDiscordRenderableByProfileId(profileId) + const creator = await getDiscordRenderableByProfileId( + data.creator_profile_id, + ) const { investor_report: report } = data const { open_trades, close_trades } = report const basicInfo = [ @@ -329,7 +330,6 @@ export async function runGetVaultDetail({ shorten: false, })})` } - const vaultEquity = [ "**Vault equity**", `${getVaultEquityEmoji( @@ -539,7 +539,6 @@ export async function runGetVaultDetail({ .concat(myNftFields) .concat(treasurerFields) .concat(recentTxFields) - const creator = data.treasurer.find((t: any) => t.role === "creator") ?? "" const basicInfo = [ `${getEmoji("ANIMATED_VAULT", true)}\`Name. ${selectedVault}\``, diff --git a/src/commands/vault/list/processor.ts b/src/commands/vault/list/processor.ts index 3cc292e5..f6a466a7 100644 --- a/src/commands/vault/list/processor.ts +++ b/src/commands/vault/list/processor.ts @@ -68,6 +68,18 @@ export async function runVaultList( ? await config.vaultList(interaction.guildId) : await config.vaultList("", false, userProfile.id) + const publicTradingVaults = ( + await mochiPay.listGlobalEarningVault(userProfile.id) + ).map((v: any) => ({ + id: v.id, + name: v.name, + wallet_address: v.evm_wallet_address, + total: v.investor_report.current_balance, + threshold: 100, + type: "trading", + discord_guild: { name: "" }, + })) + const tradingVaults = ( interaction.guildId ? await mochiPay.listEarningVaults( @@ -86,9 +98,11 @@ export async function runVaultList( discord_guild: { name: "" }, })) - const data = [...spotVaults, ...tradingVaults] - - if (!spotVaults.length && !tradingVaults.length) { + if ( + !spotVaults.length && + !tradingVaults.length && + !publicTradingVaults.length + ) { throw new InternalError({ msgOrInteraction: interaction, title: "Empty list vault", @@ -110,7 +124,7 @@ export async function runVaultList( description += "**Spot**\n" description += formatVaults( // @ts-ignore - data.filter((d) => d.type !== "trading"), + spotVaults, interaction.guildId || "", ) @@ -119,7 +133,17 @@ export async function runVaultList( description += "**Trading**\n" description += formatVaults( // @ts-ignore - data.filter((d) => d.type === "trading"), + tradingVaults, + interaction.guildId || "", + ) + } + + if (publicTradingVaults.length > 0) { + description += "\n\n" + description += "**Public Trading**\n" + description += formatVaults( + // @ts-ignore + publicTradingVaults, interaction.guildId || "", ) } @@ -148,7 +172,13 @@ export async function runVaultList( value: `trading_${v.id}`, })) - const options = [...spotOpts, ...tradingOpts] + const publicTradingOpts = publicTradingVaults.map((v: any, i: number) => ({ + emoji: getEmoji(`NUM_${tradingOpts.length + i + 1}` as EmojiKey), + label: v.name, + value: `trading_${v.id}`, + })) + + const options = [...spotOpts, ...tradingOpts, ...publicTradingOpts] const components = [ new MessageActionRow().addComponents(