forked from solana-labs/solana-program-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request solana-labs#81 from jarry-xiao/gummyroll
Add Gummyroll instructions
- Loading branch information
Showing
12 changed files
with
560 additions
and
152 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './instructions'; | ||
export * from './accounts'; | ||
export * from './types'; |
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,105 @@ | ||
import { Program } from '@project-serum/anchor'; | ||
import { Gummyroll } from "../types"; | ||
import { Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js'; | ||
|
||
export function createReplaceIx( | ||
gummyroll: Program<Gummyroll>, | ||
authority: Keypair, | ||
merkleRoll: PublicKey, | ||
treeRoot: Buffer, | ||
previousLeaf: Buffer, | ||
newLeaf: Buffer, | ||
index: number, | ||
proof: Buffer[] | ||
): TransactionInstruction { | ||
const nodeProof = proof.map((node) => { | ||
return { | ||
pubkey: new PublicKey(node), | ||
isSigner: false, | ||
isWritable: false, | ||
}; | ||
}); | ||
return gummyroll.instruction.replaceLeaf( | ||
Array.from(treeRoot), | ||
Array.from(previousLeaf), | ||
Array.from(newLeaf), | ||
index, | ||
{ | ||
accounts: { | ||
merkleRoll, | ||
authority: authority.publicKey, | ||
}, | ||
signers: [authority], | ||
remainingAccounts: nodeProof, | ||
} | ||
); | ||
} | ||
|
||
export function createAppendIx( | ||
gummyroll: Program<Gummyroll>, | ||
newLeaf: Buffer | ArrayLike<number>, | ||
authority: Keypair, | ||
appendAuthority: Keypair, | ||
merkleRoll: PublicKey, | ||
): TransactionInstruction { | ||
return gummyroll.instruction.append( | ||
Array.from(newLeaf), | ||
{ | ||
accounts: { | ||
merkleRoll, | ||
authority: authority.publicKey, | ||
appendAuthority: appendAuthority.publicKey, | ||
}, | ||
signers: [authority, appendAuthority], | ||
} | ||
); | ||
} | ||
|
||
export function createTransferAuthorityIx( | ||
gummyroll: Program<Gummyroll>, | ||
authority: Keypair, | ||
merkleRoll: PublicKey, | ||
newAuthority: PublicKey | null, | ||
newAppendAuthority: PublicKey | null, | ||
): TransactionInstruction { | ||
return gummyroll.instruction.transferAuthority( | ||
newAuthority, | ||
newAppendAuthority, | ||
{ | ||
accounts: { | ||
merkleRoll, | ||
authority: authority.publicKey, | ||
}, | ||
signers: [authority], | ||
} | ||
); | ||
} | ||
|
||
export function createVerifyLeafIx( | ||
gummyroll: Program<Gummyroll>, | ||
merkleRoll: PublicKey, | ||
root: Buffer, | ||
leaf: Buffer, | ||
index: number, | ||
proof: Buffer[], | ||
): TransactionInstruction { | ||
const nodeProof = proof.map((node) => { | ||
return { | ||
pubkey: new PublicKey(node), | ||
isSigner: false, | ||
isWritable: false, | ||
}; | ||
}); | ||
return gummyroll.instruction.verifyLeaf( | ||
Array.from(root), | ||
Array.from(leaf), | ||
index, | ||
{ | ||
accounts: { | ||
merkleRoll | ||
}, | ||
signers: [], | ||
remainingAccounts: nodeProof, | ||
} | ||
); | ||
} |
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 @@ | ||
export { Gummyroll } from "../../../target/types/gummyroll"; |
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
Oops, something went wrong.