@project-serum/anchor#utils TypeScript Examples
The following examples show how to use
@project-serum/anchor#utils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findReplicaMintAddress = async ({
programId = QUARRY_ADDRESSES.MergeMine,
primaryMint,
}: {
programId?: PublicKey;
primaryMint: PublicKey;
}): Promise<[PublicKey, number]> => {
const [pool] = await findPoolAddress({ programId, primaryMint });
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("ReplicaMint"), pool.toBuffer()],
programId
);
}
Example #2
Source File: wrappedToken.ts From saber-periphery with GNU Affero General Public License v3.0 | 6 votes |
/**
* Gets the address of a wrapped token.
* @param programID
* @param underlyingMint
* @param decimals
* @returns
*/
static getAddressSync(
underlyingMint: PublicKey,
decimals: number
): PublicKey {
return getProgramAddress(
[
utils.bytes.utf8.encode("anchor"), // b"anchor".
underlyingMint.toBytes(),
Buffer.from([decimals]),
],
SABER_ADDRESSES.AddDecimals
);
}
Example #3
Source File: wrappedToken.ts From saber-periphery with GNU Affero General Public License v3.0 | 6 votes |
/**
* Gets the address and nonce of a wrapped token.
* @param programID
* @param underlyingMint
* @param decimals
* @returns
*/
static async getAddressAndNonce(
programID: PublicKey,
underlyingMint: PublicKey,
decimals: number
): Promise<[PublicKey, number]> {
return await PublicKey.findProgramAddress(
[
Buffer.from(utils.bytes.utf8.encode("anchor")), // b"anchor".
underlyingMint.toBytes(),
Buffer.from([decimals]),
],
programID
);
}
Example #4
Source File: pda.ts From saber-periphery with GNU Affero General Public License v3.0 | 6 votes |
findRedeemerKey = async ({
iouMint,
redemptionMint,
}: {
iouMint: PublicKey;
redemptionMint: PublicKey;
}): Promise<[PublicKey, number]> => {
return PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("Redeemer"),
iouMint.toBytes(),
redemptionMint.toBytes(),
],
SABER_ADDRESSES.Redeemer
);
}
Example #5
Source File: index.ts From serum-ts with Apache License 2.0 | 6 votes |
public settleFunds(
openOrders: PublicKey,
owner: PublicKey,
baseWallet: PublicKey,
quoteWallet: PublicKey,
referrerQuoteWallet: PublicKey,
): TransactionInstruction {
const ix = DexInstructions.settleFunds({
market: this._market.address,
openOrders,
owner,
baseVault: this._market.decoded.baseVault,
quoteVault: this._market.decoded.quoteVault,
baseWallet,
quoteWallet,
vaultSigner: utils.publicKey.createProgramAddressSync(
[
this._market.address.toBuffer(),
this._market.decoded.vaultSignerNonce.toArrayLike(Buffer, 'le', 8),
],
this._dexProgramId,
),
programId: this._proxyProgramId,
referrerQuoteWallet,
});
this._middlewares.forEach((mw) => mw.settleFunds(ix));
return this.proxy(ix);
}
Example #6
Source File: pda.ts From arrow with GNU Affero General Public License v3.0 | 6 votes |
generateSunnyPoolAddress = async ({
quarry,
}: {
quarry: PublicKey;
}): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("SunnyQuarryPool"),
SUNNY_CREATOR_KEY.toBuffer(),
quarry.toBuffer(),
],
SUNNY_PROGRAM
);
}
Example #7
Source File: pda.ts From arrow with GNU Affero General Public License v3.0 | 6 votes |
generateSunnyVaultAddress = async ({
pool,
owner,
}: {
pool: PublicKey;
owner: PublicKey;
}): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("SunnyQuarryVault"),
pool.toBuffer(),
owner.toBuffer(),
],
SUNNY_PROGRAM
);
}
Example #8
Source File: pda.ts From arrow with GNU Affero General Public License v3.0 | 6 votes |
generateArrowAddress = (
mint: PublicKey,
programID: PublicKey = ARROW_ADDRESSES.ArrowSunny
): Promise<[PublicKey, number]> => {
return PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("arrow"), mint.toBuffer()],
programID
);
}
Example #9
Source File: pda.ts From tribeca with GNU Affero General Public License v3.0 | 6 votes |
findTokenRecordAddress = async (
authorityKey: PublicKey,
electorateKey: PublicKey
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("SimpleTokenRecord"),
authorityKey.toBuffer(),
electorateKey.toBuffer(),
],
TRIBECA_ADDRESSES.SimpleVoter
);
}
Example #10
Source File: pda.ts From tribeca with GNU Affero General Public License v3.0 | 6 votes |
findWhitelistAddress = async (
locker: PublicKey,
programId: PublicKey,
owner: PublicKey | null
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("LockerWhitelistEntry"),
locker.toBuffer(),
programId.toBuffer(),
owner ? owner.toBuffer() : SystemProgram.programId.toBuffer(),
],
TRIBECA_ADDRESSES.LockedVoter
);
}
Example #11
Source File: pda.ts From tribeca with GNU Affero General Public License v3.0 | 6 votes |
findEscrowAddress = async (
locker: PublicKey,
authority: PublicKey
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("Escrow"),
locker.toBuffer(),
authority.toBuffer(),
],
TRIBECA_ADDRESSES.LockedVoter
);
}
Example #12
Source File: pda.ts From tribeca with GNU Affero General Public License v3.0 | 6 votes |
findVoteAddress = async (
proposalKey: PublicKey,
voterKey: PublicKey
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("TribecaVote"),
proposalKey.toBuffer(),
voterKey.toBuffer(),
],
TRIBECA_ADDRESSES.Govern
);
}
Example #13
Source File: pda.ts From tribeca with GNU Affero General Public License v3.0 | 6 votes |
findProposalAddress = async (
governorKey: PublicKey,
index: u64
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("TribecaProposal"),
governorKey.toBuffer(),
index.toArrayLike(Buffer, "le", 8),
],
TRIBECA_ADDRESSES.Govern
);
}
Example #14
Source File: pda.ts From sencha with GNU Affero General Public License v3.0 | 6 votes |
findSwapMetaAddress = async ({
factory,
index,
programId = PROGRAM_ADDRESSES.CpAmm,
}: {
factory: PublicKey;
index: number;
programId?: PublicKey;
}): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("SwapMeta"),
factory.toBuffer(),
new u64(index).toBuffer(),
],
programId
);
}
Example #15
Source File: pda.ts From sencha with GNU Affero General Public License v3.0 | 6 votes |
findSwapAddress = async ({
factory,
mintA,
mintB,
programId = PROGRAM_ADDRESSES.CpAmm,
}: {
factory: PublicKey;
mintA: PublicKey;
mintB: PublicKey;
programId?: PublicKey;
}): Promise<[PublicKey, number]> => {
const [token0Mint, token1Mint] =
comparePubkeys(mintA, mintB) !== -1 ? [mintB, mintA] : [mintA, mintB];
return await PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("SwapInfo"),
factory.toBuffer(),
token0Mint.toBuffer(),
token1Mint.toBuffer(),
],
programId
);
}
Example #16
Source File: pda.ts From sencha with GNU Affero General Public License v3.0 | 6 votes |
findFactoryAddress = async ({
base,
programId = PROGRAM_ADDRESSES.CpAmm,
}: {
base: PublicKey;
programId?: PublicKey;
}): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("Factory"), base.toBuffer()],
programId
);
}
Example #17
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findPoolAddress = async ({
programId = QUARRY_ADDRESSES.MergeMine,
primaryMint,
}: {
programId?: PublicKey;
primaryMint: PublicKey;
}): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("MergePool"), primaryMint.toBuffer()],
programId
);
}
Example #18
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findMergeMinerAddress = async ({
programId = QUARRY_ADDRESSES.MergeMine,
pool,
owner,
}: {
programId?: PublicKey;
pool: PublicKey;
owner: PublicKey;
}): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("MergeMiner"), pool.toBuffer(), owner.toBuffer()],
programId
);
}
Example #19
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findRegistryAddress = async (
rewarderKey: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.Registry
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("QuarryRegistry"), rewarderKey.toBytes()],
programID
);
}
Example #20
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findRedeemerKey = async ({
iouMint,
redemptionMint,
}: {
iouMint: PublicKey;
redemptionMint: PublicKey;
}): Promise<[PublicKey, number]> => {
return PublicKey.findProgramAddress(
[
utils.bytes.utf8.encode("Redeemer"),
iouMint.toBytes(),
redemptionMint.toBytes(),
],
QUARRY_ADDRESSES.Redeemer
);
}
Example #21
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findRewarderAddress = async (
base: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.Mine
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[Buffer.from(utils.bytes.utf8.encode("Rewarder")), base.toBytes()],
programID
);
}
Example #22
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findOperatorAddress = async (
base: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.Operator
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("Operator"), base.toBytes()],
programID
);
}
Example #23
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findMinterAddress = async (
wrapper: PublicKey,
authority: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.MintWrapper
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
Buffer.from(utils.bytes.utf8.encode("MintWrapperMinter")),
wrapper.toBytes(),
authority.toBytes(),
],
programID
);
}
Example #24
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findMintWrapperAddress = async (
base: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.MintWrapper
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[Buffer.from(utils.bytes.utf8.encode("MintWrapper")), base.toBytes()],
programID
);
}
Example #25
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findMinerAddress = async (
quarry: PublicKey,
authority: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.Mine
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
Buffer.from(utils.bytes.utf8.encode("Miner")),
quarry.toBytes(),
authority.toBytes(),
],
programID
);
}
Example #26
Source File: pda.ts From quarry with GNU Affero General Public License v3.0 | 6 votes |
findQuarryAddress = async (
rewarder: PublicKey,
tokenMint: PublicKey,
programID: PublicKey = QUARRY_ADDRESSES.Mine
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[
Buffer.from(utils.bytes.utf8.encode("Quarry")),
rewarder.toBytes(),
tokenMint.toBytes(),
],
programID
);
}
Example #27
Source File: index.ts From saber-periphery with GNU Affero General Public License v3.0 | 5 votes |
async getProxyMintAuthority(): Promise<[PublicKey, number]> {
const stateAccount = this.program.state.address();
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("SaberMintProxy"), stateAccount.toBuffer()],
this.program.programId
);
}
Example #28
Source File: middleware.ts From serum-ts with Apache License 2.0 | 5 votes |
initOpenOrders(ix: TransactionInstruction) {
const market = ix.keys[2].pubkey;
const owner = ix.keys[1].pubkey;
// b"open-orders"
const openOrdersSeed = Buffer.from([
111,
112,
101,
110,
45,
111,
114,
100,
101,
114,
115,
]);
// b"open-orders-init"
const openOrdersInitSeed = Buffer.from([
111,
112,
101,
110,
45,
111,
114,
100,
101,
114,
115,
45,
105,
110,
105,
116,
]);
const [openOrders, bump] = utils.publicKey.findProgramAddressSync(
[
openOrdersSeed,
this._dexProgramId.toBuffer(),
market.toBuffer(),
owner.toBuffer(),
],
this._proxyProgramId,
);
const [marketAuthority, bumpInit] = utils.publicKey.findProgramAddressSync(
[openOrdersInitSeed, this._dexProgramId.toBuffer(), market.toBuffer()],
this._proxyProgramId,
);
// Override the open orders account and market authority.
ix.keys[0].pubkey = openOrders;
ix.keys[4].pubkey = marketAuthority;
// Writable because it must pay for the PDA initialization.
ix.keys[1].isWritable = true;
// Prepend to the account list extra accounts needed for PDA initialization.
ix.keys = [
{ pubkey: this._dexProgramId, isSigner: false, isWritable: false },
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
...ix.keys,
];
// Prepend the ix discriminator, bump, and bumpInit to the instruction data,
// which saves the program compute by avoiding recalculating them in the
// program.
ix.data = Buffer.concat([Buffer.from([0, bump, bumpInit]), ix.data]);
}
Example #29
Source File: pda.ts From tribeca with GNU Affero General Public License v3.0 | 5 votes |
findSimpleElectorateAddress = async (
base: PublicKey
): Promise<[PublicKey, number]> => {
return await PublicKey.findProgramAddress(
[utils.bytes.utf8.encode("SimpleElectorate"), base.toBuffer()],
TRIBECA_ADDRESSES.SimpleVoter
);
}