-
Notifications
You must be signed in to change notification settings - Fork 20
/
pda.ts
158 lines (148 loc) · 3.57 KB
/
pda.ts
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
152
153
154
155
156
157
158
import { PublicKey } from "@solana/web3.js";
import { PROGRAM_ID } from "./generated";
import { toU32Bytes, toU64Bytes, toU8Bytes, toUtfBytes } from "./utils";
import invariant from "invariant";
const SEED_PREFIX = toUtfBytes("multisig");
const SEED_PROGRAM_CONFIG = toUtfBytes("program_config");
const SEED_MULTISIG = toUtfBytes("multisig");
const SEED_VAULT = toUtfBytes("vault");
const SEED_TRANSACTION = toUtfBytes("transaction");
const SEED_PROPOSAL = toUtfBytes("proposal");
const SEED_BATCH_TRANSACTION = toUtfBytes("batch_transaction");
const SEED_EPHEMERAL_SIGNER = toUtfBytes("ephemeral_signer");
const SEED_SPENDING_LIMIT = toUtfBytes("spending_limit");
export function getProgramConfigPda({
programId = PROGRAM_ID,
}: {
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[SEED_PREFIX, SEED_PROGRAM_CONFIG],
programId
);
}
export function getMultisigPda({
createKey,
programId = PROGRAM_ID,
}: {
createKey: PublicKey;
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[SEED_PREFIX, SEED_MULTISIG, createKey.toBytes()],
programId
);
}
export function getVaultPda({
multisigPda,
/** Authority index. */
index,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
index: number;
programId?: PublicKey;
}): [PublicKey, number] {
invariant(index >= 0 && index < 256, "Invalid vault index");
return PublicKey.findProgramAddressSync(
[SEED_PREFIX, multisigPda.toBytes(), SEED_VAULT, toU8Bytes(index)],
programId
);
}
export function getEphemeralSignerPda({
transactionPda,
ephemeralSignerIndex,
programId = PROGRAM_ID,
}: {
transactionPda: PublicKey;
ephemeralSignerIndex: number;
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[
SEED_PREFIX,
transactionPda.toBytes(),
SEED_EPHEMERAL_SIGNER,
toU8Bytes(ephemeralSignerIndex),
],
programId
);
}
export function getTransactionPda({
multisigPda,
index,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
/** Transaction index. */
index: bigint;
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[SEED_PREFIX, multisigPda.toBytes(), SEED_TRANSACTION, toU64Bytes(index)],
programId
);
}
export function getProposalPda({
multisigPda,
transactionIndex,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
/** Transaction index. */
transactionIndex: bigint;
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[
SEED_PREFIX,
multisigPda.toBytes(),
SEED_TRANSACTION,
toU64Bytes(transactionIndex),
SEED_PROPOSAL,
],
programId
);
}
export function getBatchTransactionPda({
multisigPda,
batchIndex,
transactionIndex,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
batchIndex: bigint;
transactionIndex: number;
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[
SEED_PREFIX,
multisigPda.toBytes(),
SEED_TRANSACTION,
toU64Bytes(batchIndex),
SEED_BATCH_TRANSACTION,
toU32Bytes(transactionIndex),
],
programId
);
}
export function getSpendingLimitPda({
multisigPda,
createKey,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
createKey: PublicKey;
programId?: PublicKey;
}): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[
SEED_PREFIX,
multisigPda.toBytes(),
SEED_SPENDING_LIMIT,
createKey.toBytes(),
],
programId
);
}