Skip to content

[WL-492] feat/Bucket SDK Skills#120

Open
ZouBadCode wants to merge 49 commits intomainfrom
skill
Open

[WL-492] feat/Bucket SDK Skills#120
ZouBadCode wants to merge 49 commits intomainfrom
skill

Conversation

@ZouBadCode
Copy link
Contributor

Summary

Add a Copilot Skill for the Bucket Protocol SDK (bucket-sdk). This gives GitHub Copilot deep, structured knowledge of the SDK so it can accurately assist with CDP transactions, PSM swaps, saving pool operations, oracle queries, flash mints, and leverage patterns — without hallucinating API signatures or misunderstanding protocol mechanics.

The skill is strictly additive (4 new files, 966 lines) and does not modify any source code.

Changes

SKILL.md (+421 lines)

Main integration guide consumed by Copilot. Covers:

  • Installation & peer dependencies
  • Quick start with BucketClient.initialize() and buildManagePositionTransaction
  • Key concepts: PTB builder pattern, coinWithBalance lazy resolver, decimal table, Account vs EOA
  • Full API reference for all query methods and transaction builders (CDP, Saving, PSM, Flash Mint)
  • Composing multiple operations in a single PTB (e.g. PSM swap → saving deposit)
  • One-click leverage pattern via flash mint
  • Complete low-level PTB helper listing (price, CDP internals, pool calls, object refs, account helpers)
  • All public types (VaultInfo, PositionInfo, SavingPoolInfo, PsmPoolInfo, SavingInfo, FlashMintInfo)
  • 9 common gotchas (async vs sync builders, zero coin cleanup, mint caps, full liquidation, etc.)

coin-types.md (+100 lines)

Reference table of all mainnet coin type strings organized by category:

  • USDB stablecoin
  • 16 basic collateral types (SUI, BTC, ETH, WAL, USDC, USDT, haSUI, CERT, afSUI, SCA, BUCK, DEEP, XBTC, WBTC, UP_USD, XAUM)
  • 10 derivative collateral types (7 sCoin, 2 gCoin, 1 BFBTC) with underlying mappings
  • PSM pool coins, saving pool LP types, common reward types, BUT protocol token

protocol-concepts.md (+342 lines)

Protocol-level decision guide covering:

  • CDP mechanics: CR formula, liquidation price calculation, MCR, interest model (no borrow fee)
  • Liquidation: full seizure, flash-mint-based execution, bad-debt backstop
  • USDB peg: PSM 1:1 swaps, arbitrage conditions (upward/downward depeg), PSM vs CDP decision table
  • Two-layer saving system: sUSDB/BSR (Layer 1) and sUSDB Savings Pool rewards (Layer 2)
  • Flash mint mechanics and use cases
  • Leverage patterns: one-click (flash mint) and manual looping
  • Account system: EOA vs Account objects

query-state.ts (+103 lines)

Diagnostic script for querying live on-chain state. Prints USDB supply, oracle prices, vault stats, PSM pool balances, saving pool info, flash mint fees, and supported collateral types. Runnable via npx tsx skills/bucket-sdk/scripts/query-state.ts.

do0x0ob and others added 30 commits March 2, 2026 17:24
- Add test/__mocks__/fetch.ts with mockFetchOk/mockFetchFail factories
- Add test/fixtures/pyth-config.ts for shared Pyth config
- Move pyth.test.ts to test/unit/utils/ (mirror src/utils/)
- Add transaction.test.ts for getZeroCoin, destroyZeroCoin, coinWithBalance
- Add test:unit, test:e2e, test:watch scripts
- Set vitest testTimeout/hookTimeout to 10s

Made-with: Cursor
- Replace single client.test.ts with domain-specific files (oracle, config,
  cdp, flash, psm, saving, savings-rewards, supply-pools, vaults, etc.)
- Add shared setup helpers in test/e2e/helpers/setup.ts

Made-with: Cursor
- Move buildClaimBorrowRewardsTransaction to rewards.test.ts for consistency
- Fix vaults assertions: use toBe('bigint') and toBeGreaterThanOrEqual
- Replace early returns with explicit expect in oracle tests
- Extract TEST_AMOUNT_USDB constant in saving.test.ts

Made-with: Cursor
- Add on-chain config: entry.ts, bucketConfig.ts, configAdapter.ts
- Client: BucketClient.create(), refreshConfig(), require config in ctor
- Remove static src/consts/config.ts; config now fetched from chain
- E2E: inter-file delay (2s), per-test delay (600ms), setupE2E with retry
- Vitest: retry once on RESOURCE_EXHAUSTED / Too Many Requests (3s delay)
- Add onchain-config.test.ts and rateLimit.ts helpers

Made-with: Cursor
…ent typing; update test setup and formatting

Made-with: Cursor
…ides, ensureConfig race, initialSharedVersion enrichment

- queryAllConfig: fail-fast on sub-object fetch/parse errors instead of returning partial config
- refreshConfig: preserve configOverrides when called without args
- ensureConfig: use cached promise to prevent concurrent RPC calls
- enrichSharedObjectRefs: fetch initialSharedVersion for refs with objectId-only (fixes PTB tx failure)
- Add unit tests for all four fixes

Made-with: Cursor
…onfig) before queryAllConfig return

- Add required-section and key-field validation to fail-fast on incomplete RPC response
- Throw when any required section is missing or key field is empty
- Add unit tests for validation failure cases

Made-with: Cursor
- bucketConfig: missing oracleConfig/objectConfig, empty pyth_state_id, empty treasury_obj
- configAdapter: empty objectId skip, deduplication, non-Shared owner skip, no-refs case
- client: explicit refreshConfig overrides, ensureConfig when config already loaded

Made-with: Cursor
…edge tests

- client: clear _configInitPromise in ensureConfig catch so subsequent calls can retry
- client: fix mockImplementation type for queryAllConfig
- test: add reverse tests (enrichSharedObjectRefs immutability, refreshConfig({}), no retry on success)
- test: add expect.fail pattern for required section throw case
- prettier

Made-with: Cursor
- Add await to all async method calls (getAllCollateralTypes, build*,
  flashMint/flashBurn, getAggregatorObjectInfo, getVaultObjectInfo, etc.)
- Update version 1.2.8 -> 2.0.1
- Fix Example Project link (client.test.ts -> test/e2e/ directory)
- Constructor config is optional (lazy-load from chain)

Made-with: Cursor
Made-with: Cursor
- Replace private _config + getter with direct config field (match main style)
- Fix flashBurn param: use flashMintReceipt in README Pattern 2
- Update example project path to actual e2e test files
- Bump version in README to 2.0.1

Made-with: Cursor
ZouBadCode and others added 18 commits March 4, 2026 17:30
…config

- Replace _generated_onchain_config with _generated/bucket_onchain_config
- Update BucketOnchainConfig to use raw on-chain JSON shape (Record<string, unknown>)
- bucketConfig now defines local types; generated modules export BCS structs, not TS types
- Add bucket_onchain_config bindings (copied from external source)
- Remove codegen tooling (sui-codegen.config.ts, scripts, @mysten/codegen)
- Add sui-codegen.config.ts to .gitignore, pnpm-lock.yaml to .prettierignore

Made-with: Cursor
…jectRefs

Silent failure left initialSharedVersion at 0 when object fetch failed,
causing PTB to fail at execution with no clear indication of the cause.
Now logs objectId and error message for easier debugging.

Made-with: Cursor
…ated types

- Use SharedObjectRef, RewarderInfo, PsmPoolObjectInfo from generated $inferType
- Switch config parsing to snake_case and enum shapes ({ Pyth: {...} }, { SCOIN: {...} }, etc.)
- Keep manual types for AggregatorObjectInfo, PriceConfigInfo (MoveEnum requires $kind; we parse from JSON)
- Keep manual types for VaultObjectInfo, SavingPoolObjectInfo (optional rewarders/reward when empty)
- Change initialSharedVersion to string type to match BCS schema
- Update client.ts, configAdapter, and all related tests

Made-with: Cursor
On-chain derivative_kind can be 'Unihouse'; dk mapping already maps it to
'gCoin', but the switch lacked the case and threw Unsupported derivative kind.

Made-with: Cursor
…rnType

- Replace simulateTransaction + borrow_cap_mut with stateService.getCoinInfo
- PTB cannot pass &mut references between commands; SDK v2 validates and rejects
- Tighten test assertion: expect supply > 0 (was >= 0, masked failures)

Made-with: Cursor
…ls until realtime_reward_amount_by_manager)

Made-with: Cursor
…s, unit tests

- Add all-query-outputs.test.ts with getAccountBorrowRewards using coinTypesWithRewarders
- Add unit tests for client, bucketConfig, configAdapter, resolvers, transaction
- Extend cdp.test, oracle.test

Note: getAccountSavingPoolRewards / getUserSavings / getAccountSavings tests remain
skipped — not yet fixed (awaiting contract upgrade for PTB reference limitation).

Made-with: Cursor
- Replace get_rewarder + realtime_reward_amount with single get_realtime_reward_amount
  call to avoid PTB reference limitation (references cannot be passed between commands)
- Simplify response parsing: one result per reward type instead of two
- Re-enable savings-rewards e2e tests (getUserSavings, getAccountSavings,
  getAccountSavingPoolRewards) now that contract upgrade is deployed
- Remove pool: 'forks' from vitest config

Made-with: Cursor
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.

2 participants