Skip to content

Commit

Permalink
Update example to reproduce swap with join/exit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoguerios committed Mar 1, 2024
1 parent 004f86a commit 2dea410
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions test/testScripts/swapExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ function setUp(networkId: Network, provider: JsonRpcProvider): SOR {
}

export async function swap(): Promise<void> {
const networkId = Network.ARBITRUM;
const networkId = Network.MAINNET;
const provider = new JsonRpcProvider(PROVIDER_URLS[networkId]);
// gasPrice is used by SOR as a factor to determine how many pools to swap against.
// i.e. higher cost means more costly to trade against lots of different pools.
const gasPrice = BigNumber.from('14000000000');
// This determines the max no of pools the SOR will use to swap.
const maxPools = 4;

Check warning on line 68 in test/testScripts/swapExample.ts

View workflow job for this annotation

GitHub Actions / lint

'maxPools' is assigned a value but never used
const tokenIn = ADDRESSES[networkId].USDT;
const tokenOut = ADDRESSES[networkId].sfrxETH;
const tokenIn = ADDRESSES[networkId].BAL80WETH20;
const tokenOut = ADDRESSES[networkId].USDC;
const swapType: SwapTypes = SwapTypes.SwapExactIn;
const swapAmount = parseFixed('100', tokenIn.decimals);
const swapAmount = parseFixed('17', tokenIn.decimals);

const sor = setUp(networkId, provider);

Expand All @@ -82,8 +82,8 @@ export async function swap(): Promise<void> {
tokenOut.address,
swapType,
swapAmount,
{ gasPrice, maxPools },
false
undefined,
true
);

// Simulate the swap transaction
Expand All @@ -104,41 +104,41 @@ export async function swap(): Promise<void> {
tx.limits
);

if (![tokenIn, tokenOut].includes(ADDRESSES[networkId].STETH)) {
console.log('VAULT SWAP');
const vaultContract = new Contract(
vaultAddr,
vaultArtifact,
provider
);
// Simulates a call to `batchSwap`, returning an array of Vault asset deltas.
// Each element in the array corresponds to the asset at the same index, and indicates the number of tokens(or ETH)
// the Vault would take from the sender(if positive) or send to the recipient(if negative).
const deltas = await vaultContract.queryBatchSwap(
swapType,
swapInfo.swaps,
swapInfo.tokenAddresses,
tx.funds
);
console.log(deltas.toString());
// To actually make the trade:
// vaultContract.connect(wallet);
// const tx = await vaultContract
// .connect(wallet)
// .batchSwap(
// swapType,
// swapInfo.swaps,
// swapInfo.tokenAddresses,
// tx.funds,
// tx.limits,
// tx.deadline,
// tx.overRides
// );
// if (![tokenIn, tokenOut].includes(ADDRESSES[networkId].STETH)) {
// console.log('VAULT SWAP');
// const vaultContract = new Contract(
// vaultAddr,
// vaultArtifact,
// provider
// );
// // Simulates a call to `batchSwap`, returning an array of Vault asset deltas.
// // Each element in the array corresponds to the asset at the same index, and indicates the number of tokens(or ETH)
// // the Vault would take from the sender(if positive) or send to the recipient(if negative).
// const deltas = await vaultContract.queryBatchSwap(
// swapType,
// swapInfo.swaps,
// swapInfo.tokenAddresses,
// tx.funds
// );
// console.log(deltas.toString());
// // To actually make the trade:
// // vaultContract.connect(wallet);
// // const tx = await vaultContract
// // .connect(wallet)
// // .batchSwap(
// // swapType,
// // swapInfo.swaps,
// // swapInfo.tokenAddresses,
// // tx.funds,
// // tx.limits,
// // tx.deadline,
// // tx.overRides
// // );

// console.log(`tx: ${tx}`);
} else {
console.log('RELAYER SWAP - Execute via batchRelayer.');
}
// // console.log(`tx: ${tx}`);
// } else {
// console.log('RELAYER SWAP - Execute via batchRelayer.');
// }
} else {
console.log('No Valid Swap');
await printOutput(
Expand Down

0 comments on commit 2dea410

Please sign in to comment.