feat(operator fee): Adding config values to ensure bch-dex operator recieves a fee

This commit is contained in:
Chris Troutner
2025-08-09 15:02:29 -07:00
parent fe82478dc4
commit 373a52ebf1
3 changed files with 17 additions and 9 deletions
+5 -1
View File
@@ -191,5 +191,9 @@ export default {
disableNewAccounts: process.env.DISABLE_NEW_ACCOUNTS ? true : false, disableNewAccounts: process.env.DISABLE_NEW_ACCOUNTS ? true : false,
// Admin password // Admin password
adminPassword: process.env.ADMIN_PASSWORD adminPassword: process.env.ADMIN_PASSWORD,
// The Operator of BCH DEX can elect to receive a percentage of each sale.
operatorAddress: process.env.OPERATOR_ADDRESS ? process.env.OPERATOR_ADDRESS : 'bitcoincash:qqsrke9lh257tqen99dkyy2emh4uty0vky9y0z0lsr',
operatorPercentage: process.env.OPERATOR_PERCENTAGE ? parseFloat(process.env.OPERATOR_PERCENTAGE) : 2.0
} }
+5 -1
View File
@@ -43,7 +43,11 @@ const Order = new mongoose.Schema({
// Additional properties found in createOrder // Additional properties found in createOrder
dataType: { type: String, required: true }, dataType: { type: String, required: true },
userId: { type: String, required: true } userId: { type: String, required: true },
// Operator fee and address
operatorAddress: { type: String },
operatorPercentage: { type: Number }
}) })
export default mongoose.model('order', Order) export default mongoose.model('order', Order)
+7 -7
View File
@@ -44,6 +44,7 @@ class OrderLib {
if (!entryObj.tokenId) throw new Error('entry does not contain required properties') if (!entryObj.tokenId) throw new Error('entry does not contain required properties')
// Get the user data from the database, for the user creating the new Order.
const user = await this.UserModel.findById(entryObj.userId) const user = await this.UserModel.findById(entryObj.userId)
if (!user) throw new Error('user not found') if (!user) throw new Error('user not found')
@@ -81,13 +82,7 @@ class OrderLib {
// await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.optimize, {}) // await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.optimize, {})
await userWallet.optimize() await userWallet.optimize()
// Ensure sufficient tokens exist to create the order.
// await this.ensureFunds(orderEntity)
// await this.retryQueue.addToQueue(this.ensureFunds, orderEntity)
// Get Ticker for token ID. // Get Ticker for token ID.
// const tokenData = await this.adapters.wallet.bchWallet.getTxData([entryObj.tokenId])
// const tokenData = await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.getTxData, [entryObj.tokenId])
const tokenData = await userWallet.getTxData([entryObj.tokenId]) const tokenData = await userWallet.getTxData([entryObj.tokenId])
// console.log(`tokenData: ${JSON.stringify(tokenData, null, 2)}`) // console.log(`tokenData: ${JSON.stringify(tokenData, null, 2)}`)
orderEntity.ticker = tokenData[0].tokenTicker orderEntity.ticker = tokenData[0].tokenTicker
@@ -107,15 +102,20 @@ class OrderLib {
// await this.adapters.wallet.bchWallet.getUtxos() // await this.adapters.wallet.bchWallet.getUtxos()
// await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.initialize, {}) // await this.retryQueue.addToQueue(this.adapters.wallet.bchWallet.initialize, {})
await userWallet.initialize() await userWallet.initialize()
// Update the order with the new UTXO information. // Update the order with the new UTXO information.
orderEntity.utxoTxid = utxoInfo.txid orderEntity.utxoTxid = utxoInfo.txid
orderEntity.utxoVout = utxoInfo.vout orderEntity.utxoVout = utxoInfo.vout
orderEntity.tokenType = utxoInfo.tokenType orderEntity.tokenType = utxoInfo.tokenType
// Add P2WDB specific flag for signaling that this is a new offer. // Add flag to signal that this is a new offer.
orderEntity.dataType = 'offer' orderEntity.dataType = 'offer'
orderEntity.userId = user._id orderEntity.userId = user._id
// Add the operator address and percentage to the order.
orderEntity.operatorAddress = this.config.operatorAddress
orderEntity.operatorPercentage = this.config.operatorPercentage
// Post the new Order information to Nostr under the topic set in the // Post the new Order information to Nostr under the topic set in the
// config file. // config file.
const postObj = { const postObj = {