solana.js: published 2.0.97
This commit is contained in:
parent
75bbd243d5
commit
6d60e1c5c1
|
@ -1,19 +1,19 @@
|
|||
{
|
||||
"name": "@switchboard-xyz/solana.js",
|
||||
"version": "2.0.96",
|
||||
"version": "2.0.97",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@switchboard-xyz/solana.js",
|
||||
"version": "2.0.96",
|
||||
"version": "2.0.97",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@project-serum/anchor": "^0.26.0",
|
||||
"@project-serum/borsh": "^0.2.5",
|
||||
"@solana/spl-token": "^0.3.6",
|
||||
"@solana/web3.js": "^1.73.0",
|
||||
"@switchboard-xyz/common": "^2.1.8",
|
||||
"@switchboard-xyz/common": "^2.1.12",
|
||||
"big.js": "^6.2.1",
|
||||
"bn.js": "^5.2.1",
|
||||
"dotenv": "^16.0.3",
|
||||
|
@ -589,10 +589,11 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@switchboard-xyz/common": {
|
||||
"version": "2.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@switchboard-xyz/common/-/common-2.1.8.tgz",
|
||||
"integrity": "sha512-mqCDwCtBf3tY2Bvce0USR4m6DsXSqw8rn4luc2sjLL4PPFKCuCZVgzysfkwzwBHoipbnx6odRQ+BIfm35nhWDA==",
|
||||
"version": "2.1.12",
|
||||
"resolved": "https://registry.npmjs.org/@switchboard-xyz/common/-/common-2.1.12.tgz",
|
||||
"integrity": "sha512-eQ3JSybbmNG0AqHsSUXS1hKZvE21JZ9HV6s9wRNXtQhMVw9sy92NyIze5RDfyxs9mbPsrFhkqaJh+nl6TnU3rQ==",
|
||||
"dependencies": {
|
||||
"@solana/web3.js": "^1.66.2",
|
||||
"big.js": "^6.2.1",
|
||||
"bn.js": "^5.2.1",
|
||||
"decimal.js": "^10.4.3",
|
||||
|
@ -5701,10 +5702,11 @@
|
|||
}
|
||||
},
|
||||
"@switchboard-xyz/common": {
|
||||
"version": "2.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@switchboard-xyz/common/-/common-2.1.8.tgz",
|
||||
"integrity": "sha512-mqCDwCtBf3tY2Bvce0USR4m6DsXSqw8rn4luc2sjLL4PPFKCuCZVgzysfkwzwBHoipbnx6odRQ+BIfm35nhWDA==",
|
||||
"version": "2.1.12",
|
||||
"resolved": "https://registry.npmjs.org/@switchboard-xyz/common/-/common-2.1.12.tgz",
|
||||
"integrity": "sha512-eQ3JSybbmNG0AqHsSUXS1hKZvE21JZ9HV6s9wRNXtQhMVw9sy92NyIze5RDfyxs9mbPsrFhkqaJh+nl6TnU3rQ==",
|
||||
"requires": {
|
||||
"@solana/web3.js": "^1.66.2",
|
||||
"big.js": "^6.2.1",
|
||||
"bn.js": "^5.2.1",
|
||||
"decimal.js": "^10.4.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@switchboard-xyz/solana.js",
|
||||
"version": "2.0.96",
|
||||
"version": "2.0.97",
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"description": "API wrapper for integrating with the Switchboard V2 program on Solana",
|
||||
|
@ -51,7 +51,7 @@
|
|||
"@project-serum/borsh": "^0.2.5",
|
||||
"@solana/spl-token": "^0.3.6",
|
||||
"@solana/web3.js": "^1.73.0",
|
||||
"@switchboard-xyz/common": "^2.1.8",
|
||||
"@switchboard-xyz/common": "^2.1.12",
|
||||
"big.js": "^6.2.1",
|
||||
"bn.js": "^5.2.1",
|
||||
"dotenv": "^16.0.3",
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import {
|
||||
DockerOracle,
|
||||
IOracleBaseConfig,
|
||||
ISolanaOracleConfig,
|
||||
} from '@switchboard-xyz/common';
|
||||
import path from 'path';
|
||||
|
||||
export type SolanaOracleConfig = Omit<IOracleBaseConfig, 'chain'> &
|
||||
ISolanaOracleConfig;
|
||||
|
||||
export class SolanaDockerOracle extends DockerOracle {
|
||||
constructor(
|
||||
config: SolanaOracleConfig,
|
||||
readonly nodeImage: string,
|
||||
readonly switchboardDirectory = path.join(process.cwd(), '.switchboard'),
|
||||
readonly silent = false
|
||||
) {
|
||||
super(
|
||||
{ ...config, chain: 'solana' },
|
||||
nodeImage,
|
||||
switchboardDirectory,
|
||||
silent
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
export * from './accounts';
|
||||
export * from './SolanaDockerOracle';
|
||||
export * from './const';
|
||||
export * from './errors';
|
||||
export * as types from './generated';
|
||||
|
|
|
@ -71,7 +71,7 @@ export class Mint {
|
|||
public async getAssociatedAccount(
|
||||
owner: PublicKey
|
||||
): Promise<spl.Account | null> {
|
||||
const ownerTokenAddress = Mint.getAssociatedAddress(owner);
|
||||
const ownerTokenAddress = this.getAssociatedAddress(owner);
|
||||
const ownerTokenAccountInfo = await this.provider.connection.getAccountInfo(
|
||||
ownerTokenAddress
|
||||
);
|
||||
|
@ -110,16 +110,15 @@ export class Mint {
|
|||
}
|
||||
|
||||
public getAssociatedAddress(user: PublicKey): PublicKey {
|
||||
return Mint.getAssociatedAddress(user);
|
||||
return Mint.getAssociatedAddress(user, this.mint.address);
|
||||
}
|
||||
|
||||
public static getAssociatedAddress(owner: PublicKey): PublicKey {
|
||||
public static getAssociatedAddress(
|
||||
owner: PublicKey,
|
||||
mint: PublicKey
|
||||
): PublicKey {
|
||||
const [associatedToken] = anchor.utils.publicKey.findProgramAddressSync(
|
||||
[
|
||||
owner.toBuffer(),
|
||||
spl.TOKEN_PROGRAM_ID.toBuffer(),
|
||||
Mint.native.toBuffer(),
|
||||
],
|
||||
[owner.toBuffer(), spl.TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()],
|
||||
spl.ASSOCIATED_TOKEN_PROGRAM_ID
|
||||
);
|
||||
return associatedToken;
|
||||
|
@ -130,7 +129,7 @@ export class Mint {
|
|||
user?: PublicKey
|
||||
): Promise<PublicKey> {
|
||||
const owner = user ?? payer;
|
||||
const associatedToken = Mint.getAssociatedAddress(owner);
|
||||
const associatedToken = this.getAssociatedAddress(owner);
|
||||
const accountInfo = await this.connection.getAccountInfo(associatedToken);
|
||||
if (accountInfo === null) {
|
||||
await this.createAssocatedUser(payer, user);
|
||||
|
@ -155,10 +154,11 @@ export class Mint {
|
|||
|
||||
public static createAssocatedUserInstruction(
|
||||
payer: PublicKey,
|
||||
mint: PublicKey,
|
||||
user?: PublicKey
|
||||
): [TransactionObject, PublicKey] {
|
||||
const owner = user ?? payer;
|
||||
const associatedToken = Mint.getAssociatedAddress(owner);
|
||||
const associatedToken = Mint.getAssociatedAddress(owner, mint);
|
||||
const ixn = spl.createAssociatedTokenAccountInstruction(
|
||||
payer,
|
||||
associatedToken,
|
||||
|
@ -172,15 +172,16 @@ export class Mint {
|
|||
payer: PublicKey,
|
||||
user?: PublicKey
|
||||
): [TransactionObject, PublicKey] {
|
||||
return Mint.createAssocatedUserInstruction(payer, user);
|
||||
return Mint.createAssocatedUserInstruction(payer, this.mint.address, user);
|
||||
}
|
||||
|
||||
public static createUserInstruction(
|
||||
payer: PublicKey,
|
||||
mint: PublicKey,
|
||||
user?: Keypair
|
||||
): [PublicKey, TransactionObject] {
|
||||
const owner = user ? user.publicKey : payer;
|
||||
const account = Mint.getAssociatedAddress(owner);
|
||||
const account = Mint.getAssociatedAddress(owner, mint);
|
||||
const ixn = spl.createInitializeAccountInstruction(
|
||||
account,
|
||||
Mint.native,
|
||||
|
@ -193,7 +194,7 @@ export class Mint {
|
|||
payer: PublicKey,
|
||||
user?: Keypair
|
||||
): [PublicKey, TransactionObject] {
|
||||
return Mint.createUserInstruction(payer, user);
|
||||
return Mint.createUserInstruction(payer, this.mint.address, user);
|
||||
}
|
||||
|
||||
public async createUser(
|
||||
|
@ -223,6 +224,8 @@ export class Mint {
|
|||
}
|
||||
|
||||
export class NativeMint extends Mint {
|
||||
public static address = Mint.native;
|
||||
|
||||
public static async load(
|
||||
provider: anchor.AnchorProvider
|
||||
): Promise<NativeMint> {
|
||||
|
@ -259,7 +262,10 @@ export class NativeMint extends Mint {
|
|||
user?: Keypair
|
||||
): Promise<[PublicKey, TransactionObject | undefined]> {
|
||||
const owner = user ? user.publicKey : payer;
|
||||
const associatedToken = Mint.getAssociatedAddress(owner);
|
||||
const associatedToken = Mint.getAssociatedAddress(
|
||||
owner,
|
||||
NativeMint.address
|
||||
);
|
||||
const accountInfo = await this.connection.getAccountInfo(associatedToken);
|
||||
|
||||
if (accountInfo === null) {
|
||||
|
|
Loading…
Reference in New Issue