Skip to content

Commit

Permalink
Minswap Optimization & new Features after Certik Audit (#35)
Browse files Browse the repository at this point in the history
* move Liquidity Pool logic to Pool batching Withdrawal contract (#31)

* move Liquidity Pool logic to Pool batching Withdrawal contract

* use inline datum for contracts except order

* refactor code

* add dynamic fee support

* fix test

* feat: support bidirectional fee (#32)

* allow order can decide its amount by specific amount or relying on amount in its value and update spec doc (#37)

* allow order can decide its amount by specific amount or relying on amount in its value and update spec doc

* strict datum type of sender and receiver

* add offchain testing (#40)

* add offchain testing

* remove unused file

* pump aiken ci

* support donation order [MIN-532] (#42)

* support donation order

* update spec

* change test admin policy id

* use 10000 as default fee denominator (#43)

* use 10000 as default fee denominator

* fix docs and comment

* handle global setting to store authorizer that can interact with pool contract (#45)

* fix initialization transaction

* Optimization from Anastasia Labs (#46)

* Optimization from Anastasia Labs

* adhoc compare swap value (#47)

* adhoc compare swap value

* add more comments

* resolve audit finding (#48)

* remove redundant code

* verify only pool script & author script (if have) is allowed on some pool's redeemers

* Test for math functions (#49)

* increase Pool Minimum ADA from 3 ADA to 4.5 ADA to buffer for ledger change and inline datum (#50)

* increase Pool Minimum ADA from 3 ADA to 4.5 ADA to buffer for ledger change and inline datum

* update script

---------

Co-authored-by: Minggggg <[email protected]>
  • Loading branch information
h2physics and m1n999999 authored Apr 16, 2024
1 parent dd5a3aa commit 6239e7e
Show file tree
Hide file tree
Showing 39 changed files with 11,694 additions and 1,745 deletions.
36 changes: 36 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json"],
},
plugins: [
"@typescript-eslint",
"simple-import-sort",
"unused-imports",
"unicorn",
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
eqeqeq: "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-floating-promises": "error",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "all",
argsIgnorePattern: "^_",
},
],
"no-console": "warn",
"unicorn/no-array-for-each": "error",
"unicorn/prefer-regexp-test": "error",
},
};
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: aiken-lang/[email protected]
with:
version: v1.0.21-alpha
version: v1.0.24-alpha

- run: aiken fmt --check
- run: aiken check
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ artifacts/
build/
# Aiken's default documentation export
docs/
node_modules
build
build-tsc
coverage
.idea
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": false,
"trailingComma": "es5"
}
462 changes: 271 additions & 191 deletions amm-v2-docs/amm-v2-specs.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amm-v2-docs/formula.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $$swap_{x} = \left\lfloor \frac{\sqrt{((2 - f) * X)^{2} - (1 - f) * Y} - (2 - f)
$$= \left\lfloor \frac{\sqrt{((2 * f_{d} - f_{n}) * X)^{2} - f_{d} * (f_{d} - f_{n}) * Y} - (2 * f_{d} - f_{n}) * X}{(f_{d} - f_{n}) * Z} \right\rfloor $$

The LP Token users receive is:
$$\Delta L = \frac{\Delta y + receive_{y}}{y_{0} - receive_{y}} * L$$
$$\Delta L = \frac{\Delta x - swap_{x}}{x_{0} + swap_{x}} * L$$

### 4. Withdraw
$$\Delta x = \frac{\Delta L}{L} * x_{0}$$
Expand Down
Binary file modified amm-v2-docs/pics/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 206 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

export default {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "/tmp/jest_rs",

// Automatically clear mock calls, instances, contexts and results before every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: "ts-jest/presets/default-esm",

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
roots: ["./test"],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ["./jest.setup.js"],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
"^.+\\.tsx?$": [
"ts-jest",
{
useESM: true,
},
],
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,

extensionsToTreatAsEsm: [".ts"],
};
3 changes: 3 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { jest } from "@jest/globals";

jest.setTimeout(30000);
Loading

0 comments on commit 6239e7e

Please sign in to comment.