@suilend/sdk 3.0.3 → 3.0.5
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.js +4 -4
- package/_generated/_dependencies/source/0x1/option/structs.js +4 -4
- package/_generated/_dependencies/source/0x1/type-name/structs.js +4 -4
- package/_generated/_dependencies/source/0x2/bag/structs.js +4 -4
- package/_generated/_dependencies/source/0x2/balance/structs.js +3 -3
- package/_generated/_dependencies/source/0x2/object/structs.js +3 -3
- package/_generated/_dependencies/source/0x2/object-table/structs.js +4 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +3 -3
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +4 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +5 -5
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +4 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +5 -5
- package/_generated/_framework/reified.js +2 -2
- package/_generated/_framework/vector.js +2 -2
- package/_generated/suilend/cell/structs.js +4 -4
- package/_generated/suilend/decimal/structs.js +3 -3
- package/_generated/suilend/lending-market/functions.js +4 -4
- package/_generated/suilend/lending-market/structs.js +11 -11
- package/_generated/suilend/lending-market-registry/functions.js +2 -2
- package/_generated/suilend/liquidity-mining/structs.js +9 -9
- package/_generated/suilend/obligation/structs.js +8 -8
- package/_generated/suilend/rate-limiter/functions.js +2 -2
- package/_generated/suilend/rate-limiter/structs.js +4 -4
- package/_generated/suilend/reserve/structs.js +12 -12
- package/_generated/suilend/reserve-config/functions.js +2 -2
- package/_generated/suilend/reserve-config/structs.js +5 -5
- package/api/index.js +1 -1
- package/client.js +32 -50
- package/index.js +7 -7
- package/lib/index.js +5 -5
- package/lib/initialize.js +8 -8
- package/lib/liquidityMining.js +3 -3
- package/lib/pythAdapter.d.ts +1 -2
- package/lib/pythAdapter.js +96 -17
- package/lib/strategyOwnerCap.js +2 -2
- package/margin/margin/admin_cap.d.ts +1 -4
- package/margin/margin/admin_cap.js +15 -9
- package/margin/margin/deps/std/type_name.d.ts +9 -10
- package/margin/margin/deps/std/type_name.js +17 -14
- package/margin/margin/deps/sui/vec_set.d.ts +3 -5
- package/margin/margin/deps/sui/vec_set.js +9 -6
- package/margin/margin/deps/suilend/lending_market.d.ts +1 -4
- package/margin/margin/deps/suilend/lending_market.js +9 -6
- package/margin/margin/market.d.ts +22 -67
- package/margin/margin/market.js +86 -108
- package/margin/margin/permissions.d.ts +9 -16
- package/margin/margin/permissions.js +29 -29
- package/margin/margin/position.d.ts +12 -35
- package/margin/margin/position.js +84 -67
- package/margin/margin/router.d.ts +10 -50
- package/margin/margin/router.js +102 -71
- package/margin/margin/version.d.ts +1 -4
- package/margin/margin/version.js +7 -4
- package/margin/utils/index.d.ts +9 -9
- package/margin/utils/index.js +32 -29
- package/package.json +1 -1
- package/parsers/apiReserveAssetDataEvent.js +1 -1
- package/parsers/index.js +5 -5
- package/parsers/lendingMarket.js +2 -2
- package/parsers/obligation.js +1 -1
- package/parsers/rateLimiter.js +1 -1
- package/parsers/reserve.js +3 -3
- package/strategies.js +101 -42
- package/swap/index.js +2 -2
- package/swap/transaction.js +5 -14
- package/utils/index.js +3 -3
- package/utils/obligation.js +39 -30
- package/utils/simulate.js +4 -4
package/margin/utils/index.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { BcsEnum, BcsStruct, BcsTuple, BcsType, TypeTag } from "@mysten/sui/bcs";
|
|
2
|
+
import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
|
|
3
|
+
import { TransactionArgument } from "@mysten/sui/transactions";
|
|
4
4
|
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
5
|
-
export interface GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude,
|
|
5
|
+
export interface GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, "content"> = {}> extends SuiClientTypes.GetObjectOptions<Include> {
|
|
6
6
|
client: ClientWithCoreApi;
|
|
7
7
|
}
|
|
8
|
-
export interface GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude,
|
|
8
|
+
export interface GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, "content"> = {}> extends SuiClientTypes.GetObjectsOptions<Include> {
|
|
9
9
|
client: ClientWithCoreApi;
|
|
10
10
|
}
|
|
11
11
|
export declare function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null;
|
|
12
12
|
export declare function normalizeMoveArguments(args: unknown[] | object, argTypes: readonly (string | null)[], parameterNames?: string[]): TransactionArgument[];
|
|
13
13
|
export declare class MoveStruct<T extends Record<string, BcsType<any>>, const Name extends string = string> extends BcsStruct<T, Name> {
|
|
14
|
-
get<Include extends Omit<SuiClientTypes.ObjectInclude,
|
|
14
|
+
get<Include extends Omit<SuiClientTypes.ObjectInclude, "content" | "json"> = {}>({ objectId, ...options }: GetOptions<Include>): Promise<SuiClientTypes.Object<Include & {
|
|
15
15
|
content: true;
|
|
16
16
|
json: true;
|
|
17
17
|
}> & {
|
|
18
|
-
json: BcsStruct<T>[
|
|
18
|
+
json: BcsStruct<T>["$inferType"];
|
|
19
19
|
}>;
|
|
20
|
-
getMany<Include extends Omit<SuiClientTypes.ObjectInclude,
|
|
20
|
+
getMany<Include extends Omit<SuiClientTypes.ObjectInclude, "content" | "json"> = {}>({ client, ...options }: GetManyOptions<Include>): Promise<Array<SuiClientTypes.Object<Include & {
|
|
21
21
|
content: true;
|
|
22
22
|
json: true;
|
|
23
23
|
}> & {
|
|
24
|
-
json: BcsStruct<T>[
|
|
24
|
+
json: BcsStruct<T>["$inferType"];
|
|
25
25
|
}>>;
|
|
26
26
|
}
|
|
27
27
|
export declare class MoveEnum<T extends Record<string, BcsType<any> | null>, const Name extends string> extends BcsEnum<T, Name> {
|
package/margin/utils/index.js
CHANGED
|
@@ -18,57 +18,60 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
import { isArgument } from
|
|
24
|
-
|
|
25
|
-
const
|
|
21
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
22
|
+
import { BcsEnum, BcsStruct, BcsTuple, TypeTagSerializer, bcs, } from "@mysten/sui/bcs";
|
|
23
|
+
import { isArgument } from "@mysten/sui/transactions";
|
|
24
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
25
|
+
const MOVE_STDLIB_ADDRESS = normalizeSuiAddress("0x1");
|
|
26
|
+
const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
|
|
26
27
|
export function getPureBcsSchema(typeTag) {
|
|
27
|
-
const parsedTag = typeof typeTag ===
|
|
28
|
-
|
|
28
|
+
const parsedTag = typeof typeTag === "string"
|
|
29
|
+
? TypeTagSerializer.parseFromStr(typeTag)
|
|
30
|
+
: typeTag;
|
|
31
|
+
if ("u8" in parsedTag) {
|
|
29
32
|
return bcs.U8;
|
|
30
33
|
}
|
|
31
|
-
else if (
|
|
34
|
+
else if ("u16" in parsedTag) {
|
|
32
35
|
return bcs.U16;
|
|
33
36
|
}
|
|
34
|
-
else if (
|
|
37
|
+
else if ("u32" in parsedTag) {
|
|
35
38
|
return bcs.U32;
|
|
36
39
|
}
|
|
37
|
-
else if (
|
|
40
|
+
else if ("u64" in parsedTag) {
|
|
38
41
|
return bcs.U64;
|
|
39
42
|
}
|
|
40
|
-
else if (
|
|
43
|
+
else if ("u128" in parsedTag) {
|
|
41
44
|
return bcs.U128;
|
|
42
45
|
}
|
|
43
|
-
else if (
|
|
46
|
+
else if ("u256" in parsedTag) {
|
|
44
47
|
return bcs.U256;
|
|
45
48
|
}
|
|
46
|
-
else if (
|
|
49
|
+
else if ("address" in parsedTag) {
|
|
47
50
|
return bcs.Address;
|
|
48
51
|
}
|
|
49
|
-
else if (
|
|
52
|
+
else if ("bool" in parsedTag) {
|
|
50
53
|
return bcs.Bool;
|
|
51
54
|
}
|
|
52
|
-
else if (
|
|
55
|
+
else if ("vector" in parsedTag) {
|
|
53
56
|
const type = getPureBcsSchema(parsedTag.vector);
|
|
54
57
|
return type ? bcs.vector(type) : null;
|
|
55
58
|
}
|
|
56
|
-
else if (
|
|
59
|
+
else if ("struct" in parsedTag) {
|
|
57
60
|
const structTag = parsedTag.struct;
|
|
58
61
|
const pkg = normalizeSuiAddress(structTag.address);
|
|
59
62
|
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
60
|
-
if ((structTag.module ===
|
|
61
|
-
structTag.name ===
|
|
63
|
+
if ((structTag.module === "ascii" || structTag.module === "string") &&
|
|
64
|
+
structTag.name === "String") {
|
|
62
65
|
return bcs.String;
|
|
63
66
|
}
|
|
64
|
-
if (structTag.module ===
|
|
67
|
+
if (structTag.module === "option" && structTag.name === "Option") {
|
|
65
68
|
const type = getPureBcsSchema(structTag.typeParams[0]);
|
|
66
69
|
return type ? bcs.option(type) : null;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
if (pkg === SUI_FRAMEWORK_ADDRESS &&
|
|
70
|
-
structTag.module ===
|
|
71
|
-
(structTag.name ===
|
|
73
|
+
structTag.module === "object" &&
|
|
74
|
+
(structTag.name === "ID" || structTag.name === "UID")) {
|
|
72
75
|
return bcs.Address;
|
|
73
76
|
}
|
|
74
77
|
}
|
|
@@ -82,19 +85,19 @@ export function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
82
85
|
const normalizedArgs = [];
|
|
83
86
|
let index = 0;
|
|
84
87
|
for (const [i, argType] of argTypes.entries()) {
|
|
85
|
-
if (argType ===
|
|
88
|
+
if (argType === "0x2::clock::Clock") {
|
|
86
89
|
normalizedArgs.push((tx) => tx.object.clock());
|
|
87
90
|
continue;
|
|
88
91
|
}
|
|
89
|
-
if (argType ===
|
|
92
|
+
if (argType === "0x2::random::Random") {
|
|
90
93
|
normalizedArgs.push((tx) => tx.object.random());
|
|
91
94
|
continue;
|
|
92
95
|
}
|
|
93
|
-
if (argType ===
|
|
96
|
+
if (argType === "0x2::deny_list::DenyList") {
|
|
94
97
|
normalizedArgs.push((tx) => tx.object.denyList());
|
|
95
98
|
continue;
|
|
96
99
|
}
|
|
97
|
-
if (argType ===
|
|
100
|
+
if (argType === "0x3::sui_system::SuiSystemState") {
|
|
98
101
|
normalizedArgs.push((tx) => tx.object.system());
|
|
99
102
|
continue;
|
|
100
103
|
}
|
|
@@ -116,7 +119,7 @@ export function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
index += 1;
|
|
119
|
-
if (typeof arg ===
|
|
122
|
+
if (typeof arg === "function" || isArgument(arg)) {
|
|
120
123
|
normalizedArgs.push(arg);
|
|
121
124
|
continue;
|
|
122
125
|
}
|
|
@@ -127,7 +130,7 @@ export function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
127
130
|
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
128
131
|
continue;
|
|
129
132
|
}
|
|
130
|
-
else if (typeof arg ===
|
|
133
|
+
else if (typeof arg === "string") {
|
|
131
134
|
normalizedArgs.push((tx) => tx.object(arg));
|
|
132
135
|
continue;
|
|
133
136
|
}
|
|
@@ -161,10 +164,10 @@ export class MoveEnum extends BcsEnum {
|
|
|
161
164
|
export class MoveTuple extends BcsTuple {
|
|
162
165
|
}
|
|
163
166
|
function stringify(val) {
|
|
164
|
-
if (typeof val ===
|
|
167
|
+
if (typeof val === "object") {
|
|
165
168
|
return JSON.stringify(val, (val) => val);
|
|
166
169
|
}
|
|
167
|
-
if (typeof val ===
|
|
170
|
+
if (typeof val === "bigint") {
|
|
168
171
|
return val.toString();
|
|
169
172
|
}
|
|
170
173
|
return val;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"3.0.
|
|
1
|
+
{"name":"@suilend/sdk","version":"3.0.5","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./mmt":"./mmt.js","./strategies":"./strategies.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers/obligation":"./parsers/obligation.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap/transaction":"./swap/transaction.js","./swap/quote":"./swap/quote.js","./swap":"./swap/index.js","./utils/simulate":"./utils/simulate.js","./utils/events":"./utils/events.js","./utils/obligation":"./utils/obligation.js","./utils":"./utils/index.js","./lib/constants":"./lib/constants.js","./lib/pythAdapter":"./lib/pythAdapter.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./lib/initialize":"./lib/initialize.js","./lib":"./lib/index.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/strategyOwnerCap":"./lib/strategyOwnerCap.js","./lib/pyth":"./lib/pyth.js","./api/events":"./api/events.js","./api":"./api/index.js","./margin":"./margin/index.js","./margin/utils":"./margin/utils/index.js","./margin/margin/market":"./margin/margin/market.js","./margin/margin/version":"./margin/margin/version.js","./margin/margin/router":"./margin/margin/router.js","./margin/margin/admin_cap":"./margin/margin/admin_cap.js","./margin/margin/permissions":"./margin/margin/permissions.js","./margin/margin/position":"./margin/margin/position.js","./_generated/suilend":"./_generated/suilend/index.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./margin/margin/deps/sui/vec_set":"./margin/margin/deps/sui/vec_set.js","./margin/margin/deps/std/type_name":"./margin/margin/deps/std/type_name.js","./margin/margin/deps/suilend/lending_market":"./margin/margin/deps/suilend/lending_market.js","./_generated/_dependencies/source/0x2":"./_generated/_dependencies/source/0x2/index.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js","./_generated/_dependencies/source/0x1":"./_generated/_dependencies/source/0x1/index.js","./_generated/_dependencies/source/0x2/object-table/structs":"./_generated/_dependencies/source/0x2/object-table/structs.js","./_generated/_dependencies/source/0x2/balance/structs":"./_generated/_dependencies/source/0x2/balance/structs.js","./_generated/_dependencies/source/0x2/object/structs":"./_generated/_dependencies/source/0x2/object/structs.js","./_generated/_dependencies/source/0x2/bag/structs":"./_generated/_dependencies/source/0x2/bag/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js","./_generated/_dependencies/source/0x1/ascii/structs":"./_generated/_dependencies/source/0x1/ascii/structs.js","./_generated/_dependencies/source/0x1/option/structs":"./_generated/_dependencies/source/0x1/option/structs.js","./_generated/_dependencies/source/0x1/type-name/structs":"./_generated/_dependencies/source/0x1/type-name/structs.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc && node ./fix-esm-imports.js","eslint":"eslint --fix src/","prettier":"prettier --write src/","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/suilend-fe-public.git"},"bugs":{"url":"https://github.com/suilend/suilend-fe-public/issues"},"dependencies":{"@bluefin-exchange/bluefin7k-aggregator-sdk":"^7.3.0","@cetusprotocol/aggregator-sdk":"^1.5.7","@flowx-finance/sdk":"^2.1.0","@suilend/springsui-sdk":"^3.0.4","bignumber.js":"^9.1.2","bn.js":"^5.2.2","crypto-js":"^4.2.0","lodash":"^4.17.21","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"@types/bn.js":"^5.2.0","@types/lodash":"^4.17.20","ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"2.0.1","@mysten/sui":"2.17.0","@suilend/sui-fe":"^3.0.14","@pythnetwork/pyth-sui-js":"2.2.0"},"overrides":{"chalk":"5.3.0","strip-ansi":"7.1.0","color-convert":"2.0.1","color-name":"1.1.4","is-core-module":"2.13.1","error-ex":"1.3.2","has-ansi":"5.0.1","axios":"<=1.11.0"},"type":"module"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
import { WAD } from "../lib/constants";
|
|
3
|
+
import { WAD } from "../lib/constants.js";
|
|
4
4
|
export const parseReserveAssetDataEvent = (event, reserve) => {
|
|
5
5
|
const availableAmount = new BigNumber(event.availableAmount)
|
|
6
6
|
.div(WAD)
|
package/parsers/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./apiReserveAssetDataEvent";
|
|
2
|
-
export * from "./lendingMarket";
|
|
3
|
-
export * from "./obligation";
|
|
4
|
-
export * from "./rateLimiter";
|
|
5
|
-
export * from "./reserve";
|
|
1
|
+
export * from "./apiReserveAssetDataEvent.js";
|
|
2
|
+
export * from "./lendingMarket.js";
|
|
3
|
+
export * from "./obligation.js";
|
|
4
|
+
export * from "./rateLimiter.js";
|
|
5
|
+
export * from "./reserve.js";
|
package/parsers/lendingMarket.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import { parseRateLimiter } from "./rateLimiter";
|
|
3
|
-
import { parseReserve } from "./reserve";
|
|
2
|
+
import { parseRateLimiter } from "./rateLimiter.js";
|
|
3
|
+
import { parseReserve } from "./reserve.js";
|
|
4
4
|
export const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS, lendingMarketMetadata) => {
|
|
5
5
|
var _a, _b, _c;
|
|
6
6
|
const id = lendingMarket.id;
|
package/parsers/obligation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
import { WAD } from "../lib/constants";
|
|
3
|
+
import { WAD } from "../lib/constants.js";
|
|
4
4
|
export const parseObligation = (obligation, parsedReserveMap, isStrategy) => {
|
|
5
5
|
let totalDepositedAmountUsd = new BigNumber(0);
|
|
6
6
|
let totalBorrowedAmountUsd = new BigNumber(0);
|
package/parsers/rateLimiter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import { WAD } from "../lib/constants";
|
|
2
|
+
import { WAD } from "../lib/constants.js";
|
|
3
3
|
export const parseRateLimiter = (rateLimiter, nowS) => {
|
|
4
4
|
const config = parseRateLimiterConfig(rateLimiter);
|
|
5
5
|
const $typeName = rateLimiter.$typeName;
|
package/parsers/reserve.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import { WAD } from "../lib/constants";
|
|
5
|
-
import { toHexString } from "../utils";
|
|
6
|
-
import * as simulate from "../utils/simulate";
|
|
4
|
+
import { WAD } from "../lib/constants.js";
|
|
5
|
+
import { toHexString } from "../utils/index.js";
|
|
6
|
+
import * as simulate from "../utils/simulate.js";
|
|
7
7
|
export const parseReserve = (reserve, coinMetadataMap) => {
|
|
8
8
|
const config = parseReserveConfig(reserve);
|
|
9
9
|
const $typeName = reserve.$typeName;
|
package/strategies.js
CHANGED
|
@@ -12,14 +12,14 @@ import { Transaction, } from "@mysten/sui/transactions";
|
|
|
12
12
|
import { SUI_DECIMALS } from "@mysten/sui/utils";
|
|
13
13
|
import BigNumber from "bignumber.js";
|
|
14
14
|
import { BN } from "bn.js";
|
|
15
|
-
import
|
|
15
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
16
16
|
import { LstClient, SPRING_SUI_UPGRADE_CAP_ID, getLatestPackageId as getLatestSpringSuiPackageId, } from "@suilend/springsui-sdk";
|
|
17
|
-
import { API_URL, MAX_U64, MS_PER_YEAR, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE,
|
|
18
|
-
import { getNetAprPercent } from "./lib";
|
|
19
|
-
import { getRewardsMap } from "./lib/liquidityMining";
|
|
20
|
-
import { STRATEGY_TYPE_INFO_MAP, StrategyType, strategyBorrow, strategyClaimRewardsAndMergeCoins, strategyDeposit, strategyWithdraw, } from "./lib/strategyOwnerCap";
|
|
21
|
-
import { MMT_CONTRACT_PACKAGE_ID, MMT_VERSION_OBJECT_ID } from "./mmt";
|
|
22
|
-
import { getWeightedBorrowsUsd } from "./utils";
|
|
17
|
+
import { API_URL, MAX_U64, MS_PER_YEAR, NORMALIZED_AUSD_COINTYPE, NORMALIZED_SUI_COINTYPE, NORMALIZED_USDC_COINTYPE, NORMALIZED_sSUI_COINTYPE, NORMALIZED_suiUSDT_COINTYPE, NORMALIZED_suiWBTC_COINTYPE, NORMALIZED_xBTC_COINTYPE, getSpendableCoin, isSui, } from "@suilend/sui-fe";
|
|
18
|
+
import { getNetAprPercent } from "./lib/index.js";
|
|
19
|
+
import { getRewardsMap } from "./lib/liquidityMining.js";
|
|
20
|
+
import { STRATEGY_TYPE_INFO_MAP, StrategyType, strategyBorrow, strategyClaimRewardsAndMergeCoins, strategyDeposit, strategyWithdraw, } from "./lib/strategyOwnerCap.js";
|
|
21
|
+
import { MMT_CONTRACT_PACKAGE_ID, MMT_VERSION_OBJECT_ID } from "./mmt.js";
|
|
22
|
+
import { getWeightedBorrowsUsd } from "./utils/index.js";
|
|
23
23
|
export const STRATEGY_E = 10 ** -7;
|
|
24
24
|
export const LST_DECIMALS = 9;
|
|
25
25
|
export var StrategyFlashLoanProvider;
|
|
@@ -48,7 +48,7 @@ export const STRATEGY_TYPE_FLASH_LOAN_OBJ_MAP = {
|
|
|
48
48
|
poolId: "0x737ec6a4d3ed0c7e6cc18d8ba04e7ffd4806b726c97efd89867597368c4d06a9", // suiUSDT-USDC 0.001% https://app.mmt.finance/liquidity/0x737ec6a4d3ed0c7e6cc18d8ba04e7ffd4806b726c97efd89867597368c4d06a9
|
|
49
49
|
coinTypeA: NORMALIZED_suiUSDT_COINTYPE,
|
|
50
50
|
coinTypeB: NORMALIZED_USDC_COINTYPE,
|
|
51
|
-
borrowA: false,
|
|
51
|
+
borrowA: false, // Requires swap from USDT to USDsui
|
|
52
52
|
feePercent: 0.001,
|
|
53
53
|
},
|
|
54
54
|
[StrategyType.eEARN_USDC_LOOPING]: {
|
|
@@ -56,7 +56,7 @@ export const STRATEGY_TYPE_FLASH_LOAN_OBJ_MAP = {
|
|
|
56
56
|
poolId: "0x737ec6a4d3ed0c7e6cc18d8ba04e7ffd4806b726c97efd89867597368c4d06a9", // suiUSDT-USDC 0.001% https://app.mmt.finance/liquidity/0x737ec6a4d3ed0c7e6cc18d8ba04e7ffd4806b726c97efd89867597368c4d06a9
|
|
57
57
|
coinTypeA: NORMALIZED_suiUSDT_COINTYPE,
|
|
58
58
|
coinTypeB: NORMALIZED_USDC_COINTYPE,
|
|
59
|
-
borrowA: false,
|
|
59
|
+
borrowA: false, // Requires swap from USDC to eEARN
|
|
60
60
|
feePercent: 0.001,
|
|
61
61
|
},
|
|
62
62
|
[StrategyType.AUSD_sSUI_SUI_LOOPING]: {
|
|
@@ -1776,14 +1776,10 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
1776
1776
|
// 1.2) LST
|
|
1777
1777
|
else if (deposit.coinType === ((_c = depositReserves.lst) === null || _c === void 0 ? void 0 : _c.coinType)) {
|
|
1778
1778
|
// 1.2.1) Split coins
|
|
1779
|
-
const
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
.times(10 ** LST_DECIMALS)
|
|
1784
|
-
.integerValue(BigNumber.ROUND_DOWN)
|
|
1785
|
-
.toString()),
|
|
1786
|
-
]);
|
|
1779
|
+
const lstCoin = yield getSpendableCoin(suiGrpcClient, _address, depositReserves.lst.coinType, deposit.depositedAmount
|
|
1780
|
+
.times(10 ** LST_DECIMALS)
|
|
1781
|
+
.integerValue(BigNumber.ROUND_DOWN)
|
|
1782
|
+
.toString(), transaction);
|
|
1787
1783
|
// 1.2.2) Deposit LST (1x exposure)
|
|
1788
1784
|
strategyDeposit(strategyType, lstCoin, depositReserves.lst.coinType, strategyOwnerCapId, suilendClient.findReserveArrayIndex(depositReserves.lst.coinType), transaction);
|
|
1789
1785
|
// 1.2.3) Update state
|
|
@@ -1793,14 +1789,10 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
1793
1789
|
else {
|
|
1794
1790
|
const otherReserve = reserveMap[deposit.coinType];
|
|
1795
1791
|
// 1.3.1) Split coins
|
|
1796
|
-
const
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
.times(10 ** otherReserve.token.decimals)
|
|
1801
|
-
.integerValue(BigNumber.ROUND_DOWN)
|
|
1802
|
-
.toString()),
|
|
1803
|
-
]);
|
|
1792
|
+
const otherCoin = yield getSpendableCoin(suiGrpcClient, _address, otherReserve.coinType, deposit.depositedAmount
|
|
1793
|
+
.times(10 ** otherReserve.token.decimals)
|
|
1794
|
+
.integerValue(BigNumber.ROUND_DOWN)
|
|
1795
|
+
.toString(), transaction);
|
|
1804
1796
|
// 1.3.2) If the deposit coin is the same as the borrow coin, swap to base first
|
|
1805
1797
|
if (deposit.coinType === borrowReserve.coinType && depositReserve) {
|
|
1806
1798
|
const routers = yield cetusSdk.findRouters({
|
|
@@ -2359,7 +2351,7 @@ export const strategyDepositAdjustWithdrawTx = (
|
|
|
2359
2351
|
reserveMap,
|
|
2360
2352
|
// Strategy
|
|
2361
2353
|
lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, _deposits, _borrowedAmount, flashLoanBorrowedAmount, transaction, dryRunTransaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2362
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
2354
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
2363
2355
|
const strategyInfo = STRATEGY_TYPE_INFO_MAP[strategyType];
|
|
2364
2356
|
const lst = strategyInfo.depositLstCoinType !== undefined
|
|
2365
2357
|
? lstMap[strategyInfo.depositLstCoinType]
|
|
@@ -2385,12 +2377,23 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2385
2377
|
let borrowedAmount = _borrowedAmount;
|
|
2386
2378
|
// 1) Flash loan base/LST
|
|
2387
2379
|
const flashLoanObj = STRATEGY_TYPE_FLASH_LOAN_OBJ_MAP[strategyType];
|
|
2388
|
-
|
|
2380
|
+
const flashLoanCoinType = flashLoanObj.borrowA
|
|
2381
|
+
? flashLoanObj.coinTypeA
|
|
2382
|
+
: flashLoanObj.coinTypeB;
|
|
2383
|
+
const flashLoanCoinReserve = (_b = reserveMap[flashLoanCoinType]) !== null && _b !== void 0 ? _b : depositReserve;
|
|
2384
|
+
const needsFlashLoanCoinSwap = flashLoanCoinType !== depositReserve.coinType;
|
|
2385
|
+
if (depositReserve.coinType === ((_c = depositReserves.lst) === null || _c === void 0 ? void 0 : _c.coinType)) {
|
|
2389
2386
|
// TODO: Account for LST mint fees
|
|
2390
2387
|
flashLoanBorrowedAmount = flashLoanBorrowedAmount
|
|
2391
|
-
.times((
|
|
2388
|
+
.times((_d = lst === null || lst === void 0 ? void 0 : lst.lstToSuiExchangeRate) !== null && _d !== void 0 ? _d : 1)
|
|
2392
2389
|
.decimalPlaces(SUI_DECIMALS, BigNumber.ROUND_UP);
|
|
2393
2390
|
}
|
|
2391
|
+
let flashLoanBorrowAmountForLoan = flashLoanBorrowedAmount;
|
|
2392
|
+
if (needsFlashLoanCoinSwap) {
|
|
2393
|
+
flashLoanBorrowAmountForLoan = flashLoanBorrowAmountForLoan
|
|
2394
|
+
.times(1.01) // Buffer for swap slippage
|
|
2395
|
+
.decimalPlaces(flashLoanCoinReserve.token.decimals, BigNumber.ROUND_UP);
|
|
2396
|
+
}
|
|
2394
2397
|
let borrowedBalanceA, borrowedBalanceB, receipt;
|
|
2395
2398
|
if (flashLoanObj.provider === StrategyFlashLoanProvider.MMT) {
|
|
2396
2399
|
[borrowedBalanceA, borrowedBalanceB, receipt] = transaction.moveCall({
|
|
@@ -2399,9 +2402,9 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2399
2402
|
arguments: [
|
|
2400
2403
|
transaction.object(flashLoanObj.poolId),
|
|
2401
2404
|
transaction.pure.u64(flashLoanObj.borrowA
|
|
2402
|
-
?
|
|
2405
|
+
? flashLoanBorrowAmountForLoan
|
|
2403
2406
|
.times(10 **
|
|
2404
|
-
(depositReserve.coinType === ((
|
|
2407
|
+
(depositReserve.coinType === ((_e = depositReserves.lst) === null || _e === void 0 ? void 0 : _e.coinType)
|
|
2405
2408
|
? SUI_DECIMALS
|
|
2406
2409
|
: depositReserve.token.decimals))
|
|
2407
2410
|
.integerValue(BigNumber.ROUND_DOWN)
|
|
@@ -2409,11 +2412,11 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2409
2412
|
: 0),
|
|
2410
2413
|
transaction.pure.u64(flashLoanObj.borrowA
|
|
2411
2414
|
? 0
|
|
2412
|
-
:
|
|
2415
|
+
: flashLoanBorrowAmountForLoan
|
|
2413
2416
|
.times(10 **
|
|
2414
|
-
(depositReserve.coinType === ((
|
|
2417
|
+
(depositReserve.coinType === ((_f = depositReserves.lst) === null || _f === void 0 ? void 0 : _f.coinType)
|
|
2415
2418
|
? SUI_DECIMALS
|
|
2416
|
-
:
|
|
2419
|
+
: flashLoanCoinReserve.token.decimals))
|
|
2417
2420
|
.integerValue(BigNumber.ROUND_DOWN)
|
|
2418
2421
|
.toString()),
|
|
2419
2422
|
transaction.object(MMT_VERSION_OBJECT_ID),
|
|
@@ -2426,9 +2429,9 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2426
2429
|
// 2) Deposit additional (to get back up to 100% health, so the user can then unloop back down to the max leverage shown in the UI)
|
|
2427
2430
|
// 2.1) Deposit
|
|
2428
2431
|
let depositedAmount = flashLoanBorrowedAmount;
|
|
2429
|
-
if (depositReserve.coinType === ((
|
|
2432
|
+
if (depositReserve.coinType === ((_g = depositReserves.lst) === null || _g === void 0 ? void 0 : _g.coinType))
|
|
2430
2433
|
depositedAmount = new BigNumber(depositedAmount.minus(getStrategyLstMintFee(lstMap, depositReserve.coinType, depositedAmount)))
|
|
2431
|
-
.times((
|
|
2434
|
+
.times((_h = lst === null || lst === void 0 ? void 0 : lst.suiToLstExchangeRate) !== null && _h !== void 0 ? _h : 1)
|
|
2432
2435
|
.decimalPlaces(depositReserve.token.decimals, BigNumber.ROUND_DOWN);
|
|
2433
2436
|
let flashLoanBorrowedCoin = transaction.moveCall({
|
|
2434
2437
|
target: "0x2::coin::from_balance",
|
|
@@ -2437,8 +2440,34 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2437
2440
|
],
|
|
2438
2441
|
arguments: [flashLoanObj.borrowA ? borrowedBalanceA : borrowedBalanceB],
|
|
2439
2442
|
});
|
|
2440
|
-
if (depositReserve.coinType === ((
|
|
2443
|
+
if (depositReserve.coinType === ((_j = depositReserves.lst) === null || _j === void 0 ? void 0 : _j.coinType))
|
|
2441
2444
|
flashLoanBorrowedCoin = lst.client.mint(transaction, flashLoanBorrowedCoin);
|
|
2445
|
+
if (needsFlashLoanCoinSwap) {
|
|
2446
|
+
const depositRouters = yield cetusSdk.findRouters({
|
|
2447
|
+
from: flashLoanCoinType,
|
|
2448
|
+
target: depositReserve.coinType,
|
|
2449
|
+
amount: new BN(flashLoanBorrowAmountForLoan
|
|
2450
|
+
.times(10 ** flashLoanCoinReserve.token.decimals)
|
|
2451
|
+
.integerValue(BigNumber.ROUND_DOWN)
|
|
2452
|
+
.toString()),
|
|
2453
|
+
byAmountIn: true,
|
|
2454
|
+
splitCount: 0,
|
|
2455
|
+
});
|
|
2456
|
+
if (!depositRouters)
|
|
2457
|
+
throw new Error("No swap quote found");
|
|
2458
|
+
try {
|
|
2459
|
+
flashLoanBorrowedCoin = (yield cetusSdk.fixableRouterSwapV3({
|
|
2460
|
+
router: depositRouters,
|
|
2461
|
+
inputCoin: flashLoanBorrowedCoin,
|
|
2462
|
+
slippage: 1 / 100,
|
|
2463
|
+
txb: transaction,
|
|
2464
|
+
partner: cetusPartnerId,
|
|
2465
|
+
}));
|
|
2466
|
+
}
|
|
2467
|
+
catch (err) {
|
|
2468
|
+
throw new Error("No swap quote found");
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2442
2471
|
strategyDeposit(strategyType, flashLoanBorrowedCoin, depositReserve.coinType, strategyOwnerCapId, suilendClient.findReserveArrayIndex(depositReserve.coinType), transaction);
|
|
2443
2472
|
// 2.2) Update state
|
|
2444
2473
|
deposits = addOrInsertStrategyDeposit(deposits, {
|
|
@@ -2463,14 +2492,18 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2463
2492
|
const dryRunResults = yield dryRunTransaction(transaction);
|
|
2464
2493
|
const flashLoanRepayAmount = new BigNumber(bcs
|
|
2465
2494
|
.u64()
|
|
2466
|
-
.parse((_o = (_m = (_l = (_k =
|
|
2467
|
-
.div(10 **
|
|
2468
|
-
.decimalPlaces(
|
|
2495
|
+
.parse((_p = (_o = (_m = (_l = (_k = dryRunResults.commandResults) === null || _k === void 0 ? void 0 : _k[receiptDebts.Result]) === null || _l === void 0 ? void 0 : _l.returnValues) === null || _m === void 0 ? void 0 : _m[flashLoanObj.borrowA ? 0 : 1]) === null || _o === void 0 ? void 0 : _o.bcs) !== null && _p !== void 0 ? _p : new Uint8Array([0])))
|
|
2496
|
+
.div(10 ** flashLoanCoinReserve.token.decimals)
|
|
2497
|
+
.decimalPlaces(flashLoanCoinReserve.token.decimals, BigNumber.ROUND_UP);
|
|
2469
2498
|
// 4.1) Withdraw additional + fee
|
|
2470
2499
|
let withdrawnAmount = flashLoanRepayAmount;
|
|
2471
|
-
if (
|
|
2500
|
+
if (needsFlashLoanCoinSwap)
|
|
2501
|
+
withdrawnAmount = flashLoanRepayAmount
|
|
2502
|
+
.times(1.01) // Buffer for swap slippage
|
|
2503
|
+
.decimalPlaces(depositReserve.token.decimals, BigNumber.ROUND_UP);
|
|
2504
|
+
else if (depositReserve.coinType === ((_q = depositReserves.lst) === null || _q === void 0 ? void 0 : _q.coinType))
|
|
2472
2505
|
withdrawnAmount = withdrawnAmount
|
|
2473
|
-
.div(1 - +((
|
|
2506
|
+
.div(1 - +((_r = lst === null || lst === void 0 ? void 0 : lst.redeemFeePercent) !== null && _r !== void 0 ? _r : 0) / 100) // Potential rounding issue (max 1 MIST)
|
|
2474
2507
|
.decimalPlaces(depositReserve.token.decimals, BigNumber.ROUND_UP);
|
|
2475
2508
|
const { deposits: newDeposits2, borrowedAmount: newBorrowedAmount2, transaction: newTransaction2, withdrawnCoin, } = yield strategyWithdrawTx(reserveMap, lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _address, strategyOwnerCapId, obligationId, deposits, borrowedAmount, {
|
|
2476
2509
|
coinType: depositReserve.coinType,
|
|
@@ -2484,8 +2517,34 @@ lstMap, strategyType, suiGrpcClient, suilendClient, cetusSdk, cetusPartnerId, _a
|
|
|
2484
2517
|
transaction = newTransaction2;
|
|
2485
2518
|
// 4.3) Repay flash loan
|
|
2486
2519
|
let flashLoanRepayCoin = withdrawnCoin;
|
|
2487
|
-
if (depositReserve.coinType === ((
|
|
2520
|
+
if (depositReserve.coinType === ((_s = depositReserves.lst) === null || _s === void 0 ? void 0 : _s.coinType))
|
|
2488
2521
|
flashLoanRepayCoin = lst.client.redeem(transaction, flashLoanRepayCoin);
|
|
2522
|
+
if (needsFlashLoanCoinSwap) {
|
|
2523
|
+
const repayRouters = yield cetusSdk.findRouters({
|
|
2524
|
+
from: depositReserve.coinType,
|
|
2525
|
+
target: flashLoanCoinType,
|
|
2526
|
+
amount: new BN(withdrawnAmount
|
|
2527
|
+
.times(10 ** depositReserve.token.decimals)
|
|
2528
|
+
.integerValue(BigNumber.ROUND_DOWN)
|
|
2529
|
+
.toString()),
|
|
2530
|
+
byAmountIn: true,
|
|
2531
|
+
splitCount: 0,
|
|
2532
|
+
});
|
|
2533
|
+
if (!repayRouters)
|
|
2534
|
+
throw new Error("No swap quote found");
|
|
2535
|
+
try {
|
|
2536
|
+
flashLoanRepayCoin = (yield cetusSdk.fixableRouterSwapV3({
|
|
2537
|
+
router: repayRouters,
|
|
2538
|
+
inputCoin: flashLoanRepayCoin,
|
|
2539
|
+
slippage: 1 / 100,
|
|
2540
|
+
txb: transaction,
|
|
2541
|
+
partner: cetusPartnerId,
|
|
2542
|
+
}));
|
|
2543
|
+
}
|
|
2544
|
+
catch (err) {
|
|
2545
|
+
throw new Error("No swap quote found");
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2489
2548
|
const flashLoanRepayBalance = transaction.moveCall({
|
|
2490
2549
|
target: "0x2::coin::into_balance",
|
|
2491
2550
|
typeArguments: [
|
package/swap/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./quote";
|
|
2
|
-
export * from "./transaction";
|
|
1
|
+
export * from "./quote.js";
|
|
2
|
+
export * from "./transaction.js";
|
package/swap/transaction.js
CHANGED
|
@@ -9,9 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { BluefinXTx, buildTx as buildBluefin7kTransaction, } from "@bluefin-exchange/bluefin7k-aggregator-sdk";
|
|
11
11
|
import { Coin as FlowXCoin, Commission as FlowXCommission, CommissionType as FlowXCommissionType, TradeBuilder as FlowXTradeBuilder, } from "@flowx-finance/sdk";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { QuoteProvider } from "./quote";
|
|
12
|
+
import { getSpendableCoin } from "@suilend/sui-fe";
|
|
13
|
+
import { QuoteProvider } from "./quote.js";
|
|
15
14
|
const getSwapTransactionWrapper = (provider, getSwapTransaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
15
|
console.log(`[getSwapTransactionWrapper] fetching transaction for ${provider} quote`);
|
|
17
16
|
try {
|
|
@@ -28,11 +27,7 @@ export const getSwapTransaction = (suiGrpcClient, address, quote, slippagePercen
|
|
|
28
27
|
if (quote.provider === QuoteProvider.CETUS) {
|
|
29
28
|
return getSwapTransactionWrapper(QuoteProvider.CETUS, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
29
|
if (!coinIn) {
|
|
31
|
-
|
|
32
|
-
const mergeCoinIn = mergeAllCoins(quote.in.coinType, transaction, allCoinsIn);
|
|
33
|
-
[coinIn] = transaction.splitCoins(isSui(quote.in.coinType)
|
|
34
|
-
? transaction.gas
|
|
35
|
-
: transaction.object(mergeCoinIn.objectId), [BigInt(quote.quote.amountIn.toString())]);
|
|
30
|
+
coinIn = yield getSpendableCoin(suiGrpcClient, address, quote.in.coinType, quote.quote.amountIn.toString(), transaction);
|
|
36
31
|
}
|
|
37
32
|
const coinOut = yield sdkMap[QuoteProvider.CETUS].routerSwap({
|
|
38
33
|
router: quote.quote,
|
|
@@ -77,11 +72,7 @@ export const getSwapTransaction = (suiGrpcClient, address, quote, slippagePercen
|
|
|
77
72
|
else if (quote.provider === QuoteProvider.FLOWX) {
|
|
78
73
|
return getSwapTransactionWrapper(QuoteProvider.FLOWX, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
74
|
if (!coinIn) {
|
|
80
|
-
|
|
81
|
-
const mergeCoinIn = mergeAllCoins(quote.in.coinType, transaction, allCoinsIn);
|
|
82
|
-
[coinIn] = transaction.splitCoins(isSui(quote.in.coinType)
|
|
83
|
-
? transaction.gas
|
|
84
|
-
: transaction.object(mergeCoinIn.objectId), [BigInt(quote.quote.amountIn.toString())]);
|
|
75
|
+
coinIn = yield getSpendableCoin(suiGrpcClient, address, quote.in.coinType, quote.quote.amountIn.toString(), transaction);
|
|
85
76
|
}
|
|
86
77
|
const trade = new FlowXTradeBuilder("mainnet", quote.quote.routes)
|
|
87
78
|
.slippage((slippagePercent / 100) * 1e6)
|
|
@@ -89,7 +80,7 @@ export const getSwapTransaction = (suiGrpcClient, address, quote, slippagePercen
|
|
|
89
80
|
.build();
|
|
90
81
|
const coinOut = yield trade.swap({
|
|
91
82
|
coinIn: coinIn,
|
|
92
|
-
client:
|
|
83
|
+
client: suiGrpcClient,
|
|
93
84
|
tx: transaction,
|
|
94
85
|
});
|
|
95
86
|
return { transaction, coinOut: coinOut };
|
package/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
export * from "./events";
|
|
3
|
-
export * from "./obligation";
|
|
4
|
-
export * from "./simulate";
|
|
2
|
+
export * from "./events.js";
|
|
3
|
+
export * from "./obligation.js";
|
|
4
|
+
export * from "./simulate.js";
|
|
5
5
|
export const toHexString = (bytes) => Array.from(bytes, function (byte) {
|
|
6
6
|
return ("0" + (byte & 0xff).toString(16)).slice(-2);
|
|
7
7
|
}).join("");
|