Skip to content

Commit

Permalink
Fix address parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalodner committed Jun 9, 2020
1 parent 5c1eca2 commit 67a0ccd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/arb-provider-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arb-provider-ethers",
"version": "0.6.1",
"version": "0.6.2",
"description": "Arbitrum provider for ethers",
"author": "Offchain Labs, Inc.",
"license": "Apache-2.0",
Expand Down
46 changes: 16 additions & 30 deletions packages/arb-provider-ethers/src/lib/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ export enum EVMCode {
BadSequenceCode = 4,
}

function intValueToAddress(value: ArbValue.IntValue): string {
return ethers.utils.getAddress(
ethers.utils.hexZeroPad(
(value as ArbValue.IntValue).bignum.toHexString(),
20
)
)
}

function logValToLog(
val: ArbValue.Value,
index: number,
Expand Down Expand Up @@ -70,12 +79,7 @@ export class TxCall {
public data: Uint8Array

constructor(value: ArbValue.TupleValue) {
this.to = ethers.utils.getAddress(
ethers.utils.hexZeroPad(
(value.get(0) as ArbValue.IntValue).bignum.toHexString(),
20
)
)
this.to = intValueToAddress(value.get(0) as ArbValue.IntValue)
this.data = ArbValue.bytestackToBytes(value.get(1) as ArbValue.TupleValue)
}

Expand All @@ -91,12 +95,7 @@ export class TxMessage {
public data: Uint8Array

constructor(value: ArbValue.TupleValue) {
this.to = ethers.utils.getAddress(
ethers.utils.hexZeroPad(
(value.get(0) as ArbValue.IntValue).bignum.toHexString(),
20
)
)
this.to = intValueToAddress(value.get(0) as ArbValue.IntValue)
this.sequenceNum = (value.get(1) as ArbValue.IntValue).bignum
this.amount = (value.get(2) as ArbValue.IntValue).bignum
this.data = ArbValue.bytestackToBytes(value.get(3) as ArbValue.TupleValue)
Expand All @@ -113,12 +112,7 @@ export class ContractTxMessage {
public data: Uint8Array

constructor(value: ArbValue.TupleValue) {
this.to = ethers.utils.getAddress(
ethers.utils.hexZeroPad(
(value.get(0) as ArbValue.IntValue).bignum.toHexString(),
20
)
)
this.to = intValueToAddress(value.get(0) as ArbValue.IntValue)
this.amount = (value.get(1) as ArbValue.IntValue).bignum
this.data = ArbValue.bytestackToBytes(value.get(2) as ArbValue.TupleValue)
}
Expand All @@ -133,9 +127,7 @@ class EthTransferMessage {
public amount: ethers.utils.BigNumber

constructor(value: ArbValue.TupleValue) {
this.dest = ethers.utils.getAddress(
(value.get(0) as ArbValue.IntValue).bignum.toHexString()
)
this.dest = intValueToAddress(value.get(0) as ArbValue.IntValue)
this.amount = (value.get(1) as ArbValue.IntValue).bignum
}

Expand All @@ -149,12 +141,8 @@ class TokenTransferMessage {
public amount: ethers.utils.BigNumber

constructor(value: ArbValue.TupleValue) {
this.tokenAddress = ethers.utils.getAddress(
(value.get(0) as ArbValue.IntValue).bignum.toHexString()
)
this.dest = ethers.utils.getAddress(
(value.get(1) as ArbValue.IntValue).bignum.toHexString()
)
this.tokenAddress = intValueToAddress(value.get(0) as ArbValue.IntValue)
this.dest = intValueToAddress(value.get(1) as ArbValue.IntValue)
this.amount = (value.get(2) as ArbValue.IntValue).bignum
}

Expand Down Expand Up @@ -209,9 +197,7 @@ class EthBridgeMessage {
)
const restVal = value.get(3) as ArbValue.TupleValue
const typecode = (restVal.get(0) as ArbValue.IntValue).bignum.toNumber()
this.sender = ethers.utils.getAddress(
(restVal.get(1) as ArbValue.IntValue).bignum.toHexString()
)
this.sender = intValueToAddress(restVal.get(1) as ArbValue.IntValue)

this.message = unmarshalExecutedMessage(
typecode,
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-provider-web3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arb-provider-web3",
"version": "0.6.1",
"version": "0.6.2",
"description": "Arbitrum provider for web3",
"author": "Offchain Labs, Inc.",
"license": "Apache-2.0",
Expand All @@ -20,7 +20,7 @@
},
"homepage": "https://offchainlabs.com",
"dependencies": {
"arb-provider-ethers": "0.6.1",
"arb-provider-ethers": "0.6.2",
"ethers": "^4.0.44",
"ethers-providers": "^2.1.19",
"ethers-utils": "^2.1.11"
Expand Down

0 comments on commit 67a0ccd

Please sign in to comment.