-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support pfl_sendRawTransactionConditional
- Loading branch information
1 parent
ae76280
commit 8faacd9
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Logger } from "@alto/utils" | ||
import { join } from "path" | ||
import { | ||
Hex, | ||
createClient, | ||
http, | ||
SendRawTransactionReturnType, | ||
Hash, | ||
WalletClient, | ||
PublicClient, | ||
toHex, | ||
BaseError | ||
} from "viem" | ||
|
||
const pflClient = createClient({ | ||
transport: http("https://polygon-rpc.fastlane.xyz") | ||
}) | ||
|
||
export async function sendPflConditional({ | ||
serializedTransaction, | ||
publicClient, | ||
walletClient, | ||
logger | ||
}: { | ||
serializedTransaction: Hash | ||
publicClient: PublicClient | ||
walletClient: WalletClient | ||
logger: Logger | ||
}): Promise<SendRawTransactionReturnType> { | ||
try { | ||
const blockNumberMin = await publicClient.getBlockNumber() | ||
const blockNumberMax = blockNumberMin + 25n | ||
|
||
const timestampMin = Date.now() / 1000 | ||
const timestampMax = timestampMin + 500 | ||
|
||
const opts = { | ||
//knownAccounts: {} | ||
blockNumberMin: toHex(blockNumberMin), | ||
blockNumberMax: toHex(blockNumberMax), | ||
timestampMin: Math.floor(timestampMin), | ||
timestampMax: Math.floor(timestampMax) | ||
} | ||
|
||
const txHash = (await pflClient.request({ | ||
// @ts-ignore | ||
method: "pfl_sendRawTransactionConditional", | ||
// @ts-ignore | ||
params: [serializedTransaction, opts] | ||
})) as Hex | ||
|
||
if (!txHash) { | ||
const error = new BaseError( | ||
"FastLane API returned empty transaction hash" | ||
) | ||
error.details = | ||
"PFL conditional transaction failed: No txHash in response" | ||
throw error | ||
} | ||
|
||
return txHash | ||
} catch (e: unknown) { | ||
logger.error( | ||
"Error sending through pfl_sendRawTransactionConditional ", | ||
(e as any)?.details | ||
) | ||
return await walletClient.sendRawTransaction({ serializedTransaction }) | ||
} | ||
} |