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);
|
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(
|
public async getOrCreateWrappedUserInstructions(
|
||||||
payer: PublicKey,
|
payer: PublicKey,
|
||||||
params:
|
params:
|
||||||
|
|
|
@ -52,7 +52,7 @@ import {
|
||||||
SWITCHBOARD_LABS_MAINNET_PERMISSIONLESS_CRANK,
|
SWITCHBOARD_LABS_MAINNET_PERMISSIONLESS_CRANK,
|
||||||
SWITCHBOARD_LABS_MAINNET_PERMISSIONLESS_QUEUE,
|
SWITCHBOARD_LABS_MAINNET_PERMISSIONLESS_QUEUE,
|
||||||
} from './const';
|
} from './const';
|
||||||
import { types } from '.';
|
|
||||||
/**
|
/**
|
||||||
* Switchboard Devnet Program ID
|
* Switchboard Devnet Program ID
|
||||||
*/
|
*/
|
||||||
|
@ -360,9 +360,9 @@ export class SwitchboardProgram {
|
||||||
*/
|
*/
|
||||||
async loadPermissionless(): Promise<{
|
async loadPermissionless(): Promise<{
|
||||||
queueAccount: QueueAccount;
|
queueAccount: QueueAccount;
|
||||||
queue: types.OracleQueueAccountData;
|
queue: OracleQueueAccountData;
|
||||||
crankAccount: CrankAccount;
|
crankAccount: CrankAccount;
|
||||||
crank: types.CrankAccountData;
|
crank: CrankAccountData;
|
||||||
}> {
|
}> {
|
||||||
const queueKey =
|
const queueKey =
|
||||||
this.cluster === 'mainnet-beta'
|
this.cluster === 'mainnet-beta'
|
||||||
|
@ -403,9 +403,9 @@ export class SwitchboardProgram {
|
||||||
*/
|
*/
|
||||||
async loadPermissioned(): Promise<{
|
async loadPermissioned(): Promise<{
|
||||||
queueAccount: QueueAccount;
|
queueAccount: QueueAccount;
|
||||||
queue: types.OracleQueueAccountData;
|
queue: OracleQueueAccountData;
|
||||||
crankAccount: CrankAccount;
|
crankAccount: CrankAccount;
|
||||||
crank: types.CrankAccountData;
|
crank: CrankAccountData;
|
||||||
}> {
|
}> {
|
||||||
const queueKey =
|
const queueKey =
|
||||||
this.cluster === 'mainnet-beta'
|
this.cluster === 'mainnet-beta'
|
||||||
|
|
|
@ -92,12 +92,10 @@ export class SwitchboardTestContext {
|
||||||
alternateProgramId
|
alternateProgramId
|
||||||
);
|
);
|
||||||
|
|
||||||
const [userTokenWallet, userTokenInit] =
|
const [userTokenWallet] = await program.mint.getOrCreateWrappedUser(
|
||||||
await program.mint.getOrCreateWrappedUserInstructions(
|
program.walletPubkey,
|
||||||
program.walletPubkey,
|
{ fundUpTo: 1 }
|
||||||
{ fundUpTo: 1 }
|
);
|
||||||
);
|
|
||||||
await program.signAndSend(userTokenInit);
|
|
||||||
|
|
||||||
const programDataAddress = getProgramDataAddress(program.programId);
|
const programDataAddress = getProgramDataAddress(program.programId);
|
||||||
const idlAddress = await getIdlAddress(program.programId);
|
const idlAddress = await getIdlAddress(program.programId);
|
||||||
|
|
Loading…
Reference in New Issue