@reyaxyz/sdk 0.118.4 → 0.119.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/README.md +1 -1
- package/dist/services/swaps/simulation.js +21 -6
- package/dist/services/swaps/simulation.js.map +1 -1
- package/dist/services/swaps/types.js.map +1 -1
- package/dist/types/services/swaps/simulation.d.ts +2 -2
- package/dist/types/services/swaps/simulation.d.ts.map +1 -1
- package/dist/types/services/swaps/types.d.ts +16 -3
- package/dist/types/services/swaps/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/services/swaps/simulation.ts +28 -7
- package/src/services/swaps/types.ts +18 -3
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.simulateSwap = void 0;
|
|
40
40
|
var common_1 = require("@reyaxyz/common");
|
|
41
41
|
var ethers_1 = require("ethers");
|
|
42
42
|
var config_1 = require("../../config");
|
|
@@ -108,14 +108,14 @@ var abi = [
|
|
|
108
108
|
type: 'function',
|
|
109
109
|
},
|
|
110
110
|
];
|
|
111
|
-
var env = (0, config_1.getSdkEnvironment)();
|
|
112
|
-
var chainId = (0, common_1.getReyaNetwork)(env === 'production' ? 'production' : 'test');
|
|
113
|
-
var provider = ethers_1.ethers.getDefaultProvider(common_1.reyaChainIdRPCMapper[chainId]);
|
|
114
111
|
var findBestPath = function (amountFrom, tokenFrom, tokenTo, maxSteps) { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
-
var coreAddress, core, tokenInfoFrom, tokenInfoTo, amountFromScaled, result;
|
|
112
|
+
var env, chainId, provider, coreAddress, core, tokenInfoFrom, tokenInfoTo, amountFromScaled, result;
|
|
116
113
|
return __generator(this, function (_a) {
|
|
117
114
|
switch (_a.label) {
|
|
118
115
|
case 0:
|
|
116
|
+
env = (0, config_1.getSdkEnvironment)();
|
|
117
|
+
chainId = (0, common_1.getReyaNetwork)(env === 'production' ? 'production' : 'test');
|
|
118
|
+
provider = ethers_1.ethers.getDefaultProvider(common_1.reyaChainIdRPCMapper[chainId]);
|
|
119
119
|
coreAddress = (0, common_1.getAddress)(chainId, common_1.ContractType.CAMELOT_YAK_ROUTER);
|
|
120
120
|
core = new ethers_1.Contract(coreAddress, abi, provider);
|
|
121
121
|
tokenInfoFrom = (0, common_1.getTokenInfoByAddress)(tokenFrom);
|
|
@@ -136,5 +136,20 @@ var findBestPath = function (amountFrom, tokenFrom, tokenTo, maxSteps) { return
|
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
138
|
}); };
|
|
139
|
-
|
|
139
|
+
var simulateSwap = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
+
var bestPathResult;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0: return [4 /*yield*/, findBestPath(params.amountFrom, params.tokenFrom, params.tokenTo)];
|
|
144
|
+
case 1:
|
|
145
|
+
bestPathResult = _a.sent();
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
bestPath: bestPathResult,
|
|
148
|
+
estimatedSlippage: 0.013, // TODO: M?
|
|
149
|
+
marginRatio: 0.93, // TODO: IR
|
|
150
|
+
}];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}); };
|
|
154
|
+
exports.simulateSwap = simulateSwap;
|
|
140
155
|
//# sourceMappingURL=simulation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.js","sourceRoot":"/","sources":["services/swaps/simulation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAQyB;AACzB,iCAA0C;
|
|
1
|
+
{"version":3,"file":"simulation.js","sourceRoot":"/","sources":["services/swaps/simulation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAQyB;AACzB,iCAA0C;AAM1C,uCAAiD;AACjD,IAAM,GAAG,GAAG;IACV;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,YAAY,EAAE,WAAW;gBACzB,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,WAAW;aAClB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE;YACP;gBACE,UAAU,EAAE;oBACV;wBACE,YAAY,EAAE,WAAW;wBACzB,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,WAAW;qBAClB;oBACD;wBACE,YAAY,EAAE,WAAW;wBACzB,IAAI,EAAE,UAAU;wBAChB,IAAI,EAAE,WAAW;qBAClB;oBACD;wBACE,YAAY,EAAE,WAAW;wBACzB,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,WAAW;qBAClB;oBACD;wBACE,YAAY,EAAE,WAAW;wBACzB,IAAI,EAAE,YAAY;wBAClB,IAAI,EAAE,WAAW;qBAClB;oBACD;wBACE,YAAY,EAAE,SAAS;wBACvB,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,SAAS;qBAChB;iBACF;gBACD,YAAY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Y,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;wBAC/B,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;wBAChC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;wBAC/B,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;wBAC3B,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;qBAClC,EAAC;;;KACH,CAAC;AAEK,IAAM,YAAY,GAAG,UAC1B,MAA0B;;;;oBAEH,qBAAM,YAAY,CACvC,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,OAAO,CACf,EAAA;;gBAJK,cAAc,GAAG,SAItB;gBAED,sBAAO;wBACL,QAAQ,EAAE,cAAc;wBACxB,iBAAiB,EAAE,KAAK,EAAE,WAAW;wBACrC,WAAW,EAAE,IAAI,EAAE,WAAW;qBAC/B,EAAC;;;KACH,CAAC;AAdW,QAAA,YAAY,gBAcvB","sourcesContent":["import {\n ContractType,\n descale,\n getAddress,\n getReyaNetwork,\n getTokenInfoByAddress,\n scale,\n reyaChainIdRPCMapper,\n} from '@reyaxyz/common';\nimport { Contract, ethers } from 'ethers';\nimport {\n FindBestPathResult,\n SimulateSwapParams,\n SimulateSwapResult,\n} from './types';\nimport { getSdkEnvironment } from '../../config';\nconst abi = [\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_amountIn',\n type: 'uint256',\n },\n {\n internalType: 'address',\n name: '_tokenIn',\n type: 'address',\n },\n {\n internalType: 'address',\n name: '_tokenOut',\n type: 'address',\n },\n {\n internalType: 'address[]',\n name: '_trustedTokens',\n type: 'address[]',\n },\n {\n internalType: 'uint256',\n name: '_maxSteps',\n type: 'uint256',\n },\n ],\n name: 'findBestPath',\n outputs: [\n {\n components: [\n {\n internalType: 'uint256[]',\n name: 'amounts',\n type: 'uint256[]',\n },\n {\n internalType: 'address[]',\n name: 'adapters',\n type: 'address[]',\n },\n {\n internalType: 'address[]',\n name: 'path',\n type: 'address[]',\n },\n {\n internalType: 'address[]',\n name: 'recipients',\n type: 'address[]',\n },\n {\n internalType: 'uint256',\n name: 'gasEstimate',\n type: 'uint256',\n },\n ],\n internalType: 'struct FormattedOffer',\n name: '',\n type: 'tuple',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\nconst findBestPath = async (\n amountFrom: number,\n tokenFrom: string,\n tokenTo: string,\n maxSteps?: number,\n): Promise<FindBestPathResult> => {\n const env = getSdkEnvironment();\n const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');\n const provider = ethers.getDefaultProvider(\n reyaChainIdRPCMapper[chainId] as string,\n );\n const coreAddress = getAddress(chainId, ContractType.CAMELOT_YAK_ROUTER);\n const core = new Contract(coreAddress, abi, provider);\n\n const tokenInfoFrom = getTokenInfoByAddress(tokenFrom);\n const tokenInfoTo = getTokenInfoByAddress(tokenTo);\n const amountFromScaled = scale(tokenInfoFrom.decimals)(amountFrom);\n\n // amountFrom\n // tokenFrom\n // tokenTo\n // trustedTokens\n // maxSteps\n const result = await core.findBestPath(\n amountFromScaled,\n tokenFrom,\n tokenTo,\n [],\n maxSteps || 4,\n );\n return {\n amountFrom: descale(tokenInfoFrom.decimals)(result.amounts[0]),\n amountTo: descale(tokenInfoTo.decimals)(result.amounts[1]),\n amountInBase: result.amounts[0],\n amountOutBase: result.amounts[1],\n adapters: Array.from(result[1]),\n path: Array.from(result[2]),\n recipients: Array.from(result[3]),\n };\n};\n\nexport const simulateSwap = async (\n params: SimulateSwapParams,\n): Promise<SimulateSwapResult> => {\n const bestPathResult = await findBestPath(\n params.amountFrom,\n params.tokenFrom,\n params.tokenTo,\n );\n\n return {\n bestPath: bestPathResult,\n estimatedSlippage: 0.013, // TODO: M?\n marginRatio: 0.93, // TODO: IR\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/swaps/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { MarginAccountEntity, OwnerMetadataEntity } from '@reyaxyz/common';\n\nexport type SwapParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n amountInBase: FindBestPathResult['amountInBase'];\n amountOutBase: FindBestPathResult['amountOutBase'];\n path: FindBestPathResult['path'];\n adapters: FindBestPathResult['adapters'];\n recipients: FindBestPathResult['recipients'];\n tradeSource?: 'reya' | 'rage' | 'other';\n};\n\nexport type SwapResult = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type FindBestPathResult = {\n amountFrom: number;\n amountTo: number;\n amountInBase:
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["services/swaps/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { MarginAccountEntity, OwnerMetadataEntity } from '@reyaxyz/common';\n\nexport type SwapParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n amountInBase: FindBestPathResult['amountInBase'];\n amountOutBase: FindBestPathResult['amountOutBase'];\n path: FindBestPathResult['path'];\n adapters: FindBestPathResult['adapters'];\n recipients: FindBestPathResult['recipients'];\n tradeSource?: 'reya' | 'rage' | 'other';\n};\n\nexport type SwapResult = {\n transactionHash: string | null;\n coreSigNonce: number | null;\n};\n\nexport type FindBestPathResult = {\n amountFrom: number;\n amountTo: number;\n amountInBase: SimulateSwapParams['amountFrom'];\n amountOutBase: SimulateSwapParams['amountFrom'];\n path: SimulateSwapParams['tokenFrom'][];\n adapters: string[];\n recipients: string[];\n};\n\nexport type SimulateSwapParams = {\n signer: Signer | JsonRpcSigner;\n owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;\n marginAccountId: MarginAccountEntity['id'];\n amountFrom: number;\n tokenFrom: string;\n tokenTo: string;\n};\n\nexport type SimulateSwapResult = {\n bestPath: FindBestPathResult;\n estimatedSlippage: number;\n marginRatio: number;\n};\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { SimulateSwapParams, SimulateSwapResult } from './types';
|
|
2
|
+
export declare const simulateSwap: (params: SimulateSwapParams) => Promise<SimulateSwapResult>;
|
|
3
3
|
//# sourceMappingURL=simulation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.d.ts","sourceRoot":"/","sources":["services/swaps/simulation.ts"],"names":[],"mappings":"AAUA,OAAO,
|
|
1
|
+
{"version":3,"file":"simulation.d.ts","sourceRoot":"/","sources":["services/swaps/simulation.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAgHjB,eAAO,MAAM,YAAY,WACf,kBAAkB,KACzB,QAAQ,kBAAkB,CAY5B,CAAC"}
|
|
@@ -18,10 +18,23 @@ export type SwapResult = {
|
|
|
18
18
|
export type FindBestPathResult = {
|
|
19
19
|
amountFrom: number;
|
|
20
20
|
amountTo: number;
|
|
21
|
-
amountInBase:
|
|
22
|
-
amountOutBase:
|
|
23
|
-
path:
|
|
21
|
+
amountInBase: SimulateSwapParams['amountFrom'];
|
|
22
|
+
amountOutBase: SimulateSwapParams['amountFrom'];
|
|
23
|
+
path: SimulateSwapParams['tokenFrom'][];
|
|
24
24
|
adapters: string[];
|
|
25
25
|
recipients: string[];
|
|
26
26
|
};
|
|
27
|
+
export type SimulateSwapParams = {
|
|
28
|
+
signer: Signer | JsonRpcSigner;
|
|
29
|
+
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
30
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
31
|
+
amountFrom: number;
|
|
32
|
+
tokenFrom: string;
|
|
33
|
+
tokenTo: string;
|
|
34
|
+
};
|
|
35
|
+
export type SimulateSwapResult = {
|
|
36
|
+
bestPath: FindBestPathResult;
|
|
37
|
+
estimatedSlippage: number;
|
|
38
|
+
marginRatio: number;
|
|
39
|
+
};
|
|
27
40
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/swaps/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,EAAE,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACjD,aAAa,EAAE,kBAAkB,CAAC,eAAe,CAAC,CAAC;IACnD,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACjC,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACzC,UAAU,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts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AC;IAC/B,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IACjD,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.119.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"ethers": "6.9.0"
|
|
36
36
|
},
|
|
37
37
|
"packageManager": "pnpm@8.3.1",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "39997c29be665baf749a4e8857a379616d44004b"
|
|
39
39
|
}
|
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
reyaChainIdRPCMapper,
|
|
9
9
|
} from '@reyaxyz/common';
|
|
10
10
|
import { Contract, ethers } from 'ethers';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
FindBestPathResult,
|
|
13
|
+
SimulateSwapParams,
|
|
14
|
+
SimulateSwapResult,
|
|
15
|
+
} from './types';
|
|
12
16
|
import { getSdkEnvironment } from '../../config';
|
|
13
17
|
const abi = [
|
|
14
18
|
{
|
|
@@ -78,17 +82,18 @@ const abi = [
|
|
|
78
82
|
type: 'function',
|
|
79
83
|
},
|
|
80
84
|
];
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const provider = ethers.getDefaultProvider(
|
|
84
|
-
reyaChainIdRPCMapper[chainId] as string,
|
|
85
|
-
);
|
|
86
|
-
export const findBestPath = async (
|
|
85
|
+
|
|
86
|
+
const findBestPath = async (
|
|
87
87
|
amountFrom: number,
|
|
88
88
|
tokenFrom: string,
|
|
89
89
|
tokenTo: string,
|
|
90
90
|
maxSteps?: number,
|
|
91
91
|
): Promise<FindBestPathResult> => {
|
|
92
|
+
const env = getSdkEnvironment();
|
|
93
|
+
const chainId = getReyaNetwork(env === 'production' ? 'production' : 'test');
|
|
94
|
+
const provider = ethers.getDefaultProvider(
|
|
95
|
+
reyaChainIdRPCMapper[chainId] as string,
|
|
96
|
+
);
|
|
92
97
|
const coreAddress = getAddress(chainId, ContractType.CAMELOT_YAK_ROUTER);
|
|
93
98
|
const core = new Contract(coreAddress, abi, provider);
|
|
94
99
|
|
|
@@ -118,3 +123,19 @@ export const findBestPath = async (
|
|
|
118
123
|
recipients: Array.from(result[3]),
|
|
119
124
|
};
|
|
120
125
|
};
|
|
126
|
+
|
|
127
|
+
export const simulateSwap = async (
|
|
128
|
+
params: SimulateSwapParams,
|
|
129
|
+
): Promise<SimulateSwapResult> => {
|
|
130
|
+
const bestPathResult = await findBestPath(
|
|
131
|
+
params.amountFrom,
|
|
132
|
+
params.tokenFrom,
|
|
133
|
+
params.tokenTo,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
bestPath: bestPathResult,
|
|
138
|
+
estimatedSlippage: 0.013, // TODO: M?
|
|
139
|
+
marginRatio: 0.93, // TODO: IR
|
|
140
|
+
};
|
|
141
|
+
};
|
|
@@ -21,9 +21,24 @@ export type SwapResult = {
|
|
|
21
21
|
export type FindBestPathResult = {
|
|
22
22
|
amountFrom: number;
|
|
23
23
|
amountTo: number;
|
|
24
|
-
amountInBase:
|
|
25
|
-
amountOutBase:
|
|
26
|
-
path:
|
|
24
|
+
amountInBase: SimulateSwapParams['amountFrom'];
|
|
25
|
+
amountOutBase: SimulateSwapParams['amountFrom'];
|
|
26
|
+
path: SimulateSwapParams['tokenFrom'][];
|
|
27
27
|
adapters: string[];
|
|
28
28
|
recipients: string[];
|
|
29
29
|
};
|
|
30
|
+
|
|
31
|
+
export type SimulateSwapParams = {
|
|
32
|
+
signer: Signer | JsonRpcSigner;
|
|
33
|
+
owner: Pick<OwnerMetadataEntity, 'coreSigNonce'>;
|
|
34
|
+
marginAccountId: MarginAccountEntity['id'];
|
|
35
|
+
amountFrom: number;
|
|
36
|
+
tokenFrom: string;
|
|
37
|
+
tokenTo: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type SimulateSwapResult = {
|
|
41
|
+
bestPath: FindBestPathResult;
|
|
42
|
+
estimatedSlippage: number;
|
|
43
|
+
marginRatio: number;
|
|
44
|
+
};
|