@shogun-sdk/swap 0.0.2-test.7 → 0.0.2-test.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/dist/core.cjs +11 -5
- package/dist/core.js +11 -5
- package/dist/index.cjs +11 -5
- package/dist/index.js +11 -5
- package/dist/react.cjs +11 -5
- package/dist/react.js +11 -5
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -177,7 +177,7 @@ async function getQuote(params) {
|
|
|
177
177
|
tokenOut: params.tokenOut.address,
|
|
178
178
|
amount: params.amount
|
|
179
179
|
});
|
|
180
|
-
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.
|
|
180
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
181
181
|
let warning;
|
|
182
182
|
if (slippagePercent > 10) {
|
|
183
183
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
@@ -185,12 +185,17 @@ async function getQuote(params) {
|
|
|
185
185
|
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
186
186
|
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
187
187
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
188
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
189
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
190
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
191
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
188
192
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
189
193
|
return {
|
|
190
|
-
amountOut:
|
|
191
|
-
amountOutUsd:
|
|
194
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
195
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
192
196
|
amountInUsd: data.amountInUsd,
|
|
193
|
-
|
|
197
|
+
// Input USD stays the same
|
|
198
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
194
199
|
tokenIn: {
|
|
195
200
|
address: params.tokenIn.address,
|
|
196
201
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -206,7 +211,8 @@ async function getQuote(params) {
|
|
|
206
211
|
slippage: slippagePercent,
|
|
207
212
|
internal: {
|
|
208
213
|
...data,
|
|
209
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
214
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
215
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
210
216
|
},
|
|
211
217
|
warning
|
|
212
218
|
};
|
package/dist/core.js
CHANGED
|
@@ -139,7 +139,7 @@ async function getQuote(params) {
|
|
|
139
139
|
tokenOut: params.tokenOut.address,
|
|
140
140
|
amount: params.amount
|
|
141
141
|
});
|
|
142
|
-
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.
|
|
142
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
143
143
|
let warning;
|
|
144
144
|
if (slippagePercent > 10) {
|
|
145
145
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
@@ -147,12 +147,17 @@ async function getQuote(params) {
|
|
|
147
147
|
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
148
148
|
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
149
149
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
150
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
151
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
152
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
153
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
150
154
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
151
155
|
return {
|
|
152
|
-
amountOut:
|
|
153
|
-
amountOutUsd:
|
|
156
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
157
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
154
158
|
amountInUsd: data.amountInUsd,
|
|
155
|
-
|
|
159
|
+
// Input USD stays the same
|
|
160
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
156
161
|
tokenIn: {
|
|
157
162
|
address: params.tokenIn.address,
|
|
158
163
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -168,7 +173,8 @@ async function getQuote(params) {
|
|
|
168
173
|
slippage: slippagePercent,
|
|
169
174
|
internal: {
|
|
170
175
|
...data,
|
|
171
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
176
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
177
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
172
178
|
},
|
|
173
179
|
warning
|
|
174
180
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -182,7 +182,7 @@ async function getQuote(params) {
|
|
|
182
182
|
tokenOut: params.tokenOut.address,
|
|
183
183
|
amount: params.amount
|
|
184
184
|
});
|
|
185
|
-
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.
|
|
185
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
186
186
|
let warning;
|
|
187
187
|
if (slippagePercent > 10) {
|
|
188
188
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
@@ -190,12 +190,17 @@ async function getQuote(params) {
|
|
|
190
190
|
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
191
191
|
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
192
192
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
193
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
194
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
195
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
196
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
193
197
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
194
198
|
return {
|
|
195
|
-
amountOut:
|
|
196
|
-
amountOutUsd:
|
|
199
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
200
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
197
201
|
amountInUsd: data.amountInUsd,
|
|
198
|
-
|
|
202
|
+
// Input USD stays the same
|
|
203
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
199
204
|
tokenIn: {
|
|
200
205
|
address: params.tokenIn.address,
|
|
201
206
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -211,7 +216,8 @@ async function getQuote(params) {
|
|
|
211
216
|
slippage: slippagePercent,
|
|
212
217
|
internal: {
|
|
213
218
|
...data,
|
|
214
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
219
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
220
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
215
221
|
},
|
|
216
222
|
warning
|
|
217
223
|
};
|
package/dist/index.js
CHANGED
|
@@ -139,7 +139,7 @@ async function getQuote(params) {
|
|
|
139
139
|
tokenOut: params.tokenOut.address,
|
|
140
140
|
amount: params.amount
|
|
141
141
|
});
|
|
142
|
-
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.
|
|
142
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
143
143
|
let warning;
|
|
144
144
|
if (slippagePercent > 10) {
|
|
145
145
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
@@ -147,12 +147,17 @@ async function getQuote(params) {
|
|
|
147
147
|
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
148
148
|
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
149
149
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
150
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
151
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
152
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
153
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
150
154
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
151
155
|
return {
|
|
152
|
-
amountOut:
|
|
153
|
-
amountOutUsd:
|
|
156
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
157
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
154
158
|
amountInUsd: data.amountInUsd,
|
|
155
|
-
|
|
159
|
+
// Input USD stays the same
|
|
160
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
156
161
|
tokenIn: {
|
|
157
162
|
address: params.tokenIn.address,
|
|
158
163
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -168,7 +173,8 @@ async function getQuote(params) {
|
|
|
168
173
|
slippage: slippagePercent,
|
|
169
174
|
internal: {
|
|
170
175
|
...data,
|
|
171
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
176
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
177
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
172
178
|
},
|
|
173
179
|
warning
|
|
174
180
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -651,7 +651,7 @@ async function getQuote(params) {
|
|
|
651
651
|
tokenOut: params.tokenOut.address,
|
|
652
652
|
amount: params.amount
|
|
653
653
|
});
|
|
654
|
-
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.
|
|
654
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
655
655
|
let warning;
|
|
656
656
|
if (slippagePercent > 10) {
|
|
657
657
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
@@ -659,12 +659,17 @@ async function getQuote(params) {
|
|
|
659
659
|
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
660
660
|
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
661
661
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
662
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
663
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
664
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
665
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
662
666
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
663
667
|
return {
|
|
664
|
-
amountOut:
|
|
665
|
-
amountOutUsd:
|
|
668
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
669
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
666
670
|
amountInUsd: data.amountInUsd,
|
|
667
|
-
|
|
671
|
+
// Input USD stays the same
|
|
672
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
668
673
|
tokenIn: {
|
|
669
674
|
address: params.tokenIn.address,
|
|
670
675
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -680,7 +685,8 @@ async function getQuote(params) {
|
|
|
680
685
|
slippage: slippagePercent,
|
|
681
686
|
internal: {
|
|
682
687
|
...data,
|
|
683
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
688
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
689
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
684
690
|
},
|
|
685
691
|
warning
|
|
686
692
|
};
|
package/dist/react.js
CHANGED
|
@@ -630,7 +630,7 @@ async function getQuote(params) {
|
|
|
630
630
|
tokenOut: params.tokenOut.address,
|
|
631
631
|
amount: params.amount
|
|
632
632
|
});
|
|
633
|
-
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.
|
|
633
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
634
634
|
let warning;
|
|
635
635
|
if (slippagePercent > 10) {
|
|
636
636
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
@@ -638,12 +638,17 @@ async function getQuote(params) {
|
|
|
638
638
|
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
639
639
|
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
640
640
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
641
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
642
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
643
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
644
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
641
645
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
642
646
|
return {
|
|
643
|
-
amountOut:
|
|
644
|
-
amountOutUsd:
|
|
647
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
648
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
645
649
|
amountInUsd: data.amountInUsd,
|
|
646
|
-
|
|
650
|
+
// Input USD stays the same
|
|
651
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
647
652
|
tokenIn: {
|
|
648
653
|
address: params.tokenIn.address,
|
|
649
654
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -659,7 +664,8 @@ async function getQuote(params) {
|
|
|
659
664
|
slippage: slippagePercent,
|
|
660
665
|
internal: {
|
|
661
666
|
...data,
|
|
662
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
667
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
668
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
663
669
|
},
|
|
664
670
|
warning
|
|
665
671
|
};
|