Skip to content

Commit

Permalink
Remove idl
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Oct 30, 2023
1 parent 0b3815d commit 774c5c9
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions frontend/claim_sdk/claim.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as anchor from '@coral-xyz/anchor'
import { PublicKey } from '@solana/web3.js'
import tokenDispenser from './idl/token_dispenser.json'
import { ethers } from 'ethers'
import { removeLeading0x } from './index'
import { HexString } from 'aptos'

// Must be kept in line with the database types and the on-chain program
export type Ecosystem =
Expand All @@ -30,70 +28,6 @@ export class ClaimInfo {
public identity: string,
public amount: anchor.BN
) {}

/** Get the serialized form of this claim info that is stored as leaves in the merkle tree. */
public toBuffer(): Buffer {
let identityStruct: any = undefined
switch (this.ecosystem) {
case 'discord': {
identityStruct = { discord: { username: this.identity } }
break
}
case 'solana': {
identityStruct = {
solana: { pubkey: new PublicKey(this.identity).toBuffer() },
}
break
}
case 'evm': {
identityStruct = {
evm: {
pubkey: Array.from(ethers.getBytes(this.identity)),
},
}
break
}
case 'cosmwasm': {
identityStruct = {
cosmwasm: { address: this.identity },
}
break
}
case 'injective': {
identityStruct = {
injective: { address: this.identity },
}
break
}
case 'aptos': {
identityStruct = {
aptos: {
address: Buffer.from(removeLeading0x(this.identity), 'hex'),
},
}
break
}
case 'sui': {
identityStruct = {
sui: {
address: Buffer.from(removeLeading0x(this.identity), 'hex'),
},
}
break
}
default: {
// TODO: support the other ecosystems
throw new Error(`unknown ecosystem type: ${this.ecosystem}`)
}
}

const coder = new anchor.BorshCoder(tokenDispenser as anchor.Idl)
// type ascription needed because typescript doesn't think the two buffer types are equal for some reason.
return coder.types.encode('ClaimInfo', {
amount: this.amount,
identity: identityStruct,
}) as Buffer
}
}

export function getMaxAmount(claimInfos: ClaimInfo[]): anchor.BN {
Expand Down

0 comments on commit 774c5c9

Please sign in to comment.