Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parse allocation csvs #194

Merged
merged 7 commits into from
Oct 27, 2023
Merged

feat: parse allocation csvs #194

merged 7 commits into from
Oct 27, 2023

Conversation

swimricky
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Oct 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
grant-program ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 27, 2023 6:13pm

@@ -74,6 +75,9 @@ export async function addClaimInfosToDatabase(
})
)

console.log(`\n\nbuilt merkle tree\n\n`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: clean up comments.
right now this insert is taking a long time so will look into optimizing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense, I am sure you can batch the queries

usage
exit
else
test=1
fi
shift
;;
-c|--csv)
if [ "$dev" -eq 1 ] || [ "$test" -eq 1 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like if $dev + $test + $csv != 1 be simpler?

fs.readFileSync(path.resolve(CSV_DIR, defi_csv), 'utf-8'),
{
header: true,
skipEmptyLines: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? we might want to code to crash if there are empty lines

Copy link
Contributor Author

@swimricky swimricky Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i originally added this for handling any empty lines at the end but open to removing this and throwing errors/crashing

)
assert(
defiCsvClaims.meta.fields?.includes('alloc'),
"CSV file does not have required 'alloc' column"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it check that there's a chain column

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also might be useful to refactor this into a hasColumns function

assert(
!curChainsForAddr.includes(chainAndAlloc[0]),
`CurChainsForAddr: ${curChainsForAddr}. Address ${key} has duplicate chain ${chainAndAlloc[0]}`
)
Copy link
Contributor

@guibescos guibescos Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have logic here that ignores dev addresses if they are already in the defi claims csv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was planning on just removing them from the defi_dev.csv address but can change to this instead

async function main() {
await clearDatabase(pool)
const { claimInfos, evmBreakdownAddresses, solanaBreakdownData } = parseCsvs()
if (DEBUG) {
const [maxUser, maxAmount] = getMaxUserAndAmount(claimInfos)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good sanity checks

assert(
discordClaimsAddrSet.size ===
discordDevClaims.length + discordClaims.length,
'Discord claims and discord dev claims have duplicate addresses'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for defi_dev, maybe it's fine just skipping the dev claims that are already in the main table instead of crashing

evmBreakDowns.push({
chain,
identity,
amount: truncateAllocation(alloc),
Copy link
Contributor

@guibescos guibescos Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this conversion should happen inside parseCsv and parseCsv should return a EvmBreakdownRow[] and a SolanaBreakdownRow[]

@swimricky swimricky requested a review from guibescos October 26, 2023 16:29
@swimricky swimricky marked this pull request as ready for review October 26, 2023 16:30
@swimricky
Copy link
Contributor Author

@guibescos i left some console logging statements since this is just a script that will only be used internally but if you want me to remove them lmk and i can clean those up

@@ -10,6 +10,8 @@ import { getMaxAmount } from '../claim_sdk/claim'
import * as anchor from '@coral-xyz/anchor'
import { MerkleTree } from '../claim_sdk/merkleTree'
import { BN } from 'bn.js'
const sql = require('sql') as any
// import { SQL, define } from 'sql';
Copy link
Contributor

@guibescos guibescos Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code

@@ -30,3 +30,4 @@ DISPENSER_GUARD=[128,47,82,29,168,187,15,46,104,227,206,117,172,71,34,235,23,50,
FUNDER_KEYPAIR=[145,197,43,77,224,103,196,174,132,195,48,31,177,97,237,163,15,196,217,142,181,204,104,107,98,82,213,0,155,140,218,180,30,119,201,38,51,176,207,221,193,222,235,244,163,250,125,66,68,196,45,208,212,201,232,178,100,163,24,21,106,83,66,174]

PROGRAM_ID=Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add DEPLOYER_WALLET here

@@ -17,7 +19,12 @@ import BN from 'bn.js'
import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'
import { EvmBreakdownRow } from '../utils/db'
import assert from 'assert'
import path from 'path'
import { SolanaBreakdown } from 'utils/api'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

@@ -31,19 +38,43 @@ const FUNDER_KEYPAIR = Keypair.fromSecretKey(
)
const CLUSTER = envOrErr('CLUSTER')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused


const NFT_CLAIMS = 'nft.csv'

const ECOSYSTEM_LIST = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Ecosystems from ../claim_sdk/claim

})

// need solana breakdown between nft & defi
const nftCsvClaims = Papa.parse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps refactor into parseNftClaims

)
let claimInfoChunks = []
let chunkSize = 100
let chunkCounts = [...Array(Math.ceil(claimInfos.length / chunkSize))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this variable, only the index is important

]
)
let claimInfoChunks = []
let chunkSize = 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should be const

Copy link
Contributor

@guibescos guibescos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Dropped many minor comments.

* Add change

* Optimize csvs
@swimricky swimricky merged commit c6e8e32 into main Oct 27, 2023
3 checks passed
@swimricky swimricky deleted the parse-csvs branch October 27, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants