@7kprotocol/sdk-ts 2.0.4 → 2.1.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/README.md +6 -4
- package/lib/cjs/buildTx.js +16 -29
- package/lib/cjs/constants/_7k.js +6 -4
- package/lib/cjs/estimateGasFee.js +3 -2
- package/lib/cjs/types/buildTx.d.ts +5 -2
- package/lib/cjs/types/buildTx.d.ts.map +1 -1
- package/lib/cjs/types/constants/_7k.d.ts +3 -2
- package/lib/cjs/types/constants/_7k.d.ts.map +1 -1
- package/lib/cjs/types/estimateGasFee.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +4 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/types/tx.d.ts +1 -1
- package/lib/cjs/types/types/tx.d.ts.map +1 -1
- package/lib/esm/buildTx.js +17 -30
- package/lib/esm/constants/_7k.js +5 -3
- package/lib/esm/estimateGasFee.js +3 -2
- package/lib/esm/types/buildTx.d.ts +5 -2
- package/lib/esm/types/buildTx.d.ts.map +1 -1
- package/lib/esm/types/constants/_7k.d.ts +3 -2
- package/lib/esm/types/constants/_7k.d.ts.map +1 -1
- package/lib/esm/types/estimateGasFee.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +4 -1
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/types/tx.d.ts +1 -1
- package/lib/esm/types/types/tx.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ const quoteResponse = await getQuote({
|
|
|
65
65
|
```typescript
|
|
66
66
|
import { buildTx } from "@7kprotocol/sdk-ts";
|
|
67
67
|
|
|
68
|
-
const
|
|
68
|
+
const result = await buildTx({
|
|
69
69
|
quoteResponse,
|
|
70
70
|
accountAddress: "0xSenderAddress",
|
|
71
71
|
slippage: 0.01, // 1%
|
|
@@ -74,6 +74,7 @@ const tx = await buildTx({
|
|
|
74
74
|
commissionBps: 0, // 0 means no fee, 1bps = 0.01%, for example, 20bps = 0.2%
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
|
+
const { tx, coinOut } = result || {};
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
or
|
|
@@ -84,7 +85,7 @@ import { buildTx } from "@7kprotocol/sdk-ts";
|
|
|
84
85
|
|
|
85
86
|
const tx = new Transaction();
|
|
86
87
|
|
|
87
|
-
await buildTx({
|
|
88
|
+
const result = await buildTx({
|
|
88
89
|
quoteResponse,
|
|
89
90
|
accountAddress: "0xSenderAddress",
|
|
90
91
|
slippage: 0.01, // 1%
|
|
@@ -98,6 +99,7 @@ await buildTx({
|
|
|
98
99
|
coinIn: tx.object("0xCoinObjectAddress"),
|
|
99
100
|
},
|
|
100
101
|
});
|
|
102
|
+
const { coinOut } = result || {};
|
|
101
103
|
```
|
|
102
104
|
|
|
103
105
|
### Full Example
|
|
@@ -118,7 +120,7 @@ const quoteResponse = await getQuote({
|
|
|
118
120
|
amountIn: "1000000000",
|
|
119
121
|
});
|
|
120
122
|
|
|
121
|
-
const
|
|
123
|
+
const result = await buildTx({
|
|
122
124
|
quoteResponse,
|
|
123
125
|
accountAddress: "0xSenderAddress",
|
|
124
126
|
slippage: 0.01, // 1%
|
|
@@ -128,7 +130,7 @@ const tx = await buildTx({
|
|
|
128
130
|
},
|
|
129
131
|
});
|
|
130
132
|
|
|
131
|
-
console.log(
|
|
133
|
+
console.log(result);
|
|
132
134
|
```
|
|
133
135
|
|
|
134
136
|
### Estimate Gas Fee
|
package/lib/cjs/buildTx.js
CHANGED
|
@@ -22,8 +22,9 @@ const token_1 = require("./utils/token");
|
|
|
22
22
|
const sui_1 = require("./utils/sui");
|
|
23
23
|
const _7k_1 = require("./constants/_7k");
|
|
24
24
|
const utils_1 = require("@mysten/sui/utils");
|
|
25
|
-
const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteResponse, accountAddress, slippage, commission: _commission,
|
|
25
|
+
const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }) {
|
|
26
26
|
const { tx: _tx, coinIn } = extendTx || {};
|
|
27
|
+
let coinOut;
|
|
27
28
|
if (!accountAddress) {
|
|
28
29
|
throw new Error("Sender address is required");
|
|
29
30
|
}
|
|
@@ -41,7 +42,7 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteRespon
|
|
|
41
42
|
coinData = tx.splitCoins(coinIn, splits);
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
|
-
const { coinData: _data } = yield (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, quoteResponse.swapAmountWithDecimal, splits, (0, token_1.denormalizeTokenType)(quoteResponse.tokenIn), tx,
|
|
45
|
+
const { coinData: _data } = yield (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, quoteResponse.swapAmountWithDecimal, splits, (0, token_1.denormalizeTokenType)(quoteResponse.tokenIn), tx, devInspect);
|
|
45
46
|
coinData = _data;
|
|
46
47
|
}
|
|
47
48
|
const coinObjects = [];
|
|
@@ -61,48 +62,34 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteRespon
|
|
|
61
62
|
const mergeCoin = coinObjects.length > 1
|
|
62
63
|
? sui_1.SuiUtils.mergeCoins(coinObjects, tx)
|
|
63
64
|
: coinObjects[0];
|
|
65
|
+
coinOut = mergeCoin;
|
|
64
66
|
const minReceived = new bignumber_js_1.default(1)
|
|
65
67
|
.minus(slippage)
|
|
66
68
|
.multipliedBy(quoteResponse.returnAmountWithDecimal)
|
|
67
69
|
.toFixed(0);
|
|
68
|
-
const
|
|
70
|
+
const [partner] = tx.moveCall({
|
|
71
|
+
target: "0x1::option::some",
|
|
72
|
+
typeArguments: [`address`],
|
|
73
|
+
arguments: [tx.pure.address(_commission.partner)],
|
|
74
|
+
});
|
|
69
75
|
tx.moveCall({
|
|
70
76
|
target: `${_7k_1._7K_PACKAGE_ID}::settle::settle`,
|
|
71
77
|
typeArguments: [quoteResponse.tokenIn, quoteResponse.tokenOut],
|
|
72
78
|
arguments: [
|
|
73
79
|
tx.object(_7k_1._7K_CONFIG),
|
|
80
|
+
tx.object(_7k_1._7K_VAULT),
|
|
74
81
|
tx.pure.u64(quoteResponse.swapAmountWithDecimal),
|
|
75
82
|
mergeCoin,
|
|
76
83
|
tx.pure.u64(minReceived),
|
|
77
84
|
tx.pure.u64(quoteResponse.returnAmountWithDecimal),
|
|
78
|
-
|
|
85
|
+
partner,
|
|
86
|
+
tx.pure.u64(_commission.commissionBps),
|
|
79
87
|
],
|
|
80
88
|
});
|
|
81
|
-
|
|
89
|
+
if (!extendTx) {
|
|
90
|
+
tx.transferObjects([mergeCoin], tx.pure.address(accountAddress));
|
|
91
|
+
}
|
|
82
92
|
}
|
|
83
|
-
return tx;
|
|
93
|
+
return { tx, coinOut };
|
|
84
94
|
});
|
|
85
95
|
exports.buildTx = buildTx;
|
|
86
|
-
const getCommission = (tx, commission) => {
|
|
87
|
-
if (commission) {
|
|
88
|
-
const [commissionInner] = tx.moveCall({
|
|
89
|
-
target: `${_7k_1._7K_PACKAGE_ID}::commission::new`,
|
|
90
|
-
typeArguments: [],
|
|
91
|
-
arguments: [
|
|
92
|
-
tx.pure.address(commission.partner),
|
|
93
|
-
tx.pure.u64(commission.commissionBps),
|
|
94
|
-
],
|
|
95
|
-
});
|
|
96
|
-
const [result] = tx.moveCall({
|
|
97
|
-
target: "0x1::option::some",
|
|
98
|
-
typeArguments: [`${_7k_1._7K_PACKAGE_ID}::commission::Commission`],
|
|
99
|
-
arguments: [commissionInner],
|
|
100
|
-
});
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
return tx.moveCall({
|
|
104
|
-
target: "0x1::option::none",
|
|
105
|
-
typeArguments: [`${_7k_1._7K_PACKAGE_ID}::commission::Commission`],
|
|
106
|
-
arguments: [],
|
|
107
|
-
})[0];
|
|
108
|
-
};
|
package/lib/cjs/constants/_7k.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._7K_CONFIG = exports._7K_PACKAGE_ID = void 0;
|
|
4
|
-
exports._7K_PACKAGE_ID = "
|
|
5
|
-
//
|
|
6
|
-
|
|
3
|
+
exports._7K_VAULT = exports._7K_CONFIG = exports._7K_PACKAGE_ID = void 0;
|
|
4
|
+
exports._7K_PACKAGE_ID = "0x7ea6e27ad7af6f3b8671d59df1aaebd7c03dddab893e52a714227b2f4fe91519";
|
|
5
|
+
//legacy V2: "0xa13447019cd982d6bef91cf7b46ad384a52583b1dfc2bdecf31ef0c4bd787a0f";
|
|
6
|
+
//legacy V1: "0xd48e7cdc9e92bec69ce3baa75578010458a0c5b2733d661a84971e8cef6806bc";
|
|
7
|
+
exports._7K_CONFIG = "0x0f8fc23dbcc9362b72c7a4c5aa53fcefa02ebfbb83a812c8c262ccd2c076d9ee";
|
|
8
|
+
exports._7K_VAULT = "0x39a3c55742c0e011b6f65548e73cf589e1ae5e82dbfab449ca57f24c3bcd9514";
|
|
@@ -23,17 +23,18 @@ function estimateGasFee(_a) {
|
|
|
23
23
|
return __awaiter(this, arguments, void 0, function* ({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
|
|
24
24
|
if (!accountAddress)
|
|
25
25
|
return 0;
|
|
26
|
-
const
|
|
26
|
+
const result = yield (0, buildTx_1.buildTx)({
|
|
27
27
|
extendTx,
|
|
28
28
|
quoteResponse,
|
|
29
29
|
accountAddress,
|
|
30
30
|
slippage,
|
|
31
31
|
commission,
|
|
32
|
-
|
|
32
|
+
devInspect: true,
|
|
33
33
|
}).catch((err) => {
|
|
34
34
|
console.log("build tx error: ", err);
|
|
35
35
|
return undefined;
|
|
36
36
|
});
|
|
37
|
+
const { tx } = result || {};
|
|
37
38
|
if (!tx)
|
|
38
39
|
return 0;
|
|
39
40
|
const suiPrice = _suiPrice || (yield (0, getSuiPrice_1.getSuiPrice)());
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
2
|
import { BuildTxParams } from "./types/tx";
|
|
3
|
-
export declare const buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission,
|
|
3
|
+
export declare const buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }: BuildTxParams) => Promise<{
|
|
4
|
+
tx: Transaction;
|
|
5
|
+
coinOut: TransactionObjectArgument | undefined;
|
|
6
|
+
}>;
|
|
4
7
|
//# sourceMappingURL=buildTx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../src/buildTx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../src/buildTx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAE1B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAI3C,eAAO,MAAM,OAAO,gGAOjB,aAAa;;;EA2Ff,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export declare const _7K_PACKAGE_ID = "
|
|
2
|
-
export declare const _7K_CONFIG = "
|
|
1
|
+
export declare const _7K_PACKAGE_ID = "0x7ea6e27ad7af6f3b8671d59df1aaebd7c03dddab893e52a714227b2f4fe91519";
|
|
2
|
+
export declare const _7K_CONFIG = "0x0f8fc23dbcc9362b72c7a4c5aa53fcefa02ebfbb83a812c8c262ccd2c076d9ee";
|
|
3
|
+
export declare const _7K_VAULT = "0x39a3c55742c0e011b6f65548e73cf589e1ae5e82dbfab449ca57f24c3bcd9514";
|
|
3
4
|
//# sourceMappingURL=_7k.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_7k.d.ts","sourceRoot":"","sources":["../../../../src/constants/_7k.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,uEAC2C,CAAC;
|
|
1
|
+
{"version":3,"file":"_7k.d.ts","sourceRoot":"","sources":["../../../../src/constants/_7k.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,uEAC2C,CAAC;AAGvE,eAAO,MAAM,UAAU,uEAC+C,CAAC;AAEvE,eAAO,MAAM,SAAS,uEACgD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateGasFee.d.ts","sourceRoot":"","sources":["../../../src/estimateGasFee.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIlD,wBAAsB,cAAc,CAAC,EACnC,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EAAE,SAAS,EACnB,QAAQ,EACR,UAAU,GACX,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"estimateGasFee.d.ts","sourceRoot":"","sources":["../../../src/estimateGasFee.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIlD,wBAAsB,cAAc,CAAC,EACnC,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EAAE,SAAS,EACnB,QAAQ,EACR,UAAU,GACX,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAuCxC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ declare const _default: {
|
|
|
11
11
|
getQuote: typeof getQuote;
|
|
12
12
|
getSuiPrice: typeof getSuiPrice;
|
|
13
13
|
estimateGasFee: typeof estimateGasFee;
|
|
14
|
-
buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission,
|
|
14
|
+
buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }: import("./types/tx").BuildTxParams) => Promise<{
|
|
15
|
+
tx: import("@mysten/sui/dist/cjs/transactions").Transaction;
|
|
16
|
+
coinOut: import("@mysten/sui/dist/cjs/transactions").TransactionObjectArgument | undefined;
|
|
17
|
+
}>;
|
|
15
18
|
};
|
|
16
19
|
export default _default;
|
|
17
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,OAAO,GACR,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,OAAO,GACR,CAAC;;;;;;;;;;;;AAEF,wBAOE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,WAAW,CAAC;QAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;KACpC,CAAC;CACH;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,WAAW,CAAC;QAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;KACpC,CAAC;CACH;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/lib/esm/buildTx.js
CHANGED
|
@@ -5,10 +5,11 @@ import { groupSwapRoutes } from "./libs/groupSwapRoutes";
|
|
|
5
5
|
import { swapWithRoute } from "./libs/swapWithRoute";
|
|
6
6
|
import { denormalizeTokenType } from "./utils/token";
|
|
7
7
|
import { SuiUtils } from "./utils/sui";
|
|
8
|
-
import { _7K_CONFIG, _7K_PACKAGE_ID } from "./constants/_7k";
|
|
8
|
+
import { _7K_CONFIG, _7K_PACKAGE_ID, _7K_VAULT } from "./constants/_7k";
|
|
9
9
|
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
10
|
-
export const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: _commission,
|
|
10
|
+
export const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }) => {
|
|
11
11
|
const { tx: _tx, coinIn } = extendTx || {};
|
|
12
|
+
let coinOut;
|
|
12
13
|
if (!accountAddress) {
|
|
13
14
|
throw new Error("Sender address is required");
|
|
14
15
|
}
|
|
@@ -26,7 +27,7 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
|
|
|
26
27
|
coinData = tx.splitCoins(coinIn, splits);
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
|
-
const { coinData: _data } = await getSplitCoinForTx(accountAddress, quoteResponse.swapAmountWithDecimal, splits, denormalizeTokenType(quoteResponse.tokenIn), tx,
|
|
30
|
+
const { coinData: _data } = await getSplitCoinForTx(accountAddress, quoteResponse.swapAmountWithDecimal, splits, denormalizeTokenType(quoteResponse.tokenIn), tx, devInspect);
|
|
30
31
|
coinData = _data;
|
|
31
32
|
}
|
|
32
33
|
const coinObjects = [];
|
|
@@ -46,47 +47,33 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
|
|
|
46
47
|
const mergeCoin = coinObjects.length > 1
|
|
47
48
|
? SuiUtils.mergeCoins(coinObjects, tx)
|
|
48
49
|
: coinObjects[0];
|
|
50
|
+
coinOut = mergeCoin;
|
|
49
51
|
const minReceived = new BigNumber(1)
|
|
50
52
|
.minus(slippage)
|
|
51
53
|
.multipliedBy(quoteResponse.returnAmountWithDecimal)
|
|
52
54
|
.toFixed(0);
|
|
53
|
-
const
|
|
55
|
+
const [partner] = tx.moveCall({
|
|
56
|
+
target: "0x1::option::some",
|
|
57
|
+
typeArguments: [`address`],
|
|
58
|
+
arguments: [tx.pure.address(_commission.partner)],
|
|
59
|
+
});
|
|
54
60
|
tx.moveCall({
|
|
55
61
|
target: `${_7K_PACKAGE_ID}::settle::settle`,
|
|
56
62
|
typeArguments: [quoteResponse.tokenIn, quoteResponse.tokenOut],
|
|
57
63
|
arguments: [
|
|
58
64
|
tx.object(_7K_CONFIG),
|
|
65
|
+
tx.object(_7K_VAULT),
|
|
59
66
|
tx.pure.u64(quoteResponse.swapAmountWithDecimal),
|
|
60
67
|
mergeCoin,
|
|
61
68
|
tx.pure.u64(minReceived),
|
|
62
69
|
tx.pure.u64(quoteResponse.returnAmountWithDecimal),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
tx.transferObjects([mergeCoin], tx.pure.address(accountAddress));
|
|
67
|
-
}
|
|
68
|
-
return tx;
|
|
69
|
-
};
|
|
70
|
-
const getCommission = (tx, commission) => {
|
|
71
|
-
if (commission) {
|
|
72
|
-
const [commissionInner] = tx.moveCall({
|
|
73
|
-
target: `${_7K_PACKAGE_ID}::commission::new`,
|
|
74
|
-
typeArguments: [],
|
|
75
|
-
arguments: [
|
|
76
|
-
tx.pure.address(commission.partner),
|
|
77
|
-
tx.pure.u64(commission.commissionBps),
|
|
70
|
+
partner,
|
|
71
|
+
tx.pure.u64(_commission.commissionBps),
|
|
78
72
|
],
|
|
79
73
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
arguments: [commissionInner],
|
|
84
|
-
});
|
|
85
|
-
return result;
|
|
74
|
+
if (!extendTx) {
|
|
75
|
+
tx.transferObjects([mergeCoin], tx.pure.address(accountAddress));
|
|
76
|
+
}
|
|
86
77
|
}
|
|
87
|
-
return tx
|
|
88
|
-
target: "0x1::option::none",
|
|
89
|
-
typeArguments: [`${_7K_PACKAGE_ID}::commission::Commission`],
|
|
90
|
-
arguments: [],
|
|
91
|
-
})[0];
|
|
78
|
+
return { tx, coinOut };
|
|
92
79
|
};
|
package/lib/esm/constants/_7k.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export const _7K_PACKAGE_ID = "
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
export const _7K_PACKAGE_ID = "0x7ea6e27ad7af6f3b8671d59df1aaebd7c03dddab893e52a714227b2f4fe91519";
|
|
2
|
+
//legacy V2: "0xa13447019cd982d6bef91cf7b46ad384a52583b1dfc2bdecf31ef0c4bd787a0f";
|
|
3
|
+
//legacy V1: "0xd48e7cdc9e92bec69ce3baa75578010458a0c5b2733d661a84971e8cef6806bc";
|
|
4
|
+
export const _7K_CONFIG = "0x0f8fc23dbcc9362b72c7a4c5aa53fcefa02ebfbb83a812c8c262ccd2c076d9ee";
|
|
5
|
+
export const _7K_VAULT = "0x39a3c55742c0e011b6f65548e73cf589e1ae5e82dbfab449ca57f24c3bcd9514";
|
|
@@ -7,17 +7,18 @@ import { getSuiPrice } from "./getSuiPrice";
|
|
|
7
7
|
export async function estimateGasFee({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
|
|
8
8
|
if (!accountAddress)
|
|
9
9
|
return 0;
|
|
10
|
-
const
|
|
10
|
+
const result = await buildTx({
|
|
11
11
|
extendTx,
|
|
12
12
|
quoteResponse,
|
|
13
13
|
accountAddress,
|
|
14
14
|
slippage,
|
|
15
15
|
commission,
|
|
16
|
-
|
|
16
|
+
devInspect: true,
|
|
17
17
|
}).catch((err) => {
|
|
18
18
|
console.log("build tx error: ", err);
|
|
19
19
|
return undefined;
|
|
20
20
|
});
|
|
21
|
+
const { tx } = result || {};
|
|
21
22
|
if (!tx)
|
|
22
23
|
return 0;
|
|
23
24
|
const suiPrice = _suiPrice || (await getSuiPrice());
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
2
|
import { BuildTxParams } from "./types/tx";
|
|
3
|
-
export declare const buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission,
|
|
3
|
+
export declare const buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }: BuildTxParams) => Promise<{
|
|
4
|
+
tx: Transaction;
|
|
5
|
+
coinOut: TransactionObjectArgument | undefined;
|
|
6
|
+
}>;
|
|
4
7
|
//# sourceMappingURL=buildTx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../src/buildTx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../src/buildTx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAE1B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAI3C,eAAO,MAAM,OAAO,gGAOjB,aAAa;;;EA2Ff,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export declare const _7K_PACKAGE_ID = "
|
|
2
|
-
export declare const _7K_CONFIG = "
|
|
1
|
+
export declare const _7K_PACKAGE_ID = "0x7ea6e27ad7af6f3b8671d59df1aaebd7c03dddab893e52a714227b2f4fe91519";
|
|
2
|
+
export declare const _7K_CONFIG = "0x0f8fc23dbcc9362b72c7a4c5aa53fcefa02ebfbb83a812c8c262ccd2c076d9ee";
|
|
3
|
+
export declare const _7K_VAULT = "0x39a3c55742c0e011b6f65548e73cf589e1ae5e82dbfab449ca57f24c3bcd9514";
|
|
3
4
|
//# sourceMappingURL=_7k.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_7k.d.ts","sourceRoot":"","sources":["../../../../src/constants/_7k.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,uEAC2C,CAAC;
|
|
1
|
+
{"version":3,"file":"_7k.d.ts","sourceRoot":"","sources":["../../../../src/constants/_7k.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,uEAC2C,CAAC;AAGvE,eAAO,MAAM,UAAU,uEAC+C,CAAC;AAEvE,eAAO,MAAM,SAAS,uEACgD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateGasFee.d.ts","sourceRoot":"","sources":["../../../src/estimateGasFee.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIlD,wBAAsB,cAAc,CAAC,EACnC,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EAAE,SAAS,EACnB,QAAQ,EACR,UAAU,GACX,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"estimateGasFee.d.ts","sourceRoot":"","sources":["../../../src/estimateGasFee.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIlD,wBAAsB,cAAc,CAAC,EACnC,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EAAE,SAAS,EACnB,QAAQ,EACR,UAAU,GACX,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAuCxC"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ declare const _default: {
|
|
|
11
11
|
getQuote: typeof getQuote;
|
|
12
12
|
getSuiPrice: typeof getSuiPrice;
|
|
13
13
|
estimateGasFee: typeof estimateGasFee;
|
|
14
|
-
buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission,
|
|
14
|
+
buildTx: ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }: import("./types/tx").BuildTxParams) => Promise<{
|
|
15
|
+
tx: import("@mysten/sui/dist/cjs/transactions").Transaction;
|
|
16
|
+
coinOut: import("@mysten/sui/dist/cjs/transactions").TransactionObjectArgument | undefined;
|
|
17
|
+
}>;
|
|
15
18
|
};
|
|
16
19
|
export default _default;
|
|
17
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,OAAO,GACR,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,OAAO,GACR,CAAC;;;;;;;;;;;;AAEF,wBAOE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,WAAW,CAAC;QAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;KACpC,CAAC;CACH;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,WAAW,CAAC;QAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;KACpC,CAAC;CACH;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|