Skip to content

Commit

Permalink
Merge pull request #4256 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v5.8.0
  • Loading branch information
pauljusti authored Dec 19, 2024
2 parents ce9704c + 970f7fa commit a02af7f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ MATTERS_SLACK_TOKEN=
MATTERS_SLACK_PAYOUT_CHANNEL=
MATTERS_SLACK_STRIPE_ALERT_CHANNEL=
MATTERS_SLACK_QUEUE_CHANNEL=
MATTERS_SLACK_CURATION_VAULT_CHANNEL=
APOLLO_KEY=
APOLLO_GRAPH_REF=
MATTERS_OPENSEA_API_BASE=https://rinkeby-api.opensea.io/api/v1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matters-server",
"version": "5.6.2",
"version": "5.8.0",
"description": "Matters Server",
"author": "Matters <[email protected]>",
"main": "build/index.js",
Expand Down
6 changes: 6 additions & 0 deletions src/common/enums/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export const BLOCKCHAIN_RPC: { [chainId: string]: string } = {
[optimismSepolia.id]: `https://opt-sepolia.g.alchemy.com/v2/${environment.alchemyApiKey}`,
}

export const BLOCKCHAIN_EXPLORER = {
[BLOCKCHAIN.Optimism]: isProd
? optimism.blockExplorers.default
: optimismSepolia.blockExplorers.default, // TODO: update to etherscan
}

// via https://support.kraken.com/hc/en-us/articles/203325283-Cryptocurrency-deposit-processing-times
export const BLOCKCHAIN_SAFE_CONFIRMS: { [key in GQLChain]: number } = {
Polygon: 70,
Expand Down
2 changes: 2 additions & 0 deletions src/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const environment = {
slackPayoutChannel: process.env.MATTERS_SLACK_PAYOUT_CHANNEL || '',
slackStripeAlertChannel: process.env.MATTERS_SLACK_STRIPE_ALERT_CHANNEL || '',
slackStripeQueueChannel: process.env.MATTERS_SLACK_QUEUE_CHANNEL || '',
slackCurationVaultChannel:
process.env.MATTERS_SLACK_CURATION_VAULT_CHANNEL || '',
openseaAPIBase:
process.env.MATTERS_OPENSEA_API_BASE ||
(isProd
Expand Down
35 changes: 35 additions & 0 deletions src/connectors/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,41 @@ class SlackService {
}
}

public sendVaultWithdrawMessage = async ({
amount,
state,
txDbId,
userName,
txHash,
}: {
amount: number | string
state: SLACK_MESSAGE_STATE
txDbId: string
userName: string
txHash?: string
}) => {
try {
await this.client.chat.postMessage({
channel: environment.slackCurationVaultChannel,
text: `[${environment.env}] - Vault withdraw request is ${state}.`,
attachments: [
{
color: this.getMessageColor(state),
text:
'\n' +
`\n- *Matters ID:* ${userName}` +
`\n- *DB Tx ID*: ${txDbId}` +
`\n- *On-chain Tx*: ${txHash || 'N/A'}` +
`\n- *Amount*: ${amount} USD`,
},
],
markdown: true,
})
} catch (error) {
logger.error(error)
}
}

/**
* Send alert realted to stripe issues.
*/
Expand Down
20 changes: 20 additions & 0 deletions src/mutations/user/withdrawLockedTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { v4 } from 'uuid'
import { formatUnits } from 'viem'

import {
BLOCKCHAIN,
BLOCKCHAIN_EXPLORER,
BLOCKCHAIN_TRANSACTION_STATE,
NOTICE_TYPE,
PAYMENT_CURRENCY,
PAYMENT_PROVIDER,
SLACK_MESSAGE_STATE,
TRANSACTION_PURPOSE,
TRANSACTION_STATE,
USER_STATE,
Expand All @@ -19,6 +22,7 @@ import {
ServerError,
} from 'common/errors'
import { CurationVaultContract } from 'connectors/blockchain/curationVault'
import SlackService from 'connectors/slack'

const resolver: GQLMutationResolvers['withdrawLockedTokens'] = async (
_,
Expand Down Expand Up @@ -66,6 +70,7 @@ const resolver: GQLMutationResolvers['withdrawLockedTokens'] = async (

const contract = new CurationVaultContract()
const client = await contract.getClient()
const slack = new SlackService()

// check withdraw amount
const vaultAmount = await contract.getWithdrawableUSDTAmount(viewer.id)
Expand Down Expand Up @@ -129,6 +134,14 @@ const resolver: GQLMutationResolvers['withdrawLockedTokens'] = async (
{ type: 'target', entityTable: 'transaction', entity: transaction },
],
})

slack.sendVaultWithdrawMessage({
amount: transaction.amount,
state: SLACK_MESSAGE_STATE.successful,
txDbId: transaction.id,
userName: viewer.userName,
txHash: `${BLOCKCHAIN_EXPLORER[BLOCKCHAIN.Optimism].url}/tx/${txHash}`,
})
} catch (error) {
console.error(error)

Expand All @@ -154,6 +167,13 @@ const resolver: GQLMutationResolvers['withdrawLockedTokens'] = async (
],
})

slack.sendVaultWithdrawMessage({
amount: transaction.amount,
state: SLACK_MESSAGE_STATE.failed,
txDbId: transaction.id,
userName: viewer.userName,
})

throw new ServerError('failed to withdraw locked tokens')
}

Expand Down
1 change: 1 addition & 0 deletions src/queries/user/wallet/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const resolver: GQLWalletResolvers['balance'] = async (
HKD: 0,
}
}

const HKD = await paymentService.calculateBalance({
userId: id,
currency: PAYMENT_CURRENCY.HKD,
Expand Down

0 comments on commit a02af7f

Please sign in to comment.