Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import v3-sdk to ffi #682

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .forge-snapshots/removeLiquidity.snap

This file was deleted.

7 changes: 6 additions & 1 deletion test/js-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
},
"scripts": {
"forge-test-getSqrtPriceAtTick": "npx ts-node src/getSqrtPriceAtTick.ts",
"forge-test-getTickAtSqrtPrice": "npx ts-node src/getTickAtSqrtPrice.ts"
"forge-test-getTickAtSqrtPrice": "npx ts-node src/getTickAtSqrtPrice.ts",
"forge-test-mulDiv": "npx ts-node src/mulDiv.ts",
"forge-test-mulDivRoundingUp": "npx ts-node src/mulDivRoundingUp.ts"
},
"dependencies": {
"@uniswap/v3-sdk": "^3.11.2"
}
}
21 changes: 21 additions & 0 deletions test/js-scripts/src/mulDiv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import JSBI from 'jsbi'
import { ethers } from 'ethers'

// Run this script solo by: npm run forge-test-mulDiv "a,b,denominator"
// Read command line arguments
const args = process.argv[2].split(',');
const a = JSBI.BigInt(args[0])
const b = JSBI.BigInt(args[1])
const denominator = JSBI.BigInt(args[2])

// Perform mulDiv operation
const result = JSBI.divide(JSBI.multiply(a, b), denominator)

// Check if result is greater than uint256Max
const uint256Max = JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
if (JSBI.greaterThan(result, uint256Max)) {
process.stdout.write(ethers.utils.defaultAbiCoder.encode(['bool', 'uint256'], [false, 0]));
} else {
process.stdout.write(ethers.utils.defaultAbiCoder.encode(['bool', 'uint256'], [true, result.toString()]))
}

18 changes: 18 additions & 0 deletions test/js-scripts/src/mulDivRoundingUp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import JSBI from 'jsbi';
import { ethers } from 'ethers'
import { FullMath } from '@uniswap/v3-sdk';

const args = process.argv[2].split(',');
const a = JSBI.BigInt(args[0])
const b = JSBI.BigInt(args[1])
const denominator = JSBI.BigInt(args[2])

const result = FullMath.mulDivRoundingUp(a, b, denominator);

// Check if result is greater than uint256Max
const uint256Max = JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
if (JSBI.greaterThan(result, uint256Max)) {
process.stdout.write(ethers.utils.defaultAbiCoder.encode(['bool', 'uint256'], [false, 0]));
} else {
process.stdout.write(ethers.utils.defaultAbiCoder.encode(['bool', 'uint256'], [true, result.toString()]))
}
Loading
Loading