diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 55dcbc2..4c47405 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -9,13 +9,13 @@ jobs: steps: - name: Checkout the repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 - name: Retrieve the cached "node_modules" directory (if present) - uses: actions/cache@v2 + uses: actions/cache@v4 id: node-cache with: path: node_modules diff --git a/.gitignore b/.gitignore index e356a8d..1a674c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ .history/ coverage/ build/ +docs/ diff --git a/asconfig.json b/asconfig.json index 1627aaa..95c47b8 100644 --- a/asconfig.json +++ b/asconfig.json @@ -1,20 +1,25 @@ { "targets": { "debug": { - "binaryFile": "build/untouched.wasm", "textFile": "build/untouched.wat", "sourceMap": true, - "debug": true + "debug": true, + "outFile": "build/untouched.wasm" }, "release": { - "binaryFile": "build/optimized.wasm", "textFile": "build/optimized.wat", "sourceMap": true, "optimizeLevel": 3, "shrinkLevel": 0, "converge": false, - "noAssert": false + "noAssert": false, + "outFile": "build/optimized.wasm" } }, - "options": {} -} \ No newline at end of file + "options": { + "transform": [ + "json-as/transform" + ], + "bindings": "esm" + } +} diff --git a/assembly/index.ts b/assembly/index.ts index 04bca77..d591007 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -1 +1,2 @@ export * from './utils'; +export * from './panoptic'; diff --git a/assembly/panoptic/host.ts b/assembly/panoptic/host.ts new file mode 100644 index 0000000..4d8c01f --- /dev/null +++ b/assembly/panoptic/host.ts @@ -0,0 +1,285 @@ +import { JSON } from "json-as/assembly"; +import { PanopticMethods } from "./methods"; +import { + AccountCollateralRequestDto, + AccountOpenPositionIdsEnvelopeDto, + AccountOpenPositionIdsRequestDto, + AccountPositionEnvelopeDto, + AccountPositionsEnvelopeDto, + AccountTokenIdRequestDto, + AccountTokenIdsRequestDto, + CalldataPartsEnvelopeDto, + CollateralDepositFragmentRequestDto, + CollateralWithdrawFragmentRequestDto, + CollateralWithdrawWithPositionsFragmentRequestDto, + DynamicJobFragmentEnvelopeDto, + DynamicJobsRenderEnvelopeDto, + DynamicJobsRenderRequestDto, + Erc20ApproveFragmentRequestDto, + GreeksCalculateAccountRequestDto, + GreeksCalculatePositionRequestDto, + GreeksEnvelopeDto, + HypovaultBuildVaultManagerInputEnvelopeDto, + HypovaultBuildVaultManagerInputRequestDto, + HypovaultEpochContextEnvelopeDto, + HypovaultEpochContextRequestDto, + HypovaultFulfillDepositsRequestDto, + HypovaultFulfillWithdrawalsRequestDto, + HypovaultInnerCallEnvelopeDto, + HypovaultManageCalldataPartsRequestDto, + HypovaultManageRequestDto, + HypovaultPositionsHashStatusEnvelopeDto, + HypovaultPositionsHashStatusRequestDto, + HypovaultVerifyOpenTokenIdsEnvelopeDto, + HypovaultVerifyOpenTokenIdsRequestDto, + HypovaultWethInnerCallRequestDto, + MerkleBuildManageEnvelopeDto, + MerkleBuildManageRequestDto, + MerkleFindLeafEnvelopeDto, + MerkleFindLeafRequestDto, + MerkleManageVaultWithVerificationFragmentRequestDto, + PanopticDispatchExplicitRequestDto, + PanopticDispatchRequestDto, + PanopticPoolEnvelopeDto, + PanopticPoolReadRequestDto, + PanopticSdkRecordEnvelopeDto, + PanopticStringEnvelopeDto, + Permit2ApproveFragmentRequestDto, + PoolGetPricesAtTickRequestDto, + PoolGetTickSpacingRequestDto, + PoolMetadataEnvelopeDto, + PoolPricesAtTickEnvelopeDto, + PoolRiskParametersRequestDto, + PoolUtilizationRequestDto, + UniswapQuoteEnvelopeDto, + UniswapRouteRequestDto, + UniswapRouterApprovalEnvelopeDto, + UniswapRouterApprovalRequestDto, + UniswapV3ExactInRequestDto, + WethAmountRequestDto, +} from "./types"; + +@external("env", "panoptic_call") +declare function panoptic_call(method: string, paramsJson: string): string; + +export function callPanopticRaw(method: string, requestJson: string): string { + return panoptic_call(method, requestJson); +} + +export function callPanoptic(method: string, request: TRequest): TEnvelope { + return JSON.parse(panoptic_call(method, JSON.stringify(request))); +} + +export function assertPanopticOk(ok: bool, method: string): void { + if (!ok) { + throw new Error("Panoptic call failed: " + method); + } +} + +export function accountGetAccountCollateral(request: AccountCollateralRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_ACCOUNT_COLLATERAL, request); +} + +export function accountGetAccountSummaryBasic(request: AccountTokenIdsRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_ACCOUNT_SUMMARY_BASIC, request); +} + +export function accountGetAccountSummaryRisk(request: AccountTokenIdsRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_ACCOUNT_SUMMARY_RISK, request); +} + +export function accountGetLiquidationPrices(request: AccountTokenIdsRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_LIQUIDATION_PRICES, request); +} + +export function accountGetNetLiquidationValue(request: AccountTokenIdsRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_NET_LIQUIDATION_VALUE, request); +} + +export function accountGetNetLiquidationValues(request: AccountTokenIdsRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_NET_LIQUIDATION_VALUES, request); +} + +export function accountGetOpenPositionIds(request: AccountOpenPositionIdsRequestDto): AccountOpenPositionIdsEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_OPEN_POSITION_IDS, request); +} + +export function accountGetPosition(request: AccountTokenIdRequestDto): AccountPositionEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_POSITION, request); +} + +export function accountGetPositions(request: AccountTokenIdsRequestDto): AccountPositionsEnvelopeDto { + return callPanoptic(PanopticMethods.ACCOUNT_GET_POSITIONS, request); +} + +export function collateralDepositFragment(request: CollateralDepositFragmentRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.COLLATERAL_DEPOSIT_FRAGMENT, request); +} + +export function collateralWithdrawFragment(request: CollateralWithdrawFragmentRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.COLLATERAL_WITHDRAW_FRAGMENT, request); +} + +export function collateralWithdrawWithPositionsFragment(request: CollateralWithdrawWithPositionsFragmentRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.COLLATERAL_WITHDRAW_WITH_POSITIONS_FRAGMENT, request); +} + +export function dynamicJobsRenderExecuteJob(request: DynamicJobsRenderRequestDto): DynamicJobsRenderEnvelopeDto { + return callPanoptic(PanopticMethods.DYNAMIC_JOBS_RENDER_EXECUTE_JOB, request); +} + +export function erc20ApproveFragment(request: Erc20ApproveFragmentRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.ERC20_APPROVE_FRAGMENT, request); +} + +export function greeksCalculateAccountGreeksPure(request: GreeksCalculateAccountRequestDto): GreeksEnvelopeDto { + return callPanoptic(PanopticMethods.GREEKS_CALCULATE_ACCOUNT_GREEKS_PURE, request); +} + +export function greeksCalculatePositionGreeks(request: GreeksCalculatePositionRequestDto): GreeksEnvelopeDto { + return callPanoptic(PanopticMethods.GREEKS_CALCULATE_POSITION_GREEKS, request); +} + +export function greeksGetPositionGreeks(request: AccountTokenIdRequestDto): GreeksEnvelopeDto { + return callPanoptic(PanopticMethods.GREEKS_GET_POSITION_GREEKS, request); +} + +export function hypovaultBuildVaultManagerInputAtBlock(request: HypovaultBuildVaultManagerInputRequestDto): HypovaultBuildVaultManagerInputEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_BUILD_VAULT_MANAGER_INPUT_AT_BLOCK, request); +} + +export function hypovaultFulfillDepositsFragment(request: HypovaultFulfillDepositsRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_FULFILL_DEPOSITS_FRAGMENT, request); +} + +export function hypovaultFulfillWithdrawalsFragment(request: HypovaultFulfillWithdrawalsRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_FULFILL_WITHDRAWALS_FRAGMENT, request); +} + +export function hypovaultGetEpochContext(request: HypovaultEpochContextRequestDto): HypovaultEpochContextEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_GET_EPOCH_CONTEXT, request); +} + +export function hypovaultGetOpenPositionIds(request: AccountOpenPositionIdsRequestDto): AccountOpenPositionIdsEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_GET_OPEN_POSITION_IDS, request); +} + +export function hypovaultGetPositionsHashStatus(request: HypovaultPositionsHashStatusRequestDto): HypovaultPositionsHashStatusEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_GET_POSITIONS_HASH_STATUS, request); +} + +export function hypovaultManageCalldataParts(request: HypovaultManageCalldataPartsRequestDto): CalldataPartsEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_MANAGE_CALLDATA_PARTS, request); +} + +export function hypovaultManageFragment(request: HypovaultManageRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_MANAGE_FRAGMENT, request); +} + +export function hypovaultVerifyVaultOpenTokenIdsAtBlock(request: HypovaultVerifyOpenTokenIdsRequestDto): HypovaultVerifyOpenTokenIdsEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_VERIFY_VAULT_OPEN_TOKEN_IDS_AT_BLOCK, request); +} + +export function hypovaultWethDepositInnerCall(request: HypovaultWethInnerCallRequestDto): HypovaultInnerCallEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_WETH_DEPOSIT_INNER_CALL, request); +} + +export function hypovaultWethWithdrawInnerCall(request: HypovaultWethInnerCallRequestDto): HypovaultInnerCallEnvelopeDto { + return callPanoptic(PanopticMethods.HYPOVAULT_WETH_WITHDRAW_INNER_CALL, request); +} + +export function merkleBuildManageArgs(request: MerkleBuildManageRequestDto): MerkleBuildManageEnvelopeDto { + return callPanoptic(PanopticMethods.MERKLE_BUILD_MANAGE_ARGS, request); +} + +export function merkleFindLeaf(request: MerkleFindLeafRequestDto): MerkleFindLeafEnvelopeDto { + return callPanoptic(PanopticMethods.MERKLE_FIND_LEAF, request); +} + +export function merkleManageVaultWithVerificationFragment(request: MerkleManageVaultWithVerificationFragmentRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.MERKLE_MANAGE_VAULT_WITH_VERIFICATION_FRAGMENT, request); +} + +export function panopticDispatchCalldataParts(request: PanopticDispatchRequestDto): CalldataPartsEnvelopeDto { + return callPanoptic(PanopticMethods.PANOPTIC_DISPATCH_CALLDATA_PARTS, request); +} + +export function panopticDispatchExplicitCalldataParts(request: PanopticDispatchExplicitRequestDto): CalldataPartsEnvelopeDto { + return callPanoptic(PanopticMethods.PANOPTIC_DISPATCH_EXPLICIT_CALLDATA_PARTS, request); +} + +export function panopticDispatchExplicitFragment(request: PanopticDispatchExplicitRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.PANOPTIC_DISPATCH_EXPLICIT_FRAGMENT, request); +} + +export function panopticDispatchFragment(request: PanopticDispatchRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.PANOPTIC_DISPATCH_FRAGMENT, request); +} + +export function permit2ApproveFragment(request: Permit2ApproveFragmentRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.PERMIT2_APPROVE_FRAGMENT, request); +} + +export function poolFetchPoolId(request: PanopticPoolReadRequestDto): PanopticPoolEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_FETCH_POOL_ID, request); +} + +export function poolGetOracleState(request: PanopticPoolReadRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_ORACLE_STATE, request); +} + +export function poolGetPool(request: PanopticPoolReadRequestDto): PanopticPoolEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_POOL, request); +} + +export function poolGetPoolMetadata(request: PanopticPoolReadRequestDto): PoolMetadataEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_POOL_METADATA, request); +} + +export function poolGetPricesAtTick(request: PoolGetPricesAtTickRequestDto): PoolPricesAtTickEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_PRICES_AT_TICK, request); +} + +export function poolGetRiskParameters(request: PoolRiskParametersRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_RISK_PARAMETERS, request); +} + +export function poolGetTickSpacing(request: PoolGetTickSpacingRequestDto): PanopticStringEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_TICK_SPACING, request); +} + +export function poolGetUtilization(request: PoolUtilizationRequestDto): PanopticSdkRecordEnvelopeDto { + return callPanoptic(PanopticMethods.POOL_GET_UTILIZATION, request); +} + +export function uniswapBuildV3ExactInExecuteCalldataParts(request: UniswapV3ExactInRequestDto): CalldataPartsEnvelopeDto { + return callPanoptic(PanopticMethods.UNISWAP_BUILD_V3_EXACT_IN_EXECUTE_CALLDATA_PARTS, request); +} + +export function uniswapBuildV3ExactInExecuteFragment(request: UniswapV3ExactInRequestDto): DynamicJobFragmentEnvelopeDto { + return callPanoptic(PanopticMethods.UNISWAP_BUILD_V3_EXACT_IN_EXECUTE_FRAGMENT, request); +} + +export function uniswapCheckRouterApproval(request: UniswapRouterApprovalRequestDto): UniswapRouterApprovalEnvelopeDto { + return callPanoptic(PanopticMethods.UNISWAP_CHECK_ROUTER_APPROVAL, request); +} + +export function uniswapQuoteSwapExactInViaRouter(request: UniswapRouteRequestDto): UniswapQuoteEnvelopeDto { + return callPanoptic(PanopticMethods.UNISWAP_QUOTE_SWAP_EXACT_IN_VIA_ROUTER, request); +} + +export function uniswapQuoteSwapExactOutViaRouter(request: UniswapRouteRequestDto): UniswapQuoteEnvelopeDto { + return callPanoptic(PanopticMethods.UNISWAP_QUOTE_SWAP_EXACT_OUT_VIA_ROUTER, request); +} + +export function uniswapResolveSwapRoute(request: UniswapRouteRequestDto): UniswapQuoteEnvelopeDto { + return callPanoptic(PanopticMethods.UNISWAP_RESOLVE_SWAP_ROUTE, request); +} + +export function wethDepositCalldataParts(request: WethAmountRequestDto): CalldataPartsEnvelopeDto { + return callPanoptic(PanopticMethods.WETH_DEPOSIT_CALLDATA_PARTS, request); +} + +export function wethWithdrawCalldataParts(request: WethAmountRequestDto): CalldataPartsEnvelopeDto { + return callPanoptic(PanopticMethods.WETH_WITHDRAW_CALLDATA_PARTS, request); +} diff --git a/assembly/panoptic/index.ts b/assembly/panoptic/index.ts new file mode 100644 index 0000000..67768b7 --- /dev/null +++ b/assembly/panoptic/index.ts @@ -0,0 +1,3 @@ +export * from './methods'; +export * from './types'; +export * from './host'; diff --git a/assembly/panoptic/methods.ts b/assembly/panoptic/methods.ts new file mode 100644 index 0000000..435ecb1 --- /dev/null +++ b/assembly/panoptic/methods.ts @@ -0,0 +1,64 @@ +export namespace PanopticMethods { + export const ACCOUNT_GET_ACCOUNT_COLLATERAL = "account.getAccountCollateral"; + export const ACCOUNT_GET_ACCOUNT_SUMMARY_BASIC = "account.getAccountSummaryBasic"; + export const ACCOUNT_GET_ACCOUNT_SUMMARY_RISK = "account.getAccountSummaryRisk"; + export const ACCOUNT_GET_LIQUIDATION_PRICES = "account.getLiquidationPrices"; + export const ACCOUNT_GET_NET_LIQUIDATION_VALUE = "account.getNetLiquidationValue"; + export const ACCOUNT_GET_NET_LIQUIDATION_VALUES = "account.getNetLiquidationValues"; + export const ACCOUNT_GET_OPEN_POSITION_IDS = "account.getOpenPositionIds"; + export const ACCOUNT_GET_POSITION = "account.getPosition"; + export const ACCOUNT_GET_POSITIONS = "account.getPositions"; + + export const COLLATERAL_DEPOSIT_FRAGMENT = "collateral.depositFragment"; + export const COLLATERAL_WITHDRAW_FRAGMENT = "collateral.withdrawFragment"; + export const COLLATERAL_WITHDRAW_WITH_POSITIONS_FRAGMENT = "collateral.withdrawWithPositionsFragment"; + + export const DYNAMIC_JOBS_RENDER_EXECUTE_JOB = "dynamicJobs.renderExecuteJob"; + export const ERC20_APPROVE_FRAGMENT = "erc20.approveFragment"; + + export const GREEKS_CALCULATE_ACCOUNT_GREEKS_PURE = "greeks.calculateAccountGreeksPure"; + export const GREEKS_CALCULATE_POSITION_GREEKS = "greeks.calculatePositionGreeks"; + export const GREEKS_GET_POSITION_GREEKS = "greeks.getPositionGreeks"; + + export const HYPOVAULT_BUILD_VAULT_MANAGER_INPUT_AT_BLOCK = "hypovault.buildVaultManagerInputAtBlock"; + export const HYPOVAULT_FULFILL_DEPOSITS_FRAGMENT = "hypovault.fulfillDepositsFragment"; + export const HYPOVAULT_FULFILL_WITHDRAWALS_FRAGMENT = "hypovault.fulfillWithdrawalsFragment"; + export const HYPOVAULT_GET_EPOCH_CONTEXT = "hypovault.getEpochContext"; + export const HYPOVAULT_GET_OPEN_POSITION_IDS = "hypovault.getOpenPositionIds"; + export const HYPOVAULT_GET_POSITIONS_HASH_STATUS = "hypovault.getPositionsHashStatus"; + export const HYPOVAULT_MANAGE_CALLDATA_PARTS = "hypovault.manageCalldataParts"; + export const HYPOVAULT_MANAGE_FRAGMENT = "hypovault.manageFragment"; + export const HYPOVAULT_VERIFY_VAULT_OPEN_TOKEN_IDS_AT_BLOCK = "hypovault.verifyVaultOpenTokenIdsAtBlock"; + export const HYPOVAULT_WETH_DEPOSIT_INNER_CALL = "hypovault.wethDepositInnerCall"; + export const HYPOVAULT_WETH_WITHDRAW_INNER_CALL = "hypovault.wethWithdrawInnerCall"; + + export const MERKLE_BUILD_MANAGE_ARGS = "merkle.buildManageArgs"; + export const MERKLE_FIND_LEAF = "merkle.findLeaf"; + export const MERKLE_MANAGE_VAULT_WITH_VERIFICATION_FRAGMENT = "merkle.manageVaultWithVerificationFragment"; + + export const PANOPTIC_DISPATCH_CALLDATA_PARTS = "panoptic.dispatchCalldataParts"; + export const PANOPTIC_DISPATCH_EXPLICIT_CALLDATA_PARTS = "panoptic.dispatchExplicitCalldataParts"; + export const PANOPTIC_DISPATCH_EXPLICIT_FRAGMENT = "panoptic.dispatchExplicitFragment"; + export const PANOPTIC_DISPATCH_FRAGMENT = "panoptic.dispatchFragment"; + + export const PERMIT2_APPROVE_FRAGMENT = "permit2.approveFragment"; + + export const POOL_FETCH_POOL_ID = "pool.fetchPoolId"; + export const POOL_GET_ORACLE_STATE = "pool.getOracleState"; + export const POOL_GET_POOL = "pool.getPool"; + export const POOL_GET_POOL_METADATA = "pool.getPoolMetadata"; + export const POOL_GET_PRICES_AT_TICK = "pool.getPricesAtTick"; + export const POOL_GET_RISK_PARAMETERS = "pool.getRiskParameters"; + export const POOL_GET_TICK_SPACING = "pool.getTickSpacing"; + export const POOL_GET_UTILIZATION = "pool.getUtilization"; + + export const UNISWAP_BUILD_V3_EXACT_IN_EXECUTE_CALLDATA_PARTS = "uniswap.buildV3ExactInExecuteCalldataParts"; + export const UNISWAP_BUILD_V3_EXACT_IN_EXECUTE_FRAGMENT = "uniswap.buildV3ExactInExecuteFragment"; + export const UNISWAP_CHECK_ROUTER_APPROVAL = "uniswap.checkRouterApproval"; + export const UNISWAP_QUOTE_SWAP_EXACT_IN_VIA_ROUTER = "uniswap.quoteSwapExactInViaRouter"; + export const UNISWAP_QUOTE_SWAP_EXACT_OUT_VIA_ROUTER = "uniswap.quoteSwapExactOutViaRouter"; + export const UNISWAP_RESOLVE_SWAP_ROUTE = "uniswap.resolveSwapRoute"; + + export const WETH_DEPOSIT_CALLDATA_PARTS = "weth.depositCalldataParts"; + export const WETH_WITHDRAW_CALLDATA_PARTS = "weth.withdrawCalldataParts"; +} diff --git a/assembly/panoptic/types.ts b/assembly/panoptic/types.ts new file mode 100644 index 0000000..b98bb69 --- /dev/null +++ b/assembly/panoptic/types.ts @@ -0,0 +1,911 @@ +@serializable +export class PanopticContextDto { + chainId: string = ""; + sourceId: string = ""; + blockNumber: string = ""; + account: string = ""; + panopticSubgraphId: string = ""; + rpcUrl: string = ""; +} + +@serializable +export class PanopticSourceMetaDto { + chainId: string = ""; + blockNumber: string = ""; + preflightBlockNumber: string = ""; + rpcSourceId: string = ""; + subgraphSourceId: string = ""; + subgraphBlockNumber: string = ""; + blockNumberRole: string = ""; + reconciled: bool = false; +} + +@serializable +export class PanopticEmptyArgsDto {} + +@serializable +export class PanopticErrorDto { + code: string = ""; + message: string = ""; +} + +@serializable +export class PanopticStringEnvelopeDto { + ok: bool = false; + result: string = ""; +} + +@serializable +export class PanopticStringArrayEnvelopeDto { + ok: bool = false; + result: string[] = []; +} + +@serializable +export class PanopticPoolMetadataDto { + poolKeyBytes: string = ""; + poolId: string = ""; + collateralToken0Address: string = ""; + collateralToken1Address: string = ""; + riskEngineAddress: string = ""; + token0Asset: string = ""; + token1Asset: string = ""; + token0Symbol: string = ""; + token1Symbol: string = ""; + token0Decimals: string = ""; + token1Decimals: string = ""; + token0Name: string = ""; + token1Name: string = ""; + underlyingPoolId: string = ""; + isV4: bool = false; + tickSpacing: string = ""; + fee: string = ""; + sfpmAddress: string = ""; +} + +@serializable +export class PanopticPoolAddressesDto { + collateralToken0: string = ""; + collateralToken1: string = ""; +} + +@serializable +export class PanopticPoolReadArgsDto { + poolAddress: string = ""; + poolMetadata: PanopticPoolMetadataDto | null = null; + stateViewAddress: string = ""; +} + +@serializable +export class PanopticPoolReadRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: PanopticPoolReadArgsDto = new PanopticPoolReadArgsDto(); +} + +@serializable +export class PanopticPoolResultDto { + poolId: string = ""; + token0: string = ""; + token1: string = ""; + currentTick: string = ""; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class PanopticPoolEnvelopeDto { + ok: bool = false; + result: PanopticPoolResultDto = new PanopticPoolResultDto(); +} + +@serializable +export class PoolGetTickSpacingArgsDto { + feeBps: string = ""; +} + +@serializable +export class PoolGetTickSpacingRequestDto { + args: PoolGetTickSpacingArgsDto = new PoolGetTickSpacingArgsDto(); +} + +@serializable +export class PoolGetPricesAtTickArgsDto { + tick: string = ""; + decimals0: string = ""; + decimals1: string = ""; + precision: string = ""; +} + +@serializable +export class PoolGetPricesAtTickRequestDto { + args: PoolGetPricesAtTickArgsDto = new PoolGetPricesAtTickArgsDto(); +} + +@serializable +export class PoolPricesAtTickResultDto { + price0: string = ""; + price1: string = ""; +} + +@serializable +export class PoolPricesAtTickEnvelopeDto { + ok: bool = false; + result: PoolPricesAtTickResultDto = new PoolPricesAtTickResultDto(); +} + +@serializable +export class PoolRiskParametersArgsDto { + poolAddress: string = ""; + builderCode: string = ""; + riskEngineAddress: string = ""; +} + +@serializable +export class PoolRiskParametersRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: PoolRiskParametersArgsDto = new PoolRiskParametersArgsDto(); +} + +@serializable +export class PoolUtilizationArgsDto { + poolAddress: string = ""; + collateralAddresses: PanopticPoolAddressesDto = new PanopticPoolAddressesDto(); +} + +@serializable +export class PoolUtilizationRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: PoolUtilizationArgsDto = new PoolUtilizationArgsDto(); +} + +@serializable +export class PoolMetadataEnvelopeDto { + ok: bool = false; + result: PanopticPoolMetadataDto = new PanopticPoolMetadataDto(); +} + +@serializable +export class AccountBaseArgsDto { + poolAddress: string = ""; + poolMetadata: PanopticPoolMetadataDto | null = null; +} + +@serializable +export class AccountTokenIdArgsDto extends AccountBaseArgsDto { + tokenId: string = ""; + atTick: string = ""; +} + +@serializable +export class AccountTokenIdsArgsDto extends AccountBaseArgsDto { + tokenIds: string[] = []; + queryAddress: string = ""; + atTick: string = ""; + atTicks: string[] = []; + includePendingPremium: bool = false; +} + +@serializable +export class AccountOpenPositionIdsArgsDto extends AccountBaseArgsDto { + lastDispatchTxHash: string = ""; +} + +@serializable +export class AccountCollateralArgsDto extends AccountBaseArgsDto { + collateralAddresses: PanopticPoolAddressesDto = new PanopticPoolAddressesDto(); +} + +@serializable +export class AccountTokenIdRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: AccountTokenIdArgsDto = new AccountTokenIdArgsDto(); +} + +@serializable +export class AccountTokenIdsRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: AccountTokenIdsArgsDto = new AccountTokenIdsArgsDto(); +} + +@serializable +export class AccountOpenPositionIdsRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: AccountOpenPositionIdsArgsDto = new AccountOpenPositionIdsArgsDto(); +} + +@serializable +export class AccountCollateralRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: AccountCollateralArgsDto = new AccountCollateralArgsDto(); +} + +@serializable +export class AccountPositionDto { + tokenId: string = ""; + positionSize: string = ""; + tickAtMint: string = ""; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class AccountPositionEnvelopeDto { + ok: bool = false; + result: AccountPositionDto = new AccountPositionDto(); +} + +@serializable +export class AccountPositionsResultDto { + positions: AccountPositionDto[] = []; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class AccountPositionsEnvelopeDto { + ok: bool = false; + result: AccountPositionsResultDto = new AccountPositionsResultDto(); +} + +@serializable +export class AccountOpenPositionIdsResultDto { + tokenIds: string[] = []; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class AccountOpenPositionIdsEnvelopeDto { + ok: bool = false; + result: AccountOpenPositionIdsResultDto = new AccountOpenPositionIdsResultDto(); +} + +@serializable +export class TokenIdLegDto { + index: string = ""; + asset: string = ""; + optionRatio: string = ""; + isLong: bool = false; + tokenType: string = ""; + riskPartner: string = ""; + strike: string = ""; + width: string = ""; + tickLower: string = ""; + tickUpper: string = ""; +} + +@serializable +export class GreeksPositionInputDto { + tokenId: string = ""; + legs: TokenIdLegDto[] = []; + tickAtMint: string = ""; + positionSize: string = ""; +} + +@serializable +export class GreeksCalculatePositionArgsDto { + legs: TokenIdLegDto[] = []; + currentTick: string = ""; + mintTick: string = ""; + positionSize: string = ""; + poolTickSpacing: string = ""; + swapAtMint: bool = false; +} + +@serializable +export class GreeksCalculatePositionRequestDto { + args: GreeksCalculatePositionArgsDto = new GreeksCalculatePositionArgsDto(); +} + +@serializable +export class GreeksCalculateAccountArgsDto { + positions: GreeksPositionInputDto[] = []; + tickSpacing: string = ""; + atTicks: string[] = []; + collateralAssets: string[] = []; +} + +@serializable +export class GreeksCalculateAccountRequestDto { + args: GreeksCalculateAccountArgsDto = new GreeksCalculateAccountArgsDto(); +} + +@serializable +export class GreeksResultDto { + value: string = ""; + delta: string = ""; + gamma: string = ""; + totalValue: string[] = []; + positionCount: string = ""; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class GreeksEnvelopeDto { + ok: bool = false; + result: GreeksResultDto = new GreeksResultDto(); +} + +@serializable +export class DynamicJobFragmentDto { + target: string = ""; + userProvidedData: string = ""; + strategyProvidedData: string = ""; + value: string = "0"; +} + +@serializable +export class DynamicJobFragmentEnvelopeDto { + ok: bool = false; + result: DynamicJobFragmentDto = new DynamicJobFragmentDto(); +} + +@serializable +export class CalldataPartsDto { + functionName: string = ""; + calldata: string = ""; + userProvidedData: string = ""; + strategyProvidedData: string = ""; + value: string = "0"; +} + +@serializable +export class CalldataPartsEnvelopeDto { + ok: bool = false; + result: CalldataPartsDto = new CalldataPartsDto(); +} + +@serializable +export class PanopticDispatchArgsDto { + poolAddress: string = ""; + existingPositionIds: string[] = []; + tokenId: string = ""; + positionSize: string = ""; + tickLimitLow: string = ""; + tickLimitHigh: string = ""; + spreadLimit: string = ""; + swapAtMint: bool = false; + usePremiaAsCollateral: bool = false; + builderCode: string = ""; +} + +@serializable +export class PanopticDispatchRequestDto { + args: PanopticDispatchArgsDto = new PanopticDispatchArgsDto(); +} + +@serializable +export class PanopticDispatchExplicitArgsDto { + poolAddress: string = ""; + positionIdList: string[] = []; + finalPositionIdList: string[] = []; + positionSizes: string[] = []; + tickAndSpreadLimits: string[][] = []; + usePremiaAsCollateral: bool = false; + builderCode: string = ""; +} + +@serializable +export class PanopticDispatchExplicitRequestDto { + args: PanopticDispatchExplicitArgsDto = new PanopticDispatchExplicitArgsDto(); +} + +@serializable +export class Erc20ApproveFragmentArgsDto { + token: string = ""; + spender: string = ""; + amount: string = ""; +} + +@serializable +export class Erc20ApproveFragmentRequestDto { + args: Erc20ApproveFragmentArgsDto = new Erc20ApproveFragmentArgsDto(); +} + +@serializable +export class Permit2ApproveFragmentArgsDto { + permit2: string = ""; + token: string = ""; + spender: string = ""; + amount: string = ""; + expiration: string = ""; +} + +@serializable +export class Permit2ApproveFragmentRequestDto { + args: Permit2ApproveFragmentArgsDto = new Permit2ApproveFragmentArgsDto(); +} + +@serializable +export class CollateralDepositFragmentArgsDto { + collateralTracker: string = ""; + assets: string = ""; + receiver: string = ""; +} + +@serializable +export class CollateralDepositFragmentRequestDto { + args: CollateralDepositFragmentArgsDto = new CollateralDepositFragmentArgsDto(); +} + +@serializable +export class CollateralWithdrawFragmentArgsDto { + collateralTracker: string = ""; + assets: string = ""; + receiver: string = ""; + owner: string = ""; +} + +@serializable +export class CollateralWithdrawFragmentRequestDto { + args: CollateralWithdrawFragmentArgsDto = new CollateralWithdrawFragmentArgsDto(); +} + +@serializable +export class CollateralWithdrawWithPositionsFragmentArgsDto extends CollateralWithdrawFragmentArgsDto { + positionIdList: string[] = []; + usePremiaAsCollateral: bool = false; +} + +@serializable +export class CollateralWithdrawWithPositionsFragmentRequestDto { + args: CollateralWithdrawWithPositionsFragmentArgsDto = new CollateralWithdrawWithPositionsFragmentArgsDto(); +} + +@serializable +export class WethAmountArgsDto { + amount: string = ""; +} + +@serializable +export class WethAmountRequestDto { + args: WethAmountArgsDto = new WethAmountArgsDto(); +} + +@serializable +export class HypovaultWethInnerCallArgsDto { + weth: string = ""; + amount: string = ""; +} + +@serializable +export class HypovaultWethInnerCallRequestDto { + args: HypovaultWethInnerCallArgsDto = new HypovaultWethInnerCallArgsDto(); +} + +@serializable +export class HypovaultInnerCallDto { + functionName: string = ""; + target: string = ""; + data: string = ""; + value: string = ""; +} + +@serializable +export class HypovaultInnerCallEnvelopeDto { + ok: bool = false; + result: HypovaultInnerCallDto = new HypovaultInnerCallDto(); +} + +@serializable +export class HypovaultFulfillDepositsArgsDto { + vaultManager: string = ""; + assetsToFulfill: string = ""; + managerInput: string = ""; +} + +@serializable +export class HypovaultFulfillDepositsRequestDto { + args: HypovaultFulfillDepositsArgsDto = new HypovaultFulfillDepositsArgsDto(); +} + +@serializable +export class HypovaultFulfillWithdrawalsArgsDto { + vaultManager: string = ""; + sharesToFulfill: string = ""; + maxAssetsReceived: string = ""; + managerInput: string = ""; +} + +@serializable +export class HypovaultFulfillWithdrawalsRequestDto { + args: HypovaultFulfillWithdrawalsArgsDto = new HypovaultFulfillWithdrawalsArgsDto(); +} + +@serializable +export class HypovaultManageCalldataPartsArgsDto { + innerTarget: string = ""; + innerData: string = ""; + value: string = ""; +} + +@serializable +export class HypovaultManageCalldataPartsRequestDto { + args: HypovaultManageCalldataPartsArgsDto = new HypovaultManageCalldataPartsArgsDto(); +} + +@serializable +export class HypovaultManageArgsDto extends HypovaultManageCalldataPartsArgsDto { + manager: string = ""; +} + +@serializable +export class HypovaultManageRequestDto { + args: HypovaultManageArgsDto = new HypovaultManageArgsDto(); +} + +@serializable +export class HypovaultPoolInfoDto { + pool: string = ""; + token0: string = ""; + token1: string = ""; + maxPriceDeviation: i32 = 0; +} + +@serializable +export class HypovaultBuildVaultManagerInputArgsDto { + vaultAddress: string = ""; + underlyingToken: string = ""; + poolInfos: HypovaultPoolInfoDto[] = []; + tokenIds: string[][] = []; + wethAddress: string = ""; + erc4626Vaults: string[] = []; +} + +@serializable +export class HypovaultBuildVaultManagerInputRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: HypovaultBuildVaultManagerInputArgsDto = new HypovaultBuildVaultManagerInputArgsDto(); +} + +@serializable +export class HypovaultBuildVaultManagerInputResultDto { + managerInput: string = ""; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class HypovaultBuildVaultManagerInputEnvelopeDto { + ok: bool = false; + result: HypovaultBuildVaultManagerInputResultDto = new HypovaultBuildVaultManagerInputResultDto(); +} + +@serializable +export class HypovaultCandidatesByPoolDto { + poolAddress: string = ""; + candidates: string[] = []; +} + +@serializable +export class HypovaultVerifyOpenTokenIdsArgsDto { + vaultAddress: string = ""; + candidatesByPool: HypovaultCandidatesByPoolDto[] = []; +} + +@serializable +export class HypovaultVerifyOpenTokenIdsRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: HypovaultVerifyOpenTokenIdsArgsDto = new HypovaultVerifyOpenTokenIdsArgsDto(); +} + +@serializable +export class HypovaultVerifyOpenTokenIdsResultDto { + tokenIdsByPool: string[][] = []; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class HypovaultVerifyOpenTokenIdsEnvelopeDto { + ok: bool = false; + result: HypovaultVerifyOpenTokenIdsResultDto = new HypovaultVerifyOpenTokenIdsResultDto(); +} + +@serializable +export class HypovaultEpochContextArgsDto { + vaultAddress: string = ""; + account: string = ""; +} + +@serializable +export class HypovaultEpochContextRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: HypovaultEpochContextArgsDto = new HypovaultEpochContextArgsDto(); +} + +@serializable +export class HypovaultDepositSnapshotDto { + epoch: string = ""; + assetsDeposited: string = ""; + assetsFulfilled: string = ""; + sharesReceived: string = ""; + pendingValue: string = ""; + queuedDeposit: string = ""; +} + +@serializable +export class HypovaultQueuedWithdrawalDto { + amount: string = ""; + basis: string = ""; + shouldRedeposit: bool = false; +} + +@serializable +export class HypovaultWithdrawalSnapshotDto { + epoch: string = ""; + sharesWithdrawn: string = ""; + sharesFulfilled: string = ""; + assetsPaid: string = ""; + pendingShares: string = ""; + queuedWithdrawal: HypovaultQueuedWithdrawalDto = new HypovaultQueuedWithdrawalDto(); +} + +@serializable +export class HypovaultEpochContextResultDto { + vaultAddress: string = ""; + account: string = ""; + totalSupply: string = ""; + currentTimestamp: string = ""; + deposit: HypovaultDepositSnapshotDto = new HypovaultDepositSnapshotDto(); + withdrawal: HypovaultWithdrawalSnapshotDto = new HypovaultWithdrawalSnapshotDto(); + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class HypovaultEpochContextEnvelopeDto { + ok: bool = false; + result: HypovaultEpochContextResultDto = new HypovaultEpochContextResultDto(); +} + +@serializable +export class HypovaultPositionsHashStatusArgsDto { + poolAddress: string = ""; + tokenIds: string[] = []; +} + +@serializable +export class HypovaultPositionsHashStatusRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: HypovaultPositionsHashStatusArgsDto = new HypovaultPositionsHashStatusArgsDto(); +} + +@serializable +export class HypovaultPositionsHashStatusResultDto { + account: string = ""; + poolAddress: string = ""; + positionsHash: string = ""; + tokenIds: string[] = []; + computedHash: string = ""; + valid: bool = false; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class HypovaultPositionsHashStatusEnvelopeDto { + ok: bool = false; + result: HypovaultPositionsHashStatusResultDto = new HypovaultPositionsHashStatusResultDto(); +} + +@serializable +export class MerkleLeafDto { + Action: string = ""; + Description: string = ""; + LeafDigest: string = ""; + DecoderAndSanitizerAddress: string = ""; + TargetAddress: string = ""; + FunctionSignature: string = ""; + FunctionSelector: string = ""; + CanSendValue: bool = false; +} + +@serializable +export class MerkleArtifactDto { + leafs: MerkleLeafDto[] = []; + proofsByAction: Map = new Map(); + proofsByDigest: Map = new Map(); +} + +@serializable +export class MerkleFindLeafArgsDto { + artifact: MerkleArtifactDto = new MerkleArtifactDto(); + description: string = ""; +} + +@serializable +export class MerkleFindLeafRequestDto { + args: MerkleFindLeafArgsDto = new MerkleFindLeafArgsDto(); +} + +@serializable +export class MerkleFoundLeafDto { + action: string = ""; + description: string = ""; + leafDigest: string = ""; + decoder: string = ""; + target: string = ""; + functionSignature: string = ""; + functionSelector: string = ""; + canSendValue: bool = false; + proof: string[] = []; +} + +@serializable +export class MerkleFindLeafEnvelopeDto { + ok: bool = false; + result: MerkleFoundLeafDto = new MerkleFoundLeafDto(); +} + +@serializable +export class MerkleBuildManageActionDto { + description: string = ""; + data: string = ""; + value: string = ""; +} + +@serializable +export class MerkleBuildManageArgsDto { + artifact: MerkleArtifactDto = new MerkleArtifactDto(); + actions: MerkleBuildManageActionDto[] = []; +} + +@serializable +export class MerkleBuildManageRequestDto { + args: MerkleBuildManageArgsDto = new MerkleBuildManageArgsDto(); +} + +@serializable +export class MerkleBuildManageResultDto { + proofs: string[][] = []; + decoders: string[] = []; + innerTargets: string[] = []; + innerDatas: string[] = []; + values: string[] = []; + leaves: MerkleFoundLeafDto[] = []; +} + +@serializable +export class MerkleBuildManageEnvelopeDto { + ok: bool = false; + result: MerkleBuildManageResultDto = new MerkleBuildManageResultDto(); +} + +@serializable +export class MerkleManageVaultWithVerificationFragmentArgsDto { + manager: string = ""; + proofs: string[][] = []; + decoders: string[] = []; + innerTargets: string[] = []; + innerDatas: string[] = []; + values: string[] = []; +} + +@serializable +export class MerkleManageVaultWithVerificationFragmentRequestDto { + args: MerkleManageVaultWithVerificationFragmentArgsDto = new MerkleManageVaultWithVerificationFragmentArgsDto(); +} + +@serializable +export class UniswapAddressesDto { + universalRouter: string = ""; + quoter: string = ""; + permit2: string = ""; + weth: string = ""; +} + +@serializable +export class UniswapRouteArgsDto { + poolAddress: string = ""; + tokenIn: string = ""; + amountIn: string = ""; + amountOut: string = ""; + slippageBps: string = ""; + addresses: UniswapAddressesDto | null = null; +} + +@serializable +export class UniswapRouteRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: UniswapRouteArgsDto = new UniswapRouteArgsDto(); +} + +@serializable +export class UniswapQuoteResultDto { + success: bool = false; + amountIn: string = ""; + amountOut: string = ""; + tokenIn: string = ""; + tokenOut: string = ""; + zeroForOne: bool = false; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class UniswapQuoteEnvelopeDto { + ok: bool = false; + result: UniswapQuoteResultDto = new UniswapQuoteResultDto(); +} + +@serializable +export class UniswapRouterApprovalArgsDto { + tokenIn: string = ""; + owner: string = ""; + amount: string = ""; + addresses: UniswapAddressesDto | null = null; +} + +@serializable +export class UniswapRouterApprovalRequestDto { + context: PanopticContextDto = new PanopticContextDto(); + args: UniswapRouterApprovalArgsDto = new UniswapRouterApprovalArgsDto(); +} + +@serializable +export class UniswapRouterApprovalResultDto { + needsErc20Approval: bool = false; + needsPermit2Approval: bool = false; + source: PanopticSourceMetaDto | null = null; +} + +@serializable +export class UniswapRouterApprovalEnvelopeDto { + ok: bool = false; + result: UniswapRouterApprovalResultDto = new UniswapRouterApprovalResultDto(); +} + +@serializable +export class UniswapV3ExactInArgsDto { + router: string = ""; + tokenIn: string = ""; + tokenOut: string = ""; + fee: string = ""; + recipient: string = ""; + amountIn: string = ""; + amountOutMin: string = ""; + payerIsUser: bool = false; + deadline: string = ""; +} + +@serializable +export class UniswapV3ExactInRequestDto { + args: UniswapV3ExactInArgsDto = new UniswapV3ExactInArgsDto(); +} + +@serializable +export class DynamicJobsRenderArgsDto { + fragments: DynamicJobFragmentDto[] = []; +} + +@serializable +export class DynamicJobsRenderRequestDto { + args: DynamicJobsRenderArgsDto = new DynamicJobsRenderArgsDto(); +} + +@serializable +export class DynamicJobsExecutePayloadDto { + functionName: string = ""; + typesArray: string[] = []; + valuesArray: string[][] = []; +} + +@serializable +export class DynamicJobsRenderEnvelopeDto { + ok: bool = false; + result: DynamicJobsExecutePayloadDto = new DynamicJobsExecutePayloadDto(); +} + +@serializable +export class PanopticSdkRecordResultDto { + source: PanopticSourceMetaDto | null = null; + poolId: string = ""; + tokenId: string = ""; + value: string = ""; + balance0: string = ""; + balance1: string = ""; + utilization0: string = ""; + utilization1: string = ""; + currentTick: string = ""; + oracleTick: string = ""; + lower: string = ""; + upper: string = ""; +} + +@serializable +export class PanopticSdkRecordEnvelopeDto { + ok: bool = false; + result: PanopticSdkRecordResultDto = new PanopticSdkRecordResultDto(); +} diff --git a/assembly/utils/types/Price.ts b/assembly/utils/types/Price.ts index e8b692d..5c4f8c4 100644 --- a/assembly/utils/types/Price.ts +++ b/assembly/utils/types/Price.ts @@ -1,60 +1,54 @@ -import { JSON } from "assemblyscript-json"; +import { JSON } from "json-as/assembly"; +@serializable export class Price { constructor( - public high: f32, - public low: f32, - public open: f32, - public close: f32 + public high: f32 = 0, + public low: f32 = 0, + public open: f32 = 0, + public close: f32 = 0 ) {} } -export function parsePrices(_prices: String): Array { - const prices = _prices; - // Parse an object using the JSON object - let jsonObj: JSON.Obj = JSON.parse(prices); - const result: Array = []; - - const data_arr = jsonObj.getArr("data"); - if (data_arr == null) {throw new Error()}; - // First and only data result for this strategy is the candles - const val = data_arr._arr[0] - if (val != null) { - if (val.isArr) { - const pricesArray = (val).valueOf(); - - for (let priceIndex = 0; priceIndex < pricesArray.length; priceIndex++) { - const price = pricesArray[priceIndex]; - - const candle = JSON.parse(price.toString()); - - if (candle.isObj) { - const cl = candle.getValue("close"); - const hi = candle.getValue("high"); - const lo = candle.getValue("low"); - const op = candle.getValue("open"); - - if (cl && hi && lo && op) { - //@ts-ignore - const close = f32(Number.parseFloat(cl.toString())); - //@ts-ignore - const high = f32(Number.parseFloat(hi.toString())); - //@ts-ignore - const low = f32(Number.parseFloat(lo.toString())); - //@ts-ignore - const open = f32(Number.parseFloat(op.toString())); - - const obj: Price = new Price(high, low, open, close); - - result.push(obj); - } - } - - return result; - } - } - return []; - } else { - return []; +function parsePriceField(candle: JSON.Obj, key: string): f32 { + const value = candle.get(key); + + if (value === null) { + return 0; + } + + if (value!.type == JSON.Types.String) { + return f32.parse(value!.get()); + } + + return f32.parse(value!.toString()); +} + +export function parsePrices(_prices: string): Array { + const payload = JSON.parse(_prices); + const dataValue = payload.get("data"); + + if (dataValue === null) { + return []; + } + + const data = dataValue!.get(); + if (data.length == 0) { + return []; } -} \ No newline at end of file + + const candles = data.getAs(0); + const result = new Array(); + + for (let priceIndex = 0; priceIndex < candles.length; priceIndex++) { + const candle = candles.getAs(priceIndex); + result.push(new Price( + parsePriceField(candle, "high"), + parsePriceField(candle, "low"), + parsePriceField(candle, "open"), + parsePriceField(candle, "close"), + )); + } + + return result; +} diff --git a/index.js b/index.js index 47d5544..f91e3c0 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,3 @@ -const fs = require("fs"); -import * as AsBind from "as-bind/dist/as-bind.cjs.js"; - -const imports = { - console: { // File which you are injecting - log(strPtr) { - console.log(strPtr) - } - } -}; - -const asBindInstance = AsBind.instantiateSync(fs.readFileSync(__dirname + "/build/optimized.wasm"), imports) - -module.exports = asBindInstance.exports; +throw new Error( + '@steerprotocol/strategy-utils is an AssemblyScript source package. Import from assembly/index.ts in AssemblyScript strategies.', +); diff --git a/package.json b/package.json index 5545683..4b8ddbd 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { "name": "@steerprotocol/strategy-utils", - "version": "0.0.3", + "version": "0.1.0", "description": "Strategy utilities library for Steer Protocol strategies", "main": "assembly/index.ts", "types": "assembly/index.ts", "scripts": { "test": "yarn jest", - "asbuild:untouched": "asc assembly/index.ts --target debug --exportRuntime --transform as-bind", - "asbuild:optimized": "asc assembly/index.ts --target release --exportRuntime --transform as-bind", + "asbuild:untouched": "asc assembly/index.ts --target debug --exportRuntime", + "asbuild:optimized": "asc assembly/index.ts --target release --exportRuntime", "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", - "docs": "typedoc --tsconfig ./tsconfig.json", + "docs": "node scripts/build-docs.js", "strategy": "yarn asbuild && yarn test", "semantic-release": "semantic-release", "commit": "cz" @@ -17,22 +17,22 @@ "author": "Derek Barrera ", "license": "ISC", "dependencies": { - "@assemblyscript/loader": "0.19.9", + "@assemblyscript/loader": "^0.28.19", "@babel/preset-typescript": "^7.14.5", "@semantic-release/changelog": "^5.0.1", "@semantic-release/git": "^9.0.0", "@steerprotocol/base-strategy": "^0.0.2", - "as-bind": "^0.8.0", - "assemblyscript-json": "^1.1.0", "commitizen": "^4.2.4", "conventional-changelog-conventionalcommits": "^4.6.0", - "typescript": "^4.3.5" + "typescript": "^4.3.5", + "json-as": "^1.2.6", + "visitor-as": "^0.11.4" }, "devDependencies": { "@babel/preset-env": "^7.14.8", "@types/jest": "^27.0.1", "@types/node": "^16.11.11", - "assemblyscript": "0.19.9", + "assemblyscript": "^0.28.19", "babel-core": "^6.26.3", "babel-jest": "^27.0.6", "cz-conventional-changelog": "3.3.0", diff --git a/scripts/build-docs.js b/scripts/build-docs.js new file mode 100644 index 0000000..e70353d --- /dev/null +++ b/scripts/build-docs.js @@ -0,0 +1,68 @@ +const fs = require('fs'); +const path = require('path'); + +const docsDir = path.join(process.cwd(), 'docs'); +fs.mkdirSync(docsDir, { recursive: true }); + +const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); +const files = [ + 'assembly/index.ts', + 'assembly/utils/index.ts', + 'assembly/panoptic/index.ts', + 'assembly/panoptic/methods.ts', + 'assembly/panoptic/types.ts', + 'assembly/panoptic/host.ts', +].filter((file) => fs.existsSync(file)); + +const methodFile = 'assembly/panoptic/methods.ts'; +const methods = fs.existsSync(methodFile) + ? Array.from(fs.readFileSync(methodFile, 'utf8').matchAll(/export const ([A-Z0-9_]+) = \"([^\"]+)\";/g)).map((match) => ({ + name: match[1], + method: match[2], + })) + : []; + +const escapeHtml = (value) => value + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/\"/g, '"'); + +const html = ` + + + + + ${escapeHtml(packageJson.name)} ${escapeHtml(packageJson.version)} + + + +
+

${escapeHtml(packageJson.name)} ${escapeHtml(packageJson.version)}

+

AssemblyScript source package for Steer strategy utilities.

+

Import

+
import { PanopticMethods, erc20ApproveFragment } from "@steerprotocol/strategy-utils/assembly";
+

Entrypoints

+
    + ${files.map((file) => `
  • ${escapeHtml(file)}
  • `).join('\n ')} +
+

Panoptic RuntimeAdapter Methods

+ + + + ${methods.map(({ name, method }) => ``).join('\n ')} + +
ConstantMethod
${escapeHtml(name)}${escapeHtml(method)}
+
+ + +`; + +fs.writeFileSync(path.join(docsDir, 'index.html'), html); diff --git a/tests/fixtures/json-compat.ts b/tests/fixtures/json-compat.ts new file mode 100644 index 0000000..54a4bde --- /dev/null +++ b/tests/fixtures/json-compat.ts @@ -0,0 +1,30 @@ +import { JSON } from "json-as/assembly"; +import { MerkleArtifactDto } from "../../assembly/panoptic/types"; +import { parsePrices } from "../../assembly/utils/types/Price"; + +export function parseStringifiedPrices(): string { + const prices = parsePrices('{"data":[[{"high":"123.4","low":"120.1","open":"121.2","close":"122.3"},{"high":124.5,"low":121.2,"open":122.3,"close":123.4}]]}'); + + if (prices.length != 2) { + return "bad-length:" + prices.length.toString(); + } + + if (prices[0].high < 123.39 || prices[0].high > 123.41) { + return "bad-string-high:" + prices[0].high.toString(); + } + + if (prices[0].close < 122.29 || prices[0].close > 122.31) { + return "bad-string-close:" + prices[0].close.toString(); + } + + if (prices[1].high < 124.49 || prices[1].high > 124.51) { + return "bad-number-high:" + prices[1].high.toString(); + } + + return "ok"; +} + +export function roundTripMerkleProofActions(input: string): string { + const artifact = JSON.parse(input); + return JSON.stringify>(artifact.proofsByAction); +} diff --git a/tests/fixtures/panoptic-consumer.ts b/tests/fixtures/panoptic-consumer.ts new file mode 100644 index 0000000..ed375fa --- /dev/null +++ b/tests/fixtures/panoptic-consumer.ts @@ -0,0 +1,24 @@ +import { + DynamicJobFragmentDto, + Erc20ApproveFragmentRequestDto, + PanopticMethods, + erc20ApproveFragment, +} from "../../assembly"; + +export function buildTypedPanopticRequest(): string { + const request = new Erc20ApproveFragmentRequestDto(); + request.args.token = "0x00000000000000000000000000000000000000a0"; + request.args.spender = "0x00000000000000000000000000000000000000b0"; + request.args.amount = "100"; + + return PanopticMethods.ERC20_APPROVE_FRAGMENT + + ":" + request.args.token + + ":" + request.args.spender + + ":" + request.args.amount; +} + +export function compileTypedPanopticWrapper(): string { + const response = erc20ApproveFragment(new Erc20ApproveFragmentRequestDto()); + const fragment: DynamicJobFragmentDto = response.result; + return fragment.value; +} diff --git a/tests/index.test.ts b/tests/index.test.ts index 13a6964..eb8de95 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,23 +1,66 @@ -const myModule = require("../index"); - -describe("WASM Module", () => { - describe("keltnerChannels", () => { - it("Price should ", async () => { - const price = new myModule.Price(1,2,3,4); - expect(price.high).toBe(1); - expect(price.low).toBe(2); - expect(price.open).toBe(3); - expect(price.close).toBe(4); - }); - it("True average should compute properly", async () => { - const prices = [new myModule.Price(1,2,3,4),new myModule.Price(2,3,4,5)]; - const trueAverage = myModule.getAverageTrueRange(prices, 1); - expect(trueAverage).toBe(2); +const fs = require('fs'); +const os = require('os'); +const { execFileSync } = require('child_process'); +const loader = require('@assemblyscript/loader'); +const path = require('path'); + +describe('AssemblyScript package surface', () => { + it('compiles the package with the modern AssemblyScript toolchain', () => { + execFileSync('npm', ['run', 'asbuild'], { + cwd: path.resolve(__dirname, '..'), + stdio: 'pipe', }); - it("True average should support decimals ", async () => { - const prices = [new myModule.Price(6.1,4.2,2.5,1.11),new myModule.Price(41,32,41,15)]; - const trueAverage = myModule.getAverageTrueRange(prices, 1); - expect(trueAverage).toBe(39.88999938964844) + }); + + it('compiles a Panoptic consumer using exported DTOs and wrappers', () => { + execFileSync( + path.resolve(__dirname, '../node_modules/.bin/asc'), + [path.resolve(__dirname, 'fixtures/panoptic-consumer.ts'), '--config', path.resolve(__dirname, '../asconfig.json'), '--noEmit'], + { + cwd: path.resolve(__dirname, '..'), + stdio: 'pipe', + }, + ); + }); + + it('preserves json-as runtime compatibility for legacy prices and dynamic Merkle proof keys', () => { + const repoRoot = path.resolve(__dirname, '..'); + const wasmPath = path.join(os.tmpdir(), 'strategy-utils-json-compat.fixture.wasm'); + + execFileSync( + path.resolve(repoRoot, 'node_modules/.bin/asc'), + [ + path.resolve(__dirname, 'fixtures/json-compat.ts'), + '--config', + path.resolve(repoRoot, 'asconfig.json'), + '--outFile', + wasmPath, + '--exportRuntime', + ], + { + cwd: repoRoot, + stdio: 'pipe', + }, + ); + + const wasm = loader.instantiateSync(fs.readFileSync(wasmPath), {}); + const { parseStringifiedPrices, roundTripMerkleProofActions, __getString, __newString } = wasm.exports; + + expect(__getString(parseStringifiedPrices())).toBe('ok'); + + const input = JSON.stringify({ + leafs: [], + proofsByAction: { + approveToken: ['0xaaa'], + rebalanceVault: ['0xbbb', '0xccc'], + }, + proofsByDigest: { + '0x111': ['0xddd'], + }, }); + + const output = JSON.parse(__getString(roundTripMerkleProofActions(__newString(input)))); + expect(output.approveToken).toStrictEqual(['0xaaa']); + expect(output.rebalanceVault).toStrictEqual(['0xbbb', '0xccc']); }); }); diff --git a/yarn.lock b/yarn.lock index 3e42d1e..bdfcd4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15,6 +15,11 @@ resolved "https://registry.yarnpkg.com/@assemblyscript/loader/-/loader-0.19.9.tgz#9e290dbf5c164d9a0e397b253347e85e17c64057" integrity sha512-AL39UxO+LkYDXtxFTyJP1UVJYIgqVHTbwk9BMPZjoiNxPP/kxDP+LmHxkr1Pm6goR1QbnF69mn5NMuiLTde0mA== +"@assemblyscript/loader@^0.28.19": + version "0.28.19" + resolved "https://registry.yarnpkg.com/@assemblyscript/loader/-/loader-0.28.19.tgz#541cd6012ecd9e8a86ea98b2c58aa37758c1c050" + integrity sha512-6OhPTJ0nS8aay8t2lhbA/XkyffgU15ECPsLHT0VZFG7j7sUA1CT2HS7nIALwjg6Pdpgp+RTHQukgK1IoCUbxCQ== + "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.7.tgz#44416b6bd7624b998f5b1af5d470856c40138789" @@ -2010,18 +2015,13 @@ asn1@~0.2.3: dependencies: safer-buffer "~2.1.0" -assemblyscript-json@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/assemblyscript-json/-/assemblyscript-json-1.1.0.tgz#49d38bc21f1ac36f2887528a35de6cf7d59c17be" - integrity sha512-UbE8ts8csTWQgd5TnSPN7MRV9NveuHv1bVnKmDLoo/tzjqxkmsZb3lu59Uk8H7SGoqdkDSEE049alx/nHnSdFw== - -assemblyscript@0.19.9: - version "0.19.9" - resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.9.tgz#c86abab27fd6639fc2de92261334ba2c899f64ae" - integrity sha512-nVEg1bbGBegJp+UO9okNHgjCX6sri4OrIkl/LCaNWLIvioN2IjFeYt3R6ppZ6L813VYJxKhf0hr6lhXOXw3dvA== +assemblyscript@^0.28.19: + version "0.28.19" + resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.28.19.tgz#0c119bf7e50cbfc9d8629a0d234f151133b73c4d" + integrity sha512-yOAlAb9EsrI00oUaf6qUTtTcYYeelG2iC3f1LnA45XUeSlMrp2O2FF5Llj4P+Y84ZiIlh/ciEEpOaPwwmOKq8g== dependencies: - binaryen "101.0.0-nightly.20210723" - long "^4.0.0" + binaryen "130.0.0-nightly.20260609" + long "^5.2.4" assert-plus@1.0.0, assert-plus@^1.0.0: version "1.0.0" @@ -2299,10 +2299,10 @@ binary-extensions@^2.2.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -binaryen@101.0.0-nightly.20210723: - version "101.0.0-nightly.20210723" - resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210723.tgz#b6bb7f3501341727681a03866c0856500eec3740" - integrity sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA== +binaryen@130.0.0-nightly.20260609: + version "130.0.0-nightly.20260609" + resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-130.0.0-nightly.20260609.tgz#1e8501c8162ebdb72dcdc84de561052e06a34684" + integrity sha512-Zyl9Tw638x08LDew22YtxdYiUGxn+quzpR3ySIS4Nccv6yAiO5j1Yko9IEPNpj/aBZf71xtD/6hYXsgZ2ye3ew== bottleneck@^2.18.1: version "2.19.5" @@ -4518,6 +4518,13 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0= +json-as@^1.2.6: + version "1.5.0" + resolved "https://registry.yarnpkg.com/json-as/-/json-as-1.5.0.tgz#dcb5bfa6e02e56393b47bb3e3eb3120a6d442488" + integrity sha512-5p4N1D7iI0DMVGmD9yIpXBAlVHPkpqzUETpTMt4w0PwJUdixIH6ebl7+RxdVcJHJ/GoNO4nknsc9xO1LQU0xeQ== + dependencies: + xjb-as "^0.1.0" + json-parse-better-errors@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" @@ -4817,10 +4824,10 @@ lodash@^4.17.12, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17 resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== -long@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" - integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== +long@^5.2.4: + version "5.3.2" + resolved "https://registry.yarnpkg.com/long/-/long-5.3.2.tgz#1d84463095999262d7d7b7f8bfd4a8cc55167f83" + integrity sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA== longest@^2.0.1: version "2.0.1" @@ -6743,6 +6750,11 @@ ts-mixer@^5.1.0: resolved "https://registry.yarnpkg.com/ts-mixer/-/ts-mixer-5.4.1.tgz#b90db9ced48531aa17ce9184a2890d1e3c99b1e5" integrity sha512-Zo9HgPCtNouDgJ+LGtrzVOjSg8+7WGQktIKLwAfaNrlOK1mWGlz1ejsAF/YqUEqAGjUTeB5fEg8gH9Aui6w9xA== +ts-mixer@^6.0.2: + version "6.0.4" + resolved "https://registry.yarnpkg.com/ts-mixer/-/ts-mixer-6.0.4.tgz#1da39ceabc09d947a82140d9f09db0f84919ca28" + integrity sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA== + ts-node@^10.7.0: version "10.7.0" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.7.0.tgz#35d503d0fab3e2baa672a0e94f4b40653c2463f5" @@ -6971,6 +6983,14 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" +visitor-as@^0.11.4: + version "0.11.4" + resolved "https://registry.yarnpkg.com/visitor-as/-/visitor-as-0.11.4.tgz#7b2d7b7ac8be86d4741796aa0630af5e471a4744" + integrity sha512-uih7AooY2V3LhzobjLqyEQzhYYBGeq0y/rZk295foM1Ko498f24NNXBDyM1SgzcLMFCAT/fpmSRco1BpTIdKNQ== + dependencies: + lodash.clonedeep "^4.5.0" + ts-mixer "^6.0.2" + visitor-as@^0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/visitor-as/-/visitor-as-0.5.0.tgz#c0911c028df3a31218c9091ffdae172b507d536b" @@ -7126,6 +7146,11 @@ ws@^7.4.6: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.7.tgz#9e0ac77ee50af70d58326ecff7e85eb3fa375e67" integrity sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A== +xjb-as@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/xjb-as/-/xjb-as-0.1.0.tgz#cf9678158ac299b8374467cf49d81d256b2219ad" + integrity sha512-Q73gSq7cfWbsDY/RcJHTa2QU9nb6bktp4iqCxUxNg8VhK+JQd3wcwIY0Nwuo6gTtAsBBpEPMf4zfUXbATHdwhw== + xml-name-validator@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"