Skip to content

Commit d75d5c4

Browse files
committed
first commit
0 parents  commit d75d5c4

67 files changed

Lines changed: 28361 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": "opstack-kit-x-alpha",
3+
"version": "1.0.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: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
export {
36+
simulateDepositETH,
37+
type SimulateDepositETHParameters,
38+
type SimulateDepositETHReturnType,
39+
} from './public/L1/simulateDepositETH.js'
40+
export {
41+
simulateDepositTransaction,
42+
type SimulateDepositTransactionParameters,
43+
type SimulateDepositTransactionReturnType,
44+
} from './public/L1/simulateDepositTransaction.js'
45+
export {
46+
simulateFinalizeWithdrawalTransaction,
47+
type SimulateFinalizeWithdrawalTransactionParameters,
48+
type SimulateFinalizeWithdrawalTransactionReturnType,
49+
} from './public/L1/simulateFinalizeWithdrawalTransaction.js'
50+
export {
51+
simulateProveWithdrawalTransaction,
52+
type SimulateProveWithdrawalTransactionParameters,
53+
type SimulateProveWithdrawalTransactionReturnType,
54+
} from './public/L1/simulateProveWithdrawalTransaction.js'
55+
56+
// Public L2 actions
57+
export { estimateFees, type EstimateFeesParameters } from './public/L2/estimateFees.js'
58+
export { estimateL1Fee, type EstimateL1FeeParameters } from './public/L2/estimateL1Fee.js'
59+
export { estimateL1GasUsed, type EstimateL1GasUsedParameters } from './public/L2/estimateL1GasUsed.js'
60+
export {
61+
getProveWithdrawalTransactionArgs,
62+
type GetProveWithdrawalTransactionArgsParams,
63+
type GetProveWithdrawalTransactionArgsReturnType,
64+
type OutputRootProof,
65+
} from './public/L2/getProveWithdrawalTransactionArgs.js'
66+
export {
67+
getWithdrawalMessages,
68+
type GetWithdrawalMessagesParameters,
69+
type GetWithdrawalMessagesReturnType,
70+
} from './public/L2/getWithdrawalMessages.js'
71+
export {
72+
simulateWithdrawERC20,
73+
type SimulateWithdrawERC20Parameters,
74+
type SimulateWithdrawERC20ReturnType,
75+
} from './public/L2/simulateWithdrawERC20.js'
76+
export {
77+
simulateWithdrawETH,
78+
type SimulateWithdrawETHParameters,
79+
type SimulateWithdrawETHReturnType,
80+
} from './public/L2/simulateWithdrawETH.js'
81+
82+
// Wallet L1 actions
83+
export { writeContractDeposit, type WriteContractDepositParameters } from './wallet/L1/writeContractDeposit.js'
84+
export { writeDepositERC20, type WriteDepositERC20Parameters } from './wallet/L1/writeDepositERC20.js'
85+
export { writeDepositETH, type WriteDepositETHParameters } from './wallet/L1/writeDepositETH.js'
86+
export {
87+
type DepositTransactionParameters,
88+
writeDepositTransaction,
89+
type WriteDepositTransactionParameters,
90+
} from './wallet/L1/writeDepositTransaction.js'
91+
export {
92+
writeFinalizeWithdrawalTranasction,
93+
type WriteFinalizeWithdrawalTransactionParameters,
94+
} from './wallet/L1/writeFinalizeWithdrawalTransaction.js'
95+
export {
96+
writeProveWithdrawalTransaction,
97+
type WriteProveWithdrawalTransactionParameters,
98+
} from './wallet/L1/writeProveWithdrawalTransaction.js'
99+
export {
100+
type SendMessageParameters,
101+
writeSendMessage,
102+
type WriteSendMessageParameters,
103+
} from './wallet/L1/writeSendMessage.js'
104+
105+
// Wallet l2 actions
106+
export { writeWithdrawERC20, type WriteWithdrawERC20Parameters } from './wallet/L2/writeWithdrawERC20.js'
107+
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { l2OutputOracleABI } from '../../../constants/abi.js'
2+
import type { Chain, PublicClient, Transport } from 'viem'
3+
import { readContract } from 'viem/actions'
4+
import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js'
5+
6+
export type GetLatestProposedL2BlockNumberParameters<
7+
TChain extends Chain | undefined = Chain | undefined,
8+
_chainId = TChain extends Chain ? TChain['id'] : number,
9+
> = { l2OutputOracle: RawOrContractAddress<_chainId> }
10+
11+
export type GetLatestProposedL2BlockNumberReturnType = {
12+
l2BlockNumber: bigint
13+
}
14+
15+
/**
16+
* Gets the latest proposed L2 block number from the L2 Output Oracle.
17+
*
18+
* @param {RawOrContractAddress} l2OutputOracle the address of the L2 Output Oracle
19+
* @returns {GetLatestProposedL2BlockNumberReturnType} the latest proposed L2 block number
20+
*/
21+
export async function getLatestProposedL2BlockNumber<TChain extends Chain | undefined>(
22+
client: PublicClient<Transport, TChain>,
23+
{
24+
l2OutputOracle,
25+
}: GetLatestProposedL2BlockNumberParameters<TChain>,
26+
): Promise<GetLatestProposedL2BlockNumberReturnType> {
27+
const resolvedAddress = resolveAddress(l2OutputOracle)
28+
29+
const l2BlockNumber = await readContract(client, {
30+
address: resolvedAddress,
31+
abi: l2OutputOracleABI,
32+
functionName: 'latestBlockNumber',
33+
})
34+
35+
return { l2BlockNumber }
36+
}

0 commit comments

Comments
 (0)