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