@helium/spl-utils
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -58,8 +58,8 @@ "use strict"; | ||
} | ||
connection.sendTransaction = function overloadedSendTransaction(transaction, signers, options) { | ||
connection.sendTransaction = function overloadedSendTransaction(...args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield self.oldSendTransaction(transaction, signers, options); | ||
const result = yield self.oldSendTransaction(...args); | ||
this.confirmTransaction(result, "finalized") | ||
.then(() => { | ||
return self.requeryMissing(transaction.instructions); | ||
return self.requeryMissing(args[0].instructions); | ||
}) | ||
@@ -66,0 +66,0 @@ .catch(console.error); |
@@ -17,6 +17,8 @@ "use strict"; | ||
function ataResolver({ instruction, account, mint, owner, }) { | ||
return (0, individual_1.resolveIndividual)(({ path, accounts, idlIx }) => __awaiter(this, void 0, void 0, function* () { | ||
if (idlIx.name === instruction && path.join(".") === account) { | ||
return (0, individual_1.resolveIndividual)(({ path, accounts, idlIx, provider }) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
if ((typeof instruction === "undefined" || idlIx.name === instruction) && path.join(".") === account) { | ||
const mintKey = (0, utils_1.get)(accounts, mint.split(".")); | ||
const ownerKey = (0, utils_1.get)(accounts, owner.split(".")); | ||
// @ts-ignore | ||
const ownerKey = owner ? (0, utils_1.get)(accounts, owner.split(".")) : (_a = provider.wallet) === null || _a === void 0 ? void 0 : _a.publicKey; | ||
if (mintKey && ownerKey) { | ||
@@ -23,0 +25,0 @@ return (0, spl_token_1.getAssociatedTokenAddress)(mintKey, ownerKey, true); |
@@ -29,2 +29,10 @@ "use strict"; | ||
return new web3_js_1.PublicKey("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); | ||
case "governanceProgramId": | ||
return new web3_js_1.PublicKey("GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"); | ||
case "voterStakeRegistryProgramId": | ||
return new web3_js_1.PublicKey("hvsrY9UBtHhYRvstM2BWCsni81kevfn7B2DEhYbGA1a"); | ||
case "vsrProgram": | ||
return new web3_js_1.PublicKey("hvsrY9UBtHhYRvstM2BWCsni81kevfn7B2DEhYbGA1a"); | ||
case "instructions": | ||
return new web3_js_1.PublicKey("Sysvar1nstructions1111111111111111111111111"); | ||
default: | ||
@@ -31,0 +39,0 @@ return; |
@@ -21,39 +21,45 @@ "use strict"; | ||
const newPath = [...path, (0, camelcase_1.default)(idlAccounts.name)]; | ||
if (idlAccounts.accounts) { | ||
let resolved = 0; | ||
const subAccounts = idlAccounts.accounts; | ||
for (let k = 0; k < subAccounts.length; k += 1) { | ||
const subAccount = subAccounts[k]; | ||
resolved += yield resolveIndividualImpl({ | ||
idlAccounts: subAccount, | ||
programId, | ||
provider, | ||
args, | ||
accounts, | ||
path: newPath, | ||
resolver, | ||
idlIx, | ||
}); | ||
try { | ||
if (idlAccounts.accounts) { | ||
let resolved = 0; | ||
const subAccounts = idlAccounts.accounts; | ||
for (let k = 0; k < subAccounts.length; k += 1) { | ||
const subAccount = subAccounts[k]; | ||
resolved += yield resolveIndividualImpl({ | ||
idlAccounts: subAccount, | ||
programId, | ||
provider, | ||
args, | ||
accounts, | ||
path: newPath, | ||
resolver, | ||
idlIx, | ||
}); | ||
} | ||
return resolved; | ||
} | ||
return resolved; | ||
} | ||
else { | ||
let resolved = 0; | ||
let value = (0, utils_1.get)(accounts, newPath); | ||
if (!value) { | ||
value = yield resolver({ | ||
programId, | ||
provider, | ||
path: newPath, | ||
args, | ||
accounts, | ||
idlIx, | ||
}); | ||
if (value) { | ||
resolved = 1; | ||
else { | ||
let resolved = 0; | ||
let value = (0, utils_1.get)(accounts, newPath); | ||
if (!value) { | ||
value = yield resolver({ | ||
programId, | ||
provider, | ||
path: newPath, | ||
args, | ||
accounts, | ||
idlIx, | ||
}); | ||
if (value) { | ||
resolved = 1; | ||
} | ||
} | ||
(0, utils_1.set)(accounts, newPath, value); | ||
return resolved; | ||
} | ||
(0, utils_1.set)(accounts, newPath, value); | ||
return resolved; | ||
} | ||
catch (e) { | ||
console.error(`Error while resolving ${newPath}`, e); | ||
throw e; | ||
} | ||
}); | ||
@@ -60,0 +66,0 @@ } |
@@ -18,4 +18,5 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
// @ts-ignore | ||
const bs58_1 = __importDefault(require("bs58")); | ||
function getAsset(url, assetId) { | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -31,3 +32,3 @@ try { | ||
if (result) { | ||
return Object.assign(Object.assign({}, result), { id: new web3_js_1.PublicKey(result.id), compression: Object.assign(Object.assign({}, result.compression), { dataHash: (_a = result.compression.dataHash) !== null && _a !== void 0 ? _a : new web3_js_1.PublicKey(result.compression.dataHash).toBase58(), creatorHash: (_b = result.compression.creatorHash) !== null && _b !== void 0 ? _b : new web3_js_1.PublicKey(result.compression.creatorHash).toBase58(), assetHash: (_c = result.compression.assetHash) !== null && _c !== void 0 ? _c : new web3_js_1.PublicKey(result.compression.assetHash).toBase58(), tree: (_d = result.compression.tree) !== null && _d !== void 0 ? _d : new web3_js_1.PublicKey(result.compression.tree).toBase58() }), ownership: Object.assign(Object.assign({}, result.ownership), { owner: new web3_js_1.PublicKey(result.ownership.owner) }) }); | ||
return toAsset(result); | ||
} | ||
@@ -42,2 +43,6 @@ } | ||
exports.getAsset = getAsset; | ||
function toAsset(result) { | ||
var _a, _b, _c, _d, _e; | ||
return Object.assign(Object.assign({}, result), { id: new web3_js_1.PublicKey(result.id), compression: Object.assign(Object.assign({}, result.compression), { dataHash: (_a = result.compression.data_hash) !== null && _a !== void 0 ? _a : bs58_1.default.decode(result.compression.data_hash), creatorHash: (_b = result.compression.creator_hash) !== null && _b !== void 0 ? _b : bs58_1.default.decode(result.compression.creator_hash), assetHash: (_c = result.compression.asset_hash) !== null && _c !== void 0 ? _c : bs58_1.default.decode(result.compression.asset_hash), tree: (_d = result.compression.tree) !== null && _d !== void 0 ? _d : bs58_1.default.decode(result.compression.tree) }), ownership: Object.assign(Object.assign({}, result.ownership), { owner: (_e = result.ownership.owner) !== null && _e !== void 0 ? _e : new web3_js_1.PublicKey(result.ownership.owner) }) }); | ||
} | ||
function getAssetProof(url, assetId) { | ||
@@ -80,3 +85,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
}); | ||
return (_a = response.data.result) === null || _a === void 0 ? void 0 : _a.items; | ||
return (_a = response.data.result) === null || _a === void 0 ? void 0 : _a.items.map(toAsset); | ||
} | ||
@@ -83,0 +88,0 @@ catch (error) { |
@@ -31,2 +31,5 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (instructions.length == 0) { | ||
return ""; | ||
} | ||
let tx = new web3_js_1.Transaction(); | ||
@@ -33,0 +36,0 @@ tx.recentBlockhash = (yield provider.connection.getRecentBlockhash()).blockhash; |
@@ -54,7 +54,7 @@ import { Connection, PublicKey, Transaction } from "@solana/web3.js"; | ||
} | ||
connection.sendTransaction = async function overloadedSendTransaction(transaction, signers, options) { | ||
const result = await self.oldSendTransaction(transaction, signers, options); | ||
connection.sendTransaction = async function overloadedSendTransaction(...args) { | ||
const result = await self.oldSendTransaction(...args); | ||
this.confirmTransaction(result, "finalized") | ||
.then(() => { | ||
return self.requeryMissing(transaction.instructions); | ||
return self.requeryMissing(args[0].instructions); | ||
}) | ||
@@ -61,0 +61,0 @@ .catch(console.error); |
@@ -5,6 +5,7 @@ import { resolveIndividual } from "./individual"; | ||
export function ataResolver({ instruction, account, mint, owner, }) { | ||
return resolveIndividual(async ({ path, accounts, idlIx }) => { | ||
if (idlIx.name === instruction && path.join(".") === account) { | ||
return resolveIndividual(async ({ path, accounts, idlIx, provider }) => { | ||
if ((typeof instruction === "undefined" || idlIx.name === instruction) && path.join(".") === account) { | ||
const mintKey = get(accounts, mint.split(".")); | ||
const ownerKey = get(accounts, owner.split(".")); | ||
// @ts-ignore | ||
const ownerKey = owner ? get(accounts, owner.split(".")) : provider.wallet?.publicKey; | ||
if (mintKey && ownerKey) { | ||
@@ -11,0 +12,0 @@ return getAssociatedTokenAddress(mintKey, ownerKey, true); |
@@ -17,2 +17,10 @@ import { PublicKey } from "@solana/web3.js"; | ||
return new PublicKey("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); | ||
case "governanceProgramId": | ||
return new PublicKey("GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"); | ||
case "voterStakeRegistryProgramId": | ||
return new PublicKey("hvsrY9UBtHhYRvstM2BWCsni81kevfn7B2DEhYbGA1a"); | ||
case "vsrProgram": | ||
return new PublicKey("hvsrY9UBtHhYRvstM2BWCsni81kevfn7B2DEhYbGA1a"); | ||
case "instructions": | ||
return new PublicKey("Sysvar1nstructions1111111111111111111111111"); | ||
default: | ||
@@ -19,0 +27,0 @@ return; |
@@ -5,39 +5,45 @@ import camelCase from "camelcase"; | ||
const newPath = [...path, camelCase(idlAccounts.name)]; | ||
if (idlAccounts.accounts) { | ||
let resolved = 0; | ||
const subAccounts = idlAccounts.accounts; | ||
for (let k = 0; k < subAccounts.length; k += 1) { | ||
const subAccount = subAccounts[k]; | ||
resolved += await resolveIndividualImpl({ | ||
idlAccounts: subAccount, | ||
programId, | ||
provider, | ||
args, | ||
accounts, | ||
path: newPath, | ||
resolver, | ||
idlIx, | ||
}); | ||
try { | ||
if (idlAccounts.accounts) { | ||
let resolved = 0; | ||
const subAccounts = idlAccounts.accounts; | ||
for (let k = 0; k < subAccounts.length; k += 1) { | ||
const subAccount = subAccounts[k]; | ||
resolved += await resolveIndividualImpl({ | ||
idlAccounts: subAccount, | ||
programId, | ||
provider, | ||
args, | ||
accounts, | ||
path: newPath, | ||
resolver, | ||
idlIx, | ||
}); | ||
} | ||
return resolved; | ||
} | ||
return resolved; | ||
} | ||
else { | ||
let resolved = 0; | ||
let value = get(accounts, newPath); | ||
if (!value) { | ||
value = await resolver({ | ||
programId, | ||
provider, | ||
path: newPath, | ||
args, | ||
accounts, | ||
idlIx, | ||
}); | ||
if (value) { | ||
resolved = 1; | ||
else { | ||
let resolved = 0; | ||
let value = get(accounts, newPath); | ||
if (!value) { | ||
value = await resolver({ | ||
programId, | ||
provider, | ||
path: newPath, | ||
args, | ||
accounts, | ||
idlIx, | ||
}); | ||
if (value) { | ||
resolved = 1; | ||
} | ||
} | ||
set(accounts, newPath, value); | ||
return resolved; | ||
} | ||
set(accounts, newPath, value); | ||
return resolved; | ||
} | ||
catch (e) { | ||
console.error(`Error while resolving ${newPath}`, e); | ||
throw e; | ||
} | ||
} | ||
@@ -44,0 +50,0 @@ /** |
import { PublicKey } from "@solana/web3.js"; | ||
import axios from "axios"; | ||
// @ts-ignore | ||
import base58 from "bs58"; | ||
export async function getAsset(url, assetId) { | ||
@@ -13,21 +15,3 @@ try { | ||
if (result) { | ||
return { | ||
...result, | ||
id: new PublicKey(result.id), | ||
compression: { | ||
...result.compression, | ||
dataHash: result.compression.dataHash ?? | ||
new PublicKey(result.compression.dataHash).toBase58(), | ||
creatorHash: result.compression.creatorHash ?? | ||
new PublicKey(result.compression.creatorHash).toBase58(), | ||
assetHash: result.compression.assetHash ?? | ||
new PublicKey(result.compression.assetHash).toBase58(), | ||
tree: result.compression.tree ?? | ||
new PublicKey(result.compression.tree).toBase58(), | ||
}, | ||
ownership: { | ||
...result.ownership, | ||
owner: new PublicKey(result.ownership.owner), | ||
}, | ||
}; | ||
return toAsset(result); | ||
} | ||
@@ -40,2 +24,22 @@ } | ||
} | ||
function toAsset(result) { | ||
return { | ||
...result, | ||
id: new PublicKey(result.id), | ||
compression: { | ||
...result.compression, | ||
dataHash: result.compression.data_hash ?? | ||
base58.decode(result.compression.data_hash), | ||
creatorHash: result.compression.creator_hash ?? | ||
base58.decode(result.compression.creator_hash), | ||
assetHash: result.compression.asset_hash ?? | ||
base58.decode(result.compression.asset_hash), | ||
tree: result.compression.tree ?? base58.decode(result.compression.tree), | ||
}, | ||
ownership: { | ||
...result.ownership, | ||
owner: result.ownership.owner ?? new PublicKey(result.ownership.owner), | ||
}, | ||
}; | ||
} | ||
export async function getAssetProof(url, assetId) { | ||
@@ -73,3 +77,3 @@ try { | ||
}); | ||
return response.data.result?.items; | ||
return response.data.result?.items.map(toAsset); | ||
} | ||
@@ -76,0 +80,0 @@ catch (error) { |
@@ -1,4 +0,4 @@ | ||
import { createCreateMasterEditionV3Instruction, createCreateMetadataAccountV3Instruction, createVerifyCollectionInstruction, PROGRAM_ID as METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata"; | ||
import { createAssociatedTokenAccountInstruction, createInitializeMintInstruction, createMintToInstruction, createTransferInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from "@solana/spl-token"; | ||
import { Keypair, PublicKey, SystemProgram, Transaction } from "@solana/web3.js"; | ||
import { createCreateMasterEditionV3Instruction, createCreateMetadataAccountV3Instruction, createVerifyCollectionInstruction, PROGRAM_ID as METADATA_PROGRAM_ID, } from "@metaplex-foundation/mpl-token-metadata"; | ||
import { createAssociatedTokenAccountInstruction, createInitializeMintInstruction, createMintToInstruction, createTransferInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID, } from "@solana/spl-token"; | ||
import { Keypair, PublicKey, SystemProgram, Transaction, } from "@solana/web3.js"; | ||
export async function mintTo(provider, mint, amount, destination) { | ||
@@ -5,0 +5,0 @@ const mintTx = new Transaction(); |
@@ -14,2 +14,5 @@ import { Transaction, } from "@solana/web3.js"; | ||
export async function sendInstructions(provider, instructions, signers = [], payer = provider.wallet.publicKey, commitment = "confirmed", idlErrors = new Map()) { | ||
if (instructions.length == 0) { | ||
return ""; | ||
} | ||
let tx = new Transaction(); | ||
@@ -16,0 +19,0 @@ tx.recentBlockhash = (await provider.connection.getRecentBlockhash()).blockhash; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { AccountInfo, Commitment, Connection, PublicKey, SendOptions, Signer, Transaction, TransactionInstruction } from "@solana/web3.js"; | ||
import { AccountInfo, Commitment, Connection, PublicKey, SendOptions, TransactionInstruction } from "@solana/web3.js"; | ||
import { EventEmitter } from "./eventEmitter"; | ||
export declare const DEFAULT_CHUNK_SIZE = 99; | ||
export declare const DEFAULT_DELAY = 50; | ||
export declare type TypedAccountParser<T> = (pubkey: PublicKey, data: AccountInfo<Buffer>) => T; | ||
export type TypedAccountParser<T> = (pubkey: PublicKey, data: AccountInfo<Buffer>) => T; | ||
export interface ParsedAccountBase<T> { | ||
@@ -13,3 +13,3 @@ pubkey: PublicKey; | ||
} | ||
export declare type AccountParser<T> = (pubkey: PublicKey, data: AccountInfo<Buffer>) => ParsedAccountBase<T> | undefined; | ||
export type AccountParser<T> = (pubkey: PublicKey, data: AccountInfo<Buffer>) => ParsedAccountBase<T> | undefined; | ||
export declare class AccountFetchCache { | ||
@@ -32,3 +32,3 @@ connection: Connection; | ||
oldGetAccountinfo?: (publicKey: PublicKey, com?: Commitment) => Promise<AccountInfo<Buffer> | null>; | ||
oldSendTransaction: (transaction: Transaction, signers: Array<Signer>, options?: SendOptions) => Promise<string>; | ||
oldSendTransaction: (...args: any[]) => Promise<string>; | ||
oldSendRawTransaction: (rawTransaction: Buffer | Uint8Array | Array<number>, options?: SendOptions) => Promise<string>; | ||
@@ -35,0 +35,0 @@ missingInterval: NodeJS.Timeout; |
import * as anchor from "@project-serum/anchor"; | ||
export declare type AtaResolverArgs = { | ||
instruction: string; | ||
export type AtaResolverArgs = { | ||
instruction?: string; | ||
account: string; | ||
mint: string; | ||
owner: string; | ||
owner?: string; | ||
}; | ||
export declare function ataResolver<T extends anchor.Idl>({ instruction, account, mint, owner, }: AtaResolverArgs): anchor.CustomAccountResolver<T>; | ||
//# sourceMappingURL=ataResolver.d.ts.map |
@@ -6,3 +6,3 @@ import * as anchor from "@project-serum/anchor"; | ||
import { Accounts } from "./utils"; | ||
declare type IndividualResolver = (args: { | ||
type IndividualResolver = (args: { | ||
programId: PublicKey; | ||
@@ -9,0 +9,0 @@ provider: anchor.Provider; |
import { PublicKey } from "@solana/web3.js"; | ||
export declare type Accounts = { | ||
export type Accounts = { | ||
[name: string]: PublicKey | Accounts; | ||
@@ -4,0 +4,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
export declare type StringPublicKey = string; | ||
export type StringPublicKey = string; | ||
export declare const extendBorsh: () => void; | ||
//# sourceMappingURL=extendBorsh.d.ts.map |
/// <reference types="node" /> | ||
import { PublicKey } from "@solana/web3.js"; | ||
export declare type AssetProof = { | ||
export type AssetProof = { | ||
root: PublicKey; | ||
@@ -10,3 +10,3 @@ proof: PublicKey[]; | ||
}; | ||
export declare type Asset = { | ||
export type Asset = { | ||
id: PublicKey; | ||
@@ -29,3 +29,3 @@ content: any; | ||
export declare function getAssetProof(url: string, assetId: PublicKey): Promise<AssetProof | undefined>; | ||
export declare type AssetsByOwnerOpts = { | ||
export type AssetsByOwnerOpts = { | ||
sortBy?: any; | ||
@@ -32,0 +32,0 @@ limit?: number; |
import BN from "bn.js"; | ||
import { Mint } from "@solana/spl-token"; | ||
export declare type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T; | ||
export type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T; | ||
export declare const truthy: <T>(value: T) => value is Truthy<T>; | ||
@@ -5,0 +5,0 @@ export declare function toNumber(numberOrBn: bigint | BN | number, mintOrDecimals: Mint | number): number; |
{ | ||
"name": "@helium/spl-utils", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Utils shared across spl suite", | ||
@@ -34,3 +34,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@project-serum/anchor": "0.24.2", | ||
"@project-serum/anchor": "0.26.0", | ||
"@solana/web3.js": "^1.43.4", | ||
@@ -45,3 +45,3 @@ "bn.js": "^5.2.0", | ||
}, | ||
"gitHead": "fede087053d338a16cf5d4d74881af6b1248b37b" | ||
"gitHead": "ed88653af069954a3d84e2b50ea8cc696ad65d21" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3763
385833
3
115
+ Added@coral-xyz/borsh@0.26.0(transitive)
+ Added@project-serum/anchor@0.26.0(transitive)
+ Addedcamelcase@6.3.0(transitive)
+ Addedcross-fetch@3.2.0(transitive)
+ Addedsuperstruct@0.15.5(transitive)
- Removed@project-serum/anchor@0.24.2(transitive)
- Removed@project-serum/borsh@0.2.5(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcross-fetch@3.1.8(transitive)
Updated@project-serum/anchor@0.26.0