@solana/web3.js 1.17.1 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.esm.js +118 -10
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +118 -9
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +43 -18
- package/lib/index.esm.js +118 -10
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +118 -9
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +1 -1
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +57 -34
- package/package.json +2 -2
- package/src/connection.ts +23 -21
- package/src/epoch-schedule.ts +102 -0
- package/src/index.ts +1 -0
package/lib/index.d.ts
CHANGED
|
@@ -121,6 +121,36 @@ declare module '@solana/web3.js' {
|
|
|
121
121
|
|
|
122
122
|
export const BPF_LOADER_DEPRECATED_PROGRAM_ID: PublicKey;
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Epoch schedule
|
|
126
|
+
* (see https://docs.solana.com/terminology#epoch)
|
|
127
|
+
* Can be retrieved with the {@link connection.getEpochSchedule} method
|
|
128
|
+
*/
|
|
129
|
+
export class EpochSchedule {
|
|
130
|
+
/** The maximum number of slots in each epoch */
|
|
131
|
+
slotsPerEpoch: number;
|
|
132
|
+
/** The number of slots before beginning of an epoch to calculate a leader schedule for that epoch */
|
|
133
|
+
leaderScheduleSlotOffset: number;
|
|
134
|
+
/** Indicates whether epochs start short and grow */
|
|
135
|
+
warmup: boolean;
|
|
136
|
+
/** The first epoch with `slotsPerEpoch` slots */
|
|
137
|
+
firstNormalEpoch: number;
|
|
138
|
+
/** The first slot of `firstNormalEpoch` */
|
|
139
|
+
firstNormalSlot: number;
|
|
140
|
+
constructor(
|
|
141
|
+
slotsPerEpoch: number,
|
|
142
|
+
leaderScheduleSlotOffset: number,
|
|
143
|
+
warmup: boolean,
|
|
144
|
+
firstNormalEpoch: number,
|
|
145
|
+
firstNormalSlot: number,
|
|
146
|
+
);
|
|
147
|
+
getEpoch(slot: number): number;
|
|
148
|
+
getEpochAndSlotIndex(slot: number): [number, number];
|
|
149
|
+
getFirstSlotInEpoch(epoch: number): number;
|
|
150
|
+
getLastSlotInEpoch(epoch: number): number;
|
|
151
|
+
getSlotsInEpoch(epoch: number): number;
|
|
152
|
+
}
|
|
153
|
+
|
|
124
154
|
/**
|
|
125
155
|
* Calculator for transaction fees.
|
|
126
156
|
*/
|
|
@@ -651,22 +681,6 @@ declare module '@solana/web3.js' {
|
|
|
651
681
|
blockHeight?: number;
|
|
652
682
|
transactionCount?: number;
|
|
653
683
|
};
|
|
654
|
-
/**
|
|
655
|
-
* Epoch schedule
|
|
656
|
-
* (see https://docs.solana.com/terminology#epoch)
|
|
657
|
-
*/
|
|
658
|
-
export type EpochSchedule = {
|
|
659
|
-
/** The maximum number of slots in each epoch */
|
|
660
|
-
slotsPerEpoch: number;
|
|
661
|
-
/** The number of slots before beginning of an epoch to calculate a leader schedule for that epoch */
|
|
662
|
-
leaderScheduleSlotOffset: number;
|
|
663
|
-
/** Indicates whether epochs start short and grow */
|
|
664
|
-
warmup: boolean;
|
|
665
|
-
/** The first epoch with `slotsPerEpoch` slots */
|
|
666
|
-
firstNormalEpoch: number;
|
|
667
|
-
/** The first slot of `firstNormalEpoch` */
|
|
668
|
-
firstNormalSlot: number;
|
|
669
|
-
};
|
|
670
684
|
/**
|
|
671
685
|
* Leader schedule
|
|
672
686
|
* (see https://docs.solana.com/terminology#leader-schedule)
|
|
@@ -1682,11 +1696,22 @@ declare module '@solana/web3.js' {
|
|
|
1682
1696
|
commitment?: Commitment,
|
|
1683
1697
|
): Promise<NonceAccount | null>;
|
|
1684
1698
|
/**
|
|
1685
|
-
* Request an allocation of lamports to the specified
|
|
1699
|
+
* Request an allocation of lamports to the specified address
|
|
1700
|
+
*
|
|
1701
|
+
* ```typescript
|
|
1702
|
+
* import { Connection, PublicKey, LAMPORTS_PER_SOL } from "@solana/web3.js";
|
|
1703
|
+
*
|
|
1704
|
+
* (async () => {
|
|
1705
|
+
* const connection = new Connection("https://api.testnet.solana.com", "confirmed");
|
|
1706
|
+
* const myAddress = new PublicKey("2nr1bHFT86W9tGnyvmYW4vcHKsQB3sVQfnddasz4kExM");
|
|
1707
|
+
* const signature = await connection.requestAirdrop(myAddress, LAMPORTS_PER_SOL);
|
|
1708
|
+
* await connection.confirmTransaction(signature);
|
|
1709
|
+
* })();
|
|
1710
|
+
* ```
|
|
1686
1711
|
*/
|
|
1687
1712
|
requestAirdrop(
|
|
1688
1713
|
to: PublicKey,
|
|
1689
|
-
|
|
1714
|
+
lamports: number,
|
|
1690
1715
|
): Promise<TransactionSignature>;
|
|
1691
1716
|
/**
|
|
1692
1717
|
* Simulate a transaction
|
package/lib/index.esm.js
CHANGED
|
@@ -2342,6 +2342,107 @@ class AgentManager {
|
|
|
2342
2342
|
|
|
2343
2343
|
}
|
|
2344
2344
|
|
|
2345
|
+
const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
|
|
2346
|
+
|
|
2347
|
+
function trailingZeros(n) {
|
|
2348
|
+
let trailingZeros = 0;
|
|
2349
|
+
|
|
2350
|
+
while (n > 1) {
|
|
2351
|
+
n /= 2;
|
|
2352
|
+
trailingZeros++;
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
return trailingZeros;
|
|
2356
|
+
} // Returns the smallest power of two greater than or equal to n
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
function nextPowerOfTwo(n) {
|
|
2360
|
+
if (n === 0) return 1;
|
|
2361
|
+
n--;
|
|
2362
|
+
n |= n >> 1;
|
|
2363
|
+
n |= n >> 2;
|
|
2364
|
+
n |= n >> 4;
|
|
2365
|
+
n |= n >> 8;
|
|
2366
|
+
n |= n >> 16;
|
|
2367
|
+
n |= n >> 32;
|
|
2368
|
+
return n + 1;
|
|
2369
|
+
}
|
|
2370
|
+
/**
|
|
2371
|
+
* Epoch schedule
|
|
2372
|
+
* (see https://docs.solana.com/terminology#epoch)
|
|
2373
|
+
* Can be retrieved with the {@link connection.getEpochSchedule} method
|
|
2374
|
+
*/
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
class EpochSchedule {
|
|
2378
|
+
/** The maximum number of slots in each epoch */
|
|
2379
|
+
|
|
2380
|
+
/** The number of slots before beginning of an epoch to calculate a leader schedule for that epoch */
|
|
2381
|
+
|
|
2382
|
+
/** Indicates whether epochs start short and grow */
|
|
2383
|
+
|
|
2384
|
+
/** The first epoch with `slotsPerEpoch` slots */
|
|
2385
|
+
|
|
2386
|
+
/** The first slot of `firstNormalEpoch` */
|
|
2387
|
+
constructor(slotsPerEpoch, leaderScheduleSlotOffset, warmup, firstNormalEpoch, firstNormalSlot) {
|
|
2388
|
+
_defineProperty(this, "slotsPerEpoch", void 0);
|
|
2389
|
+
|
|
2390
|
+
_defineProperty(this, "leaderScheduleSlotOffset", void 0);
|
|
2391
|
+
|
|
2392
|
+
_defineProperty(this, "warmup", void 0);
|
|
2393
|
+
|
|
2394
|
+
_defineProperty(this, "firstNormalEpoch", void 0);
|
|
2395
|
+
|
|
2396
|
+
_defineProperty(this, "firstNormalSlot", void 0);
|
|
2397
|
+
|
|
2398
|
+
this.slotsPerEpoch = slotsPerEpoch;
|
|
2399
|
+
this.leaderScheduleSlotOffset = leaderScheduleSlotOffset;
|
|
2400
|
+
this.warmup = warmup;
|
|
2401
|
+
this.firstNormalEpoch = firstNormalEpoch;
|
|
2402
|
+
this.firstNormalSlot = firstNormalSlot;
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
getEpoch(slot) {
|
|
2406
|
+
return this.getEpochAndSlotIndex(slot)[0];
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
getEpochAndSlotIndex(slot) {
|
|
2410
|
+
if (slot < this.firstNormalSlot) {
|
|
2411
|
+
const epoch = trailingZeros(nextPowerOfTwo(slot + MINIMUM_SLOT_PER_EPOCH + 1)) - trailingZeros(MINIMUM_SLOT_PER_EPOCH) - 1;
|
|
2412
|
+
const epochLen = this.getSlotsInEpoch(epoch);
|
|
2413
|
+
const slotIndex = slot - (epochLen - MINIMUM_SLOT_PER_EPOCH);
|
|
2414
|
+
return [epoch, slotIndex];
|
|
2415
|
+
} else {
|
|
2416
|
+
const normalSlotIndex = slot - this.firstNormalSlot;
|
|
2417
|
+
const normalEpochIndex = Math.floor(normalSlotIndex / this.slotsPerEpoch);
|
|
2418
|
+
const epoch = this.firstNormalEpoch + normalEpochIndex;
|
|
2419
|
+
const slotIndex = normalSlotIndex % this.slotsPerEpoch;
|
|
2420
|
+
return [epoch, slotIndex];
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
getFirstSlotInEpoch(epoch) {
|
|
2425
|
+
if (epoch <= this.firstNormalEpoch) {
|
|
2426
|
+
return (Math.pow(2, epoch) - 1) * MINIMUM_SLOT_PER_EPOCH;
|
|
2427
|
+
} else {
|
|
2428
|
+
return (epoch - this.firstNormalEpoch) * this.slotsPerEpoch + this.firstNormalSlot;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
getLastSlotInEpoch(epoch) {
|
|
2433
|
+
return this.getFirstSlotInEpoch(epoch) + this.getSlotsInEpoch(epoch) - 1;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
getSlotsInEpoch(epoch) {
|
|
2437
|
+
if (epoch < this.firstNormalEpoch) {
|
|
2438
|
+
return Math.pow(2, epoch + trailingZeros(MINIMUM_SLOT_PER_EPOCH));
|
|
2439
|
+
} else {
|
|
2440
|
+
return this.slotsPerEpoch;
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2345
2446
|
// TODO: These constants should be removed in favor of reading them out of a
|
|
2346
2447
|
// Syscall account
|
|
2347
2448
|
|
|
@@ -2507,11 +2608,6 @@ const GetEpochInfoResult = type({
|
|
|
2507
2608
|
blockHeight: optional(number()),
|
|
2508
2609
|
transactionCount: optional(number())
|
|
2509
2610
|
});
|
|
2510
|
-
/**
|
|
2511
|
-
* Epoch schedule
|
|
2512
|
-
* (see https://docs.solana.com/terminology#epoch)
|
|
2513
|
-
*/
|
|
2514
|
-
|
|
2515
2611
|
const GetEpochScheduleResult = type({
|
|
2516
2612
|
slotsPerEpoch: number(),
|
|
2517
2613
|
leaderScheduleSlotOffset: number(),
|
|
@@ -4044,7 +4140,8 @@ class Connection {
|
|
|
4044
4140
|
throw new Error('failed to get epoch schedule: ' + res.error.message);
|
|
4045
4141
|
}
|
|
4046
4142
|
|
|
4047
|
-
|
|
4143
|
+
const epochSchedule = res.result;
|
|
4144
|
+
return new EpochSchedule(epochSchedule.slotsPerEpoch, epochSchedule.leaderScheduleSlotOffset, epochSchedule.warmup, epochSchedule.firstNormalEpoch, epochSchedule.firstNormalSlot);
|
|
4048
4145
|
}
|
|
4049
4146
|
/**
|
|
4050
4147
|
* Fetch the leader schedule for the current epoch
|
|
@@ -4460,12 +4557,23 @@ class Connection {
|
|
|
4460
4557
|
});
|
|
4461
4558
|
}
|
|
4462
4559
|
/**
|
|
4463
|
-
* Request an allocation of lamports to the specified
|
|
4560
|
+
* Request an allocation of lamports to the specified address
|
|
4561
|
+
*
|
|
4562
|
+
* ```typescript
|
|
4563
|
+
* import { Connection, PublicKey, LAMPORTS_PER_SOL } from "@solana/web3.js";
|
|
4564
|
+
*
|
|
4565
|
+
* (async () => {
|
|
4566
|
+
* const connection = new Connection("https://api.testnet.solana.com", "confirmed");
|
|
4567
|
+
* const myAddress = new PublicKey("2nr1bHFT86W9tGnyvmYW4vcHKsQB3sVQfnddasz4kExM");
|
|
4568
|
+
* const signature = await connection.requestAirdrop(myAddress, LAMPORTS_PER_SOL);
|
|
4569
|
+
* await connection.confirmTransaction(signature);
|
|
4570
|
+
* })();
|
|
4571
|
+
* ```
|
|
4464
4572
|
*/
|
|
4465
4573
|
|
|
4466
4574
|
|
|
4467
|
-
async requestAirdrop(to,
|
|
4468
|
-
const unsafeRes = await this._rpcRequest('requestAirdrop', [to.toBase58(),
|
|
4575
|
+
async requestAirdrop(to, lamports) {
|
|
4576
|
+
const unsafeRes = await this._rpcRequest('requestAirdrop', [to.toBase58(), lamports]);
|
|
4469
4577
|
const res = create(unsafeRes, RequestAirdropRpcResult);
|
|
4470
4578
|
|
|
4471
4579
|
if ('error' in res) {
|
|
@@ -6509,5 +6617,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
6509
6617
|
|
|
6510
6618
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
6511
6619
|
|
|
6512
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Enum, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
6620
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
6513
6621
|
//# sourceMappingURL=index.esm.js.map
|