Skip to content

Commit

Permalink
Merge pull request #7 from nachopiris/master
Browse files Browse the repository at this point in the history
update to sequence v2
  • Loading branch information
Agusx1211 authored Nov 7, 2024
2 parents d32d2b9 + 78f3b37 commit af7b2f8
Show file tree
Hide file tree
Showing 21 changed files with 231 additions and 634 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
"preview": "vite preview"
},
"dependencies": {
"@0xsequence/account": "^1.9.13",
"@0xsequence/core": "^1.9.13",
"@0xsequence/indexer": "^2.0.4",
"@0xsequence/network": "^1.9.13",
"@0xsequence/sessions": "^1.9.13",
"@0xsequence/signhub": "^1.9.13",
"@0xsequence/abi": "2.0.23",
"@0xsequence/account": "^2.0.23",
"@0xsequence/core": "^2.0.23",
"@0xsequence/indexer": "^2.0.23",
"@0xsequence/network": "^2.0.23",
"@0xsequence/sessions": "^2.0.23",
"@0xsequence/signhub": "^2.0.23",
"@mantine/core": "^7.7.1",
"@mantine/form": "^7.7.1",
"@mantine/hooks": "^7.7.1",
"@mantine/notifications": "^7.7.1",
"@tabler/icons-react": "^3.1.0",
"@tanstack/react-query": "^5.28.14",
"connectkit": "^1.7.3",
"ethers": "5.7.2",
"ethers": "6.13.4",
"idb": "^8.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
731 changes: 167 additions & 564 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/Names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ export const nameGenerator = (seed: string, length: number): string => {
const words = ethers.wordlists.en

let output = ''
let subSeed = ethers.utils.keccak256(seed)
let subSeed = ethers.keccak256(seed)
for (let i = 0; i < length; i++) {
const index = ethers.BigNumber.from(subSeed).mod(wordListSize).toNumber()
const index = Number(BigInt(subSeed) % BigInt(wordListSize))
console.log(index)
output = `${words.getWord(index)} ${output}`
subSeed = ethers.utils.keccak256(subSeed)
subSeed = ethers.keccak256(subSeed)
}

const emojiIndex = ethers.BigNumber.from(subSeed).mod(DEVICE_EMOJIS.length).toNumber()
const emojiIndex = Number(BigInt(subSeed) % BigInt(DEVICE_EMOJIS.length))
return `${DEVICE_EMOJIS[emojiIndex]} ${toUpperFirst(output)}`
}
8 changes: 4 additions & 4 deletions src/components/ActionsDecoded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function ActionArguments(props: { action: FlatTransaction, signature: Fun
export function ActionUpdateImageHash(props: { action: FlatTransaction, state: { loading: boolean, state?: AccountStatus }}) {
const { action, state } = props

const imageHash = ethers.utils.arrayify(action.data || "0x").slice(4)
const toConfig = useWalletConfig(ethers.utils.hexlify(imageHash))
const imageHash = ethers.getBytes(action.data || "0x").slice(4)
const toConfig = useWalletConfig(ethers.hexlify(imageHash))
const fromConfig = state.state?.onChain?.config

const isStale = (() => {
Expand All @@ -50,7 +50,7 @@ export function ActionUpdateImageHash(props: { action: FlatTransaction, state: {
const coderFrom = universal.genericCoderFor(fromConfig.version)
const coderTo = universal.genericCoderFor(toConfig.config.version)

return coderFrom.config.checkpointOf(fromConfig).toNumber() >= coderTo.config.checkpointOf(toConfig.config).toNumber()
return coderFrom.config.checkpointOf(fromConfig) >= coderTo.config.checkpointOf(toConfig.config)
})()

return <Box>
Expand Down Expand Up @@ -109,7 +109,7 @@ export function ActionDecode(props: { action: FlatTransaction, state: { loading:
Calls {action.to} without value or common data
</Box>}
{hasValue && <Box mt="md">
Transfer {ethers.utils.formatEther(action.value || 0)} NATIVE to {action.to}
Transfer {ethers.formatEther(action.value || 0)} NATIVE to {action.to}
</Box>}
{hasCall && <Box mt="md">
{decoded.loading && <Loader />}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SignerEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function SignerEditorValidator() {
return 'Address is required';
}

return ethers.utils.isAddress(value) ? null : 'Invalid address';
return ethers.isAddress(value) ? null : 'Invalid address';
},
weight: (value: number) => {
if (value === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/UpdateDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getChanges(
// Any address that exists in the new entries but not in the old entries is added
const tmpOldEntries = [...oldEntries]
for (const newEntry of newEntries) {
if (!ethers.utils.isAddress(newEntry.address)) {
if (!ethers.isAddress(newEntry.address)) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion src/sections/ImportWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function ImportWallet() {
return 'Wallet is required';
}

if (!ethers.utils.isAddress(value)) {
if (!ethers.isAddress(value)) {
return 'Invalid wallet address';
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/sections/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function StatefulMessage(props: {
setSigning(true);

try {
const digestBytes = ethers.utils.arrayify(message.subdigest);
const digestBytes = ethers.getBytes(message.subdigest);
const signature = await signMessageAsync({
message: { raw: digestBytes },
});
Expand Down Expand Up @@ -234,7 +234,7 @@ export function StatefulMessage(props: {
const encoded = commons.transaction.encodeBundleExecData(decorated);

const tx = await sendTransactionAsync({
chainId: ethers.BigNumber.from(message.chainId).toNumber(),
chainId: Number(message.chainId),
to: decorated.entrypoint as `0x${string}`,
data: encoded as `0x${string}`,
});
Expand Down Expand Up @@ -282,15 +282,15 @@ export function StatefulMessage(props: {
});

const signed = await account.signMessage(
ethers.utils.toUtf8Bytes(message.raw),
ethers.toUtf8Bytes(message.raw),
message.chainId,
"eip6492"
);

const validSig = await publicClient?.verifyMessage({
message: message.raw,
address: message.wallet as `0x${string}`,
signature: ethers.utils.arrayify(signed),
signature: ethers.getBytes(signed),
});

setSignature(signed);
Expand Down
2 changes: 1 addition & 1 deletion src/sections/Messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Messages() {
<MiniCard title="Wallet" value={address?.toString() || "Undefined"} />
</>

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return <>{title} Invalid wallet address</>
}

Expand Down
30 changes: 12 additions & 18 deletions src/sections/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,17 @@ export function Send() {
return "To is required";
}

return ethers.utils.isAddress(value) ? null : "Invalid address";
return ethers.isAddress(value) ? null : "Invalid address";
},
value: (value) => {
if (value) {
try {
ethers.BigNumber.from(value);
} catch (e) {
return "Value should be a number";
}
if (isNaN(Number(value))) {
return "Value should be a number";
}
},
data: (value) => {
if (value) {
try {
ethers.utils.arrayify(value);
ethers.getBytes(value);
} catch (e) {
return "Data should be a hex string";
}
Expand All @@ -122,7 +118,7 @@ export function Send() {

const sendNFTs = (recipients: Recipient[]) => {
try {
const iface = new ethers.utils.Interface([
const iface = new ethers.Interface([
"function transferFrom(address from, address to, uint256 tokenId)",
"function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data)",
]);
Expand Down Expand Up @@ -154,9 +150,9 @@ export function Send() {
}
}
for (const token in erc1155Transfers) {
const ids = erc1155Transfers[token].map((transfer) => ethers.BigNumber.from(transfer.id));
const ids = erc1155Transfers[token].map((transfer) => BigInt(transfer.id));
const amounts = erc1155Transfers[token].map(
(transfer) => ethers.BigNumber.from(transfer.amount)
(transfer) => BigInt(transfer.amount)
);
transactions.push({
to: token,
Expand Down Expand Up @@ -190,7 +186,7 @@ export function Send() {
form.setFieldValue("commitWalletUpdates", pendingUpdates > 0);
}, [pendingUpdates, form]);

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return (
<>
{title}
Expand All @@ -213,8 +209,8 @@ export function Send() {

let actions = values.transactions.map((t) => ({
to: t.to,
value: ethers.BigNumber.from(t.value || "0").toString(),
data: t.data ? ethers.utils.hexlify(t.data) : undefined,
value: BigInt(t.value || "0").toString(),
data: t.data,
revertOnError: true,
})) as commons.transaction.Transactionish;

Expand All @@ -241,10 +237,8 @@ export function Send() {

const txe: TransactionsEntry = {
wallet: address,
space: ethers.BigNumber.from(
values.space || Math.floor(Date.now())
).toString(),
nonce: ethers.BigNumber.from(values.nonce).toString(),
space: BigInt(values.space || Math.floor(Date.now())).toString(),
nonce: BigInt(values.nonce).toString(),
chainId: network.chainId.toString(),
transactions: fromSequenceTransactions(address, actions),
};
Expand Down
4 changes: 2 additions & 2 deletions src/sections/Sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function Sign() {
},
});

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return (
<>
{title}
Expand All @@ -50,7 +50,7 @@ export function Sign() {
const onSubmit = async (values: { message: string }) => {
if (!network) return;

const digest = ethers.utils.hashMessage(values.message);
const digest = ethers.hashMessage(values.message);
const subdigest = commons.signature.subdigestOf({digest, chainId: network.chainId, address})

await addMessage({raw: values.message, chainId: network.chainId, subdigest, wallet: address, digest, firstSeen: Date.now()})
Expand Down
4 changes: 2 additions & 2 deletions src/sections/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function StatefulTransaction(props: { transaction: TransactionsEntry, sta
setSigning(true)

try {
const digestBytes = ethers.utils.arrayify(subdigest)
const digestBytes = ethers.getBytes(subdigest)
const signature = await signMessageAsync({ message: { raw: digestBytes } })

const suffixed = signature + "02"
Expand Down Expand Up @@ -216,7 +216,7 @@ export function StatefulTransaction(props: { transaction: TransactionsEntry, sta
console.log("Sending transaction ...", decorated.entrypoint, encoded)

const tx = await sendTransactionAsync({
chainId: ethers.BigNumber.from(transaction.chainId).toNumber(),
chainId: Number(transaction.chainId),
to: decorated.entrypoint as `0x${string}`,
data: encoded as `0x${string}`,
})
Expand Down
2 changes: 1 addition & 1 deletion src/sections/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Transactions() {

const navigate = useNavigate()

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return <>{title} Invalid wallet address</>
}

Expand Down
2 changes: 1 addition & 1 deletion src/sections/Update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function Update() {

const { loading, state, error } = useAccountState(address)

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return <>
{title}
Invalid address
Expand Down
6 changes: 3 additions & 3 deletions src/sections/UpdateDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export function StatefulUpdateDetail(props: { subdigest: string, state: AccountS

const coder = universal.genericCoderFor(state.config.version)
const walletCheckpoint = coder.config.checkpointOf(state.config)
const checkpointDelta = update.checkpoint - walletCheckpoint.toNumber()
const checkpointDelta = BigInt(update.checkpoint) - walletCheckpoint

const status = update.checkpoint > walletCheckpoint.toNumber() ? "Pending" : "Stale"
const status = BigInt(update.checkpoint) > walletCheckpoint ? "Pending" : "Stale"

const threshold = (state.config as Config).threshold || 0

Expand Down Expand Up @@ -126,7 +126,7 @@ export function StatefulUpdateDetail(props: { subdigest: string, state: AccountS
setSigning(true)

try {
const digestBytes = ethers.utils.arrayify(subdigest)
const digestBytes = ethers.getBytes(subdigest)
const signature = await signMessageAsync({ message: { raw: digestBytes } })

const suffixed = signature + "02"
Expand Down
8 changes: 4 additions & 4 deletions src/sections/Updates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Updates() {
const st = useAccountState(address)
const navigate = useNavigate()

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return <>{title} Invalid wallet address</>
}

Expand All @@ -35,7 +35,7 @@ export function Updates() {
}

const coder = universal.genericCoderFor(state.config.version)
const checkpoint = coder.config.checkpointOf(state.config).toNumber()
const checkpoint = coder.config.checkpointOf(state.config)

const checkpointCard = <MiniCard title="Checkpoint" value={checkpoint.toString()} />

Expand All @@ -59,7 +59,7 @@ export function Updates() {
return <Table.Tr key={i}>
<Table.Td>{element.imageHash}</Table.Td>
<Table.Td>{element.checkpoint}</Table.Td>
<Table.Td>{element.checkpoint - checkpoint}</Table.Td>
<Table.Td>{(BigInt(element.checkpoint) - checkpoint).toString()}</Table.Td>
<Table.Td>
<Button
size="compact-sm"
Expand All @@ -78,7 +78,7 @@ export function Updates() {
return <Table.Tr key={i}>
<Table.Td><Text c="dimmed">{element.imageHash}</Text></Table.Td>
<Table.Td><Text c="dimmed">{element.checkpoint}</Text></Table.Td>
<Table.Td><Text c="dimmed">{element.checkpoint - checkpoint}</Text></Table.Td>
<Table.Td><Text c="dimmed">{(BigInt(element.checkpoint) - checkpoint).toString()}</Text></Table.Td>
<Table.Td>
<Button
size="compact-sm"
Expand Down
2 changes: 1 addition & 1 deletion src/sections/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function Wallet() {

const { loading, state, error } = useAccountState(address)

if (!address || !ethers.utils.isAddress(address)) {
if (!address || !ethers.isAddress(address)) {
return <>
{title}
Invalid address
Expand Down
Loading

0 comments on commit af7b2f8

Please sign in to comment.