From 6fa8299062885c413f3a41d855821bebbbe46cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B4=CF=85=CF=82?= Date: Tue, 22 Oct 2024 06:42:07 -0400 Subject: [PATCH] =?UTF-8?q?refined=20Meta-Llama=20script=20=F0=9F=90=88?= =?UTF-8?q?=E2=80=8D=E2=AC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bin/divide-assets.google-app-script.js | 83 +++++++++---------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/packages/utils/bin/divide-assets.google-app-script.js b/packages/utils/bin/divide-assets.google-app-script.js index 050af88cc..44d9cd6f8 100644 --- a/packages/utils/bin/divide-assets.google-app-script.js +++ b/packages/utils/bin/divide-assets.google-app-script.js @@ -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); } \ No newline at end of file