Skip to content

Commit ff3aa9d

Browse files
chore: merge
2 parents 0cbfd9d + 06e400d commit ff3aa9d

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

src/arch/svm/SpokeUtils.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Rpc, SolanaRpcApi } from "@solana/kit";
1+
import { Rpc, SolanaRpcApi, Address } from "@solana/kit";
2+
23
import { Deposit, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
34
import { BigNumber, isUnsafeDepositId } from "../../utils";
5+
import { fetchState } from "@across-protocol/contracts/dist/src/svm/clients/SvmSpoke";
46

57
type Provider = Rpc<SolanaRpcApi>;
68

@@ -46,18 +48,14 @@ export async function getTimestampForBlock(provider: Provider, blockNumber: numb
4648
}
4749

4850
/**
49-
* Return maximum of fill deadline buffer at start and end of block range.
50-
* @param spokePool SpokePool contract instance
51-
* @param startBlock start block
52-
* @param endBlock end block
53-
* @returns maximum of fill deadline buffer at start and end block
51+
* Returns the current fill deadline buffer.
52+
* @param provider SVM Provider instance
53+
* @param statePda Spoke Pool's State PDA
54+
* @returns fill deadline buffer
5455
*/
55-
export function getMaxFillDeadlineInRange(
56-
_spokePool: unknown,
57-
_startBlock: number,
58-
_endBlock: number
59-
): Promise<number> {
60-
throw new Error("getMaxFillDeadlineInRange: not implemented");
56+
export async function getFillDeadline(provider: Provider, statePda: Address): Promise<number> {
57+
const state = await fetchState(provider, statePda);
58+
return state.data.fillDeadlineBuffer;
6159
}
6260

6361
/**

src/arch/svm/utils.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BN, BorshEventCoder, Idl } from "@coral-xyz/anchor";
2-
import web3, { address, isAddress, RpcTransport } from "@solana/kit";
32
import { BigNumber, isUint8Array, SvmAddress } from "../../utils";
3+
import web3, { address, isAddress, RpcTransport, getProgramDerivedAddress, getU64Encoder, Address } from "@solana/kit";
4+
45
import { EventName, EventData, SVMEventNames } from "./types";
56
import { FillType } from "../../interfaces";
67

@@ -132,3 +133,18 @@ export function unwrapEventData(
132133
// Return primitives as is
133134
return data;
134135
}
136+
137+
/**
138+
* Returns the PDA for the State account.
139+
* @param programId The SpokePool program ID.
140+
* @returns The PDA for the State account.
141+
*/
142+
export async function getStatePda(programId: Address): Promise<Address> {
143+
const intEncoder = getU64Encoder();
144+
const seed = intEncoder.encode(0);
145+
const [statePda] = await getProgramDerivedAddress({
146+
programAddress: programId,
147+
seeds: ["state", seed],
148+
});
149+
return statePda;
150+
}

src/clients/SpokePoolClient/SVMSpokePoolClient.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import { Rpc, RpcTransport, SolanaRpcApiFromTransport } from "@solana/kit";
1+
import { Address, Rpc, RpcTransport, SolanaRpcApiFromTransport } from "@solana/kit";
22
import winston from "winston";
3-
import { SVMEventNames, SvmSpokeEventsClient, unwrapEventData } from "../../arch/svm";
3+
import {
4+
SVMEventNames,
5+
SvmSpokeEventsClient,
6+
unwrapEventData,
7+
getFillDeadline,
8+
getTimestampForBlock,
9+
getStatePda,
10+
} from "../../arch/svm";
411
import { FillStatus, RelayData, SortableEvent } from "../../interfaces";
512
import {
613
BigNumber,
@@ -27,6 +34,8 @@ export class SvmSpokePoolClient extends SpokePoolClient {
2734
chainId: number,
2835
deploymentSlot: bigint, // Using slot instead of block number for SVM
2936
eventSearchConfig: MakeOptional<EventSearchConfig, "toBlock">,
37+
protected programId: Address,
38+
protected statePda: Address,
3039
protected svmEventsClient: SvmSpokeEventsClient,
3140
protected rpc: Rpc<SolanaRpcApiFromTransport<RpcTransport>>
3241
) {
@@ -46,12 +55,16 @@ export class SvmSpokePoolClient extends SpokePoolClient {
4655
rpc: Rpc<SolanaRpcApiFromTransport<RpcTransport>>
4756
): Promise<SvmSpokePoolClient> {
4857
const svmEventsClient = await SvmSpokeEventsClient.create(rpc);
58+
const programId = svmEventsClient.getSvmSpokeAddress();
59+
const statePda = await getStatePda(programId);
4960
return new SvmSpokePoolClient(
5061
logger,
5162
hubPoolClient,
5263
chainId,
5364
deploymentSlot,
5465
eventSearchConfig,
66+
programId,
67+
statePda,
5568
svmEventsClient,
5669
rpc
5770
);
@@ -152,18 +165,18 @@ export class SvmSpokePoolClient extends SpokePoolClient {
152165
}
153166

154167
/**
155-
* Retrieves the maximum fill deadline buffer.
156-
* TODO: Implement SVM equivalent, perhaps reading from a config account.
168+
* Retrieves the fill deadline buffer fetched from the State PDA.
169+
* @note This function assumes that fill deadline buffer is a constant value in svm environments.
157170
*/
158-
public getMaxFillDeadlineInRange(_startSlot: number, _endSlot: number): Promise<number> {
159-
throw new Error("getMaxFillDeadlineInRange not implemented for SVM");
171+
public override getMaxFillDeadlineInRange(_startSlot: number, _endSlot: number): Promise<number> {
172+
return getFillDeadline(this.rpc, this.statePda);
160173
}
161174

162175
/**
163176
* Retrieves the timestamp for a given SVM slot number.
164177
*/
165-
public getTimestampForBlock(_blockNumber: number): Promise<number> {
166-
throw new Error("getTimestampForBlock not implemented for SVM");
178+
public override getTimestampForBlock(blockNumber: number): Promise<number> {
179+
return getTimestampForBlock(this.rpc, blockNumber);
167180
}
168181

169182
/**

0 commit comments

Comments
 (0)