Commit f52fc61e authored by smartcontracts's avatar smartcontracts Committed by GitHub

Merge pull request #2173 from ethereum-optimism/sc/sdk-remove-token-messages

feat(sdk): remove getTokenBridgeMessages function
parents 57c66bb9 5ffb5fcf
---
'@eth-optimism/sdk': patch
---
Removes the getTokenBridgeMessagesByAddress function
......@@ -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?: {
......
......@@ -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: {
......
......@@ -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.
*
......
......@@ -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.
......
......@@ -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]
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment