genius-intents 0.1.4
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 +45 -0
- package/LICENSE +21 -0
- package/README.md +376 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +62 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/intents-protocols.d.ts +69 -0
- package/dist/src/intents-protocols.d.ts.map +1 -0
- package/dist/src/intents-protocols.js +371 -0
- package/dist/src/intents-protocols.js.map +1 -0
- package/dist/src/interfaces/intent-protocol.d.ts +21 -0
- package/dist/src/interfaces/intent-protocol.d.ts.map +1 -0
- package/dist/src/interfaces/intent-protocol.js +3 -0
- package/dist/src/interfaces/intent-protocol.js.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.service.d.ts +28 -0
- package/dist/src/protocols/aftermath/aftermath.service.d.ts.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.service.js +162 -0
- package/dist/src/protocols/aftermath/aftermath.service.js.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.types.d.ts +100 -0
- package/dist/src/protocols/aftermath/aftermath.types.d.ts.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.types.js +3 -0
- package/dist/src/protocols/aftermath/aftermath.types.js.map +1 -0
- package/dist/src/protocols/aftermath/index.d.ts +3 -0
- package/dist/src/protocols/aftermath/index.d.ts.map +1 -0
- package/dist/src/protocols/aftermath/index.js +7 -0
- package/dist/src/protocols/aftermath/index.js.map +1 -0
- package/dist/src/protocols/debridge/debridge.service.d.ts +157 -0
- package/dist/src/protocols/debridge/debridge.service.d.ts.map +1 -0
- package/dist/src/protocols/debridge/debridge.service.js +462 -0
- package/dist/src/protocols/debridge/debridge.service.js.map +1 -0
- package/dist/src/protocols/debridge/debridge.types.d.ts +82 -0
- package/dist/src/protocols/debridge/debridge.types.d.ts.map +1 -0
- package/dist/src/protocols/debridge/debridge.types.js +3 -0
- package/dist/src/protocols/debridge/debridge.types.js.map +1 -0
- package/dist/src/protocols/debridge/index.d.ts +3 -0
- package/dist/src/protocols/debridge/index.d.ts.map +1 -0
- package/dist/src/protocols/debridge/index.js +7 -0
- package/dist/src/protocols/debridge/index.js.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.d.ts +36 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.d.ts.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.js +312 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.js.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.d.ts +100 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.d.ts.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.js +3 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.js.map +1 -0
- package/dist/src/protocols/genius-bridge/index.d.ts +3 -0
- package/dist/src/protocols/genius-bridge/index.d.ts.map +1 -0
- package/dist/src/protocols/genius-bridge/index.js +7 -0
- package/dist/src/protocols/genius-bridge/index.js.map +1 -0
- package/dist/src/protocols/jupiter/index.d.ts +3 -0
- package/dist/src/protocols/jupiter/index.d.ts.map +1 -0
- package/dist/src/protocols/jupiter/index.js +7 -0
- package/dist/src/protocols/jupiter/index.js.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.service.d.ts +37 -0
- package/dist/src/protocols/jupiter/jupiter.service.d.ts.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.service.js +188 -0
- package/dist/src/protocols/jupiter/jupiter.service.js.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.types.d.ts +272 -0
- package/dist/src/protocols/jupiter/jupiter.types.d.ts.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.types.js +3 -0
- package/dist/src/protocols/jupiter/jupiter.types.js.map +1 -0
- package/dist/src/protocols/kyberswap/index.d.ts +3 -0
- package/dist/src/protocols/kyberswap/index.d.ts.map +1 -0
- package/dist/src/protocols/kyberswap/index.js +7 -0
- package/dist/src/protocols/kyberswap/index.js.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.d.ts +34 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.d.ts.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.js +218 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.js.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.d.ts +114 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.d.ts.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.js +3 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.js.map +1 -0
- package/dist/src/protocols/odos/index.d.ts +3 -0
- package/dist/src/protocols/odos/index.d.ts.map +1 -0
- package/dist/src/protocols/odos/index.js +7 -0
- package/dist/src/protocols/odos/index.js.map +1 -0
- package/dist/src/protocols/odos/odos.service.d.ts +39 -0
- package/dist/src/protocols/odos/odos.service.d.ts.map +1 -0
- package/dist/src/protocols/odos/odos.service.js +207 -0
- package/dist/src/protocols/odos/odos.service.js.map +1 -0
- package/dist/src/protocols/odos/odos.types.d.ts +114 -0
- package/dist/src/protocols/odos/odos.types.d.ts.map +1 -0
- package/dist/src/protocols/odos/odos.types.js +3 -0
- package/dist/src/protocols/odos/odos.types.js.map +1 -0
- package/dist/src/protocols/okx/index.d.ts +3 -0
- package/dist/src/protocols/okx/index.d.ts.map +1 -0
- package/dist/src/protocols/okx/index.js +7 -0
- package/dist/src/protocols/okx/index.js.map +1 -0
- package/dist/src/protocols/okx/okx.service.d.ts +36 -0
- package/dist/src/protocols/okx/okx.service.d.ts.map +1 -0
- package/dist/src/protocols/okx/okx.service.js +281 -0
- package/dist/src/protocols/okx/okx.service.js.map +1 -0
- package/dist/src/protocols/okx/okx.types.d.ts +119 -0
- package/dist/src/protocols/okx/okx.types.d.ts.map +1 -0
- package/dist/src/protocols/okx/okx.types.js +4 -0
- package/dist/src/protocols/okx/okx.types.js.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.d.ts +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.d.ts.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.js +2 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.js.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.d.ts +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.d.ts.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.js +2 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.js.map +1 -0
- package/dist/src/protocols/openocean/index.d.ts +3 -0
- package/dist/src/protocols/openocean/index.d.ts.map +1 -0
- package/dist/src/protocols/openocean/index.js +7 -0
- package/dist/src/protocols/openocean/index.js.map +1 -0
- package/dist/src/protocols/openocean/openocean.service.d.ts +29 -0
- package/dist/src/protocols/openocean/openocean.service.d.ts.map +1 -0
- package/dist/src/protocols/openocean/openocean.service.js +181 -0
- package/dist/src/protocols/openocean/openocean.service.js.map +1 -0
- package/dist/src/protocols/openocean/openocean.types.d.ts +68 -0
- package/dist/src/protocols/openocean/openocean.types.d.ts.map +1 -0
- package/dist/src/protocols/openocean/openocean.types.js +3 -0
- package/dist/src/protocols/openocean/openocean.types.js.map +1 -0
- package/dist/src/protocols/pumpfun/index.d.ts +3 -0
- package/dist/src/protocols/pumpfun/index.d.ts.map +1 -0
- package/dist/src/protocols/pumpfun/index.js +7 -0
- package/dist/src/protocols/pumpfun/index.js.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.d.ts +45 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.d.ts.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.js +217 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.js.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.d.ts +14 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.d.ts.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.js +3 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.js.map +1 -0
- package/dist/src/protocols/raydium/index.d.ts +3 -0
- package/dist/src/protocols/raydium/index.d.ts.map +1 -0
- package/dist/src/protocols/raydium/index.js +7 -0
- package/dist/src/protocols/raydium/index.js.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.service.d.ts +35 -0
- package/dist/src/protocols/raydium/raydium-v2.service.d.ts.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.service.js +301 -0
- package/dist/src/protocols/raydium/raydium-v2.service.js.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.types.d.ts +96 -0
- package/dist/src/protocols/raydium/raydium-v2.types.d.ts.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.types.js +3 -0
- package/dist/src/protocols/raydium/raydium-v2.types.js.map +1 -0
- package/dist/src/protocols/zeroX/index.d.ts +3 -0
- package/dist/src/protocols/zeroX/index.d.ts.map +1 -0
- package/dist/src/protocols/zeroX/index.js +7 -0
- package/dist/src/protocols/zeroX/index.js.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.service.d.ts +37 -0
- package/dist/src/protocols/zeroX/zeroX.service.d.ts.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.service.js +209 -0
- package/dist/src/protocols/zeroX/zeroX.service.js.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.types.d.ts +120 -0
- package/dist/src/protocols/zeroX/zeroX.types.d.ts.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.types.js +3 -0
- package/dist/src/protocols/zeroX/zeroX.types.js.map +1 -0
- package/dist/src/types/enums.d.ts +42 -0
- package/dist/src/types/enums.d.ts.map +1 -0
- package/dist/src/types/enums.js +49 -0
- package/dist/src/types/enums.js.map +1 -0
- package/dist/src/types/intents-protocols.d.ts +89 -0
- package/dist/src/types/intents-protocols.d.ts.map +1 -0
- package/dist/src/types/intents-protocols.js +3 -0
- package/dist/src/types/intents-protocols.js.map +1 -0
- package/dist/src/types/price-response.d.ts +26 -0
- package/dist/src/types/price-response.d.ts.map +1 -0
- package/dist/src/types/price-response.js +3 -0
- package/dist/src/types/price-response.js.map +1 -0
- package/dist/src/types/quote-response.d.ts +31 -0
- package/dist/src/types/quote-response.d.ts.map +1 -0
- package/dist/src/types/quote-response.js +3 -0
- package/dist/src/types/quote-response.js.map +1 -0
- package/dist/src/utils/address-validation.d.ts +9 -0
- package/dist/src/utils/address-validation.d.ts.map +1 -0
- package/dist/src/utils/address-validation.js +42 -0
- package/dist/src/utils/address-validation.js.map +1 -0
- package/dist/src/utils/address.d.ts +9 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +74 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/base64-to-base58.d.ts +2 -0
- package/dist/src/utils/base64-to-base58.d.ts.map +1 -0
- package/dist/src/utils/base64-to-base58.js +22 -0
- package/dist/src/utils/base64-to-base58.js.map +1 -0
- package/dist/src/utils/chain-id-name.d.ts +3 -0
- package/dist/src/utils/chain-id-name.d.ts.map +1 -0
- package/dist/src/utils/chain-id-name.js +23 -0
- package/dist/src/utils/chain-id-name.js.map +1 -0
- package/dist/src/utils/check-vm.d.ts +8 -0
- package/dist/src/utils/check-vm.d.ts.map +1 -0
- package/dist/src/utils/check-vm.js +39 -0
- package/dist/src/utils/check-vm.js.map +1 -0
- package/dist/src/utils/constants.d.ts +7 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +10 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/create-error-message.d.ts +5 -0
- package/dist/src/utils/create-error-message.d.ts.map +1 -0
- package/dist/src/utils/create-error-message.js +42 -0
- package/dist/src/utils/create-error-message.js.map +1 -0
- package/dist/src/utils/fetch-spl-metadata.d.ts +4 -0
- package/dist/src/utils/fetch-spl-metadata.d.ts.map +1 -0
- package/dist/src/utils/fetch-spl-metadata.js +108 -0
- package/dist/src/utils/fetch-spl-metadata.js.map +1 -0
- package/dist/src/utils/is-native.d.ts +2 -0
- package/dist/src/utils/is-native.d.ts.map +1 -0
- package/dist/src/utils/is-native.js +23 -0
- package/dist/src/utils/is-native.js.map +1 -0
- package/dist/src/utils/logger.d.ts +56 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +108 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/throw-error.d.ts +3 -0
- package/dist/src/utils/throw-error.d.ts.map +1 -0
- package/dist/src/utils/throw-error.js +8 -0
- package/dist/src/utils/throw-error.js.map +1 -0
- package/dist/tests/core/intent-protocol-suite.test.d.ts +2 -0
- package/dist/tests/core/intent-protocol-suite.test.d.ts.map +1 -0
- package/dist/tests/core/intent-protocol-suite.test.js +485 -0
- package/dist/tests/core/intent-protocol-suite.test.js.map +1 -0
- package/dist/tests/core/intents-protocols.test.d.ts +2 -0
- package/dist/tests/core/intents-protocols.test.d.ts.map +1 -0
- package/dist/tests/core/intents-protocols.test.js +307 -0
- package/dist/tests/core/intents-protocols.test.js.map +1 -0
- package/dist/tests/core/protocol-test-runner.d.ts +62 -0
- package/dist/tests/core/protocol-test-runner.d.ts.map +1 -0
- package/dist/tests/core/protocol-test-runner.js +260 -0
- package/dist/tests/core/protocol-test-runner.js.map +1 -0
- package/dist/tests/core/setup.test.d.ts +1 -0
- package/dist/tests/core/setup.test.d.ts.map +1 -0
- package/dist/tests/core/setup.test.js +13 -0
- package/dist/tests/core/setup.test.js.map +1 -0
- package/dist/tests/fixtures/test-data.d.ts +84 -0
- package/dist/tests/fixtures/test-data.d.ts.map +1 -0
- package/dist/tests/fixtures/test-data.js +142 -0
- package/dist/tests/fixtures/test-data.js.map +1 -0
- package/dist/tests/integration/cross-chain.test.d.ts +2 -0
- package/dist/tests/integration/cross-chain.test.d.ts.map +1 -0
- package/dist/tests/integration/cross-chain.test.js +44 -0
- package/dist/tests/integration/cross-chain.test.js.map +1 -0
- package/dist/tests/protocols/simple-protocol.test.d.ts +2 -0
- package/dist/tests/protocols/simple-protocol.test.d.ts.map +1 -0
- package/dist/tests/protocols/simple-protocol.test.js +77 -0
- package/dist/tests/protocols/simple-protocol.test.js.map +1 -0
- package/dist/tests/setup.d.ts +24 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +48 -0
- package/dist/tests/setup.js.map +1 -0
- package/dist/tests/utils/test-generator.d.ts +30 -0
- package/dist/tests/utils/test-generator.d.ts.map +1 -0
- package/dist/tests/utils/test-generator.js +153 -0
- package/dist/tests/utils/test-generator.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ChainIdEnum } from '../../types/enums';
|
|
2
|
+
export type OdosPriceResponse = {
|
|
3
|
+
inTokens: string[];
|
|
4
|
+
outTokens: string[];
|
|
5
|
+
inAmounts: string[];
|
|
6
|
+
outAmounts: string[];
|
|
7
|
+
gasEstimate: number;
|
|
8
|
+
dataGasEstimate: number;
|
|
9
|
+
gweiPerGas: number;
|
|
10
|
+
gasEstimateValue: number;
|
|
11
|
+
inValues: number[];
|
|
12
|
+
outValues: number[];
|
|
13
|
+
netOutValue: number;
|
|
14
|
+
priceImpact: number;
|
|
15
|
+
percentDiff: number;
|
|
16
|
+
partnerFeePercent: number;
|
|
17
|
+
pathId: string;
|
|
18
|
+
pathViz: any;
|
|
19
|
+
blockNumber: number;
|
|
20
|
+
};
|
|
21
|
+
export type OdosTransaction = {
|
|
22
|
+
gas: number;
|
|
23
|
+
gasPrice: number;
|
|
24
|
+
value: string;
|
|
25
|
+
to: string;
|
|
26
|
+
from: string;
|
|
27
|
+
data: string;
|
|
28
|
+
nonce: number;
|
|
29
|
+
chainId: number;
|
|
30
|
+
};
|
|
31
|
+
export type OdosQuoteResponse = {
|
|
32
|
+
deprecated: string;
|
|
33
|
+
blockNumber: number;
|
|
34
|
+
gasEstimate: number;
|
|
35
|
+
gasEstimateValue: number;
|
|
36
|
+
inputTokens: {
|
|
37
|
+
tokenAddress: string;
|
|
38
|
+
amount: string;
|
|
39
|
+
}[];
|
|
40
|
+
outputTokens: {
|
|
41
|
+
tokenAddress: string;
|
|
42
|
+
amount: string;
|
|
43
|
+
}[];
|
|
44
|
+
netOutValue: number;
|
|
45
|
+
outValues: string[];
|
|
46
|
+
transaction: OdosTransaction;
|
|
47
|
+
simulation: {
|
|
48
|
+
isSuccess: boolean;
|
|
49
|
+
amountsOut: number[];
|
|
50
|
+
gasEstimate: number;
|
|
51
|
+
simulationError: {
|
|
52
|
+
type: string;
|
|
53
|
+
errorMessage: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type OdosQuoteRequestBody = {
|
|
58
|
+
chainId: number | string;
|
|
59
|
+
inputTokens: OdosRequestTokenInput[];
|
|
60
|
+
outputTokens: OdosRequestTokenOutput[];
|
|
61
|
+
slippageLimitPercent: string;
|
|
62
|
+
referralCode: number;
|
|
63
|
+
disableRFQs: boolean;
|
|
64
|
+
compact: boolean;
|
|
65
|
+
userAddr: string;
|
|
66
|
+
simple: boolean;
|
|
67
|
+
};
|
|
68
|
+
export type OdosAssembleRequestBody = {
|
|
69
|
+
userAddr: string;
|
|
70
|
+
pathId: string;
|
|
71
|
+
simulate: boolean;
|
|
72
|
+
receiver?: string;
|
|
73
|
+
};
|
|
74
|
+
export type OdosMultiPriceParams = {
|
|
75
|
+
network: ChainIdEnum;
|
|
76
|
+
from: string;
|
|
77
|
+
tokensIn: string[];
|
|
78
|
+
tokenOut: string;
|
|
79
|
+
amountsIn: string[];
|
|
80
|
+
slippage: string;
|
|
81
|
+
};
|
|
82
|
+
export type OdosMultiQuoteParams = {
|
|
83
|
+
network: ChainIdEnum;
|
|
84
|
+
fromAddress: string;
|
|
85
|
+
pathId: string;
|
|
86
|
+
receiver?: string;
|
|
87
|
+
};
|
|
88
|
+
export type OdosMultiPriceRequestBody = {
|
|
89
|
+
chainId: number;
|
|
90
|
+
inputTokens: OdosRequestTokenInput[];
|
|
91
|
+
outputTokens: OdosRequestTokenOutput[];
|
|
92
|
+
userAddr: string;
|
|
93
|
+
slippageLimitPercent: string;
|
|
94
|
+
referralCode: number;
|
|
95
|
+
disableRFQs: boolean;
|
|
96
|
+
compact: boolean;
|
|
97
|
+
simple: true;
|
|
98
|
+
};
|
|
99
|
+
export type OdosMultiQuoteRequestBody = {
|
|
100
|
+
userAddr: string;
|
|
101
|
+
pathId: string;
|
|
102
|
+
simulate: boolean;
|
|
103
|
+
receiver?: string;
|
|
104
|
+
};
|
|
105
|
+
type OdosRequestTokenInput = {
|
|
106
|
+
tokenAddress: string;
|
|
107
|
+
amount: string;
|
|
108
|
+
};
|
|
109
|
+
type OdosRequestTokenOutput = {
|
|
110
|
+
tokenAddress: string;
|
|
111
|
+
proportion: number;
|
|
112
|
+
};
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=odos.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"odos.types.d.ts","sourceRoot":"","sources":["../../../../src/protocols/odos/odos.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,GAAG,CA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3B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"odos.types.js","sourceRoot":"","sources":["../../../../src/protocols/odos/odos.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { OkxService } from './okx.service';
|
|
2
|
+
export type { OKXCredentials, ApprovalContracts, OKXConfig, OkxQueryParams, OkxPriceRequestBody, OkxQuoteRequestBody, Token, TokenWithPrice, DexProtocol, SinglechainDexRouter, SinglechainSubRouter, QuoteCompareItem, SinglechainTransaction, OkxPriceData, OkxQuoteData, OkxPriceResponse, OkxQuoteResponse, OkxMultiPriceParams, OkxMultiQuoteParams, } from './okx.types';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/protocols/okx/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,EACL,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OkxService = void 0;
|
|
4
|
+
// OKX Protocol - All exports
|
|
5
|
+
var okx_service_1 = require("./okx.service");
|
|
6
|
+
Object.defineProperty(exports, "OkxService", { enumerable: true, get: function () { return okx_service_1.OkxService; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/protocols/okx/index.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IIntentProtocol } from '../../interfaces/intent-protocol';
|
|
2
|
+
import { ChainIdEnum, ProtocolEnum } from '../../types/enums';
|
|
3
|
+
import { IntentPriceParams } from '../../types/price-params';
|
|
4
|
+
import { PriceResponse, RawProtocolPriceResponse } from '../../types/price-response';
|
|
5
|
+
import { IntentQuoteParams } from '../../types/quote-params';
|
|
6
|
+
import { QuoteResponse } from '../../types/quote-response';
|
|
7
|
+
import { IntentsSDKConfig } from '../../types/sdk-config';
|
|
8
|
+
import { OKXConfig, OKXCredentials, OkxPriceRequestBody, OkxPriceResponse, OkxQueryParams, OkxQuoteResponse } from './okx.types';
|
|
9
|
+
export declare class OkxService implements IIntentProtocol {
|
|
10
|
+
protected readonly okxCredentials: OKXCredentials;
|
|
11
|
+
readonly protocol = ProtocolEnum.OKX;
|
|
12
|
+
readonly chains: ChainIdEnum[];
|
|
13
|
+
readonly singleChain = true;
|
|
14
|
+
readonly multiChain = false;
|
|
15
|
+
readonly baseUrl: string;
|
|
16
|
+
readonly priceEndpoint: string;
|
|
17
|
+
readonly quoteEndpoint: string;
|
|
18
|
+
constructor(config: IntentsSDKConfig & OKXConfig);
|
|
19
|
+
isCorrectConfig<T extends {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
}>(config: {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
}): config is T;
|
|
24
|
+
fetchPrice(params: IntentPriceParams): Promise<PriceResponse>;
|
|
25
|
+
fetchQuote(params: IntentQuoteParams): Promise<QuoteResponse & {
|
|
26
|
+
protocolResponse: OkxQuoteResponse;
|
|
27
|
+
}>;
|
|
28
|
+
protected priceParamsToRequestBody(params: IntentPriceParams): OkxPriceRequestBody;
|
|
29
|
+
protected calculateSignature(method: string, requestPath: string, queryParams?: OkxQueryParams, body?: string): {
|
|
30
|
+
signature: string;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
};
|
|
33
|
+
protected validatePriceParams(params: IntentPriceParams): void;
|
|
34
|
+
protected isOkxPriceResponse(response: RawProtocolPriceResponse): response is OkxPriceResponse;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=okx.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx.service.d.ts","sourceRoot":"","sources":["../../../../src/protocols/okx/okx.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,EACL,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EAEd,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAIrB,qBAAa,UAAW,YAAW,eAAe;IAChD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAK/C;IACF,SAAgB,QAAQ,oBAAoB;IAC5C,SAAgB,MAAM,gBAQpB;IACF,SAAgB,WAAW,QAAQ;IACnC,SAAgB,UAAU,SAAS;IACnC,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC,SAAgB,aAAa,EAAE,MAAM,CAAkC;IACvE,SAAgB,aAAa,EAAE,MAAM,CAAiC;gBAE1D,MAAM,EAAE,gBAAgB,GAAG,SAAS;IA0BhD,eAAe,CAAC,CAAC,SAAS;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,MAAM,EAAE;QAC3D,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,GAAG,MAAM,IAAI,CAAC;IASF,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAuE7D,UAAU,CACrB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,aAAa,GAAG;QAAE,gBAAgB,EAAE,gBAAgB,CAAA;KAAE,CAAC;IAuFlE,SAAS,CAAC,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,GAAG,mBAAmB;IAgBlF,SAAS,CAAC,kBAAkB,CAC1B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,cAAc,EAC5B,IAAI,CAAC,EAAE,MAAM,GACZ;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IA0B3C,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IA+B9D,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,QAAQ,IAAI,gBAAgB;CAG/F"}
|
|
@@ -0,0 +1,281 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.OkxService = void 0;
|
|
40
|
+
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const crypto = __importStar(require("crypto"));
|
|
42
|
+
const enums_1 = require("../../types/enums");
|
|
43
|
+
const address_1 = require("../../utils/address");
|
|
44
|
+
const logger_1 = require("../../utils/logger");
|
|
45
|
+
const constants_1 = require("../../utils/constants");
|
|
46
|
+
const is_native_1 = require("../../utils/is-native");
|
|
47
|
+
const throw_error_1 = require("../../utils/throw-error");
|
|
48
|
+
const create_error_message_1 = require("../../utils/create-error-message");
|
|
49
|
+
let logger;
|
|
50
|
+
class OkxService {
|
|
51
|
+
constructor(config) {
|
|
52
|
+
this.okxCredentials = {
|
|
53
|
+
apiKey: '',
|
|
54
|
+
secretKey: '',
|
|
55
|
+
passphrase: '',
|
|
56
|
+
projectId: '',
|
|
57
|
+
};
|
|
58
|
+
this.protocol = enums_1.ProtocolEnum.OKX;
|
|
59
|
+
this.chains = [
|
|
60
|
+
enums_1.ChainIdEnum.ETHEREUM,
|
|
61
|
+
enums_1.ChainIdEnum.ARBITRUM,
|
|
62
|
+
enums_1.ChainIdEnum.OPTIMISM,
|
|
63
|
+
enums_1.ChainIdEnum.POLYGON,
|
|
64
|
+
enums_1.ChainIdEnum.BSC,
|
|
65
|
+
enums_1.ChainIdEnum.AVALANCHE,
|
|
66
|
+
enums_1.ChainIdEnum.BASE,
|
|
67
|
+
];
|
|
68
|
+
this.singleChain = true;
|
|
69
|
+
this.multiChain = false;
|
|
70
|
+
this.priceEndpoint = '/api/v5/dex/aggregator/quote';
|
|
71
|
+
this.quoteEndpoint = '/api/v5/dex/aggregator/swap';
|
|
72
|
+
const { okxApiKey, okxSecretKey, okxPassphrase, okxProjectId } = config;
|
|
73
|
+
if (!okxSecretKey || !okxApiKey || !okxPassphrase || !okxProjectId) {
|
|
74
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.MISSING_INITIALIZATION, 'Missing OKX Secret Key || Apikey || Passphrase || ProjectId');
|
|
75
|
+
}
|
|
76
|
+
if (config?.debug) {
|
|
77
|
+
logger_1.LoggerFactory.configure(logger_1.LoggerFactory.createConsoleLogger({ level: logger_1.LogLevelEnum.DEBUG }));
|
|
78
|
+
}
|
|
79
|
+
// Use custom logger if provided
|
|
80
|
+
else if (config?.logger) {
|
|
81
|
+
logger_1.LoggerFactory.configure(config.logger);
|
|
82
|
+
}
|
|
83
|
+
logger = logger_1.LoggerFactory.getLogger();
|
|
84
|
+
this.baseUrl = config?.okxPrivateUrl || 'https://www.okx.com';
|
|
85
|
+
this.okxCredentials = {
|
|
86
|
+
apiKey: okxApiKey,
|
|
87
|
+
secretKey: okxSecretKey,
|
|
88
|
+
passphrase: okxPassphrase,
|
|
89
|
+
projectId: okxProjectId,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
isCorrectConfig(config) {
|
|
93
|
+
return (!!config['okxApiKey'] &&
|
|
94
|
+
!!config['okxSecretKey'] &&
|
|
95
|
+
!!config['okxPassphrase'] &&
|
|
96
|
+
!!config['okxProjectId']);
|
|
97
|
+
}
|
|
98
|
+
async fetchPrice(params) {
|
|
99
|
+
this.validatePriceParams(params);
|
|
100
|
+
const requestBody = this.priceParamsToRequestBody(params);
|
|
101
|
+
logger.debug('Generated OKX price request body', requestBody);
|
|
102
|
+
try {
|
|
103
|
+
const priceUrlParams = new URLSearchParams(requestBody);
|
|
104
|
+
const { signature, timestamp } = this.calculateSignature('GET', `${this.priceEndpoint}?${priceUrlParams}`);
|
|
105
|
+
const url = `${this.baseUrl}${this.priceEndpoint}?${priceUrlParams.toString()}`;
|
|
106
|
+
logger.debug(`Making request to OKX API: ${url}`);
|
|
107
|
+
const headers = {};
|
|
108
|
+
headers['OK-ACCESS-KEY'] = this.okxCredentials.apiKey || '';
|
|
109
|
+
headers['OK-ACCESS-SIGN'] = signature;
|
|
110
|
+
headers['OK-ACCESS-TIMESTAMP'] = timestamp;
|
|
111
|
+
headers['OK-ACCESS-PASSPHRASE'] = this.okxCredentials.passphrase || '';
|
|
112
|
+
headers['OK-ACCESS-PROJECT'] = this.okxCredentials.projectId || '';
|
|
113
|
+
const response = await axios_1.default.get(url, { headers });
|
|
114
|
+
const okxPriceResponse = response.data;
|
|
115
|
+
if (!okxPriceResponse ||
|
|
116
|
+
!okxPriceResponse.data ||
|
|
117
|
+
okxPriceResponse.data.length === 0 ||
|
|
118
|
+
!okxPriceResponse?.data?.[0]?.toTokenAmount) {
|
|
119
|
+
logger.error('Invalid response received from OKX API', undefined, { okxPriceResponse });
|
|
120
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, 'Invalid response received from OKX API');
|
|
121
|
+
}
|
|
122
|
+
logger.debug('Successfully received price info from OKX', {
|
|
123
|
+
amountOut: okxPriceResponse.data[0].toTokenAmount,
|
|
124
|
+
gasEstimate: okxPriceResponse.data[0].estimateGasFee,
|
|
125
|
+
});
|
|
126
|
+
const amountOut = okxPriceResponse.data[0].toTokenAmount;
|
|
127
|
+
if (!amountOut) {
|
|
128
|
+
logger.error('No output amount received from OKX', undefined, { okxPriceResponse });
|
|
129
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, 'No output amount received from OKX');
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
protocol: this.protocol,
|
|
133
|
+
networkIn: params.networkIn,
|
|
134
|
+
networkOut: params.networkOut,
|
|
135
|
+
tokenIn: params.tokenIn,
|
|
136
|
+
tokenOut: params.tokenOut,
|
|
137
|
+
amountIn: params.amountIn,
|
|
138
|
+
amountOut,
|
|
139
|
+
estimatedGas: okxPriceResponse?.data?.[0].estimateGasFee,
|
|
140
|
+
protocolResponse: okxPriceResponse,
|
|
141
|
+
slippage: params.slippage,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const { errorMessage, errorMessageError } = (0, create_error_message_1.createErrorMessage)(error);
|
|
146
|
+
logger.error(`Failed to fetch swap price from ${this.protocol}`, errorMessageError);
|
|
147
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.PRICE_NOT_FOUND, `Failed to fetch swap price from OKX: ${errorMessage}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async fetchQuote(params) {
|
|
151
|
+
logger.info(`Fetching swap quote for address: ${params.from}`);
|
|
152
|
+
this.validatePriceParams(params);
|
|
153
|
+
const { from, receiver, tokenIn, tokenOut, amountIn, networkIn, networkOut } = params;
|
|
154
|
+
const quoteRequestBody = {
|
|
155
|
+
amount: amountIn.toString(),
|
|
156
|
+
chainId: networkIn.toString(),
|
|
157
|
+
fromTokenAddress: tokenIn,
|
|
158
|
+
toTokenAddress: tokenOut,
|
|
159
|
+
userWalletAddress: (0, address_1.formatAddress)(from),
|
|
160
|
+
slippage: params.slippage >= 1 ? params.slippage / 100 : params.slippage,
|
|
161
|
+
swapReceiverAddress: (0, address_1.formatAddress)(receiver || from),
|
|
162
|
+
};
|
|
163
|
+
logger.debug('Generated OKX quote request body', quoteRequestBody);
|
|
164
|
+
try {
|
|
165
|
+
const quoteUrlParams = new URLSearchParams(quoteRequestBody);
|
|
166
|
+
const { signature, timestamp } = this.calculateSignature('GET', `${this.quoteEndpoint}?${quoteUrlParams}`);
|
|
167
|
+
const url = `${this.baseUrl}${this.quoteEndpoint}?${quoteUrlParams.toString()}`;
|
|
168
|
+
logger.debug(`Making request to OKX quote API: ${url}`);
|
|
169
|
+
const headers = {};
|
|
170
|
+
headers['OK-ACCESS-KEY'] = this.okxCredentials.apiKey || '';
|
|
171
|
+
headers['OK-ACCESS-SIGN'] = signature;
|
|
172
|
+
headers['OK-ACCESS-TIMESTAMP'] = timestamp;
|
|
173
|
+
headers['OK-ACCESS-PASSPHRASE'] = this.okxCredentials.passphrase || '';
|
|
174
|
+
headers['OK-ACCESS-PROJECT'] = this.okxCredentials.projectId || '';
|
|
175
|
+
const response = await axios_1.default.get(url, { headers });
|
|
176
|
+
const okxQuoteResponse = response.data;
|
|
177
|
+
logger.debug('Successfully received quote info from OKX');
|
|
178
|
+
if (!okxQuoteResponse ||
|
|
179
|
+
!okxQuoteResponse.data ||
|
|
180
|
+
okxQuoteResponse.data.length === 0 ||
|
|
181
|
+
!okxQuoteResponse?.data?.[0]?.routerResult?.toTokenAmount) {
|
|
182
|
+
logger.error('Invalid quote response received from OKX', undefined, { okxQuoteResponse });
|
|
183
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, 'Invalid quote response received from OKX');
|
|
184
|
+
}
|
|
185
|
+
const gasEstimate = okxQuoteResponse.data[0].tx.gas;
|
|
186
|
+
const gasLimit = okxQuoteResponse.data[0].tx.gasLimit || (Number(gasEstimate) * 1.1).toString(); // 10% buffer if gasLimit not provided
|
|
187
|
+
return {
|
|
188
|
+
protocol: this.protocol,
|
|
189
|
+
tokenIn: tokenIn,
|
|
190
|
+
tokenOut: tokenOut,
|
|
191
|
+
amountIn: amountIn,
|
|
192
|
+
amountOut: okxQuoteResponse.data[0].routerResult.toTokenAmount,
|
|
193
|
+
from,
|
|
194
|
+
receiver: receiver || from,
|
|
195
|
+
executionPayload: {
|
|
196
|
+
transactionData: {
|
|
197
|
+
data: okxQuoteResponse?.data?.[0].tx.data,
|
|
198
|
+
to: okxQuoteResponse?.data?.[0].tx.to,
|
|
199
|
+
value: (0, is_native_1.isNative)(tokenIn) ? amountIn : okxQuoteResponse?.data?.[0].tx.value,
|
|
200
|
+
gasEstimate,
|
|
201
|
+
gasLimit,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
slippage: params.slippage >= 1 ? params.slippage / 100 : params.slippage,
|
|
205
|
+
networkIn,
|
|
206
|
+
networkOut,
|
|
207
|
+
protocolResponse: okxQuoteResponse,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
const { errorMessage, errorMessageError } = (0, create_error_message_1.createErrorMessage)(error);
|
|
212
|
+
logger.error(`Failed to fetch quote from ${this.protocol}`, errorMessageError);
|
|
213
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.QUOTE_NOT_FOUND, `Failed to fetch swap quote from OKX: ${errorMessage}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
priceParamsToRequestBody(params) {
|
|
217
|
+
const { tokenIn, tokenOut, amountIn, networkIn } = params;
|
|
218
|
+
logger.debug('Converting price params to OKX request body', { params });
|
|
219
|
+
const requestBody = {
|
|
220
|
+
amount: amountIn.toString(),
|
|
221
|
+
chainId: networkIn.toString(),
|
|
222
|
+
fromTokenAddress: (0, is_native_1.isNative)(tokenIn) ? constants_1.ZERO_ADDRESS : (0, address_1.formatAddress)(tokenIn),
|
|
223
|
+
toTokenAddress: (0, is_native_1.isNative)(tokenOut) ? constants_1.ZERO_ADDRESS : (0, address_1.formatAddress)(tokenOut),
|
|
224
|
+
};
|
|
225
|
+
logger.debug('Generated OKX request body', requestBody);
|
|
226
|
+
return requestBody;
|
|
227
|
+
}
|
|
228
|
+
calculateSignature(method, requestPath, queryParams, body) {
|
|
229
|
+
const timestamp = new Date().toISOString();
|
|
230
|
+
// Construct the pre-hash string
|
|
231
|
+
let preHash = timestamp + method.toUpperCase() + requestPath;
|
|
232
|
+
// Add query parameters to request path if present
|
|
233
|
+
if (queryParams) {
|
|
234
|
+
const queryString = new URLSearchParams(queryParams).toString();
|
|
235
|
+
preHash += '?' + queryString;
|
|
236
|
+
}
|
|
237
|
+
// Add body to pre-hash string if present
|
|
238
|
+
if (body) {
|
|
239
|
+
preHash += body;
|
|
240
|
+
}
|
|
241
|
+
// Create the HMAC SHA256 signature
|
|
242
|
+
//@ts-ignore
|
|
243
|
+
const hmac = crypto.createHmac('sha256', this.okxCredentials.secretKey);
|
|
244
|
+
hmac.update(preHash);
|
|
245
|
+
const signature = hmac.digest('base64');
|
|
246
|
+
return { signature, timestamp };
|
|
247
|
+
}
|
|
248
|
+
validatePriceParams(params) {
|
|
249
|
+
const { networkIn, networkOut } = params;
|
|
250
|
+
logger.debug('Validating price params');
|
|
251
|
+
if (!this.okxCredentials.apiKey) {
|
|
252
|
+
logger.error('API key not provided');
|
|
253
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'OKX API key not provided');
|
|
254
|
+
}
|
|
255
|
+
if (!this.okxCredentials.secretKey) {
|
|
256
|
+
logger.error('Secret key not provided');
|
|
257
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'OKX Secret key not provided');
|
|
258
|
+
}
|
|
259
|
+
if (!this.multiChain && networkIn !== networkOut) {
|
|
260
|
+
logger.error('Multi-chain swaps not supported');
|
|
261
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'Multi-chain swaps not supported');
|
|
262
|
+
}
|
|
263
|
+
if (!this.singleChain && networkIn === networkOut) {
|
|
264
|
+
logger.error('Single-chain swaps not supported');
|
|
265
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, 'Single-chain swaps not supported');
|
|
266
|
+
}
|
|
267
|
+
if (!this.chains.includes(networkIn)) {
|
|
268
|
+
logger.error(`Network ${networkIn} not supported`);
|
|
269
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Network ${networkIn} not supported`);
|
|
270
|
+
}
|
|
271
|
+
if (!this.chains.includes(networkOut)) {
|
|
272
|
+
logger.error(`Network ${networkOut} not supported`);
|
|
273
|
+
throw (0, throw_error_1.sdkError)(enums_1.SdkErrorEnum.INVALID_PARAMS, `Network ${networkOut} not supported`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
isOkxPriceResponse(response) {
|
|
277
|
+
return 'data' in response && Array.isArray(response.data) && response.data.length > 0;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.OkxService = OkxService;
|
|
281
|
+
//# sourceMappingURL=okx.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx.service.js","sourceRoot":"","sources":["../../../../src/protocols/okx/okx.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,+CAAiC;AAEjC,6CAA4E;AAM5E,iDAAoD;AACpD,+CAA0E;AAC1E,qDAAqD;AACrD,qDA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IAES,kBAAkB,CAAC,QAAkC;QAC7D,OAAO,MAAM,IAAI,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACxF,CAAC;CACF;AA9SD,gCA8SC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ChainIdEnum } from '../../types/enums';
|
|
2
|
+
export type OKXCredentials = {
|
|
3
|
+
apiKey: string | null;
|
|
4
|
+
secretKey: string | null;
|
|
5
|
+
passphrase: string | null;
|
|
6
|
+
projectId: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type ApprovalContracts = {
|
|
9
|
+
[ChainIdEnum.ETHEREUM]: string;
|
|
10
|
+
[ChainIdEnum.ARBITRUM]: string;
|
|
11
|
+
[ChainIdEnum.OPTIMISM]: string;
|
|
12
|
+
[ChainIdEnum.POLYGON]: string;
|
|
13
|
+
[ChainIdEnum.BSC]: string;
|
|
14
|
+
[ChainIdEnum.AVALANCHE]: string;
|
|
15
|
+
[ChainIdEnum.BASE]: string;
|
|
16
|
+
};
|
|
17
|
+
export type OKXConfig = {
|
|
18
|
+
okxPrivateUrl?: string;
|
|
19
|
+
okxApiKey: string;
|
|
20
|
+
okxSecretKey: string;
|
|
21
|
+
okxPassphrase: string;
|
|
22
|
+
okxProjectId: string;
|
|
23
|
+
};
|
|
24
|
+
export type OkxQueryParams = {
|
|
25
|
+
[key: string]: string | number;
|
|
26
|
+
};
|
|
27
|
+
export type OkxPriceRequestBody = {
|
|
28
|
+
amount: string;
|
|
29
|
+
chainId: string;
|
|
30
|
+
fromTokenAddress: string;
|
|
31
|
+
toTokenAddress: string;
|
|
32
|
+
};
|
|
33
|
+
export type OkxQuoteRequestBody = {
|
|
34
|
+
amount: string;
|
|
35
|
+
chainId: string;
|
|
36
|
+
fromTokenAddress: string;
|
|
37
|
+
toTokenAddress: string;
|
|
38
|
+
userWalletAddress: string;
|
|
39
|
+
slippage: number;
|
|
40
|
+
swapReceiverAddress: string;
|
|
41
|
+
};
|
|
42
|
+
export type Token = {
|
|
43
|
+
decimals: number;
|
|
44
|
+
tokenContractAddress: string;
|
|
45
|
+
tokenSymbol: string;
|
|
46
|
+
};
|
|
47
|
+
export type TokenWithPrice = Token & {
|
|
48
|
+
tokenUnitPrice: string;
|
|
49
|
+
};
|
|
50
|
+
export type DexProtocol = {
|
|
51
|
+
dexName: string;
|
|
52
|
+
percent: string;
|
|
53
|
+
};
|
|
54
|
+
export type SinglechainDexRouter = {
|
|
55
|
+
router: string;
|
|
56
|
+
routerPercent: string;
|
|
57
|
+
subRouterList: SinglechainSubRouter[];
|
|
58
|
+
};
|
|
59
|
+
export type SinglechainSubRouter = {
|
|
60
|
+
dexProtocol: DexProtocol[];
|
|
61
|
+
fromToken: TokenWithPrice;
|
|
62
|
+
toToken: TokenWithPrice;
|
|
63
|
+
};
|
|
64
|
+
export type QuoteCompareItem = {
|
|
65
|
+
amountOut: string;
|
|
66
|
+
dexLogo: string;
|
|
67
|
+
dexName: string;
|
|
68
|
+
tradeFee: string;
|
|
69
|
+
};
|
|
70
|
+
export type SinglechainTransaction = {
|
|
71
|
+
data: string;
|
|
72
|
+
from: string;
|
|
73
|
+
to: string;
|
|
74
|
+
value: string;
|
|
75
|
+
gas: string;
|
|
76
|
+
gasLimit: string;
|
|
77
|
+
gasPrice: string;
|
|
78
|
+
maxPriorityFeePerGas: string;
|
|
79
|
+
minReceiveAmount: string;
|
|
80
|
+
};
|
|
81
|
+
export type OkxPriceData = {
|
|
82
|
+
chainId: string;
|
|
83
|
+
dexRouterList: SinglechainDexRouter[];
|
|
84
|
+
estimateGasFee: string;
|
|
85
|
+
fromToken: TokenWithPrice;
|
|
86
|
+
fromTokenAmount: string;
|
|
87
|
+
quoteCompareList: QuoteCompareItem[];
|
|
88
|
+
toToken: TokenWithPrice;
|
|
89
|
+
toTokenAmount: string;
|
|
90
|
+
};
|
|
91
|
+
export type OkxQuoteData = {
|
|
92
|
+
routerResult: OkxPriceData;
|
|
93
|
+
tx: SinglechainTransaction;
|
|
94
|
+
};
|
|
95
|
+
export type OkxPriceResponse = {
|
|
96
|
+
code: string | number;
|
|
97
|
+
msg: string;
|
|
98
|
+
data: OkxPriceData[];
|
|
99
|
+
};
|
|
100
|
+
export type OkxQuoteResponse = {
|
|
101
|
+
code: string | number;
|
|
102
|
+
msg: string;
|
|
103
|
+
data: OkxQuoteData[];
|
|
104
|
+
};
|
|
105
|
+
export type OkxMultiPriceParams = {
|
|
106
|
+
network: ChainIdEnum;
|
|
107
|
+
from: string;
|
|
108
|
+
tokensIn: string[];
|
|
109
|
+
tokenOut: string;
|
|
110
|
+
amountsIn: string[];
|
|
111
|
+
slippage: string;
|
|
112
|
+
};
|
|
113
|
+
export type OkxMultiQuoteParams = {
|
|
114
|
+
network: ChainIdEnum;
|
|
115
|
+
fromAddress: string;
|
|
116
|
+
priceData: OkxPriceData;
|
|
117
|
+
receiver?: string;
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=okx.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx.types.d.ts","sourceRoot":"","sources":["../../../../src/protocols/okx/okx.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC/B,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC/B,CAAC,WAAW,CAAC,QAAQ,CAAC,E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AAsB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,YAAY,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,YAAY,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,YAAY,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx.types.js","sourceRoot":"","sources":["../../../../src/protocols/okx/okx.types.ts"],"names":[],"mappings":";;AAAA,6CAAgD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=okx-bridge.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx-bridge.service.d.ts","sourceRoot":"","sources":["../../../../src/protocols/okx-bridge/okx-bridge.service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx-bridge.service.js","sourceRoot":"","sources":["../../../../src/protocols/okx-bridge/okx-bridge.service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=okx-bridge.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx-bridge.types.d.ts","sourceRoot":"","sources":["../../../../src/protocols/okx-bridge/okx-bridge.types.ts"],"names":[],"mappings":""}
|