1.0.48 • Published 4 months ago

@once-upon/evm-context v1.0.48

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months 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.1.0-6

4 months ago

1.1.0-5

4 months ago

1.1.0-3

5 months ago

1.1.0-2

5 months ago

1.1.0-1

5 months ago

1.1.0-0

6 months ago

1.0.40

6 months ago

1.0.44

4 months ago

1.0.43

5 months ago

1.0.42

5 months ago

1.0.41

5 months ago

1.0.48

4 months ago

1.0.47

4 months ago

1.0.46

4 months ago

1.0.45

4 months ago

1.0.39

6 months ago

1.0.38

6 months ago

1.0.37

6 months ago

1.0.36

6 months ago

1.0.35

6 months ago

1.0.34

7 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.31

7 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.30

7 months ago

1.0.26

7 months ago

1.0.27

7 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.20

7 months ago

1.0.15

7 months ago

1.0.9

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago

1.0.0-9

8 months ago

1.0.0-8

8 months ago

1.0.0-7

8 months ago

0.0.90

8 months ago

0.0.88

8 months ago

0.0.89

8 months ago

0.0.87

8 months ago

0.0.86

8 months ago

1.0.0-6

8 months ago

0.0.84

8 months ago

0.0.85

8 months ago

1.0.0-5

8 months ago

1.0.0-4

8 months ago

0.0.83

8 months ago

0.0.80

8 months ago

0.0.81

8 months ago

0.0.82

8 months ago

0.0.74

8 months ago

0.0.75

8 months ago

0.0.76

8 months ago

0.0.77

8 months ago

0.0.78

8 months ago

0.0.79

8 months ago

1.0.0-3

8 months ago

0.0.73

8 months ago

1.0.0-2

8 months ago

1.0.0-0

9 months ago

0.0.70

9 months ago

0.0.71

9 months ago

0.0.72

9 months ago

0.0.69

9 months ago

0.0.65

9 months ago

0.0.66

9 months ago

0.0.67

9 months ago

0.0.68

9 months ago

0.0.63

9 months ago

0.0.64

9 months ago

0.0.62

10 months ago

0.0.61

10 months ago

0.0.60

10 months ago

0.0.59

10 months ago

0.0.57

10 months ago

0.0.58

10 months ago

0.0.56

10 months ago

0.0.54

10 months ago

0.0.55

10 months ago

0.0.53

11 months ago

0.0.52

11 months ago

0.0.51

11 months ago

0.0.50

11 months ago

0.0.49

11 months ago

0.0.48

11 months ago

0.0.47

11 months ago

0.0.46

11 months ago

0.0.45

11 months ago

0.0.40

11 months ago

0.0.41

11 months ago

0.0.42

11 months ago

0.0.43

11 months ago

0.0.44

11 months ago

0.0.38

11 months ago

0.0.39

11 months ago

0.0.37

11 months ago

0.0.35

11 months ago

0.0.36

11 months ago

0.0.31

11 months ago

0.0.32

11 months ago

0.0.33

11 months ago

0.0.34

11 months ago

0.0.30

11 months ago

0.0.29

12 months ago

0.0.28

12 months ago

0.0.27

12 months ago

0.0.26

12 months ago

0.0.20

12 months ago

0.0.21

12 months ago

0.0.22

12 months ago

0.0.23

12 months ago

0.0.24

12 months ago

0.0.25

12 months ago

0.0.19

12 months ago

0.0.18

12 months ago

0.0.17

12 months ago

0.0.16

12 months ago

0.0.15

12 months ago

0.0.14

12 months ago

0.0.13

12 months ago

0.0.12

12 months ago

0.0.11

12 months ago

0.0.10

12 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago