Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
f52fc61e
Unverified
Commit
f52fc61e
authored
Feb 08, 2022
by
smartcontracts
Committed by
GitHub
Feb 08, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2173 from ethereum-optimism/sc/sdk-remove-token-messages
feat(sdk): remove getTokenBridgeMessages function
parents
57c66bb9
5ffb5fcf
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
274 deletions
+11
-274
friendly-jobs-retire.md
.changeset/friendly-jobs-retire.md
+5
-0
standard-bridge.ts
packages/sdk/src/adapters/standard-bridge.ts
+0
-25
cross-chain-messenger.ts
packages/sdk/src/cross-chain-messenger.ts
+0
-17
bridge-adapter.ts
packages/sdk/src/interfaces/bridge-adapter.ts
+1
-24
cross-chain-messenger.ts
packages/sdk/src/interfaces/cross-chain-messenger.ts
+2
-22
cross-chain-messenger.spec.ts
packages/sdk/test/cross-chain-messenger.spec.ts
+3
-186
No files found.
.changeset/friendly-jobs-retire.md
0 → 100644
View file @
f52fc61e
---
'
@eth-optimism/sdk'
:
patch
---
Removes the getTokenBridgeMessagesByAddress function
packages/sdk/src/adapters/standard-bridge.ts
View file @
f52fc61e
...
...
@@ -52,31 +52,6 @@ export class StandardBridgeAdapter implements IBridgeAdapter {
)
}
public
async
getTokenBridgeMessagesByAddress
(
address
:
AddressLike
,
opts
?:
{
direction
?:
MessageDirection
}
):
Promise
<
TokenBridgeMessage
[]
>
{
let
messages
:
TokenBridgeMessage
[]
=
[]
if
(
opts
?.
direction
===
undefined
||
opts
?.
direction
===
MessageDirection
.
L1_TO_L2
)
{
messages
=
messages
.
concat
(
await
this
.
getDepositsByAddress
(
address
))
}
if
(
opts
?.
direction
===
undefined
||
opts
?.
direction
===
MessageDirection
.
L2_TO_L1
)
{
messages
=
messages
.
concat
(
await
this
.
getWithdrawalsByAddress
(
address
))
}
return
messages
}
public
async
getDepositsByAddress
(
address
:
AddressLike
,
opts
?:
{
...
...
packages/sdk/src/cross-chain-messenger.ts
View file @
f52fc61e
...
...
@@ -240,23 +240,6 @@ export class CrossChainMessenger implements ICrossChainMessenger {
return
bridges
[
0
]
}
public
async
getTokenBridgeMessagesByAddress
(
address
:
AddressLike
,
opts
:
{
direction
?:
MessageDirection
}
=
{}
):
Promise
<
TokenBridgeMessage
[]
>
{
return
(
await
Promise
.
all
(
Object
.
values
(
this
.
bridges
).
map
(
async
(
bridge
)
=>
{
return
bridge
.
getTokenBridgeMessagesByAddress
(
address
,
opts
)
})
)
).
reduce
((
acc
,
val
)
=>
{
return
acc
.
concat
(
val
)
},
[])
}
public
async
getDepositsByAddress
(
address
:
AddressLike
,
opts
:
{
...
...
packages/sdk/src/interfaces/bridge-adapter.ts
View file @
f52fc61e
...
...
@@ -5,12 +5,7 @@ import {
BlockTag
,
}
from
'
@ethersproject/abstract-provider
'
import
{
NumberLike
,
AddressLike
,
MessageDirection
,
TokenBridgeMessage
,
}
from
'
./types
'
import
{
NumberLike
,
AddressLike
,
TokenBridgeMessage
}
from
'
./types
'
import
{
ICrossChainMessenger
}
from
'
./cross-chain-messenger
'
/**
...
...
@@ -33,24 +28,6 @@ export interface IBridgeAdapter {
*/
l2Bridge
:
Contract
/**
* Finds all cross chain messages that correspond to token deposits or withdrawals sent by a
* particular address. Useful for finding deposits/withdrawals because the sender of the message
* will appear to be the StandardBridge contract and not the actual end user.
*
* @param address Address to search for messages from.
* @param opts Options object.
* @param opts.direction Direction to search for messages in. If not provided, will attempt to
* find all messages in both directions.
* @returns All token bridge messages sent by the given address.
*/
getTokenBridgeMessagesByAddress
(
address
:
AddressLike
,
opts
?:
{
direction
?:
MessageDirection
}
):
Promise
<
TokenBridgeMessage
[]
>
/**
* Gets all deposits for a given address.
*
...
...
packages/sdk/src/interfaces/cross-chain-messenger.ts
View file @
f52fc61e
...
...
@@ -139,27 +139,7 @@ export interface ICrossChainMessenger {
):
Promise
<
IBridgeAdapter
>
/**
* Finds all cross chain messages that correspond to token deposits or withdrawals sent by a
* particular address. Useful for finding deposits/withdrawals because the sender of the message
* will appear to be the StandardBridge contract and not the actual end user.
*
* @param address Address to search for messages from.
* @param opts Options object.
* @param opts.direction Direction to search for messages in. If not provided, will attempt to
* find all messages in both directions.
* @returns All token bridge messages sent by the given address.
*/
getTokenBridgeMessagesByAddress
(
address
:
AddressLike
,
opts
?:
{
direction
?:
MessageDirection
fromBlock
?:
BlockTag
toBlock
?:
BlockTag
}
):
Promise
<
TokenBridgeMessage
[]
>
/**
* Alias for getTokenBridgeMessagesByAddress with a drection of L1_TO_L2.
* Gets all deposits for a given address.
*
* @param address Address to search for messages from.
* @param opts Options object.
...
...
@@ -178,7 +158,7 @@ export interface ICrossChainMessenger {
):
Promise
<
TokenBridgeMessage
[]
>
/**
*
Alias for getTokenBridgeMessagesByAddress with a drection of L2_TO_L1
.
*
Gets all withdrawals for a given address
.
*
* @param address Address to search for messages from.
* @param opts Options object.
...
...
packages/sdk/test/cross-chain-messenger.spec.ts
View file @
f52fc61e
...
...
@@ -409,190 +409,6 @@ describe('CrossChainMessenger', () => {
})
})
describe
(
'
getTokenBridgeMessagesByAddress
'
,
()
=>
{
let
l1Bridge
:
Contract
let
l2Bridge
:
Contract
let
l1Messenger
:
Contract
let
l2Messenger
:
Contract
let
messenger
:
CrossChainMessenger
beforeEach
(
async
()
=>
{
l1Messenger
=
(
await
(
await
ethers
.
getContractFactory
(
'
MockMessenger
'
)
).
deploy
())
as
any
l2Messenger
=
(
await
(
await
ethers
.
getContractFactory
(
'
MockMessenger
'
)
).
deploy
())
as
any
l1Bridge
=
(
await
(
await
ethers
.
getContractFactory
(
'
MockBridge
'
)
).
deploy
(
l1Messenger
.
address
))
as
any
l2Bridge
=
(
await
(
await
ethers
.
getContractFactory
(
'
MockBridge
'
)
).
deploy
(
l2Messenger
.
address
))
as
any
messenger
=
new
CrossChainMessenger
({
l1SignerOrProvider
:
ethers
.
provider
,
l2SignerOrProvider
:
ethers
.
provider
,
l1ChainId
:
31337
,
contracts
:
{
l1
:
{
L1CrossDomainMessenger
:
l1Messenger
.
address
,
L1StandardBridge
:
l1Bridge
.
address
,
},
l2
:
{
L2CrossDomainMessenger
:
l2Messenger
.
address
,
L2StandardBridge
:
l2Bridge
.
address
,
},
},
bridges
:
{
Standard
:
{
Adapter
:
StandardBridgeAdapter
,
l1Bridge
:
l1Bridge
.
address
,
l2Bridge
:
l2Bridge
.
address
,
},
},
})
})
describe
(
'
when the address has made deposits or withdrawals
'
,
()
=>
{
describe
(
'
when a direction of L1 => L2 is specified
'
,
()
=>
{
it
(
'
should find all deposits made by the address
'
,
async
()
=>
{
const
from
=
'
0x
'
+
'
99
'
.
repeat
(
20
)
const
deposit
=
{
l1Token
:
'
0x
'
+
'
11
'
.
repeat
(
20
),
l2Token
:
'
0x
'
+
'
22
'
.
repeat
(
20
),
from
,
to
:
'
0x
'
+
'
44
'
.
repeat
(
20
),
amount
:
ethers
.
BigNumber
.
from
(
1234
),
data
:
'
0x1234
'
,
}
const
withdrawal
=
{
l1Token
:
'
0x
'
+
'
12
'
.
repeat
(
20
),
l2Token
:
'
0x
'
+
'
23
'
.
repeat
(
20
),
from
,
to
:
'
0x
'
+
'
45
'
.
repeat
(
20
),
amount
:
ethers
.
BigNumber
.
from
(
5678
),
data
:
'
0x5678
'
,
}
await
l1Bridge
.
emitERC20DepositInitiated
(
deposit
)
await
l2Bridge
.
emitWithdrawalInitiated
(
withdrawal
)
const
found
=
await
messenger
.
getTokenBridgeMessagesByAddress
(
from
,
{
direction
:
MessageDirection
.
L1_TO_L2
,
})
expect
(
found
.
length
).
to
.
equal
(
1
)
expect
(
found
[
0
].
amount
).
to
.
deep
.
equal
(
deposit
.
amount
)
expect
(
found
[
0
].
data
).
to
.
deep
.
equal
(
deposit
.
data
)
expect
(
found
[
0
].
direction
).
to
.
equal
(
MessageDirection
.
L1_TO_L2
)
expect
(
found
[
0
].
l1Token
).
to
.
deep
.
equal
(
deposit
.
l1Token
)
expect
(
found
[
0
].
l2Token
).
to
.
deep
.
equal
(
deposit
.
l2Token
)
expect
(
found
[
0
].
from
).
to
.
deep
.
equal
(
deposit
.
from
)
expect
(
found
[
0
].
to
).
to
.
deep
.
equal
(
deposit
.
to
)
})
})
describe
(
'
when a direction of L2 => L1 is specified
'
,
()
=>
{
it
(
'
should find all withdrawals made by the address
'
,
async
()
=>
{
const
from
=
'
0x
'
+
'
99
'
.
repeat
(
20
)
const
deposit
=
{
l1Token
:
'
0x
'
+
'
11
'
.
repeat
(
20
),
l2Token
:
'
0x
'
+
'
22
'
.
repeat
(
20
),
from
,
to
:
'
0x
'
+
'
44
'
.
repeat
(
20
),
amount
:
ethers
.
BigNumber
.
from
(
1234
),
data
:
'
0x1234
'
,
}
const
withdrawal
=
{
l1Token
:
'
0x
'
+
'
12
'
.
repeat
(
20
),
l2Token
:
'
0x
'
+
'
23
'
.
repeat
(
20
),
from
,
to
:
'
0x
'
+
'
45
'
.
repeat
(
20
),
amount
:
ethers
.
BigNumber
.
from
(
5678
),
data
:
'
0x5678
'
,
}
await
l1Bridge
.
emitERC20DepositInitiated
(
deposit
)
await
l2Bridge
.
emitWithdrawalInitiated
(
withdrawal
)
const
found
=
await
messenger
.
getTokenBridgeMessagesByAddress
(
from
,
{
direction
:
MessageDirection
.
L2_TO_L1
,
})
expect
(
found
.
length
).
to
.
equal
(
1
)
expect
(
found
[
0
].
amount
).
to
.
deep
.
equal
(
withdrawal
.
amount
)
expect
(
found
[
0
].
data
).
to
.
deep
.
equal
(
withdrawal
.
data
)
expect
(
found
[
0
].
direction
).
to
.
equal
(
MessageDirection
.
L2_TO_L1
)
expect
(
found
[
0
].
l1Token
).
to
.
deep
.
equal
(
withdrawal
.
l1Token
)
expect
(
found
[
0
].
l2Token
).
to
.
deep
.
equal
(
withdrawal
.
l2Token
)
expect
(
found
[
0
].
from
).
to
.
deep
.
equal
(
withdrawal
.
from
)
expect
(
found
[
0
].
to
).
to
.
deep
.
equal
(
withdrawal
.
to
)
})
})
describe
(
'
when no direction is specified
'
,
()
=>
{
it
(
'
should find all deposits and withdrawals made by the address
'
,
async
()
=>
{
const
from
=
'
0x
'
+
'
99
'
.
repeat
(
20
)
const
deposit
=
{
l1Token
:
'
0x
'
+
'
11
'
.
repeat
(
20
),
l2Token
:
'
0x
'
+
'
22
'
.
repeat
(
20
),
from
,
to
:
'
0x
'
+
'
44
'
.
repeat
(
20
),
amount
:
ethers
.
BigNumber
.
from
(
1234
),
data
:
'
0x1234
'
,
}
const
withdrawal
=
{
l1Token
:
'
0x
'
+
'
12
'
.
repeat
(
20
),
l2Token
:
'
0x
'
+
'
23
'
.
repeat
(
20
),
from
,
to
:
'
0x
'
+
'
45
'
.
repeat
(
20
),
amount
:
ethers
.
BigNumber
.
from
(
5678
),
data
:
'
0x5678
'
,
}
await
l1Bridge
.
emitERC20DepositInitiated
(
deposit
)
await
l2Bridge
.
emitWithdrawalInitiated
(
withdrawal
)
const
found
=
await
messenger
.
getTokenBridgeMessagesByAddress
(
from
)
expect
(
found
.
length
).
to
.
equal
(
2
)
// Check the deposit (deposits get searched first)
expect
(
found
[
0
].
amount
).
to
.
deep
.
equal
(
deposit
.
amount
)
expect
(
found
[
0
].
data
).
to
.
deep
.
equal
(
deposit
.
data
)
expect
(
found
[
0
].
direction
).
to
.
equal
(
MessageDirection
.
L1_TO_L2
)
expect
(
found
[
0
].
l1Token
).
to
.
deep
.
equal
(
deposit
.
l1Token
)
expect
(
found
[
0
].
l2Token
).
to
.
deep
.
equal
(
deposit
.
l2Token
)
expect
(
found
[
0
].
from
).
to
.
deep
.
equal
(
deposit
.
from
)
expect
(
found
[
0
].
to
).
to
.
deep
.
equal
(
deposit
.
to
)
// Check the withdrawal
expect
(
found
[
1
].
amount
).
to
.
deep
.
equal
(
withdrawal
.
amount
)
expect
(
found
[
1
].
data
).
to
.
deep
.
equal
(
withdrawal
.
data
)
expect
(
found
[
1
].
direction
).
to
.
equal
(
MessageDirection
.
L2_TO_L1
)
expect
(
found
[
1
].
l1Token
).
to
.
deep
.
equal
(
withdrawal
.
l1Token
)
expect
(
found
[
1
].
l2Token
).
to
.
deep
.
equal
(
withdrawal
.
l2Token
)
expect
(
found
[
1
].
from
).
to
.
deep
.
equal
(
withdrawal
.
from
)
expect
(
found
[
1
].
to
).
to
.
deep
.
equal
(
withdrawal
.
to
)
})
})
})
describe
(
'
when the address has not made any deposits or withdrawals
'
,
()
=>
{
it
(
'
should find nothing
'
,
async
()
=>
{
const
from
=
'
0x
'
+
'
99
'
.
repeat
(
20
)
const
found
=
await
messenger
.
getTokenBridgeMessagesByAddress
(
from
)
expect
(
found
).
to
.
deep
.
equal
([])
})
})
})
describe
(
'
toCrossChainMessage
'
,
()
=>
{
let
l1Bridge
:
Contract
let
l2Bridge
:
Contract
...
...
@@ -676,8 +492,9 @@ describe('CrossChainMessenger', () => {
const
foundCrossChainMessages
=
await
messenger
.
getMessagesByTransaction
(
tx
)
const
foundTokenBridgeMessages
=
await
messenger
.
getTokenBridgeMessagesByAddress
(
from
)
const
foundTokenBridgeMessages
=
await
messenger
.
getDepositsByAddress
(
from
)
const
resolved
=
await
messenger
.
toCrossChainMessage
(
foundTokenBridgeMessages
[
0
]
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment