@waterx/sdk 3.0.1 → 3.0.3
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/dist/cjs/package.json +3 -0
- package/dist/cjs/src/account/account-request.d.ts +9 -0
- package/dist/cjs/src/account/account-request.js +20 -0
- package/dist/cjs/src/account/account.d.ts +158 -0
- package/dist/cjs/src/account/account.js +238 -0
- package/dist/cjs/src/account/client.d.ts +42 -0
- package/dist/cjs/src/account/client.js +18 -0
- package/dist/cjs/src/account/config.d.ts +151 -0
- package/dist/cjs/src/account/config.js +9 -0
- package/dist/cjs/src/account/constants.d.ts +5 -0
- package/dist/cjs/src/account/constants.js +8 -0
- package/dist/cjs/src/account/fetch/referral.d.ts +15 -0
- package/dist/cjs/src/account/fetch/referral.js +56 -0
- package/dist/cjs/src/account/fetch/simulate.d.ts +34 -0
- package/dist/cjs/src/account/fetch/simulate.js +49 -0
- package/dist/cjs/src/account/funding/balance.d.ts +32 -0
- package/dist/cjs/src/account/funding/balance.js +100 -0
- package/dist/cjs/src/account/funding/consolidate.d.ts +46 -0
- package/dist/cjs/src/account/funding/consolidate.js +143 -0
- package/dist/cjs/src/account/funding/credit.d.ts +129 -0
- package/dist/cjs/src/account/funding/credit.js +252 -0
- package/dist/cjs/src/account/funding/custody.d.ts +57 -0
- package/dist/cjs/src/account/funding/custody.js +139 -0
- package/dist/cjs/src/account/funding/wormhole.d.ts +86 -0
- package/dist/cjs/src/account/funding/wormhole.js +166 -0
- package/dist/cjs/src/account/index.d.ts +29 -0
- package/dist/cjs/src/account/index.js +45 -0
- package/dist/cjs/src/account/referral.d.ts +21 -0
- package/dist/cjs/src/account/referral.js +78 -0
- package/dist/cjs/src/account/waterx-account.d.ts +31 -0
- package/dist/cjs/src/account/waterx-account.js +29 -0
- package/dist/cjs/src/base-client.d.ts +74 -0
- package/dist/cjs/src/base-client.js +101 -0
- package/dist/cjs/src/constants.d.ts +32 -0
- package/dist/cjs/src/constants.js +41 -0
- package/dist/cjs/src/generated/bucket_v2_framework/account.d.ts +107 -0
- package/dist/cjs/src/generated/bucket_v2_framework/account.js +141 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/bucket_v2_framework/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/bucket_v2_framework/double.d.ts +384 -0
- package/dist/cjs/src/generated/bucket_v2_framework/double.js +504 -0
- package/dist/cjs/src/generated/bucket_v2_framework/float.d.ts +364 -0
- package/dist/cjs/src/generated/bucket_v2_framework/float.js +476 -0
- package/dist/cjs/src/generated/bucket_v2_framework/liability.d.ts +171 -0
- package/dist/cjs/src/generated/bucket_v2_framework/liability.js +192 -0
- package/dist/cjs/src/generated/bucket_v2_framework/linked_table.d.ts +384 -0
- package/dist/cjs/src/generated/bucket_v2_framework/linked_table.js +405 -0
- package/dist/cjs/src/generated/bucket_v2_framework/sheet.d.ts +424 -0
- package/dist/cjs/src/generated/bucket_v2_framework/sheet.js +395 -0
- package/dist/cjs/src/generated/native_custody/custody_vault.d.ts +586 -0
- package/dist/cjs/src/generated/native_custody/custody_vault.js +555 -0
- package/dist/cjs/src/generated/native_custody/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/native_custody/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/native_custody/deps/bucket_v2_framework/liability.d.ts +11 -0
- package/dist/cjs/src/generated/native_custody/deps/bucket_v2_framework/liability.js +16 -0
- package/dist/cjs/src/generated/native_custody/deps/bucket_v2_framework/sheet.d.ts +49 -0
- package/dist/cjs/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +52 -0
- package/dist/cjs/src/generated/native_custody/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/native_custody/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/native_custody/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/native_custody/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/native_custody/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/native_custody/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/native_custody/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/native_custody/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/native_custody/events.d.ts +36 -0
- package/dist/cjs/src/generated/native_custody/events.js +71 -0
- package/dist/cjs/src/generated/pyth_sponsor_rule/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/pyth_sponsor_rule/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +68 -0
- package/dist/cjs/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +113 -0
- package/dist/cjs/src/generated/utils/index.d.ts +30 -0
- package/dist/cjs/src/generated/utils/index.js +168 -0
- package/dist/cjs/src/generated/waterx_account/account.d.ts +1906 -0
- package/dist/cjs/src/generated/waterx_account/account.js +1929 -0
- package/dist/cjs/src/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +11 -0
- package/dist/cjs/src/generated/waterx_account/deps/bucket_v2_framework/liability.js +16 -0
- package/dist/cjs/src/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +49 -0
- package/dist/cjs/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +52 -0
- package/dist/cjs/src/generated/waterx_account/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/waterx_account/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/object_table.d.ts +17 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/object_table.js +22 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/table.d.ts +29 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/table.js +34 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_account/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_account/direct_rule.d.ts +77 -0
- package/dist/cjs/src/generated/waterx_account/direct_rule.js +83 -0
- package/dist/cjs/src/generated/waterx_account/events.d.ts +190 -0
- package/dist/cjs/src/generated/waterx_account/events.js +173 -0
- package/dist/cjs/src/generated/waterx_account/version.d.ts +10 -0
- package/dist/cjs/src/generated/waterx_account/version.js +11 -0
- package/dist/cjs/src/generated/waterx_constant_rule/constant_rule.d.ts +68 -0
- package/dist/cjs/src/generated/waterx_constant_rule/constant_rule.js +97 -0
- package/dist/cjs/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/waterx_constant_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_constant_rule/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_credit/credit_registry.d.ts +708 -0
- package/dist/cjs/src/generated/waterx_credit/credit_registry.js +728 -0
- package/dist/cjs/src/generated/waterx_credit/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/waterx_credit/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/waterx_credit/deps/sui/table.d.ts +29 -0
- package/dist/cjs/src/generated/waterx_credit/deps/sui/table.js +34 -0
- package/dist/cjs/src/generated/waterx_credit/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_credit/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_credit/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_credit/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_credit/limited_supply.d.ts +107 -0
- package/dist/cjs/src/generated/waterx_credit/limited_supply.js +143 -0
- package/dist/cjs/src/generated/waterx_oracle/aggregator.d.ts +211 -0
- package/dist/cjs/src/generated/waterx_oracle/aggregator.js +258 -0
- package/dist/cjs/src/generated/waterx_oracle/collector.d.ts +119 -0
- package/dist/cjs/src/generated/waterx_oracle/collector.js +147 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_oracle/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_oracle/oracle.d.ts +304 -0
- package/dist/cjs/src/generated/waterx_oracle/oracle.js +381 -0
- package/dist/cjs/src/generated/waterx_oracle/version.d.ts +10 -0
- package/dist/cjs/src/generated/waterx_oracle/version.js +11 -0
- package/dist/cjs/src/generated/waterx_perp/account_data.d.ts +269 -0
- package/dist/cjs/src/generated/waterx_perp/account_data.js +340 -0
- package/dist/cjs/src/generated/waterx_perp/admin.d.ts +19 -0
- package/dist/cjs/src/generated/waterx_perp/admin.js +26 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/double.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/double.js +13 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/liability.d.ts +11 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/liability.js +16 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/linked_table.js +21 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.d.ts +49 -0
- package/dist/cjs/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +52 -0
- package/dist/cjs/src/generated/waterx_perp/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/waterx_perp/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/balance.d.ts +15 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/balance.js +20 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/coin.d.ts +14 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/coin.js +51 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_perp/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_perp/events.d.ts +1283 -0
- package/dist/cjs/src/generated/waterx_perp/events.js +990 -0
- package/dist/cjs/src/generated/waterx_perp/global_config.d.ts +775 -0
- package/dist/cjs/src/generated/waterx_perp/global_config.js +918 -0
- package/dist/cjs/src/generated/waterx_perp/keyed_big_vector.d.ts +553 -0
- package/dist/cjs/src/generated/waterx_perp/keyed_big_vector.js +626 -0
- package/dist/cjs/src/generated/waterx_perp/lp_pool.d.ts +1648 -0
- package/dist/cjs/src/generated/waterx_perp/lp_pool.js +1630 -0
- package/dist/cjs/src/generated/waterx_perp/market_config.d.ts +733 -0
- package/dist/cjs/src/generated/waterx_perp/market_config.js +871 -0
- package/dist/cjs/src/generated/waterx_perp/math.d.ts +63 -0
- package/dist/cjs/src/generated/waterx_perp/math.js +70 -0
- package/dist/cjs/src/generated/waterx_perp/memo.d.ts +251 -0
- package/dist/cjs/src/generated/waterx_perp/memo.js +360 -0
- package/dist/cjs/src/generated/waterx_perp/order_book.d.ts +290 -0
- package/dist/cjs/src/generated/waterx_perp/order_book.js +388 -0
- package/dist/cjs/src/generated/waterx_perp/position.d.ts +1005 -0
- package/dist/cjs/src/generated/waterx_perp/position.js +1200 -0
- package/dist/cjs/src/generated/waterx_perp/request.d.ts +544 -0
- package/dist/cjs/src/generated/waterx_perp/request.js +609 -0
- package/dist/cjs/src/generated/waterx_perp/response.d.ts +247 -0
- package/dist/cjs/src/generated/waterx_perp/response.js +331 -0
- package/dist/cjs/src/generated/waterx_perp/trading.d.ts +2945 -0
- package/dist/cjs/src/generated/waterx_perp/trading.js +2616 -0
- package/dist/cjs/src/generated/waterx_perp/version.d.ts +10 -0
- package/dist/cjs/src/generated/waterx_perp/version.js +11 -0
- package/dist/cjs/src/generated/waterx_perp/witness.d.ts +18 -0
- package/dist/cjs/src/generated/waterx_perp/witness.js +25 -0
- package/dist/cjs/src/generated/waterx_perp_view/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/waterx_perp_view/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/waterx_perp_view/view.d.ts +447 -0
- package/dist/cjs/src/generated/waterx_perp_view/view.js +459 -0
- package/dist/cjs/src/generated/waterx_prediction/account_data.d.ts +344 -0
- package/dist/cjs/src/generated/waterx_prediction/account_data.js +470 -0
- package/dist/cjs/src/generated/waterx_prediction/admin.d.ts +7 -0
- package/dist/cjs/src/generated/waterx_prediction/admin.js +12 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +21 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/sui/table.d.ts +29 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/sui/table.js +34 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_prediction/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_prediction/events.d.ts +288 -0
- package/dist/cjs/src/generated/waterx_prediction/events.js +254 -0
- package/dist/cjs/src/generated/waterx_prediction/global_config.d.ts +121 -0
- package/dist/cjs/src/generated/waterx_prediction/global_config.js +186 -0
- package/dist/cjs/src/generated/waterx_prediction/order.d.ts +233 -0
- package/dist/cjs/src/generated/waterx_prediction/order.js +339 -0
- package/dist/cjs/src/generated/waterx_prediction/outcome.d.ts +58 -0
- package/dist/cjs/src/generated/waterx_prediction/outcome.js +82 -0
- package/dist/cjs/src/generated/waterx_prediction/position.d.ts +175 -0
- package/dist/cjs/src/generated/waterx_prediction/position.js +232 -0
- package/dist/cjs/src/generated/waterx_prediction/version.d.ts +10 -0
- package/dist/cjs/src/generated/waterx_prediction/version.js +11 -0
- package/dist/cjs/src/generated/waterx_prediction/view.d.ts +418 -0
- package/dist/cjs/src/generated/waterx_prediction/view.js +492 -0
- package/dist/cjs/src/generated/waterx_prediction/waterx_prediction.d.ts +1858 -0
- package/dist/cjs/src/generated/waterx_prediction/waterx_prediction.js +1972 -0
- package/dist/cjs/src/generated/waterx_pyth_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_pyth_rule/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_pyth_rule/pyth_rule.d.ts +192 -0
- package/dist/cjs/src/generated/waterx_pyth_rule/pyth_rule.js +214 -0
- package/dist/cjs/src/generated/waterx_referral/deps/sui/table.d.ts +29 -0
- package/dist/cjs/src/generated/waterx_referral/deps/sui/table.js +34 -0
- package/dist/cjs/src/generated/waterx_referral/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_referral/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_referral/referral_table.d.ts +171 -0
- package/dist/cjs/src/generated/waterx_referral/referral_table.js +239 -0
- package/dist/cjs/src/generated/waterx_staking/deps/bucket_v2_framework/double.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_staking/deps/bucket_v2_framework/double.js +13 -0
- package/dist/cjs/src/generated/waterx_staking/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/waterx_staking/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/waterx_staking/deps/sui/table.d.ts +29 -0
- package/dist/cjs/src/generated/waterx_staking/deps/sui/table.js +34 -0
- package/dist/cjs/src/generated/waterx_staking/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_staking/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/waterx_staking/waterx_staking.d.ts +746 -0
- package/dist/cjs/src/generated/waterx_staking/waterx_staking.js +797 -0
- package/dist/cjs/src/generated/waterx_staking/witness.d.ts +16 -0
- package/dist/cjs/src/generated/waterx_staking/witness.js +21 -0
- package/dist/cjs/src/generated/waterx_supra_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_supra_rule/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_supra_rule/supra_rule.d.ts +158 -0
- package/dist/cjs/src/generated/waterx_supra_rule/supra_rule.js +189 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/bucket_v2_framework/linked_table.js +21 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/std/type_name.d.ts +17 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/std/type_name.js +22 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/sui/balance.d.ts +12 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/sui/balance.js +17 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/withdrawal_queue/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/withdrawal_queue/withdrawal_queue.d.ts +923 -0
- package/dist/cjs/src/generated/withdrawal_queue/withdrawal_queue.js +965 -0
- package/dist/cjs/src/generated/wlp/wlp.d.ts +28 -0
- package/dist/cjs/src/generated/wlp/wlp.js +37 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/sui/table.d.ts +29 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/sui/table.js +34 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/sui/vec_set.d.ts +16 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/sui/vec_set.js +22 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/wormhole_sdk/consumed_vaas.d.ts +12 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/wormhole_sdk/consumed_vaas.js +45 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/wormhole_sdk/emitter.d.ts +14 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/wormhole_sdk/emitter.js +19 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/wormhole_sdk/set.d.ts +16 -0
- package/dist/cjs/src/generated/wormhole_bridge/deps/wormhole_sdk/set.js +51 -0
- package/dist/cjs/src/generated/wormhole_bridge/events.d.ts +32 -0
- package/dist/cjs/src/generated/wormhole_bridge/events.js +31 -0
- package/dist/cjs/src/generated/wormhole_bridge/wormhole_bridge.d.ts +638 -0
- package/dist/cjs/src/generated/wormhole_bridge/wormhole_bridge.js +692 -0
- package/dist/cjs/src/oracle/aggregate.d.ts +74 -0
- package/dist/cjs/src/oracle/aggregate.js +118 -0
- package/dist/cjs/src/oracle/config.d.ts +99 -0
- package/dist/cjs/src/oracle/config.js +26 -0
- package/dist/cjs/src/oracle/host.d.ts +32 -0
- package/dist/cjs/src/oracle/host.js +11 -0
- package/dist/cjs/src/oracle/index.d.ts +16 -0
- package/dist/cjs/src/oracle/index.js +31 -0
- package/dist/cjs/src/oracle/pyth.d.ts +52 -0
- package/dist/cjs/src/oracle/pyth.js +227 -0
- package/dist/cjs/src/oracle/rules/constant-rule.d.ts +9 -0
- package/dist/cjs/src/oracle/rules/constant-rule.js +17 -0
- package/dist/cjs/src/oracle/rules/pyth-rule.d.ts +11 -0
- package/dist/cjs/src/oracle/rules/pyth-rule.js +23 -0
- package/dist/cjs/src/oracle/rules/sponsor.d.ts +28 -0
- package/dist/cjs/src/oracle/rules/sponsor.js +52 -0
- package/dist/cjs/src/oracle/rules/supra-rule.d.ts +11 -0
- package/dist/cjs/src/oracle/rules/supra-rule.js +25 -0
- package/dist/cjs/src/perp/client.d.ts +78 -0
- package/dist/cjs/src/perp/client.js +112 -0
- package/dist/cjs/src/perp/config-view.d.ts +102 -0
- package/dist/cjs/src/perp/config-view.js +178 -0
- package/dist/cjs/src/perp/config.d.ts +126 -0
- package/dist/cjs/src/perp/config.js +119 -0
- package/dist/cjs/src/perp/constants.d.ts +49 -0
- package/dist/cjs/src/perp/constants.js +79 -0
- package/dist/cjs/src/perp/fetch/account.d.ts +43 -0
- package/dist/cjs/src/perp/fetch/account.js +69 -0
- package/dist/cjs/src/perp/fetch/bridge.d.ts +90 -0
- package/dist/cjs/src/perp/fetch/bridge.js +131 -0
- package/dist/cjs/src/perp/fetch/custody.d.ts +32 -0
- package/dist/cjs/src/perp/fetch/custody.js +66 -0
- package/dist/cjs/src/perp/fetch/market.d.ts +30 -0
- package/dist/cjs/src/perp/fetch/market.js +75 -0
- package/dist/cjs/src/perp/fetch/positions.d.ts +70 -0
- package/dist/cjs/src/perp/fetch/positions.js +195 -0
- package/dist/cjs/src/perp/fetch/simulate.d.ts +12 -0
- package/dist/cjs/src/perp/fetch/simulate.js +21 -0
- package/dist/cjs/src/perp/fetch.d.ts +23 -0
- package/dist/cjs/src/perp/fetch.js +39 -0
- package/dist/cjs/src/perp/index.d.ts +29 -0
- package/dist/cjs/src/perp/index.js +183 -0
- package/dist/cjs/src/perp/tx-builders/common.d.ts +83 -0
- package/dist/cjs/src/perp/tx-builders/common.js +76 -0
- package/dist/cjs/src/perp/tx-builders/credit.d.ts +65 -0
- package/dist/cjs/src/perp/tx-builders/credit.js +67 -0
- package/dist/cjs/src/perp/tx-builders/rewards.d.ts +30 -0
- package/dist/cjs/src/perp/tx-builders/rewards.js +37 -0
- package/dist/cjs/src/perp/tx-builders/trading.d.ts +51 -0
- package/dist/cjs/src/perp/tx-builders/trading.js +71 -0
- package/dist/cjs/src/perp/tx-builders/wlp.d.ts +90 -0
- package/dist/cjs/src/perp/tx-builders/wlp.js +126 -0
- package/dist/cjs/src/perp/tx-builders.d.ts +23 -0
- package/dist/cjs/src/perp/tx-builders.js +45 -0
- package/dist/cjs/src/perp/user/index.d.ts +8 -0
- package/dist/cjs/src/perp/user/index.js +24 -0
- package/dist/cjs/src/perp/user/order.d.ts +89 -0
- package/dist/cjs/src/perp/user/order.js +175 -0
- package/dist/cjs/src/perp/user/staking.d.ts +54 -0
- package/dist/cjs/src/perp/user/staking.js +147 -0
- package/dist/cjs/src/perp/user/trading.d.ts +119 -0
- package/dist/cjs/src/perp/user/trading.js +310 -0
- package/dist/cjs/src/perp/user/wlp.d.ts +58 -0
- package/dist/cjs/src/perp/user/wlp.js +139 -0
- package/dist/cjs/src/prediction/account.d.ts +96 -0
- package/dist/cjs/src/prediction/account.js +212 -0
- package/dist/cjs/src/prediction/admin.d.ts +47 -0
- package/dist/cjs/src/prediction/admin.js +116 -0
- package/dist/cjs/src/prediction/bcs.d.ts +28 -0
- package/dist/cjs/src/prediction/bcs.js +189 -0
- package/dist/cjs/src/prediction/client.d.ts +45 -0
- package/dist/cjs/src/prediction/client.js +112 -0
- package/dist/cjs/src/prediction/config.d.ts +74 -0
- package/dist/cjs/src/prediction/config.js +86 -0
- package/dist/cjs/src/prediction/constants.d.ts +44 -0
- package/dist/cjs/src/prediction/constants.js +49 -0
- package/dist/cjs/src/prediction/fetch.d.ts +82 -0
- package/dist/cjs/src/prediction/fetch.js +294 -0
- package/dist/cjs/src/prediction/gift-link.d.ts +6 -0
- package/dist/cjs/src/prediction/gift-link.js +16 -0
- package/dist/cjs/src/prediction/gift.d.ts +223 -0
- package/dist/cjs/src/prediction/gift.js +465 -0
- package/dist/cjs/src/prediction/index.d.ts +29 -0
- package/dist/cjs/src/prediction/index.js +154 -0
- package/dist/cjs/src/prediction/prediction.d.ts +149 -0
- package/dist/cjs/src/prediction/prediction.js +410 -0
- package/dist/cjs/src/prediction/tx-builders.d.ts +44 -0
- package/dist/cjs/src/prediction/tx-builders.js +56 -0
- package/dist/cjs/src/prediction/types.d.ts +95 -0
- package/dist/cjs/src/prediction/types.js +2 -0
- package/dist/cjs/src/prediction/user/account.d.ts +2 -0
- package/dist/cjs/src/prediction/user/account.js +17 -0
- package/dist/cjs/src/prediction/user/admin.d.ts +6 -0
- package/dist/cjs/src/prediction/user/admin.js +19 -0
- package/dist/cjs/src/prediction/user/gift.d.ts +2 -0
- package/dist/cjs/src/prediction/user/gift.js +24 -0
- package/dist/cjs/src/prediction/user/index.d.ts +5 -0
- package/dist/cjs/src/prediction/user/index.js +60 -0
- package/dist/cjs/src/prediction/user/keeper.d.ts +2 -0
- package/dist/cjs/src/prediction/user/keeper.js +13 -0
- package/dist/cjs/src/prediction/user/order.d.ts +2 -0
- package/dist/cjs/src/prediction/user/order.js +6 -0
- package/dist/cjs/src/prediction/user/position.d.ts +2 -0
- package/dist/cjs/src/prediction/user/position.js +11 -0
- package/dist/cjs/src/prediction/utils/bcs.d.ts +6 -0
- package/dist/cjs/src/prediction/utils/bcs.js +29 -0
- package/dist/cjs/src/prediction/utils/index.d.ts +8 -0
- package/dist/cjs/src/prediction/utils/index.js +31 -0
- package/dist/cjs/src/prediction/utils.d.ts +30 -0
- package/dist/cjs/src/prediction/utils.js +200 -0
- package/dist/cjs/src/sdk.d.ts +22 -0
- package/dist/cjs/src/sdk.js +62 -0
- package/dist/cjs/src/unified-client.d.ts +402 -0
- package/dist/cjs/src/unified-client.js +218 -0
- package/dist/cjs/src/utils/config.d.ts +11 -0
- package/dist/cjs/src/utils/config.js +19 -0
- package/dist/cjs/src/utils/math.d.ts +287 -0
- package/dist/cjs/src/utils/math.js +469 -0
- package/package.json +119 -31
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rawPrice = rawPrice;
|
|
4
|
+
exports.calcNotional = calcNotional;
|
|
5
|
+
exports.calcFee = calcFee;
|
|
6
|
+
exports.calcUnrealizedPnl = calcUnrealizedPnl;
|
|
7
|
+
exports.calcLeverage = calcLeverage;
|
|
8
|
+
exports.calcEstLiqPrice = calcEstLiqPrice;
|
|
9
|
+
exports.calcEffectiveCollateralUsd = calcEffectiveCollateralUsd;
|
|
10
|
+
exports.calcMaxReducibleCollateralUsd = calcMaxReducibleCollateralUsd;
|
|
11
|
+
exports.calcImpactFeeRate = calcImpactFeeRate;
|
|
12
|
+
exports.calcTotalTradingFeeRate = calcTotalTradingFeeRate;
|
|
13
|
+
exports.calcFundingRate = calcFundingRate;
|
|
14
|
+
exports.calcFundingFeeUsd = calcFundingFeeUsd;
|
|
15
|
+
exports.decodeFundingIndexDelta = decodeFundingIndexDelta;
|
|
16
|
+
exports.calcBorrowRate = calcBorrowRate;
|
|
17
|
+
exports.calcBorrowRateAccrual = calcBorrowRateAccrual;
|
|
18
|
+
exports.calcPositionBorrowFee = calcPositionBorrowFee;
|
|
19
|
+
exports.calcTokenUtilizationBps = calcTokenUtilizationBps;
|
|
20
|
+
exports.annualizeFundingRate = annualizeFundingRate;
|
|
21
|
+
exports.annualizedApyFromRatio = annualizedApyFromRatio;
|
|
22
|
+
exports.calcWlpIncentiveApy = calcWlpIncentiveApy;
|
|
23
|
+
exports.calcWlpPrice = calcWlpPrice;
|
|
24
|
+
exports.calcWlpMintOut = calcWlpMintOut;
|
|
25
|
+
exports.calcWlpRedeemOut = calcWlpRedeemOut;
|
|
26
|
+
exports.calcDynamicFeeBps = calcDynamicFeeBps;
|
|
27
|
+
const constants_ts_1 = require("../constants.js");
|
|
28
|
+
// ======== On-chain encoding ========
|
|
29
|
+
/**
|
|
30
|
+
* Convert a human-readable USD price to the raw 1e9-scaled `u128` value
|
|
31
|
+
* that on-chain `Float`-typed parameters expect.
|
|
32
|
+
*/
|
|
33
|
+
function rawPrice(usd) {
|
|
34
|
+
const n = typeof usd === "string" ? Number(usd) : usd;
|
|
35
|
+
if (!Number.isFinite(n))
|
|
36
|
+
throw new Error(`Invalid USD price: ${usd}`);
|
|
37
|
+
return BigInt(Math.round(n * Number(constants_ts_1.FLOAT_SCALE)));
|
|
38
|
+
}
|
|
39
|
+
// ======== Basic position math ========
|
|
40
|
+
/** Notional value in USD: sizeInAsset × price. */
|
|
41
|
+
function calcNotional(sizeInAsset, price) {
|
|
42
|
+
return sizeInAsset * price;
|
|
43
|
+
}
|
|
44
|
+
/** Trading fee in USD: notional × feeRate. */
|
|
45
|
+
function calcFee(sizeUsd, feeRate) {
|
|
46
|
+
return sizeUsd * feeRate;
|
|
47
|
+
}
|
|
48
|
+
/** Unrealized perp Pnl in USD (before fees). */
|
|
49
|
+
function calcUnrealizedPnl(isLong, entryPrice, spotPrice, sizeInAsset) {
|
|
50
|
+
return (isLong ? 1 : -1) * sizeInAsset * (spotPrice - entryPrice);
|
|
51
|
+
}
|
|
52
|
+
/** Position leverage = notional / collateralUsd. Returns Infinity when collateral is zero. */
|
|
53
|
+
function calcLeverage(sizeUsd, collateralUsd) {
|
|
54
|
+
if (collateralUsd === 0)
|
|
55
|
+
return Infinity;
|
|
56
|
+
return sizeUsd / collateralUsd;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Estimated liquidation price.
|
|
60
|
+
*
|
|
61
|
+
* Matches `calculate_est_liq_price` in `waterx_perp_view/sources/view.move`:
|
|
62
|
+
* maintenance = maintenanceMarginRate × (size × spotPrice) ← uses current notional
|
|
63
|
+
* ratio = (collateralUsd − totalFeesUsd − maintenance) / (size × avgPrice)
|
|
64
|
+
* long: liq = avgPrice × (1 − ratio)
|
|
65
|
+
* short: liq = avgPrice × (1 + ratio)
|
|
66
|
+
*
|
|
67
|
+
* Returns 0 when the position is already liquidatable or has no size.
|
|
68
|
+
*
|
|
69
|
+
* @param totalFeesUsd Sum of all accrued fees in USD: borrow + trading + net funding.
|
|
70
|
+
*/
|
|
71
|
+
function calcEstLiqPrice(params) {
|
|
72
|
+
const { isLong, avgPrice, sizeInAsset, collateralUsd, maintenanceMarginRate, spotPrice, totalFeesUsd, } = params;
|
|
73
|
+
if (sizeInAsset === 0)
|
|
74
|
+
return 0;
|
|
75
|
+
const entryNotional = sizeInAsset * avgPrice;
|
|
76
|
+
const maintenance = maintenanceMarginRate * sizeInAsset * spotPrice;
|
|
77
|
+
const marginRemaining = collateralUsd - totalFeesUsd - maintenance;
|
|
78
|
+
if (marginRemaining <= 0 || entryNotional === 0)
|
|
79
|
+
return 0;
|
|
80
|
+
const ratio = marginRemaining / entryNotional;
|
|
81
|
+
if (isLong) {
|
|
82
|
+
if (ratio >= 1)
|
|
83
|
+
return 0;
|
|
84
|
+
return avgPrice * (1 - ratio);
|
|
85
|
+
}
|
|
86
|
+
return avgPrice * (1 + ratio);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Effective (fee-adjusted) collateral in USD.
|
|
90
|
+
*
|
|
91
|
+
* Mirrors `calculate_effective_collateral_amount` in `trading.move`: the contract
|
|
92
|
+
* subtracts accrued borrow + trading fees and, **only when the position owes funding**
|
|
93
|
+
* (`fundingSign === true`, i.e. `unrealized_funding_sign`), the funding fee too. Funding
|
|
94
|
+
* *income* (position receives funding, `fundingSign === false`) is NOT added here —
|
|
95
|
+
* matching the contract's saturating-subtract path. Result clamps at 0.
|
|
96
|
+
*
|
|
97
|
+
* This is the collateral the contract actually uses for the max-leverage and
|
|
98
|
+
* min-collateral checks on `withdraw_collateral` — NOT the gross `collateral_amount`.
|
|
99
|
+
* Displaying leverage / max-reducible off gross collateral is the common UI bug
|
|
100
|
+
* (a position shows e.g. 23.3x on gross while the contract sees ~24.9x on effective).
|
|
101
|
+
*
|
|
102
|
+
* All inputs are human-readable USD. Convert raw collateral-token fee fields via
|
|
103
|
+
* `feeUsd = (rawFee / 10 ** collateralDecimal) * collateralPriceUsd`.
|
|
104
|
+
*
|
|
105
|
+
* @param grossCollateralUsd Position collateral in USD (`collateral_amount` → USD).
|
|
106
|
+
* @param borrowFeeUsd `unrealized_borrow_fee` in USD.
|
|
107
|
+
* @param fundingSign `unrealized_funding_sign` — true when the position owes funding.
|
|
108
|
+
* @param fundingFeeUsd `unrealized_funding_fee` magnitude in USD.
|
|
109
|
+
* @param tradingFeeUsd `unrealized_trading_fee` in USD.
|
|
110
|
+
* @param projectedTradingFeeUsd Closing fee to reserve (0 for a bare collateral withdrawal).
|
|
111
|
+
*/
|
|
112
|
+
function calcEffectiveCollateralUsd(params) {
|
|
113
|
+
const { grossCollateralUsd, borrowFeeUsd, fundingSign, fundingFeeUsd, tradingFeeUsd, projectedTradingFeeUsd = 0, } = params;
|
|
114
|
+
const eff = grossCollateralUsd -
|
|
115
|
+
borrowFeeUsd -
|
|
116
|
+
tradingFeeUsd -
|
|
117
|
+
projectedTradingFeeUsd -
|
|
118
|
+
(fundingSign ? fundingFeeUsd : 0);
|
|
119
|
+
return Math.max(0, eff);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Maximum collateral (in USD) a position can safely withdraw ("最大可减少").
|
|
123
|
+
*
|
|
124
|
+
* Reproduces the three post-withdrawal checks in `execute_withdraw_collateral`
|
|
125
|
+
* (`trading.move`), all evaluated on **effective** (fee-adjusted) collateral, and
|
|
126
|
+
* returns the smallest allowed withdrawal:
|
|
127
|
+
*
|
|
128
|
+
* (A) max leverage — `notional / (effLeverage − w) ≤ maxLeverage`
|
|
129
|
+
* (B) min collateral — `(effLeverage − w) ≥ minCollValueUsd`
|
|
130
|
+
* (C) not liquidatable — `(liqRemaining − w) > maintenanceMargin × notional`
|
|
131
|
+
*
|
|
132
|
+
* where
|
|
133
|
+
* notional = sizeInAsset × spotPrice
|
|
134
|
+
* effLeverage = effective collateral with projectedTradingFee = 0
|
|
135
|
+
* (the contract's leverage/min-coll checks ignore the closing fee and PnL)
|
|
136
|
+
* liqRemaining = grossCollateralUsd + signedPnl − borrow − trading − closingFee ∓ funding
|
|
137
|
+
* (the contract's `is_liquidatable` boundary; funding income is added back)
|
|
138
|
+
*
|
|
139
|
+
* The result is a USD figure (matching the "$X" the UI shows), already aligned so that
|
|
140
|
+
* converting it to raw collateral units with floor is abort-safe:
|
|
141
|
+
* `rawAmount = floor((maxReducibleUsd / collateralPriceUsd) * 10 ** collateralDecimal)`.
|
|
142
|
+
* The liquidation leg backs off one raw collateral unit because `is_liquidatable` aborts
|
|
143
|
+
* on `remaining <= maintenance` (inclusive) — the safe withdrawal must leave remaining
|
|
144
|
+
* *strictly* above maintenance. The leverage (`> max`) and min-collateral (`>=`) checks
|
|
145
|
+
* are equality-safe on their own and floor-rounding only adds margin, so they need no offset.
|
|
146
|
+
*
|
|
147
|
+
* Funding handling is signed (income added, expense subtracted) — a close approximation
|
|
148
|
+
* of the contract's deficit-aware sequencing, exact whenever the position is solvent
|
|
149
|
+
* (the only case where a withdrawal can succeed). Clamps at 0.
|
|
150
|
+
*
|
|
151
|
+
* @param maxLeverage Max leverage as a ratio (e.g. 25 for `max_leverage_bps` 250000).
|
|
152
|
+
* @param maintenanceMarginRate `maintenance_margin` as a fraction (e.g. 0.01 for 1%).
|
|
153
|
+
* @param minCollValueUsd `min_coll_value` in USD (raw scaled value ÷ 1e9).
|
|
154
|
+
* @param closingFeeUsd Full closing fee in USD (`close_fee` → USD).
|
|
155
|
+
* @param collateralPriceUsd Oracle price of the collateral token (USD per token).
|
|
156
|
+
* @param collateralDecimal Collateral token decimals — sets the smallest withdraw step.
|
|
157
|
+
*/
|
|
158
|
+
function calcMaxReducibleCollateralUsd(params) {
|
|
159
|
+
const { grossCollateralUsd, sizeInAsset, spotPrice, isLong, entryPrice, maxLeverage, maintenanceMarginRate, minCollValueUsd, borrowFeeUsd, tradingFeeUsd, closingFeeUsd, fundingSign, fundingFeeUsd, collateralPriceUsd, collateralDecimal, } = params;
|
|
160
|
+
const notional = sizeInAsset * spotPrice;
|
|
161
|
+
// effLeverage: matches calculate_effective_collateral_amount(..., projectedTradingFee = 0).
|
|
162
|
+
const effLeverage = calcEffectiveCollateralUsd({
|
|
163
|
+
grossCollateralUsd,
|
|
164
|
+
borrowFeeUsd,
|
|
165
|
+
fundingSign,
|
|
166
|
+
fundingFeeUsd,
|
|
167
|
+
tradingFeeUsd,
|
|
168
|
+
});
|
|
169
|
+
// (A) max leverage and (B) min collateral, both bounded by effLeverage. Both checks
|
|
170
|
+
// pass at equality (`leverage_bps > max` / `collateral >= min`), so no offset needed.
|
|
171
|
+
const leverageHeadroom = maxLeverage > 0 ? effLeverage - notional / maxLeverage : effLeverage;
|
|
172
|
+
const minCollHeadroom = effLeverage - minCollValueUsd;
|
|
173
|
+
// (C) is_liquidatable: aborts on `remaining <= maintenance`, so the post-withdrawal
|
|
174
|
+
// remaining must stay STRICTLY above maintenance. Back off one raw collateral unit (the
|
|
175
|
+
// smallest withdrawable step) so the floored raw amount can never land on equality.
|
|
176
|
+
const signedPnl = calcUnrealizedPnl(isLong, entryPrice, spotPrice, sizeInAsset);
|
|
177
|
+
const liqRemaining = grossCollateralUsd +
|
|
178
|
+
signedPnl -
|
|
179
|
+
borrowFeeUsd -
|
|
180
|
+
tradingFeeUsd -
|
|
181
|
+
closingFeeUsd -
|
|
182
|
+
(fundingSign ? fundingFeeUsd : -fundingFeeUsd);
|
|
183
|
+
const maintenanceUsd = maintenanceMarginRate * notional;
|
|
184
|
+
const oneRawUnitUsd = collateralPriceUsd > 0 ? collateralPriceUsd / 10 ** collateralDecimal : 0;
|
|
185
|
+
const liquidationHeadroom = liqRemaining - maintenanceUsd - oneRawUnitUsd;
|
|
186
|
+
return Math.max(0, Math.min(leverageHeadroom, minCollHeadroom, liquidationHeadroom));
|
|
187
|
+
}
|
|
188
|
+
// ======== Impact fee ========
|
|
189
|
+
/**
|
|
190
|
+
* Cost integral used by the impact fee curve (internal helper).
|
|
191
|
+
* Matches `impact_fee_cost_usd` in `trading.move`.
|
|
192
|
+
*/
|
|
193
|
+
function impactFeeCostUsd(maxImpactFee, allocatedExposureUsd, exposureUsd, curvature, scale) {
|
|
194
|
+
if (exposureUsd === 0)
|
|
195
|
+
return 0;
|
|
196
|
+
const scaledRatio = Math.min(1, exposureUsd / (allocatedExposureUsd * scale));
|
|
197
|
+
return exposureUsd * Math.pow(scaledRatio, curvature) * maxImpactFee;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Impact fee rate for an order (as a fraction, not bps).
|
|
201
|
+
*
|
|
202
|
+
* Matches `calculate_impact_fee` in `trading.move`. Returns 0 when the order
|
|
203
|
+
* reduces LP risk (new LP exposure ≤ original). Caller adds this to the base
|
|
204
|
+
* trading fee rate to get the total fee rate.
|
|
205
|
+
*
|
|
206
|
+
* @param longOi Current long open interest in base tokens.
|
|
207
|
+
* @param shortOi Current short open interest in base tokens.
|
|
208
|
+
* @param orderIsLong Direction of the order.
|
|
209
|
+
* @param orderSize Size of the order in base tokens.
|
|
210
|
+
* @param executionPrice Execution price (USD per base token).
|
|
211
|
+
* @param maxImpactFee Max impact fee rate (e.g. 0.0003).
|
|
212
|
+
* @param allocatedLpExposureBps Bps of pool TVL allocated as LP exposure cap.
|
|
213
|
+
* @param poolTvlUsd Total pool TVL in USD.
|
|
214
|
+
* @param curvature Impact fee curve curvature exponent (default 1).
|
|
215
|
+
* @param scale Impact fee curve scale (default 1).
|
|
216
|
+
*/
|
|
217
|
+
function calcImpactFeeRate(params) {
|
|
218
|
+
const { longOi, shortOi, orderIsLong, orderSize, executionPrice, maxImpactFee, allocatedLpExposureBps, poolTvlUsd, curvature = 1, scale = 1, } = params;
|
|
219
|
+
if (maxImpactFee === 0 || orderSize === 0)
|
|
220
|
+
return 0;
|
|
221
|
+
const lpOriginalSide = longOi > shortOi ? false : true;
|
|
222
|
+
const lpOriginalSize = Math.abs(longOi - shortOi);
|
|
223
|
+
const lpNewSize = lpOriginalSide === orderIsLong
|
|
224
|
+
? lpOriginalSize > orderSize
|
|
225
|
+
? lpOriginalSize - orderSize
|
|
226
|
+
: orderSize - lpOriginalSize
|
|
227
|
+
: lpOriginalSize + orderSize;
|
|
228
|
+
if (lpNewSize <= lpOriginalSize)
|
|
229
|
+
return 0;
|
|
230
|
+
if (allocatedLpExposureBps === 0 || poolTvlUsd === 0)
|
|
231
|
+
return 0;
|
|
232
|
+
const allocatedExposureUsd = (poolTvlUsd * allocatedLpExposureBps) / Number(constants_ts_1.BPS_SCALE);
|
|
233
|
+
if (allocatedExposureUsd === 0)
|
|
234
|
+
return 0;
|
|
235
|
+
const originalExposureUsd = lpOriginalSize * executionPrice;
|
|
236
|
+
const newExposureUsd = lpNewSize * executionPrice;
|
|
237
|
+
if (newExposureUsd <= originalExposureUsd)
|
|
238
|
+
return 0;
|
|
239
|
+
const orderNotionalUsd = orderSize * executionPrice;
|
|
240
|
+
if (orderNotionalUsd === 0)
|
|
241
|
+
return 0;
|
|
242
|
+
const originalCost = impactFeeCostUsd(maxImpactFee, allocatedExposureUsd, originalExposureUsd, curvature, scale);
|
|
243
|
+
const newCost = impactFeeCostUsd(maxImpactFee, allocatedExposureUsd, newExposureUsd, curvature, scale);
|
|
244
|
+
return (newCost - originalCost) / orderNotionalUsd;
|
|
245
|
+
}
|
|
246
|
+
/** Total trading fee rate = base fee + impact fee. */
|
|
247
|
+
function calcTotalTradingFeeRate(baseFeeRate, impactFeeRate) {
|
|
248
|
+
return baseFeeRate + impactFeeRate;
|
|
249
|
+
}
|
|
250
|
+
// ======== Funding rate ========
|
|
251
|
+
/**
|
|
252
|
+
* Per-interval funding rate for a market.
|
|
253
|
+
*
|
|
254
|
+
* Matches `calculate_funding_rate` in `market_config.move`.
|
|
255
|
+
* OI values must be in USD (multiply raw OI by base price before calling).
|
|
256
|
+
*
|
|
257
|
+
* @returns `{ sign, rate }` where sign=true means longs pay shorts.
|
|
258
|
+
*/
|
|
259
|
+
function calcFundingRate(longOiUsd, shortOiUsd, basicRate, tvlUsd) {
|
|
260
|
+
if ((longOiUsd === 0 && shortOiUsd === 0) || tvlUsd === 0)
|
|
261
|
+
return { sign: true, rate: 0 };
|
|
262
|
+
if (longOiUsd >= shortOiUsd) {
|
|
263
|
+
return { sign: true, rate: (basicRate * (longOiUsd - shortOiUsd)) / tvlUsd };
|
|
264
|
+
}
|
|
265
|
+
return { sign: false, rate: (basicRate * (shortOiUsd - longOiUsd)) / tvlUsd };
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Funding fee in USD for a position over a period.
|
|
269
|
+
*
|
|
270
|
+
* Simplified from `calculate_funding_fee` in `position.move` for off-chain estimation.
|
|
271
|
+
* For exact on-chain accounting use the Double-precision index from `position.move`.
|
|
272
|
+
*
|
|
273
|
+
* @param sizeInAsset Position size in base tokens.
|
|
274
|
+
* @param deltaIndexUsdPerAsset Change in cumulative funding index (USD per base token).
|
|
275
|
+
* @param positionIsLong Position direction.
|
|
276
|
+
* @param fundingSignIsLong True if the current funding interval charges longs.
|
|
277
|
+
*/
|
|
278
|
+
function calcFundingFeeUsd(sizeInAsset, deltaIndexUsdPerAsset, positionIsLong, fundingSignIsLong) {
|
|
279
|
+
const fee = sizeInAsset * Math.abs(deltaIndexUsdPerAsset);
|
|
280
|
+
const shouldPay = positionIsLong ? fundingSignIsLong : !fundingSignIsLong;
|
|
281
|
+
return shouldPay ? fee : -fee; // positive = cost to position, negative = receipt
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Decode raw Double-precision cumulative funding index delta into USD per base token.
|
|
285
|
+
*
|
|
286
|
+
* Raw index values from on-chain use Double scale (1e18). This converts them to
|
|
287
|
+
* human-readable form (USD per base token) so they can be passed to `calcFundingFeeUsd`.
|
|
288
|
+
*/
|
|
289
|
+
function decodeFundingIndexDelta(rawDelta) {
|
|
290
|
+
return Number((rawDelta * constants_ts_1.FLOAT_SCALE) / constants_ts_1.DOUBLE_SCALE) / Number(constants_ts_1.FLOAT_SCALE);
|
|
291
|
+
}
|
|
292
|
+
// ======== Borrow rate ========
|
|
293
|
+
/**
|
|
294
|
+
* Per-interval borrow rate using the 3-slope utilization curve.
|
|
295
|
+
*
|
|
296
|
+
* Matches `calculate_borrow_rate` in `lp_pool.move`.
|
|
297
|
+
* Rates are Float values (e.g. 0.000001 per interval).
|
|
298
|
+
*/
|
|
299
|
+
function calcBorrowRate(utilizationBps, rate0, rate1, rate2, threshold0Bps, threshold1Bps) {
|
|
300
|
+
if (utilizationBps <= threshold0Bps)
|
|
301
|
+
return rate0;
|
|
302
|
+
if (utilizationBps <= threshold1Bps) {
|
|
303
|
+
if (threshold1Bps === threshold0Bps)
|
|
304
|
+
return rate1;
|
|
305
|
+
return (rate0 + ((rate1 - rate0) * (utilizationBps - threshold0Bps)) / (threshold1Bps - threshold0Bps));
|
|
306
|
+
}
|
|
307
|
+
const remaining = Number(constants_ts_1.BPS_SCALE) - threshold1Bps;
|
|
308
|
+
if (remaining === 0)
|
|
309
|
+
return rate2;
|
|
310
|
+
return rate1 + ((rate2 - rate1) * (utilizationBps - threshold1Bps)) / remaining;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Time-weighted borrow rate accrual for a given elapsed period.
|
|
314
|
+
*
|
|
315
|
+
* Matches `calculate_borrow_rate_accrual` in `lp_pool.move`.
|
|
316
|
+
* `elapsedMs / intervalMs` gives the number of completed intervals.
|
|
317
|
+
*/
|
|
318
|
+
function calcBorrowRateAccrual(borrowRate, elapsedMs, intervalMs) {
|
|
319
|
+
if (borrowRate === 0 || elapsedMs === 0 || intervalMs === 0)
|
|
320
|
+
return 0;
|
|
321
|
+
return (borrowRate * elapsedMs) / intervalMs;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Unrealized borrow fee delta for a position (in raw collateral token units).
|
|
325
|
+
*
|
|
326
|
+
* Matches `calculate_borrow_fee` in `position.move`.
|
|
327
|
+
* Returns 0 when cumulative rate has not advanced past the entry index.
|
|
328
|
+
*
|
|
329
|
+
* @param borrowReserveAmount Position's borrow reserve in raw collateral units.
|
|
330
|
+
* @param cumulativeBorrowRate Current cumulative borrow rate (Float).
|
|
331
|
+
* @param entryBorrowIndex Cumulative borrow rate at position entry (Float).
|
|
332
|
+
*/
|
|
333
|
+
function calcPositionBorrowFee(borrowReserveAmount, cumulativeBorrowRate, entryBorrowIndex) {
|
|
334
|
+
if (cumulativeBorrowRate <= entryBorrowIndex)
|
|
335
|
+
return 0;
|
|
336
|
+
return (cumulativeBorrowRate - entryBorrowIndex) * borrowReserveAmount;
|
|
337
|
+
}
|
|
338
|
+
/** Token utilization in bps: reservedAmount / liquidityAmount × BPS_SCALE. */
|
|
339
|
+
function calcTokenUtilizationBps(reservedAmount, liquidityAmount) {
|
|
340
|
+
if (liquidityAmount === 0)
|
|
341
|
+
return 0;
|
|
342
|
+
return Math.floor((reservedAmount / liquidityAmount) * Number(constants_ts_1.BPS_SCALE));
|
|
343
|
+
}
|
|
344
|
+
// ======== Funding annualization ========
|
|
345
|
+
/**
|
|
346
|
+
* Annualize a per-interval funding rate.
|
|
347
|
+
*
|
|
348
|
+
* @param rate Per-interval funding rate (e.g. from `calcFundingRate`).
|
|
349
|
+
* @param intervalMs Funding interval in milliseconds (e.g. 3_600_000 for 1H).
|
|
350
|
+
*/
|
|
351
|
+
function annualizeFundingRate(rate, intervalMs) {
|
|
352
|
+
if (intervalMs === 0)
|
|
353
|
+
return 0;
|
|
354
|
+
return rate * (constants_ts_1.MS_PER_YEAR / intervalMs);
|
|
355
|
+
}
|
|
356
|
+
// ======== WLP APY ========
|
|
357
|
+
/**
|
|
358
|
+
* Annualized APY from a NAV ratio over a given number of days.
|
|
359
|
+
*
|
|
360
|
+
* Compounds `ratio` (WLP price now / WLP price past) to a 365-day return.
|
|
361
|
+
* Returns 0 when the result is not finite (e.g. ratio ≤ 0 or days = 0).
|
|
362
|
+
*
|
|
363
|
+
* @param ratio Current NAV divided by past NAV (e.g. 1.05 for 5% growth).
|
|
364
|
+
* @param days Number of days elapsed between the two NAV samples.
|
|
365
|
+
*/
|
|
366
|
+
function annualizedApyFromRatio(ratio, days) {
|
|
367
|
+
if (days === 0 || ratio <= 0)
|
|
368
|
+
return 0;
|
|
369
|
+
const apy = Math.pow(ratio, 365 / days) - 1;
|
|
370
|
+
return Number.isFinite(apy) ? apy : 0;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Convert a continuously-compounded incentive APR to APY.
|
|
374
|
+
*
|
|
375
|
+
* Rewards stream via `flow_rate` (continuous compounding), so APY = e^APR − 1.
|
|
376
|
+
* Returns 0 when the result is not finite.
|
|
377
|
+
*
|
|
378
|
+
* @param apr Time-weighted incentive APR as a decimal fraction (e.g. 0.12 for 12%).
|
|
379
|
+
*/
|
|
380
|
+
function calcWlpIncentiveApy(apr) {
|
|
381
|
+
const apy = Math.expm1(apr);
|
|
382
|
+
return Number.isFinite(apy) ? apy : 0;
|
|
383
|
+
}
|
|
384
|
+
// ======== WLP ========
|
|
385
|
+
/**
|
|
386
|
+
* WLP share price in USD.
|
|
387
|
+
*
|
|
388
|
+
* @param tvlUsd Total pool TVL in USD (AUM equity).
|
|
389
|
+
* @param totalSupply Total WLP supply (in raw LP token units).
|
|
390
|
+
* @param lpDecimals WLP token decimals (6).
|
|
391
|
+
*/
|
|
392
|
+
function calcWlpPrice(tvlUsd, totalSupply, lpDecimals) {
|
|
393
|
+
if (totalSupply === 0)
|
|
394
|
+
return 0;
|
|
395
|
+
return (tvlUsd * Math.pow(10, lpDecimals)) / totalSupply;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* WLP tokens minted for a deposit (post-fee net deposit).
|
|
399
|
+
*
|
|
400
|
+
* Matches the LP-amount formula in `mint_wlp_with_pricing_tvl` in `lp_pool.move`.
|
|
401
|
+
* Pass `netDepositUsd` (after the dynamic mint fee is deducted).
|
|
402
|
+
* Bootstrap path (totalSupply === 0): lpAmount = netDepositUsd × 10^lpDecimals.
|
|
403
|
+
*
|
|
404
|
+
* @param netDepositUsd Deposit value in USD after dynamic mint fee.
|
|
405
|
+
* @param tvlUsd Pool TVL in USD at pricing time.
|
|
406
|
+
* @param totalSupply Current total WLP supply in raw units.
|
|
407
|
+
* @param lpDecimals WLP token decimals (6).
|
|
408
|
+
*/
|
|
409
|
+
function calcWlpMintOut(netDepositUsd, tvlUsd, totalSupply, lpDecimals) {
|
|
410
|
+
const scale = Math.pow(10, lpDecimals);
|
|
411
|
+
if (totalSupply === 0 || tvlUsd === 0)
|
|
412
|
+
return Math.floor(netDepositUsd * scale);
|
|
413
|
+
return Math.floor((netDepositUsd * totalSupply) / tvlUsd);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Raw token amount redeemable for a given LP amount (before burn fee).
|
|
417
|
+
*
|
|
418
|
+
* Matches the settlement formula in `settle_redeem_with_pricing_tvl` in `lp_pool.move`.
|
|
419
|
+
* Apply `calcDynamicFeeBps` separately to get the net output.
|
|
420
|
+
*
|
|
421
|
+
* @param lpAmount LP tokens being redeemed (raw units).
|
|
422
|
+
* @param tvlUsd Pool TVL in USD at pricing time.
|
|
423
|
+
* @param totalSupply Current total WLP supply in raw units.
|
|
424
|
+
* @param tokenPriceUsd Oracle price of the output token.
|
|
425
|
+
* @param tokenDecimals Output token decimals.
|
|
426
|
+
*/
|
|
427
|
+
function calcWlpRedeemOut(lpAmount, tvlUsd, totalSupply, tokenPriceUsd, tokenDecimals) {
|
|
428
|
+
if (totalSupply === 0 || tokenPriceUsd === 0)
|
|
429
|
+
return 0;
|
|
430
|
+
const burnValueUsd = (tvlUsd * lpAmount) / totalSupply;
|
|
431
|
+
return Math.floor((burnValueUsd / tokenPriceUsd) * Math.pow(10, tokenDecimals));
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Dynamic mint/burn fee in bps based on weight deviation.
|
|
435
|
+
*
|
|
436
|
+
* Matches `calculate_dynamic_fee` in `lp_pool.move`. Returns `baseFeeBps` when
|
|
437
|
+
* the operation moves the token closer to (or does not worsen) its target weight.
|
|
438
|
+
* Adds an additional fee proportional to the average deviation when it moves
|
|
439
|
+
* further away.
|
|
440
|
+
*
|
|
441
|
+
* @param tokenValueUsd Current USD value of this token in the pool.
|
|
442
|
+
* @param tvlUsd Total pool TVL in USD.
|
|
443
|
+
* @param operationValueUsd USD value of the deposit or withdrawal.
|
|
444
|
+
* @param targetWeightBps Target allocation weight for this token (bps).
|
|
445
|
+
* @param baseFeeBps Base mint/burn fee (bps).
|
|
446
|
+
* @param isDeposit True for mint, false for redeem.
|
|
447
|
+
*/
|
|
448
|
+
function calcDynamicFeeBps(tokenValueUsd, tvlUsd, operationValueUsd, targetWeightBps, baseFeeBps, isDeposit) {
|
|
449
|
+
if (tvlUsd === 0 || operationValueUsd === 0 || targetWeightBps === 0)
|
|
450
|
+
return baseFeeBps;
|
|
451
|
+
const targetValue = (tvlUsd * targetWeightBps) / Number(constants_ts_1.BPS_SCALE);
|
|
452
|
+
const originalDiff = Math.abs(tokenValueUsd - targetValue);
|
|
453
|
+
const newTokenValue = isDeposit
|
|
454
|
+
? tokenValueUsd + operationValueUsd
|
|
455
|
+
: Math.max(0, tokenValueUsd - operationValueUsd);
|
|
456
|
+
const newTvl = isDeposit ? tvlUsd + operationValueUsd : Math.max(0, tvlUsd - operationValueUsd);
|
|
457
|
+
if (newTvl === 0)
|
|
458
|
+
return baseFeeBps;
|
|
459
|
+
const newTargetValue = (newTvl * targetWeightBps) / Number(constants_ts_1.BPS_SCALE);
|
|
460
|
+
const newDiff = Math.abs(newTokenValue - newTargetValue);
|
|
461
|
+
if (newDiff <= originalDiff)
|
|
462
|
+
return baseFeeBps;
|
|
463
|
+
const avgDiff = (originalDiff + newDiff) / 2;
|
|
464
|
+
const avgTargetValue = (targetValue + newTargetValue) / 2;
|
|
465
|
+
if (avgTargetValue === 0)
|
|
466
|
+
return baseFeeBps;
|
|
467
|
+
const additional = Math.floor((avgDiff / avgTargetValue) * baseFeeBps);
|
|
468
|
+
return baseFeeBps + additional;
|
|
469
|
+
}
|