@shogun-sdk/intents-sdk 1.1.0 → 1.2.0

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 (118) hide show
  1. package/dist/esm/constants.js +24 -8
  2. package/dist/esm/constants.js.map +1 -1
  3. package/dist/esm/core/evm/intent-provider.js +55 -2
  4. package/dist/esm/core/evm/intent-provider.js.map +1 -1
  5. package/dist/esm/core/evm/order-signature.js +12 -1
  6. package/dist/esm/core/evm/order-signature.js.map +1 -1
  7. package/dist/esm/core/evm/permit2.js +24 -1
  8. package/dist/esm/core/evm/permit2.js.map +1 -1
  9. package/dist/esm/core/evm/sdk.js +5 -18
  10. package/dist/esm/core/evm/sdk.js.map +1 -1
  11. package/dist/esm/core/evm/validator.js +21 -0
  12. package/dist/esm/core/evm/validator.js.map +1 -1
  13. package/dist/esm/core/orders/api/index.js +31 -0
  14. package/dist/esm/core/orders/api/index.js.map +1 -0
  15. package/dist/esm/core/orders/cross-chain.js +3 -0
  16. package/dist/esm/core/orders/cross-chain.js.map +1 -1
  17. package/dist/esm/core/orders/dca-single-chain.js +169 -0
  18. package/dist/esm/core/orders/dca-single-chain.js.map +1 -0
  19. package/dist/esm/core/orders/single-chain.js +4 -0
  20. package/dist/esm/core/orders/single-chain.js.map +1 -1
  21. package/dist/esm/core/sdk.js +55 -81
  22. package/dist/esm/core/sdk.js.map +1 -1
  23. package/dist/esm/core/solana/dca/cancel-order.js +61 -0
  24. package/dist/esm/core/solana/dca/cancel-order.js.map +1 -0
  25. package/dist/esm/core/solana/dca/create-order.js +82 -0
  26. package/dist/esm/core/solana/dca/create-order.js.map +1 -0
  27. package/dist/esm/core/solana/inspect.js +43 -0
  28. package/dist/esm/core/solana/inspect.js.map +1 -0
  29. package/dist/esm/core/solana/sdk.js +36 -18
  30. package/dist/esm/core/solana/sdk.js.map +1 -1
  31. package/dist/esm/core/solana/utils.js.map +1 -1
  32. package/dist/esm/core/solana/validator.js +3 -0
  33. package/dist/esm/core/solana/validator.js.map +1 -1
  34. package/dist/esm/core/sui/sdk.js +0 -21
  35. package/dist/esm/core/sui/sdk.js.map +1 -1
  36. package/dist/esm/core/sui/validator.js +4 -0
  37. package/dist/esm/core/sui/validator.js.map +1 -1
  38. package/dist/esm/index.js +4 -1
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/utils/base-validator.js +28 -0
  41. package/dist/esm/utils/base-validator.js.map +1 -1
  42. package/dist/esm/utils/order-validator.js +31 -0
  43. package/dist/esm/utils/order-validator.js.map +1 -1
  44. package/dist/esm/utils/quote/liquidswap.js.map +1 -1
  45. package/dist/types/constants.d.ts +10 -7
  46. package/dist/types/constants.d.ts.map +1 -1
  47. package/dist/types/core/evm/intent-provider.d.ts +5 -2
  48. package/dist/types/core/evm/intent-provider.d.ts.map +1 -1
  49. package/dist/types/core/evm/order-signature.d.ts +5 -0
  50. package/dist/types/core/evm/order-signature.d.ts.map +1 -1
  51. package/dist/types/core/evm/permit2.d.ts +90 -0
  52. package/dist/types/core/evm/permit2.d.ts.map +1 -1
  53. package/dist/types/core/evm/sdk.d.ts +3 -5
  54. package/dist/types/core/evm/sdk.d.ts.map +1 -1
  55. package/dist/types/core/evm/validator.d.ts +4 -0
  56. package/dist/types/core/evm/validator.d.ts.map +1 -1
  57. package/dist/types/core/orders/api/index.d.ts +8 -0
  58. package/dist/types/core/orders/api/index.d.ts.map +1 -0
  59. package/dist/types/core/orders/cross-chain.d.ts.map +1 -1
  60. package/dist/types/core/orders/dca-single-chain.d.ts +47 -0
  61. package/dist/types/core/orders/dca-single-chain.d.ts.map +1 -0
  62. package/dist/types/core/orders/single-chain.d.ts.map +1 -1
  63. package/dist/types/core/sdk.d.ts +16 -12
  64. package/dist/types/core/sdk.d.ts.map +1 -1
  65. package/dist/types/core/solana/dca/cancel-order.d.ts +5 -0
  66. package/dist/types/core/solana/dca/cancel-order.d.ts.map +1 -0
  67. package/dist/types/core/solana/dca/create-order.d.ts +8 -0
  68. package/dist/types/core/solana/dca/create-order.d.ts.map +1 -0
  69. package/dist/types/core/solana/inspect.d.ts +14 -0
  70. package/dist/types/core/solana/inspect.d.ts.map +1 -0
  71. package/dist/types/core/solana/sdk.d.ts +4 -5
  72. package/dist/types/core/solana/sdk.d.ts.map +1 -1
  73. package/dist/types/core/solana/utils.d.ts +2 -1
  74. package/dist/types/core/solana/utils.d.ts.map +1 -1
  75. package/dist/types/core/solana/validator.d.ts +1 -0
  76. package/dist/types/core/solana/validator.d.ts.map +1 -1
  77. package/dist/types/core/sui/sdk.d.ts +1 -6
  78. package/dist/types/core/sui/sdk.d.ts.map +1 -1
  79. package/dist/types/core/sui/validator.d.ts +1 -0
  80. package/dist/types/core/sui/validator.d.ts.map +1 -1
  81. package/dist/types/index.d.ts +4 -1
  82. package/dist/types/index.d.ts.map +1 -1
  83. package/dist/types/types/intent.d.ts +22 -0
  84. package/dist/types/types/intent.d.ts.map +1 -1
  85. package/dist/types/utils/base-validator.d.ts +7 -0
  86. package/dist/types/utils/base-validator.d.ts.map +1 -1
  87. package/dist/types/utils/order-validator.d.ts +15 -0
  88. package/dist/types/utils/order-validator.d.ts.map +1 -1
  89. package/package.json +1 -1
  90. package/src/auth/siwe.ts +1 -1
  91. package/src/constants.ts +72 -39
  92. package/src/core/evm/connectors/hyperevm.ts +1 -1
  93. package/src/core/evm/intent-provider.ts +88 -4
  94. package/src/core/evm/order-signature.ts +23 -1
  95. package/src/core/evm/permit2.ts +47 -1
  96. package/src/core/evm/sdk.ts +15 -21
  97. package/src/core/evm/validator.ts +32 -0
  98. package/src/core/orders/api/index.ts +33 -0
  99. package/src/core/orders/cross-chain.ts +4 -0
  100. package/src/core/orders/dca-single-chain.ts +143 -0
  101. package/src/core/orders/single-chain.ts +6 -0
  102. package/src/core/sdk.ts +73 -102
  103. package/src/core/solana/cancel-order.ts +1 -1
  104. package/src/core/solana/dca/cancel-order.ts +91 -0
  105. package/src/core/solana/dca/create-order.ts +142 -0
  106. package/src/core/solana/inspect.ts +50 -0
  107. package/src/core/solana/order-instructions.ts +1 -1
  108. package/src/core/solana/sdk.ts +65 -21
  109. package/src/core/solana/utils.ts +2 -1
  110. package/src/core/solana/validator.ts +4 -0
  111. package/src/core/sui/sdk.ts +2 -24
  112. package/src/core/sui/validator.ts +5 -0
  113. package/src/index.ts +13 -1
  114. package/src/types/api.ts +1 -1
  115. package/src/types/intent.ts +27 -0
  116. package/src/utils/base-validator.ts +40 -0
  117. package/src/utils/order-validator.ts +38 -0
  118. package/src/utils/quote/liquidswap.ts +2 -2
@@ -2,8 +2,9 @@ import BN from 'bn.js';
2
2
  import type { SingleChainOrder } from '../orders/single-chain.js';
3
3
  import { PublicKey } from '@solana/web3.js';
4
4
  import sha3 from 'js-sha3';
5
+ import type { DcaSingleChainOrder } from '../orders/dca-single-chain.js';
5
6
 
6
- export function genSecretHashAndNumber(order: SingleChainOrder): {
7
+ export function genSecretHashAndNumber(order: SingleChainOrder | DcaSingleChainOrder): {
7
8
  secretHash: number[];
8
9
  secretNumber: string;
9
10
  } {
@@ -27,4 +27,8 @@ export class SolanaValidator extends BaseValidator {
27
27
  // No chain-specific validation implemented for now for Solana
28
28
  return;
29
29
  }
30
+
31
+ override async validateDcaSingleChainOrderFeasability(): Promise<void> {
32
+ return Promise.resolve();
33
+ }
30
34
  }
@@ -5,11 +5,9 @@ import { BaseSDK } from '../sdk.js';
5
5
  import { createSuiClient } from './client.js';
6
6
  import { getSuiOrderTransaction } from './order-transaction.js';
7
7
  import { getSuiCancelCrossChainOrder } from './cancel.js';
8
- import type { CrossChainOrderPrepared, SingleChainOrderPrepared } from '../../types/intent.js';
8
+ import type { CrossChainOrderPrepared } from '../../types/intent.js';
9
9
  import type { CrossChainOrder } from '../orders/cross-chain.js';
10
- import type { ApiUserOrders } from '../../types/api.js';
11
10
  import { fetchJWTToken, fetchSiweMessage } from '../../auth/siwe.js';
12
- import { fetchUserOrders } from '../orders/api/fetch.js';
13
11
  import { ChainID } from '../../chains.js';
14
12
 
15
13
  /**
@@ -24,7 +22,6 @@ export class SuiSDK extends BaseSDK {
24
22
  private readonly config: SuiConfig;
25
23
  /** Client for Sui RPC interactions and transaction handling */
26
24
  private client: SuiClient;
27
- private token?: string;
28
25
 
29
26
  /**
30
27
  * Creates a new instance of the Sui SDK
@@ -60,10 +57,6 @@ export class SuiSDK extends BaseSDK {
60
57
  return Ed25519Keypair.fromSecretKey(this.config.privateKey);
61
58
  }
62
59
 
63
- protected override prepareSingleChainOrder(): Promise<SingleChainOrderPrepared> {
64
- throw new Error('Single-chain orders are not supported on Sui');
65
- }
66
-
67
60
  public async authenticate(token?: string): Promise<string> {
68
61
  const wallet = await this.getUserAddress();
69
62
 
@@ -93,21 +86,6 @@ export class SuiSDK extends BaseSDK {
93
86
  return newToken;
94
87
  }
95
88
 
96
- public setToken(token: string) {
97
- this.token = token;
98
-
99
- return this;
100
- }
101
-
102
- public override async getOrders(): Promise<ApiUserOrders> {
103
- if (!this.token) {
104
- throw new Error('No token provided');
105
- }
106
-
107
- const orders = await fetchUserOrders(this.token);
108
-
109
- return orders;
110
- }
111
89
  /**
112
90
  * Prepares a Sui order for submission
113
91
  *
@@ -121,7 +99,7 @@ export class SuiSDK extends BaseSDK {
121
99
  * @returns Promise resolving to a prepared order with Sui-specific data
122
100
  * @protected
123
101
  */
124
- protected async prepareCrossChainOrder(order: CrossChainOrder): Promise<CrossChainOrderPrepared> {
102
+ protected override async prepareCrossChainOrder(order: CrossChainOrder): Promise<CrossChainOrderPrepared> {
125
103
  const signer = this.getKeyPair();
126
104
 
127
105
  const transaction = await getSuiOrderTransaction(order);
@@ -1,6 +1,7 @@
1
1
  import { isValidSuiAddress, normalizeSuiAddress } from '@mysten/sui/utils';
2
2
  import { MAX_UINT_64 } from '../../constants.js';
3
3
  import { BaseValidator } from '../../utils/base-validator.js';
4
+ import { ValidationError } from '../../errors/index.js';
4
5
 
5
6
  const SUI_TOKEN_ADDRESS_REGEX = /^0x[a-fA-F0-9]{64}::\w+::\w+$/;
6
7
 
@@ -33,4 +34,8 @@ export class SuiValidator extends BaseValidator {
33
34
  override validateSingleChainOrderFeasability(): Promise<void> {
34
35
  return Promise.resolve();
35
36
  }
37
+
38
+ override validateDcaSingleChainOrderFeasability(): Promise<void> {
39
+ throw new ValidationError('DCA orders are not supported on Sui');
40
+ }
36
41
  }
package/src/index.ts CHANGED
@@ -11,9 +11,18 @@ export { SingleChainOrder } from './core/orders/single-chain.js';
11
11
  export type { CreateSingleChainOrderParams } from './core/orders/single-chain.js';
12
12
 
13
13
  export { fetchUserOrders } from './core/orders/api/fetch.js';
14
+ export { AuctioneerAPI } from './core/orders/api/index.js';
14
15
  export { type FetchJWTParams, type FetchSiweMessageParams, fetchJWTToken, fetchSiweMessage } from './auth/siwe.js';
15
16
  export { ValidationError } from './errors/index.js';
16
- export { type ApiCrossChainOrder, type ApiResponse, type ApiSingleChainOrder, type ApiUserOrders, type ChainOrderStatus, isErrorApiResponse, isSuccessApiResponse } from './types/api.js';
17
+ export {
18
+ type ApiCrossChainOrder,
19
+ type ApiResponse,
20
+ type ApiSingleChainOrder,
21
+ type ApiUserOrders,
22
+ type ChainOrderStatus,
23
+ isErrorApiResponse,
24
+ isSuccessApiResponse,
25
+ } from './types/api.js';
17
26
  export { calculateAmounts, getCoinFromResponse, getTokensData } from './utils/defillama.js';
18
27
  export type { DefiLlamaCoinData, DefiLlamaTokensResponse } from './utils/defillama.js';
19
28
  export {
@@ -23,8 +32,11 @@ export {
23
32
  type CancelCrossChainOrderParams,
24
33
  getInvalidateNoncesRawData,
25
34
  } from './core/evm/cancel-order.js';
35
+ export { cancelDcaSingleChainOrderInstructions } from './core/solana/dca/cancel-order.js';
26
36
  export { getEVMCrossChainOrderTypedData, getEVMSingleChainOrderTypedData } from './core/evm/order-signature.js';
27
37
 
38
+ export { getSolanaOrdersWithLockedFunds } from './core/solana/inspect.js';
39
+
28
40
  export {
29
41
  getSolanaCrossChainOrderInstructions,
30
42
  getSolanaSingleChainOrderInstructions,
package/src/types/api.ts CHANGED
@@ -75,4 +75,4 @@ export function isErrorApiResponse<T extends ValidResponseData>(
75
75
  response: ApiResponse<T>,
76
76
  ): response is ApiResponse<T> & { success: false; error: unknown } {
77
77
  return !response.success;
78
- }
78
+ }
@@ -2,6 +2,7 @@ import type { SupportedChain } from '../chains.js';
2
2
  import type { CrossChainOrder } from '../core/orders/cross-chain.js';
3
3
  import type { ExtraTransfer } from '../core/orders/common.js';
4
4
  import type { SingleChainOrder } from '../core/orders/single-chain.js';
5
+ import type { DcaSingleChainOrder } from '../core/orders/dca-single-chain.js';
5
6
 
6
7
  /**
7
8
  * Details required to execute the order on the destination chain
@@ -120,3 +121,29 @@ export type SingleChainOrderPrepared = {
120
121
  order: SingleChainOrder;
121
122
  preparedData: SingleChainPreparedData;
122
123
  };
124
+
125
+ export type DcaSingleChainUserIntentRequest = {
126
+ genericData: DcaSingleChainOrder;
127
+ chainSpecificData: {
128
+ EVM?: DcaSingleChainEVMPreparedData;
129
+ Solana?: DcaSingleChainSolanaPreparedData;
130
+ Sui?: never; // DCA not supported on Sui
131
+ };
132
+ };
133
+
134
+ export type DcaSingleChainEVMPreparedData = {
135
+ nonce: string;
136
+ signature: string | Hash;
137
+ };
138
+
139
+ export type DcaSingleChainSolanaPreparedData = {
140
+ secretNumber: string;
141
+ orderPubkey: string;
142
+ };
143
+
144
+ export type DcaSingleChainPreparedData = DcaSingleChainEVMPreparedData | DcaSingleChainSolanaPreparedData;
145
+
146
+ export type DcaSingleChainOrderPrepared = {
147
+ order: DcaSingleChainOrder;
148
+ preparedData: DcaSingleChainPreparedData;
149
+ };
@@ -1,4 +1,5 @@
1
1
  import type { CreateCrossChainOrderParams } from '../core/orders/cross-chain.js';
2
+ import type { CreateDcaSingleChainOrderParams } from '../core/orders/dca-single-chain.js';
2
3
  import type { CreateSingleChainOrderParams } from '../core/orders/single-chain.js';
3
4
  import { ValidationError } from '../errors/index.js';
4
5
  import type { IChainValidator } from './order-validator.js';
@@ -59,6 +60,45 @@ export abstract class BaseValidator implements IChainValidator {
59
60
  }
60
61
  }
61
62
 
63
+ abstract validateDcaSingleChainOrderFeasability(
64
+ order: CreateDcaSingleChainOrderParams & { user: string },
65
+ ): Promise<void>;
66
+
67
+ async validateDcaSingleChainOrder(order: CreateDcaSingleChainOrderParams & { user: string }): Promise<void> {
68
+ this.validateTokenAddress(order.tokenIn);
69
+ this.validateTokenAddress(order.tokenOut);
70
+ this.validateAmount(order.amountInPerInterval);
71
+ this.validateAmount(order.amountOutMin ?? 1n);
72
+ this.validateAddress(order.destinationAddress);
73
+
74
+ // Validate DCA-specific parameters
75
+ if (order.totalIntervals <= 0) {
76
+ throw new ValidationError('Total intervals must be greater than 0');
77
+ }
78
+
79
+ if (order.intervalDuration <= 0) {
80
+ throw new ValidationError('Interval duration must be greater than 0');
81
+ }
82
+
83
+ if (order.startTime < 0) {
84
+ throw new ValidationError('Start time must be non-negative');
85
+ }
86
+
87
+ // Validate total amount doesn't overflow
88
+ const totalAmount = order.amountInPerInterval * BigInt(order.totalIntervals);
89
+ this.validateAmount(totalAmount);
90
+
91
+ if (order.extraTransfers) {
92
+ for (const extraTransfer of order.extraTransfers) {
93
+ this.validateAddress(extraTransfer.receiver);
94
+ this.validateTokenAddress(extraTransfer.token);
95
+ this.validateAmount(extraTransfer.amount);
96
+ }
97
+ }
98
+
99
+ await this.validateDcaSingleChainOrderFeasability(order);
100
+ }
101
+
62
102
  /**
63
103
  * Helper methods that throw specific validation errors
64
104
  */
@@ -26,6 +26,7 @@ export interface IChainValidator extends IAddressValidator, ITokenValidator, IAm
26
26
  validateSourceChain(order: CreateCrossChainOrderParams & { user: string }): Promise<void>;
27
27
  validateDestinationChain(order: CreateCrossChainOrderParams): void;
28
28
  validateSingleChainOrder(order: CreateSingleChainOrderParams & { user: string }): Promise<void>;
29
+ validateDcaSingleChainOrder(order: CreateDcaSingleChainOrderParams & { user: string }): Promise<void>;
29
30
  }
30
31
 
31
32
  /**
@@ -99,3 +100,40 @@ export class SingleChainOrderValidator {
99
100
  chainValidator.validateSingleChainOrder(order);
100
101
  }
101
102
  }
103
+
104
+ import type { CreateDcaSingleChainOrderParams } from '../core/orders/dca-single-chain.js';
105
+
106
+ export interface IDcaValidator {
107
+ validateDcaSingleChainOrder(order: CreateDcaSingleChainOrderParams & { user: string }): Promise<void>;
108
+ }
109
+
110
+ export class DcaSingleChainOrderValidator {
111
+ private readonly commonValidator = new CommonValidator();
112
+
113
+ async validateOrder(order: CreateDcaSingleChainOrderParams & { user: string }): Promise<void> {
114
+ this.commonValidator.validateDeadline(order.deadline);
115
+
116
+ // Validate start time is in the future or current time
117
+ if (order.startTime < Math.floor(Date.now() / 1000)) {
118
+ throw new ValidationError('Start time must be in the future or current time');
119
+ }
120
+
121
+ // Validate intervals
122
+ if (order.totalIntervals <= 0) {
123
+ throw new ValidationError('Total intervals must be greater than 0');
124
+ }
125
+
126
+ if (order.intervalDuration <= 0) {
127
+ throw new ValidationError('Interval duration must be greater than 0');
128
+ }
129
+
130
+ // Validate that the order will complete before deadline
131
+ const estimatedCompletionTime = order.startTime + order.totalIntervals * order.intervalDuration;
132
+ if (estimatedCompletionTime > order.deadline) {
133
+ throw new ValidationError('Order would complete after deadline');
134
+ }
135
+
136
+ const chainValidator = ValidatorFactory.getValidatorForChain(order.chainId);
137
+ await chainValidator.validateDcaSingleChainOrder(order);
138
+ }
139
+ }
@@ -18,8 +18,8 @@ const LIQUID_SWAP_API_URL = 'https://api.liqd.ag';
18
18
 
19
19
  export class LiquidSwapQuoteProvider {
20
20
  public async getQuote(liquidSwapParams: LiquidSwapQuoteParams): Promise<LiquidSwapQuoteResponse> {
21
- const params = {...liquidSwapParams};
22
-
21
+ const params = { ...liquidSwapParams };
22
+
23
23
  if (isNativeEvmToken(params.tokenOut)) {
24
24
  params.tokenOut = WRAPPED_ETH_ADDRESSES[ChainID.Hyperliquid];
25
25
  }