@alephium/powfi-sdk 0.0.1-rc.1
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/README.md +4 -0
- package/clmm/artifacts/BitmapWord.ral.json +125 -0
- package/clmm/artifacts/BitmapWordDeployer.ral.json +31 -0
- package/clmm/artifacts/CreateConfig.ral.json +37 -0
- package/clmm/artifacts/CreateLiquidPool.ral.json +55 -0
- package/clmm/artifacts/DexAccount.ral.json +110 -0
- package/clmm/artifacts/LiquidityAmountsTest.ral.json +161 -0
- package/clmm/artifacts/LiquidityManagmentTest.ral.json +384 -0
- package/clmm/artifacts/Pool.ral.json +1530 -0
- package/clmm/artifacts/PoolConfig.ral.json +31 -0
- package/clmm/artifacts/PoolFactory.ral.json +300 -0
- package/clmm/artifacts/PoolRouterDemo.ral.json +49 -0
- package/clmm/artifacts/PoolUser.ral.json +89 -0
- package/clmm/artifacts/Position.ral.json +183 -0
- package/clmm/artifacts/PositionManager.ral.json +416 -0
- package/clmm/artifacts/SwapWithoutAccount.ral.json +46 -0
- package/clmm/artifacts/TestToken.ral.json +68 -0
- package/clmm/artifacts/Tick.ral.json +161 -0
- package/clmm/artifacts/TickBitmapTest.ral.json +220 -0
- package/clmm/artifacts/constants.ral.json +81 -0
- package/clmm/artifacts/structs.ral.json +335 -0
- package/clmm/artifacts/ts/BitmapWord.ts +337 -0
- package/clmm/artifacts/ts/BitmapWordDeployer.ts +164 -0
- package/clmm/artifacts/ts/DexAccount.ts +330 -0
- package/clmm/artifacts/ts/LiquidityAmountsTest.ts +464 -0
- package/clmm/artifacts/ts/LiquidityManagmentTest.ts +859 -0
- package/clmm/artifacts/ts/Pool.ts +2535 -0
- package/clmm/artifacts/ts/PoolConfig.ts +179 -0
- package/clmm/artifacts/ts/PoolFactory.ts +640 -0
- package/clmm/artifacts/ts/PoolUser.ts +237 -0
- package/clmm/artifacts/ts/Position.ts +440 -0
- package/clmm/artifacts/ts/PositionManager.ts +929 -0
- package/clmm/artifacts/ts/TestToken.ts +277 -0
- package/clmm/artifacts/ts/Tick.ts +351 -0
- package/clmm/artifacts/ts/TickBitmapTest.ts +512 -0
- package/clmm/artifacts/ts/constants.ts +17 -0
- package/clmm/artifacts/ts/contracts.ts +26 -0
- package/clmm/artifacts/ts/deployments.ts +160 -0
- package/clmm/artifacts/ts/index.ts +20 -0
- package/clmm/artifacts/ts/scripts.ts +76 -0
- package/clmm/artifacts/ts/types.ts +105 -0
- package/clmm/deployments/.deployments.devnet.json +350 -0
- package/clmm/deployments/.deployments.testnet.json +350 -0
- package/cpmm/artifacts/dex/DexAccount.ral.json +110 -0
- package/cpmm/artifacts/dex/Router.ral.json +361 -0
- package/cpmm/artifacts/dex/TokenPair.ral.json +512 -0
- package/cpmm/artifacts/dex/TokenPairFactory.ral.json +297 -0
- package/cpmm/artifacts/examples/ExampleOracleSimple.ral.json +192 -0
- package/cpmm/artifacts/examples/FeeCollectorFactoryImpl.ral.json +185 -0
- package/cpmm/artifacts/examples/FeeCollectorPerTokenPairImpl.ral.json +216 -0
- package/cpmm/artifacts/examples/FullMathTest.ral.json +123 -0
- package/cpmm/artifacts/scripts/AddLiquidity.ral.json +46 -0
- package/cpmm/artifacts/scripts/Burn.ral.json +31 -0
- package/cpmm/artifacts/scripts/CollectFee.ral.json +25 -0
- package/cpmm/artifacts/scripts/CreatePair.ral.json +37 -0
- package/cpmm/artifacts/scripts/CreatePairAndAddLiquidity.ral.json +43 -0
- package/cpmm/artifacts/scripts/EnableFeeCollector.ral.json +28 -0
- package/cpmm/artifacts/scripts/Mint.ral.json +34 -0
- package/cpmm/artifacts/scripts/RemoveLiquidity.ral.json +43 -0
- package/cpmm/artifacts/scripts/SetFeeCollectorFactory.ral.json +28 -0
- package/cpmm/artifacts/scripts/Swap.ral.json +46 -0
- package/cpmm/artifacts/scripts/SwapMaxIn.ral.json +46 -0
- package/cpmm/artifacts/scripts/SwapMinOut.ral.json +46 -0
- package/cpmm/artifacts/test/GetToken.ral.json +31 -0
- package/cpmm/artifacts/test/MathTest.ral.json +49 -0
- package/cpmm/artifacts/test/TestToken.ral.json +87 -0
- package/cpmm/artifacts/ts/DexAccount.ts +329 -0
- package/cpmm/artifacts/ts/ExampleOracleSimple.ts +383 -0
- package/cpmm/artifacts/ts/FeeCollectorFactoryImpl.ts +227 -0
- package/cpmm/artifacts/ts/FeeCollectorPerTokenPairImpl.ts +327 -0
- package/cpmm/artifacts/ts/FullMathTest.ts +251 -0
- package/cpmm/artifacts/ts/MathTest.ts +183 -0
- package/cpmm/artifacts/ts/Router.ts +554 -0
- package/cpmm/artifacts/ts/TestToken.ts +312 -0
- package/cpmm/artifacts/ts/TokenPair.ts +947 -0
- package/cpmm/artifacts/ts/TokenPairFactory.ts +501 -0
- package/cpmm/artifacts/ts/contracts.ts +26 -0
- package/cpmm/artifacts/ts/deployments.ts +109 -0
- package/cpmm/artifacts/ts/index.ts +16 -0
- package/cpmm/artifacts/ts/scripts.ts +142 -0
- package/cpmm/deployments/.deployments.devnet.json +77 -0
- package/cpmm/deployments/.deployments.testnet.json +79 -0
- package/lib/index.d.mts +8800 -0
- package/lib/index.d.ts +8800 -0
- package/lib/index.js +21769 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +22118 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +80 -0
- package/src/clmm/clmm.ts +607 -0
- package/src/clmm/constants.ts +7 -0
- package/src/clmm/index.ts +6 -0
- package/src/clmm/liquidity.ts +163 -0
- package/src/clmm/pool.ts +154 -0
- package/src/clmm/tick.ts +335 -0
- package/src/clmm/types.ts +155 -0
- package/src/common/constants.ts +1 -0
- package/src/common/error.ts +46 -0
- package/src/common/index.ts +7 -0
- package/src/common/logger.ts +82 -0
- package/src/common/math.ts +88 -0
- package/src/common/numeric.ts +64 -0
- package/src/common/types.ts +49 -0
- package/src/common/utils.ts +3 -0
- package/src/cpmm/constants.ts +2 -0
- package/src/cpmm/cpmm.ts +631 -0
- package/src/cpmm/index.ts +3 -0
- package/src/cpmm/types.ts +113 -0
- package/src/index.ts +25 -0
- package/src/moduleBase.ts +64 -0
- package/src/staking/index.ts +4 -0
- package/src/staking/settings.ts +38 -0
- package/src/staking/staking.ts +277 -0
- package/src/staking/types.ts +15 -0
- package/src/staking/utils.ts +25 -0
- package/src/token/index.ts +1 -0
- package/src/token/token.ts +163 -0
- package/src/zeta.ts +105 -0
- package/staking/artifacts/AlphStakeAndLock.ral.json +31 -0
- package/staking/artifacts/AlphUnstakeVault.ral.json +151 -0
- package/staking/artifacts/XAlphStakeVault.ral.json +559 -0
- package/staking/artifacts/XAlphToken.ral.json +404 -0
- package/staking/artifacts/XAlphUnlockAndStartUnstake.ral.json +31 -0
- package/staking/artifacts/examples/GovernanceDemo.ral.json +282 -0
- package/staking/artifacts/examples/RewardSharingVault.ral.json +253 -0
- package/staking/artifacts/structs.ral.json +47 -0
- package/staking/artifacts/ts/AlphUnstakeVault.ts +354 -0
- package/staking/artifacts/ts/FullMathTest.ts +175 -0
- package/staking/artifacts/ts/GovernanceDemo.ts +726 -0
- package/staking/artifacts/ts/RewardSharingVault.ts +559 -0
- package/staking/artifacts/ts/TestDynamicArrayByteVec32.ts +431 -0
- package/staking/artifacts/ts/TestDynamicSortedArrayForU256.ts +516 -0
- package/staking/artifacts/ts/TestMerkleProof.ts +343 -0
- package/staking/artifacts/ts/XAlphStakeVault.ts +1120 -0
- package/staking/artifacts/ts/XAlphToken.ts +835 -0
- package/staking/artifacts/ts/contracts.ts +26 -0
- package/staking/artifacts/ts/deployments.ts +109 -0
- package/staking/artifacts/ts/index.ts +15 -0
- package/staking/artifacts/ts/scripts.ts +35 -0
- package/staking/artifacts/ts/types.ts +19 -0
- package/staking/artifacts/utils/FullMathTest.ral.json +57 -0
- package/staking/artifacts/utils/TestDynamicArrayByteVec32.ral.json +165 -0
- package/staking/artifacts/utils/TestDynamicSortedArrayForU256.ral.json +189 -0
- package/staking/artifacts/utils/TestMerkleProof.ral.json +134 -0
- package/staking/deployments/.deployments.devnet.json +77 -0
- package/staking/deployments/.deployments.testnet.json +78 -0
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alephium/powfi-sdk",
|
|
3
|
+
"version": "0.0.1-rc.1",
|
|
4
|
+
"description": "Typescript SDK for Alephium PoWFi",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/index.mjs",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.mjs",
|
|
12
|
+
"require": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"src",
|
|
18
|
+
"clmm",
|
|
19
|
+
"cpmm",
|
|
20
|
+
"staking"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prebuild": "bun run copy-artifacts",
|
|
24
|
+
"build": "bunx tsup",
|
|
25
|
+
"copy-artifacts": "rm -rf clmm cpmm staking && mkdir -p clmm cpmm staking && cp -r ../clmm/artifacts clmm/ && cp -r ../clmm/deployments clmm/ && cp -r ../cpmm/artifacts cpmm/ && cp -r ../cpmm/deployments cpmm/ && cp -r ../staking/artifacts staking/ && cp -r ../staking/deployments staking/",
|
|
26
|
+
"dev": "bunx tsup src --watch --format cjs,esm --dts --sourcemap --no-splitting -d lib",
|
|
27
|
+
"test": "bunx jest",
|
|
28
|
+
"test:watch": "bunx jest --watch",
|
|
29
|
+
"test:coverage": "bunx jest --coverage",
|
|
30
|
+
"lint": "bunx eslint --max-warnings=0 . --ext .ts",
|
|
31
|
+
"format": "bunx prettier --write .",
|
|
32
|
+
"typecheck": "bunx tsc --noEmit",
|
|
33
|
+
"clean": "rm -rf lib clmm cpmm staking",
|
|
34
|
+
"prepublishOnly": "bun run build",
|
|
35
|
+
"lint:fix": "bun run lint -- --fix",
|
|
36
|
+
"format:check": "bunx prettier --check ."
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"alephium",
|
|
40
|
+
"cpmm",
|
|
41
|
+
"clmm",
|
|
42
|
+
"staking",
|
|
43
|
+
"dex",
|
|
44
|
+
"defi",
|
|
45
|
+
"blockchain",
|
|
46
|
+
"sdk",
|
|
47
|
+
"zetamarkets"
|
|
48
|
+
],
|
|
49
|
+
"author": "Zeta Markets",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/zetamarkets/zeta-alephium-sdk.git"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@alephium/token-list": "0.0.20",
|
|
57
|
+
"@alephium/web3": "^2.0.8",
|
|
58
|
+
"decimal.js": "^10.6.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"clmm": "0.0.26",
|
|
62
|
+
"cpmm": "0.1.0",
|
|
63
|
+
"staking": "0.1.0",
|
|
64
|
+
"@alephium/web3-test": "^v2.0.8",
|
|
65
|
+
"@types/jest": "^29.5.12",
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
67
|
+
"@typescript-eslint/parser": "^6.17.0",
|
|
68
|
+
"eslint": "^8.56.0",
|
|
69
|
+
"eslint-config-prettier": "^9.1.0",
|
|
70
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
71
|
+
"jest": "^29.7.0",
|
|
72
|
+
"prettier": "^3.2.5",
|
|
73
|
+
"ts-jest": "^29.1.2",
|
|
74
|
+
"tsup": "^8.0.1",
|
|
75
|
+
"typescript": "^5.3.3"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"bun": ">=1.0.0"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/clmm/clmm.ts
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import type { SignExecuteScriptTxResult, Token } from '@alephium/web3';
|
|
2
|
+
import {
|
|
3
|
+
addressFromContractId,
|
|
4
|
+
binToHex,
|
|
5
|
+
DUST_AMOUNT,
|
|
6
|
+
MINIMAL_CONTRACT_DEPOSIT,
|
|
7
|
+
subContractId,
|
|
8
|
+
codec,
|
|
9
|
+
encodePrimitiveValues,
|
|
10
|
+
groupOfAddress,
|
|
11
|
+
isGrouplessAddressWithoutGroupIndex,
|
|
12
|
+
ALPH_TOKEN_ID,
|
|
13
|
+
} from '@alephium/web3';
|
|
14
|
+
import { loadDeployments } from 'clmm/artifacts/ts/deployments';
|
|
15
|
+
import ModuleBase from '../moduleBase';
|
|
16
|
+
import type { Zeta } from '../zeta';
|
|
17
|
+
import type {
|
|
18
|
+
AddLiquidity,
|
|
19
|
+
ClmmConfig,
|
|
20
|
+
CollectProtocolFees,
|
|
21
|
+
CollectTokens,
|
|
22
|
+
LiquidityDistribution,
|
|
23
|
+
RemoveLiquidity,
|
|
24
|
+
SimulateSwap,
|
|
25
|
+
ClmmSwapParams,
|
|
26
|
+
ClmmPoolContractState,
|
|
27
|
+
ClmmPoolConfig,
|
|
28
|
+
SetRewardParams,
|
|
29
|
+
ExtendRewards,
|
|
30
|
+
PositionPath,
|
|
31
|
+
ClmmPositionInfo,
|
|
32
|
+
} from './types';
|
|
33
|
+
import type { PoolInstance, PoolTypes } from 'clmm/artifacts/ts';
|
|
34
|
+
import {
|
|
35
|
+
CreateLiquidPool,
|
|
36
|
+
Pool,
|
|
37
|
+
PoolConfig,
|
|
38
|
+
PoolFactory,
|
|
39
|
+
PositionManager,
|
|
40
|
+
SwapWithoutAccount,
|
|
41
|
+
} from 'clmm/artifacts/ts';
|
|
42
|
+
import { PoolUtils } from './pool';
|
|
43
|
+
import { TickUtils } from './tick';
|
|
44
|
+
import { ClmmLiquidityUtils } from './liquidity';
|
|
45
|
+
import { PoolNotFoundError, sortTokens } from '../common';
|
|
46
|
+
|
|
47
|
+
function normalizeAddress(address: string, group: number): string {
|
|
48
|
+
return isGrouplessAddressWithoutGroupIndex(address) ? `${address}:${group}` : address;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class ClmmModule extends ModuleBase {
|
|
52
|
+
private config: ClmmConfig;
|
|
53
|
+
private configsByIndex = new Map<bigint, ClmmPoolConfig>();
|
|
54
|
+
|
|
55
|
+
constructor(scope: Zeta) {
|
|
56
|
+
super({ scope, moduleName: 'ClmmModule' });
|
|
57
|
+
|
|
58
|
+
this.config = this._getClmmConfig();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setConfig(config: ClmmConfig) {
|
|
62
|
+
this.config = config;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getClmmConfig(): ClmmConfig {
|
|
66
|
+
return this.config;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getPoolConfigId(configIndex: bigint): string {
|
|
70
|
+
const rawIndex = codec.u256Codec.encode(configIndex);
|
|
71
|
+
const configPath = binToHex(rawIndex);
|
|
72
|
+
const group = this.config.groupIndex;
|
|
73
|
+
return subContractId(this.config.factoryId, configPath, group);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async getAllPoolConfigs(): Promise<ClmmPoolConfig[]> {
|
|
77
|
+
const factoryAddress = addressFromContractId(this.config.factoryId);
|
|
78
|
+
const factory = PoolFactory.at(factoryAddress);
|
|
79
|
+
const state = await factory.fetchState();
|
|
80
|
+
const nextConfigIndex = state.fields.nextConfigIndex;
|
|
81
|
+
|
|
82
|
+
const configs: ClmmPoolConfig[] = [];
|
|
83
|
+
for (let i = 0n; i < nextConfigIndex; i++) {
|
|
84
|
+
let config = this.configsByIndex.get(i);
|
|
85
|
+
if (!config) {
|
|
86
|
+
config = await this.fetchConfigFromChain(i);
|
|
87
|
+
this.configsByIndex.set(i, config);
|
|
88
|
+
}
|
|
89
|
+
configs.push(config);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return configs;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async getPoolConfig(configIndex: bigint): Promise<ClmmPoolConfig | undefined> {
|
|
96
|
+
const cached = this.configsByIndex.get(configIndex);
|
|
97
|
+
if (cached) {
|
|
98
|
+
return cached;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const config = await this.fetchConfigFromChain(configIndex);
|
|
103
|
+
this.configsByIndex.set(configIndex, config);
|
|
104
|
+
return config;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
this.logWarning(`Failed to fetch config ${configIndex.toString()}`, error);
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async fetchConfigFromChain(configIndex: bigint): Promise<ClmmPoolConfig> {
|
|
112
|
+
const poolConfigId = this.getPoolConfigId(configIndex);
|
|
113
|
+
const poolConfigAddress = addressFromContractId(poolConfigId);
|
|
114
|
+
const poolConfig = PoolConfig.at(poolConfigAddress);
|
|
115
|
+
const poolConfigState = await poolConfig.fetchState();
|
|
116
|
+
return {
|
|
117
|
+
configIndex,
|
|
118
|
+
tickSpacing: poolConfigState.fields.config.tickSpacing,
|
|
119
|
+
tradingFee: poolConfigState.fields.config.fee,
|
|
120
|
+
protocolFee: poolConfigState.fields.config.feeProtocol,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async getPoolState(poolId: string): Promise<ClmmPoolContractState> {
|
|
125
|
+
try {
|
|
126
|
+
const poolAddress = addressFromContractId(poolId);
|
|
127
|
+
const pool = Pool.at(poolAddress);
|
|
128
|
+
const state = await pool.fetchState();
|
|
129
|
+
const token0Info = await this.scope.token.getTokenById(state.fields.token0);
|
|
130
|
+
const token1Info = await this.scope.token.getTokenById(state.fields.token1);
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
poolId,
|
|
134
|
+
token0Info,
|
|
135
|
+
token1Info,
|
|
136
|
+
liquidity: state.fields.liquidity,
|
|
137
|
+
tradingFee: state.fields.fee,
|
|
138
|
+
protocolFee: state.fields.slot0.feeProtocol,
|
|
139
|
+
tick: state.fields.slot0.tick,
|
|
140
|
+
tickSpacing: state.fields.tickSpacing,
|
|
141
|
+
sqrtPriceX96: state.fields.slot0.sqrtPriceX96,
|
|
142
|
+
configIndex: state.fields.configIndex,
|
|
143
|
+
};
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
146
|
+
throw new PoolNotFoundError(poolId);
|
|
147
|
+
}
|
|
148
|
+
this.logAndThrowError(`Failed to fetch CLMM pool state on ${poolId}`, error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async getPoolTokenBalances(poolId: string): Promise<{ token0Balance: bigint; token1Balance: bigint }> {
|
|
153
|
+
try {
|
|
154
|
+
const poolAddress = addressFromContractId(poolId);
|
|
155
|
+
const state = await Pool.at(poolAddress).fetchState();
|
|
156
|
+
const { token0, token1 } = state.fields;
|
|
157
|
+
|
|
158
|
+
const balance = await this.scope.nodeProvider.addresses.getAddressesAddressBalance(poolAddress);
|
|
159
|
+
|
|
160
|
+
const getBalance = (tokenId: string) =>
|
|
161
|
+
tokenId === ALPH_TOKEN_ID
|
|
162
|
+
? BigInt(balance.balance)
|
|
163
|
+
: BigInt(balance.tokenBalances?.find((t) => t.id === tokenId)?.amount || '0');
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
token0Balance: getBalance(token0),
|
|
167
|
+
token1Balance: getBalance(token1),
|
|
168
|
+
};
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
171
|
+
throw new PoolNotFoundError(poolId);
|
|
172
|
+
}
|
|
173
|
+
this.logAndThrowError(`Failed to fetch CLMM pool token balances for ${poolId}`, error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
getPoolId(tokenA: string, tokenB: string, configIndex: bigint): string {
|
|
178
|
+
const [token0, token1] = sortTokens(tokenA, tokenB);
|
|
179
|
+
const group = this.config.groupIndex;
|
|
180
|
+
const factoryId = this.config.factoryId;
|
|
181
|
+
const rawIndex = codec.u256Codec.encode(configIndex);
|
|
182
|
+
const configPath = binToHex(rawIndex);
|
|
183
|
+
const configId = subContractId(factoryId, configPath, group);
|
|
184
|
+
const path = token0 + token1 + configId;
|
|
185
|
+
return subContractId(factoryId, path, group);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
getPositionId(poolId: string, owner: string, tickLower: bigint, tickUpper: bigint): string {
|
|
189
|
+
const group = groupOfAddress(addressFromContractId(poolId));
|
|
190
|
+
const path = encodePrimitiveValues([
|
|
191
|
+
{ type: 'U256', value: Pool.consts.PathPrefixes.Position },
|
|
192
|
+
{ type: 'Address', value: owner },
|
|
193
|
+
{ type: 'I256', value: tickLower },
|
|
194
|
+
{ type: 'I256', value: tickUpper },
|
|
195
|
+
]);
|
|
196
|
+
return subContractId(poolId, binToHex(path), group);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
getPoolAddress(tokenA: string, tokenB: string, configIndex: bigint): string {
|
|
200
|
+
const poolId = this.getPoolId(tokenA, tokenB, configIndex);
|
|
201
|
+
return addressFromContractId(poolId);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
getPool(tokenA: string, tokenB: string, configIndex: bigint): PoolInstance {
|
|
205
|
+
const poolAddress = this.getPoolAddress(tokenA, tokenB, configIndex);
|
|
206
|
+
return Pool.at(poolAddress);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async poolExists(tokenA: string, tokenB: string, configIndex: bigint): Promise<boolean> {
|
|
210
|
+
const poolAddress = this.getPoolAddress(tokenA, tokenB, configIndex);
|
|
211
|
+
const pool = Pool.at(poolAddress);
|
|
212
|
+
try {
|
|
213
|
+
await pool.fetchState();
|
|
214
|
+
return true;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
this.logAndThrowError(`Failed to fetch pool state on ${poolAddress}`, error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async createPool(
|
|
224
|
+
configIndex: bigint,
|
|
225
|
+
token0: string,
|
|
226
|
+
token1: string,
|
|
227
|
+
rewardToken: string,
|
|
228
|
+
tick: bigint,
|
|
229
|
+
amount0: bigint,
|
|
230
|
+
amount1: bigint,
|
|
231
|
+
tickLower: bigint,
|
|
232
|
+
tickUpper: bigint,
|
|
233
|
+
dustAmount?: bigint,
|
|
234
|
+
): Promise<{ poolAddress: string; result: SignExecuteScriptTxResult }> {
|
|
235
|
+
const sqrtPriceX96 = TickUtils.getSqrtRatioAtTick(tick);
|
|
236
|
+
const tokens = [token0, token1];
|
|
237
|
+
const amounts = [amount0, amount1];
|
|
238
|
+
const ticks = [tickLower, tickUpper];
|
|
239
|
+
if (token0 > token1) {
|
|
240
|
+
tokens.reverse();
|
|
241
|
+
amounts.reverse();
|
|
242
|
+
}
|
|
243
|
+
if (tickLower > tickUpper) {
|
|
244
|
+
ticks.reverse();
|
|
245
|
+
}
|
|
246
|
+
const sqrtPriceX96A = TickUtils.getSqrtRatioAtTick(ticks[0]);
|
|
247
|
+
const sqrtPriceX96B = TickUtils.getSqrtRatioAtTick(ticks[1]);
|
|
248
|
+
const liquidity = ClmmLiquidityUtils.getLiquidityFromAmounts(
|
|
249
|
+
sqrtPriceX96,
|
|
250
|
+
sqrtPriceX96A,
|
|
251
|
+
sqrtPriceX96B,
|
|
252
|
+
amounts[0],
|
|
253
|
+
amounts[1],
|
|
254
|
+
);
|
|
255
|
+
const result = await CreateLiquidPool.execute({
|
|
256
|
+
signer: this.scope.signer,
|
|
257
|
+
initialFields: {
|
|
258
|
+
factory: this.config.factoryId,
|
|
259
|
+
token0: tokens[0],
|
|
260
|
+
token1: tokens[1],
|
|
261
|
+
rewardToken,
|
|
262
|
+
liquidity,
|
|
263
|
+
tickLower: ticks[0],
|
|
264
|
+
tickUpper: ticks[1],
|
|
265
|
+
sqrtPriceX96,
|
|
266
|
+
configIndex,
|
|
267
|
+
amount0: amounts[0],
|
|
268
|
+
amount1: amounts[1],
|
|
269
|
+
},
|
|
270
|
+
attoAlphAmount: MINIMAL_CONTRACT_DEPOSIT * 6n,
|
|
271
|
+
tokens: [
|
|
272
|
+
{ id: tokens[0], amount: amounts[0] },
|
|
273
|
+
{ id: tokens[1], amount: amounts[1] },
|
|
274
|
+
],
|
|
275
|
+
dustAmount: dustAmount ?? MINIMAL_CONTRACT_DEPOSIT * 2n,
|
|
276
|
+
});
|
|
277
|
+
const poolAddress = this.getPoolAddress(tokens[0], tokens[1], configIndex);
|
|
278
|
+
return { poolAddress, result };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async addLiquidity(
|
|
282
|
+
p: AddLiquidity,
|
|
283
|
+
): Promise<{ positionId: string; result: SignExecuteScriptTxResult }> {
|
|
284
|
+
const poolAddress = this.getPoolAddress(p.token0, p.token1, p.configIndex);
|
|
285
|
+
const pool = Pool.at(poolAddress);
|
|
286
|
+
const positionManagerAddress = addressFromContractId(this.config.positionManagerId);
|
|
287
|
+
const positionManager = PositionManager.at(positionManagerAddress);
|
|
288
|
+
|
|
289
|
+
const signerAccount = await this.scope.signer.getSelectedAccount();
|
|
290
|
+
const owner = p.owner || signerAccount.address;
|
|
291
|
+
|
|
292
|
+
const group = this.config.groupIndex;
|
|
293
|
+
const normalizedOwner = normalizeAddress(owner, group);
|
|
294
|
+
const normalizedPayer = normalizeAddress(signerAccount.address, group);
|
|
295
|
+
|
|
296
|
+
const {
|
|
297
|
+
returns: [sqrtPriceX96, sqrtRatioAX96, sqrtRatioBX96, deposit],
|
|
298
|
+
} = await positionManager.view.getSqrtPricesX96({
|
|
299
|
+
args: {
|
|
300
|
+
tickLower: p.tickLower,
|
|
301
|
+
tickUpper: p.tickUpper,
|
|
302
|
+
pool: pool.contractId,
|
|
303
|
+
owner: normalizedOwner,
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
const currentTick = TickUtils.getTickAtSqrtRatio(sqrtPriceX96);
|
|
307
|
+
const minTick = currentTick - p.slippage;
|
|
308
|
+
const maxTick = currentTick + p.slippage;
|
|
309
|
+
const minSqrtPriceX96 = TickUtils.getSqrtRatioAtTick(minTick);
|
|
310
|
+
const maxSqrtPriceX96 = TickUtils.getSqrtRatioAtTick(maxTick);
|
|
311
|
+
|
|
312
|
+
const liquidity = ClmmLiquidityUtils.getLiquidityFromAmounts(
|
|
313
|
+
sqrtPriceX96,
|
|
314
|
+
sqrtRatioAX96,
|
|
315
|
+
sqrtRatioBX96,
|
|
316
|
+
p.amount0,
|
|
317
|
+
p.amount1,
|
|
318
|
+
);
|
|
319
|
+
const [spotAmount0, spotAmount1] = ClmmLiquidityUtils.getAmountsForLiquidity(
|
|
320
|
+
sqrtPriceX96,
|
|
321
|
+
sqrtRatioAX96,
|
|
322
|
+
sqrtRatioBX96,
|
|
323
|
+
-liquidity,
|
|
324
|
+
);
|
|
325
|
+
const [minAmount0, minAmount1] = ClmmLiquidityUtils.getAmountsForLiquidity(
|
|
326
|
+
minSqrtPriceX96,
|
|
327
|
+
sqrtRatioAX96,
|
|
328
|
+
sqrtRatioBX96,
|
|
329
|
+
-liquidity,
|
|
330
|
+
);
|
|
331
|
+
const [maxAmount0, maxAmount1] = ClmmLiquidityUtils.getAmountsForLiquidity(
|
|
332
|
+
maxSqrtPriceX96,
|
|
333
|
+
sqrtRatioAX96,
|
|
334
|
+
sqrtRatioBX96,
|
|
335
|
+
-liquidity,
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const positionId = PoolUtils.getPositionId(poolAddress, owner, p.tickLower, p.tickUpper);
|
|
339
|
+
const tokens: Token[] = [
|
|
340
|
+
{ id: p.token0, amount: -minAmount0 },
|
|
341
|
+
{ id: p.token1, amount: -maxAmount1 },
|
|
342
|
+
];
|
|
343
|
+
|
|
344
|
+
if (p.existingPosition) {
|
|
345
|
+
tokens.push({ id: positionId, amount: 1n });
|
|
346
|
+
}
|
|
347
|
+
const result = await positionManager.transact.addLiquidity({
|
|
348
|
+
signer: this.scope.signer,
|
|
349
|
+
args: {
|
|
350
|
+
payer: normalizedPayer,
|
|
351
|
+
p: {
|
|
352
|
+
token0: p.token0,
|
|
353
|
+
token1: p.token1,
|
|
354
|
+
configIndex: p.configIndex,
|
|
355
|
+
owner: normalizedOwner,
|
|
356
|
+
tickLower: p.tickLower,
|
|
357
|
+
tickUpper: p.tickUpper,
|
|
358
|
+
amount0Desired: -spotAmount0,
|
|
359
|
+
amount1Desired: -spotAmount1,
|
|
360
|
+
amount0Min: -maxAmount0,
|
|
361
|
+
amount1Min: -minAmount1,
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
tokens,
|
|
365
|
+
attoAlphAmount: deposit,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
return { positionId, result };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async removeLiquidity(
|
|
372
|
+
p: RemoveLiquidity,
|
|
373
|
+
): Promise<{ positionId: string; result: SignExecuteScriptTxResult }> {
|
|
374
|
+
const poolAddress = this.getPoolAddress(p.token0, p.token1, p.configIndex);
|
|
375
|
+
const positionManagerAddress = addressFromContractId(this.config.positionManagerId);
|
|
376
|
+
const positionManager = PositionManager.at(positionManagerAddress);
|
|
377
|
+
const signerAccount = await this.scope.signer.getSelectedAccount();
|
|
378
|
+
|
|
379
|
+
const group = this.config.groupIndex;
|
|
380
|
+
const normalizedOwner = normalizeAddress(p.owner, group);
|
|
381
|
+
const normalizedOperator = normalizeAddress(signerAccount.address, group);
|
|
382
|
+
|
|
383
|
+
const positionId = PoolUtils.getPositionId(poolAddress, p.owner, p.tickLower, p.tickUpper);
|
|
384
|
+
|
|
385
|
+
// Determine minimum amounts based on base token selection (Raydium pattern)
|
|
386
|
+
// For remove liquidity: base amount is what we expect, other amount is the minimum we'll accept
|
|
387
|
+
const amount0Min = p.base === 'token0' ? p.baseAmount : p.otherAmountMax;
|
|
388
|
+
const amount1Min = p.base === 'token0' ? p.otherAmountMax : p.baseAmount;
|
|
389
|
+
|
|
390
|
+
const result = await positionManager.transact.decreaseLiquidity({
|
|
391
|
+
signer: this.scope.signer,
|
|
392
|
+
args: {
|
|
393
|
+
liquidity: p.liquidity,
|
|
394
|
+
operator: normalizedOperator,
|
|
395
|
+
p: {
|
|
396
|
+
configIndex: p.configIndex,
|
|
397
|
+
token0: p.token0,
|
|
398
|
+
token1: p.token1,
|
|
399
|
+
owner: normalizedOwner,
|
|
400
|
+
tickLower: p.tickLower,
|
|
401
|
+
tickUpper: p.tickUpper,
|
|
402
|
+
amount0Min: amount0Min,
|
|
403
|
+
amount1Min: amount1Min,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
tokens: [{ id: positionId, amount: 1n }],
|
|
407
|
+
attoAlphAmount: DUST_AMOUNT * 3n,
|
|
408
|
+
});
|
|
409
|
+
return { positionId, result };
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
async positionInfo({ poolId, ...args }: PositionPath): Promise<ClmmPositionInfo> {
|
|
413
|
+
const pool = Pool.at(addressFromContractId(poolId));
|
|
414
|
+
const { returns } = await pool.view.positionInfo({ args });
|
|
415
|
+
return returns;
|
|
416
|
+
}
|
|
417
|
+
async collectTokens(
|
|
418
|
+
p: CollectTokens,
|
|
419
|
+
): Promise<{ positionId: string; result: SignExecuteScriptTxResult }> {
|
|
420
|
+
const poolAddress = this.getPoolAddress(p.token0, p.token1, p.configIndex);
|
|
421
|
+
const positionId = PoolUtils.getPositionId(poolAddress, p.owner, p.tickLower, p.tickUpper);
|
|
422
|
+
const positionManagerAddress = addressFromContractId(this.config.positionManagerId);
|
|
423
|
+
const signerAccount = await this.scope.signer.getSelectedAccount();
|
|
424
|
+
|
|
425
|
+
const group = this.config.groupIndex;
|
|
426
|
+
const normalizedOwner = normalizeAddress(p.owner, group);
|
|
427
|
+
const normalizedOperator = normalizeAddress(signerAccount.address, group);
|
|
428
|
+
const normalizedRecipient = normalizeAddress(p.recipient, group);
|
|
429
|
+
|
|
430
|
+
const positionManager = PositionManager.at(positionManagerAddress);
|
|
431
|
+
const result = await positionManager.transact.collect({
|
|
432
|
+
signer: this.scope.signer,
|
|
433
|
+
args: {
|
|
434
|
+
liquidity: p.liquidity,
|
|
435
|
+
operator: normalizedOperator,
|
|
436
|
+
p: {
|
|
437
|
+
configIndex: p.configIndex,
|
|
438
|
+
token0: p.token0,
|
|
439
|
+
token1: p.token1,
|
|
440
|
+
owner: normalizedOwner,
|
|
441
|
+
recipient: normalizedRecipient,
|
|
442
|
+
tickLower: p.tickLower,
|
|
443
|
+
tickUpper: p.tickUpper,
|
|
444
|
+
amount0Max: p.amount0Max,
|
|
445
|
+
amount1Max: p.amount1Max,
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
tokens: [{ id: positionId, amount: 1n }],
|
|
449
|
+
attoAlphAmount: DUST_AMOUNT * 3n,
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
return { positionId, result };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
async findBestRoute(token0: string, token1: string): Promise<bigint> {
|
|
456
|
+
const poolFactoryAddress = addressFromContractId(this.config.factoryId);
|
|
457
|
+
const poolFactory = PoolFactory.at(poolFactoryAddress);
|
|
458
|
+
const state = await poolFactory.fetchState();
|
|
459
|
+
const f = (_: number, i: number) => this.getPoolAddress(token0, token1, BigInt(i));
|
|
460
|
+
const addresses = Array.from({ length: Number(state.fields.nextConfigIndex) }, f);
|
|
461
|
+
const pools = await Promise.all(
|
|
462
|
+
addresses.map(async (addr, i) =>
|
|
463
|
+
(await this.poolExists(token0, token1, BigInt(i))) ? Pool.at(addr).fetchState() : undefined,
|
|
464
|
+
),
|
|
465
|
+
);
|
|
466
|
+
const [index] = pools.reduce<[bigint, bigint]>(
|
|
467
|
+
([index, liquidity], pool, i) => {
|
|
468
|
+
const liquidity2 = pool?.fields.liquidity || 0n;
|
|
469
|
+
return liquidity2 > liquidity ? [BigInt(i), liquidity2] : [index, liquidity];
|
|
470
|
+
},
|
|
471
|
+
[-1n, 0n],
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
if (index === -1n) {
|
|
475
|
+
throw new PoolNotFoundError(`No concentrated liquidity pool found for token pair ${token0}/${token1}`);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return index;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async simulateSwap(p: SimulateSwap): Promise<LiquidityDistribution> {
|
|
482
|
+
const poolAddress = this.getPoolAddress(p.token0, p.token1, p.configIndex);
|
|
483
|
+
const pool = Pool.at(poolAddress);
|
|
484
|
+
const result = await pool.view.simulateSwap({
|
|
485
|
+
args: {
|
|
486
|
+
amountSpecified: p.amount,
|
|
487
|
+
zeroForOne: p.zeroForOne,
|
|
488
|
+
data: '',
|
|
489
|
+
maxSteps: 500n,
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const poolState = result.contracts.at(0)?.fields as PoolTypes.Fields;
|
|
494
|
+
const startEvent = result.events.at(0) as PoolTypes.SwapStartEvent;
|
|
495
|
+
return {
|
|
496
|
+
sqrtPriceX96: poolState.slot0.sqrtPriceX96,
|
|
497
|
+
baseSqrtPriceX96: startEvent.fields.sqrtPriceX96,
|
|
498
|
+
liquidity: poolState.liquidity,
|
|
499
|
+
fee: poolState.fee,
|
|
500
|
+
rows: result.events.slice(1).map((e) => {
|
|
501
|
+
const event = e as PoolTypes.SwapStepEvent;
|
|
502
|
+
return {
|
|
503
|
+
sqrtPriceX96: event.fields.sqrtPriceX96,
|
|
504
|
+
liquidity: event.fields.liquidity,
|
|
505
|
+
};
|
|
506
|
+
}),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async swap(p: ClmmSwapParams): Promise<SignExecuteScriptTxResult> {
|
|
511
|
+
const configIndex = p.routePlan[0];
|
|
512
|
+
const pool = this.getPool(p.token0, p.token1, configIndex);
|
|
513
|
+
const poolState = await pool.fetchState();
|
|
514
|
+
const sqrtPriceX96 = poolState.fields.slot0.sqrtPriceX96;
|
|
515
|
+
const zeroForOne = poolState.fields.token0 === p.token0;
|
|
516
|
+
const sqrtPriceLimitX96 = TickUtils.getSqrtPriceLimitX96(sqrtPriceX96, p.slippage, zeroForOne);
|
|
517
|
+
|
|
518
|
+
const tokens = sortTokens(p.token0, p.token1);
|
|
519
|
+
const [tokenIn, tokenOut] = zeroForOne ? tokens : tokens.reverse();
|
|
520
|
+
return await SwapWithoutAccount.execute({
|
|
521
|
+
signer: this.scope.signer,
|
|
522
|
+
initialFields: {
|
|
523
|
+
dexAccount: this.config.accountRoot,
|
|
524
|
+
pool: pool.contractId,
|
|
525
|
+
tokenIn,
|
|
526
|
+
tokenOut,
|
|
527
|
+
zeroForOne,
|
|
528
|
+
amountSpecified: p.amount,
|
|
529
|
+
sqrtPriceLimitX96,
|
|
530
|
+
data: '',
|
|
531
|
+
},
|
|
532
|
+
tokens: [{ id: tokenIn, amount: p.amount }],
|
|
533
|
+
attoAlphAmount: DUST_AMOUNT * 2n,
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async collectProtocolFees(p: CollectProtocolFees): Promise<SignExecuteScriptTxResult> {
|
|
538
|
+
const poolFactoryAddress = addressFromContractId(this.config.factoryId);
|
|
539
|
+
const poolFactory = PoolFactory.at(poolFactoryAddress);
|
|
540
|
+
const result = await poolFactory.transact.collectProtocolFees({
|
|
541
|
+
signer: this.scope.signer,
|
|
542
|
+
args: {
|
|
543
|
+
recipient: p.recipient,
|
|
544
|
+
configIndex: p.configIndex,
|
|
545
|
+
token0: p.token0,
|
|
546
|
+
token1: p.token1,
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
async setRewardParams(p: SetRewardParams): Promise<SignExecuteScriptTxResult> {
|
|
553
|
+
const poolFactoryAddress = addressFromContractId(this.config.factoryId);
|
|
554
|
+
const poolFactory = PoolFactory.at(poolFactoryAddress);
|
|
555
|
+
const index = p.rewardToken === p.token0 ? 0n : p.rewardToken === p.token1 ? 1n : 2n;
|
|
556
|
+
const result = await poolFactory.transact.setRewardParams({
|
|
557
|
+
signer: this.scope.signer,
|
|
558
|
+
args: {
|
|
559
|
+
token0: p.token0,
|
|
560
|
+
token1: p.token1,
|
|
561
|
+
configIndex: p.configIndex,
|
|
562
|
+
amount: p.amount,
|
|
563
|
+
index,
|
|
564
|
+
openTime: p.openTime,
|
|
565
|
+
endTime: p.endTime,
|
|
566
|
+
payer: p.payer,
|
|
567
|
+
tokenId: p.rewardToken,
|
|
568
|
+
},
|
|
569
|
+
tokens: [{ id: p.rewardToken, amount: p.amount }],
|
|
570
|
+
attoAlphAmount: DUST_AMOUNT,
|
|
571
|
+
});
|
|
572
|
+
return result;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
async extendRewards(p: ExtendRewards): Promise<SignExecuteScriptTxResult> {
|
|
576
|
+
const poolAddress = this.getPoolAddress(p.token0, p.token1, p.configIndex);
|
|
577
|
+
const pool = Pool.at(poolAddress);
|
|
578
|
+
const index = p.rewardToken === p.token0 ? 0n : p.rewardToken === p.token1 ? 1n : 2n;
|
|
579
|
+
const result = await pool.transact.extendRewards({
|
|
580
|
+
signer: this.scope.signer,
|
|
581
|
+
args: {
|
|
582
|
+
payer: p.payer,
|
|
583
|
+
index,
|
|
584
|
+
amount: p.amount,
|
|
585
|
+
},
|
|
586
|
+
tokens: [{ id: p.rewardToken, amount: p.amount }],
|
|
587
|
+
attoAlphAmount: DUST_AMOUNT,
|
|
588
|
+
});
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private _getClmmConfig(): ClmmConfig {
|
|
593
|
+
const networkId = this.scope.network.id;
|
|
594
|
+
try {
|
|
595
|
+
const deployments = loadDeployments(networkId);
|
|
596
|
+
return {
|
|
597
|
+
groupIndex: deployments.contracts.PoolFactory.contractInstance.groupIndex,
|
|
598
|
+
factoryId: deployments.contracts.PoolFactory.contractInstance.contractId,
|
|
599
|
+
positionManagerId: deployments.contracts.PositionManager.contractInstance.contractId,
|
|
600
|
+
defaultConfigIndex: 0n,
|
|
601
|
+
accountRoot: deployments.contracts.DexAccount.contractInstance.contractId,
|
|
602
|
+
};
|
|
603
|
+
} catch (error) {
|
|
604
|
+
this.logAndThrowError(`Failed to load deployments on ${networkId}`, error);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const U256_MAX = 2n ** 256n - 1n;
|
|
2
|
+
|
|
3
|
+
// Default "unlimited" amount for CLMM calculations
|
|
4
|
+
// This ensures the other amount is always the limiting factor
|
|
5
|
+
export const UNLIMITED_AMOUNT = 2n ** 128n - 1n; // uint128 max
|
|
6
|
+
|
|
7
|
+
export { MAX_TICK, MIN_TICK } from 'clmm/artifacts/ts/constants';
|