-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code from Hugging Face: Meta-Llama-3.1 🍁
- Loading branch information
Showing
5 changed files
with
300 additions
and
39 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,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); | ||
} |
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,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) }) | ||
}) ) |
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.