-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d691e58
commit 0d00e28
Showing
79 changed files
with
2,845 additions
and
3,948 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
cli/accounts/indexed_array_pubkey_44J4oDXpjPAbzHCSc24q7NEiPekss4sAbLd8ka4gd9CZ.json
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
cli/accounts/merkle_tree_pubkey_5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Connection, PublicKey } from "@solana/web3.js"; | ||
import { getSolanaRpcUrl } from "../../src"; | ||
import { confirmTx } from "@lightprotocol/stateless.js"; | ||
import { confirmTx, getTestRpc } from "@lightprotocol/stateless.js"; | ||
|
||
export async function requestAirdrop(address: PublicKey, amount = 3e9) { | ||
const rpc = await getTestRpc(getSolanaRpcUrl()); | ||
const connection = new Connection(getSolanaRpcUrl(), "finalized"); | ||
let sig = await connection.requestAirdrop(address, amount); | ||
await confirmTx(connection, sig); | ||
await confirmTx(rpc, sig); | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Signer, PublicKey } from '@solana/web3.js'; | ||
|
||
/** @internal */ | ||
export function getSigners( | ||
signerOrMultisig: Signer | PublicKey, | ||
multiSigners: Signer[], | ||
): [PublicKey, Signer[]] { | ||
// TODO: add multisig support | ||
if (multiSigners.length > 0) throw new Error('Multisig not supported yet.'); | ||
|
||
if (signerOrMultisig instanceof PublicKey) | ||
throw new Error('Multisig not supported yet.'); | ||
|
||
return signerOrMultisig instanceof PublicKey | ||
? [signerOrMultisig, multiSigners] | ||
: [signerOrMultisig.publicKey, [signerOrMultisig]]; | ||
} | ||
|
||
/** @internal remove signer from signers if part of signers */ | ||
export function dedupeSigner(signer: Signer, signers: Signer[]): Signer[] { | ||
if (signers.includes(signer)) { | ||
return signers.filter( | ||
s => s.publicKey.toString() !== signer.publicKey.toString(), | ||
); | ||
} | ||
return signers; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,58 @@ | ||
import { | ||
ConfirmOptions, | ||
Connection, | ||
Keypair, | ||
PublicKey, | ||
Signer, | ||
TransactionSignature, | ||
} from '@solana/web3.js'; | ||
import { CompressedTokenProgram } from '../program'; | ||
import { MINT_SIZE } from '@solana/spl-token'; | ||
import { sendAndConfirmTx } from '@lightprotocol/stateless.js'; | ||
import { buildAndSignTx } from '@lightprotocol/stateless.js'; | ||
import { | ||
Rpc, | ||
buildAndSignTx, | ||
sendAndConfirmTx, | ||
} from '@lightprotocol/stateless.js'; | ||
import { dedupeSigner } from './common'; | ||
|
||
/** | ||
* Create and initialize a new compressed token mint | ||
* | ||
* @param connection Connection to use | ||
* @param rpc RPC to use | ||
* @param payer Payer of the transaction and initialization fees | ||
* @param mintAuthority Account or multisig that will control minting | ||
* @param mintAuthority Account or multisig that will control minting. Is signer. | ||
* @param decimals Location of the decimal place | ||
* @param keypair Optional keypair, defaulting to a new random one | ||
* @param confirmOptions Options for confirming the transaction | ||
* | ||
* @return Address of the new mint and the transaction signature | ||
*/ | ||
export async function createMint( | ||
connection: Connection, | ||
rpc: Rpc, | ||
payer: Signer, | ||
mintAuthority: PublicKey, | ||
mintAuthority: Signer, | ||
decimals: number, | ||
keypair = Keypair.generate(), | ||
confirmOptions?: ConfirmOptions, | ||
): Promise<{ mint: PublicKey; transactionSignature: TransactionSignature }> { | ||
const rentExemptBalance = | ||
await connection.getMinimumBalanceForRentExemption(MINT_SIZE); | ||
await rpc.getMinimumBalanceForRentExemption(MINT_SIZE); | ||
|
||
const ixs = await CompressedTokenProgram.createMint({ | ||
feePayer: payer.publicKey, | ||
mint: keypair.publicKey, | ||
decimals, | ||
authority: mintAuthority, | ||
authority: mintAuthority.publicKey, | ||
freezeAuthority: null, // TODO: add feature | ||
rentExemptBalance, | ||
}); | ||
|
||
const { blockhash } = await connection.getLatestBlockhash(); | ||
const { blockhash } = await rpc.getLatestBlockhash(); | ||
|
||
const additionalSigners = dedupeSigner(payer, [mintAuthority, keypair]); | ||
|
||
const tx = buildAndSignTx(ixs, payer, blockhash, [keypair]); | ||
const tx = buildAndSignTx(ixs, payer, blockhash, additionalSigners); | ||
|
||
const txId = await sendAndConfirmTx(connection, tx, confirmOptions); | ||
const txId = await sendAndConfirmTx(rpc, tx, confirmOptions); | ||
|
||
return { mint: keypair.publicKey, transactionSignature: txId }; | ||
} |
Oops, something went wrong.