@7kprotocol/sdk-ts 3.4.2-beta.6 → 3.4.2-beta.8
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 +2 -2
- package/lib/cjs/features/metaAg/index.js +44 -10
- package/lib/cjs/features/metaAg/providers/bluefin.js +2 -1
- package/lib/cjs/features/metaAg/providers/flowx.js +3 -3
- package/lib/cjs/types/features/metaAg/index.d.ts +5 -0
- package/lib/cjs/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/esm/features/metaAg/index.js +44 -10
- package/lib/esm/features/metaAg/providers/bluefin.js +2 -1
- package/lib/esm/features/metaAg/providers/flowx.js +3 -3
- package/lib/esm/types/features/metaAg/index.d.ts +5 -0
- package/lib/esm/types/features/metaAg/index.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,7 +178,7 @@ const quotes = await metaAg.quote({
|
|
|
178
178
|
|
|
179
179
|
// Find the best quote
|
|
180
180
|
const bestQuote = quotes.reduce((best, current) =>
|
|
181
|
-
Number(current.amountOut) > Number(best.amountOut) ? current : best
|
|
181
|
+
Number(current.amountOut) > Number(best.amountOut) ? current : best,
|
|
182
182
|
);
|
|
183
183
|
```
|
|
184
184
|
|
|
@@ -256,7 +256,7 @@ const coinIn = coinWithBalance({
|
|
|
256
256
|
import { getTokenPrice, getTokenPrices, getSuiPrice } from "@7kprotocol/sdk-ts";
|
|
257
257
|
|
|
258
258
|
const tokenPrice = await getTokenPrice(
|
|
259
|
-
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
259
|
+
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
260
260
|
);
|
|
261
261
|
|
|
262
262
|
const tokenPrices = await getTokenPrices([
|
|
@@ -70,23 +70,20 @@ class MetaAg {
|
|
|
70
70
|
const p = this.providers[provider];
|
|
71
71
|
if (p)
|
|
72
72
|
return p;
|
|
73
|
+
const providerOptions = this.options.providers[provider];
|
|
74
|
+
(0, condition_1.assert)(!!providerOptions, `Provider not found: ${provider}`);
|
|
75
|
+
// eslint-disable-next-line no-case-declarations
|
|
73
76
|
switch (provider) {
|
|
74
77
|
case metaAg_1.EProvider.BLUEFIN7K:
|
|
75
|
-
|
|
76
|
-
(0, condition_1.assert)(!!bluefinOptions, `Provider not found: ${provider}`);
|
|
77
|
-
this.providers[metaAg_1.EProvider.BLUEFIN7K] = new bluefin_1.BluefinProvider(bluefinOptions, this.options, this.client);
|
|
78
|
+
this.providers[metaAg_1.EProvider.BLUEFIN7K] = new bluefin_1.BluefinProvider(providerOptions, this.options, this.client);
|
|
78
79
|
break;
|
|
79
80
|
case metaAg_1.EProvider.FLOWX:
|
|
80
|
-
const flowxOptions = this.options.providers[provider];
|
|
81
|
-
(0, condition_1.assert)(!!flowxOptions, `Provider not found: ${provider}`);
|
|
82
81
|
const { FlowxProvider } = await Promise.resolve().then(() => __importStar(require("./providers/flowx"))).catch(catchImportError(metaAg_1.EProvider.FLOWX));
|
|
83
|
-
this.providers[metaAg_1.EProvider.FLOWX] = new FlowxProvider(
|
|
82
|
+
this.providers[metaAg_1.EProvider.FLOWX] = new FlowxProvider(providerOptions, this.options, this.client);
|
|
84
83
|
break;
|
|
85
84
|
case metaAg_1.EProvider.CETUS:
|
|
86
|
-
const cetusOptions = this.options.providers[provider];
|
|
87
|
-
(0, condition_1.assert)(!!cetusOptions, `Provider not found: ${provider}`);
|
|
88
85
|
const { CetusProvider } = await Promise.resolve().then(() => __importStar(require("./providers/cetus"))).catch(catchImportError(metaAg_1.EProvider.CETUS));
|
|
89
|
-
this.providers[metaAg_1.EProvider.CETUS] = new CetusProvider(
|
|
86
|
+
this.providers[metaAg_1.EProvider.CETUS] = new CetusProvider(providerOptions, this.options, this.client);
|
|
90
87
|
break;
|
|
91
88
|
default:
|
|
92
89
|
throw new Error(`Provider not supported: ${provider}`);
|
|
@@ -102,6 +99,7 @@ class MetaAg {
|
|
|
102
99
|
coinIn: (0, transactions_1.coinWithBalance)({
|
|
103
100
|
balance: BigInt(quote.amountIn),
|
|
104
101
|
type: quote.coinTypeIn,
|
|
102
|
+
useGasCoin: false,
|
|
105
103
|
}),
|
|
106
104
|
signer: simulation.sender,
|
|
107
105
|
tx,
|
|
@@ -112,6 +110,9 @@ class MetaAg {
|
|
|
112
110
|
sender: simulation.sender,
|
|
113
111
|
transactionBlock: tx,
|
|
114
112
|
}), simulation.timeout ?? 2000, `simulation for ${provider.kind} provider with id ${id}`);
|
|
113
|
+
if (res.effects.status.status === 'failure') {
|
|
114
|
+
throw new Error(res.error ?? 'Simulation failed');
|
|
115
|
+
}
|
|
115
116
|
const amountOut = extractAmountOutWrapper(res.events);
|
|
116
117
|
return {
|
|
117
118
|
id,
|
|
@@ -129,7 +130,9 @@ class MetaAg {
|
|
|
129
130
|
if (simulation) {
|
|
130
131
|
if (simulation.onSimulated) {
|
|
131
132
|
this._simulate(provider, quote, simulation).then((payload) => {
|
|
132
|
-
|
|
133
|
+
if (payload) {
|
|
134
|
+
simulation.onSimulated?.(payload);
|
|
135
|
+
}
|
|
133
136
|
});
|
|
134
137
|
}
|
|
135
138
|
else {
|
|
@@ -171,6 +174,37 @@ class MetaAg {
|
|
|
171
174
|
options.tx.setSenderIfNotSet(options.signer);
|
|
172
175
|
return coinOut;
|
|
173
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Update meta aggregator options
|
|
179
|
+
* @param options - update options payload
|
|
180
|
+
*/
|
|
181
|
+
updateMetaAgOptions(options) {
|
|
182
|
+
if (Object.keys(options).length === 0)
|
|
183
|
+
return;
|
|
184
|
+
this.options.slippageBps = options.slippageBps ?? this.options.slippageBps;
|
|
185
|
+
this.options.partner = options.partner ?? this.options.partner;
|
|
186
|
+
this.options.partnerCommissionBps =
|
|
187
|
+
options.partnerCommissionBps ?? this.options.partnerCommissionBps;
|
|
188
|
+
this.options.tipBps = options.tipBps ?? this.options.tipBps;
|
|
189
|
+
if (options.fullnodeUrl &&
|
|
190
|
+
options.fullnodeUrl !== this.options.fullnodeUrl) {
|
|
191
|
+
this.client = new client_1.SuiClient({ url: options.fullnodeUrl });
|
|
192
|
+
this.inspector = new SuiClientUtils_1.SuiClientUtils(this.client);
|
|
193
|
+
this.options.fullnodeUrl = options.fullnodeUrl;
|
|
194
|
+
}
|
|
195
|
+
if (options.hermesApi && options.hermesApi !== this.options.hermesApi) {
|
|
196
|
+
this.providers = {};
|
|
197
|
+
this.options.hermesApi = options.hermesApi;
|
|
198
|
+
}
|
|
199
|
+
// if update provider's options, we need to re-initialize the provider
|
|
200
|
+
for (const [provider, opt] of Object.entries(options.providers || {})) {
|
|
201
|
+
this.options.providers[provider] = {
|
|
202
|
+
...opt,
|
|
203
|
+
...this.options.providers[provider],
|
|
204
|
+
};
|
|
205
|
+
delete this.providers[provider];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
174
208
|
}
|
|
175
209
|
exports.MetaAg = MetaAg;
|
|
176
210
|
/**
|
|
@@ -20,7 +20,8 @@ class BluefinProvider {
|
|
|
20
20
|
this.kind = metaAg_1.EProvider.BLUEFIN7K;
|
|
21
21
|
const pythClient = new pyth_sui_js_1.SuiPythClient(client, PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
22
22
|
const pythConnection = new pyth_sui_js_1.SuiPriceServiceConnection(this.metaOptions.hermesApi);
|
|
23
|
-
|
|
23
|
+
if (options.apiKey)
|
|
24
|
+
config_1.Config.setApiKey(options.apiKey);
|
|
24
25
|
config_1.Config.setSuiClient(client);
|
|
25
26
|
config_1.Config.setPythClient(pythClient);
|
|
26
27
|
config_1.Config.setPythConnection(pythConnection);
|
|
@@ -25,13 +25,13 @@ class FlowxProvider {
|
|
|
25
25
|
maxHops: this.options.maxHops,
|
|
26
26
|
splitDistributionPercent: this.options.splitDistributionPercent,
|
|
27
27
|
});
|
|
28
|
-
const { expectedAmount } = (0, buildTx_1.getExpectedReturn)(quote.amountOut
|
|
28
|
+
const { expectedAmount } = (0, buildTx_1.getExpectedReturn)(quote.amountOut?.toString() ?? "0", 0, this.metaOptions.partnerCommissionBps ?? 0, this.metaOptions.tipBps ?? 0);
|
|
29
29
|
return {
|
|
30
30
|
id: (0, uuid_1.v4)(),
|
|
31
31
|
provider: metaAg_1.EProvider.FLOWX,
|
|
32
32
|
quote: quote,
|
|
33
|
-
amountIn: quote.amountIn
|
|
34
|
-
rawAmountOut: quote.amountOut
|
|
33
|
+
amountIn: quote.amountIn?.toString() ?? "0",
|
|
34
|
+
rawAmountOut: quote.amountOut?.toString() ?? "0",
|
|
35
35
|
amountOut: expectedAmount,
|
|
36
36
|
coinTypeIn: quoteOptions.coinInType,
|
|
37
37
|
coinTypeOut: quoteOptions.coinOutType,
|
|
@@ -24,5 +24,10 @@ export declare class MetaAg {
|
|
|
24
24
|
* @returns coin out object, you must consume it by transferObjects, or other sub sequence commands
|
|
25
25
|
*/
|
|
26
26
|
swap(options: MetaSwapOptions, slippageBps?: number): Promise<TransactionObjectArgument>;
|
|
27
|
+
/**
|
|
28
|
+
* Update meta aggregator options
|
|
29
|
+
* @param options - update options payload
|
|
30
|
+
*/
|
|
31
|
+
updateMetaAgOptions(options: MetaAgOptions): void;
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/metaAg/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAY,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAGL,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAQlC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/metaAg/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAY,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAGL,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAML,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAa5B,qBAAa,MAAM;IACjB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,OAAO,CAA0B;gBAC7B,OAAO,CAAC,EAAE,aAAa;YAkBrB,YAAY;YAyCZ,SAAS;YAqDT,MAAM;IA0BpB;;;;;OAKG;IACG,KAAK,CACT,OAAO,EAAE,gBAAgB,EACzB,UAAU,CAAC,EAAE,qBAAqB,GACjC,OAAO,CAAC,SAAS,EAAE,CAAC;IAgBvB;;;;;OAKG;IACG,IAAI,CACR,OAAO,EAAE,eAAe,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,yBAAyB,CAAC;IAkBrC;;;OAGG;IACH,mBAAmB,CAAC,OAAO,EAAE,aAAa;CA4B3C"}
|
|
@@ -37,23 +37,20 @@ export class MetaAg {
|
|
|
37
37
|
const p = this.providers[provider];
|
|
38
38
|
if (p)
|
|
39
39
|
return p;
|
|
40
|
+
const providerOptions = this.options.providers[provider];
|
|
41
|
+
assert(!!providerOptions, `Provider not found: ${provider}`);
|
|
42
|
+
// eslint-disable-next-line no-case-declarations
|
|
40
43
|
switch (provider) {
|
|
41
44
|
case EProvider.BLUEFIN7K:
|
|
42
|
-
|
|
43
|
-
assert(!!bluefinOptions, `Provider not found: ${provider}`);
|
|
44
|
-
this.providers[EProvider.BLUEFIN7K] = new BluefinProvider(bluefinOptions, this.options, this.client);
|
|
45
|
+
this.providers[EProvider.BLUEFIN7K] = new BluefinProvider(providerOptions, this.options, this.client);
|
|
45
46
|
break;
|
|
46
47
|
case EProvider.FLOWX:
|
|
47
|
-
const flowxOptions = this.options.providers[provider];
|
|
48
|
-
assert(!!flowxOptions, `Provider not found: ${provider}`);
|
|
49
48
|
const { FlowxProvider } = await import("./providers/flowx").catch(catchImportError(EProvider.FLOWX));
|
|
50
|
-
this.providers[EProvider.FLOWX] = new FlowxProvider(
|
|
49
|
+
this.providers[EProvider.FLOWX] = new FlowxProvider(providerOptions, this.options, this.client);
|
|
51
50
|
break;
|
|
52
51
|
case EProvider.CETUS:
|
|
53
|
-
const cetusOptions = this.options.providers[provider];
|
|
54
|
-
assert(!!cetusOptions, `Provider not found: ${provider}`);
|
|
55
52
|
const { CetusProvider } = await import("./providers/cetus").catch(catchImportError(EProvider.CETUS));
|
|
56
|
-
this.providers[EProvider.CETUS] = new CetusProvider(
|
|
53
|
+
this.providers[EProvider.CETUS] = new CetusProvider(providerOptions, this.options, this.client);
|
|
57
54
|
break;
|
|
58
55
|
default:
|
|
59
56
|
throw new Error(`Provider not supported: ${provider}`);
|
|
@@ -69,6 +66,7 @@ export class MetaAg {
|
|
|
69
66
|
coinIn: coinWithBalance({
|
|
70
67
|
balance: BigInt(quote.amountIn),
|
|
71
68
|
type: quote.coinTypeIn,
|
|
69
|
+
useGasCoin: false,
|
|
72
70
|
}),
|
|
73
71
|
signer: simulation.sender,
|
|
74
72
|
tx,
|
|
@@ -79,6 +77,9 @@ export class MetaAg {
|
|
|
79
77
|
sender: simulation.sender,
|
|
80
78
|
transactionBlock: tx,
|
|
81
79
|
}), simulation.timeout ?? 2000, `simulation for ${provider.kind} provider with id ${id}`);
|
|
80
|
+
if (res.effects.status.status === 'failure') {
|
|
81
|
+
throw new Error(res.error ?? 'Simulation failed');
|
|
82
|
+
}
|
|
82
83
|
const amountOut = extractAmountOutWrapper(res.events);
|
|
83
84
|
return {
|
|
84
85
|
id,
|
|
@@ -96,7 +97,9 @@ export class MetaAg {
|
|
|
96
97
|
if (simulation) {
|
|
97
98
|
if (simulation.onSimulated) {
|
|
98
99
|
this._simulate(provider, quote, simulation).then((payload) => {
|
|
99
|
-
|
|
100
|
+
if (payload) {
|
|
101
|
+
simulation.onSimulated?.(payload);
|
|
102
|
+
}
|
|
100
103
|
});
|
|
101
104
|
}
|
|
102
105
|
else {
|
|
@@ -138,6 +141,37 @@ export class MetaAg {
|
|
|
138
141
|
options.tx.setSenderIfNotSet(options.signer);
|
|
139
142
|
return coinOut;
|
|
140
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Update meta aggregator options
|
|
146
|
+
* @param options - update options payload
|
|
147
|
+
*/
|
|
148
|
+
updateMetaAgOptions(options) {
|
|
149
|
+
if (Object.keys(options).length === 0)
|
|
150
|
+
return;
|
|
151
|
+
this.options.slippageBps = options.slippageBps ?? this.options.slippageBps;
|
|
152
|
+
this.options.partner = options.partner ?? this.options.partner;
|
|
153
|
+
this.options.partnerCommissionBps =
|
|
154
|
+
options.partnerCommissionBps ?? this.options.partnerCommissionBps;
|
|
155
|
+
this.options.tipBps = options.tipBps ?? this.options.tipBps;
|
|
156
|
+
if (options.fullnodeUrl &&
|
|
157
|
+
options.fullnodeUrl !== this.options.fullnodeUrl) {
|
|
158
|
+
this.client = new SuiClient({ url: options.fullnodeUrl });
|
|
159
|
+
this.inspector = new SuiClientUtils(this.client);
|
|
160
|
+
this.options.fullnodeUrl = options.fullnodeUrl;
|
|
161
|
+
}
|
|
162
|
+
if (options.hermesApi && options.hermesApi !== this.options.hermesApi) {
|
|
163
|
+
this.providers = {};
|
|
164
|
+
this.options.hermesApi = options.hermesApi;
|
|
165
|
+
}
|
|
166
|
+
// if update provider's options, we need to re-initialize the provider
|
|
167
|
+
for (const [provider, opt] of Object.entries(options.providers || {})) {
|
|
168
|
+
this.options.providers[provider] = {
|
|
169
|
+
...opt,
|
|
170
|
+
...this.options.providers[provider],
|
|
171
|
+
};
|
|
172
|
+
delete this.providers[provider];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
141
175
|
}
|
|
142
176
|
/**
|
|
143
177
|
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
@@ -19,7 +19,8 @@ export class BluefinProvider {
|
|
|
19
19
|
this.metaOptions = metaOptions;
|
|
20
20
|
const pythClient = new SuiPythClient(client, PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
21
21
|
const pythConnection = new SuiPriceServiceConnection(this.metaOptions.hermesApi);
|
|
22
|
-
|
|
22
|
+
if (options.apiKey)
|
|
23
|
+
Config.setApiKey(options.apiKey);
|
|
23
24
|
Config.setSuiClient(client);
|
|
24
25
|
Config.setPythClient(pythClient);
|
|
25
26
|
Config.setPythConnection(pythConnection);
|
|
@@ -26,13 +26,13 @@ export class FlowxProvider {
|
|
|
26
26
|
maxHops: this.options.maxHops,
|
|
27
27
|
splitDistributionPercent: this.options.splitDistributionPercent,
|
|
28
28
|
});
|
|
29
|
-
const { expectedAmount } = getExpectedReturn(quote.amountOut
|
|
29
|
+
const { expectedAmount } = getExpectedReturn(quote.amountOut?.toString() ?? "0", 0, this.metaOptions.partnerCommissionBps ?? 0, this.metaOptions.tipBps ?? 0);
|
|
30
30
|
return {
|
|
31
31
|
id: v4(),
|
|
32
32
|
provider: EProvider.FLOWX,
|
|
33
33
|
quote: quote,
|
|
34
|
-
amountIn: quote.amountIn
|
|
35
|
-
rawAmountOut: quote.amountOut
|
|
34
|
+
amountIn: quote.amountIn?.toString() ?? "0",
|
|
35
|
+
rawAmountOut: quote.amountOut?.toString() ?? "0",
|
|
36
36
|
amountOut: expectedAmount,
|
|
37
37
|
coinTypeIn: quoteOptions.coinInType,
|
|
38
38
|
coinTypeOut: quoteOptions.coinOutType,
|
|
@@ -24,5 +24,10 @@ export declare class MetaAg {
|
|
|
24
24
|
* @returns coin out object, you must consume it by transferObjects, or other sub sequence commands
|
|
25
25
|
*/
|
|
26
26
|
swap(options: MetaSwapOptions, slippageBps?: number): Promise<TransactionObjectArgument>;
|
|
27
|
+
/**
|
|
28
|
+
* Update meta aggregator options
|
|
29
|
+
* @param options - update options payload
|
|
30
|
+
*/
|
|
31
|
+
updateMetaAgOptions(options: MetaAgOptions): void;
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/metaAg/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAY,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAGL,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAQlC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/metaAg/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAY,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAGL,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAML,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAa5B,qBAAa,MAAM;IACjB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,OAAO,CAA0B;gBAC7B,OAAO,CAAC,EAAE,aAAa;YAkBrB,YAAY;YAyCZ,SAAS;YAqDT,MAAM;IA0BpB;;;;;OAKG;IACG,KAAK,CACT,OAAO,EAAE,gBAAgB,EACzB,UAAU,CAAC,EAAE,qBAAqB,GACjC,OAAO,CAAC,SAAS,EAAE,CAAC;IAgBvB;;;;;OAKG;IACG,IAAI,CACR,OAAO,EAAE,eAAe,EACxB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,yBAAyB,CAAC;IAkBrC;;;OAGG;IACH,mBAAmB,CAAC,OAAO,EAAE,aAAa;CA4B3C"}
|