Skip to content
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

Or 1446 titan canyon upgrade sdk to supply portal deposit and passer withdrawal #116

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/tokamak/core-utils/src/optimism/deposit-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
hexConcat,
zeroPad,
} from '@ethersproject/bytes'
import { Log } from '@ethersproject/abstract-provider'

const formatBoolean = (value: boolean): Uint8Array => {
return value ? new Uint8Array([1]) : new Uint8Array([])
Expand Down Expand Up @@ -261,4 +262,50 @@ export class DepositTx {
static fromL1Event(event: Event): DepositTx {
return new this({}).fromL1Event(event)
}

fromL1Log(log: Log): DepositTx {
if (typeof log.topics[1] === 'undefined') {
throw new Error('"from" undefined')
}
this.from = log.topics[1].substring(26)

if (typeof log.topics[2] === 'undefined') {
throw new Error('"to" undefined')
}
this.to = log.topics[2].substring(26)

if (typeof log.topics[3] === 'undefined') {
throw new Error(`"verison" undefined`)
}
if (!BigNumber.from(log.topics[3]).eq(0)) {
throw new Error(`Unsupported version ${log.topics[2].substring(2)}`)
}

const opaqueData = log.data

let offset = BigNumber.from(hexDataSlice(opaqueData, 0, 32)).toNumber()
const metadataLength = BigNumber.from(hexDataSlice(opaqueData, offset, offset + 32)).toNumber()
offset += 32
this.mint = BigNumber.from(hexDataSlice(opaqueData, offset, offset + 32))
offset += 32
this.value = BigNumber.from(hexDataSlice(opaqueData, offset, offset + 32))
offset += 32
this.gas = BigNumber.from(hexDataSlice(opaqueData, offset, offset + 8))
offset += 8
// bypass isCreation
offset += 1

const length = (metadataLength + 64) - offset
this.isSystemTransaction = false
this.data = hexDataSlice(opaqueData, offset, offset + length)
this.domain = SourceHashDomain.UserDeposit
this.l1BlockHash = log.blockHash
this.logIndex = log.logIndex
this.sourceHash()
return this
}

static fromL1Log(log: Log): DepositTx {
return new this({}).fromL1Log(log)
}
}
1 change: 1 addition & 0 deletions packages/tokamak/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './interfaces'
export * from './utils'
export * from './cross-chain-messenger'
export * from './portals'
export * from './adapters'
export * from './l2-provider'
33 changes: 33 additions & 0 deletions packages/tokamak/sdk/src/interfaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,39 @@ export enum MessageDirection {
L1_TO_L2,
L2_TO_L1,
}
/**
* Deposit data
*/
export interface DepositTransactionRequest {
to: AddressLike
value: BigNumber
gasLimit: BigNumber
data: string
}

/**
* Withdrawal data
*/
export interface WithdrawalTransactionRequest {
target: AddressLike
value: BigNumber
gasLimit: BigNumber
data: string
}

/**
* Core components of a cross chain message.
*/
export interface WithdrawalMessageInfo {
sender: string
target: string
message: string
messageNonce: BigNumber
value: BigNumber
minGasLimit: BigNumber
withdrawalHash: string
l2BlockNumber: number
}

/**
* Partial message that needs to be signed and executed by a specific signer.
Expand Down
Loading
Loading