Skip to content

Commit

Permalink
fix case of split utxos
Browse files Browse the repository at this point in the history
  • Loading branch information
0xngmi committed Apr 21, 2024
1 parent 3757bbb commit 0367458
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions fees/wbtc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ async function getBitcoinTx(txId:string){
return btcRpcCall("decoderawtransaction", [fullTx.result])
}

function findClosest(arr:number[], target:number){
return arr.reduce((best, item)=>{
if(Math.abs(target-item) < Math.abs(target-best)){
return item
}
return best
})
}

export default {
adapter: {
"ethereum": {
Expand All @@ -34,7 +25,7 @@ export default {
await Promise.all(mints.concat(burns).map(async event=>{
const amount = Number(event.amount)
const btcTx = await getBitcoinTx(event.btcTxid)
const btcSend = findClosest(btcTx.result.vout.map(v=>v.value), amount/1e8)
const btcSend = btcTx.result.vout.filter(v=>v.scriptPubKey.address === event.btcDepositAddress).reduce((sum, v)=>sum+v.value, 0)
dailyFees.add('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', Math.abs(amount-btcSend*1e8));
}))
return { dailyFees, dailyRevenue: dailyFees }
Expand Down

0 comments on commit 0367458

Please sign in to comment.