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

add change liquidity entrypoint #296

Merged
merged 10 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const main = async () => {
10 ** 24
try {
const poolSqrtPrice = priceToSqrtPrice(BigInt(Math.round(price)))
console.log(poolKey)
await invariant.createPool(account, poolKey, poolSqrtPrice)
} catch (e) {
console.log('Create pool error', poolKey, e)
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const main = async () => {
)
const firstSwapEvent = firstSwapResult.events[0] as SwapEvent
assert(firstSimualtion.globalInsufficientLiquidity === false)
assert(firstSimualtion.maxTicksCrossed === false)
assert(firstSimualtion.maxSwapStepsReached === false)
assert(firstSimualtion.stateOutdated === false)
assert(firstSimualtion.amountIn == firstSwapEvent.amountIn)
assert(firstSimualtion.amountOut == firstSwapEvent.amountOut)
Expand Down Expand Up @@ -117,7 +117,7 @@ const main = async () => {
)
const secondSwapEvent = secondSwapResult.events[0] as SwapEvent
assert(secondSimulation.globalInsufficientLiquidity === false)
assert(secondSimulation.maxTicksCrossed === false)
assert(secondSimulation.maxSwapStepsReached === false)
assert(secondSimulation.stateOutdated === false)
assert(secondSimulation.amountIn === secondSwapEvent.amountIn)
assert(secondSimulation.amountOut === secondSwapEvent.amountOut)
Expand Down
164 changes: 163 additions & 1 deletion sdk/contracts/invariant/invariant.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x4f19a0152491660087fd1d38d163ab436967e96ac14a07220133afc86e2bd9ec",
"hash": "0xcc659012169a620a3cd6565f4f6c238646150a3d846fc4849c1a5718f803cda5",
"language": "ink! 5.0.0",
"compiler": "rustc 1.77.0",
"build_info": {
Expand Down Expand Up @@ -176,6 +176,102 @@
"module_path": "invariant::contracts::events",
"signature_topic": "0x50a25822f8984babdbc09246e1d170630167a27235d98a5ff8ac7516a5cdab15"
},
{
"args": [
{
"docs": [],
"indexed": true,
"label": "timestamp",
"type": {
"displayName": [
"u64"
],
"type": 9
}
},
{
"docs": [],
"indexed": false,
"label": "address",
"type": {
"displayName": [
"AccountId"
],
"type": 2
}
},
{
"docs": [],
"indexed": false,
"label": "pool",
"type": {
"displayName": [
"PoolKey"
],
"type": 16
}
},
{
"docs": [],
"indexed": false,
"label": "delta_liquidity",
"type": {
"displayName": [
"Liquidity"
],
"type": 19
}
},
{
"docs": [],
"indexed": false,
"label": "add_liquidity",
"type": {
"displayName": [
"bool"
],
"type": 34
}
},
{
"docs": [],
"indexed": false,
"label": "lower_tick",
"type": {
"displayName": [
"i32"
],
"type": 12
}
},
{
"docs": [],
"indexed": false,
"label": "upper_tick",
"type": {
"displayName": [
"i32"
],
"type": 12
}
},
{
"docs": [],
"indexed": false,
"label": "current_sqrt_price",
"type": {
"displayName": [
"SqrtPrice"
],
"type": 27
}
}
],
"docs": [],
"label": "ChangeLiquidityEvent",
"module_path": "invariant::contracts::events",
"signature_topic": "0x46cd3c5dbfeaa26a33c451719cec81defa409942d31339858154c409c72b6d5a"
},
{
"args": [
{
Expand Down Expand Up @@ -701,6 +797,68 @@
},
"selector": "0x0a1ca76b"
},
{
"args": [
{
"label": "index",
"type": {
"displayName": [
"u32"
],
"type": 0
}
},
{
"label": "delta_liquidity",
"type": {
"displayName": [
"Liquidity"
],
"type": 19
}
},
{
"label": "add_liquidity",
"type": {
"displayName": [
"bool"
],
"type": 34
}
},
{
"label": "slippage_limit_lower",
"type": {
"displayName": [
"SqrtPrice"
],
"type": 27
}
},
{
"label": "slippage_limit_upper",
"type": {
"displayName": [
"SqrtPrice"
],
"type": 27
}
}
],
"default": false,
"docs": [],
"label": "InvariantTrait::change_liquidity",
"mutates": true,
"payable": false,
"returnType": {
"displayName": [
"ink",
"MessageResult"
],
"type": 58
},
"selector": "0x19b443b7"
},
{
"args": [
{
Expand Down Expand Up @@ -4140,6 +4298,10 @@
{
"index": 34,
"name": "SetCodeHashError"
},
{
"index": 35,
"name": "LiquidityChangeZero"
}
]
}
Expand Down
Binary file modified sdk/contracts/invariant/invariant.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@invariant-labs/a0-sdk",
"version": "0.2.20",
"version": "0.2.21",
"collaborators": [
"Invariant Labs"
],
Expand Down Expand Up @@ -36,7 +36,7 @@
"docs:copy": "cp ../README.md README.md",
"build:copy-wasm": "cd target && mkdir wasm && cp -r ../src/wasm/pkg ./wasm/pkg",
"test:all": "ts-mocha",
"test:local": "npm run test:utils && npm run test:wazero && npm run test:psp22 && npm run test:protocol-fee && npm run test:math && npm run test:invariant && npm run test:example && npm run test:events && npm run test:tx && npm run test:position && npm run test:get-position-with-associates && npm run test:get-positions && npm run test:get-all && npm run test:query-on-pair && npm run test:get-liquidity-ticks",
"test:local": "npm run test:utils && npm run test:wazero && npm run test:psp22 && npm run test:protocol-fee && npm run test:math && npm run test:invariant && npm run test:example && npm run test:events && npm run test:tx && npm run test:position && npm run test:get-position-with-associates && npm run test:get-positions && npm run test:get-all && npm run test:query-on-pair && npm run test:change-liquidity && npm run test:get-liquidity-ticks && npm run test:update-position-seconds-per-liquidity",
"test:utils": "mocha ./tests/utils.test.ts -g utils",
"test:wazero": "mocha ./tests/wrapped-azero.test.ts -g wrapped-azero",
"test:psp22": "mocha ./tests/psp22.test.ts -g psp22",
Expand All @@ -56,10 +56,11 @@
"test:simulate-invariant-swap": "mocha ./tests/simulate-invariant-swap.test.ts -g simulateInvariantSwap",
"test:query-on-pair": "mocha ./tests/query-on-pair.test.ts -g query-on-pair",
"test:get-all": "mocha ./tests/get-all.test.ts -g get-all",
"test:change-liquidity": "mocha ./tests/change-liquidity.test.ts -g change-liquidity",
"test:update-position-seconds-per-liquidity": "mocha ./tests/update-position-seconds-per-liquidity.test.ts -g update-position-seconds-per-liquidity"
},
"dependencies": {
"@invariant-labs/a0-sdk-wasm": "file:./src/wasm/pkg",
"@invariant-labs/a0-sdk-wasm": "0.1.24",
"@polkadot/api": "^10.12.4",
"@polkadot/api-contract": "^10.12.4",
"@scio-labs/use-inkathon": "^0.6.3",
Expand Down
Loading
Loading