From c97ce2627b93c77095b91430a3649f515c359bef Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 19 Oct 2024 16:21:50 +0200 Subject: [PATCH] Rename to autoWithdrawMaxFeeTotal --- api/resolvers/wallet.js | 4 ++-- api/typeDefs/user.js | 2 +- api/typeDefs/wallet.js | 2 +- components/autowithdraw-shared.js | 4 ++-- fragments/users.js | 2 +- lib/validate.js | 2 +- .../migrations/20241018160708_max_base_fee/migration.sql | 8 -------- .../migrations/20241018160708_max_fee_total/migration.sql | 8 ++++++++ prisma/schema.prisma | 2 +- wallets/index.js | 4 ++-- worker/autowithdraw.js | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 prisma/migrations/20241018160708_max_base_fee/migration.sql create mode 100644 prisma/migrations/20241018160708_max_fee_total/migration.sql diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index 296516a9..ee1677aa 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -650,7 +650,7 @@ async function upsertWallet ( const { autoWithdrawThreshold, autoWithdrawMaxFeePercent, - autoWithdrawMaxBaseFee, + autoWithdrawMaxFeeTotal, enabled, priority } = settings @@ -661,7 +661,7 @@ async function upsertWallet ( data: { autoWithdrawMaxFeePercent, autoWithdrawThreshold, - autoWithdrawMaxBaseFee + autoWithdrawMaxFeeTotal } }) ] diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index 39f417a8..4f987cd5 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -182,7 +182,7 @@ export default gql` withdrawMaxFeeDefault: Int! autoWithdrawThreshold: Int autoWithdrawMaxFeePercent: Float - autoWithdrawMaxBaseFee: Int + autoWithdrawMaxFeeTotal: Int } type UserOptional { diff --git a/api/typeDefs/wallet.js b/api/typeDefs/wallet.js index 12e5e4be..cdd47a3c 100644 --- a/api/typeDefs/wallet.js +++ b/api/typeDefs/wallet.js @@ -91,7 +91,7 @@ const typeDefs = ` input AutowithdrawSettings { autoWithdrawThreshold: Int! autoWithdrawMaxFeePercent: Float! - autoWithdrawMaxBaseFee: Int! + autoWithdrawMaxFeeTotal: Int! priority: Int enabled: Boolean } diff --git a/components/autowithdraw-shared.js b/components/autowithdraw-shared.js index 62c62bcd..27917ed9 100644 --- a/components/autowithdraw-shared.js +++ b/components/autowithdraw-shared.js @@ -14,7 +14,7 @@ export function autowithdrawInitial ({ me }) { return { autoWithdrawThreshold: autoWithdrawThreshold({ me }), autoWithdrawMaxFeePercent: isNumber(me?.privates?.autoWithdrawMaxFeePercent) ? me?.privates?.autoWithdrawMaxFeePercent : 1, - autoWithdrawMaxBaseFee: isNumber(me?.privates?.autoWithdrawMaxBaseFee) ? me?.privates?.autoWithdrawMaxBaseFee : 1 + autoWithdrawMaxFeeTotal: isNumber(me?.privates?.autoWithdrawMaxFeeTotal) ? me?.privates?.autoWithdrawMaxFeeTotal : 1 } } @@ -72,7 +72,7 @@ export function AutowithdrawSettings ({ wallet }) { /> sats} required diff --git a/fragments/users.js b/fragments/users.js index 11d592d8..16a703ce 100644 --- a/fragments/users.js +++ b/fragments/users.js @@ -27,7 +27,7 @@ ${STREAK_FIELDS} noReferralLinks fiatCurrency autoWithdrawMaxFeePercent - autoWithdrawMaxBaseFee + autoWithdrawMaxFeeTotal autoWithdrawThreshold withdrawMaxFeeDefault satsFilter diff --git a/lib/validate.js b/lib/validate.js index 02705088..f8fd24d9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -367,7 +367,7 @@ 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'), - autoWithdrawMaxBaseFee: intValidator.required('required').min(0, 'must be at least 0').max(1_000, 'must not exceed 1000') + autoWithdrawMaxFeeTotal: 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 deleted file mode 100644 index 23381126..00000000 --- a/prisma/migrations/20241018160708_max_base_fee/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- 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/migrations/20241018160708_max_fee_total/migration.sql b/prisma/migrations/20241018160708_max_fee_total/migration.sql new file mode 100644 index 00000000..0533ff9b --- /dev/null +++ b/prisma/migrations/20241018160708_max_fee_total/migration.sql @@ -0,0 +1,8 @@ +-- AlterTable +ALTER TABLE "users" ADD COLUMN "autoWithdrawMaxFeeTotal" INTEGER; + +-- set max total 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 "autoWithdrawMaxFeeTotal" = 0 +WHERE "autoWithdrawMaxFeePercent" IS NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cb3162e2..ee6e1804 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -118,7 +118,7 @@ model User { lnAddr String? autoWithdrawMaxFeePercent Float? autoWithdrawThreshold Int? - autoWithdrawMaxBaseFee Int? + autoWithdrawMaxFeeTotal Int? muters Mute[] @relation("muter") muteds Mute[] @relation("muted") ArcOut Arc[] @relation("fromUser") diff --git a/wallets/index.js b/wallets/index.js index 0333becd..c403677f 100644 --- a/wallets/index.js +++ b/wallets/index.js @@ -296,7 +296,7 @@ function useServerConfig (wallet) { const saveConfig = useCallback(async ({ autoWithdrawThreshold, autoWithdrawMaxFeePercent, - autoWithdrawMaxBaseFee, + autoWithdrawMaxFeeTotal, priority, enabled, ...config @@ -311,7 +311,7 @@ function useServerConfig (wallet) { settings: { autoWithdrawThreshold: Number(autoWithdrawThreshold), autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent), - autoWithdrawMaxBaseFee: Number(autoWithdrawMaxBaseFee), + autoWithdrawMaxFeeTotal: Number(autoWithdrawMaxFeeTotal), priority, enabled }, diff --git a/worker/autowithdraw.js b/worker/autowithdraw.js index 0589159a..04611599 100644 --- a/worker/autowithdraw.js +++ b/worker/autowithdraw.js @@ -7,7 +7,7 @@ export async function autoWithdraw ({ data: { id }, models, lnd }) { if ( user.autoWithdrawThreshold === null || user.autoWithdrawMaxFeePercent === null || - user.autoWithdrawMaxBaseFee === null) return + user.autoWithdrawMaxFeeTotal === null) return const threshold = satsToMsats(user.autoWithdrawThreshold) const excess = Number(user.msats - threshold) @@ -18,7 +18,7 @@ export async function autoWithdraw ({ data: { id }, models, lnd }) { // floor fee to nearest sat but still denominated in msats const maxFeeMsats = msatsSatsFloor(Math.max( Math.ceil(excess * (user.autoWithdrawMaxFeePercent / 100.0)), - Number(satsToMsats(user.autoWithdrawMaxBaseFee)) + Number(satsToMsats(user.autoWithdrawMaxFeeTotal)) )) // msats will be floored by createInvoice if it needs to be const msats = BigInt(excess) - maxFeeMsats