1import { EthAddress, Ship } from '@urbit/roller-api';
2import { useCallback } from 'react';
3import Web3 from 'web3';
4import { INITIAL_NETWORK_KEY_REVISION } from './constants';
5import { reticketPointBetweenWallets } from './reticket';
6import BridgeWallet from './types/BridgeWallet';
7import { ReticketProgressCallback } from './types/L2Transaction';
8import useRoller from './useRoller';
9import { registerProxyAddress } from './utils/roller';
10import { useWallet } from 'store/wallet';
11import { useWalletConnect } from './useWalletConnect';
12import { ITxData } from './types/ITxData';
14interface ReticketL2SpawnParams {
15 fromWallet: BridgeWallet;
16 fromWalletType: symbol;
17 fromWalletHdPath: string;
18 toWallet: UrbitWallet;
21 contracts: any; // azimuth contracts
23 onUpdate?: ReticketProgressCallback;
24 transferEth?: boolean;
35 }: ITxData) => Promise<string>;
44 }: ITxData) => Promise<string>;
48 * This hook is used to reticket points that are still on L1 but have the
49 * spawn set to L2. It first performs 3-4 L1 transactions (set keys, set
50 * management / voting proxy, and transfer).
52 * It then sets the spawn proxy using an L2 transaction.
54 * Under the hood, it wraps two existing functions:
55 * `reticketPointBetweenWallets` for L1, and `registerProxyAddress` for L2.
58export const useReticketL2Spawn = () => {
59 const { api } = useRoller();
60 const { walletType }: any = useWallet();
61 const { connector, signPersonalMessage, isConnected } = useWalletConnect();
63 const performL2SpawnReticket = useCallback(
75 nextRevision = INITIAL_NETWORK_KEY_REVISION,
79 }: ReticketL2SpawnParams) => {
80 // call reticketPointBetweenWallets, with isL2Spawn set to true; this will
81 // skip setting the L1 spawn proxy
82 await reticketPointBetweenWallets({
96 doSetSpawnProxy: false,
99 // instead, set spawn proxy on L2
100 // In most TX sending cases, we would use the fromWallet to sign and send
101 // the TX. However, because we are transferring this point during the
102 // reticket, we will instead sign the final set spawn proxy TX with the
103 // receiving wallet's private key.
105 // `registerProxyAddress` expects a toWallet object shaped like a
106 // BridgeWallet with `address` and `privateKey` properties.
107 const toWalletStub = {
108 address: toWallet.ownership.keys.address,
109 privateKey: Buffer.from(toWallet.ownership.keys.private, 'hex'),
112 const nonce = await api.getNonce({ ship: point, proxy });
114 await registerProxyAddress(
121 toWallet?.spawn?.keys?.address || to,
130 [api, connector, walletType, isConnected, signPersonalMessage]
134 performL2SpawnReticket,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list