Skip to content
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
1 change: 1 addition & 0 deletions src/chaincode/dex/addLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function addLiquidity(
tickUpper,
tickLower,
dto.uniqueKey,
liquidityProvider,
dto.positionId
);
const { tickUpperData, tickLowerData } = await fetchOrCreateTickDataPair(
Expand Down
11 changes: 8 additions & 3 deletions src/chaincode/dex/position.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ChainError, NotFoundError } from "@gala-chain/api";
import { ChainError, NotFoundError, UserAlias } from "@gala-chain/api";
import { GalaChainContext, getObjectByKey, putChainObject } from "@gala-chain/chaincode";
import { keccak256 } from "js-sha3";

Expand All @@ -27,20 +27,25 @@ import { genTickRange, getUserPositionIds } from "./dexUtils";
* @param pool - The liquidity pool in which this position exists
* @param tickUpper - The upper bound of the tick range
* @param tickLower - The lower bound of the tick range
* @param owner - (Optional) The user address; defaults to the calling user
* @param uniqueKey - A unique key used to deterministically generate a position ID if none exists
* @param liquidityProvider - The user address or alias of the liquidity provider
* @param positionId - (Optional) The explicit position ID to fetch; if not provided, one is derived from the tick range
* @returns The DexPositionData object representing the user's position
* @throws NotFoundError - If the provided positionId does not match the given tick range
* @throws ValidationError - If the user’s position record fails validation
*/
export async function fetchOrCreateDexPosition(
ctx: GalaChainContext,
pool: Pool,
tickUpper: number,
tickLower: number,
uniqueKey: string,
liquidityProvider: UserAlias,
positionId?: string
): Promise<DexPositionData> {
const poolHash = pool.genPoolHash();
const tickRange = genTickRange(tickLower, tickUpper);
const emptyUserPosition = new DexPositionOwner(ctx.callingUser, poolHash);
const emptyUserPosition = new DexPositionOwner(liquidityProvider, poolHash);

// Fetch or initialize positionHolder's DEX position owner record
const fetchedUserPosition = await getObjectByKey(
Expand Down
Loading