Skip to content

Commit 3b1d776

Browse files
committed
chore(solana): make OutgoinMessage a PDA
1 parent 6e87f4f commit 3b1d776

38 files changed

Lines changed: 2750 additions & 3200 deletions

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

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

17-
/** UnauthorizedConfigUpdate: Unauthorized to update configuration */
18-
export const BASE_RELAYER_ERROR__UNAUTHORIZED_CONFIG_UPDATE = 0x2ee0; // 12000
17+
/** GasLimitTooLow: Gas limit too low */
18+
export const BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW = 0x1770; // 6000
19+
/** GasLimitExceeded: Gas limit exceeded */
20+
export const BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED = 0x1771; // 6001
1921

2022
export type BaseRelayerError =
21-
typeof BASE_RELAYER_ERROR__UNAUTHORIZED_CONFIG_UPDATE;
23+
| typeof BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED
24+
| typeof BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW;
2225

2326
let baseRelayerErrorMessages: Record<BaseRelayerError, string> | undefined;
2427
if (process.env.NODE_ENV !== 'production') {
2528
baseRelayerErrorMessages = {
26-
[BASE_RELAYER_ERROR__UNAUTHORIZED_CONFIG_UPDATE]: `Unauthorized to update configuration`,
29+
[BASE_RELAYER_ERROR__GAS_LIMIT_EXCEEDED]: `Gas limit exceeded`,
30+
[BASE_RELAYER_ERROR__GAS_LIMIT_TOO_LOW]: `Gas limit too low`,
2731
};
2832
}
2933

clients/ts/src/bridge/generated/accounts/bridge.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
type MaybeAccount,
3838
type MaybeEncodedAccount,
3939
type ReadonlyUint8Array,
40-
} from "@solana/kit";
40+
} from '@solana/kit';
4141
import {
4242
getBaseOracleConfigDecoder,
4343
getBaseOracleConfigEncoder,
@@ -63,7 +63,7 @@ import {
6363
type PartnerOracleConfigArgs,
6464
type ProtocolConfig,
6565
type ProtocolConfigArgs,
66-
} from "../types";
66+
} from '../types';
6767

6868
export const BRIDGE_DISCRIMINATOR = new Uint8Array([
6969
231, 232, 31, 98, 110, 3, 23, 59,
@@ -123,35 +123,35 @@ export type BridgeArgs = {
123123
export function getBridgeEncoder(): FixedSizeEncoder<BridgeArgs> {
124124
return transformEncoder(
125125
getStructEncoder([
126-
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
127-
["baseBlockNumber", getU64Encoder()],
128-
["nonce", getU64Encoder()],
129-
["guardian", getAddressEncoder()],
130-
["paused", getBooleanEncoder()],
131-
["eip1559", getEip1559Encoder()],
132-
["gasConfig", getGasConfigEncoder()],
133-
["protocolConfig", getProtocolConfigEncoder()],
134-
["bufferConfig", getBufferConfigEncoder()],
135-
["partnerOracleConfig", getPartnerOracleConfigEncoder()],
136-
["baseOracleConfig", getBaseOracleConfigEncoder()],
126+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
127+
['baseBlockNumber', getU64Encoder()],
128+
['nonce', getU64Encoder()],
129+
['guardian', getAddressEncoder()],
130+
['paused', getBooleanEncoder()],
131+
['eip1559', getEip1559Encoder()],
132+
['gasConfig', getGasConfigEncoder()],
133+
['protocolConfig', getProtocolConfigEncoder()],
134+
['bufferConfig', getBufferConfigEncoder()],
135+
['partnerOracleConfig', getPartnerOracleConfigEncoder()],
136+
['baseOracleConfig', getBaseOracleConfigEncoder()],
137137
]),
138138
(value) => ({ ...value, discriminator: BRIDGE_DISCRIMINATOR })
139139
);
140140
}
141141

142142
export function getBridgeDecoder(): FixedSizeDecoder<Bridge> {
143143
return getStructDecoder([
144-
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
145-
["baseBlockNumber", getU64Decoder()],
146-
["nonce", getU64Decoder()],
147-
["guardian", getAddressDecoder()],
148-
["paused", getBooleanDecoder()],
149-
["eip1559", getEip1559Decoder()],
150-
["gasConfig", getGasConfigDecoder()],
151-
["protocolConfig", getProtocolConfigDecoder()],
152-
["bufferConfig", getBufferConfigDecoder()],
153-
["partnerOracleConfig", getPartnerOracleConfigDecoder()],
154-
["baseOracleConfig", getBaseOracleConfigDecoder()],
144+
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
145+
['baseBlockNumber', getU64Decoder()],
146+
['nonce', getU64Decoder()],
147+
['guardian', getAddressDecoder()],
148+
['paused', getBooleanDecoder()],
149+
['eip1559', getEip1559Decoder()],
150+
['gasConfig', getGasConfigDecoder()],
151+
['protocolConfig', getProtocolConfigDecoder()],
152+
['bufferConfig', getBufferConfigDecoder()],
153+
['partnerOracleConfig', getPartnerOracleConfigDecoder()],
154+
['baseOracleConfig', getBaseOracleConfigDecoder()],
155155
]);
156156
}
157157

clients/ts/src/bridge/generated/errors/bridge.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ import { BRIDGE_PROGRAM_ADDRESS } from '../programs';
1616

1717
/** IncorrectGasFeeReceiver: Incorrect gas fee receiver */
1818
export const BRIDGE_ERROR__INCORRECT_GAS_FEE_RECEIVER = 0x1770; // 6000
19-
/** BridgePaused: Bridge is paused */
20-
export const BRIDGE_ERROR__BRIDGE_PAUSED = 0x1771; // 6001
19+
/** Unauthorized: Only the owner can close this call buffer */
20+
export const BRIDGE_ERROR__UNAUTHORIZED = 0x1771; // 6001
21+
/** BridgePaused: Bridge is currently paused */
22+
export const BRIDGE_ERROR__BRIDGE_PAUSED = 0x1772; // 6002
2123

2224
export type BridgeError =
2325
| typeof BRIDGE_ERROR__BRIDGE_PAUSED
24-
| typeof BRIDGE_ERROR__INCORRECT_GAS_FEE_RECEIVER;
26+
| typeof BRIDGE_ERROR__INCORRECT_GAS_FEE_RECEIVER
27+
| typeof BRIDGE_ERROR__UNAUTHORIZED;
2528

2629
let bridgeErrorMessages: Record<BridgeError, string> | undefined;
2730
if (process.env.NODE_ENV !== 'production') {
2831
bridgeErrorMessages = {
29-
[BRIDGE_ERROR__BRIDGE_PAUSED]: `Bridge is paused`,
32+
[BRIDGE_ERROR__BRIDGE_PAUSED]: `Bridge is currently paused`,
3033
[BRIDGE_ERROR__INCORRECT_GAS_FEE_RECEIVER]: `Incorrect gas fee receiver`,
34+
[BRIDGE_ERROR__UNAUTHORIZED]: `Only the owner can close this call buffer`,
3135
};
3236
}
3337

clients/ts/src/bridge/generated/instructions/bridgeCall.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export type BridgeCallInstruction<
7777
? WritableAccount<TAccountBridge>
7878
: TAccountBridge,
7979
TAccountOutgoingMessage extends string
80-
? WritableSignerAccount<TAccountOutgoingMessage> &
81-
AccountSignerMeta<TAccountOutgoingMessage>
80+
? WritableAccount<TAccountOutgoingMessage>
8281
: TAccountOutgoingMessage,
8382
TAccountSystemProgram extends string
8483
? ReadonlyAccount<TAccountSystemProgram>
@@ -89,15 +88,20 @@ export type BridgeCallInstruction<
8988

9089
export type BridgeCallInstructionData = {
9190
discriminator: ReadonlyUint8Array;
91+
outgoingMessageSalt: ReadonlyUint8Array;
9292
call: Call;
9393
};
9494

95-
export type BridgeCallInstructionDataArgs = { call: CallArgs };
95+
export type BridgeCallInstructionDataArgs = {
96+
outgoingMessageSalt: ReadonlyUint8Array;
97+
call: CallArgs;
98+
};
9699

97100
export function getBridgeCallInstructionDataEncoder(): Encoder<BridgeCallInstructionDataArgs> {
98101
return transformEncoder(
99102
getStructEncoder([
100103
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
104+
['outgoingMessageSalt', fixEncoderSize(getBytesEncoder(), 32)],
101105
['call', getCallEncoder()],
102106
]),
103107
(value) => ({ ...value, discriminator: BRIDGE_CALL_DISCRIMINATOR })
@@ -107,6 +111,7 @@ export function getBridgeCallInstructionDataEncoder(): Encoder<BridgeCallInstruc
107111
export function getBridgeCallInstructionDataDecoder(): Decoder<BridgeCallInstructionData> {
108112
return getStructDecoder([
109113
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
114+
['outgoingMessageSalt', fixDecoderSize(getBytesDecoder(), 32)],
110115
['call', getCallDecoder()],
111116
]);
112117
}
@@ -156,12 +161,13 @@ export type BridgeCallInput<
156161
* the worst-case message variant to ensure sufficient capacity even for large payloads
157162
* - Contains all information needed for execution on Base
158163
*/
159-
outgoingMessage: TransactionSigner<TAccountOutgoingMessage>;
164+
outgoingMessage: Address<TAccountOutgoingMessage>;
160165
/**
161166
* System program required for creating the outgoing message account.
162167
* Used internally by Anchor for account initialization.
163168
*/
164169
systemProgram?: Address<TAccountSystemProgram>;
170+
outgoingMessageSalt: BridgeCallInstructionDataArgs['outgoingMessageSalt'];
165171
call: BridgeCallInstructionDataArgs['call'];
166172
};
167173

clients/ts/src/bridge/generated/instructions/bridgeCallBuffered.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export type BridgeCallBufferedInstruction<
8282
? WritableAccount<TAccountCallBuffer>
8383
: TAccountCallBuffer,
8484
TAccountOutgoingMessage extends string
85-
? WritableSignerAccount<TAccountOutgoingMessage> &
86-
AccountSignerMeta<TAccountOutgoingMessage>
85+
? WritableAccount<TAccountOutgoingMessage>
8786
: TAccountOutgoingMessage,
8887
TAccountSystemProgram extends string
8988
? ReadonlyAccount<TAccountSystemProgram>
@@ -94,20 +93,27 @@ export type BridgeCallBufferedInstruction<
9493

9594
export type BridgeCallBufferedInstructionData = {
9695
discriminator: ReadonlyUint8Array;
96+
outgoingMessageSalt: ReadonlyUint8Array;
9797
};
9898

99-
export type BridgeCallBufferedInstructionDataArgs = {};
99+
export type BridgeCallBufferedInstructionDataArgs = {
100+
outgoingMessageSalt: ReadonlyUint8Array;
101+
};
100102

101103
export function getBridgeCallBufferedInstructionDataEncoder(): FixedSizeEncoder<BridgeCallBufferedInstructionDataArgs> {
102104
return transformEncoder(
103-
getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]),
105+
getStructEncoder([
106+
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
107+
['outgoingMessageSalt', fixEncoderSize(getBytesEncoder(), 32)],
108+
]),
104109
(value) => ({ ...value, discriminator: BRIDGE_CALL_BUFFERED_DISCRIMINATOR })
105110
);
106111
}
107112

108113
export function getBridgeCallBufferedInstructionDataDecoder(): FixedSizeDecoder<BridgeCallBufferedInstructionData> {
109114
return getStructDecoder([
110115
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
116+
['outgoingMessageSalt', fixDecoderSize(getBytesDecoder(), 32)],
111117
]);
112118
}
113119

@@ -168,12 +174,13 @@ export type BridgeCallBufferedInput<
168174
* cover the Call variant
169175
* - Includes `nonce` and `sender` metadata used on Base
170176
*/
171-
outgoingMessage: TransactionSigner<TAccountOutgoingMessage>;
177+
outgoingMessage: Address<TAccountOutgoingMessage>;
172178
/**
173179
* System program required for creating the outgoing message account.
174180
* Used internally by Anchor for account initialization.
175181
*/
176182
systemProgram?: Address<TAccountSystemProgram>;
183+
outgoingMessageSalt: BridgeCallBufferedInstructionDataArgs['outgoingMessageSalt'];
177184
};
178185

179186
export function getBridgeCallBufferedInstruction<
@@ -228,6 +235,9 @@ export function getBridgeCallBufferedInstruction<
228235
ResolvedAccount
229236
>;
230237

238+
// Original args.
239+
const args = { ...input };
240+
231241
// Resolve default values.
232242
if (!accounts.systemProgram.value) {
233243
accounts.systemProgram.value =
@@ -247,7 +257,9 @@ export function getBridgeCallBufferedInstruction<
247257
getAccountMeta(accounts.systemProgram),
248258
],
249259
programAddress,
250-
data: getBridgeCallBufferedInstructionDataEncoder().encode({}),
260+
data: getBridgeCallBufferedInstructionDataEncoder().encode(
261+
args as BridgeCallBufferedInstructionDataArgs
262+
),
251263
} as BridgeCallBufferedInstruction<
252264
TProgramAddress,
253265
TAccountPayer,

clients/ts/src/bridge/generated/instructions/bridgeSol.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ export type BridgeSolInstruction<
8686
? WritableAccount<TAccountBridge>
8787
: TAccountBridge,
8888
TAccountOutgoingMessage extends string
89-
? WritableSignerAccount<TAccountOutgoingMessage> &
90-
AccountSignerMeta<TAccountOutgoingMessage>
89+
? WritableAccount<TAccountOutgoingMessage>
9190
: TAccountOutgoingMessage,
9291
TAccountSystemProgram extends string
9392
? ReadonlyAccount<TAccountSystemProgram>
@@ -98,13 +97,15 @@ export type BridgeSolInstruction<
9897

9998
export type BridgeSolInstructionData = {
10099
discriminator: ReadonlyUint8Array;
100+
outgoingMessageSalt: ReadonlyUint8Array;
101101
to: ReadonlyUint8Array;
102102
remoteToken: ReadonlyUint8Array;
103103
amount: bigint;
104104
call: Option<Call>;
105105
};
106106

107107
export type BridgeSolInstructionDataArgs = {
108+
outgoingMessageSalt: ReadonlyUint8Array;
108109
to: ReadonlyUint8Array;
109110
remoteToken: ReadonlyUint8Array;
110111
amount: number | bigint;
@@ -115,6 +116,7 @@ export function getBridgeSolInstructionDataEncoder(): Encoder<BridgeSolInstructi
115116
return transformEncoder(
116117
getStructEncoder([
117118
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
119+
['outgoingMessageSalt', fixEncoderSize(getBytesEncoder(), 32)],
118120
['to', fixEncoderSize(getBytesEncoder(), 20)],
119121
['remoteToken', fixEncoderSize(getBytesEncoder(), 20)],
120122
['amount', getU64Encoder()],
@@ -127,6 +129,7 @@ export function getBridgeSolInstructionDataEncoder(): Encoder<BridgeSolInstructi
127129
export function getBridgeSolInstructionDataDecoder(): Decoder<BridgeSolInstructionData> {
128130
return getStructDecoder([
129131
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
132+
['outgoingMessageSalt', fixDecoderSize(getBytesDecoder(), 32)],
130133
['to', fixDecoderSize(getBytesDecoder(), 20)],
131134
['remoteToken', fixDecoderSize(getBytesDecoder(), 20)],
132135
['amount', getU64Decoder()],
@@ -185,12 +188,13 @@ export type BridgeSolInput<
185188
* - Payer funds the account creation
186189
* - Space allocated dynamically based on optional call data size
187190
*/
188-
outgoingMessage: TransactionSigner<TAccountOutgoingMessage>;
191+
outgoingMessage: Address<TAccountOutgoingMessage>;
189192
/**
190193
* System program required for SOL transfers and account creation.
191194
* Used for transferring SOL from user to vault and creating outgoing message accounts.
192195
*/
193196
systemProgram?: Address<TAccountSystemProgram>;
197+
outgoingMessageSalt: BridgeSolInstructionDataArgs['outgoingMessageSalt'];
194198
to: BridgeSolInstructionDataArgs['to'];
195199
remoteToken: BridgeSolInstructionDataArgs['remoteToken'];
196200
amount: BridgeSolInstructionDataArgs['amount'];

clients/ts/src/bridge/generated/instructions/bridgeSolWithBufferedCall.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ export type BridgeSolWithBufferedCallInstruction<
8787
? WritableAccount<TAccountCallBuffer>
8888
: TAccountCallBuffer,
8989
TAccountOutgoingMessage extends string
90-
? WritableSignerAccount<TAccountOutgoingMessage> &
91-
AccountSignerMeta<TAccountOutgoingMessage>
90+
? WritableAccount<TAccountOutgoingMessage>
9291
: TAccountOutgoingMessage,
9392
TAccountSystemProgram extends string
9493
? ReadonlyAccount<TAccountSystemProgram>
@@ -99,12 +98,14 @@ export type BridgeSolWithBufferedCallInstruction<
9998

10099
export type BridgeSolWithBufferedCallInstructionData = {
101100
discriminator: ReadonlyUint8Array;
101+
outgoingMessageSalt: ReadonlyUint8Array;
102102
to: ReadonlyUint8Array;
103103
remoteToken: ReadonlyUint8Array;
104104
amount: bigint;
105105
};
106106

107107
export type BridgeSolWithBufferedCallInstructionDataArgs = {
108+
outgoingMessageSalt: ReadonlyUint8Array;
108109
to: ReadonlyUint8Array;
109110
remoteToken: ReadonlyUint8Array;
110111
amount: number | bigint;
@@ -114,6 +115,7 @@ export function getBridgeSolWithBufferedCallInstructionDataEncoder(): FixedSizeE
114115
return transformEncoder(
115116
getStructEncoder([
116117
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
118+
['outgoingMessageSalt', fixEncoderSize(getBytesEncoder(), 32)],
117119
['to', fixEncoderSize(getBytesEncoder(), 20)],
118120
['remoteToken', fixEncoderSize(getBytesEncoder(), 20)],
119121
['amount', getU64Encoder()],
@@ -128,6 +130,7 @@ export function getBridgeSolWithBufferedCallInstructionDataEncoder(): FixedSizeE
128130
export function getBridgeSolWithBufferedCallInstructionDataDecoder(): FixedSizeDecoder<BridgeSolWithBufferedCallInstructionData> {
129131
return getStructDecoder([
130132
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
133+
['outgoingMessageSalt', fixDecoderSize(getBytesDecoder(), 32)],
131134
['to', fixDecoderSize(getBytesDecoder(), 20)],
132135
['remoteToken', fixDecoderSize(getBytesDecoder(), 20)],
133136
['amount', getU64Decoder()],
@@ -195,9 +198,10 @@ export type BridgeSolWithBufferedCallInput<
195198
* - Funded by `payer`
196199
* - Space: DISCRIMINATOR_LEN + serialized `OutgoingMessage`
197200
*/
198-
outgoingMessage: TransactionSigner<TAccountOutgoingMessage>;
201+
outgoingMessage: Address<TAccountOutgoingMessage>;
199202
/** System program required for account creation and the SOL transfer CPI. */
200203
systemProgram?: Address<TAccountSystemProgram>;
204+
outgoingMessageSalt: BridgeSolWithBufferedCallInstructionDataArgs['outgoingMessageSalt'];
201205
to: BridgeSolWithBufferedCallInstructionDataArgs['to'];
202206
remoteToken: BridgeSolWithBufferedCallInstructionDataArgs['remoteToken'];
203207
amount: BridgeSolWithBufferedCallInstructionDataArgs['amount'];

0 commit comments

Comments
 (0)