Skip to content

Commit

Permalink
refined Meta-Llama script 🐈‍⬛
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Oct 22, 2024
1 parent ec4991c commit 6fa8299
Showing 1 changed file with 38 additions and 45 deletions.
83 changes: 38 additions & 45 deletions packages/utils/bin/divide-assets.google-app-script.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
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");
const input = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
const inputData = input.getDataRange().getValues()

const recipients = [
'0x13251746A15A687c14E22A25739fbBfa60F29b22',
'0x0078aE1617b89bbf219ebEE143CAD69461805026',
]
const ratio = 0.5

const outputData = (
[['token_type', 'token_address', 'receiver', 'amount', 'id']]
)
for (let i = 1; i < inputData.length; i++) {
let [name, symbol, address, balance, decimals] = inputData[i]
decimals = decimals == null || decimals === '' ? 18 : decimals
const half = balance * ratio
const amounts = [half, balance - half].map(
(amt) => amt / Math.pow(10, decimals)
)

recipients.forEach((rcpt, idx) => {
outputData.push([
!!symbol ? 'erc20' : 'native',
address,
rcpt,
amounts[idx],
])
})
}

// 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;
if(outputData.length <= 1) {
Logger.log('No output rows.')
} else {
const name = `${input.getName()} Divided`
let output = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(name)

// 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];
if (!output) {
output = SpreadsheetApp.getActiveSpreadsheet().insertSheet(name)
}

// 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
]);
output.clearContents()
output.getRange(1, 1, outputData.length, outputData[0].length).setValues(outputData)
}

// Write output data to output sheet
outputSheet.clearContents();
outputSheet.getRange(1, 1, outputData.length, 4).setValues(outputData);
}

0 comments on commit 6fa8299

Please sign in to comment.