@across-protocol/sdk 4.3.6 → 4.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/arch/svm/SpokeUtils.d.ts +9 -1
  2. package/dist/cjs/arch/svm/SpokeUtils.js +52 -3
  3. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +1 -0
  5. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -0
  6. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  7. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +1 -0
  8. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +2 -0
  9. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  10. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +1 -0
  11. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  12. package/dist/cjs/clients/SpokePoolClient/index.js +6 -7
  13. package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
  14. package/dist/cjs/clients/SpokePoolClient/types.d.ts +2 -0
  15. package/dist/cjs/clients/SpokePoolClient/types.js +6 -0
  16. package/dist/cjs/clients/SpokePoolClient/types.js.map +1 -0
  17. package/dist/esm/arch/svm/SpokeUtils.d.ts +18 -2
  18. package/dist/esm/arch/svm/SpokeUtils.js +59 -3
  19. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  20. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +1 -0
  21. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -0
  22. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  23. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +1 -0
  24. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +2 -0
  25. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  26. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +1 -0
  27. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  28. package/dist/esm/clients/SpokePoolClient/index.js +5 -4
  29. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  30. package/dist/esm/clients/SpokePoolClient/types.d.ts +2 -0
  31. package/dist/esm/clients/SpokePoolClient/types.js +3 -0
  32. package/dist/esm/clients/SpokePoolClient/types.js.map +1 -0
  33. package/dist/types/arch/svm/SpokeUtils.d.ts +18 -2
  34. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  35. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +1 -0
  36. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  37. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +1 -0
  38. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts.map +1 -1
  39. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +1 -0
  40. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  41. package/dist/types/clients/SpokePoolClient/index.d.ts.map +1 -1
  42. package/dist/types/clients/SpokePoolClient/types.d.ts +3 -0
  43. package/dist/types/clients/SpokePoolClient/types.d.ts.map +1 -0
  44. package/package.json +1 -1
  45. package/src/arch/svm/SpokeUtils.ts +78 -3
  46. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +2 -0
  47. package/src/clients/SpokePoolClient/SVMSpokePoolClient.ts +2 -0
  48. package/src/clients/SpokePoolClient/SpokePoolClient.ts +1 -0
  49. package/src/clients/SpokePoolClient/index.ts +5 -2
  50. package/src/clients/SpokePoolClient/types.ts +2 -0
@@ -671,21 +671,95 @@ export const createDepositInstruction = async (
671
671
  * Creates a request slow fill instruction.
672
672
  * @param signer - The signer of the transaction.
673
673
  * @param solanaClient - The Solana client.
674
- * @param depositInput - The deposit input.
674
+ * @param requestSlowFillInput - The input arguments for the `requestSlowFill` instruction.
675
675
  * @returns The request slow fill instruction.
676
676
  */
677
677
  export const createRequestSlowFillInstruction = async (
678
678
  signer: TransactionSigner,
679
679
  solanaClient: SVMProvider,
680
- depositInput: SvmSpokeClient.RequestSlowFillInput
680
+ requestSlowFillInput: SvmSpokeClient.RequestSlowFillInput
681
681
  ) => {
682
- const requestSlowFillIx = SvmSpokeClient.getRequestSlowFillInstruction(depositInput);
682
+ const requestSlowFillIx = SvmSpokeClient.getRequestSlowFillInstruction(requestSlowFillInput);
683
683
 
684
684
  return pipe(await createDefaultTransaction(solanaClient, signer), (tx) =>
685
685
  appendTransactionMessageInstruction(requestSlowFillIx, tx)
686
686
  );
687
687
  };
688
688
 
689
+ /**
690
+ * @notice Return the requestSlowFill transaction for a given deposit
691
+ * @param spokePoolAddr Address of the spoke pool we're trying to fill through
692
+ * @param solanaClient RPC client to interact with Solana chain
693
+ * @param relayData RelayData instance, supplemented with destinationChainId
694
+ * @param signer signer associated with the relayer creating a Fill.
695
+ * @returns requestSlowFill transaction
696
+ */
697
+ export async function getSlowFillRequestTx(
698
+ spokePoolAddr: SvmAddress,
699
+ solanaClient: SVMProvider,
700
+ relayData: Omit<RelayData, "recipient" | "outputToken"> & {
701
+ destinationChainId: number;
702
+ recipient: SvmAddress;
703
+ outputToken: SvmAddress;
704
+ },
705
+ signer: TransactionSigner
706
+ ) {
707
+ const {
708
+ depositor,
709
+ recipient,
710
+ inputToken,
711
+ outputToken,
712
+ exclusiveRelayer,
713
+ destinationChainId,
714
+ originChainId,
715
+ depositId,
716
+ fillDeadline,
717
+ exclusivityDeadline,
718
+ message,
719
+ } = relayData;
720
+
721
+ const program = toAddress(spokePoolAddr);
722
+ const relayDataHash = getRelayDataHash(relayData, destinationChainId);
723
+
724
+ const [state, fillStatus, eventAuthority] = await Promise.all([
725
+ getStatePda(program),
726
+ getFillStatusPda(program, relayData, destinationChainId),
727
+ getEventAuthority(program),
728
+ ]);
729
+
730
+ const depositIdBuffer = new Uint8Array(32);
731
+ const shortenedBuffer = arrayify(depositId.toHexString());
732
+ depositIdBuffer.set(shortenedBuffer, 32 - shortenedBuffer.length);
733
+
734
+ const relayDataInput: SvmSpokeClient.RequestSlowFillInput["relayData"] = {
735
+ depositor: toAddress(depositor),
736
+ recipient: toAddress(recipient),
737
+ exclusiveRelayer: toAddress(exclusiveRelayer),
738
+ inputToken: toAddress(inputToken),
739
+ outputToken: toAddress(outputToken),
740
+ inputAmount: bigToU8a32(relayData.inputAmount.toBigInt()),
741
+ outputAmount: relayData.outputAmount.toBigInt(),
742
+ originChainId: BigInt(originChainId),
743
+ depositId: depositIdBuffer,
744
+ fillDeadline: fillDeadline,
745
+ exclusivityDeadline: exclusivityDeadline,
746
+ message: arrayify(message),
747
+ };
748
+
749
+ const requestSlowFillInput: SvmSpokeClient.RequestSlowFillInput = {
750
+ signer,
751
+ state,
752
+ fillStatus,
753
+ eventAuthority,
754
+ program,
755
+ relayHash: arrayify(relayDataHash),
756
+ relayData: relayDataInput,
757
+ systemProgram: SYSTEM_PROGRAM_ADDRESS,
758
+ };
759
+
760
+ return createRequestSlowFillInstruction(signer, solanaClient, requestSlowFillInput);
761
+ }
762
+
689
763
  /**
690
764
  * Creates a close fill PDA instruction.
691
765
  * @param signer - The signer of the transaction.
@@ -707,6 +781,7 @@ export const createCloseFillPdaInstruction = async (
707
781
  appendTransactionMessageInstruction(closeFillPdaIx, tx)
708
782
  );
709
783
  };
784
+
710
785
  export async function getAssociatedTokenAddress(
711
786
  owner: SvmAddress,
712
787
  mint: SvmAddress,
@@ -29,11 +29,13 @@ import { isUpdateFailureReason } from "../BaseAbstractClient";
29
29
  import { knownEventNames, SpokePoolClient, SpokePoolUpdate } from "./SpokePoolClient";
30
30
  import winston from "winston";
31
31
  import { HubPoolClient } from "../HubPoolClient";
32
+ import { EVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
32
33
 
33
34
  /**
34
35
  * An EVM-specific SpokePoolClient.
35
36
  */
36
37
  export class EVMSpokePoolClient extends SpokePoolClient {
38
+ readonly type = EVM_SPOKE_POOL_CLIENT_TYPE;
37
39
  constructor(
38
40
  logger: winston.Logger,
39
41
  public readonly spokePool: Contract,
@@ -24,12 +24,14 @@ import {
24
24
  import { isUpdateFailureReason } from "../BaseAbstractClient";
25
25
  import { HubPoolClient } from "../HubPoolClient";
26
26
  import { knownEventNames, SpokePoolClient, SpokePoolUpdate } from "./SpokePoolClient";
27
+ import { SVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
27
28
 
28
29
  /**
29
30
  * SvmSpokePoolClient is a client for the SVM SpokePool program. It extends the base SpokePoolClient
30
31
  * and implements the abstract methods required for interacting with an SVM Spoke Pool.
31
32
  */
32
33
  export class SVMSpokePoolClient extends SpokePoolClient {
34
+ readonly type = SVM_SPOKE_POOL_CLIENT_TYPE;
33
35
  /**
34
36
  * Note: Strongly prefer to use the async create() method to instantiate.
35
37
  */
@@ -79,6 +79,7 @@ export const knownEventNames = [
79
79
  * for events and storing them in memory. It also provides some convenience methods for querying the stored events.
80
80
  */
81
81
  export abstract class SpokePoolClient extends BaseAbstractClient {
82
+ abstract readonly type: string;
82
83
  protected currentTime = 0;
83
84
  protected duplicateDepositHashes: { [depositHash: string]: DepositWithBlock[] } = {};
84
85
  protected depositHashesToFills: { [depositHash: string]: FillWithBlock[] } = {};
@@ -1,6 +1,7 @@
1
1
  import { EVMSpokePoolClient } from "./EVMSpokePoolClient";
2
2
  import { SVMSpokePoolClient } from "./SVMSpokePoolClient";
3
3
  import { SpokePoolClient } from "./SpokePoolClient";
4
+ import { EVM_SPOKE_POOL_CLIENT_TYPE, SVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
4
5
 
5
6
  export { EVMSpokePoolClient } from "./EVMSpokePoolClient";
6
7
  export { SpokePoolClient, SpokePoolUpdate } from "./SpokePoolClient";
@@ -13,7 +14,8 @@ export { SpokePoolManager } from "./SpokePoolClientManager";
13
14
  * @returns True if the SpokePoolClient is an EVMSpokePoolClient, false otherwise.
14
15
  */
15
16
  export function isEVMSpokePoolClient(spokePoolClient: SpokePoolClient): spokePoolClient is EVMSpokePoolClient {
16
- return spokePoolClient instanceof EVMSpokePoolClient;
17
+ // @TODO: Shoud we handle the case where spokePoolClient is undefined?
18
+ return spokePoolClient?.type === EVM_SPOKE_POOL_CLIENT_TYPE;
17
19
  }
18
20
 
19
21
  /**
@@ -22,5 +24,6 @@ export function isEVMSpokePoolClient(spokePoolClient: SpokePoolClient): spokePoo
22
24
  * @returns True if the SpokePoolClient is an SVMSpokePoolClient, false otherwise.
23
25
  */
24
26
  export function isSVMSpokePoolClient(spokePoolClient: SpokePoolClient): spokePoolClient is SVMSpokePoolClient {
25
- return spokePoolClient instanceof SVMSpokePoolClient;
27
+ // @TODO: Shoud we handle the case where spokePoolClient is undefined?
28
+ return spokePoolClient?.type === SVM_SPOKE_POOL_CLIENT_TYPE;
26
29
  }
@@ -0,0 +1,2 @@
1
+ export const EVM_SPOKE_POOL_CLIENT_TYPE = "EVM";
2
+ export const SVM_SPOKE_POOL_CLIENT_TYPE = "SVM";