Skip to content

Commit

Permalink
export address helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Jul 11, 2024
1 parent 36a6cc8 commit 584bcae
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ser-kit",
"version": "0.3.1",
"version": "0.3.2",
"author": "Gnosis Guild",
"license": "LGPL-3.0",
"homepage": "https://github.com/gnosisguild/ser-kit",
Expand Down
16 changes: 15 additions & 1 deletion src/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { getAddress } from 'viem'
import { chains } from './chains'
import type { PrefixedAddress } from './types'
import type { ChainId, PrefixedAddress } from './types'

export const formatPrefixedAddress = (
chainId: ChainId | undefined,
address: `0x${string}`
) => {
const chain = chainId && chains.find((chain) => chain.chainId === chainId)

if (!chain && chainId) {
throw new Error(`Unsupported chain ID: ${chainId}`)
}

const prefix = chain ? chain.shortName : 'eoa'
return `${prefix}:${address.toLowerCase()}`
}

export const parsePrefixedAddress = (prefixedAddress: PrefixedAddress) => {
const [prefix, address] = prefixedAddress.split(':')
Expand Down
4 changes: 2 additions & 2 deletions src/execute/multisend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const encodeMultiSendData = (
['uint8', 'address', 'uint256', 'uint256', 'bytes'],
[
tx.operation || OperationType.Call,
tx.to,
tx.to as `0x${string}`,
BigInt(tx.value),
BigInt(hexToBytes(tx.data as `0x${string}`).length),
tx.data,
tx.data as `0x${string}`,
]
)
)
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './addresses'
export * from './chains'
export * from './query'
export * from './execute'
Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export interface Roles {
prefixedAddress: PrefixedAddress

chain: ChainId
defaultRole: Map<`0x${string}`, string>
multisend: `0x${string}`[]
version: 1 | 2
}
Expand Down Expand Up @@ -84,7 +83,7 @@ export type Connection =
| IsMemberConnection

/** An execution route starts with the signing EOA or initiating smart contract account. */
interface StartingPoint {
export interface StartingPoint {
/** The account that is used as the signer or initiator of the transaction */
account: Account
}
Expand Down

0 comments on commit 584bcae

Please sign in to comment.