1.0.36 • Published 6 days ago

@once-upon/evm-context v1.0.36

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

EVM Context

Context for Ethereum L1 and L2 transactions

If you want your protocol to work well on your own app, use a private indexer. If you want your protocol to work well across all of web3, contribute to EVM Context.

Ideal contributors:

  • Protocol teams

Ideal users

  • Wallets
  • Web3 browsing tools
  • Web3 analytics tools

Quick start

Generating a new contextualization

If you're ready to start building with a certain transaction in mind:

npm run create:contextualizer [name of protocol] -- -h [transaction hash]

If you don't yet know which transaction you want to test against:

npm run create:contextualizer [name of protocol]

This will generate a new file called protocol/[name of protocol].ts and a test file called protocol/[name of protocol].spec.ts.

Tests

npm run test

You should write unit tests for your PR using a real transaction.

If you used a tx hash when running npm run create:contextualizer, this is already set up for you.

To include more transactions in your tests, run this command:

npm run grab:transaction [txHash] [nickname for the type of tx]

Running contextualizers

To confirm that the contextualizers work with live transaction data, run this command:

npm run run:contextualizers -- -l [number of transactions]

Finishing your new contextualization

Once that's ready, please open a PR on this repo and request review from pcowgill and jordanmessina

Example contextualization

// The transaction variable is an object containing the raw tx data

// the contextualization lives under the context key
transaction.context = {
  variables: {
    sender: {
      type: 'address',
      value: '0xabc...123',
    },
    asset1: {
      type: 'erc20',
      token: '0xdef...456', // the contract address
      value: '200',
    },
  },
  summaries: {
    category: 'PROTOCOL_1', // can be 1-5, with 1 being the "most important"
    // English
    en: {
      title: '<Name of protocol>', // e.g. Farcaster
      variables: {
        contextAction: {
          type: 'contextAction',
          value: 'sent',
        },
        // any other variables that only make sense for the english contextualization
        // ...
      },
      // default is the main sentence version, with others optionally defined below
      // this could be rendered however a UI wants
      // the most basic version would be "0xabc...123 sent 200 0xdef...456"
      default:
        '[[sender]] [[contextAction]] [[asset1]]',
    },
    // other languages
    // ...
  },

Usage with an RPC endpoint directly

This library is meant to be usable with any RPC endpoint. It depends on some upstream convenience keys/values added to transaction objects - assetTransfers and netAssetTransfers, and parties.

Input

Raw transaction data from an EVM RPC

Output

Transaction objects with

  • a parties key containing an array of involved parties (addresses included in input data, logs, etc.) in the transaction.
  • an assetTransfers key containing an array of objects for all individual ETH, ERC20, ERC721, ERC1155 transfers that took place in that transaction.
  • a netAssetTransfers key containing an object with rolled up net balance change information for each address involved in the transaction, containing their net gain or loss of ETH, ERC20, ERC721, ERC1155 in that that transaction.

In other words, assetTransfers shows everything that happened under the hood in order, and netAssetTransfers is a summary of the end result.

Example

const inputTransaction = {
  to: '0xabc...123',
  // ...
};

const outputTransaction = {
  to: '0xabc...123',
  // ...
  parties: [
    '0x662127bf82b794a26b7ddb6b495f6a5a20b81738',
    '0x2d660d49473dbbcaf63929d10d0e3501b4533182',
    '0x8ca5e648c5dfefcdda06d627f4b490b719ccfd98',
    // ...
  ],
  assetTransfers: [
    {
      contract: '0x2d660d49473dbbcaf63929d10d0e3501b4533182',
      from: '0x0000000000000000000000000000000000000000',
      to: '0x662127bf82b794a26b7ddb6b495f6a5a20b81738',
      tokenId: '610',
      type: 'erc721',
    },
    // ..
  ],
  netAssetTransfers: {
    '0x662127bf82b794a26b7ddb6b495f6a5a20b81738': {
      received: [
        {
          contract: '0x2d660d49473dbbcaf63929d10d0e3501b4533182',
          tokenId: '610',
          type: 'erc721',
        },
      ],
      sent: [
        {
          asset: 'eth',
          id: 'eth',
          type: 'eth',
          value: '100777000000000000',
        },
      ],
    },
    // ..
  },
};

License

See the LICENSE file for license rights and limitations (MIT).

1.0.36

6 days ago

1.0.35

6 days ago

1.0.34

13 days ago

1.0.33

14 days ago

1.0.32

14 days ago

1.0.31

14 days ago

1.0.29

15 days ago

1.0.28

15 days ago

1.0.30

15 days ago

1.0.26

17 days ago

1.0.27

17 days ago

1.0.25

18 days ago

1.0.24

20 days ago

1.0.23

20 days ago

1.0.22

21 days ago

1.0.21

21 days ago

1.0.19

25 days ago

1.0.18

25 days ago

1.0.17

25 days ago

1.0.16

26 days ago

1.0.20

25 days ago

1.0.15

26 days ago

1.0.9

28 days ago

1.0.11

28 days ago

1.0.10

28 days ago

1.0.14

28 days ago

1.0.13

28 days ago

1.0.12

28 days ago

1.0.7

1 month ago

1.0.6

1 month ago

1.0.5

1 month ago

1.0.4

1 month ago

1.0.3

1 month ago

1.0.2

1 month ago

1.0.1

1 month ago

1.0.0

1 month ago

1.0.0-9

1 month ago

1.0.0-8

1 month ago

1.0.0-7

1 month ago

0.0.90

1 month ago

0.0.88

2 months ago

0.0.89

2 months ago

0.0.87

2 months ago

0.0.86

2 months ago

1.0.0-6

2 months ago

0.0.84

2 months ago

0.0.85

2 months ago

1.0.0-5

2 months ago

1.0.0-4

2 months ago

0.0.83

2 months ago

0.0.80

2 months ago

0.0.81

2 months ago

0.0.82

2 months ago

0.0.74

2 months ago

0.0.75

2 months ago

0.0.76

2 months ago

0.0.77

2 months ago

0.0.78

2 months ago

0.0.79

2 months ago

1.0.0-3

2 months ago

0.0.73

2 months ago

1.0.0-2

2 months ago

1.0.0-0

2 months ago

0.0.70

3 months ago

0.0.71

3 months ago

0.0.72

3 months ago

0.0.69

3 months ago

0.0.65

3 months ago

0.0.66

3 months ago

0.0.67

3 months ago

0.0.68

3 months ago

0.0.63

3 months ago

0.0.64

3 months ago

0.0.62

4 months ago

0.0.61

4 months ago

0.0.60

4 months ago

0.0.59

4 months ago

0.0.57

4 months ago

0.0.58

4 months ago

0.0.56

4 months ago

0.0.54

4 months ago

0.0.55

4 months ago

0.0.53

4 months ago

0.0.52

5 months ago

0.0.51

5 months ago

0.0.50

5 months ago

0.0.49

5 months ago

0.0.48

5 months ago

0.0.47

5 months ago

0.0.46

5 months ago

0.0.45

5 months ago

0.0.40

5 months ago

0.0.41

5 months ago

0.0.42

5 months ago

0.0.43

5 months ago

0.0.44

5 months ago

0.0.38

5 months ago

0.0.39

5 months ago

0.0.37

5 months ago

0.0.35

5 months ago

0.0.36

5 months ago

0.0.31

5 months ago

0.0.32

5 months ago

0.0.33

5 months ago

0.0.34

5 months ago

0.0.30

5 months ago

0.0.29

5 months ago

0.0.28

5 months ago

0.0.27

5 months ago

0.0.26

5 months ago

0.0.20

5 months ago

0.0.21

5 months ago

0.0.22

5 months ago

0.0.23

5 months ago

0.0.24

5 months ago

0.0.25

5 months ago

0.0.19

5 months ago

0.0.18

5 months ago

0.0.17

5 months ago

0.0.16

5 months ago

0.0.15

5 months ago

0.0.14

5 months ago

0.0.13

5 months ago

0.0.12

5 months ago

0.0.11

5 months ago

0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago