Skip to content

Commit

Permalink
code from Hugging Face: Meta-Llama-3.1 🍁
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Oct 22, 2024
1 parent fd25a8a commit ec4991c
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 39 deletions.
30 changes: 7 additions & 23 deletions packages/utils/bin/balances-to-csv.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,13 @@ import {
avalanche,
bsc
} from 'viem/chains'
import { erc20Abi } from 'viem'
import { getChain, erc20Abi } from 'viem'
import fs from 'fs'
import path from 'path'

// Chain configurations
const CHAINS = {
1: mainnet,
137: polygon,
10: optimism,
42161: arbitrum,
8453: base,
43114: avalanche,
56: bsc
}

// Common tokens across chains (example addresses - verify before use)
const CHAIN_TOKENS = {
// Mainnet
1: [
'0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
'0x6B175474E89094C44Da98b954EedeAC495271d0F', // DAI
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // USDC
],
[mainnet.id]: {
},
// Polygon
137: [
'0xc2132D05D31c914a87C6611C10748AEb04B58e8F', // USDT
Expand Down Expand Up @@ -195,7 +179,7 @@ if (!CHAINS[chainId]) {

// Run the script
exportBalanceCSV(walletAddress, chainId)
.catch(error => {
console.error('Script failed:', error)
process.exit(1)
})
.catch(error => {
console.error('Script failed:', error)
process.exit(1)
})
52 changes: 52 additions & 0 deletions packages/utils/bin/divide-assets.google-app-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function distributeTokens() {
var inputSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var outputSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Output");

// Check if output sheet exists, create if not
if (!outputSheet) {
outputSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet("Output");
}

// Get input data
var inputData = inputSheet.getDataRange().getValues();

// Define recipients
var recipient1 = "0xRecipient1Address";
var recipient2 = "0xRecipient2Address";

// Define distribution ratio (50/50 in this example)
var ratio1 = 0.5;
var ratio2 = 0.5;

// Process input data
var outputData = [];
for (var i = 1; i < inputData.length; i++) {
var tokenName = inputData[i][0];
var tokenSymbol = inputData[i][1];
var tokenAddress = inputData[i][2];
var tokenBalance = inputData[i][3];
var tokenDecimals = inputData[i][4];

// Calculate token amounts for each recipient
var amount1 = tokenBalance * ratio1 / Math.pow(10, tokenDecimals);
var amount2 = tokenBalance * ratio2 / Math.pow(10, tokenDecimals);

// Create output rows
outputData.push([
tokenSymbol,
tokenAddress,
recipient1,
amount1
]);
outputData.push([
tokenSymbol,
tokenAddress,
recipient2,
amount2
]);
}

// Write output data to output sheet
outputSheet.clearContents();
outputSheet.getRange(1, 1, outputData.length, 4).setValues(outputData);
}
55 changes: 55 additions & 0 deletions packages/utils/bin/safe-balances.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

import SafeAPIKitImport from '@safe-global/api-kit'
import {
mainnet,
polygon,
optimism,
arbitrum,
base,
gnosis,
} from 'viem/chains'
import process from 'node:process'

const SafeAPIKit = SafeAPIKitImport.default

const [node, me, ...safes] = process.argv

if(safes.length === 0) {
console.info(`
Usage: ${me.replace(/^.*\//g, '')} <Safe Address> <Safe Address>…
Lists the token holdings of the listed Gnosis Safes in a CSV file.
`)
}

// Prefixes from: https://github.com/ethereum-lists/chains/tree/master/_data/chains
const erc3770 = {
eth: mainnet.id,
matic: polygon.id,
oeth: optimism.id,
arb1: arbitrum.id,
gno: gnosis.id,
base: base.id,
}

await Promise.all(safes.map(async (safe) => {
const [chain, address] = safe.split(':')
if(!address) {
throw new Error(`Invalid Safe Id: ${safe}`)
}

const chainId = erc3770[chain]
if(!chainId) {
throw new Error(`Unknown ERC-3770 Prefix: ${chain}`)
}

console.debug({ SafeAPIKit })

const safeAPI = new SafeAPIKit({ chainId })
const tokens = await safeAPI.getTokenList()
const info = await safeAPI.getSafeInfo()

console.debug({ tokens: JSON.stringify(tokens, null, 2) })
console.debug({ info: JSON.stringify(info, null, 2) })
}) )
1 change: 1 addition & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"devDependencies": {
"@composedb/types": "^0.7.1",
"@safe-global/api-kit": "^2.5.2",
"@types/uuid": "^10.0.0",
"key-did-provider-ed25519": "^2.0.1",
"key-did-resolver": "^2.1.3",
Expand Down
Loading

0 comments on commit ec4991c

Please sign in to comment.