forked from lnp2pBot/bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dotenv is not needed & maybe should create some model for currencies on line 1147
- Loading branch information
Showing
8 changed files
with
430 additions
and
292 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
declare global { | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
|
||
LND_CERT_BASE64: string; | ||
|
||
LND_MACAROON_BASE64: string; | ||
LND_GRPC_HOST: string; | ||
BOT_TOKEN: string; | ||
|
||
MAX_FEE: number; | ||
|
||
FEE_PERCENT: number; | ||
|
||
DB_USER: string; | ||
DB_PASS: string; | ||
DB_HOST: string; | ||
DB_PORT: string; | ||
DB_NAME: string; | ||
|
||
MONGO_URI: string; | ||
|
||
INVOICE_EXPIRATION_WINDOW: number; | ||
|
||
HOLD_INVOICE_EXPIRATION_WINDOW: number; | ||
|
||
CHANNEL: string; | ||
ADMIN_CHANNEL: string; | ||
HELP_GROUP: string; | ||
|
||
MAX_DISPUTES: number; | ||
|
||
HOLD_INVOICE_CLTV_DELTA: number; | ||
HOLD_INVOICE_CLTV_DELTA_SAFETY_WINDOW: number; | ||
|
||
PENDING_PAYMENT_WINDOW: number; | ||
|
||
FIAT_RATE_NAME: string; | ||
FIAT_RATE_EP: string; | ||
NODE_ENV: string; | ||
|
||
ORDER_PUBLISHED_EXPIRATION_WINDOW: number; | ||
|
||
MIN_PAYMENT_AMT: number; | ||
|
||
MAX_PENDING_ORDERS: number; | ||
|
||
LOG_LEVEL: string; | ||
|
||
MAX_ROUTING_FEE: number; | ||
|
||
PAYMENT_ATTEMPTS: number; | ||
|
||
DISPUTE_CHANNEL: string; | ||
|
||
COMMUNITY_TTL: number; | ||
|
||
NOSTR_SK: string | ||
} | ||
} | ||
} | ||
|
||
// If this file has no import/export statements (i.e. is a script) | ||
// convert it into a module by adding an empty export statement. | ||
export { } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import mongoose, { Document, Schema } from 'mongoose'; | ||
|
||
export interface IConfig extends Document { | ||
maintenance: boolean; | ||
node_status: string; | ||
node_uri: string; | ||
} | ||
|
||
|
||
const configSchema = new Schema<IConfig>({ | ||
maintenance: { type: Boolean, default: false }, | ||
node_status: { type: String, default: 'down' }, | ||
node_uri: { type: String }, | ||
}); | ||
|
||
|
||
module.exports = mongoose.model<IConfig>('Config', configSchema); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import mongoose, { Document, Schema } from 'mongoose'; | ||
|
||
export interface IOrder extends Document { | ||
description?: string; | ||
amount: number; | ||
max_amount: number; | ||
min_amount: number; | ||
fee: number; | ||
bot_fee: number; | ||
community_fee:number; | ||
routing_fee: number; | ||
hash: string; | ||
secret: string; | ||
creator_id: string; | ||
seller_id: string; | ||
buyer_id: string; | ||
buyer_invoice: string; | ||
buyer_dispute: boolean | ||
seller_dispute: boolean | ||
buyer_cooperativecancel: boolean; | ||
seller_cooperativecancel: boolean; | ||
canceled_by: string | ||
status: string; | ||
type: string; | ||
fiat_amount: number; | ||
fiat_code: string; | ||
payment_method: string; | ||
created_at: Date; | ||
invoice_held_at: Date; | ||
taken_at: Date; | ||
tg_chat_id: string; | ||
tg_order_message: string; | ||
tg_channel_message1: string; | ||
range_parent_id: string; | ||
price_from_api: boolean; | ||
price_margin: number; | ||
calculated: boolean; | ||
admin_warned: boolean; | ||
paid_hold_buyer_invoice_updated: boolean; | ||
community_id: string; | ||
is_public: boolean; | ||
} | ||
|
||
const orderSchema = new Schema<IOrder>({ | ||
description: { type: String, required: true }, | ||
amount: { | ||
// amount in satoshis | ||
type: Number, | ||
min: 0, | ||
}, | ||
max_amount: { | ||
// max amount in fiat | ||
type: Number, | ||
min: 0, | ||
}, | ||
min_amount: { | ||
// min amount in fiat | ||
type: Number, | ||
min: 0, | ||
}, | ||
fee: { type: Number, min: 0 }, | ||
bot_fee: { type: Number, min: 0 }, // bot MAX_FEE at the moment of order creation | ||
community_fee: { type: Number, min: 0 }, // community FEE_PERCENT at the moment of order creation | ||
routing_fee: { type: Number, min: 0, default: 0 }, | ||
hash: { | ||
type: String, | ||
index: { | ||
unique: true, | ||
partialFilterExpression: { hash: { $type: 'string' } }, | ||
}, | ||
}, // hold invoice hash | ||
secret: { | ||
type: String, | ||
index: { | ||
unique: true, | ||
partialFilterExpression: { secret: { $type: 'string' } }, | ||
}, | ||
}, // hold invoice secret | ||
creator_id: { type: String }, | ||
seller_id: { type: String }, | ||
buyer_id: { type: String }, | ||
buyer_invoice: { type: String }, | ||
buyer_dispute: { type: Boolean, default: false }, | ||
seller_dispute: { type: Boolean, default: false }, | ||
buyer_cooperativecancel: { type: Boolean, default: false }, | ||
seller_cooperativecancel: { type: Boolean, default: false }, | ||
canceled_by: { type: String }, | ||
status: { | ||
type: String, | ||
enum: [ | ||
'WAITING_PAYMENT', // buyer waiting for seller pay hold invoice | ||
'WAITING_BUYER_INVOICE', // seller waiting for buyer add invoice where will receive sats | ||
'PENDING', // order published on CHANNEL but not taken yet | ||
'ACTIVE', // order taken | ||
'FIAT_SENT', // buyer indicates the fiat payment is already done | ||
'CLOSED', // order closed | ||
'DISPUTE', // one of the parties started a dispute | ||
'CANCELED', | ||
'SUCCESS', | ||
'PAID_HOLD_INVOICE', // seller released funds | ||
'CANCELED_BY_ADMIN', | ||
'EXPIRED', // Expired orders, stated changed by a job | ||
'COMPLETED_BY_ADMIN', | ||
], | ||
}, | ||
type: { type: String }, | ||
fiat_amount: { type: Number, min: 1 }, // amount in fiat | ||
fiat_code: { type: String }, | ||
payment_method: { type: String, required: true }, | ||
created_at: { type: Date, default: Date.now }, | ||
invoice_held_at: { type: Date }, | ||
taken_at: { type: Date }, | ||
tg_chat_id: { type: String }, | ||
tg_order_message: { type: String }, | ||
tg_channel_message1: { type: String }, | ||
range_parent_id: { type: String }, // If the order have a parent we save the Id | ||
price_from_api: { type: Boolean }, | ||
price_margin: { type: Number, default: 0 }, | ||
calculated: { type: Boolean, default: false }, | ||
admin_warned: { type: Boolean, default: false }, // We set this to true when the bot warns admins the order is about to expire | ||
paid_hold_buyer_invoice_updated: { type: Boolean, default: false }, // We set this to true when buyer executes /setinvoice on a order PAID_HOLD_INVOICE | ||
community_id: { type: String }, | ||
is_public: { type: Boolean, default: true } | ||
}); | ||
|
||
module.exports = mongoose.model<IOrder>('Order', orderSchema); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import mongoose, { Document, Schema } from 'mongoose'; | ||
|
||
export interface IPendingPayment extends Document { | ||
description: string; | ||
amount: number; | ||
attempts: number; | ||
paid: boolean; | ||
is_invoice_expired: boolean; | ||
payment_request: string; | ||
hash: string; | ||
created_at: Date; | ||
paid_at: Date; | ||
user_id: string; | ||
order_id: string; | ||
community_id: string; | ||
} | ||
|
||
|
||
const PendingPaymentSchema = new Schema<IPendingPayment>({ | ||
description: { type: String }, | ||
amount: { | ||
// amount in satoshis | ||
type: Number, | ||
min: [1, 'Minimum amount is 1 sat'], | ||
validate: { | ||
validator: Number.isInteger, | ||
message: '{VALUE} is not an integer value', | ||
}, | ||
}, | ||
attempts: { type: Number, min: 0, default: 0 }, | ||
paid: { type: Boolean, default: false }, | ||
is_invoice_expired: { type: Boolean, default: false }, | ||
payment_request: { type: String }, | ||
hash: { type: String }, | ||
created_at: { type: Date, default: Date.now }, | ||
paid_at: { type: Date }, | ||
user_id: { type: String }, | ||
order_id: { type: String }, | ||
community_id: { type: String }, | ||
}); | ||
|
||
|
||
module.exports = mongoose.model<IPendingPayment>('PendingPayment', PendingPaymentSchema); |