Skip to content

Commit d768355

Browse files
authored
Merge branch 'main' into jack/format
2 parents db98c51 + d9e7ce9 commit d768355

19 files changed

Lines changed: 1242 additions & 252 deletions

File tree

clients/ts/src/base-relayer/generated/errors/baseRelayer.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,36 @@ import {
1414
} from '@solana/kit';
1515
import { BASE_RELAYER_PROGRAM_ADDRESS } from '../programs';
1616

17+
/** UnauthorizedInitialization: Only the upgrade authority can initialize the relayer */
18+
export const BASE_RELAYER_ERROR__UNAUTHORIZED_INITIALIZATION = 0x2ee0; // 12000
19+
/** IncorrectRelayerProgram: Incorrect relayer program */
20+
export const BASE_RELAYER_ERROR__INCORRECT_RELAYER_PROGRAM = 0x2ee1; // 12001
21+
/** UnauthorizedConfigUpdate: Unauthorized to update configuration */
22+
export const BASE_RELAYER_ERROR__UNAUTHORIZED_CONFIG_UPDATE = 0x2f44; // 12100
1723
/** GasLimitTooLow: Gas limit too low */
18-
export const BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW = 0x1770; // 6000
24+
export const BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW = 0x2fa8; // 12200
1925
/** GasLimitExceeded: Gas limit exceeded */
20-
export const BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED = 0x1771; // 6001
26+
export const BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED = 0x2fa9; // 12201
27+
/** IncorrectGasFeeReceiver: Incorrect gas fee receiver */
28+
export const BASE_RELAYER_ERROR__INCORRECT_GAS_FEE_RECEIVER = 0x300c; // 12300
2129

2230
export type BaseRelayerError =
2331
| typeof BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED
24-
| typeof BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW;
32+
| typeof BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW
33+
| typeof BASE_RELAYER_ERROR__INCORRECT_GAS_FEE_RECEIVER
34+
| typeof BASE_RELAYER_ERROR__INCORRECT_RELAYER_PROGRAM
35+
| typeof BASE_RELAYER_ERROR__UNAUTHORIZED_CONFIG_UPDATE
36+
| typeof BASE_RELAYER_ERROR__UNAUTHORIZED_INITIALIZATION;
2537

2638
let baseRelayerErrorMessages: Record<BaseRelayerError, string> | undefined;
2739
if (process.env.NODE_ENV !== 'production') {
2840
baseRelayerErrorMessages = {
2941
[BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED]: `Gas limit exceeded`,
3042
[BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW]: `Gas limit too low`,
43+
[BASE_RELAYER_ERROR__INCORRECT_GAS_FEE_RECEIVER]: `Incorrect gas fee receiver`,
44+
[BASE_RELAYER_ERROR__INCORRECT_RELAYER_PROGRAM]: `Incorrect relayer program`,
45+
[BASE_RELAYER_ERROR__UNAUTHORIZED_CONFIG_UPDATE]: `Unauthorized to update configuration`,
46+
[BASE_RELAYER_ERROR__UNAUTHORIZED_INITIALIZATION]: `Only the upgrade authority can initialize the relayer`,
3147
};
3248
}
3349

clients/ts/src/base-relayer/generated/instructions/initialize.ts

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ export function getInitializeDiscriminatorBytes() {
5656

5757
export type InitializeInstruction<
5858
TProgram extends string = typeof BASE_RELAYER_PROGRAM_ADDRESS,
59+
TAccountUpgradeAuthority extends string | AccountMeta<string> = string,
5960
TAccountPayer extends string | AccountMeta<string> = string,
6061
TAccountCfg extends string | AccountMeta<string> = string,
61-
TAccountGuardian extends string | AccountMeta<string> = string,
62+
TAccountProgramData extends string | AccountMeta<string> = string,
63+
TAccountProgram extends string | AccountMeta<string> = string,
6264
TAccountSystemProgram extends
6365
| string
6466
| AccountMeta<string> = '11111111111111111111111111111111',
@@ -67,15 +69,21 @@ export type InitializeInstruction<
6769
InstructionWithData<ReadonlyUint8Array> &
6870
InstructionWithAccounts<
6971
[
72+
TAccountUpgradeAuthority extends string
73+
? ReadonlySignerAccount<TAccountUpgradeAuthority> &
74+
AccountSignerMeta<TAccountUpgradeAuthority>
75+
: TAccountUpgradeAuthority,
7076
TAccountPayer extends string
7177
? WritableSignerAccount<TAccountPayer> &
7278
AccountSignerMeta<TAccountPayer>
7379
: TAccountPayer,
7480
TAccountCfg extends string ? WritableAccount<TAccountCfg> : TAccountCfg,
75-
TAccountGuardian extends string
76-
? ReadonlySignerAccount<TAccountGuardian> &
77-
AccountSignerMeta<TAccountGuardian>
78-
: TAccountGuardian,
81+
TAccountProgramData extends string
82+
? ReadonlyAccount<TAccountProgramData>
83+
: TAccountProgramData,
84+
TAccountProgram extends string
85+
? ReadonlyAccount<TAccountProgram>
86+
: TAccountProgram,
7987
TAccountSystemProgram extends string
8088
? ReadonlyAccount<TAccountSystemProgram>
8189
: TAccountSystemProgram,
@@ -85,13 +93,13 @@ export type InitializeInstruction<
8593

8694
export type InitializeInstructionData = {
8795
discriminator: ReadonlyUint8Array;
88-
newGuardian: Address;
96+
guardian: Address;
8997
eip1559Config: Eip1559Config;
9098
gasConfig: GasConfig;
9199
};
92100

93101
export type InitializeInstructionDataArgs = {
94-
newGuardian: Address;
102+
guardian: Address;
95103
eip1559Config: Eip1559ConfigArgs;
96104
gasConfig: GasConfigArgs;
97105
};
@@ -100,7 +108,7 @@ export function getInitializeInstructionDataEncoder(): FixedSizeEncoder<Initiali
100108
return transformEncoder(
101109
getStructEncoder([
102110
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
103-
['newGuardian', getAddressEncoder()],
111+
['guardian', getAddressEncoder()],
104112
['eip1559Config', getEip1559ConfigEncoder()],
105113
['gasConfig', getGasConfigEncoder()],
106114
]),
@@ -111,7 +119,7 @@ export function getInitializeInstructionDataEncoder(): FixedSizeEncoder<Initiali
111119
export function getInitializeInstructionDataDecoder(): FixedSizeDecoder<InitializeInstructionData> {
112120
return getStructDecoder([
113121
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
114-
['newGuardian', getAddressDecoder()],
122+
['guardian', getAddressDecoder()],
115123
['eip1559Config', getEip1559ConfigDecoder()],
116124
['gasConfig', getGasConfigDecoder()],
117125
]);
@@ -128,67 +136,91 @@ export function getInitializeInstructionDataCodec(): FixedSizeCodec<
128136
}
129137

130138
export type InitializeInput<
139+
TAccountUpgradeAuthority extends string = string,
131140
TAccountPayer extends string = string,
132141
TAccountCfg extends string = string,
133-
TAccountGuardian extends string = string,
142+
TAccountProgramData extends string = string,
143+
TAccountProgram extends string = string,
134144
TAccountSystemProgram extends string = string,
135145
> = {
136146
/**
137-
* The account that pays for the transaction and bridge account creation.
147+
* The upgrade authority that is authorized to initialize the relayer.
148+
* This ensures only the program deployer can set the initial configuration.
149+
*/
150+
upgradeAuthority: TransactionSigner<TAccountUpgradeAuthority>;
151+
/**
152+
* The account that pays for the transaction and config account creation.
138153
* Must be mutable to deduct lamports for account rent.
154+
* Can be different from the upgrade_authority.
139155
*/
140156
payer: TransactionSigner<TAccountPayer>;
141157
/**
142158
* The relayer config state account that tracks fee parameters.
143159
* - Uses PDA with CFG_SEED for deterministic address
144-
* - Mutable to update EIP1559 fee data
160+
* - Payer funds the account creation
161+
* - Space allocated for config state (DISCRIMINATOR_LEN + Cfg::INIT_SPACE)
145162
*/
146163
cfg: Address<TAccountCfg>;
147164
/**
148-
* The guardian account that will have administrative authority over the bridge.
149-
* Must be a signer to prove ownership of the guardian key. The payer and guardian
150-
* may be distinct signers.
165+
* Program data account containing the upgrade authority.
166+
* Validates that the signer is indeed the upgrade authority.
151167
*/
152-
guardian: TransactionSigner<TAccountGuardian>;
168+
programData: Address<TAccountProgramData>;
169+
/**
170+
* The base_relayer program itself.
171+
* Validates that program_data is the correct ProgramData account for this program.
172+
*/
173+
program: Address<TAccountProgram>;
153174
/**
154175
* System program required for creating new accounts.
155176
* Used internally by Anchor for account initialization.
156177
*/
157178
systemProgram?: Address<TAccountSystemProgram>;
158-
newGuardian: InitializeInstructionDataArgs['newGuardian'];
179+
guardian: InitializeInstructionDataArgs['guardian'];
159180
eip1559Config: InitializeInstructionDataArgs['eip1559Config'];
160181
gasConfig: InitializeInstructionDataArgs['gasConfig'];
161182
};
162183

163184
export function getInitializeInstruction<
185+
TAccountUpgradeAuthority extends string,
164186
TAccountPayer extends string,
165187
TAccountCfg extends string,
166-
TAccountGuardian extends string,
188+
TAccountProgramData extends string,
189+
TAccountProgram extends string,
167190
TAccountSystemProgram extends string,
168191
TProgramAddress extends Address = typeof BASE_RELAYER_PROGRAM_ADDRESS,
169192
>(
170193
input: InitializeInput<
194+
TAccountUpgradeAuthority,
171195
TAccountPayer,
172196
TAccountCfg,
173-
TAccountGuardian,
197+
TAccountProgramData,
198+
TAccountProgram,
174199
TAccountSystemProgram
175200
>,
176201
config?: { programAddress?: TProgramAddress }
177202
): InitializeInstruction<
178203
TProgramAddress,
204+
TAccountUpgradeAuthority,
179205
TAccountPayer,
180206
TAccountCfg,
181-
TAccountGuardian,
207+
TAccountProgramData,
208+
TAccountProgram,
182209
TAccountSystemProgram
183210
> {
184211
// Program address.
185212
const programAddress = config?.programAddress ?? BASE_RELAYER_PROGRAM_ADDRESS;
186213

187214
// Original accounts.
188215
const originalAccounts = {
216+
upgradeAuthority: {
217+
value: input.upgradeAuthority ?? null,
218+
isWritable: false,
219+
},
189220
payer: { value: input.payer ?? null, isWritable: true },
190221
cfg: { value: input.cfg ?? null, isWritable: true },
191-
guardian: { value: input.guardian ?? null, isWritable: false },
222+
programData: { value: input.programData ?? null, isWritable: false },
223+
program: { value: input.program ?? null, isWritable: false },
192224
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
193225
};
194226
const accounts = originalAccounts as Record<
@@ -208,9 +240,11 @@ export function getInitializeInstruction<
208240
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
209241
return Object.freeze({
210242
accounts: [
243+
getAccountMeta(accounts.upgradeAuthority),
211244
getAccountMeta(accounts.payer),
212245
getAccountMeta(accounts.cfg),
213-
getAccountMeta(accounts.guardian),
246+
getAccountMeta(accounts.programData),
247+
getAccountMeta(accounts.program),
214248
getAccountMeta(accounts.systemProgram),
215249
],
216250
data: getInitializeInstructionDataEncoder().encode(
@@ -219,9 +253,11 @@ export function getInitializeInstruction<
219253
programAddress,
220254
} as InitializeInstruction<
221255
TProgramAddress,
256+
TAccountUpgradeAuthority,
222257
TAccountPayer,
223258
TAccountCfg,
224-
TAccountGuardian,
259+
TAccountProgramData,
260+
TAccountProgram,
225261
TAccountSystemProgram
226262
>);
227263
}
@@ -233,27 +269,38 @@ export type ParsedInitializeInstruction<
233269
programAddress: Address<TProgram>;
234270
accounts: {
235271
/**
236-
* The account that pays for the transaction and bridge account creation.
272+
* The upgrade authority that is authorized to initialize the relayer.
273+
* This ensures only the program deployer can set the initial configuration.
274+
*/
275+
upgradeAuthority: TAccountMetas[0];
276+
/**
277+
* The account that pays for the transaction and config account creation.
237278
* Must be mutable to deduct lamports for account rent.
279+
* Can be different from the upgrade_authority.
238280
*/
239-
payer: TAccountMetas[0];
281+
payer: TAccountMetas[1];
240282
/**
241283
* The relayer config state account that tracks fee parameters.
242284
* - Uses PDA with CFG_SEED for deterministic address
243-
* - Mutable to update EIP1559 fee data
285+
* - Payer funds the account creation
286+
* - Space allocated for config state (DISCRIMINATOR_LEN + Cfg::INIT_SPACE)
287+
*/
288+
cfg: TAccountMetas[2];
289+
/**
290+
* Program data account containing the upgrade authority.
291+
* Validates that the signer is indeed the upgrade authority.
244292
*/
245-
cfg: TAccountMetas[1];
293+
programData: TAccountMetas[3];
246294
/**
247-
* The guardian account that will have administrative authority over the bridge.
248-
* Must be a signer to prove ownership of the guardian key. The payer and guardian
249-
* may be distinct signers.
295+
* The base_relayer program itself.
296+
* Validates that program_data is the correct ProgramData account for this program.
250297
*/
251-
guardian: TAccountMetas[2];
298+
program: TAccountMetas[4];
252299
/**
253300
* System program required for creating new accounts.
254301
* Used internally by Anchor for account initialization.
255302
*/
256-
systemProgram: TAccountMetas[3];
303+
systemProgram: TAccountMetas[5];
257304
};
258305
data: InitializeInstructionData;
259306
};
@@ -266,7 +313,7 @@ export function parseInitializeInstruction<
266313
InstructionWithAccounts<TAccountMetas> &
267314
InstructionWithData<ReadonlyUint8Array>
268315
): ParsedInitializeInstruction<TProgram, TAccountMetas> {
269-
if (instruction.accounts.length < 4) {
316+
if (instruction.accounts.length < 6) {
270317
// TODO: Coded error.
271318
throw new Error('Not enough accounts');
272319
}
@@ -279,9 +326,11 @@ export function parseInitializeInstruction<
279326
return {
280327
programAddress: instruction.programAddress,
281328
accounts: {
329+
upgradeAuthority: getNextAccount(),
282330
payer: getNextAccount(),
283331
cfg: getNextAccount(),
284-
guardian: getNextAccount(),
332+
programData: getNextAccount(),
333+
program: getNextAccount(),
285334
systemProgram: getNextAccount(),
286335
},
287336
data: getInitializeInstructionDataDecoder().decode(instruction.data),

0 commit comments

Comments
 (0)