solana.js: add getOrCreateWrappedUser
This commit is contained in:
parent
f0d886f186
commit
a5bedd7d6d
|
@ -224,6 +224,25 @@ export class NativeMint extends Mint {
|
|||
return new NativeMint(provider, splMint);
|
||||
}
|
||||
|
||||
public async getOrCreateWrappedUser(
|
||||
payer: PublicKey,
|
||||
params:
|
||||
| {
|
||||
amount: number;
|
||||
}
|
||||
| { fundUpTo: number },
|
||||
user?: Keypair
|
||||
): Promise<[PublicKey, TransactionSignature | undefined]> {
|
||||
const [userAddress, userInit] =
|
||||
await this.getOrCreateWrappedUserInstructions(payer, params, user);
|
||||
if (userInit.ixns.length > 0) {
|
||||
const signature = await this.signAndSend(userInit);
|
||||
return [userAddress, signature];
|
||||
}
|
||||
|
||||
return [userAddress, undefined];
|
||||
}
|
||||
|
||||
public async getOrCreateWrappedUserInstructions(
|
||||
payer: PublicKey,
|
||||
params:
|
||||
|
|
|
@ -52,7 +52,7 @@ import {
|
|||
SWITCHBOARD_LABS_MAINNET_PERMISSIONLESS_CRANK,
|
||||
SWITCHBOARD_LABS_MAINNET_PERMISSIONLESS_QUEUE,
|
||||
} from './const';
|
||||
import { types } from '.';
|
||||
|
||||
/**
|
||||
* Switchboard Devnet Program ID
|
||||
*/
|
||||
|
@ -360,9 +360,9 @@ export class SwitchboardProgram {
|
|||
*/
|
||||
async loadPermissionless(): Promise<{
|
||||
queueAccount: QueueAccount;
|
||||
queue: types.OracleQueueAccountData;
|
||||
queue: OracleQueueAccountData;
|
||||
crankAccount: CrankAccount;
|
||||
crank: types.CrankAccountData;
|
||||
crank: CrankAccountData;
|
||||
}> {
|
||||
const queueKey =
|
||||
this.cluster === 'mainnet-beta'
|
||||
|
@ -403,9 +403,9 @@ export class SwitchboardProgram {
|
|||
*/
|
||||
async loadPermissioned(): Promise<{
|
||||
queueAccount: QueueAccount;
|
||||
queue: types.OracleQueueAccountData;
|
||||
queue: OracleQueueAccountData;
|
||||
crankAccount: CrankAccount;
|
||||
crank: types.CrankAccountData;
|
||||
crank: CrankAccountData;
|
||||
}> {
|
||||
const queueKey =
|
||||
this.cluster === 'mainnet-beta'
|
||||
|
|
|
@ -92,12 +92,10 @@ export class SwitchboardTestContext {
|
|||
alternateProgramId
|
||||
);
|
||||
|
||||
const [userTokenWallet, userTokenInit] =
|
||||
await program.mint.getOrCreateWrappedUserInstructions(
|
||||
const [userTokenWallet] = await program.mint.getOrCreateWrappedUser(
|
||||
program.walletPubkey,
|
||||
{ fundUpTo: 1 }
|
||||
);
|
||||
await program.signAndSend(userTokenInit);
|
||||
|
||||
const programDataAddress = getProgramDataAddress(program.programId);
|
||||
const idlAddress = await getIdlAddress(program.programId);
|
||||
|
|
Loading…
Reference in New Issue