Repository navigation
Feat/BASE BUILDER CODE addition #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d5ebee
BASE_BUILDER_CODE_SUFFIX for fillOTC tx
Velenir 3b379ac
ethers/apply dataSuffix
Velenir b2cc1f9
web3/apply dataSuffix
Velenir 73dc0ce
inline BASE_BUILDER_CODE_SUFFIX
Velenir e7dbe58
tests for dataSuffix
Velenir e7dbafc
lint fix
Velenir 5bba62f
Release 11.0.1
Velenir 6566d9d
test:more generic suffic test
Velenir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import replace from '@rollup/plugin-replace'; | ||
| import { config as loadEnv } from 'dotenv'; | ||
| import type { DtsConfig } from 'dts-cli/dist/types'; | ||
|
|
||
| loadEnv(); | ||
|
|
||
| const code = process.env.BASE_BUILDER_CODE || ''; | ||
| if (code && (code.length > 255 || !/^[\x21-\x2b\x2d-\x7e]+$/.test(code))) { | ||
| throw new Error( | ||
| 'BASE_BUILDER_CODE must be 1-255 printable ASCII bytes without commas' | ||
| ); | ||
| } | ||
| const suffix = code | ||
| ? `0x${Buffer.from(code, 'ascii').toString('hex')}${code.length | ||
| .toString(16) | ||
| .padStart(2, '0')}0080218021802180218021802180218021` | ||
| : ''; | ||
|
|
||
| const config: DtsConfig = { | ||
| rollup(config) { | ||
| return { | ||
| ...config, | ||
| plugins: [ | ||
| replace({ | ||
| 'process.env.BASE_BUILDER_CODE_SUFFIX': JSON.stringify(suffix), | ||
| preventAssignment: true, | ||
| }), | ||
| ...(Array.isArray(config.plugins) ? config.plugins : []), | ||
| ], | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const BASE_BUILDER_CODE_SUFFIX = process.env.BASE_BUILDER_CODE_SUFFIX as | ||
| | `0x${string}` | ||
| | ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import type { Signer as EthersV5Signer } from '@ethersproject/abstract-signer'; | ||
| import type { ContractRunner, Signer as EthersV6Signer } from 'ethers'; | ||
| import { bytesToHex } from 'viem'; | ||
|
|
||
| export type WithDataSuffixInput<T> = { signer: T; suffix?: string }; | ||
|
|
||
| export function withEthersV5DataSuffix({ | ||
| signer, | ||
| suffix, | ||
| }: WithDataSuffixInput<EthersV5Signer>): EthersV5Signer { | ||
| if (!suffix) return signer; | ||
| return { | ||
| _isSigner: true, | ||
| provider: signer.provider, | ||
| getAddress: signer.getAddress.bind(signer), | ||
| signMessage: signer.signMessage.bind(signer), | ||
| signTransaction: signer.signTransaction.bind(signer), | ||
| getBalance: signer.getBalance.bind(signer), | ||
| getTransactionCount: signer.getTransactionCount.bind(signer), | ||
| estimateGas: signer.estimateGas.bind(signer), | ||
| call: signer.call.bind(signer), | ||
| getChainId: signer.getChainId.bind(signer), | ||
| getGasPrice: signer.getGasPrice.bind(signer), | ||
| getFeeData: signer.getFeeData.bind(signer), | ||
| resolveName: signer.resolveName.bind(signer), | ||
| checkTransaction: signer.checkTransaction.bind(signer), | ||
| populateTransaction: signer.populateTransaction.bind(signer), | ||
| _checkProvider: signer._checkProvider.bind(signer), | ||
| connect: (provider) => | ||
| withEthersV5DataSuffix({ signer: signer.connect(provider), suffix }), | ||
| // Contract retains its receipt decoding; the signer receives final calldata. | ||
| sendTransaction: async (tx) => | ||
| signer.sendTransaction({ | ||
| ...tx, | ||
| data: appendSuffix(await tx.data, suffix), | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| export function withEthersV6DataSuffix({ | ||
| signer, | ||
| suffix, | ||
| }: WithDataSuffixInput<EthersV6Signer>): ContractRunner { | ||
| if (!suffix) return signer; | ||
| return { | ||
| provider: signer.provider, | ||
| resolveName: signer.resolveName.bind(signer), | ||
| sendTransaction: (tx) => | ||
| signer.sendTransaction({ | ||
| ...tx, | ||
| data: appendSuffix(tx.data, suffix), | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| function appendSuffix( | ||
| data: string | ArrayLike<number> | null | undefined, | ||
| suffix: string | ||
| ): string { | ||
| const hex = | ||
| typeof data === 'string' | ||
| ? data | ||
| : data | ||
| ? bytesToHex(Uint8Array.from(data)) | ||
| : '0x'; | ||
| return `${hex}${suffix.slice(2)}`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.