diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js
index daa41ab8..296516a9 100644
--- a/api/resolvers/wallet.js
+++ b/api/resolvers/wallet.js
@@ -647,14 +647,21 @@ async function upsertWallet (
}
const { id, ...walletData } = data
- const { autoWithdrawThreshold, autoWithdrawMaxFeePercent, enabled, priority } = settings
+ const {
+ autoWithdrawThreshold,
+ autoWithdrawMaxFeePercent,
+ autoWithdrawMaxBaseFee,
+ enabled,
+ priority
+ } = settings
const txs = [
models.user.update({
where: { id: me.id },
data: {
autoWithdrawMaxFeePercent,
- autoWithdrawThreshold
+ autoWithdrawThreshold,
+ autoWithdrawMaxBaseFee
}
})
]
diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js
index 0f208951..39f417a8 100644
--- a/api/typeDefs/user.js
+++ b/api/typeDefs/user.js
@@ -182,6 +182,7 @@ export default gql`
withdrawMaxFeeDefault: Int!
autoWithdrawThreshold: Int
autoWithdrawMaxFeePercent: Float
+ autoWithdrawMaxBaseFee: Int
}
type UserOptional {
diff --git a/api/typeDefs/wallet.js b/api/typeDefs/wallet.js
index d87af0e0..12e5e4be 100644
--- a/api/typeDefs/wallet.js
+++ b/api/typeDefs/wallet.js
@@ -91,6 +91,7 @@ const typeDefs = `
input AutowithdrawSettings {
autoWithdrawThreshold: Int!
autoWithdrawMaxFeePercent: Float!
+ autoWithdrawMaxBaseFee: Int!
priority: Int
enabled: Boolean
}
diff --git a/components/autowithdraw-shared.js b/components/autowithdraw-shared.js
index de8323f7..cc02b4b1 100644
--- a/components/autowithdraw-shared.js
+++ b/components/autowithdraw-shared.js
@@ -4,6 +4,7 @@ import { useMe } from './me'
import { useEffect, useState } from 'react'
import { isNumber } from '@/lib/validate'
import { useIsClient } from './use-client'
+import Link from 'next/link'
function autoWithdrawThreshold ({ me }) {
return isNumber(me?.privates?.autoWithdrawThreshold) ? me?.privates?.autoWithdrawThreshold : 10000
@@ -12,7 +13,8 @@ function autoWithdrawThreshold ({ me }) {
export function autowithdrawInitial ({ me }) {
return {
autoWithdrawThreshold: autoWithdrawThreshold({ me }),
- autoWithdrawMaxFeePercent: isNumber(me?.privates?.autoWithdrawMaxFeePercent) ? me?.privates?.autoWithdrawMaxFeePercent : 1
+ autoWithdrawMaxFeePercent: isNumber(me?.privates?.autoWithdrawMaxFeePercent) ? me?.privates?.autoWithdrawMaxFeePercent : 1,
+ autoWithdrawMaxBaseFee: isNumber(me?.privates?.autoWithdrawMaxBaseFee) ? me?.privates?.autoWithdrawMaxBaseFee : 1
}
}
@@ -51,13 +53,30 @@ export function AutowithdrawSettings ({ wallet }) {
append={sats}
required
/>
+
network fees
+
+ the setting that allows a higher max fee will be used during{' '}
+ pathfinding
+
+
%}
required
/>
+ sats}
+ required
+ />
>
diff --git a/fragments/users.js b/fragments/users.js
index 26d92144..11d592d8 100644
--- a/fragments/users.js
+++ b/fragments/users.js
@@ -27,6 +27,7 @@ ${STREAK_FIELDS}
noReferralLinks
fiatCurrency
autoWithdrawMaxFeePercent
+ autoWithdrawMaxBaseFee
autoWithdrawThreshold
withdrawMaxFeeDefault
satsFilter
diff --git a/lib/validate.js b/lib/validate.js
index 9c53047f..02705088 100644
--- a/lib/validate.js
+++ b/lib/validate.js
@@ -366,7 +366,8 @@ export function advSchema (args) {
export const autowithdrawSchemaMembers = {
enabled: boolean(),
autoWithdrawThreshold: intValidator.required('required').min(0, 'must be at least 0').max(msatsToSats(BALANCE_LIMIT_MSATS), `must be at most ${abbrNum(msatsToSats(BALANCE_LIMIT_MSATS))}`),
- autoWithdrawMaxFeePercent: floatValidator.required('required').min(0, 'must be at least 0').max(50, 'must not exceed 50')
+ autoWithdrawMaxFeePercent: floatValidator.required('required').min(0, 'must be at least 0').max(50, 'must not exceed 50'),
+ autoWithdrawMaxBaseFee: intValidator.required('required').min(0, 'must be at least 0').max(1_000, 'must not exceed 1000')
}
export const lnAddrAutowithdrawSchema = object({
diff --git a/prisma/migrations/20241018160708_max_base_fee/migration.sql b/prisma/migrations/20241018160708_max_base_fee/migration.sql
new file mode 100644
index 00000000..23381126
--- /dev/null
+++ b/prisma/migrations/20241018160708_max_base_fee/migration.sql
@@ -0,0 +1,8 @@
+-- AlterTable
+ALTER TABLE "users" ADD COLUMN "autoWithdrawMaxBaseFee" INTEGER;
+
+-- set max_base_fee for users with autowithdrawals enabled to not interfere with them.
+-- we set it to 0 instead of 1 because that preserves old behavior.
+UPDATE "users"
+SET "autoWithdrawMaxBaseFee" = 0
+WHERE "autoWithdrawMaxFeePercent" IS NOT NULL;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 7a629e44..cb3162e2 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -118,6 +118,7 @@ model User {
lnAddr String?
autoWithdrawMaxFeePercent Float?
autoWithdrawThreshold Int?
+ autoWithdrawMaxBaseFee Int?
muters Mute[] @relation("muter")
muteds Mute[] @relation("muted")
ArcOut Arc[] @relation("fromUser")
diff --git a/wallets/index.js b/wallets/index.js
index fee17703..0333becd 100644
--- a/wallets/index.js
+++ b/wallets/index.js
@@ -296,6 +296,7 @@ function useServerConfig (wallet) {
const saveConfig = useCallback(async ({
autoWithdrawThreshold,
autoWithdrawMaxFeePercent,
+ autoWithdrawMaxBaseFee,
priority,
enabled,
...config
@@ -310,6 +311,7 @@ function useServerConfig (wallet) {
settings: {
autoWithdrawThreshold: Number(autoWithdrawThreshold),
autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent),
+ autoWithdrawMaxBaseFee: Number(autoWithdrawMaxBaseFee),
priority,
enabled
},
diff --git a/worker/autowithdraw.js b/worker/autowithdraw.js
index ef8d49e3..0589159a 100644
--- a/worker/autowithdraw.js
+++ b/worker/autowithdraw.js
@@ -4,7 +4,10 @@ import { createInvoice } from 'wallets/server'
export async function autoWithdraw ({ data: { id }, models, lnd }) {
const user = await models.user.findUnique({ where: { id } })
- if (user.autoWithdrawThreshold === null || user.autoWithdrawMaxFeePercent === null) return
+ if (
+ user.autoWithdrawThreshold === null ||
+ user.autoWithdrawMaxFeePercent === null ||
+ user.autoWithdrawMaxBaseFee === null) return
const threshold = satsToMsats(user.autoWithdrawThreshold)
const excess = Number(user.msats - threshold)
@@ -13,7 +16,10 @@ export async function autoWithdraw ({ data: { id }, models, lnd }) {
if (excess < Number(threshold) * 0.1) return
// floor fee to nearest sat but still denominated in msats
- const maxFeeMsats = msatsSatsFloor(Math.ceil(excess * (user.autoWithdrawMaxFeePercent / 100.0)))
+ const maxFeeMsats = msatsSatsFloor(Math.max(
+ Math.ceil(excess * (user.autoWithdrawMaxFeePercent / 100.0)),
+ Number(satsToMsats(user.autoWithdrawMaxBaseFee))
+ ))
// msats will be floored by createInvoice if it needs to be
const msats = BigInt(excess) - maxFeeMsats