mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
feat(operator fee): Adding config values to ensure bch-dex operator recieves a fee
This commit is contained in:
Vendored
+5
-1
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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 = {
|
||||||
|
|||||||
Reference in New Issue
Block a user