@7kprotocol/sdk-ts 3.4.2-beta.6 → 3.4.2-beta.7
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 +40 -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 +40 -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}`);
|
|
@@ -129,7 +126,9 @@ class MetaAg {
|
|
|
129
126
|
if (simulation) {
|
|
130
127
|
if (simulation.onSimulated) {
|
|
131
128
|
this._simulate(provider, quote, simulation).then((payload) => {
|
|
132
|
-
|
|
129
|
+
if (payload) {
|
|
130
|
+
simulation.onSimulated?.(payload);
|
|
131
|
+
}
|
|
133
132
|
});
|
|
134
133
|
}
|
|
135
134
|
else {
|
|
@@ -171,6 +170,37 @@ class MetaAg {
|
|
|
171
170
|
options.tx.setSenderIfNotSet(options.signer);
|
|
172
171
|
return coinOut;
|
|
173
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Update meta aggregator options
|
|
175
|
+
* @param options - update options payload
|
|
176
|
+
*/
|
|
177
|
+
updateMetaAgOptions(options) {
|
|
178
|
+
if (Object.keys(options).length === 0)
|
|
179
|
+
return;
|
|
180
|
+
this.options.slippageBps = options.slippageBps ?? this.options.slippageBps;
|
|
181
|
+
this.options.partner = options.partner ?? this.options.partner;
|
|
182
|
+
this.options.partnerCommissionBps =
|
|
183
|
+
options.partnerCommissionBps ?? this.options.partnerCommissionBps;
|
|
184
|
+
this.options.tipBps = options.tipBps ?? this.options.tipBps;
|
|
185
|
+
if (options.fullnodeUrl &&
|
|
186
|
+
options.fullnodeUrl !== this.options.fullnodeUrl) {
|
|
187
|
+
this.client = new client_1.SuiClient({ url: options.fullnodeUrl });
|
|
188
|
+
this.inspector = new SuiClientUtils_1.SuiClientUtils(this.client);
|
|
189
|
+
this.options.fullnodeUrl = options.fullnodeUrl;
|
|
190
|
+
}
|
|
191
|
+
if (options.hermesApi && options.hermesApi !== this.options.hermesApi) {
|
|
192
|
+
this.providers = {};
|
|
193
|
+
this.options.hermesApi = options.hermesApi;
|
|
194
|
+
}
|
|
195
|
+
// if update provider's options, we need to re-initialize the provider
|
|
196
|
+
for (const [provider, opt] of Object.entries(options.providers || {})) {
|
|
197
|
+
this.options.providers[provider] = {
|
|
198
|
+
...opt,
|
|
199
|
+
...this.options.providers[provider],
|
|
200
|
+
};
|
|
201
|
+
delete this.providers[provider];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
174
204
|
}
|
|
175
205
|
exports.MetaAg = MetaAg;
|
|
176
206
|
/**
|
|
@@ -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;YAiDT,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}`);
|
|
@@ -96,7 +93,9 @@ export class MetaAg {
|
|
|
96
93
|
if (simulation) {
|
|
97
94
|
if (simulation.onSimulated) {
|
|
98
95
|
this._simulate(provider, quote, simulation).then((payload) => {
|
|
99
|
-
|
|
96
|
+
if (payload) {
|
|
97
|
+
simulation.onSimulated?.(payload);
|
|
98
|
+
}
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
@@ -138,6 +137,37 @@ export class MetaAg {
|
|
|
138
137
|
options.tx.setSenderIfNotSet(options.signer);
|
|
139
138
|
return coinOut;
|
|
140
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Update meta aggregator options
|
|
142
|
+
* @param options - update options payload
|
|
143
|
+
*/
|
|
144
|
+
updateMetaAgOptions(options) {
|
|
145
|
+
if (Object.keys(options).length === 0)
|
|
146
|
+
return;
|
|
147
|
+
this.options.slippageBps = options.slippageBps ?? this.options.slippageBps;
|
|
148
|
+
this.options.partner = options.partner ?? this.options.partner;
|
|
149
|
+
this.options.partnerCommissionBps =
|
|
150
|
+
options.partnerCommissionBps ?? this.options.partnerCommissionBps;
|
|
151
|
+
this.options.tipBps = options.tipBps ?? this.options.tipBps;
|
|
152
|
+
if (options.fullnodeUrl &&
|
|
153
|
+
options.fullnodeUrl !== this.options.fullnodeUrl) {
|
|
154
|
+
this.client = new SuiClient({ url: options.fullnodeUrl });
|
|
155
|
+
this.inspector = new SuiClientUtils(this.client);
|
|
156
|
+
this.options.fullnodeUrl = options.fullnodeUrl;
|
|
157
|
+
}
|
|
158
|
+
if (options.hermesApi && options.hermesApi !== this.options.hermesApi) {
|
|
159
|
+
this.providers = {};
|
|
160
|
+
this.options.hermesApi = options.hermesApi;
|
|
161
|
+
}
|
|
162
|
+
// if update provider's options, we need to re-initialize the provider
|
|
163
|
+
for (const [provider, opt] of Object.entries(options.providers || {})) {
|
|
164
|
+
this.options.providers[provider] = {
|
|
165
|
+
...opt,
|
|
166
|
+
...this.options.providers[provider],
|
|
167
|
+
};
|
|
168
|
+
delete this.providers[provider];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
141
171
|
}
|
|
142
172
|
/**
|
|
143
173
|
* 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;YAiDT,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"}
|