@shogun-sdk/swap 0.0.2-test.40 → 0.0.2-test.41
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 +52 -23
- package/dist/core.js +52 -23
- package/dist/index.cjs +52 -23
- package/dist/index.js +52 -23
- package/dist/react.cjs +52 -23
- package/dist/react.js +52 -23
- package/package.json +2 -2
package/dist/core.cjs
CHANGED
|
@@ -192,33 +192,62 @@ async function getQuote(params) {
|
|
|
192
192
|
if (amount <= 0n) {
|
|
193
193
|
throw new Error("Amount must be greater than 0.");
|
|
194
194
|
}
|
|
195
|
-
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
196
|
-
const data = await import_intents_sdk3.QuoteProvider.getQuote({
|
|
197
|
-
sourceChainId: params.sourceChainId,
|
|
198
|
-
destChainId: params.destChainId,
|
|
199
|
-
tokenIn: normalizedTokenIn,
|
|
200
|
-
tokenOut: params.tokenOut.address,
|
|
201
|
-
amount
|
|
202
|
-
});
|
|
203
195
|
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
196
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
197
|
+
const applyUserSlippage = (value) => value * (10000n - slippageBps) / 10000n;
|
|
204
198
|
let warning;
|
|
205
199
|
if (slippagePercent > 10) {
|
|
206
200
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
207
201
|
}
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
202
|
+
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
203
|
+
const isSingleChain = params.sourceChainId === params.destChainId;
|
|
204
|
+
let data;
|
|
205
|
+
let netFloor;
|
|
206
|
+
let minStablecoinsAmount;
|
|
207
|
+
if (isSingleChain) {
|
|
208
|
+
const { quote, netAmountOut } = await import_intents_sdk3.QuoteProvider.getSingleChainNetQuote({
|
|
209
|
+
chainId: params.sourceChainId,
|
|
210
|
+
amount,
|
|
211
|
+
tokenIn: normalizedTokenIn,
|
|
212
|
+
tokenOut: params.tokenOut.address
|
|
213
|
+
});
|
|
214
|
+
netFloor = netAmountOut;
|
|
215
|
+
minStablecoinsAmount = 0n;
|
|
216
|
+
data = {
|
|
217
|
+
amountInUsd: quote.amountInUsd,
|
|
218
|
+
estimatedAmountInAsMinStablecoinAmount: 0n,
|
|
219
|
+
estimatedAmountOut: quote.amountOut,
|
|
220
|
+
estimatedAmountOutUsd: quote.amountOutUsd,
|
|
221
|
+
// filled in below once the user slippage buffer is known
|
|
222
|
+
estimatedAmountOutReduced: netAmountOut,
|
|
223
|
+
estimatedAmountOutUsdReduced: quote.amountOutUsd,
|
|
224
|
+
tokenIn: { address: params.tokenIn.address, chainId: params.sourceChainId },
|
|
225
|
+
tokenOut: { address: params.tokenOut.address, chainId: params.destChainId }
|
|
226
|
+
};
|
|
227
|
+
} else {
|
|
228
|
+
const crossChainQuote = await import_intents_sdk3.QuoteProvider.getCrossChainNetQuote({
|
|
229
|
+
sourceChainId: params.sourceChainId,
|
|
230
|
+
destChainId: params.destChainId,
|
|
231
|
+
tokenIn: normalizedTokenIn,
|
|
232
|
+
tokenOut: params.tokenOut.address,
|
|
233
|
+
amount
|
|
234
|
+
});
|
|
235
|
+
data = crossChainQuote;
|
|
236
|
+
netFloor = BigInt(crossChainQuote.estimatedAmountOutReduced);
|
|
237
|
+
minStablecoinsAmount = applyUserSlippage(
|
|
238
|
+
BigInt(crossChainQuote.estimatedAmountInAsMinStablecoinAmount)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
const amountOut = applyUserSlippage(netFloor);
|
|
242
|
+
const grossAmountOut = BigInt(data.estimatedAmountOut);
|
|
243
|
+
const pricePerTokenOutInUsd = grossAmountOut > 0n ? data.estimatedAmountOutUsd / Number(grossAmountOut) : 0;
|
|
244
|
+
const amountOutUsd = Number(amountOut) * pricePerTokenOutInUsd;
|
|
245
|
+
const pricePerInputToken = grossAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / amount;
|
|
216
246
|
return {
|
|
217
|
-
amountOut
|
|
218
|
-
amountOutUsd
|
|
247
|
+
amountOut,
|
|
248
|
+
amountOutUsd,
|
|
219
249
|
amountInUsd: data.amountInUsd,
|
|
220
|
-
|
|
221
|
-
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
250
|
+
minStablecoinsAmount,
|
|
222
251
|
tokenIn: {
|
|
223
252
|
address: params.tokenIn.address,
|
|
224
253
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -229,13 +258,13 @@ async function getQuote(params) {
|
|
|
229
258
|
decimals: params.tokenOut.decimals ?? 18,
|
|
230
259
|
chainId: params.destChainId
|
|
231
260
|
},
|
|
232
|
-
amountIn:
|
|
261
|
+
amountIn: amount,
|
|
233
262
|
pricePerInputToken,
|
|
234
263
|
slippage: slippagePercent,
|
|
235
264
|
internal: {
|
|
236
265
|
...data,
|
|
237
|
-
estimatedAmountOutReduced:
|
|
238
|
-
estimatedAmountOutUsdReduced:
|
|
266
|
+
estimatedAmountOutReduced: amountOut,
|
|
267
|
+
estimatedAmountOutUsdReduced: amountOutUsd
|
|
239
268
|
},
|
|
240
269
|
warning
|
|
241
270
|
};
|
package/dist/core.js
CHANGED
|
@@ -163,33 +163,62 @@ async function getQuote(params) {
|
|
|
163
163
|
if (amount <= 0n) {
|
|
164
164
|
throw new Error("Amount must be greater than 0.");
|
|
165
165
|
}
|
|
166
|
-
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
167
|
-
const data = await QuoteProvider.getQuote({
|
|
168
|
-
sourceChainId: params.sourceChainId,
|
|
169
|
-
destChainId: params.destChainId,
|
|
170
|
-
tokenIn: normalizedTokenIn,
|
|
171
|
-
tokenOut: params.tokenOut.address,
|
|
172
|
-
amount
|
|
173
|
-
});
|
|
174
166
|
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
167
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
168
|
+
const applyUserSlippage = (value) => value * (10000n - slippageBps) / 10000n;
|
|
175
169
|
let warning;
|
|
176
170
|
if (slippagePercent > 10) {
|
|
177
171
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
178
172
|
}
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
174
|
+
const isSingleChain = params.sourceChainId === params.destChainId;
|
|
175
|
+
let data;
|
|
176
|
+
let netFloor;
|
|
177
|
+
let minStablecoinsAmount;
|
|
178
|
+
if (isSingleChain) {
|
|
179
|
+
const { quote, netAmountOut } = await QuoteProvider.getSingleChainNetQuote({
|
|
180
|
+
chainId: params.sourceChainId,
|
|
181
|
+
amount,
|
|
182
|
+
tokenIn: normalizedTokenIn,
|
|
183
|
+
tokenOut: params.tokenOut.address
|
|
184
|
+
});
|
|
185
|
+
netFloor = netAmountOut;
|
|
186
|
+
minStablecoinsAmount = 0n;
|
|
187
|
+
data = {
|
|
188
|
+
amountInUsd: quote.amountInUsd,
|
|
189
|
+
estimatedAmountInAsMinStablecoinAmount: 0n,
|
|
190
|
+
estimatedAmountOut: quote.amountOut,
|
|
191
|
+
estimatedAmountOutUsd: quote.amountOutUsd,
|
|
192
|
+
// filled in below once the user slippage buffer is known
|
|
193
|
+
estimatedAmountOutReduced: netAmountOut,
|
|
194
|
+
estimatedAmountOutUsdReduced: quote.amountOutUsd,
|
|
195
|
+
tokenIn: { address: params.tokenIn.address, chainId: params.sourceChainId },
|
|
196
|
+
tokenOut: { address: params.tokenOut.address, chainId: params.destChainId }
|
|
197
|
+
};
|
|
198
|
+
} else {
|
|
199
|
+
const crossChainQuote = await QuoteProvider.getCrossChainNetQuote({
|
|
200
|
+
sourceChainId: params.sourceChainId,
|
|
201
|
+
destChainId: params.destChainId,
|
|
202
|
+
tokenIn: normalizedTokenIn,
|
|
203
|
+
tokenOut: params.tokenOut.address,
|
|
204
|
+
amount
|
|
205
|
+
});
|
|
206
|
+
data = crossChainQuote;
|
|
207
|
+
netFloor = BigInt(crossChainQuote.estimatedAmountOutReduced);
|
|
208
|
+
minStablecoinsAmount = applyUserSlippage(
|
|
209
|
+
BigInt(crossChainQuote.estimatedAmountInAsMinStablecoinAmount)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const amountOut = applyUserSlippage(netFloor);
|
|
213
|
+
const grossAmountOut = BigInt(data.estimatedAmountOut);
|
|
214
|
+
const pricePerTokenOutInUsd = grossAmountOut > 0n ? data.estimatedAmountOutUsd / Number(grossAmountOut) : 0;
|
|
215
|
+
const amountOutUsd = Number(amountOut) * pricePerTokenOutInUsd;
|
|
216
|
+
const pricePerInputToken = grossAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / amount;
|
|
187
217
|
return {
|
|
188
|
-
amountOut
|
|
189
|
-
amountOutUsd
|
|
218
|
+
amountOut,
|
|
219
|
+
amountOutUsd,
|
|
190
220
|
amountInUsd: data.amountInUsd,
|
|
191
|
-
|
|
192
|
-
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
221
|
+
minStablecoinsAmount,
|
|
193
222
|
tokenIn: {
|
|
194
223
|
address: params.tokenIn.address,
|
|
195
224
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -200,13 +229,13 @@ async function getQuote(params) {
|
|
|
200
229
|
decimals: params.tokenOut.decimals ?? 18,
|
|
201
230
|
chainId: params.destChainId
|
|
202
231
|
},
|
|
203
|
-
amountIn:
|
|
232
|
+
amountIn: amount,
|
|
204
233
|
pricePerInputToken,
|
|
205
234
|
slippage: slippagePercent,
|
|
206
235
|
internal: {
|
|
207
236
|
...data,
|
|
208
|
-
estimatedAmountOutReduced:
|
|
209
|
-
estimatedAmountOutUsdReduced:
|
|
237
|
+
estimatedAmountOutReduced: amountOut,
|
|
238
|
+
estimatedAmountOutUsdReduced: amountOutUsd
|
|
210
239
|
},
|
|
211
240
|
warning
|
|
212
241
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -192,33 +192,62 @@ async function getQuote(params) {
|
|
|
192
192
|
if (amount <= 0n) {
|
|
193
193
|
throw new Error("Amount must be greater than 0.");
|
|
194
194
|
}
|
|
195
|
-
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
196
|
-
const data = await import_intents_sdk3.QuoteProvider.getQuote({
|
|
197
|
-
sourceChainId: params.sourceChainId,
|
|
198
|
-
destChainId: params.destChainId,
|
|
199
|
-
tokenIn: normalizedTokenIn,
|
|
200
|
-
tokenOut: params.tokenOut.address,
|
|
201
|
-
amount
|
|
202
|
-
});
|
|
203
195
|
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
196
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
197
|
+
const applyUserSlippage = (value) => value * (10000n - slippageBps) / 10000n;
|
|
204
198
|
let warning;
|
|
205
199
|
if (slippagePercent > 10) {
|
|
206
200
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
207
201
|
}
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
202
|
+
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
203
|
+
const isSingleChain = params.sourceChainId === params.destChainId;
|
|
204
|
+
let data;
|
|
205
|
+
let netFloor;
|
|
206
|
+
let minStablecoinsAmount;
|
|
207
|
+
if (isSingleChain) {
|
|
208
|
+
const { quote, netAmountOut } = await import_intents_sdk3.QuoteProvider.getSingleChainNetQuote({
|
|
209
|
+
chainId: params.sourceChainId,
|
|
210
|
+
amount,
|
|
211
|
+
tokenIn: normalizedTokenIn,
|
|
212
|
+
tokenOut: params.tokenOut.address
|
|
213
|
+
});
|
|
214
|
+
netFloor = netAmountOut;
|
|
215
|
+
minStablecoinsAmount = 0n;
|
|
216
|
+
data = {
|
|
217
|
+
amountInUsd: quote.amountInUsd,
|
|
218
|
+
estimatedAmountInAsMinStablecoinAmount: 0n,
|
|
219
|
+
estimatedAmountOut: quote.amountOut,
|
|
220
|
+
estimatedAmountOutUsd: quote.amountOutUsd,
|
|
221
|
+
// filled in below once the user slippage buffer is known
|
|
222
|
+
estimatedAmountOutReduced: netAmountOut,
|
|
223
|
+
estimatedAmountOutUsdReduced: quote.amountOutUsd,
|
|
224
|
+
tokenIn: { address: params.tokenIn.address, chainId: params.sourceChainId },
|
|
225
|
+
tokenOut: { address: params.tokenOut.address, chainId: params.destChainId }
|
|
226
|
+
};
|
|
227
|
+
} else {
|
|
228
|
+
const crossChainQuote = await import_intents_sdk3.QuoteProvider.getCrossChainNetQuote({
|
|
229
|
+
sourceChainId: params.sourceChainId,
|
|
230
|
+
destChainId: params.destChainId,
|
|
231
|
+
tokenIn: normalizedTokenIn,
|
|
232
|
+
tokenOut: params.tokenOut.address,
|
|
233
|
+
amount
|
|
234
|
+
});
|
|
235
|
+
data = crossChainQuote;
|
|
236
|
+
netFloor = BigInt(crossChainQuote.estimatedAmountOutReduced);
|
|
237
|
+
minStablecoinsAmount = applyUserSlippage(
|
|
238
|
+
BigInt(crossChainQuote.estimatedAmountInAsMinStablecoinAmount)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
const amountOut = applyUserSlippage(netFloor);
|
|
242
|
+
const grossAmountOut = BigInt(data.estimatedAmountOut);
|
|
243
|
+
const pricePerTokenOutInUsd = grossAmountOut > 0n ? data.estimatedAmountOutUsd / Number(grossAmountOut) : 0;
|
|
244
|
+
const amountOutUsd = Number(amountOut) * pricePerTokenOutInUsd;
|
|
245
|
+
const pricePerInputToken = grossAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / amount;
|
|
216
246
|
return {
|
|
217
|
-
amountOut
|
|
218
|
-
amountOutUsd
|
|
247
|
+
amountOut,
|
|
248
|
+
amountOutUsd,
|
|
219
249
|
amountInUsd: data.amountInUsd,
|
|
220
|
-
|
|
221
|
-
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
250
|
+
minStablecoinsAmount,
|
|
222
251
|
tokenIn: {
|
|
223
252
|
address: params.tokenIn.address,
|
|
224
253
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -229,13 +258,13 @@ async function getQuote(params) {
|
|
|
229
258
|
decimals: params.tokenOut.decimals ?? 18,
|
|
230
259
|
chainId: params.destChainId
|
|
231
260
|
},
|
|
232
|
-
amountIn:
|
|
261
|
+
amountIn: amount,
|
|
233
262
|
pricePerInputToken,
|
|
234
263
|
slippage: slippagePercent,
|
|
235
264
|
internal: {
|
|
236
265
|
...data,
|
|
237
|
-
estimatedAmountOutReduced:
|
|
238
|
-
estimatedAmountOutUsdReduced:
|
|
266
|
+
estimatedAmountOutReduced: amountOut,
|
|
267
|
+
estimatedAmountOutUsdReduced: amountOutUsd
|
|
239
268
|
},
|
|
240
269
|
warning
|
|
241
270
|
};
|
package/dist/index.js
CHANGED
|
@@ -163,33 +163,62 @@ async function getQuote(params) {
|
|
|
163
163
|
if (amount <= 0n) {
|
|
164
164
|
throw new Error("Amount must be greater than 0.");
|
|
165
165
|
}
|
|
166
|
-
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
167
|
-
const data = await QuoteProvider.getQuote({
|
|
168
|
-
sourceChainId: params.sourceChainId,
|
|
169
|
-
destChainId: params.destChainId,
|
|
170
|
-
tokenIn: normalizedTokenIn,
|
|
171
|
-
tokenOut: params.tokenOut.address,
|
|
172
|
-
amount
|
|
173
|
-
});
|
|
174
166
|
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
167
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
168
|
+
const applyUserSlippage = (value) => value * (10000n - slippageBps) / 10000n;
|
|
175
169
|
let warning;
|
|
176
170
|
if (slippagePercent > 10) {
|
|
177
171
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
178
172
|
}
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
174
|
+
const isSingleChain = params.sourceChainId === params.destChainId;
|
|
175
|
+
let data;
|
|
176
|
+
let netFloor;
|
|
177
|
+
let minStablecoinsAmount;
|
|
178
|
+
if (isSingleChain) {
|
|
179
|
+
const { quote, netAmountOut } = await QuoteProvider.getSingleChainNetQuote({
|
|
180
|
+
chainId: params.sourceChainId,
|
|
181
|
+
amount,
|
|
182
|
+
tokenIn: normalizedTokenIn,
|
|
183
|
+
tokenOut: params.tokenOut.address
|
|
184
|
+
});
|
|
185
|
+
netFloor = netAmountOut;
|
|
186
|
+
minStablecoinsAmount = 0n;
|
|
187
|
+
data = {
|
|
188
|
+
amountInUsd: quote.amountInUsd,
|
|
189
|
+
estimatedAmountInAsMinStablecoinAmount: 0n,
|
|
190
|
+
estimatedAmountOut: quote.amountOut,
|
|
191
|
+
estimatedAmountOutUsd: quote.amountOutUsd,
|
|
192
|
+
// filled in below once the user slippage buffer is known
|
|
193
|
+
estimatedAmountOutReduced: netAmountOut,
|
|
194
|
+
estimatedAmountOutUsdReduced: quote.amountOutUsd,
|
|
195
|
+
tokenIn: { address: params.tokenIn.address, chainId: params.sourceChainId },
|
|
196
|
+
tokenOut: { address: params.tokenOut.address, chainId: params.destChainId }
|
|
197
|
+
};
|
|
198
|
+
} else {
|
|
199
|
+
const crossChainQuote = await QuoteProvider.getCrossChainNetQuote({
|
|
200
|
+
sourceChainId: params.sourceChainId,
|
|
201
|
+
destChainId: params.destChainId,
|
|
202
|
+
tokenIn: normalizedTokenIn,
|
|
203
|
+
tokenOut: params.tokenOut.address,
|
|
204
|
+
amount
|
|
205
|
+
});
|
|
206
|
+
data = crossChainQuote;
|
|
207
|
+
netFloor = BigInt(crossChainQuote.estimatedAmountOutReduced);
|
|
208
|
+
minStablecoinsAmount = applyUserSlippage(
|
|
209
|
+
BigInt(crossChainQuote.estimatedAmountInAsMinStablecoinAmount)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const amountOut = applyUserSlippage(netFloor);
|
|
213
|
+
const grossAmountOut = BigInt(data.estimatedAmountOut);
|
|
214
|
+
const pricePerTokenOutInUsd = grossAmountOut > 0n ? data.estimatedAmountOutUsd / Number(grossAmountOut) : 0;
|
|
215
|
+
const amountOutUsd = Number(amountOut) * pricePerTokenOutInUsd;
|
|
216
|
+
const pricePerInputToken = grossAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / amount;
|
|
187
217
|
return {
|
|
188
|
-
amountOut
|
|
189
|
-
amountOutUsd
|
|
218
|
+
amountOut,
|
|
219
|
+
amountOutUsd,
|
|
190
220
|
amountInUsd: data.amountInUsd,
|
|
191
|
-
|
|
192
|
-
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
221
|
+
minStablecoinsAmount,
|
|
193
222
|
tokenIn: {
|
|
194
223
|
address: params.tokenIn.address,
|
|
195
224
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -200,13 +229,13 @@ async function getQuote(params) {
|
|
|
200
229
|
decimals: params.tokenOut.decimals ?? 18,
|
|
201
230
|
chainId: params.destChainId
|
|
202
231
|
},
|
|
203
|
-
amountIn:
|
|
232
|
+
amountIn: amount,
|
|
204
233
|
pricePerInputToken,
|
|
205
234
|
slippage: slippagePercent,
|
|
206
235
|
internal: {
|
|
207
236
|
...data,
|
|
208
|
-
estimatedAmountOutReduced:
|
|
209
|
-
estimatedAmountOutUsdReduced:
|
|
237
|
+
estimatedAmountOutReduced: amountOut,
|
|
238
|
+
estimatedAmountOutUsdReduced: amountOutUsd
|
|
210
239
|
},
|
|
211
240
|
warning
|
|
212
241
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -213,33 +213,62 @@ async function getQuote(params) {
|
|
|
213
213
|
if (amount <= 0n) {
|
|
214
214
|
throw new Error("Amount must be greater than 0.");
|
|
215
215
|
}
|
|
216
|
-
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
217
|
-
const data = await import_intents_sdk3.QuoteProvider.getQuote({
|
|
218
|
-
sourceChainId: params.sourceChainId,
|
|
219
|
-
destChainId: params.destChainId,
|
|
220
|
-
tokenIn: normalizedTokenIn,
|
|
221
|
-
tokenOut: params.tokenOut.address,
|
|
222
|
-
amount
|
|
223
|
-
});
|
|
224
216
|
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
217
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
218
|
+
const applyUserSlippage = (value) => value * (10000n - slippageBps) / 10000n;
|
|
225
219
|
let warning;
|
|
226
220
|
if (slippagePercent > 10) {
|
|
227
221
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
228
222
|
}
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
223
|
+
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
224
|
+
const isSingleChain = params.sourceChainId === params.destChainId;
|
|
225
|
+
let data;
|
|
226
|
+
let netFloor;
|
|
227
|
+
let minStablecoinsAmount;
|
|
228
|
+
if (isSingleChain) {
|
|
229
|
+
const { quote, netAmountOut } = await import_intents_sdk3.QuoteProvider.getSingleChainNetQuote({
|
|
230
|
+
chainId: params.sourceChainId,
|
|
231
|
+
amount,
|
|
232
|
+
tokenIn: normalizedTokenIn,
|
|
233
|
+
tokenOut: params.tokenOut.address
|
|
234
|
+
});
|
|
235
|
+
netFloor = netAmountOut;
|
|
236
|
+
minStablecoinsAmount = 0n;
|
|
237
|
+
data = {
|
|
238
|
+
amountInUsd: quote.amountInUsd,
|
|
239
|
+
estimatedAmountInAsMinStablecoinAmount: 0n,
|
|
240
|
+
estimatedAmountOut: quote.amountOut,
|
|
241
|
+
estimatedAmountOutUsd: quote.amountOutUsd,
|
|
242
|
+
// filled in below once the user slippage buffer is known
|
|
243
|
+
estimatedAmountOutReduced: netAmountOut,
|
|
244
|
+
estimatedAmountOutUsdReduced: quote.amountOutUsd,
|
|
245
|
+
tokenIn: { address: params.tokenIn.address, chainId: params.sourceChainId },
|
|
246
|
+
tokenOut: { address: params.tokenOut.address, chainId: params.destChainId }
|
|
247
|
+
};
|
|
248
|
+
} else {
|
|
249
|
+
const crossChainQuote = await import_intents_sdk3.QuoteProvider.getCrossChainNetQuote({
|
|
250
|
+
sourceChainId: params.sourceChainId,
|
|
251
|
+
destChainId: params.destChainId,
|
|
252
|
+
tokenIn: normalizedTokenIn,
|
|
253
|
+
tokenOut: params.tokenOut.address,
|
|
254
|
+
amount
|
|
255
|
+
});
|
|
256
|
+
data = crossChainQuote;
|
|
257
|
+
netFloor = BigInt(crossChainQuote.estimatedAmountOutReduced);
|
|
258
|
+
minStablecoinsAmount = applyUserSlippage(
|
|
259
|
+
BigInt(crossChainQuote.estimatedAmountInAsMinStablecoinAmount)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
const amountOut = applyUserSlippage(netFloor);
|
|
263
|
+
const grossAmountOut = BigInt(data.estimatedAmountOut);
|
|
264
|
+
const pricePerTokenOutInUsd = grossAmountOut > 0n ? data.estimatedAmountOutUsd / Number(grossAmountOut) : 0;
|
|
265
|
+
const amountOutUsd = Number(amountOut) * pricePerTokenOutInUsd;
|
|
266
|
+
const pricePerInputToken = grossAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / amount;
|
|
237
267
|
return {
|
|
238
|
-
amountOut
|
|
239
|
-
amountOutUsd
|
|
268
|
+
amountOut,
|
|
269
|
+
amountOutUsd,
|
|
240
270
|
amountInUsd: data.amountInUsd,
|
|
241
|
-
|
|
242
|
-
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
271
|
+
minStablecoinsAmount,
|
|
243
272
|
tokenIn: {
|
|
244
273
|
address: params.tokenIn.address,
|
|
245
274
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -250,13 +279,13 @@ async function getQuote(params) {
|
|
|
250
279
|
decimals: params.tokenOut.decimals ?? 18,
|
|
251
280
|
chainId: params.destChainId
|
|
252
281
|
},
|
|
253
|
-
amountIn:
|
|
282
|
+
amountIn: amount,
|
|
254
283
|
pricePerInputToken,
|
|
255
284
|
slippage: slippagePercent,
|
|
256
285
|
internal: {
|
|
257
286
|
...data,
|
|
258
|
-
estimatedAmountOutReduced:
|
|
259
|
-
estimatedAmountOutUsdReduced:
|
|
287
|
+
estimatedAmountOutReduced: amountOut,
|
|
288
|
+
estimatedAmountOutUsdReduced: amountOutUsd
|
|
260
289
|
},
|
|
261
290
|
warning
|
|
262
291
|
};
|
package/dist/react.js
CHANGED
|
@@ -166,33 +166,62 @@ async function getQuote(params) {
|
|
|
166
166
|
if (amount <= 0n) {
|
|
167
167
|
throw new Error("Amount must be greater than 0.");
|
|
168
168
|
}
|
|
169
|
-
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
170
|
-
const data = await QuoteProvider.getQuote({
|
|
171
|
-
sourceChainId: params.sourceChainId,
|
|
172
|
-
destChainId: params.destChainId,
|
|
173
|
-
tokenIn: normalizedTokenIn,
|
|
174
|
-
tokenOut: params.tokenOut.address,
|
|
175
|
-
amount
|
|
176
|
-
});
|
|
177
169
|
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
170
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
171
|
+
const applyUserSlippage = (value) => value * (10000n - slippageBps) / 10000n;
|
|
178
172
|
let warning;
|
|
179
173
|
if (slippagePercent > 10) {
|
|
180
174
|
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
181
175
|
}
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
177
|
+
const isSingleChain = params.sourceChainId === params.destChainId;
|
|
178
|
+
let data;
|
|
179
|
+
let netFloor;
|
|
180
|
+
let minStablecoinsAmount;
|
|
181
|
+
if (isSingleChain) {
|
|
182
|
+
const { quote, netAmountOut } = await QuoteProvider.getSingleChainNetQuote({
|
|
183
|
+
chainId: params.sourceChainId,
|
|
184
|
+
amount,
|
|
185
|
+
tokenIn: normalizedTokenIn,
|
|
186
|
+
tokenOut: params.tokenOut.address
|
|
187
|
+
});
|
|
188
|
+
netFloor = netAmountOut;
|
|
189
|
+
minStablecoinsAmount = 0n;
|
|
190
|
+
data = {
|
|
191
|
+
amountInUsd: quote.amountInUsd,
|
|
192
|
+
estimatedAmountInAsMinStablecoinAmount: 0n,
|
|
193
|
+
estimatedAmountOut: quote.amountOut,
|
|
194
|
+
estimatedAmountOutUsd: quote.amountOutUsd,
|
|
195
|
+
// filled in below once the user slippage buffer is known
|
|
196
|
+
estimatedAmountOutReduced: netAmountOut,
|
|
197
|
+
estimatedAmountOutUsdReduced: quote.amountOutUsd,
|
|
198
|
+
tokenIn: { address: params.tokenIn.address, chainId: params.sourceChainId },
|
|
199
|
+
tokenOut: { address: params.tokenOut.address, chainId: params.destChainId }
|
|
200
|
+
};
|
|
201
|
+
} else {
|
|
202
|
+
const crossChainQuote = await QuoteProvider.getCrossChainNetQuote({
|
|
203
|
+
sourceChainId: params.sourceChainId,
|
|
204
|
+
destChainId: params.destChainId,
|
|
205
|
+
tokenIn: normalizedTokenIn,
|
|
206
|
+
tokenOut: params.tokenOut.address,
|
|
207
|
+
amount
|
|
208
|
+
});
|
|
209
|
+
data = crossChainQuote;
|
|
210
|
+
netFloor = BigInt(crossChainQuote.estimatedAmountOutReduced);
|
|
211
|
+
minStablecoinsAmount = applyUserSlippage(
|
|
212
|
+
BigInt(crossChainQuote.estimatedAmountInAsMinStablecoinAmount)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
const amountOut = applyUserSlippage(netFloor);
|
|
216
|
+
const grossAmountOut = BigInt(data.estimatedAmountOut);
|
|
217
|
+
const pricePerTokenOutInUsd = grossAmountOut > 0n ? data.estimatedAmountOutUsd / Number(grossAmountOut) : 0;
|
|
218
|
+
const amountOutUsd = Number(amountOut) * pricePerTokenOutInUsd;
|
|
219
|
+
const pricePerInputToken = grossAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / amount;
|
|
190
220
|
return {
|
|
191
|
-
amountOut
|
|
192
|
-
amountOutUsd
|
|
221
|
+
amountOut,
|
|
222
|
+
amountOutUsd,
|
|
193
223
|
amountInUsd: data.amountInUsd,
|
|
194
|
-
|
|
195
|
-
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
224
|
+
minStablecoinsAmount,
|
|
196
225
|
tokenIn: {
|
|
197
226
|
address: params.tokenIn.address,
|
|
198
227
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -203,13 +232,13 @@ async function getQuote(params) {
|
|
|
203
232
|
decimals: params.tokenOut.decimals ?? 18,
|
|
204
233
|
chainId: params.destChainId
|
|
205
234
|
},
|
|
206
|
-
amountIn:
|
|
235
|
+
amountIn: amount,
|
|
207
236
|
pricePerInputToken,
|
|
208
237
|
slippage: slippagePercent,
|
|
209
238
|
internal: {
|
|
210
239
|
...data,
|
|
211
|
-
estimatedAmountOutReduced:
|
|
212
|
-
estimatedAmountOutUsdReduced:
|
|
240
|
+
estimatedAmountOutReduced: amountOut,
|
|
241
|
+
estimatedAmountOutUsdReduced: amountOutUsd
|
|
213
242
|
},
|
|
214
243
|
warning
|
|
215
244
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shogun-sdk/swap",
|
|
3
|
-
"version": "0.0.2-test.
|
|
3
|
+
"version": "0.0.2-test.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shogun Network Swap utilities and helpers",
|
|
6
6
|
"author": "Shogun Network",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"sideEffects": false,
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@solana/web3.js": "^1.98.4",
|
|
48
|
-
"@shogun-sdk/intents-sdk": "1.4.
|
|
48
|
+
"@shogun-sdk/intents-sdk": "1.4.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@ethersproject/abstract-signer": "^5.7.0",
|