-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
179 additions
and
80 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 was deleted.
Oops, something went wrong.
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,58 @@ | ||
import { | ||
SequencerProvider as NewProvider, | ||
Account as NewAccount, | ||
} from "starknet-490"; | ||
import { | ||
Call, | ||
SequencerProvider as OldProvider, | ||
Account as OldAccount, | ||
ec, | ||
} from "starknet"; | ||
import { BigNumber } from "ethers"; | ||
import { Account } from "./ui/pickAccounts"; | ||
|
||
export async function estimateFee(account: Account, call: Call[] | Call) { | ||
const calls = Array.isArray(call) ? call : [call]; | ||
const lowerCaseAddress = account.address.toLowerCase(); | ||
const keyPair = ec.getKeyPair(account.privateKey); | ||
const starkKey = ec.getStarkKey(keyPair); | ||
if (!BigNumber.from(account.signer).eq(starkKey)) { | ||
throw new Error( | ||
"Account cant be controlled with the selected private key or seed" | ||
); | ||
} | ||
try { | ||
const oldProvider = new OldProvider({ network: account.networkId as any }); | ||
const a = new OldAccount(oldProvider, lowerCaseAddress, keyPair); | ||
return await a.estimateFee(calls); | ||
} catch { | ||
const newProvider = new NewProvider({ network: account.networkId as any }); | ||
const a = new NewAccount(newProvider, lowerCaseAddress, keyPair); | ||
return a.estimateFee(calls); | ||
} | ||
} | ||
|
||
export async function execute(account: Account, call: Call[] | Call) { | ||
const calls = Array.isArray(call) ? call : [call]; | ||
const lowerCaseAddress = account.address.toLowerCase(); | ||
const keyPair = ec.getKeyPair(account.privateKey); | ||
const starkKey = ec.getStarkKey(keyPair); | ||
if (!BigNumber.from(account.signer).eq(starkKey)) { | ||
throw new Error( | ||
"Account cant be controlled with the selected private key or seed" | ||
); | ||
} | ||
try { | ||
const oldProvider = new OldProvider({ network: account.networkId as any }); | ||
const a = new OldAccount(oldProvider, lowerCaseAddress, keyPair); | ||
return await a.execute(calls); | ||
} catch (e) { | ||
console.warn("old failed", e); | ||
const newProvider = new NewProvider({ network: account.networkId as any }); | ||
const a = new NewAccount(newProvider, lowerCaseAddress, keyPair); | ||
return a.execute(calls).catch((e) => { | ||
console.warn("new failed", e); | ||
throw e; | ||
}); | ||
} | ||
} |
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
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,8 @@ | ||
import { BigNumber } from "ethers"; | ||
import { Account } from "../../ui/pickAccounts"; | ||
|
||
export const detect = async (accounts: Account[]): Promise<string[]> => { | ||
return accounts | ||
.filter(({ signer }) => BigNumber.from(signer).eq(0)) | ||
.map(({ 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,52 @@ | ||
import ora from "ora"; | ||
import { ec, SequencerProvider } from "starknet"; | ||
import { compileCalldata } from "starknet/dist/utils/stark"; | ||
import { execute } from "../../execute"; | ||
import { oraLog } from "../../oraLog"; | ||
import { Account, pickAccounts } from "../../ui/pickAccounts"; | ||
|
||
export const fix = async ( | ||
accounts: Account[], | ||
network: "mainnet-alpha" | "goerli-alpha", | ||
accountsToRecover: string[] | ||
): Promise<void> => { | ||
const [accountToCredit] = await pickAccounts(accounts, network, { | ||
single: true, | ||
accountsToRecoverMessage: | ||
"Select the account you want to use for the recovery", | ||
}); | ||
if (!accountToCredit) { | ||
throw new Error("No account to credit"); | ||
} | ||
const privateKey = accountToCredit.privateKey; | ||
if (!privateKey) { | ||
throw new Error("No private key for account to credit"); | ||
} | ||
const spinner = ora(`Fixing 0signer issue (this may take some time)`).start(); | ||
const provider = new SequencerProvider({ network }); | ||
const keyPair = ec.getKeyPair(privateKey); | ||
const starkKey = ec.getStarkKey(keyPair); | ||
|
||
for (const address of accountsToRecover) { | ||
const transaction = await execute(accountToCredit, { | ||
contractAddress: address, | ||
entrypoint: "initialize", | ||
calldata: compileCalldata({ | ||
signer: starkKey, | ||
guardian: "0", | ||
}), | ||
}); | ||
oraLog(spinner, `Transaction ${transaction.transaction_hash} created`); | ||
await provider.waitForTransaction(transaction.transaction_hash); | ||
|
||
const accountToUpdate = accounts.find((a) => a.address === address); | ||
if (accountToUpdate) { | ||
accountToUpdate.signer = starkKey; | ||
accountToUpdate.privateKey = privateKey; | ||
} | ||
|
||
// wait 1 minute extra to make sure the transaction is mined | ||
await new Promise((resolve) => setTimeout(resolve, 60000)); | ||
} | ||
spinner.succeed(`Fixed 0signer issue`); | ||
}; |
Oops, something went wrong.