Skip to content

Commit f1229ec

Browse files
committed
Anchor 0.30.1 update, callback update, libs update
1 parent 380e27e commit f1229ec

33 files changed

+7146
-2282
lines changed

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ exclude = ["rust/examples/cpi", "callback/rust/examples/cpi"]
44
resolver = "2"
55

66
[workspace.dependencies]
7-
anchor-lang = "0.29.0"
8-
anchor-spl = "0.29.0"
9-
anchor-client = { version = "0.29.0" }
7+
anchor-lang = "0.30.1"
8+
anchor-spl = "0.30.1"
9+
anchor-client = { version = "0.30.1" }
1010
ed25519-dalek = { version = "1.0.1" }
1111
solana-cli-config = { version = "1.18" }
1212
rand = { version = "0.8" }
13+
bs58 = "0.4"

callback/rust/sdk/src/state/request.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anchor_lang::{prelude::*, solana_program::clock::Slot};
22

33
use super::{
44
super::{majority, MAX_FULFILLMENT_AUTHORITIES},
5-
client::ValidatedCallback,
5+
client::{Callback, Client, ValidatedCallback},
66
};
77

88
#[derive(AnchorDeserialize, AnchorSerialize, Clone, Debug)]
@@ -41,6 +41,16 @@ impl RequestAccount {
4141
pub const STATIC_SIZE: usize = 1 + 8 + 32 + 32;
4242
pub const FULFILLED_SIZE: usize = Self::STATIC_SIZE + RequestState::FULFILLED_SIZE;
4343

44+
/// This function estimates the expected size of the new RequestAccount given the callback used.
45+
pub fn expected_size(client: &Client, callback: Option<&Callback>) -> usize {
46+
let callback_size = callback
47+
.map(|x| x.valid_size())
48+
.or_else(|| client.callback.as_ref().map(|c| c.size()))
49+
.unwrap_or_default();
50+
51+
Self::STATIC_SIZE + 1 + Pending::STATIC_SIZE + 1 + callback_size
52+
}
53+
4454
pub fn new(bump: u8, slot: Slot, client: Pubkey, seed: [u8; 32], state: RequestState) -> Self {
4555
Self {
4656
bump,

js/dist/index.d.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/// <reference types="node" />
22
import { BN, Program, Provider, web3 } from "@coral-xyz/anchor";
33
import { TransactionInstruction } from "@solana/web3.js";
4-
import { NetworkConfiguration, NetworkState, OraoTokenFeeConfig, Randomness, FulfilledRandomness } from "./state";
4+
import { NetworkConfiguration, NetworkState, OraoTokenFeeConfig, RandomnessAccountData, FulfilledRandomnessAccountData } from "./state";
55
import { OraoVrf } from "./types/orao_vrf";
66
import { MethodsBuilder } from "@coral-xyz/anchor/dist/cjs/program/namespace/methods";
7+
import { AllInstructionsMap } from "@coral-xyz/anchor/dist/cjs/program/namespace/types";
78
export { Randomness, FulfilledRandomness, RandomnessResponse, NetworkConfiguration, NetworkState, OraoTokenFeeConfig, } from "./state";
89
export declare const PROGRAM_ADDRESS: string;
910
export declare const PROGRAM_ID: web3.PublicKey;
@@ -80,7 +81,7 @@ export declare class Orao extends Program<OraoVrf> {
8081
* @param seed - seed buffer.
8182
* @param commitment - you can override the provider's commitment level.
8283
*/
83-
getRandomness(seed: Buffer | Uint8Array, commitment?: web3.Commitment): Promise<Randomness>;
84+
getRandomness(seed: Buffer | Uint8Array, commitment?: web3.Commitment): Promise<RandomnessAccountData>;
8485
/**
8586
* Prepares a randomness request (see {@link RequestBuilder}).
8687
*
@@ -103,7 +104,7 @@ export declare class Orao extends Program<OraoVrf> {
103104
* @returns a {@link RequestBuilder} instance.
104105
*/
105106
request(seed?: Buffer | Uint8Array): Promise<RequestBuilder>;
106-
waitFulfilled(seed: Buffer | Uint8Array, commitment?: web3.Commitment): Promise<FulfilledRandomness>;
107+
waitFulfilled(seed: Buffer | Uint8Array, commitment?: web3.Commitment): Promise<FulfilledRandomnessAccountData>;
107108
}
108109
declare class ComputeBudgetConfig {
109110
computeUnitPrice: bigint | null;
@@ -172,7 +173,7 @@ export declare class InitBuilder {
172173
* instance (use {@link InitBuilder.withComputeUnitPrice} and
173174
* {@link InitBuilder.withComputeUnitLimit} to opt-out).
174175
*/
175-
build(): Promise<MethodsBuilder<OraoVrf, OraoVrf["instructions"][0]>>;
176+
build(): Promise<MethodsBuilder<OraoVrf, AllInstructionsMap<OraoVrf>["initNetwork"]>>;
176177
/**
177178
* Performs an RPC call.
178179
*
@@ -247,7 +248,7 @@ export declare class UpdateBuilder {
247248
* instance (use {@link UpdateBuilder.withComputeUnitPrice} and
248249
* {@link UpdateBuilder.withComputeUnitLimit} to opt-out).
249250
*/
250-
build(): Promise<MethodsBuilder<OraoVrf, OraoVrf["instructions"][1]>>;
251+
build(): Promise<MethodsBuilder<OraoVrf, AllInstructionsMap<OraoVrf>["updateNetwork"]>>;
251252
/**
252253
* Performs an RPC call.
253254
*
@@ -319,7 +320,7 @@ export declare class RequestBuilder {
319320
* instance (use {@link RequestBuilder.withComputeUnitPrice} and
320321
* {@link RequestBuilder.withComputeUnitLimit} to opt-out).
321322
*/
322-
build(): Promise<MethodsBuilder<OraoVrf, OraoVrf["instructions"][2]>>;
323+
build(): Promise<MethodsBuilder<OraoVrf, AllInstructionsMap<OraoVrf>["requestV2"]>>;
323324
/**
324325
* Performs an RPC call.
325326
*
@@ -384,7 +385,7 @@ export declare class FulfillBuilder {
384385
* @param fulfillmentAuthority - public key of a fulfillment authority
385386
* @param signature - signature of a seed, performed by the fulfillment authority
386387
*/
387-
build(fulfillmentAuthority: web3.PublicKey, signature: Uint8Array): Promise<MethodsBuilder<OraoVrf, OraoVrf["instructions"][3]>>;
388+
build(fulfillmentAuthority: web3.PublicKey, signature: Uint8Array): Promise<MethodsBuilder<OraoVrf, AllInstructionsMap<OraoVrf>["fulfill"]> | MethodsBuilder<OraoVrf, AllInstructionsMap<OraoVrf>["fulfillV2"]>>;
388389
/**
389390
* Performs an RPC call.
390391
*

js/dist/index.js

+76-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
225
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
326
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
427
return new (P || (P = Promise))(function (resolve, reject) {
@@ -17,15 +40,15 @@ const anchor_1 = require("@coral-xyz/anchor");
1740
const web3_js_1 = require("@solana/web3.js");
1841
const tweetnacl_1 = __importDefault(require("tweetnacl"));
1942
const state_1 = require("./state");
20-
const orao_vrf_1 = require("./types/orao_vrf");
43+
const IDL = __importStar(require("./types/orao_vrf.json"));
2144
var state_2 = require("./state");
2245
Object.defineProperty(exports, "Randomness", { enumerable: true, get: function () { return state_2.Randomness; } });
2346
Object.defineProperty(exports, "FulfilledRandomness", { enumerable: true, get: function () { return state_2.FulfilledRandomness; } });
2447
Object.defineProperty(exports, "RandomnessResponse", { enumerable: true, get: function () { return state_2.RandomnessResponse; } });
2548
Object.defineProperty(exports, "NetworkConfiguration", { enumerable: true, get: function () { return state_2.NetworkConfiguration; } });
2649
Object.defineProperty(exports, "NetworkState", { enumerable: true, get: function () { return state_2.NetworkState; } });
2750
Object.defineProperty(exports, "OraoTokenFeeConfig", { enumerable: true, get: function () { return state_2.OraoTokenFeeConfig; } });
28-
exports.PROGRAM_ADDRESS = "VRFzZoJdhFWL8rkvu87LpKM3RbcVezpMEc6X5GVDr7y";
51+
exports.PROGRAM_ADDRESS = IDL.address;
2952
exports.PROGRAM_ID = new anchor_1.web3.PublicKey(exports.PROGRAM_ADDRESS);
3053
exports.RANDOMNESS_ACCOUNT_SEED = Buffer.from("orao-vrf-randomness-request");
3154
exports.CONFIG_ACCOUNT_SEED = Buffer.from("orao-vrf-network-configuration");
@@ -87,7 +110,7 @@ class Orao extends anchor_1.Program {
87110
* @param [id=PROGRAM_ID] - you can override the program ID.
88111
*/
89112
constructor(provider, id = exports.PROGRAM_ID) {
90-
super(orao_vrf_1.IDL, id, provider);
113+
super(Object.assign(Object.assign({}, IDL), { address: id.toString() }), provider);
91114
if (!provider.publicKey) {
92115
throw new Error("Wallet not provided");
93116
}
@@ -131,9 +154,23 @@ class Orao extends anchor_1.Program {
131154
*/
132155
getRandomness(seed, commitment) {
133156
return __awaiter(this, void 0, void 0, function* () {
134-
let randomness = yield this.account.randomness.fetch(randomnessAccountAddress(seed, this.programId), commitment);
135-
let responses = randomness.responses;
136-
return new state_1.Randomness(randomness.seed, randomness.randomness, responses.map((x) => new state_1.RandomnessResponse(x.pubkey, x.randomness)));
157+
let address = randomnessAccountAddress(seed, this.programId);
158+
try {
159+
let randomness = yield this.account.randomnessV2.fetch(address, commitment);
160+
if ("pending" in randomness.request && randomness.request.pending !== undefined) {
161+
let pending = randomness.request.pending[0];
162+
return new state_1.RandomnessAccountDataV2(new state_1.RandomnessV2(new state_1.PendingRequest(pending.seed, pending.client, pending.responses.map((x) => new state_1.RandomnessResponse(x.pubkey, x.randomness)))));
163+
}
164+
else {
165+
let fulfilled = randomness.request.fulfilled[0];
166+
return new state_1.RandomnessAccountDataV2(new state_1.RandomnessV2(new state_1.FulfilledRequest(fulfilled.seed, fulfilled.client, fulfilled.randomness)));
167+
}
168+
}
169+
catch (_e) {
170+
let randomness = yield this.account.randomness.fetch(address, commitment);
171+
let responses = randomness.responses;
172+
return new state_1.RandomnessAccountDataV1(new state_1.Randomness(randomness.seed, randomness.randomness, responses.map((x) => new state_1.RandomnessResponse(x.pubkey, x.randomness))));
173+
}
137174
});
138175
}
139176
/**
@@ -179,20 +216,28 @@ class Orao extends anchor_1.Program {
179216
return new Promise((_resolve, reject) => __awaiter(this, void 0, void 0, function* () {
180217
let resolved = false;
181218
let maybeResolve = (subscriptionId, randomness) => {
182-
if (!randomness.fulfilled()) {
219+
if (!randomness.getFulfilledRandomness()) {
183220
return;
184221
}
185222
if (resolved) {
186223
return;
187224
}
188225
resolved = true;
189226
this.provider.connection.removeAccountChangeListener(subscriptionId);
190-
_resolve(state_1.FulfilledRandomness.unchecked(randomness));
227+
_resolve(new state_1.FulfilledRandomnessAccountData(randomness));
191228
};
192229
try {
193230
let subscriptionId = this.provider.connection.onAccountChange(account, (accountInfo, _ctx) => {
194-
let randomness = this.account.randomness.coder.accounts.decode("randomness", accountInfo.data);
195-
maybeResolve(subscriptionId, new state_1.Randomness(randomness.seed, randomness.randomness, randomness.responses.map((x) => new state_1.RandomnessResponse(x.pubkey, x.randomness))));
231+
try {
232+
let randomness = this.account.randomness.coder.accounts.decode("randomnessV2", accountInfo.data);
233+
maybeResolve(subscriptionId, new state_1.RandomnessAccountDataV2(new state_1.RandomnessV2("fulfilled" in randomness.request
234+
? new state_1.FulfilledRequest(randomness.request.fulfilled[0].seed, randomness.request.fulfilled[0].client, randomness.request.fulfilled[0].randomness)
235+
: new state_1.PendingRequest(randomness.request.pending[0].seed, randomness.request.pending[0].client, randomness.request.pending[0].responses.map((r) => new state_1.RandomnessResponse(r.pubkey, r.randomness))))));
236+
}
237+
catch (_e) {
238+
let randomness = this.account.randomness.coder.accounts.decode("randomness", accountInfo.data);
239+
maybeResolve(subscriptionId, new state_1.RandomnessAccountDataV1(new state_1.Randomness(randomness.seed, randomness.randomness, randomness.responses.map((x) => new state_1.RandomnessResponse(x.pubkey, x.randomness)))));
240+
}
196241
}, commitment);
197242
// In case it's already fulfilled
198243
let randomness = yield this.getRandomness(seed, commitment);
@@ -308,7 +353,7 @@ class InitBuilder {
308353
const networkState = networkStateAccountAddress(this.vrf.programId);
309354
let tx = this.vrf.methods
310355
.initNetwork(this.config.requestFee, this.config.authority, this.config.fulfillmentAuthorities, this.config.tokenFeeConfig)
311-
.accounts({
356+
.accountsPartial({
312357
networkState,
313358
treasury: this.config.treasury,
314359
});
@@ -431,7 +476,7 @@ class UpdateBuilder {
431476
let tokenFeeConfig = this.tokenFeeConfig !== undefined ? this.tokenFeeConfig : config.tokenFeeConfig;
432477
let tx = this.vrf.methods
433478
.updateNetwork(requestFee, authority, fulfillmentAuthorities, tokenFeeConfig)
434-
.accounts({
479+
.accountsPartial({
435480
networkState,
436481
treasury,
437482
});
@@ -535,7 +580,7 @@ class RequestBuilder {
535580
return __awaiter(this, void 0, void 0, function* () {
536581
const networkState = networkStateAccountAddress(this.vrf.programId);
537582
const networkStateAcc = yield this.vrf.getNetworkState();
538-
let tx = this.vrf.methods.request([...this.seed]).accounts({
583+
let tx = this.vrf.methods.requestV2([...this.seed]).accountsPartial({
539584
networkState,
540585
treasury: networkStateAcc.config.treasury,
541586
request: randomnessAccountAddress(this.seed, this.vrf.programId),
@@ -629,11 +674,24 @@ class FulfillBuilder {
629674
*/
630675
build(fulfillmentAuthority, signature) {
631676
return __awaiter(this, void 0, void 0, function* () {
632-
let tx = this.vrf.methods.fulfill().accounts({
633-
instructionAcc: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
634-
networkState: networkStateAccountAddress(this.vrf.programId),
635-
request: randomnessAccountAddress(this.seed, this.vrf.programId),
636-
});
677+
let randomness = yield this.vrf.getRandomness(this.seed);
678+
let tx;
679+
if (randomness.getVersion() === "V1") {
680+
tx = this.vrf.methods.fulfill().accountsPartial({
681+
instructionAcc: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
682+
networkState: networkStateAccountAddress(this.vrf.programId),
683+
request: randomnessAccountAddress(this.seed, this.vrf.programId),
684+
});
685+
}
686+
else {
687+
tx = this.vrf.methods.fulfillV2().accountsPartial({
688+
instructionAcc: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
689+
networkState: networkStateAccountAddress(this.vrf.programId),
690+
request: randomnessAccountAddress(this.seed, this.vrf.programId),
691+
client: randomness.getClient() || undefined,
692+
systemProgram: web3_js_1.SystemProgram.programId,
693+
});
694+
}
637695
if (!this.computeBudgetConfig.isEmpty()) {
638696
tx = tx.preInstructions(yield this.computeBudgetConfig.getInstructions(this.vrf.provider.connection));
639697
}

0 commit comments

Comments
 (0)