Created
April 16, 2022 04:25
-
-
Save staccDOTsol/b1f615fe534ea9b8111e6c0923289f64 to your computer and use it in GitHub Desktop.
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
// @ts-nocheck | |
// ye, fuck ts. fuck prettier | |
import {Account, Connection, Keypair, LAMPORTS_PER_SOL, PublicKey} from "@solana/web3.js"; | |
import {NodeWallet} from "@project-serum/common"; //TODO remove this | |
import {Fanout, FanoutClient, FanoutMembershipVoucher, FanoutMint, MembershipModel} from "@glasseaters/hydra-sdk"; | |
import fs from 'fs' | |
import { getMintInfo, getTokenAccount } from "@strata-foundation/spl-utils"; | |
import { Numberu64, NAME_PROGRAM_ID, createInstruction, createNameRegistry, getNameAccountKey, getHashedName, NameRegistryState } from "@solana/spl-name-service"; | |
import { SystemProgram, sendAndConfirmRawTransaction } from "@solana/web3.js"; | |
import{ ExponentialCurveConfig} from '@strata-foundation/spl-token-bonding' | |
import * as anchor from "@project-serum/anchor"; | |
import { SplTokenBonding } from "@strata-foundation/spl-token-bonding"; | |
import { SplTokenCollective } from "@strata-foundation/spl-token-collective"; | |
import { getAssociatedAccountBalance, SplTokenMetadata } from "@strata-foundation/spl-utils"; | |
let tokenCollectiveSdk, tokenBondingSdk, tokenMetadataSdk; | |
setTimeout(async function(){ | |
const connection = new Connection("https://ssc-dao.genesysgo.net/", "confirmed"); | |
let authorityWallet: Keypair; | |
let fanoutSdk: FanoutClient; | |
authorityWallet = Keypair.fromSecretKey( | |
new Uint8Array([redacted_key]) | |
); | |
//await airdrop(connection, authorityWallet.publicKey, LAMPORTS_PER_SOL * 10); | |
fanoutSdk = new FanoutClient( | |
connection, | |
new NodeWallet(new Account(authorityWallet.secretKey)) | |
); /* await Token.createMint( | |
*/ | |
tokenCollectiveSdk = await SplTokenCollective.init(fanoutSdk.provider); | |
tokenBondingSdk = await SplTokenBonding.init(fanoutSdk.provider); | |
tokenMetadataSdk = await SplTokenMetadata.init(fanoutSdk.provider); | |
/* | |
// Create a simple exponential curve 0.001 sqrt(S) | |
var curve = await tokenBondingSdk.initializeCurve({ | |
config: new ExponentialCurveConfig({ | |
c: 0.001, | |
b: 0, | |
pow: 2, | |
frac: 2 | |
}) | |
}); | |
// Create a collective around the Target of the above token bonding | |
var { collective, tokenBonding } = await tokenCollectiveSdk.createCollective({ | |
metadata: { | |
name: "Unlimited COPE", | |
symbol: "uCOPE", | |
uri: "https://gist.github.com/staccDOTsol/dc7ff91303966c47889c0287cc5d2288/raw/9021e52621fcde08f48790bd1098c70a0a18435f/uCOPE.json", | |
}, | |
bonding: { | |
curve, | |
baseMint: new PublicKey("8HGyAAB1yoM1ttS7pXjHMa3dukTFGQggnFFH3hJZgzQh"), | |
targetMintDecimals: 9, | |
buyBaseRoyaltyPercentage: 1, | |
buyTargetRoyaltyPercentage: 1, | |
sellBaseRoyaltyPercentage: 1, | |
sellTargetRoyaltyPercentage: 1 | |
}, | |
authority: authorityWallet.publicKey, | |
config: { | |
isOpen: true, | |
unclaimedTokenBondingSettings: { | |
buyTargetRoyalties: { | |
// This account is owned by the name service name, and will be transferred to the person who claims this token | |
ownedByName: true | |
} | |
} | |
} | |
}); | |
var collectiveTokenBonding = tokenBonding; | |
var collectiveAcct = await tokenCollectiveSdk.getCollective(collective); | |
var collectiveBondingAcct = await tokenBondingSdk.getTokenBonding(tokenBonding); | |
var name = "twitter" | |
var twitterTld = await getNameAccountKey(await getHashedName(name)); | |
var twitterHandle = "fairlyCOPE" | |
var hashedTwitterHandle = await getHashedName(twitterHandle); | |
var twitterName = await getNameAccountKey( | |
hashedTwitterHandle, | |
undefined, // No class | |
twitterTld // Every twitter handle is under our tld | |
) | |
var { ownerTokenRef, tokenBonding } = await tokenCollectiveSdk.createSocialToken({ | |
isPrimary: true, // Creates a social token explicitly associated with the collective by pda, instead of the wallet alone. | |
collective, | |
name: twitterName, | |
metadata: { | |
name: "fairlyCOPE", | |
symbol: "fairlyCOPE", | |
uri: "https://gist.github.com/staccDOTsol/d4c06f73176d9bb028187c9346d7e58f/raw/b68177133aab25882deda81cb809e940716bead6/fairCOPE.json", | |
}, | |
ignoreIfExists: false, // If a Social Token already exists for this wallet, ignore. | |
tokenBondingParams: { | |
curve, | |
buyBaseRoyaltyPercentage: 5, | |
buyTargetRoyaltyPercentage: 5, | |
sellBaseRoyaltyPercentage: 5, | |
sellTargetRoyaltyPercentage: 5 | |
} | |
}); | |
var tokenBondingAcct = await tokenBondingSdk.getTokenBonding(tokenBonding); | |
var ownerTokenRefAcct = await tokenCollectiveSdk.getTokenRef(ownerTokenRef); | |
*/ | |
var tokenRef = await tokenCollectiveSdk.getTokenRef(new PublicKey("3B9mW3tKWp92R6eD87PwhLP6rd4YNpqzvN81E2rKPRDa")); | |
console.log(tokenRef.mint.toBase58()) | |
//var tokenRef2 = await tokenCollectiveSdk.getTokenRef (new PublicKey("FhkDvSjyqo8oAU8gS4kizVydgotVoVDdZ15Af6iFgfG8")); | |
var mint = tokenRef.mint// getMintInfo(fanoutSdk.provider, tokenRef.mint); | |
var collectiveMint = new PublicKey("HoFAt8pK2jWhpts6L82KB1CpE3KDkz6bL6CAkBUCHXB6")//you guys r smart figure this out. I went and bought my token then explorer'd my way into my collective mint//tokenRef2.mint | |
console.log(collectiveMint.toBase58()) | |
const membershipMint = mint | |
const {fanout} = await fanoutSdk.initializeFanout({ | |
totalShares: 0, | |
name: `fairlyCOPE`, | |
membershipModel: MembershipModel.Token, | |
mint: membershipMint | |
}); | |
const {tokenAccount: bt} = await fanoutSdk.initializeFanoutForMint({ | |
fanout: fanout, | |
mint: membershipMint | |
}) | |
await fanoutSdk.initializeFanoutForMint({ | |
fanout: fanout, | |
mint: new PublicKey("8HGyAAB1yoM1ttS7pXjHMa3dukTFGQggnFFH3hJZgzQh") | |
}) | |
const { tokenAccount: br} = await fanoutSdk.initializeFanoutForMint({ | |
fanout: fanout, | |
mint: collectiveMint | |
}) | |
console.log(fanout.toBase58()) | |
var lala = await tokenCollectiveSdk.updateTokenBondingInstructions({ | |
// so this is going to need to be tokenRefKey, and not this | |
tokenRef: new PublicKey("3B9mW3tKWp92R6eD87PwhLP6rd4YNpqzvN81E2rKPRDa"), | |
buyBaseRoyalties: br, | |
sellBaseRoyalties: br, | |
buyTargetRoyalties: bt, | |
sellTargetRoyalties: bt, | |
}) | |
H7ZgieC19ksDm8sssZ87qzaa16izRsiFFhTwyA2RASLx | |
await tokenCollectiveSdk.sendInstructions(lala.instructions, lala.signers) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment