1
1
"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
+ } ;
2
25
var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
3
26
function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
4
27
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
@@ -17,15 +40,15 @@ const anchor_1 = require("@coral-xyz/anchor");
17
40
const web3_js_1 = require ( "@solana/web3.js" ) ;
18
41
const tweetnacl_1 = __importDefault ( require ( "tweetnacl" ) ) ;
19
42
const state_1 = require ( "./state" ) ;
20
- const orao_vrf_1 = require ( "./types/orao_vrf" ) ;
43
+ const IDL = __importStar ( require ( "./types/orao_vrf.json" ) ) ;
21
44
var state_2 = require ( "./state" ) ;
22
45
Object . defineProperty ( exports , "Randomness" , { enumerable : true , get : function ( ) { return state_2 . Randomness ; } } ) ;
23
46
Object . defineProperty ( exports , "FulfilledRandomness" , { enumerable : true , get : function ( ) { return state_2 . FulfilledRandomness ; } } ) ;
24
47
Object . defineProperty ( exports , "RandomnessResponse" , { enumerable : true , get : function ( ) { return state_2 . RandomnessResponse ; } } ) ;
25
48
Object . defineProperty ( exports , "NetworkConfiguration" , { enumerable : true , get : function ( ) { return state_2 . NetworkConfiguration ; } } ) ;
26
49
Object . defineProperty ( exports , "NetworkState" , { enumerable : true , get : function ( ) { return state_2 . NetworkState ; } } ) ;
27
50
Object . defineProperty ( exports , "OraoTokenFeeConfig" , { enumerable : true , get : function ( ) { return state_2 . OraoTokenFeeConfig ; } } ) ;
28
- exports . PROGRAM_ADDRESS = "VRFzZoJdhFWL8rkvu87LpKM3RbcVezpMEc6X5GVDr7y" ;
51
+ exports . PROGRAM_ADDRESS = IDL . address ;
29
52
exports . PROGRAM_ID = new anchor_1 . web3 . PublicKey ( exports . PROGRAM_ADDRESS ) ;
30
53
exports . RANDOMNESS_ACCOUNT_SEED = Buffer . from ( "orao-vrf-randomness-request" ) ;
31
54
exports . CONFIG_ACCOUNT_SEED = Buffer . from ( "orao-vrf-network-configuration" ) ;
@@ -87,7 +110,7 @@ class Orao extends anchor_1.Program {
87
110
* @param [id=PROGRAM_ID] - you can override the program ID.
88
111
*/
89
112
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 ) ;
91
114
if ( ! provider . publicKey ) {
92
115
throw new Error ( "Wallet not provided" ) ;
93
116
}
@@ -131,9 +154,23 @@ class Orao extends anchor_1.Program {
131
154
*/
132
155
getRandomness ( seed , commitment ) {
133
156
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
+ }
137
174
} ) ;
138
175
}
139
176
/**
@@ -179,20 +216,28 @@ class Orao extends anchor_1.Program {
179
216
return new Promise ( ( _resolve , reject ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
180
217
let resolved = false ;
181
218
let maybeResolve = ( subscriptionId , randomness ) => {
182
- if ( ! randomness . fulfilled ( ) ) {
219
+ if ( ! randomness . getFulfilledRandomness ( ) ) {
183
220
return ;
184
221
}
185
222
if ( resolved ) {
186
223
return ;
187
224
}
188
225
resolved = true ;
189
226
this . provider . connection . removeAccountChangeListener ( subscriptionId ) ;
190
- _resolve ( state_1 . FulfilledRandomness . unchecked ( randomness ) ) ;
227
+ _resolve ( new state_1 . FulfilledRandomnessAccountData ( randomness ) ) ;
191
228
} ;
192
229
try {
193
230
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
+ }
196
241
} , commitment ) ;
197
242
// In case it's already fulfilled
198
243
let randomness = yield this . getRandomness ( seed , commitment ) ;
@@ -308,7 +353,7 @@ class InitBuilder {
308
353
const networkState = networkStateAccountAddress ( this . vrf . programId ) ;
309
354
let tx = this . vrf . methods
310
355
. initNetwork ( this . config . requestFee , this . config . authority , this . config . fulfillmentAuthorities , this . config . tokenFeeConfig )
311
- . accounts ( {
356
+ . accountsPartial ( {
312
357
networkState,
313
358
treasury : this . config . treasury ,
314
359
} ) ;
@@ -431,7 +476,7 @@ class UpdateBuilder {
431
476
let tokenFeeConfig = this . tokenFeeConfig !== undefined ? this . tokenFeeConfig : config . tokenFeeConfig ;
432
477
let tx = this . vrf . methods
433
478
. updateNetwork ( requestFee , authority , fulfillmentAuthorities , tokenFeeConfig )
434
- . accounts ( {
479
+ . accountsPartial ( {
435
480
networkState,
436
481
treasury,
437
482
} ) ;
@@ -535,7 +580,7 @@ class RequestBuilder {
535
580
return __awaiter ( this , void 0 , void 0 , function * ( ) {
536
581
const networkState = networkStateAccountAddress ( this . vrf . programId ) ;
537
582
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 ( {
539
584
networkState,
540
585
treasury : networkStateAcc . config . treasury ,
541
586
request : randomnessAccountAddress ( this . seed , this . vrf . programId ) ,
@@ -629,11 +674,24 @@ class FulfillBuilder {
629
674
*/
630
675
build ( fulfillmentAuthority , signature ) {
631
676
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
+ }
637
695
if ( ! this . computeBudgetConfig . isEmpty ( ) ) {
638
696
tx = tx . preInstructions ( yield this . computeBudgetConfig . getInstructions ( this . vrf . provider . connection ) ) ;
639
697
}
0 commit comments