-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate & Upload (near,mpc,safe) Address Tuples To Dune (#124)
This script is a small data pipeline querying all [sign requests](https://nearblocks.io/address/v1.signer) made to `v1.signer` from [Dune](https://dune.com/queries/4611467?sidebar=none) along with their `derivation_path` and `key_version`. It then filters for `(key_version, derivation_path) = (0, ethereum,1)` (i.e. those used by [bitte.ai](https://wallet.bitte.ai/)) and generates the tuple `(nearAddress,mpcAddress,safeAddress)` and uploads the CSV back to Dune which can be queried as demonstrated [here](https://dune.com/queries/4611928). This data can be joined with all the safe activity data to gain insight on Near Accounts Interacting with EVMs via Bitte Protocol.
- Loading branch information
Showing
4 changed files
with
304 additions
and
190 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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { DuneClient } from "@duneanalytics/client-sdk"; | ||
import dotenv from "dotenv"; | ||
|
||
import { NearSafe } from "../src"; | ||
|
||
interface Pairing { | ||
near: string; | ||
mpc: string; | ||
safe: string; | ||
} | ||
|
||
export async function accountPairings(data: { | ||
nearAddress: string; | ||
keyVersion: number; | ||
derivationPath: string; | ||
safeSaltNonce: string; | ||
}): Promise<Pairing> { | ||
const { nearAddress, keyVersion, derivationPath, safeSaltNonce } = data; | ||
if (keyVersion !== 0) { | ||
throw new Error("Only key version 0 is supported"); | ||
} | ||
const adapter = await NearSafe.create({ | ||
mpc: { | ||
accountId: nearAddress, | ||
mpcContractId: "v1.signer", | ||
derivationPath, | ||
}, | ||
pimlicoKey: "", | ||
safeSaltNonce, | ||
}); | ||
return { | ||
near: nearAddress, | ||
mpc: adapter.mpcAddress, | ||
safe: adapter.address, | ||
}; | ||
} | ||
|
||
interface SignerUser { | ||
sign_for: string; | ||
key_version: number; | ||
derivation_path: string; | ||
num_relayed: number; | ||
total: number; | ||
} | ||
|
||
// Example usage | ||
export async function getAllSignerUsers( | ||
dune: DuneClient | ||
): Promise<SignerUser[]> { | ||
// This Dune Query is better than near blocks: | ||
// https://dune.com/queries/4611467 | ||
const queryId = 4611467; | ||
const { result } = await dune.getLatestResult({ queryId }); | ||
const data: SignerUser[] = (result?.rows ?? []).map((row) => ({ | ||
sign_for: String(row.sign_for), | ||
key_version: Number(row.key_version), | ||
derivation_path: String(row.derivation_path), | ||
num_relayed: Number(row.num_relayed), | ||
total: Number(row.total), | ||
})); | ||
return data; | ||
} | ||
|
||
export async function generateCSV(dune: DuneClient): Promise<string> { | ||
const data = await getAllSignerUsers(dune); | ||
const BITTE_WALLET_SALT_NONCE = "130811896738364156958237239906781888512"; | ||
const pairings = await Promise.all( | ||
data | ||
.filter((user) => user.derivation_path === "ethereum,1") | ||
.map((user) => | ||
accountPairings({ | ||
nearAddress: user.sign_for, | ||
keyVersion: user.key_version, | ||
derivationPath: user.derivation_path, | ||
safeSaltNonce: BITTE_WALLET_SALT_NONCE, | ||
}) | ||
) | ||
); | ||
|
||
const csvContent = pairings | ||
.map((pairing) => `${pairing.near},${pairing.mpc},${pairing.safe}`) | ||
.join("\n"); | ||
|
||
// fs.writeFileSync("wallet-pairings.csv", "near,mpc,safe\n" + csvContent); | ||
return csvContent; | ||
} | ||
|
||
export async function duneUpload(): Promise<void> { | ||
dotenv.config(); | ||
const dune = new DuneClient(process.env.DUNE_API_KEY ?? ""); | ||
const csv = await generateCSV(dune); | ||
// fs.writeFileSync("wallet-pairings.csv", "near,mpc,safe\n" + csv); | ||
const result = await dune.table.uploadCsv({ | ||
table_name: "neareth_pairings", | ||
data: "near,mpc,safe\n" + csv, | ||
description: "Near -> MPC -> Safe Tuples", | ||
is_private: false, | ||
}); | ||
console.log(result); | ||
} |
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
Oops, something went wrong.