@lemmaoracle/x402 0.1.1

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.
Files changed (126) hide show
  1. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996174982.json +34 -0
  2. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996423983.json +51 -0
  3. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-1775996907850.json +51 -0
  4. package/broadcast/DeployPaymentVerifier.s.sol/10143/run-latest.json +51 -0
  5. package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996174982.json +7 -0
  6. package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996423983.json +7 -0
  7. package/cache/DeployPaymentVerifier.s.sol/10143/run-1775996907850.json +7 -0
  8. package/cache/DeployPaymentVerifier.s.sol/10143/run-latest.json +7 -0
  9. package/cache/solidity-files-cache.json +1 -0
  10. package/circuits/README.md +78 -0
  11. package/circuits/payment-comprehensive.test.mjs +272 -0
  12. package/circuits/payment.circom +89 -0
  13. package/circuits/payment.test.mjs +173 -0
  14. package/dist/index.d.ts +48 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +83 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/proof-generator.d.ts +26 -0
  19. package/dist/proof-generator.d.ts.map +1 -0
  20. package/dist/proof-generator.js +154 -0
  21. package/dist/proof-generator.js.map +1 -0
  22. package/dist/proof-generator.test.d.ts +7 -0
  23. package/dist/proof-generator.test.d.ts.map +1 -0
  24. package/dist/proof-generator.test.js +121 -0
  25. package/dist/proof-generator.test.js.map +1 -0
  26. package/dist/transaction-watcher.d.ts +42 -0
  27. package/dist/transaction-watcher.d.ts.map +1 -0
  28. package/dist/transaction-watcher.js +88 -0
  29. package/dist/transaction-watcher.js.map +1 -0
  30. package/dist/transaction-watcher.test.d.ts +7 -0
  31. package/dist/transaction-watcher.test.d.ts.map +1 -0
  32. package/dist/transaction-watcher.test.js +111 -0
  33. package/dist/transaction-watcher.test.js.map +1 -0
  34. package/dist/types.d.ts +76 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +2 -0
  37. package/dist/types.js.map +1 -0
  38. package/foundry.lock +11 -0
  39. package/foundry.toml +16 -0
  40. package/lib/forge-std/.gitattributes +1 -0
  41. package/lib/forge-std/.github/CODEOWNERS +1 -0
  42. package/lib/forge-std/.github/dependabot.yml +6 -0
  43. package/lib/forge-std/.github/workflows/ci.yml +161 -0
  44. package/lib/forge-std/.github/workflows/sync.yml +36 -0
  45. package/lib/forge-std/CONTRIBUTING.md +193 -0
  46. package/lib/forge-std/LICENSE-APACHE +203 -0
  47. package/lib/forge-std/LICENSE-MIT +25 -0
  48. package/lib/forge-std/README.md +314 -0
  49. package/lib/forge-std/RELEASE_CHECKLIST.md +12 -0
  50. package/lib/forge-std/foundry.toml +18 -0
  51. package/lib/forge-std/package.json +16 -0
  52. package/lib/forge-std/scripts/vm.py +636 -0
  53. package/lib/forge-std/src/Base.sol +48 -0
  54. package/lib/forge-std/src/Config.sol +60 -0
  55. package/lib/forge-std/src/LibVariable.sol +477 -0
  56. package/lib/forge-std/src/Script.sol +28 -0
  57. package/lib/forge-std/src/StdAssertions.sol +1300 -0
  58. package/lib/forge-std/src/StdChains.sol +303 -0
  59. package/lib/forge-std/src/StdCheats.sol +825 -0
  60. package/lib/forge-std/src/StdConfig.sol +632 -0
  61. package/lib/forge-std/src/StdConstants.sol +30 -0
  62. package/lib/forge-std/src/StdError.sol +15 -0
  63. package/lib/forge-std/src/StdInvariant.sol +161 -0
  64. package/lib/forge-std/src/StdJson.sol +275 -0
  65. package/lib/forge-std/src/StdMath.sol +47 -0
  66. package/lib/forge-std/src/StdStorage.sol +476 -0
  67. package/lib/forge-std/src/StdStyle.sol +333 -0
  68. package/lib/forge-std/src/StdToml.sol +275 -0
  69. package/lib/forge-std/src/StdUtils.sol +200 -0
  70. package/lib/forge-std/src/Test.sol +32 -0
  71. package/lib/forge-std/src/Vm.sol +2533 -0
  72. package/lib/forge-std/src/console.sol +1551 -0
  73. package/lib/forge-std/src/console2.sol +4 -0
  74. package/lib/forge-std/src/interfaces/IERC1155.sol +105 -0
  75. package/lib/forge-std/src/interfaces/IERC165.sol +12 -0
  76. package/lib/forge-std/src/interfaces/IERC20.sol +43 -0
  77. package/lib/forge-std/src/interfaces/IERC4626.sol +190 -0
  78. package/lib/forge-std/src/interfaces/IERC6909.sol +72 -0
  79. package/lib/forge-std/src/interfaces/IERC721.sol +164 -0
  80. package/lib/forge-std/src/interfaces/IERC7540.sol +145 -0
  81. package/lib/forge-std/src/interfaces/IERC7575.sol +241 -0
  82. package/lib/forge-std/src/interfaces/IMulticall3.sol +68 -0
  83. package/lib/forge-std/src/safeconsole.sol +13248 -0
  84. package/lib/forge-std/test/CommonBase.t.sol +44 -0
  85. package/lib/forge-std/test/Config.t.sol +381 -0
  86. package/lib/forge-std/test/LibVariable.t.sol +452 -0
  87. package/lib/forge-std/test/StdAssertions.t.sol +141 -0
  88. package/lib/forge-std/test/StdChains.t.sol +227 -0
  89. package/lib/forge-std/test/StdCheats.t.sol +638 -0
  90. package/lib/forge-std/test/StdConstants.t.sol +38 -0
  91. package/lib/forge-std/test/StdError.t.sol +119 -0
  92. package/lib/forge-std/test/StdJson.t.sol +49 -0
  93. package/lib/forge-std/test/StdMath.t.sol +202 -0
  94. package/lib/forge-std/test/StdStorage.t.sol +532 -0
  95. package/lib/forge-std/test/StdStyle.t.sol +110 -0
  96. package/lib/forge-std/test/StdToml.t.sol +49 -0
  97. package/lib/forge-std/test/StdUtils.t.sol +342 -0
  98. package/lib/forge-std/test/Vm.t.sol +18 -0
  99. package/lib/forge-std/test/compilation/CompilationScript.sol +8 -0
  100. package/lib/forge-std/test/compilation/CompilationScriptBase.sol +8 -0
  101. package/lib/forge-std/test/compilation/CompilationTest.sol +8 -0
  102. package/lib/forge-std/test/compilation/CompilationTestBase.sol +8 -0
  103. package/lib/forge-std/test/fixtures/broadcast.log.json +187 -0
  104. package/lib/forge-std/test/fixtures/config.toml +81 -0
  105. package/lib/forge-std/test/fixtures/test.json +8 -0
  106. package/lib/forge-std/test/fixtures/test.toml +6 -0
  107. package/package.json +55 -0
  108. package/package.json.backup +55 -0
  109. package/scripts/DeployPaymentVerifier.s.sol +18 -0
  110. package/scripts/build.sh +61 -0
  111. package/scripts/deploy.sh +65 -0
  112. package/scripts/fix-verifier.mjs +64 -0
  113. package/scripts/register-circuit.ts +213 -0
  114. package/scripts/test-with-circuit.mjs +88 -0
  115. package/src/index.ts +115 -0
  116. package/src/proof-generator.test.ts +139 -0
  117. package/src/proof-generator.ts +220 -0
  118. package/src/transaction-watcher.test.ts +153 -0
  119. package/src/transaction-watcher.ts +154 -0
  120. package/src/types.ts +110 -0
  121. package/tsconfig.json +14 -0
  122. package/tsconfig.tsbuildinfo +1 -0
  123. package/vitest.config.ts +18 -0
  124. package/workers/x402-facilitator/src/index.ts +582 -0
  125. package/workers/x402-facilitator/src/x402-env.d.ts +25 -0
  126. package/workers/x402-facilitator/wrangler.toml +19 -0
@@ -0,0 +1,76 @@
1
+ /** Configuration for payment facilitator */
2
+ type Config = Readonly<{
3
+ /** x402 facilitator URL (for HTTPFacilitatorClient compatibility) */
4
+ facilitatorUrl?: string;
5
+ /** Address to receive payments */
6
+ payToAddress: `0x${string}`;
7
+ /** Network identifier (e.g., "eip155:84532" for Base Sepolia) */
8
+ network: string;
9
+ /** Price for accessing verified attributes (e.g., "$0.001") */
10
+ price: string;
11
+ /** Ethereum RPC URL for transaction monitoring */
12
+ ethereumRpcUrl: string;
13
+ /** Chain ID for the network */
14
+ chainId: number;
15
+ /** Lemma API base URL */
16
+ lemmaApiBase: string;
17
+ /** Lemma API key (if required) */
18
+ lemmaApiKey?: string;
19
+ /** Circuit ID for the payment proof */
20
+ circuitId: string;
21
+ /** Minimum amount in USDC smallest unit (6 decimals) */
22
+ minAmount: bigint;
23
+ /** Number of block confirmations before considering payment valid */
24
+ requiredConfirmations: number;
25
+ /** Maximum age of payment proof in seconds */
26
+ maxProofAge: number;
27
+ /** IPFS gateway URL for fetching circuit artifacts */
28
+ ipfsGateway?: string;
29
+ }>;
30
+ /** Parsed transaction details */
31
+ type Transaction = Readonly<{
32
+ /** Transaction hash */
33
+ txHash: `0x${string}`;
34
+ /** Sender address */
35
+ from: `0x${string}`;
36
+ /** Recipient address */
37
+ to: `0x${string}`;
38
+ /** Amount in smallest token unit */
39
+ amount: bigint;
40
+ /** Block timestamp */
41
+ timestamp: number;
42
+ /** Block number */
43
+ blockNumber: bigint;
44
+ /** Number of confirmations */
45
+ confirmations: number;
46
+ }>;
47
+ /** Generated proof with inputs for Lemma API */
48
+ type Proof = Readonly<{
49
+ /** ZK proof data (base64 encoded) */
50
+ proof: string;
51
+ /** Public inputs for the circuit */
52
+ inputs: ReadonlyArray<string>;
53
+ /** Circuit ID used */
54
+ circuitId: string;
55
+ /** Timestamp when proof was generated */
56
+ generatedAt: number;
57
+ }>;
58
+ /** Result of proof generation */
59
+ type ProofResult = Readonly<{
60
+ /** Transaction */
61
+ payment: Transaction;
62
+ /** Generated proof */
63
+ proof: Proof;
64
+ }>;
65
+ /** Disclosure condition for Lemma API query */
66
+ type DisclosureCondition = Readonly<{
67
+ circuitId: string;
68
+ }>;
69
+ /** Disclosure object to send with query */
70
+ type Disclosure = Readonly<{
71
+ condition?: DisclosureCondition;
72
+ proof: string;
73
+ inputs: ReadonlyArray<string>;
74
+ }>;
75
+ export type { Config, Transaction, Proof, ProofResult, Disclosure, DisclosureCondition, };
76
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,KAAK,MAAM,GAAG,QAAQ,CAAC;IACrB,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,kCAAkC;IAClC,YAAY,EAAE,KAAK,MAAM,EAAE,CAAC;IAE5B,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAEhB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IAEd,kDAAkD;IAClD,cAAc,EAAE,MAAM,CAAC;IAEvB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAEhB,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAC;IAErB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAElB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAElB,qEAAqE;IACrE,qBAAqB,EAAE,MAAM,CAAC;IAE9B,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IAEpB,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC,CAAC;AAEH,iCAAiC;AACjC,KAAK,WAAW,GAAG,QAAQ,CAAC;IAC1B,uBAAuB;IACvB,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;IAEtB,qBAAqB;IACrB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IAEpB,wBAAwB;IACxB,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;IAElB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IAEf,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAElB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IAEpB,8BAA8B;IAC9B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC,CAAC;AAEH,gDAAgD;AAChD,KAAK,KAAK,GAAG,QAAQ,CAAC;IACpB,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IAEd,oCAAoC;IACpC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAE9B,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAElB,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAAC;AAEH,iCAAiC;AACjC,KAAK,WAAW,GAAG,QAAQ,CAAC;IAC1B,kBAAkB;IAClB,OAAO,EAAE,WAAW,CAAC;IAErB,sBAAsB;IACtB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC,CAAC;AAEH,+CAA+C;AAC/C,KAAK,mBAAmB,GAAG,QAAQ,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAAC;AAEH,2CAA2C;AAC3C,KAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC/B,CAAC,CAAC;AAEH,YAAY,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,WAAW,EACX,UAAU,EACV,mBAAmB,GACpB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/foundry.lock ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "../contracts/lib/forge-std": {
3
+ "rev": "0844d7e1fc5e60d77b68e469bff60265f236c398"
4
+ },
5
+ "lib/forge-std": {
6
+ "tag": {
7
+ "name": "v1.15.0",
8
+ "rev": "0844d7e1fc5e60d77b68e469bff60265f236c398"
9
+ }
10
+ }
11
+ }
package/foundry.toml ADDED
@@ -0,0 +1,16 @@
1
+ [profile.default]
2
+ src = "build"
3
+ out = "out"
4
+ libs = ["lib"]
5
+ solc_version = "0.8.28"
6
+ optimizer = true
7
+ optimizer_runs = 200
8
+ via_ir = false
9
+
10
+ [rpc_endpoints]
11
+ monad_testnet = "https://testnet-rpc.monad.xyz"
12
+ base_sepolia = "https://sepolia.base.org"
13
+
14
+ [etherscan]
15
+ monad_testnet = { key = "${ETHERSCAN_API_KEY}", chain = 10143 }
16
+ base_sepolia = { key = "${ETHERSCAN_API_KEY}", chain = 84532 }
@@ -0,0 +1 @@
1
+ src/Vm.sol linguist-generated
@@ -0,0 +1 @@
1
+ * @danipopes @mattsse @grandizzy @zerosnacks @onbjerg @0xrusowsky
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -0,0 +1,161 @@
1
+ name: CI
2
+
3
+ permissions: {}
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ pull_request:
8
+ push:
9
+ branches:
10
+ - master
11
+
12
+ env:
13
+ SOLC_MINIMUM: "0.8.13"
14
+ SOLC_LATEST: "0.8.34"
15
+ SOLC_PRERELEASE: "0.8.35-pre.1"
16
+
17
+ jobs:
18
+ build-matrix:
19
+ runs-on: ubuntu-latest
20
+ timeout-minutes: 5
21
+ permissions:
22
+ contents: read
23
+ outputs:
24
+ matrix: ${{ steps.generate.outputs.matrix }}
25
+ steps:
26
+ - id: generate
27
+ run: |
28
+ MINIMUM="${{ env.SOLC_MINIMUM }}"
29
+ LATEST="${{ env.SOLC_LATEST }}"
30
+ PRERELEASE="${{ env.SOLC_PRERELEASE }}"
31
+ matrix='{"include":['
32
+ for toolchain in stable nightly; do
33
+ for flags in \
34
+ "" \
35
+ "--via-ir" \
36
+ "--use solc:${LATEST}" \
37
+ "--use solc:${LATEST} --via-ir" \
38
+ "--use solc:${MINIMUM}" \
39
+ "--use solc:${MINIMUM} --via-ir"
40
+ do
41
+ matrix+='{"toolchain":"'"$toolchain"'","flags":"'"$flags"'","prerelease":false},'
42
+ done
43
+ done
44
+ # prerelease (nightly only, svm-rs is not up to date on stable)
45
+ for flags in \
46
+ "--use solc:${PRERELEASE}" \
47
+ "--use solc:${PRERELEASE} --via-ir"
48
+ do
49
+ matrix+='{"toolchain":"nightly","flags":"'"$flags"'","prerelease":true},'
50
+ done
51
+ matrix="${matrix%,}]}"
52
+ echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
53
+
54
+ build:
55
+ needs: build-matrix
56
+ name: build +${{ matrix.toolchain }} ${{ matrix.flags }}
57
+ runs-on: ubuntu-latest
58
+ timeout-minutes: 10
59
+ permissions:
60
+ contents: read
61
+ strategy:
62
+ fail-fast: false
63
+ matrix: ${{ fromJSON(needs.build-matrix.outputs.matrix) }}
64
+ steps:
65
+ - uses: actions/checkout@v6
66
+ with:
67
+ persist-credentials: false
68
+ - uses: foundry-rs/foundry-toolchain@v1
69
+ with:
70
+ version: ${{ matrix.toolchain }}
71
+ - run: forge --version
72
+ # 3805: "This is a pre-release compiler version, please do not use it in production."
73
+ - run: forge build -vvvvv --skip test --deny warnings ${{ matrix.prerelease && '--ignored-error-codes 3805' || '' }} ${{ matrix.flags }} --contracts 'test/compilation/*'
74
+
75
+ test:
76
+ runs-on: ubuntu-latest
77
+ timeout-minutes: 10
78
+ permissions:
79
+ contents: read
80
+ strategy:
81
+ fail-fast: false
82
+ matrix:
83
+ toolchain: [stable, nightly]
84
+ steps:
85
+ - uses: actions/checkout@v6
86
+ with:
87
+ persist-credentials: false
88
+ - uses: foundry-rs/foundry-toolchain@v1
89
+ with:
90
+ version: ${{ matrix.toolchain }}
91
+ - run: forge --version
92
+ - run: forge test -vvv
93
+
94
+ fmt:
95
+ runs-on: ubuntu-latest
96
+ timeout-minutes: 10
97
+ permissions:
98
+ contents: read
99
+ steps:
100
+ - uses: actions/checkout@v6
101
+ with:
102
+ persist-credentials: false
103
+ - uses: foundry-rs/foundry-toolchain@v1
104
+ - run: forge --version
105
+ - run: forge fmt --check
106
+
107
+ typos:
108
+ runs-on: ubuntu-latest
109
+ timeout-minutes: 10
110
+ permissions:
111
+ contents: read
112
+ steps:
113
+ - uses: actions/checkout@v6
114
+ with:
115
+ persist-credentials: false
116
+ - uses: crate-ci/typos@02ea592e44b3a53c302f697cddca7641cd051c3d # v1
117
+
118
+ codeql:
119
+ name: Analyze (${{ matrix.language }})
120
+ runs-on: ubuntu-latest
121
+ permissions:
122
+ security-events: write
123
+ actions: read
124
+ contents: read
125
+ strategy:
126
+ fail-fast: false
127
+ matrix:
128
+ include:
129
+ - language: actions
130
+ build-mode: none
131
+ steps:
132
+ - name: Checkout repository
133
+ uses: actions/checkout@v6
134
+ with:
135
+ persist-credentials: false
136
+ - name: Initialize CodeQL
137
+ uses: github/codeql-action/init@v4
138
+ with:
139
+ languages: ${{ matrix.language }}
140
+ build-mode: ${{ matrix.build-mode }}
141
+ - name: Perform CodeQL Analysis
142
+ uses: github/codeql-action/analyze@v4
143
+ with:
144
+ category: "/language:${{matrix.language}}"
145
+
146
+ ci-success:
147
+ runs-on: ubuntu-latest
148
+ if: always()
149
+ needs:
150
+ - build-matrix
151
+ - build
152
+ - test
153
+ - fmt
154
+ - typos
155
+ - codeql
156
+ timeout-minutes: 10
157
+ steps:
158
+ - name: Decide whether the needed jobs succeeded or failed
159
+ uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # release/v1
160
+ with:
161
+ jobs: ${{ toJSON(needs) }}
@@ -0,0 +1,36 @@
1
+ name: Sync Release Branch
2
+
3
+ permissions: {}
4
+
5
+ on:
6
+ release:
7
+ types:
8
+ - created
9
+
10
+ jobs:
11
+ sync-release-branch:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: write
15
+ if: startsWith(github.event.release.tag_name, 'v1')
16
+ steps:
17
+ - name: Check out the repo
18
+ uses: actions/checkout@v6
19
+ with:
20
+ persist-credentials: true
21
+ fetch-depth: 0
22
+ ref: v1
23
+
24
+ # The email is derived from the bots user id,
25
+ # found here: https://api.github.com/users/github-actions%5Bbot%5D
26
+ - name: Configure Git
27
+ run: |
28
+ git config user.name github-actions[bot]
29
+ git config user.email 41898282+github-actions[bot]@users.noreply.github.com
30
+
31
+ - name: Sync Release Branch
32
+ run: |
33
+ git fetch --tags
34
+ git checkout v1
35
+ git reset --hard ${GITHUB_REF}
36
+ git push --force
@@ -0,0 +1,193 @@
1
+ ## Contributing to Foundry
2
+
3
+ Thanks for your interest in improving Foundry!
4
+
5
+ There are multiple opportunities to contribute at any level. It doesn't matter if you are just getting started with Rust or are the most weathered expert, we can use your help.
6
+
7
+ This document will help you get started. **Do not let the document intimidate you**.
8
+ It should be considered as a guide to help you navigate the process.
9
+
10
+ The [dev Telegram][dev-tg] is available for any concerns you may have that are not covered in this guide.
11
+
12
+ ### Code of Conduct
13
+
14
+ The Foundry project adheres to the [Rust Code of Conduct][rust-coc]. This code of conduct describes the _minimum_ behavior expected from all contributors.
15
+
16
+ Instances of violations of the Code of Conduct can be reported by contacting the team at [me@gakonst.com](mailto:me@gakonst.com).
17
+
18
+ ### Ways to contribute
19
+
20
+ There are fundamentally four ways an individual can contribute:
21
+
22
+ 1. **By opening an issue:** For example, if you believe that you have uncovered a bug
23
+ in Foundry, creating a new issue in the issue tracker is the way to report it.
24
+ 2. **By adding context:** Providing additional context to existing issues,
25
+ such as screenshots and code snippets, which help resolve issues.
26
+ 3. **By resolving issues:** Typically this is done in the form of either
27
+ demonstrating that the issue reported is not a problem after all, or more often,
28
+ by opening a pull request that fixes the underlying problem, in a concrete and
29
+ reviewable manner.
30
+
31
+ **Anybody can participate in any stage of contribution**. We urge you to participate in the discussion
32
+ around bugs and participate in reviewing PRs.
33
+
34
+ ### Contributions Related to Spelling and Grammar
35
+
36
+ At this time, we will not be accepting contributions that only fix spelling or grammatical errors in documentation, code or
37
+ elsewhere.
38
+
39
+ ### Asking for help
40
+
41
+ If you have reviewed existing documentation and still have questions, or you are having problems, you can get help in the following ways:
42
+
43
+ - **Asking in the support Telegram:** The [Foundry Support Telegram][support-tg] is a fast and easy way to ask questions.
44
+ - **Opening a discussion:** This repository comes with a discussions board where you can also ask for help. Click the "Discussions" tab at the top.
45
+
46
+ As Foundry is still in heavy development, the documentation can be a bit scattered.
47
+ The [Foundry Book][foundry-book] is our current best-effort attempt at keeping up-to-date information.
48
+
49
+ ### Submitting a bug report
50
+
51
+ When filing a new bug report in the issue tracker, you will be presented with a basic form to fill out.
52
+
53
+ If you believe that you have uncovered a bug, please fill out the form to the best of your ability. Do not worry if you cannot answer every detail; just fill in what you can. Contributors will ask follow-up questions if something is unclear.
54
+
55
+ The most important pieces of information we need in a bug report are:
56
+
57
+ - The Foundry version you are on (and that it is up to date)
58
+ - The platform you are on (Windows, macOS, an M1 Mac or Linux)
59
+ - Code snippets if this is happening in relation to testing or building code
60
+ - Concrete steps to reproduce the bug
61
+
62
+ In order to rule out the possibility of the bug being in your project, the code snippets should be as minimal
63
+ as possible. It is better if you can reproduce the bug with a small snippet as opposed to an entire project!
64
+
65
+ See [this guide][mcve] on how to create a minimal, complete, and verifiable example.
66
+
67
+ ### Submitting a feature request
68
+
69
+ When adding a feature request in the issue tracker, you will be presented with a basic form to fill out.
70
+
71
+ Please include as detailed of an explanation as possible of the feature you would like, adding additional context if necessary.
72
+
73
+ If you have examples of other tools that have the feature you are requesting, please include them as well.
74
+
75
+ ### Resolving an issue
76
+
77
+ Pull requests are the way concrete changes are made to the code, documentation, and dependencies of Foundry.
78
+
79
+ Even minor pull requests, such as those fixing wording, are greatly appreciated. Before making a large change, it is usually
80
+ a good idea to first open an issue describing the change to solicit feedback and guidance. This will increase
81
+ the likelihood of the PR getting merged.
82
+
83
+ Please make sure that the following commands pass if you have changed the code:
84
+
85
+ ```sh
86
+ forge fmt --check
87
+ forge test -vvv
88
+ ```
89
+
90
+ To make sure your changes are compatible with all compiler version targets, run the following commands:
91
+
92
+ ```sh
93
+ forge build --skip test --use solc:0.6.2
94
+ forge build --skip test --use solc:0.6.12
95
+ forge build --skip test --use solc:0.7.0
96
+ forge build --skip test --use solc:0.7.6
97
+ forge build --skip test --use solc:0.8.0
98
+ ```
99
+
100
+ The CI will also ensure that the code is formatted correctly and that the tests are passing across all compiler version targets.
101
+
102
+ #### Adding cheatcodes
103
+
104
+ Please follow the guide outlined in the [cheatcodes](https://github.com/foundry-rs/foundry/blob/master/docs/dev/cheatcodes.md#adding-a-new-cheatcode) documentation of Foundry.
105
+
106
+ When making modifications to the native cheatcodes or adding new ones, please make sure to run [`./scripts/vm.py`](./scripts/vm.py) to update the cheatcodes in the [`src/Vm.sol`](./src/Vm.sol) file.
107
+
108
+ By default the script will automatically generate the cheatcodes from the [`cheatcodes.json`](https://raw.githubusercontent.com/foundry-rs/foundry/master/crates/cheatcodes/assets/cheatcodes.json) file but alternatively you can provide a path to a JSON file containing the Vm interface, as generated by Foundry, with the `--from` flag.
109
+
110
+ ```sh
111
+ ./scripts/vm.py --from path/to/cheatcodes.json
112
+ ```
113
+
114
+ It is possible that the resulting [`src/Vm.sol`](./src/Vm.sol) file will have some changes that are not directly related to your changes, this is not a problem.
115
+
116
+ #### Commits
117
+
118
+ It is a recommended best practice to keep your changes as logically grouped as possible within individual commits. There is no limit to the number of commits any single pull request may have, and many contributors find it easier to review changes that are split across multiple commits.
119
+
120
+ That said, if you have a number of commits that are "checkpoints" and don't represent a single logical change, please squash those together.
121
+
122
+ #### Opening the pull request
123
+
124
+ From within GitHub, opening a new pull request will present you with a template that should be filled out. Please try your best at filling out the details, but feel free to skip parts if you're not sure what to put.
125
+
126
+ #### Discuss and update
127
+
128
+ You will probably get feedback or requests for changes to your pull request.
129
+ This is a big part of the submission process, so don't be discouraged! Some contributors may sign off on the pull request right away, others may have more detailed comments or feedback.
130
+ This is a necessary part of the process in order to evaluate whether the changes are correct and necessary.
131
+
132
+ **Any community member can review a PR, so you might get conflicting feedback**.
133
+ Keep an eye out for comments from code owners to provide guidance on conflicting feedback.
134
+
135
+ #### Reviewing pull requests
136
+
137
+ **Any Foundry community member is welcome to review any pull request**.
138
+
139
+ All contributors who choose to review and provide feedback on pull requests have a responsibility to both the project and individual making the contribution. Reviews and feedback must be helpful, insightful, and geared towards improving the contribution as opposed to simply blocking it. If there are reasons why you feel the PR should not be merged, explain what those are. Do not expect to be able to block a PR from advancing simply because you say "no" without giving an explanation. Be open to having your mind changed. Be open to working _with_ the contributor to make the pull request better.
140
+
141
+ Reviews that are dismissive or disrespectful of the contributor or any other reviewers are strictly counter to the Code of Conduct.
142
+
143
+ When reviewing a pull request, the primary goals are for the codebase to improve and for the person submitting the request to succeed. **Even if a pull request is not merged, the submitter should come away from the experience feeling like their effort was appreciated**. Every PR from a new contributor is an opportunity to grow the community.
144
+
145
+ ##### Review a bit at a time
146
+
147
+ Do not overwhelm new contributors.
148
+
149
+ It is tempting to micro-optimize and make everything about relative performance, perfect grammar, or exact style matches. Do not succumb to that temptation.
150
+
151
+ Focus first on the most significant aspects of the change:
152
+
153
+ 1. Does this change make sense for Foundry?
154
+ 2. Does this change make Foundry better, even if only incrementally?
155
+ 3. Are there clear bugs or larger scale issues that need attending?
156
+ 4. Are the commit messages readable and correct? If it contains a breaking change, is it clear enough?
157
+
158
+ Note that only **incremental** improvement is needed to land a PR. This means that the PR does not need to be perfect, only better than the status quo. Follow-up PRs may be opened to continue iterating.
159
+
160
+ When changes are necessary, _request_ them, do not _demand_ them, and **do not assume that the submitter already knows how to add a test or run a benchmark**.
161
+
162
+ Specific performance optimization techniques, coding styles and conventions change over time. The first impression you give to a new contributor never does.
163
+
164
+ Nits (requests for small changes that are not essential) are fine, but try to avoid stalling the pull request. Most nits can typically be fixed by the Foundry maintainers merging the pull request, but they can also be an opportunity for the contributor to learn a bit more about the project.
165
+
166
+ It is always good to clearly indicate nits when you comment, e.g.: `Nit: change foo() to bar(). But this is not blocking`.
167
+
168
+ If your comments were addressed but were not folded after new commits, or if they proved to be mistaken, please, [hide them][hiding-a-comment] with the appropriate reason to keep the conversation flow concise and relevant.
169
+
170
+ ##### Be aware of the person behind the code
171
+
172
+ Be aware that _how_ you communicate requests and reviews in your feedback can have a significant impact on the success of the pull request. Yes, we may merge a particular change that makes Foundry better, but the individual might just not want to have anything to do with Foundry ever again. The goal is not just having good code.
173
+
174
+ ##### Abandoned or stale pull requests
175
+
176
+ If a pull request appears to be abandoned or stalled, it is polite to first check with the contributor to see if they intend to continue the work before checking if they would mind if you took it over (especially if it just has nits left). When doing so, it is courteous to give the original contributor credit for the work they started, either by preserving their name and e-mail address in the commit log, or by using the `Author: ` or `Co-authored-by: ` metadata tag in the commits.
177
+
178
+ _Adapted from the [ethers-rs contributing guide](https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md)_.
179
+
180
+ ### Releasing
181
+
182
+ Releases are automatically done by the release workflow when a tag is pushed, however, these steps still need to be taken:
183
+
184
+ 1. Ensure that the versions in the relevant `Cargo.toml` files are up-to-date.
185
+ 2. Update documentation links
186
+ 3. Perform a final audit for breaking changes.
187
+
188
+ [rust-coc]: https://github.com/rust-lang/rust/blob/master/CODE_OF_CONDUCT.md
189
+ [dev-tg]: https://t.me/foundry_rs
190
+ [foundry-book]: https://github.com/foundry-rs/foundry-book
191
+ [support-tg]: https://t.me/foundry_support
192
+ [mcve]: https://stackoverflow.com/help/mcve
193
+ [hiding-a-comment]: https://help.github.com/articles/managing-disruptive-comments/#hiding-a-comment