genius-intents 0.18.2 → 0.19.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.
- package/CHANGELOG.md +46 -3
- package/dist/genius-intents.d.ts.map +1 -1
- package/dist/genius-intents.js +8 -2
- package/dist/genius-intents.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/dex/algebra/algebra-factory.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.js +34 -0
- package/dist/lib/dex/algebra/algebra-factory.abi.js.map +1 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.js +135 -0
- package/dist/lib/dex/algebra/algebra-quoter.abi.js.map +1 -0
- package/dist/lib/dex/algebra/algebra-router.abi.d.ts +3 -0
- package/dist/lib/dex/algebra/algebra-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/algebra/algebra-router.abi.js +273 -0
- package/dist/lib/dex/algebra/algebra-router.abi.js.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.d.ts +3 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.js +30 -0
- package/dist/lib/dex/uniswapv3/slipstream-quoter.abi.js.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.d.ts +3 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.js +45 -0
- package/dist/lib/dex/uniswapv3/slipstream-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.js +17 -0
- package/dist/lib/dex/ve33/aerodrome-factory.abi.js.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.js +119 -0
- package/dist/lib/dex/ve33/aerodrome-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.js +1492 -0
- package/dist/lib/dex/ve33/blackhole-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.js +502 -0
- package/dist/lib/dex/ve33/pharaoh-router.abi.js.map +1 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.d.ts +3 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.d.ts.map +1 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.js +634 -0
- package/dist/lib/dex/ve33/velodrome-router.abi.js.map +1 -0
- package/dist/protocols/algebra/algebra.service.d.ts +61 -0
- package/dist/protocols/algebra/algebra.service.d.ts.map +1 -0
- package/dist/protocols/algebra/algebra.service.js +562 -0
- package/dist/protocols/algebra/algebra.service.js.map +1 -0
- package/dist/protocols/algebra/algebra.types.d.ts +83 -0
- package/dist/protocols/algebra/algebra.types.d.ts.map +1 -0
- package/dist/protocols/algebra/algebra.types.js +9 -0
- package/dist/protocols/algebra/algebra.types.js.map +1 -0
- package/dist/protocols/algebra/index.d.ts +3 -0
- package/dist/protocols/algebra/index.d.ts.map +1 -0
- package/dist/protocols/algebra/index.js +21 -0
- package/dist/protocols/algebra/index.js.map +1 -0
- package/dist/protocols/okx/okx.service.d.ts +9 -8
- package/dist/protocols/okx/okx.service.d.ts.map +1 -1
- package/dist/protocols/okx/okx.service.js +133 -143
- package/dist/protocols/okx/okx.service.js.map +1 -1
- package/dist/protocols/okx/okx.types.d.ts +9 -3
- package/dist/protocols/okx/okx.types.d.ts.map +1 -1
- package/dist/protocols/relay/relay.service.d.ts +3 -0
- package/dist/protocols/relay/relay.service.d.ts.map +1 -1
- package/dist/protocols/relay/relay.service.js +7 -1
- package/dist/protocols/relay/relay.service.js.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.service.d.ts +0 -3
- package/dist/protocols/v2-dex/v2-dex.service.d.ts.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.service.js +54 -55
- package/dist/protocols/v2-dex/v2-dex.service.js.map +1 -1
- package/dist/protocols/v2-dex/v2-dex.types.d.ts +0 -10
- package/dist/protocols/v2-dex/v2-dex.types.d.ts.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.service.d.ts +50 -6
- package/dist/protocols/v3-dex/v3-dex.service.d.ts.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.service.js +369 -193
- package/dist/protocols/v3-dex/v3-dex.service.js.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.types.d.ts +4 -1
- package/dist/protocols/v3-dex/v3-dex.types.d.ts.map +1 -1
- package/dist/protocols/v3-dex/v3-dex.types.js +3 -0
- package/dist/protocols/v3-dex/v3-dex.types.js.map +1 -1
- package/dist/protocols/ve33/index.d.ts +3 -0
- package/dist/protocols/ve33/index.d.ts.map +1 -0
- package/dist/protocols/ve33/index.js +6 -0
- package/dist/protocols/ve33/index.js.map +1 -0
- package/dist/protocols/ve33/ve33.handlers.d.ts +3 -0
- package/dist/protocols/ve33/ve33.handlers.d.ts.map +1 -0
- package/dist/protocols/ve33/ve33.handlers.js +187 -0
- package/dist/protocols/ve33/ve33.handlers.js.map +1 -0
- package/dist/protocols/ve33/ve33.service.d.ts +26 -0
- package/dist/protocols/ve33/ve33.service.d.ts.map +1 -0
- package/dist/protocols/ve33/ve33.service.js +486 -0
- package/dist/protocols/ve33/ve33.service.js.map +1 -0
- package/dist/protocols/ve33/ve33.types.d.ts +136 -0
- package/dist/protocols/ve33/ve33.types.d.ts.map +1 -0
- package/dist/protocols/ve33/ve33.types.js +11 -0
- package/dist/protocols/ve33/ve33.types.js.map +1 -0
- package/dist/types/enums.d.ts +5 -2
- package/dist/types/enums.d.ts.map +1 -1
- package/dist/types/enums.js +3 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/price-params.d.ts +4 -0
- package/dist/types/price-params.d.ts.map +1 -1
- package/dist/types/price-response.d.ts +4 -2
- package/dist/types/price-response.d.ts.map +1 -1
- package/dist/types/quote-response.d.ts +3 -1
- package/dist/types/quote-response.d.ts.map +1 -1
- package/dist/utils/dex-deployment-key.d.ts +14 -0
- package/dist/utils/dex-deployment-key.d.ts.map +1 -0
- package/dist/utils/dex-deployment-key.js +17 -0
- package/dist/utils/dex-deployment-key.js.map +1 -0
- package/dist/utils/min-amount-out.d.ts +12 -0
- package/dist/utils/min-amount-out.d.ts.map +1 -0
- package/dist/utils/min-amount-out.js +18 -0
- package/dist/utils/min-amount-out.js.map +1 -0
- package/dist/utils/sort-addresses.d.ts +2 -0
- package/dist/utils/sort-addresses.d.ts.map +1 -0
- package/dist/utils/sort-addresses.js +14 -0
- package/dist/utils/sort-addresses.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
import type { ChainIdEnum } from '../../types/enums';
|
|
3
|
+
export declare enum AlgebraDexTagEnum {
|
|
4
|
+
BLACKHOLE = "blackhole"
|
|
5
|
+
}
|
|
6
|
+
export type AlgebraDeployment = {
|
|
7
|
+
tag: AlgebraDexTagEnum;
|
|
8
|
+
/** Factory that owns poolByPair/customPoolByPair/compute* */
|
|
9
|
+
factory: Address;
|
|
10
|
+
/** Quoter V2 (Algebra) used for off-chain quoting */
|
|
11
|
+
quoterV2: Address;
|
|
12
|
+
/** Swap Router capable of exactInput/exactInputSingle for Algebra paths */
|
|
13
|
+
router: Address;
|
|
14
|
+
/** Canonical/default pool deployer (factory.poolDeployer()) if you want to pin it;
|
|
15
|
+
* optional because we can read it from the factory at runtime. */
|
|
16
|
+
defaultDeployer?: Address;
|
|
17
|
+
/** Optional set of custom deployers that may have created custom pools
|
|
18
|
+
* (Blackhole publishes several). 20-byte addresses.
|
|
19
|
+
*/
|
|
20
|
+
customDeployers?: Address[];
|
|
21
|
+
};
|
|
22
|
+
export type AlgebraDeploymentsByChain = Partial<Record<ChainIdEnum, AlgebraDeployment[]>>;
|
|
23
|
+
export type AlgebraPriceOverrideParams = {
|
|
24
|
+
amountOutMin?: string;
|
|
25
|
+
pair?: Address;
|
|
26
|
+
deployer?: Address;
|
|
27
|
+
};
|
|
28
|
+
export type AlgebraResolveDeployerForPairParams = {
|
|
29
|
+
client: PublicClient;
|
|
30
|
+
deployments: AlgebraDeployment[];
|
|
31
|
+
pair: Address;
|
|
32
|
+
tokenA: Address;
|
|
33
|
+
tokenB: Address;
|
|
34
|
+
};
|
|
35
|
+
export type AlgebraResolveDeployerForPairResponse = {
|
|
36
|
+
deploymentIndex: number;
|
|
37
|
+
deployer: Address;
|
|
38
|
+
} | undefined;
|
|
39
|
+
export type AlgebraFoundPool = {
|
|
40
|
+
/** Pool address that actually exists (non-zero, has code) */
|
|
41
|
+
pool: Address;
|
|
42
|
+
/** Which deployer created this pool (required by QuoterV2 and path building) */
|
|
43
|
+
deployer: Address;
|
|
44
|
+
/** Which deployment entry produced this pool */
|
|
45
|
+
deploymentIndex: number;
|
|
46
|
+
/** 0 for default, 1 for custom (purely informational) */
|
|
47
|
+
kind: 'default' | 'custom';
|
|
48
|
+
};
|
|
49
|
+
export type AlgebraQuoteCandidate = {
|
|
50
|
+
deploymentIndex: number;
|
|
51
|
+
pool: Address;
|
|
52
|
+
deployer: Address;
|
|
53
|
+
tokenIn: Address;
|
|
54
|
+
tokenOut: Address;
|
|
55
|
+
};
|
|
56
|
+
export type AlgebraPriceProtocolResponse = {
|
|
57
|
+
/** "<TAG>:<router>:<factory>:<chainId>" */
|
|
58
|
+
deploymentKey: string;
|
|
59
|
+
/** Deployment assets */
|
|
60
|
+
router: Address;
|
|
61
|
+
factory: Address;
|
|
62
|
+
/** Chosen pool/deployer */
|
|
63
|
+
pool: Address;
|
|
64
|
+
deployer: Address;
|
|
65
|
+
/** Quote analytics (from QuoterV2) */
|
|
66
|
+
expectedAmountOut: string;
|
|
67
|
+
sqrtPriceX96After?: string;
|
|
68
|
+
initializedTicksCrossed?: number;
|
|
69
|
+
gasEstimate?: string;
|
|
70
|
+
/** Path bytes we would use for exactInput (single-hop here) */
|
|
71
|
+
path: Hex;
|
|
72
|
+
};
|
|
73
|
+
export type AlgebraQuoteProtocolResponse = AlgebraPriceProtocolResponse & {
|
|
74
|
+
/** Which router method we encoded (e.g., "SwapRouter.exactInput") */
|
|
75
|
+
functionSelector: string;
|
|
76
|
+
};
|
|
77
|
+
export type AlgebraConfig = {
|
|
78
|
+
/** viem chain configs keyed by ChainIdEnum (same shape you use elsewhere) */
|
|
79
|
+
algebraChainConfigs: Record<number, unknown>;
|
|
80
|
+
/** extra deployments to merge in */
|
|
81
|
+
algebraExtraDeployments?: AlgebraDeploymentsByChain;
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=algebra.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algebra.types.d.ts","sourceRoot":"","sources":["../../../src/protocols/algebra/algebra.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,oBAAY,iBAAiB;IAC3B,SAAS,cAAc;CACxB;AAGD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,iBAAiB,CAAC;IAEvB,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAC;IAEjB,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;IAElB,2EAA2E;IAC3E,MAAM,EAAE,OAAO,CAAC;IAEhB;uEACmE;IACnE,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC;AAE1F,MAAM,MAAM,0BAA0B,GAAG;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAC7C;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC9C,SAAS,CAAC;AAGd,MAAM,MAAM,gBAAgB,GAAG;IAC7B,6DAA6D;IAC7D,IAAI,EAAE,OAAO,CAAC;IACd,gFAAgF;IAChF,QAAQ,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,eAAe,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAGF,MAAM,MAAM,4BAA4B,GAAG;IACzC,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IAEtB,wBAAwB;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IAEjB,2BAA2B;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAElB,sCAAsC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,+DAA+D;IAC/D,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,4BAA4B,GAAG;IACxE,qEAAqE;IACrE,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,aAAa,GAAG;IAC1B,6EAA6E;IAC7E,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,oCAAoC;IACpC,uBAAuB,CAAC,EAAE,yBAAyB,CAAC;CACrD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlgebraDexTagEnum = void 0;
|
|
4
|
+
// ---- DEX tag (we only wire Blackhole for now) ----
|
|
5
|
+
var AlgebraDexTagEnum;
|
|
6
|
+
(function (AlgebraDexTagEnum) {
|
|
7
|
+
AlgebraDexTagEnum["BLACKHOLE"] = "blackhole";
|
|
8
|
+
})(AlgebraDexTagEnum || (exports.AlgebraDexTagEnum = AlgebraDexTagEnum = {}));
|
|
9
|
+
//# sourceMappingURL=algebra.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algebra.types.js","sourceRoot":"","sources":["../../../src/protocols/algebra/algebra.types.ts"],"names":[],"mappings":";;;AAGA,qDAAqD;AACrD,IAAY,iBAEX;AAFD,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;AACzB,CAAC,EAFW,iBAAiB,iCAAjB,iBAAiB,QAE5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/protocols/algebra/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AlgebraService = void 0;
|
|
18
|
+
var algebra_service_1 = require("./algebra.service");
|
|
19
|
+
Object.defineProperty(exports, "AlgebraService", { enumerable: true, get: function () { return algebra_service_1.AlgebraService; } });
|
|
20
|
+
__exportStar(require("./algebra.types"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/protocols/algebra/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,kDAAgC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { OKXConfig, OKXCredentials, OkxEvmQuoteToExecutionPayloadParams, OkxPriceRequestBody, OkxPriceResponse, OkxQuoteRequestBody,
|
|
2
|
+
import { OKXConfig, OKXCredentials, OkxEvmQuoteToExecutionPayloadParams, OkxPriceRequestBody, OkxPriceResponse, OkxQuoteRequestBody, OkxSignatureParams, OkxSignatureResponse, OkxSolanaQuoteToExecutionPayloadParams } from './okx.types';
|
|
3
3
|
import { EvmQuoteExecutionPayload, SvmQuoteExecutionPayload } from '../../types/quote-execution-payload';
|
|
4
4
|
import { PriceResponse, RawProtocolPriceResponse } from '../../types/price-response';
|
|
5
5
|
import { IIntentProtocol } from '../../interfaces/intent-protocol';
|
|
@@ -107,9 +107,7 @@ export declare class OkxService implements IIntentProtocol {
|
|
|
107
107
|
* @throws {SdkError} If the API returns an invalid response.
|
|
108
108
|
* @throws {SdkError} If there's an error fetching the quote.
|
|
109
109
|
*/
|
|
110
|
-
fetchQuote(params: IntentQuoteParams): Promise<QuoteResponse
|
|
111
|
-
protocolResponse: OkxQuoteResponse | OkxSolanaQuoteResponse;
|
|
112
|
-
}>;
|
|
110
|
+
fetchQuote(params: IntentQuoteParams): Promise<QuoteResponse>;
|
|
113
111
|
protected okxEvmQuoteResponseToExecutionPayload(params: OkxEvmQuoteToExecutionPayloadParams): EvmQuoteExecutionPayload;
|
|
114
112
|
protected okxSolanaQuoteResponseToExecutionPayload(params: OkxSolanaQuoteToExecutionPayloadParams): Promise<SvmQuoteExecutionPayload>;
|
|
115
113
|
private _estimateTransactionSize;
|
|
@@ -129,10 +127,13 @@ export declare class OkxService implements IIntentProtocol {
|
|
|
129
127
|
* @returns {OkxQuoteRequestBody} The transformed parameters ready for the OKX API.
|
|
130
128
|
*/
|
|
131
129
|
protected quoteParamsToRequestBody(params: IntentQuoteParams): OkxQuoteRequestBody;
|
|
132
|
-
protected determineSolanaSlippageParameters(slippage: number
|
|
133
|
-
autoSlippage
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
protected determineSolanaSlippageParameters(slippage: number, opts?: {
|
|
131
|
+
autoSlippage?: boolean;
|
|
132
|
+
maxAutoSlippagePercent?: number | string;
|
|
133
|
+
}): {
|
|
134
|
+
slippagePercent: string;
|
|
135
|
+
autoSlippage?: boolean;
|
|
136
|
+
maxAutoSlippagePercent?: string;
|
|
136
137
|
};
|
|
137
138
|
/**
|
|
138
139
|
* Calculates the HMAC-SHA256 signature required for authenticating requests to the OKX API.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"okx.service.d.ts","sourceRoot":"","sources":["../../../src/protocols/okx/okx.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,UAAU,EACX,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EACL,SAAS,EACT,cAAc,EACd,mCAAmC,EACnC,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"okx.service.d.ts","sourceRoot":"","sources":["../../../src/protocols/okx/okx.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -47,7 +47,6 @@ const logger_1 = require("../../utils/logger");
|
|
|
47
47
|
const constants_1 = require("../../utils/constants");
|
|
48
48
|
const is_native_1 = require("../../utils/is-native");
|
|
49
49
|
const throw_error_1 = require("../../utils/throw-error");
|
|
50
|
-
const create_error_message_1 = require("../../utils/create-error-message");
|
|
51
50
|
const check_vm_1 = require("../../utils/check-vm");
|
|
52
51
|
let logger;
|
|
53
52
|
/**
|
|
@@ -103,15 +102,15 @@ class OkxService {
|
|
|
103
102
|
/**
|
|
104
103
|
* The endpoint for price quote requests.
|
|
105
104
|
*/
|
|
106
|
-
this.priceEndpoint = '/api/
|
|
105
|
+
this.priceEndpoint = '/api/v6/dex/aggregator/quote';
|
|
107
106
|
/**
|
|
108
107
|
* The endpoint for transaction quote requests.
|
|
109
108
|
*/
|
|
110
|
-
this.quoteEndpoint = '/api/
|
|
109
|
+
this.quoteEndpoint = '/api/v6/dex/aggregator/swap';
|
|
111
110
|
/**
|
|
112
111
|
* The endpoint for Solana quote requests.
|
|
113
112
|
*/
|
|
114
|
-
this.solanaQuoteEndpoint = '/api/
|
|
113
|
+
this.solanaQuoteEndpoint = '/api/v6/dex/aggregator/swap-instruction';
|
|
115
114
|
/**
|
|
116
115
|
* The chain ID used by OKX for solana
|
|
117
116
|
*/
|
|
@@ -169,8 +168,11 @@ class OkxService {
|
|
|
169
168
|
*/
|
|
170
169
|
async fetchPrice(params) {
|
|
171
170
|
this.validatePriceParams(params);
|
|
172
|
-
const requestBody = this.priceParamsToRequestBody(
|
|
173
|
-
|
|
171
|
+
const requestBody = this.priceParamsToRequestBody({
|
|
172
|
+
...params,
|
|
173
|
+
swapMode: 'exactIn',
|
|
174
|
+
});
|
|
175
|
+
logger.debug('Generated OKX v6 price request body', requestBody);
|
|
174
176
|
try {
|
|
175
177
|
const priceUrlParams = new URLSearchParams(requestBody);
|
|
176
178
|
const { signature, timestamp } = this.calculateSignature({
|
|
@@ -178,34 +180,42 @@ class OkxService {
|
|
|
178
180
|
requestPath: `${this.priceEndpoint}?${priceUrlParams}`,
|
|
179
181
|
});
|
|
180
182
|
const url = `${this.baseUrl}${this.priceEndpoint}?${priceUrlParams.toString()}`;
|
|
181
|
-
logger.debug(`Making request to OKX API: ${url}`);
|
|
182
|
-
const headers = {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
logger.debug(`Making request to OKX v6 quote API: ${url}`);
|
|
184
|
+
const headers = {
|
|
185
|
+
['OK-ACCESS-KEY']: this.okxCredentials.apiKey || '',
|
|
186
|
+
['OK-ACCESS-SIGN']: signature,
|
|
187
|
+
['OK-ACCESS-TIMESTAMP']: timestamp,
|
|
188
|
+
['OK-ACCESS-PASSPHRASE']: this.okxCredentials.passphrase || '',
|
|
189
|
+
['OK-ACCESS-PROJECT']: this.okxCredentials.projectId || '',
|
|
190
|
+
};
|
|
188
191
|
const response = await axios_1.default.get(url, { headers });
|
|
189
192
|
const okxPriceResponse = response.data;
|
|
190
193
|
if (!okxPriceResponse ||
|
|
191
194
|
!okxPriceResponse.data ||
|
|
192
195
|
okxPriceResponse.data.length === 0 ||
|
|
193
|
-
!okxPriceResponse?.data?.[0]?.toTokenAmount
|
|
194
|
-
|
|
196
|
+
(!okxPriceResponse?.data?.[0]?.toTokenAmount &&
|
|
197
|
+
!okxPriceResponse?.data?.[0]?.fromTokenAmount)) {
|
|
198
|
+
logger.error('Invalid response received from OKX v6 API', undefined, {
|
|
195
199
|
okxPriceResponse,
|
|
196
200
|
});
|
|
197
|
-
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, 'Invalid response received from OKX API');
|
|
201
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, 'Invalid response received from OKX v6 API');
|
|
198
202
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
203
|
+
const item = okxPriceResponse.data[0];
|
|
204
|
+
// For exactIn: amountIn is params.amountIn, amountOut is response.toTokenAmount
|
|
205
|
+
// For exactOut: amountOut is response.toTokenAmount (≈ requested), amountIn is response.fromTokenAmount
|
|
206
|
+
const amountOut = typeof item.toTokenAmount === 'string' ? item.toTokenAmount : '';
|
|
207
|
+
const computedAmountIn = params.amountIn;
|
|
208
|
+
logger.debug('Successfully received price info from OKX v6', {
|
|
209
|
+
swapMode: 'exactIn',
|
|
210
|
+
amountIn: computedAmountIn,
|
|
211
|
+
amountOut,
|
|
212
|
+
gasEstimate: item.estimateGasFee,
|
|
202
213
|
});
|
|
203
|
-
const amountOut = okxPriceResponse.data[0].toTokenAmount;
|
|
204
214
|
if (!amountOut) {
|
|
205
|
-
logger.error('No output amount received from OKX', undefined, {
|
|
215
|
+
logger.error('No output amount received from OKX v6', undefined, {
|
|
206
216
|
okxPriceResponse,
|
|
207
217
|
});
|
|
208
|
-
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, 'No output amount received from OKX');
|
|
218
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, 'No output amount received from OKX v6');
|
|
209
219
|
}
|
|
210
220
|
return {
|
|
211
221
|
protocol: this.protocol,
|
|
@@ -213,16 +223,16 @@ class OkxService {
|
|
|
213
223
|
networkOut: params.networkOut,
|
|
214
224
|
tokenIn: params.tokenIn,
|
|
215
225
|
tokenOut: params.tokenOut,
|
|
216
|
-
amountIn:
|
|
217
|
-
amountOut
|
|
218
|
-
estimatedGas:
|
|
226
|
+
amountIn: computedAmountIn,
|
|
227
|
+
amountOut,
|
|
228
|
+
estimatedGas: item.estimateGasFee,
|
|
219
229
|
protocolResponse: okxPriceResponse,
|
|
220
230
|
slippage: params.slippage,
|
|
221
231
|
};
|
|
222
232
|
}
|
|
223
|
-
catch (
|
|
224
|
-
const
|
|
225
|
-
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND,
|
|
233
|
+
catch (err) {
|
|
234
|
+
const errorMessage = err?.message ?? String(err);
|
|
235
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, errorMessage);
|
|
226
236
|
}
|
|
227
237
|
}
|
|
228
238
|
/**
|
|
@@ -244,12 +254,15 @@ class OkxService {
|
|
|
244
254
|
async fetchQuote(params) {
|
|
245
255
|
logger.info(`Fetching swap quote for address: ${params.from}`);
|
|
246
256
|
this.validatePriceParams(params);
|
|
247
|
-
|
|
248
|
-
const requestBody = this.quoteParamsToRequestBody(
|
|
249
|
-
|
|
257
|
+
const { from, receiver, tokenIn, tokenOut, amountIn, networkIn, networkOut } = params;
|
|
258
|
+
const requestBody = this.quoteParamsToRequestBody({
|
|
259
|
+
...params,
|
|
260
|
+
swapMode: 'exactIn',
|
|
261
|
+
});
|
|
262
|
+
logger.debug('Generated OKX v6 quote request body', requestBody);
|
|
250
263
|
const quoteEndpoint = (0, check_vm_1.isSolanaNetwork)(networkIn)
|
|
251
|
-
? this.solanaQuoteEndpoint
|
|
252
|
-
: this.quoteEndpoint;
|
|
264
|
+
? this.solanaQuoteEndpoint // /api/v6/dex/aggregator/swap-instruction
|
|
265
|
+
: this.quoteEndpoint; // /api/v6/dex/aggregator/swap
|
|
253
266
|
try {
|
|
254
267
|
const quoteUrlParams = new URLSearchParams(requestBody);
|
|
255
268
|
const { signature, timestamp } = this.calculateSignature({
|
|
@@ -257,21 +270,25 @@ class OkxService {
|
|
|
257
270
|
requestPath: `${quoteEndpoint}?${quoteUrlParams}`,
|
|
258
271
|
});
|
|
259
272
|
const url = `${this.baseUrl}${quoteEndpoint}?${quoteUrlParams.toString()}`;
|
|
260
|
-
logger.debug(`Making request to OKX
|
|
261
|
-
const headers = {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
273
|
+
logger.debug(`Making request to OKX v6 swap API: ${url}`);
|
|
274
|
+
const headers = {
|
|
275
|
+
['OK-ACCESS-KEY']: this.okxCredentials.apiKey || '',
|
|
276
|
+
['OK-ACCESS-SIGN']: signature,
|
|
277
|
+
['OK-ACCESS-TIMESTAMP']: timestamp,
|
|
278
|
+
['OK-ACCESS-PASSPHRASE']: this.okxCredentials.passphrase || '',
|
|
279
|
+
['OK-ACCESS-PROJECT']: this.okxCredentials.projectId || '',
|
|
280
|
+
};
|
|
267
281
|
const response = await axios_1.default.get(url, { headers });
|
|
268
|
-
const isEvm = (0, check_vm_1.isEVMNetwork)(networkIn);
|
|
269
282
|
const okxQuoteResponse = response.data;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
283
|
+
const isEvm = (0, check_vm_1.isEVMNetwork)(networkIn);
|
|
284
|
+
// Basic shape validation
|
|
285
|
+
const isValidEvm = Array.isArray(okxQuoteResponse.data) &&
|
|
286
|
+
okxQuoteResponse.data.length > 0;
|
|
287
|
+
const isValidSol = !!okxQuoteResponse?.data?.instructionLists;
|
|
288
|
+
if (!okxQuoteResponse || (isEvm && !isValidEvm) || (!isEvm && !isValidSol)) {
|
|
289
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, okxQuoteResponse?.msg ?? `No quote returned from OKX v6`);
|
|
274
290
|
}
|
|
291
|
+
// Build execution payload
|
|
275
292
|
const executionPayload = isEvm
|
|
276
293
|
? this.okxEvmQuoteResponseToExecutionPayload({
|
|
277
294
|
tokenIn,
|
|
@@ -283,79 +300,30 @@ class OkxService {
|
|
|
283
300
|
from,
|
|
284
301
|
response: okxQuoteResponse,
|
|
285
302
|
});
|
|
286
|
-
logger.debug('Successfully received quote info from OKX');
|
|
287
|
-
|
|
303
|
+
logger.debug('Successfully received quote info from OKX v6');
|
|
304
|
+
// --- AmountOut resolution ---
|
|
305
|
+
let amountOut;
|
|
288
306
|
if (isEvm) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
: undefined;
|
|
297
|
-
}
|
|
298
|
-
else if (typeof okxQuoteResponse.data === 'object' &&
|
|
299
|
-
okxQuoteResponse.data !== null &&
|
|
300
|
-
'routerResult' in okxQuoteResponse.data &&
|
|
301
|
-
okxQuoteResponse.data.routerResult &&
|
|
302
|
-
typeof okxQuoteResponse.data
|
|
303
|
-
.routerResult?.toTokenAmount === 'string') {
|
|
304
|
-
amountOut = okxQuoteResponse.data
|
|
305
|
-
.routerResult.toTokenAmount;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, 'No valid routerResult.toTokenAmount found in OKX response');
|
|
307
|
+
const d = okxQuoteResponse.data;
|
|
308
|
+
amountOut =
|
|
309
|
+
d?.[0]?.routerResult?.toTokenAmount && typeof d[0].routerResult.toTokenAmount === 'string'
|
|
310
|
+
? d[0].routerResult.toTokenAmount
|
|
311
|
+
: undefined;
|
|
312
|
+
if (!amountOut) {
|
|
313
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, 'No valid routerResult.toTokenAmount found in OKX v6 response');
|
|
309
314
|
}
|
|
310
315
|
}
|
|
311
316
|
else {
|
|
312
|
-
//
|
|
313
|
-
const
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const url = `${this.baseUrl}${quoteEndpoint}?${quoteUrlParams.toString()}`;
|
|
323
|
-
logger.debug(`Making request to OKX quote API: ${url}`);
|
|
324
|
-
const response = await axios_1.default.get(url, {
|
|
325
|
-
headers: {
|
|
326
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
327
|
-
'OK-ACCESS-KEY': this.okxCredentials.apiKey,
|
|
328
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
329
|
-
'OK-ACCESS-SIGN': signature,
|
|
330
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
331
|
-
'OK-ACCESS-TIMESTAMP': timestamp,
|
|
332
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
333
|
-
'OK-ACCESS-PASSPHRASE': this.okxCredentials.passphrase,
|
|
334
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
335
|
-
'OK-ACCESS-PROJECT': this.okxCredentials.projectId,
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
if (Array.isArray(response.data.data)) {
|
|
339
|
-
amountOut =
|
|
340
|
-
response.data.data &&
|
|
341
|
-
Array.isArray(response.data.data) &&
|
|
342
|
-
response.data.data[0] &&
|
|
343
|
-
response.data.data[0].routerResult &&
|
|
344
|
-
typeof response.data.data[0].routerResult.toTokenAmount === 'string'
|
|
345
|
-
? response.data.data[0].routerResult.toTokenAmount
|
|
346
|
-
: undefined;
|
|
347
|
-
}
|
|
348
|
-
else if (typeof response.data.data === 'object' &&
|
|
349
|
-
response.data.data !== null &&
|
|
350
|
-
'routerResult' in response.data.data &&
|
|
351
|
-
response.data.data.routerResult &&
|
|
352
|
-
typeof response.data.data.routerResult
|
|
353
|
-
?.toTokenAmount === 'string') {
|
|
354
|
-
amountOut = response.data.data
|
|
355
|
-
.routerResult.toTokenAmount;
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, 'No valid routerResult.toTokenAmount found in OKX response');
|
|
317
|
+
// v6 Solana /swap-instruction now returns routerResult & toTokenAmount directly in the same payload
|
|
318
|
+
const sol = okxQuoteResponse;
|
|
319
|
+
const direct = sol?.data?.toTokenAmount;
|
|
320
|
+
const viaRouter = sol?.data?.routerResult?.toTokenAmount;
|
|
321
|
+
amountOut =
|
|
322
|
+
(typeof direct === 'string' && direct) ||
|
|
323
|
+
(typeof viaRouter === 'string' && viaRouter) ||
|
|
324
|
+
undefined;
|
|
325
|
+
if (!amountOut) {
|
|
326
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, 'No valid toTokenAmount found in OKX v6 Solana swap-instruction response');
|
|
359
327
|
}
|
|
360
328
|
}
|
|
361
329
|
const executionPayloadKey = (0, check_vm_1.isEVMNetwork)(params.networkIn)
|
|
@@ -366,7 +334,7 @@ class OkxService {
|
|
|
366
334
|
tokenIn,
|
|
367
335
|
tokenOut,
|
|
368
336
|
amountIn,
|
|
369
|
-
amountOut
|
|
337
|
+
amountOut,
|
|
370
338
|
from,
|
|
371
339
|
receiver: receiver || from,
|
|
372
340
|
[executionPayloadKey]: executionPayload,
|
|
@@ -377,8 +345,7 @@ class OkxService {
|
|
|
377
345
|
};
|
|
378
346
|
}
|
|
379
347
|
catch (error) {
|
|
380
|
-
|
|
381
|
-
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, formattedError);
|
|
348
|
+
throw error;
|
|
382
349
|
}
|
|
383
350
|
}
|
|
384
351
|
okxEvmQuoteResponseToExecutionPayload(params) {
|
|
@@ -577,14 +544,36 @@ class OkxService {
|
|
|
577
544
|
*/
|
|
578
545
|
priceParamsToRequestBody(params) {
|
|
579
546
|
const { tokenIn, tokenOut, amountIn, networkIn } = params;
|
|
580
|
-
|
|
547
|
+
const isEvm = (0, check_vm_1.isEVMNetwork)(networkIn);
|
|
548
|
+
const networkNativeAddress = isEvm ? constants_1.NATIVE_ADDRESS : constants_1.NATIVE_SOL;
|
|
549
|
+
const fromTokenAddress = (0, is_native_1.isNative)(tokenIn) ? networkNativeAddress : (0, address_1.formatAddress)(tokenIn);
|
|
550
|
+
const toTokenAddress = (0, is_native_1.isNative)(tokenOut) ? networkNativeAddress : (0, address_1.formatAddress)(tokenOut);
|
|
551
|
+
// Allow caller to optionally pass v6-only fields without breaking existing signatures.
|
|
552
|
+
const okxOpts = params || {};
|
|
553
|
+
const swapMode = 'exactIn';
|
|
554
|
+
// For exactOut, v6 expects `amount` to be the desired output amount.
|
|
555
|
+
const effectiveAmount = amountIn.toString();
|
|
581
556
|
const requestBody = {
|
|
582
|
-
amount:
|
|
583
|
-
|
|
584
|
-
fromTokenAddress
|
|
585
|
-
toTokenAddress
|
|
557
|
+
amount: effectiveAmount,
|
|
558
|
+
chainIndex: networkIn.toString(),
|
|
559
|
+
fromTokenAddress,
|
|
560
|
+
toTokenAddress,
|
|
561
|
+
swapMode, // v6
|
|
562
|
+
// Optional passthroughs (only include if defined)
|
|
563
|
+
...(okxOpts.okxQuoteOptions?.dexIds ? { dexIds: okxOpts.okxQuoteOptions.dexIds } : {}),
|
|
564
|
+
...(typeof okxOpts.okxQuoteOptions?.directRoute === 'boolean'
|
|
565
|
+
? { directRoute: okxOpts.okxQuoteOptions.directRoute }
|
|
566
|
+
: {}),
|
|
567
|
+
...(okxOpts.okxQuoteOptions?.priceImpactProtectionPercent !== undefined
|
|
568
|
+
? {
|
|
569
|
+
priceImpactProtectionPercent: String(okxOpts.okxQuoteOptions.priceImpactProtectionPercent),
|
|
570
|
+
}
|
|
571
|
+
: {}),
|
|
572
|
+
...(okxOpts.okxQuoteOptions?.feePercent !== undefined
|
|
573
|
+
? { feePercent: String(okxOpts.okxQuoteOptions.feePercent) }
|
|
574
|
+
: {}),
|
|
586
575
|
};
|
|
587
|
-
logger.debug('Generated OKX request body', requestBody);
|
|
576
|
+
logger.debug('Generated OKX v6 request body', requestBody);
|
|
588
577
|
return requestBody;
|
|
589
578
|
}
|
|
590
579
|
/**
|
|
@@ -602,34 +591,35 @@ class OkxService {
|
|
|
602
591
|
const networkNativeAddress = isEvm ? constants_1.NATIVE_ADDRESS : constants_1.NATIVE_SOL;
|
|
603
592
|
const tokenInToUse = tokenInIsNative ? networkNativeAddress : (0, address_1.formatAddress)(tokenIn);
|
|
604
593
|
const tokenOutToUse = tokenOutIsNative ? networkNativeAddress : (0, address_1.formatAddress)(tokenOut);
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
594
|
+
const effectiveSwapMode = 'exactIn';
|
|
595
|
+
// v6 requires slippagePercent (percent units, e.g. "0.5" for 0.5%)
|
|
596
|
+
const rawSlip = params.slippage ?? 0.5;
|
|
597
|
+
const slippagePercent = typeof rawSlip === 'number' ? String(rawSlip) : `${rawSlip}`;
|
|
598
|
+
// For exactOut, API expects amount to represent the desired OUTPUT amount.
|
|
599
|
+
const effectiveAmount = amountIn.toString();
|
|
600
|
+
// Base body
|
|
601
|
+
const body = {
|
|
602
|
+
amount: effectiveAmount,
|
|
603
|
+
chainIndex: isEvm ? networkIn.toString() : this.solanaChainId,
|
|
609
604
|
fromTokenAddress: tokenInToUse,
|
|
610
605
|
toTokenAddress: tokenOutToUse,
|
|
611
606
|
userWalletAddress: (0, address_1.formatAddress)(from),
|
|
612
607
|
swapReceiverAddress: (0, address_1.formatAddress)(receiver || from),
|
|
613
|
-
|
|
608
|
+
swapMode: effectiveSwapMode,
|
|
609
|
+
slippagePercent,
|
|
614
610
|
};
|
|
615
|
-
return
|
|
611
|
+
return body;
|
|
616
612
|
}
|
|
617
|
-
determineSolanaSlippageParameters(slippage) {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
slippage: 0.15,
|
|
623
|
-
};
|
|
613
|
+
determineSolanaSlippageParameters(slippage, opts) {
|
|
614
|
+
const slippagePercent = String(slippage ?? 0.5);
|
|
615
|
+
const out = { slippagePercent };
|
|
616
|
+
if (typeof opts?.autoSlippage === 'boolean') {
|
|
617
|
+
out.autoSlippage = opts.autoSlippage;
|
|
624
618
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
return {
|
|
628
|
-
autoSlippage: true,
|
|
629
|
-
maxAutoSlippage: slippagePercentage,
|
|
630
|
-
slippage: slippagePercentage,
|
|
631
|
-
};
|
|
619
|
+
if (opts?.maxAutoSlippagePercent !== undefined) {
|
|
620
|
+
out.maxAutoSlippagePercent = String(opts.maxAutoSlippagePercent);
|
|
632
621
|
}
|
|
622
|
+
return out;
|
|
633
623
|
}
|
|
634
624
|
/**
|
|
635
625
|
* Calculates the HMAC-SHA256 signature required for authenticating requests to the OKX API.
|