Skip to content

Commit

Permalink
Merge branch 'develop' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnh12 committed May 22, 2024
2 parents 8cdd246 + ec41860 commit 4731dda
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 48 deletions.
79 changes: 34 additions & 45 deletions src/commands/vault/info/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,81 +184,68 @@ export async function runGetVaultDetail(
}

const creator = await getDiscordRenderableByProfileId(profileId)
const key = shortenHashOrAddress(data.metadata.api_key, 5, 5)
const { trade_rounds: rounds, account } = data
const basicInfo = [
`${getEmoji("ANIMATED_VAULT", true)}\`Name. ${data.name}\``,
`${getEmoji("ANIMATED_VAULT_KEY", true)}\`Creator. \`${creator}`,
`${getEmoji("CALENDAR")}\`Created. \` ${formatDate(
new Date(data.created_at),
)}`,
`${getEmoji("ANIMATED_BADGE_1")}\`Tier. \` ${data.metadata.tier.name}`,
`${getEmoji("CASH")}\`Balance. \`$${formatUsdDigit(
data.current_assets_in_usd,
)}`,
`${getEmoji("ANIMATED_VAULT_KEY")}\`Key. \` ${key}`,
`${getEmoji("ANIMATED_BADGE_1")}\`Tier. \` ${account.tier.name}`,
`${getEmoji("CASH")}\`Balance. \`$${formatUsdDigit(account.balance)}`,
`${getEmoji("ANIMATED_VAULT_KEY")}\`Key. \` ${account.api_key}`,
].join("\n")

const openRound = data.investment_rounds.find(
(r: any) => r.status === "ongoing",
)
const openRound = rounds.find((r: any) => r.status === 1)
const startDate = moment(new Date(openRound.start_date))
const startDiff = `${startDate.fromNow(true)} ${
startDate.isBefore() ? " ago" : " left"
}`
const openRoundPnlPerc =
(openRound.metadata.realized_pnl * 100) /
openRound.metadata.initial_balance
const roundInfo = [

const roundFields = [
`**Round info**`,
`${getEmoji("CALENDAR")} \`Start. \` ${formatDate(
startDate.toDate(),
)}, ${startDiff}`,
`🟢 \`Acc. PnL. \` ${utils.formatPercentDigit(openRoundPnlPerc)}`,
`🏎️ \`Rounds. \` ${openRound.metadata.no}`,
`🎫 \`Total fee. \` ${utils.formatUsdPriceDigit(
data.metadata.total_fee,
)}`,
`🟢 \`Acc. PnL. \` ${utils.formatUsdPriceDigit(
account.accumulative_pnl,
)} (${utils.formatPercentDigit(account.accumulative_pl * 100)})`,
`🏎️ \`Rounds. \` ${openRound.no}`,
`🎫 \`Total fee. \` ${utils.formatUsdPriceDigit(openRound.fee)}`,
].join("\n")

const vaultEquity = [
"**Vault equity**",
`${getEmoji("CHART")} \`Your share. \` 100%`,
`${getEmoji("MONEY")} \`Claimable amount. \` ${utils.formatUsdPriceDigit(
openRound.metadata.vault_equity.claimable,
account.claimable,
)}`,
].join("\n")

const openTrades = [
"**Open trades**",
`\`${formatDate(new Date(openRound.end_date))}\` ${getEmoji(
`\`${formatDate(new Date(openRound.start_date))}\` ${getEmoji(
"ANIMATED_COIN_1",
)} Init: ${utils.formatUsdPriceDigit(
openRound.metadata.initial_balance,
)} 💰 Current: ${utils.formatUsdPriceDigit(
openRound.metadata.realized_pnl,
)} **(:${
openRoundPnlPerc >= 0 ? "green" : "red"
}_circle: ${utils.formatPercentDigit(openRoundPnlPerc)})**`,
openRound.initial_balance,
)} 💰 Current: ${utils.formatUsdPriceDigit(openRound.realized_pnl)} **(:${
openRound.pnl_percentage >= 0 ? "green" : "red"
}_circle: ${utils.formatPercentDigit(openRound.pnl_percentage)})**`,
].join("\n")

const closedRounds = data.investment_rounds
.filter((r: any) => r.status !== "ongoing")
.slice(0, 3)
const closedRounds = rounds.filter((r: any) => r.status === 0).slice(0, 3)
const closedTrades = [
"**Closed trades**",
closedRounds.map((r: any) => {
const percentage =
(r.metadata.realized_pnl * 100) / r.metadata.initial_balance
return `\`${formatDate(new Date(r.end_date))}\` ${getEmoji(
"WAVING_HAND",
)} Init: ${utils.formatUsdPriceDigit(
r.metadata.initial_balance,
)} 💰 PnL: ${utils.formatUsdPriceDigit(
r.metadata.realized_pnl ?? 0,
)} (:${
percentage >= 0 ? "green" : "red"
}_circle: ${utils.formatPercentDigit(percentage)})`
}),
...closedRounds.map(
(r: any) =>
`\`${formatDate(new Date(r.start_date))}\` ${getEmoji(
"WAVING_HAND",
)} Init: ${utils.formatUsdPriceDigit(
r.initial_balance,
)} 💰 PnL: ${utils.formatUsdPriceDigit(r.realized_pnl ?? 0)} (:${
r.pnl_percentage >= 0 ? "green" : "red"
}_circle: ${utils.formatPercentDigit(r.pnl_percentage)})`,
),
// `\`24.05.07\` ${getEmoji(
// "WAVING_HAND",
// )} Init: $10,653 💰 PnL: -$247 (:red_circle: -2.32%)`,
Expand All @@ -277,14 +264,16 @@ export async function runGetVaultDetail(
const embed = composeEmbedMessage2(interaction as any, {
color: msgColors.BLUE,
author: ["Trading vault info", getEmojiURL(emojis.ANIMATED_DIAMOND)],
description: `${basicInfo}\n\n${vaultEquity}\n\n${address}\n\n${roundInfo}\n\n${openTrades}\n\n${closedTrades}`,
description: `${basicInfo}\n\n${vaultEquity}\n\n${address}\n\n${roundFields}\n\n${openTrades}\n\n${
closedTrades.length > 1 ? closedTrades : ""
}`,
})

return {
context: {
deposit: {
evm: faker.finance.ethereumAddress(),
sol: faker.finance.ethereumAddress(),
evm: data.evm_wallet_address,
sol: data.solana_wallet_address,
},
},
msgOpts: {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/vault/list/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import profile from "adapters/profile"
import { ModelVault } from "types/api"
import { faker } from "@faker-js/faker"
import mochiPay from "adapters/mochi-pay"
import { formatUsdDigit } from "utils/defi"
import { utils } from "@consolelabs/mochi-formatter"

export function formatVaults(
vaults: Array<ModelVault & { total?: string }>,
Expand Down Expand Up @@ -76,8 +76,8 @@ export async function runVaultList(interaction: CommandInteraction) {
(v: any) => ({
id: v.id,
name: v.name,
wallet_address: faker.finance.ethereumAddress(),
total: formatUsdDigit(v.current_assets_in_usd),
wallet_address: v.evm_wallet_address,
total: utils.formatUsdPriceDigit(v.account.balance),
threshold: 100,
type: "trading",
discord_guild: { name: "" },
Expand Down

0 comments on commit 4731dda

Please sign in to comment.