@xyo-network/chain-services 1.20.14 → 1.20.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +0,0 @@
1
- import { type Address, hexFromBigInt } from '@xylabs/sdk-js'
2
- import { assertEx } from '@xylabs/sdk-js'
3
- import { PayloadBuilder } from '@xyo-network/sdk-js'
4
- import type {
5
- SignedHydratedTransaction,
6
- Transfer,
7
- XL1,
8
- } from '@xyo-network/xl1-sdk'
9
- import {
10
- HydratedTransactionWrapper,
11
- transactionRequiredGas, TransferSchema, XYO_ZERO_ADDRESS,
12
- } from '@xyo-network/xl1-sdk'
13
-
14
- export async function generateTransactionFeeTransfers(address: Address, transactions: SignedHydratedTransaction[]): Promise<Transfer[]> {
15
- const txs = await Promise.all(transactions.map(async (tx) => {
16
- return HydratedTransactionWrapper.parse([await PayloadBuilder.addStorageMeta(tx[0]), await PayloadBuilder.addStorageMeta(tx[1])])
17
- }))
18
-
19
- // merge transactions with the same from address
20
- const txBaseFeeCosts: Record<Address, bigint> = {}
21
- for (const tx of txs) {
22
- txBaseFeeCosts[tx.boundWitness.from] = (txBaseFeeCosts[tx.boundWitness.from] ?? 0n)
23
- + tx.fees.base
24
- }
25
-
26
- const txGasCosts: Record<Address, bigint> = {}
27
- for (const tx of txs) {
28
- const requiredGas = transactionRequiredGas(tx.data)
29
- const totalGasCost = requiredGas * tx.fees.gasPrice
30
- txGasCosts[tx.boundWitness.from] = (txBaseFeeCosts[tx.boundWitness.from] ?? 0n)
31
- + totalGasCost
32
- }
33
-
34
- // generate actual Transfer Payloads & burn the base fee
35
- const payloads = (Object.entries(txBaseFeeCosts) as [Address, XL1][]).map(([from, amount]) => {
36
- const payload: Transfer = {
37
- schema: TransferSchema,
38
- epoch: Date.now(),
39
- from,
40
- transfers: {
41
- // burn the base fee
42
- [XYO_ZERO_ADDRESS]: hexFromBigInt(amount),
43
- },
44
- }
45
- return payload
46
- })
47
-
48
- // transfer gas cost to producer
49
- for (const [from, amount] of Object.entries(txGasCosts)) {
50
- // every gas from should also be a base fee from
51
- const fromPayload = assertEx(payloads.find(p => p.from === from), () => 'from payload not found')
52
- fromPayload.transfers[address] = hexFromBigInt(amount)
53
- }
54
-
55
- return payloads
56
- }
@@ -1 +0,0 @@
1
- export * from './SimpleBlockRunner.ts'
@@ -1 +0,0 @@
1
- export * from './block/index.ts'