@@ -25,7 +25,7 @@ export const isSolanaDevnet = (provider: AnchorProvider): boolean => {
25
25
} ;
26
26
27
27
/**
28
- * Borsh‐serializable struct matching your Rust DelegateSeedData
28
+ * Deposit Delegate Seed Data
29
29
*/
30
30
class DepositDelegateSeedData {
31
31
depositor ! : Uint8Array ;
@@ -56,7 +56,7 @@ class DepositDelegateSeedData {
56
56
}
57
57
58
58
/**
59
- * Borsh schema for DelegateSeedData
59
+ * Borsh schema for DepositDelegateSeedData
60
60
*/
61
61
const delegateSeedSchema = new Map ( [
62
62
[
@@ -93,17 +93,14 @@ export function getDepositDelegateSeedHash(depositData: DepositData): Uint8Array
93
93
// Borsh will automatically prefix this with a 4‑byte LE length
94
94
message : Uint8Array . from ( depositData . message ) ,
95
95
} ) ;
96
-
97
- // Serialize with borsh
98
- const serialized = serialize ( delegateSeedSchema , ds ) ; // Uint8Array
96
+ const serialized = serialize ( delegateSeedSchema , ds ) ;
99
97
const hashHex = ethers . utils . keccak256 ( serialized ) ;
100
- const seedHash = Buffer . from ( hashHex . slice ( 2 ) , "hex" ) ;
101
- return seedHash ;
98
+
99
+ return Buffer . from ( hashHex . slice ( 2 ) , "hex" ) ;
102
100
}
103
101
104
102
/**
105
- * Returns the delegate PDA for a deposit, Borsh‐serializing exactly the same fields
106
- * and ordering as your Rust `derive_deposit_delegate_seed_hash`.
103
+ * Returns the delegate PDA for a deposit.
107
104
*/
108
105
export function getDepositDelegatePda ( depositData : DepositData , programId : PublicKey ) : PublicKey {
109
106
const seedHash = getDepositDelegateSeedHash ( depositData ) ;
@@ -113,8 +110,9 @@ export function getDepositDelegatePda(depositData: DepositData, programId: Publi
113
110
114
111
return pda ;
115
112
}
113
+
116
114
/**
117
- * Fill‐delegate seed data for relays
115
+ * Fill Delegate Seed Data
118
116
*/
119
117
class FillDelegateSeedData {
120
118
relayHash : Uint8Array ;
@@ -145,8 +143,7 @@ const fillDelegateSeedSchema = new Map<any, any>([
145
143
] ) ;
146
144
147
145
/**
148
- * Computes the delegate seed hash for a fill relay operation.
149
- * Must match the Rust `derive_fill_delegate_seed_hash` logic exactly.
146
+ * Returns the fill delegate seed hash.
150
147
*/
151
148
152
149
export function getFillRelayDelegateSeedHash (
@@ -160,12 +157,12 @@ export function getFillRelayDelegateSeedHash(
160
157
repaymentAddress : repaymentAddress . toBuffer ( ) ,
161
158
} ) ;
162
159
const serialized = serialize ( fillDelegateSeedSchema , ds ) ;
160
+
163
161
return Buffer . from ( ethers . utils . keccak256 ( serialized ) . slice ( 2 ) , "hex" ) ;
164
162
}
165
163
166
164
/**
167
- * Derives the program address (PDA) for a fill relay delegate.
168
- * Returns only the PDA; bump can be retrieved via `findProgramAddressSync` if needed.
165
+ * Returns the fill delegate PDA.
169
166
*/
170
167
export function getFillRelayDelegatePda (
171
168
relayHash : Uint8Array ,
@@ -175,5 +172,6 @@ export function getFillRelayDelegatePda(
175
172
) : { seedHash : Uint8Array ; pda : PublicKey } {
176
173
const seedHash = getFillRelayDelegateSeedHash ( relayHash , repaymentChainId , repaymentAddress ) ;
177
174
const [ pda ] = PublicKey . findProgramAddressSync ( [ Buffer . from ( "delegate" ) , seedHash ] , programId ) ;
175
+
178
176
return { seedHash, pda } ;
179
177
}
0 commit comments