Compare commits

..

No commits in common. "8441e04d3eadf62d12f8c1af84ce0d323bff9bcb" and "c2dc0be1c1210725897bb71beb9ffb720e452a2a" have entirely different histories.

4 changed files with 22 additions and 25 deletions

View File

@ -56,8 +56,7 @@ export default async function performPaidAction (actionType, args, incomingConte
}
const context = {
...contextWithMe,
cost: await paidAction.getCost(args, contextWithMe),
sybilFeePercent: await paidAction.getSybilFeePercent?.(args, contextWithMe)
cost: await paidAction.getCost(args, contextWithMe)
}
// special case for zero cost actions
@ -68,7 +67,6 @@ export default async function performPaidAction (actionType, args, incomingConte
for (const paymentMethod of paidAction.paymentMethods) {
console.log(`considering payment method ${paymentMethod}`)
const contextWithPaymentMethod = { ...context, paymentMethod }
if (forcePaymentMethod &&
paymentMethod !== forcePaymentMethod) {
@ -79,7 +77,7 @@ export default async function performPaidAction (actionType, args, incomingConte
// payment methods that anonymous users can use
if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.P2P) {
try {
return await performP2PAction(actionType, args, contextWithPaymentMethod)
return await performP2PAction(actionType, args, context)
} catch (e) {
if (e instanceof NonInvoiceablePeerError) {
console.log('peer cannot be invoiced, skipping')
@ -89,14 +87,14 @@ export default async function performPaidAction (actionType, args, incomingConte
throw e
}
} else if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.PESSIMISTIC) {
return await beginPessimisticAction(actionType, args, contextWithPaymentMethod)
return await beginPessimisticAction(actionType, args, context)
}
// additional payment methods that logged in users can use
// additionalpayment methods that logged in users can use
if (me) {
if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.FEE_CREDIT) {
try {
return await performNoInvoiceAction(actionType, args, contextWithPaymentMethod)
return await performNoInvoiceAction(actionType, args, { ...context, paymentMethod })
} catch (e) {
// if we fail with fee credits or reward sats, but not because of insufficient funds, bail
console.error(`${paymentMethod} action failed`, e)
@ -105,7 +103,7 @@ export default async function performPaidAction (actionType, args, incomingConte
}
}
} else if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.OPTIMISTIC) {
return await performOptimisticAction(actionType, args, contextWithPaymentMethod)
return await performOptimisticAction(actionType, args, context)
}
}
}
@ -188,19 +186,25 @@ async function beginPessimisticAction (actionType, args, context) {
async function performP2PAction (actionType, args, incomingContext) {
// if the action has an invoiceable peer, we'll create a peer invoice
// wrap it, and return the wrapped invoice
const { cost, sybilFeePercent, models, lnd, me } = incomingContext
const { cost, models, lnd, me } = incomingContext
const sybilFeePercent = await paidActions[actionType].getSybilFeePercent?.(args, incomingContext)
if (!sybilFeePercent) {
throw new Error('sybil fee percent is not set for an invoiceable peer action')
}
const userId = await paidActions[actionType]?.getInvoiceablePeer?.(args, incomingContext)
const contextWithSybilFeePercent = {
...incomingContext,
sybilFeePercent
}
const userId = await paidActions[actionType]?.getInvoiceablePeer?.(args, contextWithSybilFeePercent)
if (!userId) {
throw new NonInvoiceablePeerError()
}
await assertBelowMaxPendingInvoices(incomingContext)
await assertBelowMaxPendingInvoices(contextWithSybilFeePercent)
const description = await paidActions[actionType].describe(args, incomingContext)
const description = await paidActions[actionType].describe(args, contextWithSybilFeePercent)
const { invoice, wrappedInvoice, wallet, maxFee } = await createWrappedInvoice(userId, {
msats: cost,
feePercent: sybilFeePercent,
@ -209,7 +213,7 @@ async function performP2PAction (actionType, args, incomingContext) {
}, { models, me, lnd })
const context = {
...incomingContext,
...contextWithSybilFeePercent,
invoiceArgs: {
bolt11: invoice,
wrappedBolt11: wrappedInvoice,

View File

@ -53,10 +53,8 @@ export async function perform ({
}
}
export async function describe ({ description }, { me, cost, paymentMethod, sybilFeePercent }) {
const fee = paymentMethod === PAID_ACTION_PAYMENT_METHODS.P2P
? cost * BigInt(sybilFeePercent) / 100n
: 0n
export async function describe ({ description }, { me, cost, sybilFeePercent }) {
const fee = sybilFeePercent ? cost * BigInt(sybilFeePercent) / 100n : 0n
return description ?? `SN: ${me?.name ?? ''} receives ${numWithUnits(msatsToSats(cost - fee))}`
}

View File

@ -137,8 +137,3 @@ SouthKoreaLN,issue,#1436,,easy,,,,10k,south_korea_ln@stacker.news,2024-10-02
TonyGiorgio,issue,#1462,,easy,urgent,,,30k,TonyGiorgio@stacker.news,2024-10-07
hkarani,issue,#1369,#1458,good-first-issue,,,,2k,asterisk32@stacker.news,2024-10-21
toyota-corolla0,pr,#1369,#1458,good-first-issue,,,,20k,toyota_corolla0@stacker.news,2024-10-20
Soxasora,pr,#1593,#1569,good-first-issue,,,,20k,soxasora@blink.sv,2024-11-19
Soxasora,pr,#1599,#1258,medium,,,,250k,soxasora@blink.sv,2024-11-19
aegroto,pr,#1585,#1522,easy,high,,1,180k,aegroto@blink.sv,2024-11-19
sig47,issue,#1585,#1522,easy,high,,1,18k,siggy47@stacker.news,2024-11-19
aegroto,pr,#1583,#1572,easy,,,2,80k,aegroto@blink.sv,2024-11-19

1 name type pr id issue ids difficulty priority changes requested notes amount receive method date paid
137 TonyGiorgio issue #1462 easy urgent 30k TonyGiorgio@stacker.news 2024-10-07
138 hkarani issue #1369 #1458 good-first-issue 2k asterisk32@stacker.news 2024-10-21
139 toyota-corolla0 pr #1369 #1458 good-first-issue 20k toyota_corolla0@stacker.news 2024-10-20
Soxasora pr #1593 #1569 good-first-issue 20k soxasora@blink.sv 2024-11-19
Soxasora pr #1599 #1258 medium 250k soxasora@blink.sv 2024-11-19
aegroto pr #1585 #1522 easy high 1 180k aegroto@blink.sv 2024-11-19
sig47 issue #1585 #1522 easy high 1 18k siggy47@stacker.news 2024-11-19
aegroto pr #1583 #1572 easy 2 80k aegroto@blink.sv 2024-11-19

View File

@ -119,11 +119,11 @@ async function performPessimisticAction ({ lndInvoice, dbInvoice, tx, models, ln
const context = {
tx,
cost: BigInt(lndInvoice.received_mtokens),
me: dbInvoice.user,
sybilFeePercent: await paidActions[dbInvoice.actionType].getSybilFeePercent?.()
me: dbInvoice.user
}
const sybilFeePercent = await paidActions[dbInvoice.actionType].getSybilFeePercent?.(args, context)
const result = await paidActions[dbInvoice.actionType].perform(args, context)
const result = await paidActions[dbInvoice.actionType].perform(args, { ...context, sybilFeePercent })
await tx.invoice.update({
where: { id: dbInvoice.id },
data: {