-
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
15 changed files
with
550 additions
and
570 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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,35 @@ | ||
import { BigNumber, Wallet } from "ethers"; | ||
import { ec, number } from "starknet"; | ||
import { BASE_DERIVATION_PATHS } from "./getAccounts"; | ||
import { getPathForIndex, getStarkPair } from "./keyDerivation"; | ||
|
||
export function equalSigner(a: string, b: string): boolean { | ||
return BigNumber.from(a).eq(b); | ||
} | ||
|
||
interface Signer { | ||
signer: string; | ||
privateKey: string; | ||
derivationPath?: string; | ||
} | ||
|
||
const amountOfSignersToGenerate = 20; | ||
|
||
export function getDefaultSigners(seedPhrase?: string): Array<Signer> { | ||
if (!seedPhrase) { | ||
return []; | ||
} | ||
const privateKey = Wallet.fromMnemonic(seedPhrase).privateKey; | ||
const arr = new Array(amountOfSignersToGenerate).fill(0); | ||
const keypairs = BASE_DERIVATION_PATHS.flatMap((p) => | ||
arr.map((_, i) => ({ | ||
keyPair: getStarkPair(i, privateKey, p), | ||
derivationPath: getPathForIndex(i, p), | ||
})) | ||
); | ||
return keypairs.map(({ keyPair, ...rest }) => ({ | ||
...rest, | ||
signer: ec.getStarkKey(keyPair), | ||
privateKey: number.toHex(number.toBN(keyPair.getPrivate().toString())), | ||
})); | ||
} |
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 |
---|---|---|
@@ -1,46 +1,23 @@ | ||
import MULTICALL_ABI from "./abi/Multicall.json"; | ||
import { | ||
SequencerProvider, | ||
Contract as SNContract, | ||
Abi, | ||
stark, | ||
hash, | ||
number, | ||
} from "starknet"; | ||
|
||
const MULTICALL_ADDRESS = { | ||
"mainnet-alpha": | ||
"0x0740a7a14618bb7e4688d10059bc42104d22c315bb647130630c77d3b6d3ee50", | ||
"goerli-alpha": | ||
"0x042a12c5a641619a6c58e623d5735273cdfb0e13df72c4bacb4e188892034bd6", | ||
}; | ||
import { Multicall } from "@argent/x-multicall"; | ||
import { SequencerProvider } from "starknet"; | ||
|
||
export async function getImplementation( | ||
addresses: string[], | ||
network: "mainnet-alpha" | "goerli-alpha" | ||
) { | ||
const provider = new SequencerProvider({ network }); | ||
const multicallContract = new SNContract( | ||
MULTICALL_ABI as Abi, | ||
MULTICALL_ADDRESS[network], | ||
provider | ||
); | ||
|
||
const calls = addresses.flatMap((address) => { | ||
const compiledCalldata = stark.compileCalldata({}); | ||
return [ | ||
address, | ||
hash.getSelectorFromName("get_implementation"), | ||
compiledCalldata.length, | ||
...compiledCalldata, | ||
]; | ||
}); | ||
|
||
const response = await multicallContract.aggregate(calls); | ||
const multicallProvider = new Multicall(provider); | ||
|
||
const results: string[] = response.result.map((res: any) => | ||
number.toHex(res) | ||
); | ||
const implementations = ( | ||
await Promise.all( | ||
addresses.map((address) => | ||
multicallProvider.call({ | ||
contractAddress: address, | ||
entrypoint: "get_implementation", | ||
}) | ||
) | ||
) | ||
).flat(); | ||
|
||
return results; | ||
return implementations; | ||
} |
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,46 +1,30 @@ | ||
import MULTICALL_ABI from "./abi/Multicall.json"; | ||
import { | ||
SequencerProvider, | ||
Contract as SNContract, | ||
Abi, | ||
stark, | ||
hash, | ||
number, | ||
} from "starknet"; | ||
|
||
const MULTICALL_ADDRESS = { | ||
"mainnet-alpha": | ||
"0x0740a7a14618bb7e4688d10059bc42104d22c315bb647130630c77d3b6d3ee50", | ||
"goerli-alpha": | ||
"0x042a12c5a641619a6c58e623d5735273cdfb0e13df72c4bacb4e188892034bd6", | ||
}; | ||
import { SequencerProvider } from "starknet"; | ||
import { Multicall } from "@argent/x-multicall"; | ||
|
||
export async function getSigners( | ||
addresses: string[], | ||
network: "mainnet-alpha" | "goerli-alpha" | ||
) { | ||
const provider = new SequencerProvider({ network }); | ||
const multicallContract = new SNContract( | ||
MULTICALL_ABI as Abi, | ||
MULTICALL_ADDRESS[network], | ||
provider | ||
); | ||
|
||
const calls = addresses.flatMap((address) => { | ||
const compiledCalldata = stark.compileCalldata({}); | ||
return [ | ||
address, | ||
hash.getSelectorFromName("get_signer"), | ||
compiledCalldata.length, | ||
...compiledCalldata, | ||
]; | ||
}); | ||
|
||
const response = await multicallContract.aggregate(calls); | ||
const multicallProvider = new Multicall(provider); | ||
|
||
const results: string[] = response.result.map((res: any) => | ||
number.toHex(res) | ||
); | ||
const signers = ( | ||
await Promise.all( | ||
addresses.map((address) => | ||
multicallProvider | ||
.call({ | ||
contractAddress: address, | ||
entrypoint: "getSigner", | ||
}) | ||
.catch(() => | ||
multicallProvider.call({ | ||
contractAddress: address, | ||
entrypoint: "get_signer", | ||
}) | ||
) | ||
) | ||
) | ||
).flat(); | ||
|
||
return results; | ||
return signers; | ||
} |
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,47 +1,30 @@ | ||
import MULTICALL_ABI from "./abi/Multicall.json"; | ||
import { | ||
SequencerProvider, | ||
Contract as SNContract, | ||
Abi, | ||
stark, | ||
hash, | ||
number, | ||
shortString, | ||
} from "starknet"; | ||
|
||
const MULTICALL_ADDRESS = { | ||
"mainnet-alpha": | ||
"0x0740a7a14618bb7e4688d10059bc42104d22c315bb647130630c77d3b6d3ee50", | ||
"goerli-alpha": | ||
"0x042a12c5a641619a6c58e623d5735273cdfb0e13df72c4bacb4e188892034bd6", | ||
}; | ||
import { Multicall } from "@argent/x-multicall"; | ||
import { SequencerProvider } from "starknet"; | ||
|
||
export async function getVersion( | ||
addresses: string[], | ||
network: "mainnet-alpha" | "goerli-alpha" | ||
) { | ||
const provider = new SequencerProvider({ network }); | ||
const multicallContract = new SNContract( | ||
MULTICALL_ABI as Abi, | ||
MULTICALL_ADDRESS[network], | ||
provider | ||
); | ||
|
||
const calls = addresses.flatMap((address) => { | ||
const compiledCalldata = stark.compileCalldata({}); | ||
return [ | ||
address, | ||
hash.getSelectorFromName("get_version"), | ||
compiledCalldata.length, | ||
...compiledCalldata, | ||
]; | ||
}); | ||
|
||
const response = await multicallContract.aggregate(calls); | ||
const multicallContract = new Multicall(provider); | ||
|
||
const results: string[] = response.result.map((res: any) => | ||
shortString.decodeShortString(number.toHex(res)) | ||
); | ||
const versions = ( | ||
await Promise.all( | ||
addresses.map((address) => | ||
multicallContract | ||
.call({ | ||
contractAddress: address, | ||
entrypoint: "getVersion", | ||
}) | ||
.catch(() => | ||
multicallContract.call({ | ||
contractAddress: address, | ||
entrypoint: "get_version", | ||
}) | ||
) | ||
) | ||
) | ||
).flat(); | ||
|
||
return results; | ||
return versions; | ||
} |
Oops, something went wrong.