Skip to content

Commit 7d1af93

Browse files
committed
first commit
0 parents  commit 7d1af93

73 files changed

Lines changed: 28790 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
bench
25+
dist
26+
cache
27+
node_modules
28+
tsconfig*.tsbuildinfo
29+
*.tgz
30+
vitest.config.ts.timestamp*

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 opstack-kit
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

biome.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.0.0/schema.json",
3+
"organizeImports": {
4+
"enabled": false
5+
},
6+
"files": {
7+
"ignore": [
8+
"**/node_modules",
9+
"CHANGELOG.md",
10+
"cache",
11+
"coverage",
12+
"dist",
13+
"tsconfig.json",
14+
"tsconfig.*.json",
15+
"generated.ts",
16+
"pnpm-lock.yaml",
17+
"bench"
18+
]
19+
},
20+
"linter": {
21+
"enabled": true,
22+
"rules": {
23+
"recommended": true,
24+
"a11y": {
25+
"useButtonType": "off"
26+
},
27+
"correctness": {
28+
"noUnusedVariables": "error"
29+
},
30+
"performance": {
31+
"noDelete": "off"
32+
},
33+
"style": {
34+
"noNonNullAssertion": "off",
35+
"useShorthandArrayType": "error"
36+
},
37+
"suspicious": {
38+
"noArrayIndexKey": "off",
39+
"noAssignInExpressions": "off",
40+
"noExplicitAny": "off"
41+
}
42+
}
43+
},
44+
"formatter": {
45+
"enabled": false
46+
}
47+
}

package.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"name": "test-opstack-kit-x-alpha-v2",
3+
"version": "1.3.0",
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/opstack-kit/opstack-kit-x-alpha.git"
7+
},
8+
"type": "module",
9+
"main": "./dist/cjs/index.js",
10+
"module": "./dist/esm/index.js",
11+
"types": "./dist/types/index.d.ts",
12+
"typings": "./dist/types/index.d.ts",
13+
"sideEffects": false,
14+
"license": "MIT",
15+
"files": [
16+
"dist",
17+
"!dist/**/*.tsbuildinfo",
18+
"src/**/*.ts",
19+
"!src/**/*.test.ts",
20+
"!src/**/*.test-d.ts",
21+
"!src/**/*.bench.ts",
22+
"!src/_test/**/*"
23+
],
24+
"exports": {
25+
".": {
26+
"types": "./dist/types/index.d.ts",
27+
"import": "./dist/esm/index.js",
28+
"default": "./dist/cjs/index.js"
29+
},
30+
"./actions": {
31+
"types": "./dist/types/actions/index.d.ts",
32+
"import": "./dist/esm/actions/index.js",
33+
"default": "./dist/cjs/actions/index.js"
34+
},
35+
"./chains": {
36+
"types": "./dist/types/chains/index.d.ts",
37+
"import": "./dist/esm/chains/index.js",
38+
"default": "./dist/cjs/chains/index.js"
39+
},
40+
"./utils": {
41+
"types": "./dist/types/utils/index.d.ts",
42+
"import": "./dist/esm/utils/index.js",
43+
"default": "./dist/cjs/utils/index.js"
44+
},
45+
"./package.json": "./package.json"
46+
},
47+
"typesVersions": {
48+
"*": {
49+
"actions": [
50+
"./dist/types/actions/index.d.ts"
51+
],
52+
"chains": [
53+
"./dist/types/chains/index.d.ts"
54+
],
55+
"utils": [
56+
"./dist/types/utils/index.d.ts"
57+
]
58+
}
59+
},
60+
"devDependencies": {
61+
"@biomejs/biome": "1.0.0",
62+
"@changesets/changelog-github": "^0.4.8",
63+
"@changesets/cli": "^2.26.2",
64+
"@eth-optimism/core-utils": "^0.12.3",
65+
"@eth-optimism/sdk": "^3.1.2",
66+
"@testing-library/react": "^13.3.0",
67+
"@testing-library/react-hooks": "^8.0.1",
68+
"@types/react": "^18.0.9",
69+
"@types/react-dom": "^18.0.3",
70+
"@types/use-sync-external-store": "^0.0.3",
71+
"@viem/anvil": "^0.0.6",
72+
"@vitest/coverage-v8": "^1.2.2",
73+
"@wagmi/cli": "^1.3.0",
74+
"dprint": "^0.40.2",
75+
"ethers": "^5.7.0",
76+
"react": "^18.1.0",
77+
"react-dom": "^18.1.0",
78+
"rimraf": "^5.0.1",
79+
"simple-git-hooks": "^2.9.0",
80+
"typescript": "5.0.4",
81+
"test-use-viem": "^2.7.14",
82+
"vitest": "^2.0.4",
83+
"wagmi": "^2.x"
84+
},
85+
"scripts": {
86+
"build": "yarn run clean && yarn run build:cjs && yarn run build:esm && yarn run build:types",
87+
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
88+
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json \"{\\\"type\\\":\\\"module\\\",\\\"sideEffects\\\":false}\"",
89+
"build:types": "tsc --project tsconfig.build.json --module esnext --outDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
90+
"release:check": "changeset status --verbose --since=origin/main",
91+
"release:publish": "yarn install && yarn build && changeset publish",
92+
"release:version": "changeset version && yarn install --lockfile-only",
93+
"clean": "rimraf dist"
94+
},
95+
"dependencies": {
96+
"@eth-optimism/contracts-ts": "^0.15.0",
97+
"viem": "^2.0.0"
98+
},
99+
"peerDependenciesMeta": {
100+
"typescript": {
101+
"optional": true
102+
}
103+
},
104+
"yarn": {
105+
"overrides": {
106+
"opstack-kit-x-alpha": "workspace:*"
107+
}
108+
}
109+
}

src/actions/index.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
export { type AccountProof, getProof, type GetProofParameters, type StorageProof } from './public/getProof.js'
2+
3+
// Public L1 actions
4+
export {
5+
getL2HashesForDepositTx,
6+
type GetL2HashesForDepositTxParamters,
7+
type GetL2HashesForDepositTxReturnType,
8+
} from './public/L1/getL2HashesForDepositTx.js'
9+
export {
10+
getLatestProposedL2BlockNumber,
11+
type GetLatestProposedL2BlockNumberParameters,
12+
type GetLatestProposedL2BlockNumberReturnType,
13+
} from './public/L1/getLatestProposedL2BlockNumber.js'
14+
export {
15+
getOutputForL2Block,
16+
type GetOutputForL2BlockParameters,
17+
type GetOutputForL2BlockReturnType,
18+
type Proposal,
19+
} from './public/L1/getOutputForL2Block.js'
20+
export { getSecondsToFinalizable, type GetSecondsToFinalizableParameters } from './public/L1/getSecondsToFinalizable.js'
21+
export {
22+
getSecondsToNextL2Output,
23+
type GetSecondsToNextL2OutputParameters,
24+
} from './public/L1/getSecondsToNextL2Output.js'
25+
export {
26+
readFinalizedWithdrawals,
27+
type ReadFinalizedWithdrawalsParameters,
28+
} from './public/L1/readFinalizedWithdrawals.js'
29+
export { readProvenWithdrawals, type ReadProvenWithdrawalsParameters } from './public/L1/readProvenWithdrawals.js'
30+
export {
31+
simulateDepositERC20,
32+
type SimulateDepositERC20Parameters,
33+
type SimulateDepositERC20ReturnType,
34+
} from './public/L1/simulateDepositERC20.js'
35+
//
36+
export {
37+
simulateDepositCustomGas,
38+
type SimulateDepositCustomGasParameters,
39+
type SimulateDepositCustomGasReturnType,
40+
} from './public/L1/simulateDepositCustomGas.js'
41+
//
42+
export {
43+
simulateDepositETH,
44+
type SimulateDepositETHParameters,
45+
type SimulateDepositETHReturnType,
46+
} from './public/L1/simulateDepositETH.js'
47+
export {
48+
simulateDepositTransaction,
49+
type SimulateDepositTransactionParameters,
50+
type SimulateDepositTransactionReturnType,
51+
} from './public/L1/simulateDepositTransaction.js'
52+
export {
53+
simulateFinalizeWithdrawalTransaction,
54+
type SimulateFinalizeWithdrawalTransactionParameters,
55+
type SimulateFinalizeWithdrawalTransactionReturnType,
56+
} from './public/L1/simulateFinalizeWithdrawalTransaction.js'
57+
export {
58+
simulateProveWithdrawalTransaction,
59+
type SimulateProveWithdrawalTransactionParameters,
60+
type SimulateProveWithdrawalTransactionReturnType,
61+
} from './public/L1/simulateProveWithdrawalTransaction.js'
62+
63+
// Public L2 actions
64+
export { estimateFees, type EstimateFeesParameters } from './public/L2/estimateFees.js'
65+
export { estimateL1Fee, type EstimateL1FeeParameters } from './public/L2/estimateL1Fee.js'
66+
export { estimateL1GasUsed, type EstimateL1GasUsedParameters } from './public/L2/estimateL1GasUsed.js'
67+
export {
68+
getProveWithdrawalTransactionArgs,
69+
type GetProveWithdrawalTransactionArgsParams,
70+
type GetProveWithdrawalTransactionArgsReturnType,
71+
type OutputRootProof,
72+
} from './public/L2/getProveWithdrawalTransactionArgs.js'
73+
export {
74+
getWithdrawalMessages,
75+
type GetWithdrawalMessagesParameters,
76+
type GetWithdrawalMessagesReturnType,
77+
} from './public/L2/getWithdrawalMessages.js'
78+
export {
79+
simulateWithdrawERC20,
80+
type SimulateWithdrawERC20Parameters,
81+
type SimulateWithdrawERC20ReturnType,
82+
} from './public/L2/simulateWithdrawERC20.js'
83+
//
84+
export {
85+
simulateInitiateWithdrawal,
86+
type SimulateWithdrawInitiateParameters,
87+
type SimulateWithdrawInitiateReturnType,
88+
} from './public/L2/simulateInitiateWithdrawal.js'
89+
//
90+
export {
91+
simulateWithdrawETH,
92+
type SimulateWithdrawETHParameters,
93+
type SimulateWithdrawETHReturnType,
94+
} from './public/L2/simulateWithdrawETH.js'
95+
96+
// Wallet L1 actions
97+
export { writeContractDeposit, type WriteContractDepositParameters } from './wallet/L1/writeContractDeposit.js'
98+
export { writeDepositERC20, type WriteDepositERC20Parameters } from './wallet/L1/writeDepositERC20.js'
99+
//
100+
export { writeDepositCustomGas, type WriteDepositCustomGasParameters } from './wallet/L1/writeDepositCustomGas.js'
101+
// export { writeDepositCustomGas, type WriteDepositERC20Parameters } from './wallet/L1/writeDepositCustomGas.js'
102+
//
103+
export { writeDepositETH, type WriteDepositETHParameters } from './wallet/L1/writeDepositETH.js'
104+
export {
105+
type DepositTransactionParameters,
106+
writeDepositTransaction,
107+
type WriteDepositTransactionParameters,
108+
} from './wallet/L1/writeDepositTransaction.js'
109+
export {
110+
writeFinalizeWithdrawalTranasction,
111+
type WriteFinalizeWithdrawalTransactionParameters,
112+
} from './wallet/L1/writeFinalizeWithdrawalTransaction.js'
113+
export {
114+
writeProveWithdrawalTransaction,
115+
type WriteProveWithdrawalTransactionParameters,
116+
} from './wallet/L1/writeProveWithdrawalTransaction.js'
117+
export {
118+
type SendMessageParameters,
119+
writeSendMessage,
120+
type WriteSendMessageParameters,
121+
} from './wallet/L1/writeSendMessage.js'
122+
123+
// Wallet l2 actions
124+
export { writeWithdrawERC20, type WriteWithdrawERC20Parameters } from './wallet/L2/writeWithdrawERC20.js'
125+
//
126+
export { writeInitiateWithdrawal, type WriteWithdrawInitiateParameters } from './wallet/L2/writeInitiateWithdrawal.js'
127+
//
128+
export { writeWithdrawETH, type WriteWithdrawETHParameters } from './wallet/L2/writeWithdrawETH.js'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Chain, Hash, PublicClient, TransactionReceipt, Transport } from 'viem'
2+
import { getTransactionReceipt } from 'viem/actions'
3+
import { getL2HashFromL1DepositInfo } from '../../../utils/getL2HashFromL1DepositInfo.js'
4+
import { getTransactionDepositedEvents } from '../../../utils/getTransactionDepositedEvents.js'
5+
6+
export type GetL2HashesForDepositTxParamters = {
7+
l1TxHash: Hash
8+
l1TxReceipt?: never
9+
} | { l1TxHash?: never; l1TxReceipt: TransactionReceipt }
10+
11+
export type GetL2HashesForDepositTxReturnType = Hash[]
12+
13+
/**
14+
* Gets the L2 transaction hashes for a given L1 deposit transaction
15+
*
16+
* @param {Hash} l1TxHash the L1 transaction hash of the deposit
17+
* @returns {GetL2HashesForDepositTxReturnType} the L2 transaction hashes for the deposit
18+
*/
19+
export async function getL2HashesForDepositTx<TChain extends Chain | undefined>(
20+
client: PublicClient<Transport, TChain>,
21+
{ l1TxHash, l1TxReceipt }: GetL2HashesForDepositTxParamters,
22+
): Promise<GetL2HashesForDepositTxReturnType> {
23+
const txReceipt = l1TxReceipt ?? await getTransactionReceipt(client, { hash: l1TxHash })
24+
const depositEvents = getTransactionDepositedEvents({ txReceipt })
25+
26+
return depositEvents.map(({ event, logIndex }) =>
27+
getL2HashFromL1DepositInfo({
28+
event,
29+
logIndex,
30+
blockHash: txReceipt.blockHash,
31+
})
32+
)
33+
}

0 commit comments

Comments
 (0)