-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
looks up safeTx on gnosis tx service api
waits for tx to become available detects contract wallets uses safeDecodeLogs drops custom gh next config Signed-off-by: stadolf <[email protected]>
- Loading branch information
1 parent
5502fe9
commit 15bae8e
Showing
8 changed files
with
161 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
output: "export", | ||
basePath: "/test-wagmi-safe-privy", | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { usePrivyWagmi } from "@privy-io/wagmi-connector"; | ||
import { useEffect, useState } from "react"; | ||
import { Address } from "viem"; | ||
import { usePublicClient } from "wagmi"; | ||
|
||
export const useIsContractWallet = () => { | ||
const publicClient = usePublicClient(); | ||
const [isContractWallet, setIsContractWallet] = useState<boolean>(); | ||
const { wallet: activeWallet } = usePrivyWagmi(); | ||
|
||
useEffect(() => { | ||
if (!activeWallet || !publicClient) return; | ||
|
||
console.log(activeWallet, publicClient); | ||
|
||
//maybe check -> if (activeWallet.connectorType.startsWith("wallet_connect")) | ||
|
||
publicClient | ||
.getBytecode({ address: activeWallet.address as Address }) | ||
.then((b) => { | ||
setIsContractWallet((b?.length || 0) > 0); | ||
}); | ||
}, [activeWallet, publicClient]); | ||
|
||
return isContractWallet; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function delay(milliseconds: number) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, milliseconds); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// emulates some features of api kit https://github.com/safe-global/safe-core-sdk/tree/main/packages/api-kit | ||
// https://docs.safe.global/safe-core-api/available-services | ||
|
||
import { Address } from "viem"; | ||
import { goerli, mainnet } from "viem/chains"; | ||
import { delay } from "./delay"; | ||
|
||
type TxServiceApiTransactionResponse = { | ||
safe: Address; | ||
to: Address; | ||
data: `0x${string}`; | ||
blockNumber: number; | ||
transactionHash: `0x${string}`; | ||
safeTxHash: `0x${string}`; | ||
executor: Address; | ||
isExecuted: boolean; | ||
isSuccessful: boolean; | ||
confirmations: Array<{ | ||
owner: Address; | ||
}>; | ||
}; | ||
|
||
const NetworkMap: Record<number, string | null> = { | ||
[goerli.id]: "goerli", | ||
[mainnet.id]: "mainnet", | ||
}; | ||
|
||
// https://safe-transaction-goerli.safe.global/ | ||
// https://safe-transaction-mainnet.safe.global/ | ||
/** | ||
* @param network goerli|mainnet | ||
* @param safeTxHash the "internal" safe tx hash | ||
* @returns 0xstring the executed transaction | ||
*/ | ||
export const resolveSafeTx = async ( | ||
networkId: number, | ||
safeTxHash: `0x${string}`, | ||
attempt = 1 | ||
): Promise<`0x${string}` | undefined> => { | ||
const server = `https://safe-transaction-${NetworkMap[networkId]}.safe.global`; | ||
// https://safe-transaction-goerli.safe.global/api/v1/multisig-transactions/0xc02ba93a6f025e3e78dfceb5c9d4d681aa9aafc780ba6243d3d70ac9fdf48288/' | ||
const url = `${server}/api/v1/multisig-transactions/${safeTxHash}`; | ||
|
||
const response = <TxServiceApiTransactionResponse>( | ||
await (await fetch(url)).json() | ||
); | ||
console.debug(`Safe Tx Api attempt ${attempt}`, response); | ||
if (response.isSuccessful === null) { | ||
await delay(2500 * attempt); | ||
return resolveSafeTx(networkId, safeTxHash, attempt + 1); | ||
} | ||
|
||
if (!response.isSuccessful) { | ||
return undefined; | ||
} | ||
return response.transactionHash; | ||
}; | ||
|
||
// export const isSafe = (address: Address) => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Abi, TransactionReceipt, decodeEventLog } from "viem"; | ||
|
||
export const safeDecodeLogs = (receipt: TransactionReceipt, abi: Abi) => { | ||
return receipt.logs | ||
.map((log) => { | ||
try { | ||
return decodeEventLog({ | ||
abi, | ||
data: log.data, | ||
topics: log.topics, | ||
}) as any; | ||
} catch (e) { | ||
return null; | ||
} | ||
}) | ||
.filter((log) => !!log); | ||
}; |