Skip to content

WL-777 waterx sdk increase decrease wlp view + test#11

Merged
JustaLiang merged 19 commits intomainfrom
WL-777-waterx-sdk-increase-decrease-wlp-view
Apr 2, 2026
Merged

WL-777 waterx sdk increase decrease wlp view + test#11
JustaLiang merged 19 commits intomainfrom
WL-777-waterx-sdk-increase-decrease-wlp-view

Conversation

@do0x0ob
Copy link
Copy Markdown
Contributor

@do0x0ob do0x0ob commented Apr 2, 2026

Summary

Delivers WL-777 SDK work: trading helpers for increase/decrease position, WLP-related reads and tx builders, testnet-aligned fetch (view package resolution + BCS matching deployed view structs), plus Vitest unit/e2e (and integration project), coverage, and README/tsconfig updates.

Details

  • Trading / tx-builders: increasePosition / decreasePosition and high-level buildIncreasePositionTx / buildDecreasePositionTx; WLP mint/redeem paths updated for current params (e.g. oracle, recipient where required).
  • Fetch / views: Resolve view::* package from shared object runtime type; market_summary / position_* use <LP>; align MarketSummary, PositionInfo, TokenPoolSummary BCS with on-chain layout; testnet WLP type matches live pool (wlp_token::WLP_TOKEN).
  • Tests: PTB wiring assertions (3 type args, match_orders, deposit/withdraw collateral names), e2e simulate tests, query-output script (WLP supply/TVL dumps).
  • Tooling: Root tsconfig for src+test+scripts typecheck; pnpm test:coverage / test:ci unchanged and valid.

Supersedes

Closes the older tests-only PR (e.g. feat/sdk-tests-and-ci) in favor of this branch, which includes those changes plus SDK + fetch fixes.

How to verify

pnpm install && pnpm typecheck && pnpm test && pnpm test:coverage

do0x0ob and others added 12 commits April 2, 2026 12:00
- Trading: AccountRequest via bucket framework; deposit/withdraw collateral;
  increase/decrease position; destroy_response 3 type args; keeper APIs
- Orders/WLP: match contract signatures (recipient, cancel sender)
- Fetch: getWlpTotalSupply, getWlpTvlUsd
- README: concise exported API reference for temporary branch work

Made-with: Cursor
…increase/decrease tx builders

Made-with: Cursor
- Add unit/simulate/integration/e2e tests; import tx-builders and
  isValidReferralCode via src subpaths where not re-exported from index.
- Align src with origin/main; remove extractVaa-only unit tests (helper is
  non-exported on main). Drop unused imports in client and tx-builders.
- Restrict Prettier to test/ and scripts/ so SDK layout stays unchanged.
- CLAUDE.md: reflect new lint toolchain (ESLint + Prettier) and
  multi-project test scripts (test:unit, test:e2e, test:integration,
  test:ci, lint:eslint, lint:prettier, lint:fix)
- test/integration/setup.ts: log a console.warn per failed keystore
  entry instead of silently continuing, to aid debugging
…EADME

- Resolve view module package from shared object runtime type; market/position views use <LP> only
- Align MarketSummary, PositionInfo, TokenPoolSummary BCS with deployed view.json
- Testnet WLP type to wlp_token::WLP_TOKEN; WLP_STANDALONE for contracts/wlp package
- Update PTB invariant tests (3 type args, match_orders indices, deposit/withdraw collateral)
- tsconfig: noEmit + allowImportingTsExtensions for root typecheck
- README: document view behavior and API changes (marketIndex, lastPriceRefreshTimestamp)
- query-output: replace getMarketCount with WLP supply/TVL dumps

Made-with: Cursor
- Add shared recipient/coin IDs (mockSuiAddress) and dummyBucketFloatPriceResult
- Wire user-wlp and tx-builders WLP tests; cross-link from sui-mock-fixtures

Made-with: Cursor
- Add PTB_DUMMY_ACCOUNT_ID, PTB_DUMMY_RECEIVING_COINS, dummyBucketFloatPricePair
- Align user-order-ptb imports with .ts extension

Made-with: Cursor
- Trigger CI on pull_request to main only; one Lint job (pnpm lint), Test uses test:ci
- Remove lint.yml and unit-test.yml to avoid double eslint / double vitest
- Document in test/README; keep security + coverage jobs

Made-with: Cursor
@do0x0ob do0x0ob requested review from JustaLiang and allen-hsu April 2, 2026 08:38
@github-advanced-security
Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

- Format ptb-test-dummies.ts for Prettier (lint job)
- Pass workflow inputs via env in publish.yml (Semgrep run-shell-injection)
- Add .gitleaks.toml allowlist for public Sui IDs in constants.ts, dist/, coverage/

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Notes from spot-check:

  • PTB flow matches latest request/execute/destroy_response pattern with AccountRequest.
  • view package resolution + updated BCS layouts align with the stated on-chain changes.
  • Newly added tests cover key PTB wiring and fetch parsing paths.

🤖 Generated with Rex (OpenClaw)

Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Found 2 issues:


1. N+1 RPC calls from viewPackageForObject — every view call now fetches the shared object type first

getAccountsByOwner, getAccountDelegates, getAccountObjectId each call viewPackageForObject(client, client.config.accountRegistry) — resolving the same object ID on every invocation. Same for getMarketSummary / getPosition / positionExists (each resolving the market object), and pool queries (resolving wlpPool). Without memoization this doubles latency on every read.

Suggestion: cache resolved package IDs at the call site (e.g. a module-level Map<objectId, packageId> or inside WaterXClient) — the type of a shared object doesn't change unless deliberately upgraded, so a session-scoped cache is safe.

waterx-sdk/src/fetch.ts

Lines 145 to 157 in 99e7093

* package ID than `config.packageId` while `AccountRegistry` / `GlobalConfig` stay on an
* older publish. `view::*` must be invoked from the package that defines the argument type.
*/
function packageIdFromMoveStructType(moveType: string): string {
const sep = moveType.indexOf("::");
if (sep <= 0) {
throw new Error(`Invalid Move object type: ${moveType}`);
}
return moveType.slice(0, sep);
}
async function viewPackageForObject(client: WaterXClient, objectId: string): Promise<string> {
const res = await client.getObject(objectId);


2. buildMintWlpTx and buildSettleRedeemWlpTx are now async — silent breaking change for callers

Both functions changed from sync to async. Any caller that was using the return value without await (e.g. directly passing to signAndExecuteTransaction) will silently pass a Promise<Transaction> instead of a Transaction. TypeScript will catch this if callers are typed, but if any downstream code uses these via the SDK without strict type-checking, it will silently break at runtime. Worth a clear callout in the release notes or a CHANGELOG entry.

depositCoin: any;
/** Deposit coin type (default: config `usdcType`) */
depositTokenType?: string;
/** Minimum LP tokens to receive (slippage protection). Default: 0 */
minLpAmount?: bigint | number;
/** Recipient address for LP tokens */
recipient: string;

requestId: bigint | number;
/** Must match the type used in `request_redeem` (default: config `usdcType`) */
redeemTokenType?: string;
gasBudget?: number;
pythCache?: PythCache;
}
export async function buildSettleRedeemWlpTx(


Everything else looks solid:

  • Contract alignment (3 type args for destroy_response, deposit_collateral / withdraw_collateral renames, accountSenderRequest wiring, recipient on requestRedeemWlp) is consistent throughout
  • BCS fix (lp_decimal: bcs.u8()) is correct — the old u64 would have silently corrupted all subsequent fields
  • viewPackageForObject pattern is the right approach for handling package upgrades between shared objects
  • Testnet constant updates (GLOBAL_CONFIG, ACCOUNT_REGISTRY, REFERRAL_TABLE, WATERX_PERP) look consistent
  • CI consolidation (replacing lint.yml + unit-test.yml with single ci.yml) is cleaner; Semgrep shell injection fix (inputs via env) is correct
  • Test infrastructure (multi-project Vitest, coverage-v8, PTB assertion helpers) is well-structured

📦 Dependency Security

New devDeps: @vitest/coverage-v8, dotenv, typescript-eslint, eslint-config-prettier, globals — all well-established packages, no advisories or concerns.

🤖 Generated with Jarvis (OpenClaw)

Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Notes from spot-check:

  • trading PTB flow matches latest request/execute/destroy_response pattern with AccountRequest.
  • fetch view package resolution + updated BCS layouts align with the stated on-chain changes.
  • Newly added tests cover key PTB wiring and fetch parsing paths.

🤖 Generated with Rex (OpenClaw)

runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊好像可以用最新的v5那些

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好,我改下

Copy link
Copy Markdown
Contributor

@bucket-bot bucket-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review (latest contract alignment: naming & params)

整體對齊方向是對的,不過有幾個命名/參數面向建議再收斂,避免 SDK 使用端誤解:

  1. Builder async breaking change 需要明確標示

    • buildMintWlpTxbuildSettleRedeemWlpTx 已改成 async(回傳 Promise<Transaction>)。
    • 建議在 README / changelog 明確標記 breaking change,並在 migration snippet 全部補 await
  2. accountId 命名語意偏弱,建議改成 accountObjectAddress(或 userAccountAddress

    • 多處實際是 tx.pure.address(...) 且語意是 UserAccount object address。
    • 目前 accountId 容易讓人誤以為是 numeric id / registry index。
  3. 保留舊 API 名稱可理解,但應明確 deprecate

    • increaseCollateral / releaseCollateral 實際已對應 deposit_collateral_request / withdraw_collateral_request
    • 建議:
      • 新增對外 alias:depositCollateral / withdrawCollateral
      • 舊名稱加 @deprecated 註記 + 移轉說明。
  4. ViewMarketTypeArgs 包含 baseTokenType 但目前被忽略,容易誤導

    • 若現階段只吃 LP type,建議先移除 baseTokenType 或在型別名稱/註解明確標示 ignored。
  5. viewPackageForObject 建議加 cache(效能)

    • 現在每次 view call 都會 getObject 解析 package。
    • 可在 WaterXClient 或 module scope 做 Map<objectId, packageId> 快取,減少重複 RPC。

以上都偏 API ergonomics / DX 層級,非 blocker。

🤖 Generated with Rex (OpenClaw)

feed: PYTH_TESTNET_FEED_IDS["ETH/USD"]!.replace(/^0x/, ""),
};
}
throw new Error(`No Pyth feed mapping for token type: ${tokenType}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

除了這三個交易對 其他都暫時沒有嗎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前接 Hermes 只有 config 裡那幾個、若要再支援其他幣種,需要再補 mapping 或改用低階方式自己帶價格

const cfg = client.config;

increasePosition(client, tx, {
collateralTokenType: cfg.usdcType,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊是不是先不要寫死?之後還有其他抵押品?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

應該讓外部傳入?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

高階 build*Tx 這邊加上可選的 collateralTokenType,不填的話預設還是 USDC

const cfg = client.config;

decreasePosition(client, tx, {
collateralTokenType: cfg.usdcType,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裡也是?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上~

tx.object(client.config.globalConfig),
tx.object(client.config.accountRegistry),
tx.object(params.market),
tx.pure.id(params.accountId),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊還要叫accountid 嗎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要,公開API一律改為 accountObjectAddress(UserAccount 的物件 id 字串)

do0x0ob added 5 commits April 2, 2026 17:19
…ses, view cache

- README: breaking change for async buildMintWlpTx/buildSettleRedeemWlpTx; accountId semantics
- trading: depositCollateral/withdrawCollateral as primary; deprecate increase/release
- tx-builders: buildDepositCollateralTx/buildWithdrawCollateralTx; deprecate old names
- fetch: ViewMarketTypeArgs only lpTokenType; module Map cache for viewPackageForObject
- Tests: stub getObject for view helpers; use new builder/trading names
- CLAUDE.md: document preferred collateral API names

Made-with: Cursor
…order accountObjectAddress

- addPriceFeeds/fetchAccountCoins use configurable collateral type (default usdcType)
- resolveTokenPriceFeed: document scope; clearer error for unmapped types
- PlaceOrderParams/CancelOrderParams: accountId -> accountObjectAddress (breaking)
- BuildPlaceOrderParams/BuildCancelOrderParams: accountObjectAddress + optional collateralTokenType
- README/CLAUDE: Allen review (pairs scope, collateral override, naming)

Made-with: Cursor
- Rename public accountId fields to accountObjectAddress (trading, account,
  tx-builders, AccountInfo, fetch helpers) for consistent naming with orders.
- Document pure.address vs pure.id usage in README and CLAUDE.md.
- Add PTB_DUMMY_ID_CC / PTB_DUMMY_OBJECT_DD; reuse dummies in unit tests.

Made-with: Cursor
- withdrawCollateral / buildWithdrawCollateralTx: primary collateralAmount, deprecated amount.
- parseTokenPoolSummaryReturn: legacy 72B + optional 8B tail, or vNext BCS (u8 decimal + timestamp).
- Mark getAccountObjectId @deprecated; README/CLAUDE + simulate test use accountObjectAddress.

Made-with: Cursor
@JustaLiang JustaLiang merged commit 92ad299 into main Apr 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants