Compare commits

...

2 Commits

Author SHA1 Message Date
Keyan 8441e04d3e
Update awards.csv 2024-11-19 12:55:55 -06:00
ekzyis bcd229af93
Fix 'Cannot mix BigInt and other types' on zaps (#1609)
* Fix 'Cannot mix BigInt and other types' on zaps

* Also add sybilFeePercent to context in worker

* add paymentMethod to context

---------

Co-authored-by: k00b <k00b@stacker.news>
2024-11-19 09:31:26 -06:00
4 changed files with 25 additions and 22 deletions

View File

@ -56,7 +56,8 @@ 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
@ -67,6 +68,7 @@ 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) {
@ -77,7 +79,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, context) return await performP2PAction(actionType, args, contextWithPaymentMethod)
} 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')
@ -87,14 +89,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, context) return await beginPessimisticAction(actionType, args, contextWithPaymentMethod)
} }
// additionalpayment methods that logged in users can use // additional payment 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, { ...context, paymentMethod }) return await performNoInvoiceAction(actionType, args, contextWithPaymentMethod)
} 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)
@ -103,7 +105,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, context) return await performOptimisticAction(actionType, args, contextWithPaymentMethod)
} }
} }
} }
@ -186,25 +188,19 @@ 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, models, lnd, me } = incomingContext const { cost, sybilFeePercent, 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 contextWithSybilFeePercent = { const userId = await paidActions[actionType]?.getInvoiceablePeer?.(args, incomingContext)
...incomingContext,
sybilFeePercent
}
const userId = await paidActions[actionType]?.getInvoiceablePeer?.(args, contextWithSybilFeePercent)
if (!userId) { if (!userId) {
throw new NonInvoiceablePeerError() throw new NonInvoiceablePeerError()
} }
await assertBelowMaxPendingInvoices(contextWithSybilFeePercent) await assertBelowMaxPendingInvoices(incomingContext)
const description = await paidActions[actionType].describe(args, contextWithSybilFeePercent) const description = await paidActions[actionType].describe(args, incomingContext)
const { invoice, wrappedInvoice, wallet, maxFee } = await createWrappedInvoice(userId, { const { invoice, wrappedInvoice, wallet, maxFee } = await createWrappedInvoice(userId, {
msats: cost, msats: cost,
feePercent: sybilFeePercent, feePercent: sybilFeePercent,
@ -213,7 +209,7 @@ async function performP2PAction (actionType, args, incomingContext) {
}, { models, me, lnd }) }, { models, me, lnd })
const context = { const context = {
...contextWithSybilFeePercent, ...incomingContext,
invoiceArgs: { invoiceArgs: {
bolt11: invoice, bolt11: invoice,
wrappedBolt11: wrappedInvoice, wrappedBolt11: wrappedInvoice,

View File

@ -53,8 +53,10 @@ export async function perform ({
} }
} }
export async function describe ({ description }, { me, cost, sybilFeePercent }) { export async function describe ({ description }, { me, cost, paymentMethod, sybilFeePercent }) {
const fee = sybilFeePercent ? cost * BigInt(sybilFeePercent) / 100n : 0n const fee = paymentMethod === PAID_ACTION_PAYMENT_METHODS.P2P
? 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,3 +137,8 @@ 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
140 Soxasora pr #1593 #1569 good-first-issue 20k soxasora@blink.sv 2024-11-19
141 Soxasora pr #1599 #1258 medium 250k soxasora@blink.sv 2024-11-19
142 aegroto pr #1585 #1522 easy high 1 180k aegroto@blink.sv 2024-11-19
143 sig47 issue #1585 #1522 easy high 1 18k siggy47@stacker.news 2024-11-19
144 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, sybilFeePercent }) const result = await paidActions[dbInvoice.actionType].perform(args, context)
await tx.invoice.update({ await tx.invoice.update({
where: { id: dbInvoice.id }, where: { id: dbInvoice.id },
data: { data: {