-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk.rs
151 lines (142 loc) · 5.27 KB
/
sdk.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use ephemeral_rollups_sdk::consts::{DELEGATION_PROGRAM_ID, MAGIC_CONTEXT_ID, MAGIC_PROGRAM_ID};
use ephemeral_rollups_sdk::pda::{
delegate_buffer_pda_from_delegated_account_and_owner_program,
delegation_metadata_pda_from_delegated_account, delegation_record_pda_from_delegated_account,
};
use solana_curve25519::ristretto::PodRistrettoPoint;
use solana_curve25519::scalar::PodScalar;
use steel::*;
use crate::prelude::*;
pub fn initialize(signer: Pubkey) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(oracles_pda().0, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Initialize {}.to_bytes(),
}
}
pub fn add_oracle(signer: Pubkey, identity: Pubkey, oracle_pubkey: [u8; 32]) -> Instruction {
let oracle_pubkey = PodRistrettoPoint(oracle_pubkey);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(oracles_pda().0, false),
AccountMeta::new(oracle_data_pda(&identity).0, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: ModifyOracle {
identity,
oracle_pubkey,
operation: 0,
}
.to_bytes(),
}
}
pub fn remove_oracle(signer: Pubkey, identity: Pubkey) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(oracles_pda().0, false),
AccountMeta::new(oracle_data_pda(&identity).0, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: ModifyOracle {
identity,
oracle_pubkey: PodRistrettoPoint::default(),
operation: 1,
}
.to_bytes(),
}
}
pub fn initialize_oracle_queue(signer: Pubkey, identity: Pubkey, index: u8) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new_readonly(identity, false),
AccountMeta::new_readonly(oracle_data_pda(&identity).0, false),
AccountMeta::new(oracle_queue_pda(&identity, index).0, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: InitializeOracleQueue { index }.to_bytes(),
}
}
#[allow(clippy::too_many_arguments)]
pub fn provide_randomness(
oracle_identity: Pubkey,
oracle_queue: Pubkey,
callback_program_id: Pubkey,
rnd_seed: [u8; 32],
output: PodRistrettoPoint,
commitment_base_compressed: PodRistrettoPoint,
commitment_hash_compressed: PodRistrettoPoint,
s: PodScalar,
) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(oracle_identity, true),
AccountMeta::new_readonly(program_identity_pda().0, false),
AccountMeta::new_readonly(oracle_data_pda(&oracle_identity).0, false),
AccountMeta::new(oracle_queue, false),
AccountMeta::new_readonly(callback_program_id, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: ProvideRandomness {
oracle_identity,
input: rnd_seed,
output,
commitment_base_compressed,
commitment_hash_compressed,
s,
}
.to_bytes(),
}
}
pub fn delegate_oracle_queue(signer: Pubkey, queue: Pubkey, index: u8) -> Instruction {
let buffer = delegate_buffer_pda_from_delegated_account_and_owner_program(&queue, &crate::ID);
let delegation_record = delegation_record_pda_from_delegated_account(&queue);
let delegation_metadata = delegation_metadata_pda_from_delegated_account(&queue);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(queue, false),
AccountMeta::new(buffer, false),
AccountMeta::new(delegation_record, false),
AccountMeta::new(delegation_metadata, false),
AccountMeta::new_readonly(DELEGATION_PROGRAM_ID, false),
AccountMeta::new_readonly(crate::ID, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: DelegateOracleQueue { index }.to_bytes(),
}
}
pub fn undelegate_oracle_queue(signer: Pubkey, queue: Pubkey, index: u8) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(queue, false),
AccountMeta::new(MAGIC_CONTEXT_ID, false),
AccountMeta::new_readonly(MAGIC_PROGRAM_ID, false),
],
data: UndelegateOracleQueue { index }.to_bytes(),
}
}
pub fn close_oracle_queue(identity: Pubkey, index: u8) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new_readonly(identity, false),
AccountMeta::new_readonly(oracle_data_pda(&identity).0, false),
AccountMeta::new(oracle_queue_pda(&identity, index).0, false),
],
data: CloseOracleQueue { index }.to_bytes(),
}
}