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

View File

@ -53,10 +53,8 @@ export async function perform ({
} }
} }
export async function describe ({ description }, { me, cost, paymentMethod, sybilFeePercent }) { export async function describe ({ description }, { me, cost, sybilFeePercent }) {
const fee = paymentMethod === PAID_ACTION_PAYMENT_METHODS.P2P const fee = sybilFeePercent ? cost * BigInt(sybilFeePercent) / 100n : 0n
? cost * BigInt(sybilFeePercent) / 100n
: 0n
return description ?? `SN: ${me?.name ?? ''} receives ${numWithUnits(msatsToSats(cost - fee))}` 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 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 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 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 = { const context = {
tx, tx,
cost: BigInt(lndInvoice.received_mtokens), cost: BigInt(lndInvoice.received_mtokens),
me: dbInvoice.user, me: dbInvoice.user
sybilFeePercent: await paidActions[dbInvoice.actionType].getSybilFeePercent?.()
} }
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({ await tx.invoice.update({
where: { id: dbInvoice.id }, where: { id: dbInvoice.id },
data: { data: {