@suilend/sdk 1.1.99 → 2.0.1
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/_generated/_dependencies/source/0x1/ascii/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x1/ascii/structs.js +35 -75
- package/_generated/_dependencies/source/0x1/index.js +3 -6
- package/_generated/_dependencies/source/0x1/option/structs.d.ts +3 -3
- package/_generated/_dependencies/source/0x1/option/structs.js +31 -69
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x1/type-name/structs.js +20 -25
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x2/bag/structs.js +24 -29
- package/_generated/_dependencies/source/0x2/balance/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x2/balance/structs.js +49 -56
- package/_generated/_dependencies/source/0x2/index.js +3 -6
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +8 -8
- package/_generated/_dependencies/source/0x2/object/structs.js +34 -41
- package/_generated/_dependencies/source/0x2/object-table/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x2/object-table/structs.js +31 -36
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +23 -28
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +4 -7
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +11 -11
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +32 -37
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +23 -23
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +29 -34
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +4 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +21 -59
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +55 -55
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +46 -53
- package/_generated/_framework/reified.d.ts +2 -2
- package/_generated/_framework/reified.js +27 -40
- package/_generated/_framework/util.js +26 -40
- package/_generated/_framework/vector.d.ts +4 -4
- package/_generated/_framework/vector.js +16 -21
- package/_generated/suilend/cell/structs.d.ts +4 -4
- package/_generated/suilend/cell/structs.js +31 -36
- package/_generated/suilend/decimal/structs.d.ts +4 -4
- package/_generated/suilend/decimal/structs.js +19 -24
- package/_generated/suilend/index.js +8 -12
- package/_generated/suilend/lending-market/functions.d.ts +1 -0
- package/_generated/suilend/lending-market/functions.js +271 -302
- package/_generated/suilend/lending-market/structs.d.ts +146 -146
- package/_generated/suilend/lending-market/structs.js +549 -617
- package/_generated/suilend/lending-market-registry/functions.js +7 -11
- package/_generated/suilend/liquidity-mining/structs.d.ts +50 -50
- package/_generated/suilend/liquidity-mining/structs.js +159 -205
- package/_generated/suilend/obligation/structs.d.ts +106 -106
- package/_generated/suilend/obligation/structs.js +313 -363
- package/_generated/suilend/rate-limiter/functions.js +23 -31
- package/_generated/suilend/rate-limiter/structs.d.ts +15 -15
- package/_generated/suilend/rate-limiter/structs.js +49 -56
- package/_generated/suilend/reserve/structs.d.ts +139 -139
- package/_generated/suilend/reserve/structs.js +397 -451
- package/_generated/suilend/reserve-config/functions.js +149 -190
- package/_generated/suilend/reserve-config/structs.d.ts +33 -33
- package/_generated/suilend/reserve-config/structs.js +109 -149
- package/api/events.js +1 -5
- package/api/index.js +1 -17
- package/client.d.ts +10 -10
- package/client.js +118 -128
- package/index.js +7 -23
- package/lib/constants.js +3 -9
- package/lib/index.js +5 -21
- package/lib/initialize.d.ts +3 -3
- package/lib/initialize.js +103 -140
- package/lib/liquidityMining.d.ts +3 -3
- package/lib/liquidityMining.js +57 -72
- package/lib/pyth.js +9 -14
- package/lib/strategyOwnerCap.js +106 -119
- package/lib/transactions.js +2 -7
- package/lib/types.js +4 -7
- package/mmt.js +2 -5
- package/package.json +1 -1
- package/parsers/apiReserveAssetDataEvent.js +25 -33
- package/parsers/index.js +5 -21
- package/parsers/lendingMarket.d.ts +1 -1
- package/parsers/lendingMarket.js +12 -19
- package/parsers/obligation.js +19 -26
- package/parsers/rateLimiter.js +11 -19
- package/parsers/reserve.d.ts +1 -1
- package/parsers/reserve.js +42 -85
- package/strategies.d.ts +11 -11
- package/strategies.js +547 -586
- package/swap/index.js +2 -18
- package/swap/quote.js +57 -65
- package/swap/transaction.d.ts +2 -2
- package/swap/transaction.js +40 -35
- package/utils/events.d.ts +3 -3
- package/utils/events.js +18 -35
- package/utils/index.js +16 -40
- package/utils/obligation.d.ts +4 -4
- package/utils/obligation.js +17 -60
- package/utils/simulate.js +118 -143
package/swap/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
__exportStar(require("./quote"), exports);
|
|
18
|
-
__exportStar(require("./transaction"), exports);
|
|
1
|
+
export * from "./quote";
|
|
2
|
+
export * from "./transaction";
|
package/swap/quote.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,25 +7,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
19
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
20
|
-
const uuid_1 = require("uuid");
|
|
21
|
-
const lib_1 = require("../lib");
|
|
22
|
-
var QuoteProvider;
|
|
10
|
+
import { getQuote as getBluefin7kQuoteOriginal, } from "@bluefin-exchange/bluefin7k-aggregator-sdk/cjs";
|
|
11
|
+
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
12
|
+
import BigNumber from "bignumber.js";
|
|
13
|
+
import BN from "bn.js";
|
|
14
|
+
import { v4 as uuidv4 } from "uuid";
|
|
15
|
+
import { WAD } from "../lib";
|
|
16
|
+
export var QuoteProvider;
|
|
23
17
|
(function (QuoteProvider) {
|
|
24
18
|
QuoteProvider["AFTERMATH"] = "aftermath";
|
|
25
19
|
QuoteProvider["CETUS"] = "cetus";
|
|
26
20
|
QuoteProvider["BLUEFIN7K"] = "bluefin7k";
|
|
27
21
|
QuoteProvider["FLOWX"] = "flowx";
|
|
28
|
-
})(QuoteProvider || (
|
|
29
|
-
|
|
22
|
+
})(QuoteProvider || (QuoteProvider = {}));
|
|
23
|
+
export const QUOTE_PROVIDER_NAME_MAP = {
|
|
30
24
|
[QuoteProvider.AFTERMATH]: "Aftermath",
|
|
31
25
|
[QuoteProvider.CETUS]: "Cetus",
|
|
32
26
|
[QuoteProvider.BLUEFIN7K]: "Bluefin7k",
|
|
@@ -65,30 +59,30 @@ const getAftermathQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0
|
|
|
65
59
|
coinInAmount: BigInt(amountIn),
|
|
66
60
|
});
|
|
67
61
|
const standardizedQuote = {
|
|
68
|
-
id: (
|
|
62
|
+
id: uuidv4(),
|
|
69
63
|
provider: QuoteProvider.AFTERMATH,
|
|
70
64
|
in: {
|
|
71
65
|
coinType: tokenIn.coinType,
|
|
72
|
-
amount: new
|
|
66
|
+
amount: new BigNumber(quote.coinIn.amount.toString()).div(10 ** tokenIn.decimals),
|
|
73
67
|
},
|
|
74
68
|
out: {
|
|
75
69
|
coinType: tokenOut.coinType,
|
|
76
|
-
amount: new
|
|
70
|
+
amount: new BigNumber(quote.coinOut.amount.toString()).div(10 ** tokenOut.decimals),
|
|
77
71
|
},
|
|
78
72
|
routes: quote.routes.map((route, routeIndex) => ({
|
|
79
|
-
percent: new
|
|
73
|
+
percent: new BigNumber(route.portion.toString()).div(WAD).times(100),
|
|
80
74
|
path: route.paths.map((path) => ({
|
|
81
|
-
id: (
|
|
75
|
+
id: uuidv4(),
|
|
82
76
|
poolId: path.poolId,
|
|
83
77
|
routeIndex,
|
|
84
78
|
provider: path.protocolName,
|
|
85
79
|
in: {
|
|
86
|
-
coinType:
|
|
87
|
-
amount: new
|
|
80
|
+
coinType: normalizeStructTag(path.coinIn.type),
|
|
81
|
+
amount: new BigNumber(path.coinIn.amount.toString()),
|
|
88
82
|
},
|
|
89
83
|
out: {
|
|
90
|
-
coinType:
|
|
91
|
-
amount: new
|
|
84
|
+
coinType: normalizeStructTag(path.coinOut.type),
|
|
85
|
+
amount: new BigNumber(path.coinOut.amount.toString()),
|
|
92
86
|
},
|
|
93
87
|
})),
|
|
94
88
|
})),
|
|
@@ -100,7 +94,7 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
100
94
|
const quote = yield sdk.findRouters({
|
|
101
95
|
from: tokenIn.coinType,
|
|
102
96
|
target: tokenOut.coinType,
|
|
103
|
-
amount: new
|
|
97
|
+
amount: new BN(amountIn),
|
|
104
98
|
byAmountIn: true,
|
|
105
99
|
});
|
|
106
100
|
if (!quote)
|
|
@@ -113,8 +107,8 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
113
107
|
for (const route of routes) {
|
|
114
108
|
if (route.paths.length > 0 &&
|
|
115
109
|
path.amountIn === route.paths[route.paths.length - 1].amountOut &&
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
normalizeStructTag(path.from) ===
|
|
111
|
+
normalizeStructTag(route.paths[route.paths.length - 1].target)) {
|
|
118
112
|
route.paths.push(path);
|
|
119
113
|
addedToExistingRoute = true;
|
|
120
114
|
break;
|
|
@@ -122,9 +116,9 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
122
116
|
}
|
|
123
117
|
// If couldn't add to existing route, only start a new route if it's from the quote's from field
|
|
124
118
|
if (!addedToExistingRoute &&
|
|
125
|
-
|
|
119
|
+
normalizeStructTag(path.from) === normalizeStructTag(tokenIn.coinType)) {
|
|
126
120
|
routes.push({
|
|
127
|
-
amountIn: new
|
|
121
|
+
amountIn: new BigNumber(path.amountIn),
|
|
128
122
|
paths: [path],
|
|
129
123
|
});
|
|
130
124
|
}
|
|
@@ -132,32 +126,32 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
132
126
|
const remainingPaths = quote.paths.filter((path) => !routes.some((route) => route.paths.some((p) => p.id === path.id)));
|
|
133
127
|
// TODO
|
|
134
128
|
const standardizedQuote = {
|
|
135
|
-
id: (
|
|
129
|
+
id: uuidv4(),
|
|
136
130
|
provider: QuoteProvider.CETUS,
|
|
137
131
|
in: {
|
|
138
132
|
coinType: tokenIn.coinType,
|
|
139
|
-
amount: new
|
|
133
|
+
amount: new BigNumber(quote.amountIn.toString()).div(10 ** tokenIn.decimals),
|
|
140
134
|
},
|
|
141
135
|
out: {
|
|
142
136
|
coinType: tokenOut.coinType,
|
|
143
|
-
amount: new
|
|
137
|
+
amount: new BigNumber(quote.amountOut.toString()).div(10 ** tokenOut.decimals),
|
|
144
138
|
},
|
|
145
139
|
routes: routes.map((route, routeIndex) => ({
|
|
146
|
-
percent: new
|
|
140
|
+
percent: new BigNumber(route.amountIn.toString())
|
|
147
141
|
.div(quote.amountIn.toString())
|
|
148
142
|
.times(100),
|
|
149
143
|
path: route.paths.map((path) => ({
|
|
150
|
-
id: (
|
|
144
|
+
id: uuidv4(),
|
|
151
145
|
poolId: path.id,
|
|
152
146
|
routeIndex,
|
|
153
147
|
provider: path.provider,
|
|
154
148
|
in: {
|
|
155
|
-
coinType:
|
|
156
|
-
amount: new
|
|
149
|
+
coinType: normalizeStructTag(path.from),
|
|
150
|
+
amount: new BigNumber(path.amountIn.toString()),
|
|
157
151
|
},
|
|
158
152
|
out: {
|
|
159
|
-
coinType:
|
|
160
|
-
amount: new
|
|
153
|
+
coinType: normalizeStructTag(path.target),
|
|
154
|
+
amount: new BigNumber(path.amountOut.toString()),
|
|
161
155
|
},
|
|
162
156
|
})),
|
|
163
157
|
})),
|
|
@@ -167,42 +161,42 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
167
161
|
});
|
|
168
162
|
const getBluefin7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
163
|
var _a;
|
|
170
|
-
const quote = yield (
|
|
164
|
+
const quote = yield getBluefin7kQuoteOriginal({
|
|
171
165
|
tokenIn: tokenIn.coinType,
|
|
172
166
|
tokenOut: tokenOut.coinType,
|
|
173
167
|
amountIn,
|
|
174
168
|
});
|
|
175
169
|
const standardizedQuote = {
|
|
176
|
-
id: (
|
|
170
|
+
id: uuidv4(),
|
|
177
171
|
provider: QuoteProvider.BLUEFIN7K,
|
|
178
172
|
in: {
|
|
179
173
|
coinType: tokenIn.coinType,
|
|
180
|
-
amount: new
|
|
174
|
+
amount: new BigNumber(quote.swapAmountWithDecimal).div(10 ** tokenIn.decimals),
|
|
181
175
|
},
|
|
182
176
|
out: {
|
|
183
177
|
coinType: tokenOut.coinType,
|
|
184
|
-
amount: new
|
|
178
|
+
amount: new BigNumber(quote.returnAmountWithDecimal).div(10 ** tokenOut.decimals),
|
|
185
179
|
},
|
|
186
180
|
routes: ((_a = quote.routes) !== null && _a !== void 0 ? _a : []).map((route, routeIndex) => ({
|
|
187
|
-
percent: new
|
|
181
|
+
percent: new BigNumber(route.tokenInAmount)
|
|
188
182
|
.div(quote.swapAmount)
|
|
189
183
|
.times(100),
|
|
190
184
|
path: route.hops.map((hop) => ({
|
|
191
|
-
id: (
|
|
185
|
+
id: uuidv4(),
|
|
192
186
|
poolId: hop.poolId,
|
|
193
187
|
routeIndex,
|
|
194
188
|
provider: hop.pool.type,
|
|
195
189
|
in: {
|
|
196
|
-
coinType:
|
|
197
|
-
amount: new
|
|
198
|
-
hop.pool.allTokens.find((t) =>
|
|
199
|
-
|
|
190
|
+
coinType: normalizeStructTag(hop.tokenIn),
|
|
191
|
+
amount: new BigNumber(hop.tokenInAmount).times(10 **
|
|
192
|
+
hop.pool.allTokens.find((t) => normalizeStructTag(t.address) ===
|
|
193
|
+
normalizeStructTag(hop.tokenIn)).decimal),
|
|
200
194
|
},
|
|
201
195
|
out: {
|
|
202
|
-
coinType:
|
|
203
|
-
amount: new
|
|
204
|
-
hop.pool.allTokens.find((t) =>
|
|
205
|
-
|
|
196
|
+
coinType: normalizeStructTag(hop.tokenOut),
|
|
197
|
+
amount: new BigNumber(hop.tokenOutAmount).times(10 **
|
|
198
|
+
hop.pool.allTokens.find((t) => normalizeStructTag(t.address) ===
|
|
199
|
+
normalizeStructTag(hop.tokenOut)).decimal),
|
|
206
200
|
},
|
|
207
201
|
})),
|
|
208
202
|
})),
|
|
@@ -218,32 +212,32 @@ const getFlowXQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
218
212
|
amountIn: amountIn,
|
|
219
213
|
});
|
|
220
214
|
const standardizedQuote = {
|
|
221
|
-
id: (
|
|
215
|
+
id: uuidv4(),
|
|
222
216
|
provider: QuoteProvider.FLOWX,
|
|
223
217
|
in: {
|
|
224
218
|
coinType: tokenIn.coinType,
|
|
225
|
-
amount: new
|
|
219
|
+
amount: new BigNumber(quote.amountIn.toString()).div(10 ** tokenIn.decimals),
|
|
226
220
|
},
|
|
227
221
|
out: {
|
|
228
222
|
coinType: tokenOut.coinType,
|
|
229
|
-
amount: new
|
|
223
|
+
amount: new BigNumber(quote.amountOut.toString()).div(10 ** tokenOut.decimals),
|
|
230
224
|
},
|
|
231
225
|
routes: ((_a = quote.routes) !== null && _a !== void 0 ? _a : []).map((route, routeIndex) => ({
|
|
232
|
-
percent: new
|
|
226
|
+
percent: new BigNumber(route.amountIn.toString())
|
|
233
227
|
.div(quote.amountIn.toString())
|
|
234
228
|
.times(100),
|
|
235
229
|
path: route.paths.map((hop) => ({
|
|
236
|
-
id: (
|
|
230
|
+
id: uuidv4(),
|
|
237
231
|
poolId: hop.pool.id,
|
|
238
232
|
routeIndex,
|
|
239
233
|
provider: hop.protocol(),
|
|
240
234
|
in: {
|
|
241
|
-
coinType:
|
|
242
|
-
amount: new
|
|
235
|
+
coinType: normalizeStructTag(hop.input.coinType),
|
|
236
|
+
amount: new BigNumber(hop.amountIn.toString()),
|
|
243
237
|
},
|
|
244
238
|
out: {
|
|
245
|
-
coinType:
|
|
246
|
-
amount: new
|
|
239
|
+
coinType: normalizeStructTag(hop.output.coinType),
|
|
240
|
+
amount: new BigNumber(hop.amountOut.toString()),
|
|
247
241
|
},
|
|
248
242
|
})),
|
|
249
243
|
})),
|
|
@@ -251,7 +245,7 @@ const getFlowXQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
|
|
|
251
245
|
};
|
|
252
246
|
return standardizedQuote;
|
|
253
247
|
});
|
|
254
|
-
const getAggQuotes = (sdkMap, activeProviders, onGetAggQuote, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
248
|
+
export const getAggQuotes = (sdkMap, activeProviders, onGetAggQuote, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
255
249
|
const timeoutMs = 15000;
|
|
256
250
|
// Get quotes in parallel
|
|
257
251
|
// Aftermath
|
|
@@ -283,8 +277,7 @@ const getAggQuotes = (sdkMap, activeProviders, onGetAggQuote, tokenIn, tokenOut,
|
|
|
283
277
|
}))();
|
|
284
278
|
}
|
|
285
279
|
});
|
|
286
|
-
|
|
287
|
-
const getAggSortedQuotesAll = (sdkMap, activeProviders, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
280
|
+
export const getAggSortedQuotesAll = (sdkMap, activeProviders, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
281
|
const timeoutMs = 1500;
|
|
289
282
|
// Get quotes in parallel
|
|
290
283
|
const quotes = yield Promise.all([
|
|
@@ -306,4 +299,3 @@ const getAggSortedQuotesAll = (sdkMap, activeProviders, tokenIn, tokenOut, amoun
|
|
|
306
299
|
.sort((a, b) => +b.out.amount.minus(a.out.amount));
|
|
307
300
|
return sortedQuotes;
|
|
308
301
|
});
|
|
309
|
-
exports.getAggSortedQuotesAll = getAggSortedQuotesAll;
|
package/swap/transaction.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
|
|
2
2
|
import { AggregatorQuoter as FlowXAggregatorQuoter } from "@flowx-finance/sdk";
|
|
3
|
-
import {
|
|
3
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
4
4
|
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
5
5
|
import { Aftermath as AftermathSdk } from "aftermath-ts-sdk";
|
|
6
6
|
import { QuoteProvider, StandardizedQuote } from "./quote";
|
|
7
|
-
export declare const getSwapTransaction: (suiClient:
|
|
7
|
+
export declare const getSwapTransaction: (suiClient: SuiJsonRpcClient, address: string, quote: StandardizedQuote, slippagePercent: number, sdkMap: {
|
|
8
8
|
[QuoteProvider.AFTERMATH]: AftermathSdk;
|
|
9
9
|
[QuoteProvider.CETUS]: CetusSdk;
|
|
10
10
|
[QuoteProvider.FLOWX]: FlowXAggregatorQuoter;
|
package/swap/transaction.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const sui_fe_1 = require("@suilend/sui-fe");
|
|
16
|
-
const quote_1 = require("./quote");
|
|
10
|
+
import { BluefinXTx, buildTx as buildBluefin7kTransaction, } from "@bluefin-exchange/bluefin7k-aggregator-sdk/cjs";
|
|
11
|
+
import { Coin as FlowXCoin, Commission as FlowXCommission, CommissionType as FlowXCommissionType, TradeBuilder as FlowXTradeBuilder, } from "@flowx-finance/sdk";
|
|
12
|
+
import { getAllCoins, isSui, mergeAllCoins } from "@suilend/sui-fe";
|
|
13
|
+
import { QuoteProvider } from "./quote";
|
|
17
14
|
const getSwapTransactionWrapper = (provider, getSwapTransaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
15
|
console.log(`[getSwapTransactionWrapper] fetching transaction for ${provider} quote`);
|
|
19
16
|
try {
|
|
@@ -26,10 +23,10 @@ const getSwapTransactionWrapper = (provider, getSwapTransaction) => __awaiter(vo
|
|
|
26
23
|
throw err;
|
|
27
24
|
}
|
|
28
25
|
});
|
|
29
|
-
const getSwapTransaction = (suiClient, address, quote, slippagePercent, sdkMap, partnerIdMap, transaction, coinIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
if (quote.provider ===
|
|
31
|
-
return getSwapTransactionWrapper(
|
|
32
|
-
const { tx: transaction2, coinOutId: coinOut } = yield sdkMap[
|
|
26
|
+
export const getSwapTransaction = (suiClient, address, quote, slippagePercent, sdkMap, partnerIdMap, transaction, coinIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
if (quote.provider === QuoteProvider.AFTERMATH) {
|
|
28
|
+
return getSwapTransactionWrapper(QuoteProvider.AFTERMATH, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const { tx: transaction2, coinOutId: coinOut } = yield sdkMap[QuoteProvider.AFTERMATH]
|
|
33
30
|
.Router()
|
|
34
31
|
.addTransactionForCompleteTradeRoute({
|
|
35
32
|
tx: transaction,
|
|
@@ -38,64 +35,73 @@ const getSwapTransaction = (suiClient, address, quote, slippagePercent, sdkMap,
|
|
|
38
35
|
slippage: slippagePercent / 100,
|
|
39
36
|
coinInId: coinIn,
|
|
40
37
|
});
|
|
41
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
transaction: transaction2,
|
|
40
|
+
coinOut: coinOut,
|
|
41
|
+
};
|
|
42
42
|
}));
|
|
43
43
|
}
|
|
44
|
-
else if (quote.provider ===
|
|
45
|
-
return getSwapTransactionWrapper(
|
|
44
|
+
else if (quote.provider === QuoteProvider.CETUS) {
|
|
45
|
+
return getSwapTransactionWrapper(QuoteProvider.CETUS, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
if (!coinIn) {
|
|
47
|
-
const allCoinsIn = yield
|
|
48
|
-
const mergeCoinIn =
|
|
49
|
-
[coinIn] = transaction.splitCoins(
|
|
47
|
+
const allCoinsIn = yield getAllCoins(suiClient, address, quote.in.coinType);
|
|
48
|
+
const mergeCoinIn = mergeAllCoins(quote.in.coinType, transaction, allCoinsIn);
|
|
49
|
+
[coinIn] = transaction.splitCoins(isSui(quote.in.coinType)
|
|
50
50
|
? transaction.gas
|
|
51
51
|
: transaction.object(mergeCoinIn.coinObjectId), [BigInt(quote.quote.amountIn.toString())]);
|
|
52
52
|
}
|
|
53
|
-
const coinOut = yield sdkMap[
|
|
53
|
+
const coinOut = yield sdkMap[QuoteProvider.CETUS].routerSwap({
|
|
54
54
|
router: quote.quote,
|
|
55
55
|
inputCoin: coinIn,
|
|
56
56
|
slippage: slippagePercent / 100,
|
|
57
57
|
txb: transaction,
|
|
58
|
-
partner: partnerIdMap[
|
|
58
|
+
partner: partnerIdMap[QuoteProvider.CETUS],
|
|
59
59
|
});
|
|
60
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
transaction: transaction,
|
|
62
|
+
coinOut: coinOut,
|
|
63
|
+
};
|
|
61
64
|
}));
|
|
62
65
|
}
|
|
63
|
-
else if (quote.provider ===
|
|
64
|
-
return getSwapTransactionWrapper(
|
|
65
|
-
const { tx: transaction2, coinOut } = yield (
|
|
66
|
+
else if (quote.provider === QuoteProvider.BLUEFIN7K) {
|
|
67
|
+
return getSwapTransactionWrapper(QuoteProvider.BLUEFIN7K, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const { tx: transaction2, coinOut } = yield buildBluefin7kTransaction({
|
|
66
69
|
quoteResponse: quote.quote,
|
|
67
70
|
accountAddress: address,
|
|
68
71
|
slippage: slippagePercent / 100,
|
|
69
72
|
commission: {
|
|
70
|
-
partner: partnerIdMap[
|
|
73
|
+
partner: partnerIdMap[QuoteProvider.BLUEFIN7K],
|
|
71
74
|
commissionBps: 0,
|
|
72
75
|
},
|
|
73
76
|
extendTx: {
|
|
74
77
|
tx: transaction,
|
|
75
|
-
coinIn,
|
|
78
|
+
coinIn: coinIn,
|
|
76
79
|
},
|
|
77
80
|
});
|
|
78
|
-
if (transaction2 instanceof
|
|
81
|
+
if (transaction2 instanceof BluefinXTx) {
|
|
79
82
|
// BluefinXTx
|
|
80
83
|
throw new Error("BluefinXTx not supported");
|
|
81
84
|
}
|
|
82
85
|
else {
|
|
83
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
transaction: transaction2,
|
|
88
|
+
coinOut: coinOut,
|
|
89
|
+
};
|
|
84
90
|
}
|
|
85
91
|
}));
|
|
86
92
|
}
|
|
87
|
-
else if (quote.provider ===
|
|
88
|
-
return getSwapTransactionWrapper(
|
|
93
|
+
else if (quote.provider === QuoteProvider.FLOWX) {
|
|
94
|
+
return getSwapTransactionWrapper(QuoteProvider.FLOWX, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
95
|
if (!coinIn) {
|
|
90
|
-
const allCoinsIn = yield
|
|
91
|
-
const mergeCoinIn =
|
|
92
|
-
[coinIn] = transaction.splitCoins(
|
|
96
|
+
const allCoinsIn = yield getAllCoins(suiClient, address, quote.in.coinType);
|
|
97
|
+
const mergeCoinIn = mergeAllCoins(quote.in.coinType, transaction, allCoinsIn);
|
|
98
|
+
[coinIn] = transaction.splitCoins(isSui(quote.in.coinType)
|
|
93
99
|
? transaction.gas
|
|
94
100
|
: transaction.object(mergeCoinIn.coinObjectId), [BigInt(quote.quote.amountIn.toString())]);
|
|
95
101
|
}
|
|
96
|
-
const trade = new
|
|
102
|
+
const trade = new FlowXTradeBuilder("mainnet", quote.quote.routes)
|
|
97
103
|
.slippage((slippagePercent / 100) * 1e6)
|
|
98
|
-
.commission(new
|
|
104
|
+
.commission(new FlowXCommission(partnerIdMap[QuoteProvider.FLOWX], new FlowXCoin(quote.out.coinType), FlowXCommissionType.PERCENTAGE, 0, false))
|
|
99
105
|
.build();
|
|
100
106
|
const coinOut = yield trade.swap({
|
|
101
107
|
coinIn: coinIn,
|
|
@@ -108,4 +114,3 @@ const getSwapTransaction = (suiClient, address, quote, slippagePercent, sdkMap,
|
|
|
108
114
|
else
|
|
109
115
|
throw new Error("Unknown quote type");
|
|
110
116
|
});
|
|
111
|
-
exports.getSwapTransaction = getSwapTransaction;
|
package/utils/events.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiEvent, SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
2
2
|
type TypeName = {
|
|
3
3
|
name: string;
|
|
4
4
|
};
|
|
@@ -171,6 +171,6 @@ export declare class ObligationDataEvent extends TypedParamsSuiEvent<{
|
|
|
171
171
|
closable: boolean;
|
|
172
172
|
}> {
|
|
173
173
|
}
|
|
174
|
-
export declare function getEvents(client:
|
|
175
|
-
export declare function getRedeemEvent(client:
|
|
174
|
+
export declare function getEvents(client: SuiJsonRpcClient, digest: string): Promise<GenericSuilendEvent[]>;
|
|
175
|
+
export declare function getRedeemEvent(client: SuiJsonRpcClient, digest: string): Promise<RedeemEvent | null>;
|
|
176
176
|
export {};
|
package/utils/events.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,11 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
exports.ObligationDataEvent = exports.ClaimRewardEvent = exports.LiquidateEvent = exports.RepayEvent = exports.BorrowEvent = exports.WithdrawEvent = exports.DepositEvent = exports.RedeemEvent = exports.MintEvent = exports.ReserveAssetDataEvent = exports.InterestUpdateEvent = exports.GenericSuilendEvent = exports.SuilendTransactionModule = exports.SuilendEventType = void 0;
|
|
13
|
-
exports.getEvents = getEvents;
|
|
14
|
-
exports.getRedeemEvent = getRedeemEvent;
|
|
15
|
-
var SuilendEventType;
|
|
10
|
+
export var SuilendEventType;
|
|
16
11
|
(function (SuilendEventType) {
|
|
17
12
|
SuilendEventType["InterestUpdateEvent"] = "InterestUpdateEvent";
|
|
18
13
|
SuilendEventType["ReserveAssetDataEvent"] = "ReserveAssetDataEvent";
|
|
@@ -25,12 +20,12 @@ var SuilendEventType;
|
|
|
25
20
|
SuilendEventType["LiquidateEvent"] = "LiquidateEvent";
|
|
26
21
|
SuilendEventType["ClaimRewardEvent"] = "ClaimRewardEvent";
|
|
27
22
|
SuilendEventType["ObligationDataEvent"] = "ObligationDataEvent";
|
|
28
|
-
})(SuilendEventType || (
|
|
29
|
-
var SuilendTransactionModule;
|
|
23
|
+
})(SuilendEventType || (SuilendEventType = {}));
|
|
24
|
+
export var SuilendTransactionModule;
|
|
30
25
|
(function (SuilendTransactionModule) {
|
|
31
26
|
SuilendTransactionModule["LendingMarket"] = "lending_market";
|
|
32
27
|
SuilendTransactionModule["Reserve"] = "reserve";
|
|
33
|
-
})(SuilendTransactionModule || (
|
|
28
|
+
})(SuilendTransactionModule || (SuilendTransactionModule = {}));
|
|
34
29
|
class TypedParamsSuiEvent {
|
|
35
30
|
constructor(event) {
|
|
36
31
|
this.event = event;
|
|
@@ -42,43 +37,31 @@ class TypedParamsSuiEvent {
|
|
|
42
37
|
return this.event.type.includes(`${module}::${eventType}`);
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
|
-
class GenericSuilendEvent extends TypedParamsSuiEvent {
|
|
40
|
+
export class GenericSuilendEvent extends TypedParamsSuiEvent {
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
class InterestUpdateEvent extends TypedParamsSuiEvent {
|
|
42
|
+
export class InterestUpdateEvent extends TypedParamsSuiEvent {
|
|
49
43
|
}
|
|
50
|
-
|
|
51
|
-
class ReserveAssetDataEvent extends TypedParamsSuiEvent {
|
|
44
|
+
export class ReserveAssetDataEvent extends TypedParamsSuiEvent {
|
|
52
45
|
}
|
|
53
|
-
|
|
54
|
-
class MintEvent extends TypedParamsSuiEvent {
|
|
46
|
+
export class MintEvent extends TypedParamsSuiEvent {
|
|
55
47
|
}
|
|
56
|
-
|
|
57
|
-
class RedeemEvent extends TypedParamsSuiEvent {
|
|
48
|
+
export class RedeemEvent extends TypedParamsSuiEvent {
|
|
58
49
|
}
|
|
59
|
-
|
|
60
|
-
class DepositEvent extends TypedParamsSuiEvent {
|
|
50
|
+
export class DepositEvent extends TypedParamsSuiEvent {
|
|
61
51
|
}
|
|
62
|
-
|
|
63
|
-
class WithdrawEvent extends TypedParamsSuiEvent {
|
|
52
|
+
export class WithdrawEvent extends TypedParamsSuiEvent {
|
|
64
53
|
}
|
|
65
|
-
|
|
66
|
-
class BorrowEvent extends TypedParamsSuiEvent {
|
|
54
|
+
export class BorrowEvent extends TypedParamsSuiEvent {
|
|
67
55
|
}
|
|
68
|
-
|
|
69
|
-
class RepayEvent extends TypedParamsSuiEvent {
|
|
56
|
+
export class RepayEvent extends TypedParamsSuiEvent {
|
|
70
57
|
}
|
|
71
|
-
|
|
72
|
-
class LiquidateEvent extends TypedParamsSuiEvent {
|
|
58
|
+
export class LiquidateEvent extends TypedParamsSuiEvent {
|
|
73
59
|
}
|
|
74
|
-
|
|
75
|
-
class ClaimRewardEvent extends TypedParamsSuiEvent {
|
|
60
|
+
export class ClaimRewardEvent extends TypedParamsSuiEvent {
|
|
76
61
|
}
|
|
77
|
-
|
|
78
|
-
class ObligationDataEvent extends TypedParamsSuiEvent {
|
|
62
|
+
export class ObligationDataEvent extends TypedParamsSuiEvent {
|
|
79
63
|
}
|
|
80
|
-
|
|
81
|
-
function getEvents(client, digest) {
|
|
64
|
+
export function getEvents(client, digest) {
|
|
82
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
66
|
const tx = yield client.getTransactionBlock({
|
|
84
67
|
digest,
|
|
@@ -91,7 +74,7 @@ function getEvents(client, digest) {
|
|
|
91
74
|
return events;
|
|
92
75
|
});
|
|
93
76
|
}
|
|
94
|
-
function getRedeemEvent(client, digest) {
|
|
77
|
+
export function getRedeemEvent(client, digest) {
|
|
95
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
79
|
const events = yield getEvents(client, digest);
|
|
97
80
|
for (const event of events) {
|