From f3c2c5c882eac615918eb5b7d8828852057bc27c Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Thu, 9 Jan 2025 16:46:53 -0800 Subject: [PATCH 1/6] Add walrus package --- packages/walrus/.prettierignore | 2 + packages/walrus/README.md | 1 + packages/walrus/package.json | 51 ++ .../ascii.ts | 15 + .../bit_vector.ts | 11 + .../fixed_point32.ts | 10 + .../option.ts | 10 + .../string.ts | 9 + .../type_name.ts | 9 + .../uq32_32.ts | 9 + .../uq64_64.ts | 9 + .../authenticator_state.ts | 39 + .../bag.ts | 12 + .../balance.ts | 14 + .../bcs.ts | 9 + .../bls12381.ts | 29 + .../borrow.ts | 17 + .../clock.ts | 12 + .../coin.ts | 53 ++ .../config.ts | 24 + .../deny_list.ts | 48 ++ .../display.ts | 26 + .../dynamic_field.ts | 16 + .../dynamic_object_field.ts | 10 + .../groth16.ts | 27 + .../group_ops.ts | 9 + .../kiosk.ts | 72 ++ .../kiosk_extension.ts | 18 + .../linked_table.ts | 30 + .../object.ts | 14 + .../object_bag.ts | 12 + .../object_table.ts | 12 + .../package.ts | 35 + .../priority_queue.ts | 16 + .../random.ts | 28 + .../sui.ts | 9 + .../table.ts | 12 + .../table_vec.ts | 11 + .../token.ts | 50 ++ .../transfer.ts | 10 + .../transfer_policy.ts | 45 ++ .../tx_context.ts | 13 + .../url.ts | 9 + .../vec_map.ts | 20 + .../vec_set.ts | 10 + .../versioned.ts | 18 + .../zklogin_verified_id.ts | 16 + .../zklogin_verified_issuer.ts | 13 + packages/walrus/src/contracts/utils/index.ts | 92 +++ packages/walrus/src/contracts/wal/wal.ts | 28 + .../contracts/wal_exchange/wal_exchange.ts | 325 +++++++++ .../walrus/src/contracts/walrus/active_set.ts | 183 +++++ packages/walrus/src/contracts/walrus/blob.ts | 338 +++++++++ .../src/contracts/walrus/bls_aggregate.ts | 242 ++++++ .../walrus/src/contracts/walrus/committee.ts | 105 +++ .../walrus/src/contracts/walrus/encoding.ts | 26 + .../src/contracts/walrus/epoch_parameters.ts | 64 ++ .../walrus/src/contracts/walrus/event_blob.ts | 259 +++++++ .../walrus/src/contracts/walrus/events.ts | 230 ++++++ packages/walrus/src/contracts/walrus/init.ts | 65 ++ .../walrus/src/contracts/walrus/messages.ts | 275 +++++++ .../walrus/src/contracts/walrus/metadata.ts | 52 ++ .../src/contracts/walrus/pending_values.ts | 121 +++ .../contracts/walrus/pool_exchange_rate.ts | 58 ++ .../walrus/src/contracts/walrus/redstuff.ts | 103 +++ .../src/contracts/walrus/shared_blob.ts | 56 ++ .../walrus/src/contracts/walrus/staked_wal.ts | 222 ++++++ .../walrus/src/contracts/walrus/staking.ts | 441 +++++++++++ .../src/contracts/walrus/staking_inner.ts | 687 ++++++++++++++++++ .../src/contracts/walrus/staking_pool.ts | 501 +++++++++++++ .../contracts/walrus/storage_accounting.ts | 200 +++++ .../src/contracts/walrus/storage_node.ts | 233 ++++++ .../src/contracts/walrus/storage_resource.ts | 186 +++++ .../walrus/src/contracts/walrus/system.ts | 335 +++++++++ .../contracts/walrus/system_state_inner.ts | 393 ++++++++++ .../src/contracts/walrus/walrus_context.ts | 56 ++ packages/walrus/src/index.ts | 4 + packages/walrus/tsconfig.esm.json | 7 + packages/walrus/tsconfig.json | 11 + packages/walrus/typedoc.json | 6 + packages/walrus/vitest.config.mts | 6 + pnpm-lock.yaml | 22 + 82 files changed, 6886 insertions(+) create mode 100644 packages/walrus/.prettierignore create mode 100644 packages/walrus/README.md create mode 100644 packages/walrus/package.json create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/ascii.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts create mode 100644 packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts create mode 100644 packages/walrus/src/contracts/utils/index.ts create mode 100644 packages/walrus/src/contracts/wal/wal.ts create mode 100644 packages/walrus/src/contracts/wal_exchange/wal_exchange.ts create mode 100644 packages/walrus/src/contracts/walrus/active_set.ts create mode 100644 packages/walrus/src/contracts/walrus/blob.ts create mode 100644 packages/walrus/src/contracts/walrus/bls_aggregate.ts create mode 100644 packages/walrus/src/contracts/walrus/committee.ts create mode 100644 packages/walrus/src/contracts/walrus/encoding.ts create mode 100644 packages/walrus/src/contracts/walrus/epoch_parameters.ts create mode 100644 packages/walrus/src/contracts/walrus/event_blob.ts create mode 100644 packages/walrus/src/contracts/walrus/events.ts create mode 100644 packages/walrus/src/contracts/walrus/init.ts create mode 100644 packages/walrus/src/contracts/walrus/messages.ts create mode 100644 packages/walrus/src/contracts/walrus/metadata.ts create mode 100644 packages/walrus/src/contracts/walrus/pending_values.ts create mode 100644 packages/walrus/src/contracts/walrus/pool_exchange_rate.ts create mode 100644 packages/walrus/src/contracts/walrus/redstuff.ts create mode 100644 packages/walrus/src/contracts/walrus/shared_blob.ts create mode 100644 packages/walrus/src/contracts/walrus/staked_wal.ts create mode 100644 packages/walrus/src/contracts/walrus/staking.ts create mode 100644 packages/walrus/src/contracts/walrus/staking_inner.ts create mode 100644 packages/walrus/src/contracts/walrus/staking_pool.ts create mode 100644 packages/walrus/src/contracts/walrus/storage_accounting.ts create mode 100644 packages/walrus/src/contracts/walrus/storage_node.ts create mode 100644 packages/walrus/src/contracts/walrus/storage_resource.ts create mode 100644 packages/walrus/src/contracts/walrus/system.ts create mode 100644 packages/walrus/src/contracts/walrus/system_state_inner.ts create mode 100644 packages/walrus/src/contracts/walrus/walrus_context.ts create mode 100644 packages/walrus/src/index.ts create mode 100644 packages/walrus/tsconfig.esm.json create mode 100644 packages/walrus/tsconfig.json create mode 100644 packages/walrus/typedoc.json create mode 100644 packages/walrus/vitest.config.mts diff --git a/packages/walrus/.prettierignore b/packages/walrus/.prettierignore new file mode 100644 index 0000000..f44447b --- /dev/null +++ b/packages/walrus/.prettierignore @@ -0,0 +1,2 @@ +CHANGELOG.md +dist/ diff --git a/packages/walrus/README.md b/packages/walrus/README.md new file mode 100644 index 0000000..2900836 --- /dev/null +++ b/packages/walrus/README.md @@ -0,0 +1 @@ +# `@mysten/walrus` diff --git a/packages/walrus/package.json b/packages/walrus/package.json new file mode 100644 index 0000000..0a8aa42 --- /dev/null +++ b/packages/walrus/package.json @@ -0,0 +1,51 @@ +{ + "name": "@mysten/walrus", + "version": "0.0.0", + "description": "Walrus SDK", + "license": "Apache-2.0", + "author": "Mysten Labs ", + "type": "commonjs", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/cjs/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, + "sideEffects": false, + "files": [ + "CHANGELOG.md", + "dist" + ], + "scripts": { + "clean": "rm -rf tsconfig.tsbuildinfo ./dist", + "build": "build-package", + "prepublishOnly": "pnpm build", + "prettier:check": "prettier -c --ignore-unknown .", + "prettier:fix": "prettier -w --ignore-unknown .", + "eslint:check": "eslint --max-warnings=0 .", + "eslint:fix": "pnpm run eslint:check --fix", + "lint": "pnpm run eslint:check && pnpm run prettier:check", + "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mystenlabs/ts-sdks.git" + }, + "bugs": { + "url": "https://github.com/mystenlabs/ts-sdks/issues" + }, + "homepage": "https://github.com/mystenlabs/ts-sdks#readme", + "devDependencies": { + "@mysten/build-scripts": "workspace:*", + "@types/node": "^22.10.5", + "typescript": "^5.7.2", + "vitest": "^2.1.8" + }, + "dependencies": { + "@mysten/bcs": "workspace:*", + "@mysten/sui": "workspace:*" + } +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/ascii.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/ascii.ts new file mode 100644 index 0000000..d268136 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/ascii.ts @@ -0,0 +1,15 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { bcs } from '@mysten/sui/bcs'; + +export function String() { + return bcs.struct('String', { + bytes: bcs.vector(bcs.u8()), + }); +} +export function Char() { + return bcs.struct('Char', { + byte: bcs.u8(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts new file mode 100644 index 0000000..c026a1e --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts @@ -0,0 +1,11 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { bcs } from '@mysten/sui/bcs'; + +export function BitVector() { + return bcs.struct('BitVector', { + length: bcs.u64(), + bit_field: bcs.vector(bcs.bool()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts new file mode 100644 index 0000000..41052db --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts @@ -0,0 +1,10 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { bcs } from '@mysten/sui/bcs'; + +export function FixedPoint32() { + return bcs.struct('FixedPoint32', { + value: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts new file mode 100644 index 0000000..86002a3 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts @@ -0,0 +1,10 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +export function Option>(...typeParameters: [T0]) { + return bcs.struct('Option', { + vec: bcs.vector(typeParameters[0]), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts new file mode 100644 index 0000000..9544a33 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function String() { + return bcs.struct('String', { + bytes: bcs.vector(bcs.u8()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts new file mode 100644 index 0000000..a777803 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function TypeName() { + return bcs.struct('TypeName', { + name: bcs.string(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts new file mode 100644 index 0000000..8c2aab8 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function UQ32_32() { + return bcs.struct('UQ32_32', { + pos0: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts new file mode 100644 index 0000000..9587bd5 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function UQ64_64() { + return bcs.struct('UQ64_64', { + pos0: bcs.u128(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts new file mode 100644 index 0000000..51c9678 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts @@ -0,0 +1,39 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function AuthenticatorState() { + return bcs.struct('AuthenticatorState', { + id: object.UID(), + version: bcs.u64(), + }); +} +export function AuthenticatorStateInner() { + return bcs.struct('AuthenticatorStateInner', { + version: bcs.u64(), + active_jwks: bcs.vector(ActiveJwk()), + }); +} +export function JWK() { + return bcs.struct('JWK', { + kty: bcs.string(), + e: bcs.string(), + n: bcs.string(), + alg: bcs.string(), + }); +} +export function JwkId() { + return bcs.struct('JwkId', { + iss: bcs.string(), + kid: bcs.string(), + }); +} +export function ActiveJwk() { + return bcs.struct('ActiveJwk', { + jwk_id: JwkId(), + jwk: JWK(), + epoch: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts new file mode 100644 index 0000000..e6e7337 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Bag() { + return bcs.struct('Bag', { + id: object.UID(), + size: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts new file mode 100644 index 0000000..11963a9 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts @@ -0,0 +1,14 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function Supply() { + return bcs.struct('Supply', { + value: bcs.u64(), + }); +} +export function Balance() { + return bcs.struct('Balance', { + value: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts new file mode 100644 index 0000000..281c5aa --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function BCS() { + return bcs.struct('BCS', { + bytes: bcs.vector(bcs.u8()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts new file mode 100644 index 0000000..c113e4e --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts @@ -0,0 +1,29 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function Scalar() { + return bcs.struct('Scalar', { + dummy_field: bcs.bool(), + }); +} +export function G1() { + return bcs.struct('G1', { + dummy_field: bcs.bool(), + }); +} +export function G2() { + return bcs.struct('G2', { + dummy_field: bcs.bool(), + }); +} +export function GT() { + return bcs.struct('GT', { + dummy_field: bcs.bool(), + }); +} +export function UncompressedG1() { + return bcs.struct('UncompressedG1', { + dummy_field: bcs.bool(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts new file mode 100644 index 0000000..7ee2df0 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts @@ -0,0 +1,17 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +export function Referent>(...typeParameters: [T0]) { + return bcs.struct('Referent', { + id: bcs.Address, + value: bcs.option(typeParameters[0]), + }); +} +export function Borrow() { + return bcs.struct('Borrow', { + ref: bcs.Address, + obj: bcs.Address, + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts new file mode 100644 index 0000000..3735c90 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Clock() { + return bcs.struct('Clock', { + id: object.UID(), + timestamp_ms: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts new file mode 100644 index 0000000..618dbf1 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts @@ -0,0 +1,53 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as balance from './balance.js'; +import * as object from './object.js'; +import * as url from './url.js'; + +export function Coin() { + return bcs.struct('Coin', { + id: object.UID(), + balance: balance.Balance(), + }); +} +export function CoinMetadata() { + return bcs.struct('CoinMetadata', { + id: object.UID(), + decimals: bcs.u8(), + name: bcs.string(), + symbol: bcs.string(), + description: bcs.string(), + icon_url: bcs.option(url.Url()), + }); +} +export function RegulatedCoinMetadata() { + return bcs.struct('RegulatedCoinMetadata', { + id: object.UID(), + coin_metadata_object: bcs.Address, + deny_cap_object: bcs.Address, + }); +} +export function TreasuryCap() { + return bcs.struct('TreasuryCap', { + id: object.UID(), + total_supply: balance.Supply(), + }); +} +export function DenyCapV2() { + return bcs.struct('DenyCapV2', { + id: object.UID(), + allow_global_pause: bcs.bool(), + }); +} +export function CurrencyCreated() { + return bcs.struct('CurrencyCreated', { + decimals: bcs.u8(), + }); +} +export function DenyCap() { + return bcs.struct('DenyCap', { + id: object.UID(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts new file mode 100644 index 0000000..e3350bc --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts @@ -0,0 +1,24 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Config() { + return bcs.struct('Config', { + id: object.UID(), + }); +} +export function Setting>(...typeParameters: [T0]) { + return bcs.struct('Setting', { + data: bcs.option(SettingData(typeParameters[0])), + }); +} +export function SettingData>(...typeParameters: [T0]) { + return bcs.struct('SettingData', { + newer_value_epoch: bcs.u64(), + newer_value: bcs.option(typeParameters[0]), + older_value_opt: bcs.option(typeParameters[0]), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts new file mode 100644 index 0000000..3fa131e --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts @@ -0,0 +1,48 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as bag from './bag.js'; +import * as object from './object.js'; +import * as table from './table.js'; + +export function DenyList() { + return bcs.struct('DenyList', { + id: object.UID(), + lists: bag.Bag(), + }); +} +export function ConfigWriteCap() { + return bcs.struct('ConfigWriteCap', { + dummy_field: bcs.bool(), + }); +} +export function ConfigKey() { + return bcs.struct('ConfigKey', { + per_type_index: bcs.u64(), + per_type_key: bcs.vector(bcs.u8()), + }); +} +export function AddressKey() { + return bcs.struct('AddressKey', { + pos0: bcs.Address, + }); +} +export function GlobalPauseKey() { + return bcs.struct('GlobalPauseKey', { + dummy_field: bcs.bool(), + }); +} +export function PerTypeConfigCreated() { + return bcs.struct('PerTypeConfigCreated', { + key: ConfigKey(), + config_id: bcs.Address, + }); +} +export function PerTypeList() { + return bcs.struct('PerTypeList', { + id: object.UID(), + denied_count: table.Table(), + denied_addresses: table.Table(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts new file mode 100644 index 0000000..a74cc05 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts @@ -0,0 +1,26 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; +import * as vec_map from './vec_map.js'; + +export function Display() { + return bcs.struct('Display', { + id: object.UID(), + fields: vec_map.VecMap(bcs.string(), bcs.string()), + version: bcs.u16(), + }); +} +export function DisplayCreated() { + return bcs.struct('DisplayCreated', { + id: bcs.Address, + }); +} +export function VersionUpdated() { + return bcs.struct('VersionUpdated', { + id: bcs.Address, + version: bcs.u16(), + fields: vec_map.VecMap(bcs.string(), bcs.string()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts new file mode 100644 index 0000000..b811658 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts @@ -0,0 +1,16 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Field, T1 extends BcsType>( + ...typeParameters: [T0, T1] +) { + return bcs.struct('Field', { + id: object.UID(), + name: typeParameters[0], + value: typeParameters[1], + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts new file mode 100644 index 0000000..72a3c91 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts @@ -0,0 +1,10 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +export function Wrapper>(...typeParameters: [T0]) { + return bcs.struct('Wrapper', { + name: typeParameters[0], + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts new file mode 100644 index 0000000..98256d4 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts @@ -0,0 +1,27 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function Curve() { + return bcs.struct('Curve', { + id: bcs.u8(), + }); +} +export function PreparedVerifyingKey() { + return bcs.struct('PreparedVerifyingKey', { + vk_gamma_abc_g1_bytes: bcs.vector(bcs.u8()), + alpha_g1_beta_g2_bytes: bcs.vector(bcs.u8()), + gamma_g2_neg_pc_bytes: bcs.vector(bcs.u8()), + delta_g2_neg_pc_bytes: bcs.vector(bcs.u8()), + }); +} +export function PublicProofInputs() { + return bcs.struct('PublicProofInputs', { + bytes: bcs.vector(bcs.u8()), + }); +} +export function ProofPoints() { + return bcs.struct('ProofPoints', { + bytes: bcs.vector(bcs.u8()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts new file mode 100644 index 0000000..c55a196 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function Element() { + return bcs.struct('Element', { + bytes: bcs.vector(bcs.u8()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts new file mode 100644 index 0000000..bed6579 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts @@ -0,0 +1,72 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as balance from './balance.js'; +import * as object from './object.js'; + +export function Kiosk() { + return bcs.struct('Kiosk', { + id: object.UID(), + profits: balance.Balance(), + owner: bcs.Address, + item_count: bcs.u32(), + allow_extensions: bcs.bool(), + }); +} +export function KioskOwnerCap() { + return bcs.struct('KioskOwnerCap', { + id: object.UID(), + for: bcs.Address, + }); +} +export function PurchaseCap() { + return bcs.struct('PurchaseCap', { + id: object.UID(), + kiosk_id: bcs.Address, + item_id: bcs.Address, + min_price: bcs.u64(), + }); +} +export function Borrow() { + return bcs.struct('Borrow', { + kiosk_id: bcs.Address, + item_id: bcs.Address, + }); +} +export function Item() { + return bcs.struct('Item', { + id: bcs.Address, + }); +} +export function Listing() { + return bcs.struct('Listing', { + id: bcs.Address, + is_exclusive: bcs.bool(), + }); +} +export function Lock() { + return bcs.struct('Lock', { + id: bcs.Address, + }); +} +export function ItemListed() { + return bcs.struct('ItemListed', { + kiosk: bcs.Address, + id: bcs.Address, + price: bcs.u64(), + }); +} +export function ItemPurchased() { + return bcs.struct('ItemPurchased', { + kiosk: bcs.Address, + id: bcs.Address, + price: bcs.u64(), + }); +} +export function ItemDelisted() { + return bcs.struct('ItemDelisted', { + kiosk: bcs.Address, + id: bcs.Address, + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts new file mode 100644 index 0000000..f198fcb --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts @@ -0,0 +1,18 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as bag from './bag.js'; + +export function Extension() { + return bcs.struct('Extension', { + storage: bag.Bag(), + permissions: bcs.u128(), + is_enabled: bcs.bool(), + }); +} +export function ExtensionKey() { + return bcs.struct('ExtensionKey', { + dummy_field: bcs.bool(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts new file mode 100644 index 0000000..5e40f2f --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts @@ -0,0 +1,30 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function LinkedTable>(...typeParameters: [T0]) { + return bcs.struct('LinkedTable', { + id: object.UID(), + size: bcs.u64(), + head: bcs.option(typeParameters[0]), + tail: bcs.option(typeParameters[0]), + }); +} +export function Node, T1 extends BcsType>( + ...typeParameters: [T0, T1] +) { + return bcs.struct('Node', { + prev: bcs.option(typeParameters[0]), + next: bcs.option(typeParameters[0]), + _value: typeParameters[1], + get value() { + return this._value; + }, + set value(value) { + this._value = value; + }, + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts new file mode 100644 index 0000000..ace8451 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts @@ -0,0 +1,14 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function ID() { + return bcs.struct('ID', { + bytes: bcs.Address, + }); +} +export function UID() { + return bcs.struct('UID', { + id: bcs.Address, + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts new file mode 100644 index 0000000..4d7a56e --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function ObjectBag() { + return bcs.struct('ObjectBag', { + id: object.UID(), + size: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts new file mode 100644 index 0000000..4926668 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function ObjectTable() { + return bcs.struct('ObjectTable', { + id: object.UID(), + size: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts new file mode 100644 index 0000000..07b3290 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts @@ -0,0 +1,35 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Publisher() { + return bcs.struct('Publisher', { + id: object.UID(), + package: bcs.string(), + module_name: bcs.string(), + }); +} +export function UpgradeCap() { + return bcs.struct('UpgradeCap', { + id: object.UID(), + package: bcs.Address, + version: bcs.u64(), + policy: bcs.u8(), + }); +} +export function UpgradeTicket() { + return bcs.struct('UpgradeTicket', { + cap: bcs.Address, + package: bcs.Address, + policy: bcs.u8(), + digest: bcs.vector(bcs.u8()), + }); +} +export function UpgradeReceipt() { + return bcs.struct('UpgradeReceipt', { + cap: bcs.Address, + package: bcs.Address, + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts new file mode 100644 index 0000000..66d6cfb --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts @@ -0,0 +1,16 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +export function PriorityQueue>(...typeParameters: [T0]) { + return bcs.struct('PriorityQueue', { + entries: bcs.vector(Entry(typeParameters[0])), + }); +} +export function Entry>(...typeParameters: [T0]) { + return bcs.struct('Entry', { + priority: bcs.u64(), + value: typeParameters[0], + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts new file mode 100644 index 0000000..9d7b0e1 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts @@ -0,0 +1,28 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; +import * as versioned from './versioned.js'; + +export function Random() { + return bcs.struct('Random', { + id: object.UID(), + inner: versioned.Versioned(), + }); +} +export function RandomInner() { + return bcs.struct('RandomInner', { + version: bcs.u64(), + epoch: bcs.u64(), + randomness_round: bcs.u64(), + random_bytes: bcs.vector(bcs.u8()), + }); +} +export function RandomGenerator() { + return bcs.struct('RandomGenerator', { + seed: bcs.vector(bcs.u8()), + counter: bcs.u16(), + buffer: bcs.vector(bcs.u8()), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts new file mode 100644 index 0000000..922da4f --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function SUI() { + return bcs.struct('SUI', { + dummy_field: bcs.bool(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts new file mode 100644 index 0000000..4886ff5 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Table() { + return bcs.struct('Table', { + id: object.UID(), + size: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts new file mode 100644 index 0000000..c310eaf --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts @@ -0,0 +1,11 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as table from './table.js'; + +export function TableVec() { + return bcs.struct('TableVec', { + contents: table.Table(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts new file mode 100644 index 0000000..0edb732 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts @@ -0,0 +1,50 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as type_name from '../0000000000000000000000000000000000000000000000000000000000000001/type_name.js'; +import * as balance from './balance.js'; +import * as object from './object.js'; +import * as vec_map from './vec_map.js'; +import * as vec_set from './vec_set.js'; + +export function Token() { + return bcs.struct('Token', { + id: object.UID(), + balance: balance.Balance(), + }); +} +export function TokenPolicyCap() { + return bcs.struct('TokenPolicyCap', { + id: object.UID(), + for: bcs.Address, + }); +} +export function TokenPolicy() { + return bcs.struct('TokenPolicy', { + id: object.UID(), + spent_balance: balance.Balance(), + rules: vec_map.VecMap(bcs.string(), vec_set.VecSet(type_name.TypeName())), + }); +} +export function ActionRequest() { + return bcs.struct('ActionRequest', { + name: bcs.string(), + amount: bcs.u64(), + sender: bcs.Address, + recipient: bcs.option(bcs.Address), + spent_balance: bcs.option(balance.Balance()), + approvals: vec_set.VecSet(type_name.TypeName()), + }); +} +export function RuleKey() { + return bcs.struct('RuleKey', { + is_protected: bcs.bool(), + }); +} +export function TokenPolicyCreated() { + return bcs.struct('TokenPolicyCreated', { + id: bcs.Address, + is_mutable: bcs.bool(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts new file mode 100644 index 0000000..1f9dcf4 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts @@ -0,0 +1,10 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function Receiving() { + return bcs.struct('Receiving', { + id: bcs.Address, + version: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts new file mode 100644 index 0000000..1cf4637 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts @@ -0,0 +1,45 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as type_name from '../0000000000000000000000000000000000000000000000000000000000000001/type_name.js'; +import * as balance from './balance.js'; +import * as object from './object.js'; +import * as vec_set from './vec_set.js'; + +export function TransferRequest() { + return bcs.struct('TransferRequest', { + item: bcs.Address, + paid: bcs.u64(), + from: bcs.Address, + receipts: vec_set.VecSet(type_name.TypeName()), + }); +} +export function TransferPolicy() { + return bcs.struct('TransferPolicy', { + id: object.UID(), + balance: balance.Balance(), + rules: vec_set.VecSet(type_name.TypeName()), + }); +} +export function TransferPolicyCap() { + return bcs.struct('TransferPolicyCap', { + id: object.UID(), + policy_id: bcs.Address, + }); +} +export function TransferPolicyCreated() { + return bcs.struct('TransferPolicyCreated', { + id: bcs.Address, + }); +} +export function TransferPolicyDestroyed() { + return bcs.struct('TransferPolicyDestroyed', { + id: bcs.Address, + }); +} +export function RuleKey() { + return bcs.struct('RuleKey', { + dummy_field: bcs.bool(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts new file mode 100644 index 0000000..60cec52 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts @@ -0,0 +1,13 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function TxContext() { + return bcs.struct('TxContext', { + sender: bcs.Address, + tx_hash: bcs.vector(bcs.u8()), + epoch: bcs.u64(), + epoch_timestamp_ms: bcs.u64(), + ids_created: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts new file mode 100644 index 0000000..04fa1f2 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts @@ -0,0 +1,9 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +export function Url() { + return bcs.struct('Url', { + url: bcs.string(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts new file mode 100644 index 0000000..943ed5d --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts @@ -0,0 +1,20 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +export function VecMap, T1 extends BcsType>( + ...typeParameters: [T0, T1] +) { + return bcs.struct('VecMap', { + contents: bcs.vector(Entry(typeParameters[0], typeParameters[1])), + }); +} +export function Entry, T1 extends BcsType>( + ...typeParameters: [T0, T1] +) { + return bcs.struct('Entry', { + key: typeParameters[0], + value: typeParameters[1], + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts new file mode 100644 index 0000000..35c16c5 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts @@ -0,0 +1,10 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { BcsType } from '@mysten/sui/bcs'; + +export function VecSet>(...typeParameters: [T0]) { + return bcs.struct('VecSet', { + contents: bcs.vector(typeParameters[0]), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts new file mode 100644 index 0000000..3aab82a --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts @@ -0,0 +1,18 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function Versioned() { + return bcs.struct('Versioned', { + id: object.UID(), + version: bcs.u64(), + }); +} +export function VersionChangeCap() { + return bcs.struct('VersionChangeCap', { + versioned_id: bcs.Address, + old_version: bcs.u64(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts new file mode 100644 index 0000000..1c47d1f --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts @@ -0,0 +1,16 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function VerifiedID() { + return bcs.struct('VerifiedID', { + id: object.UID(), + owner: bcs.Address, + key_claim_name: bcs.string(), + key_claim_value: bcs.string(), + issuer: bcs.string(), + audience: bcs.string(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts new file mode 100644 index 0000000..b45b6e5 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts @@ -0,0 +1,13 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; + +import * as object from './object.js'; + +export function VerifiedIssuer() { + return bcs.struct('VerifiedIssuer', { + id: object.UID(), + owner: bcs.Address, + issuer: bcs.string(), + }); +} diff --git a/packages/walrus/src/contracts/utils/index.ts b/packages/walrus/src/contracts/utils/index.ts new file mode 100644 index 0000000..6c17816 --- /dev/null +++ b/packages/walrus/src/contracts/utils/index.ts @@ -0,0 +1,92 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import type { BcsType, TypeTag } from '@mysten/sui/bcs'; +import { bcs, TypeTagSerializer } from '@mysten/sui/bcs'; +import type { TransactionArgument } from '@mysten/sui/transactions'; +import { isArgument } from '@mysten/sui/transactions'; +import { normalizeSuiAddress } from '@mysten/sui/utils'; + +const MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1'); +const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2'); + +export type RawTransactionArgument = T | TransactionArgument; + +export function getPureBcsSchema(typeTag: string | TypeTag): BcsType | null { + const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag; + + if ('u8' in parsedTag) { + return bcs.U8; + } else if ('u16' in parsedTag) { + return bcs.U16; + } else if ('u32' in parsedTag) { + return bcs.U32; + } else if ('u64' in parsedTag) { + return bcs.U64; + } else if ('u128' in parsedTag) { + return bcs.U128; + } else if ('u256' in parsedTag) { + return bcs.U256; + } else if ('address' in parsedTag) { + return bcs.Address; + } else if ('bool' in parsedTag) { + return bcs.Bool; + } else if ('vector' in parsedTag) { + const type = getPureBcsSchema(parsedTag.vector); + return type ? bcs.vector(type) : null; + } else if ('struct' in parsedTag) { + const structTag = parsedTag.struct; + const pkg = normalizeSuiAddress(parsedTag.struct.address); + + if (pkg === MOVE_STDLIB_ADDRESS) { + if ( + (structTag.module === 'ascii' || structTag.module === 'string') && + structTag.name === 'String' + ) { + return bcs.String; + } + + if (structTag.module === 'option' && structTag.name === 'Option') { + const type = getPureBcsSchema(structTag.typeParams[0]); + return type ? bcs.vector(type) : null; + } + } + + if (pkg === SUI_FRAMEWORK_ADDRESS && structTag.module === 'Object' && structTag.name === 'ID') { + return bcs.Address; + } + } + + return null; +} + +export function normalizeMoveArguments(args: unknown[], argTypes: string[]) { + if (args.length !== argTypes.length) { + throw new Error(`Invalid number of arguments, expected ${argTypes.length}, got ${args.length}`); + } + + const normalizedArgs: TransactionArgument[] = []; + + for (const [i, arg] of args.entries()) { + if (typeof arg === 'function' || isArgument(arg)) { + normalizedArgs.push(arg as TransactionArgument); + continue; + } + + const type = argTypes[i]; + const bcsType = getPureBcsSchema(type); + + if (bcsType) { + const bytes = bcsType.serialize(arg as never); + normalizedArgs.push((tx) => tx.pure(bytes)); + continue; + } else if (typeof arg === 'string') { + normalizedArgs.push((tx) => tx.object(arg)); + continue; + } + + throw new Error(`Invalid argument ${JSON.stringify(arg)} for type ${type}`); + } + + return normalizedArgs; +} diff --git a/packages/walrus/src/contracts/wal/wal.ts b/packages/walrus/src/contracts/wal/wal.ts new file mode 100644 index 0000000..ed1da28 --- /dev/null +++ b/packages/walrus/src/contracts/wal/wal.ts @@ -0,0 +1,28 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import { normalizeMoveArguments } from '../utils/index.js'; +import type { RawTransactionArgument } from '../utils/index.js'; + +export function WAL() { + return bcs.struct('WAL', { + dummy_field: bcs.bool(), + }); +} +export function init(packageAddress: string) { + function init(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal::WAL', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal', + function: 'init', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { init }; +} diff --git a/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts b/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts new file mode 100644 index 0000000..25ab05e --- /dev/null +++ b/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts @@ -0,0 +1,325 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as balance from '../deps/0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import type { RawTransactionArgument } from '../utils/index.js'; + +export function Exchange() { + return bcs.struct('Exchange', { + id: object.UID(), + wal: balance.Balance(), + sui: balance.Balance(), + rate: ExchangeRate(), + admin: bcs.Address, + }); +} +export function AdminCap() { + return bcs.struct('AdminCap', { + id: object.UID(), + }); +} +export function ExchangeRate() { + return bcs.struct('ExchangeRate', { + wal: bcs.u64(), + sui: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function new_exchange_rate(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'new_exchange_rate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function wal_to_sui(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::ExchangeRate', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'wal_to_sui', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function sui_to_wal(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::ExchangeRate', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'sui_to_wal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + + function new_funded(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'new_funded', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function add_wal(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'add_wal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function add_sui(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'add_sui', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function add_all_wal(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'add_all_wal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function add_all_sui(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'add_all_sui', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function check_admin(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'check_admin', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_wal(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + 'u64', + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'withdraw_wal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_sui(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + 'u64', + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'withdraw_sui', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_exchange_rate(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + 'u64', + 'u64', + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'set_exchange_rate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function exchange_all_for_wal(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'exchange_all_for_wal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function exchange_for_wal(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'exchange_for_wal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function exchange_all_for_sui(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'exchange_all_for_sui', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function exchange_for_sui(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'exchange_for_sui', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + new_exchange_rate, + wal_to_sui, + sui_to_wal, + new_funded, + add_wal, + add_sui, + add_all_wal, + add_all_sui, + check_admin, + withdraw_wal, + withdraw_sui, + set_exchange_rate, + exchange_all_for_wal, + exchange_for_wal, + exchange_all_for_sui, + exchange_for_sui, + }; +} diff --git a/packages/walrus/src/contracts/walrus/active_set.ts b/packages/walrus/src/contracts/walrus/active_set.ts new file mode 100644 index 0000000..60c6b42 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/active_set.ts @@ -0,0 +1,183 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function ActiveSetEntry() { + return bcs.struct('ActiveSetEntry', { + node_id: bcs.Address, + staked_amount: bcs.u64(), + }); +} +export function ActiveSet() { + return bcs.struct('ActiveSet', { + max_size: bcs.u16(), + threshold_stake: bcs.u64(), + nodes: bcs.vector(ActiveSetEntry()), + total_stake: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function insert_or_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'insert_or_update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function insert(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'insert', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function remove(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'remove', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function max_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'max_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function active_ids(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'active_ids', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function active_ids_and_stake(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'active_ids_and_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function threshold_stake(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'threshold_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function total_stake(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'total_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + insert_or_update, + update, + insert, + remove, + max_size, + size, + active_ids, + active_ids_and_stake, + threshold_stake, + total_stake, + }; +} diff --git a/packages/walrus/src/contracts/walrus/blob.ts b/packages/walrus/src/contracts/walrus/blob.ts new file mode 100644 index 0000000..b56c2e6 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/blob.ts @@ -0,0 +1,338 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import * as storage_resource from './storage_resource.js'; + +export function Blob() { + return bcs.struct('Blob', { + id: object.UID(), + registered_epoch: bcs.u32(), + blob_id: bcs.u256(), + size: bcs.u64(), + encoding_type: bcs.u8(), + certified_epoch: bcs.option(bcs.u32()), + storage: storage_resource.Storage(), + deletable: bcs.bool(), + }); +} +export function BlobIdDerivation() { + return bcs.struct('BlobIdDerivation', { + encoding_type: bcs.u8(), + size: bcs.u64(), + root_hash: bcs.u256(), + }); +} +export function init(packageAddress: string) { + function registered_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'registered_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function encoding_type(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'encoding_type', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certified_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'certified_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'storage', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function encoded_size(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'encoded_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_mut(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'storage_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function end_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'end_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function assert_certified_not_expired(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'assert_certified_not_expired', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function derive_blob_id(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['u256', 'u8', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'derive_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + + function certify_with_certified_msg(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedBlobMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'certify_with_certified_msg', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + + function burn(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'burn', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend_with_resource(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'extend_with_resource', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_certified(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'bool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'emit_certified', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function add_metadata(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + '0000000000000000000000000000000000000000000000000000000000000000::metadata::Metadata', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'add_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function take_metadata(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'take_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function metadata(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function insert_or_update_metadata_pair(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'insert_or_update_metadata_pair', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function remove_metadata_pair(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'remove_metadata_pair', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + registered_epoch, + blob_id, + size, + encoding_type, + certified_epoch, + storage, + encoded_size, + storage_mut, + end_epoch, + assert_certified_not_expired, + derive_blob_id, + certify_with_certified_msg, + burn, + extend_with_resource, + emit_certified, + add_metadata, + take_metadata, + metadata, + insert_or_update_metadata_pair, + remove_metadata_pair, + }; +} diff --git a/packages/walrus/src/contracts/walrus/bls_aggregate.ts b/packages/walrus/src/contracts/walrus/bls_aggregate.ts new file mode 100644 index 0000000..0386f47 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/bls_aggregate.ts @@ -0,0 +1,242 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as group_ops from '../deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function BlsCommitteeMember() { + return bcs.struct('BlsCommitteeMember', { + public_key: group_ops.Element(), + weight: bcs.u16(), + node_id: bcs.Address, + }); +} +export function BlsCommittee() { + return bcs.struct('BlsCommittee', { + members: bcs.vector(BlsCommitteeMember()), + n_shards: bcs.u16(), + epoch: bcs.u32(), + }); +} +export function init(packageAddress: string) { + function new_bls_committee(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + 'u32', + 'vector<0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommitteeMember>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'new_bls_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function new_bls_committee_member(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::group_ops::Element<0000000000000000000000000000000000000000000000000000000000000002::bls12381::G1>', + 'u16', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'new_bls_committee_member', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function node_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommitteeMember', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'node_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function n_shards(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'n_shards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_idx(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'get_idx', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function contains(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'contains', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_member_weight(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'get_member_weight', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function find_index(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'find_index', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function to_vec_map(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'to_vec_map', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function verify_quorum_in_epoch(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'verify_quorum_in_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function verify_quorum(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'verify_quorum', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function verify_certificate(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'verify_certificate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + new_bls_committee, + new_bls_committee_member, + node_id, + epoch, + n_shards, + get_idx, + contains, + get_member_weight, + find_index, + to_vec_map, + verify_quorum_in_epoch, + verify_quorum, + verify_certificate, + }; +} diff --git a/packages/walrus/src/contracts/walrus/committee.ts b/packages/walrus/src/contracts/walrus/committee.ts new file mode 100644 index 0000000..56b6751 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/committee.ts @@ -0,0 +1,105 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as vec_map from '../deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function Committee() { + return bcs.struct('Committee', { + pos0: vec_map.VecMap(bcs.Address, bcs.vector(bcs.u16())), + }); +} +export function init(packageAddress: string) { + function empty(options: { arguments: [] }) { + const argumentsTypes: [] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function initialize(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0000000000000000000000000000000000000000000000000000000000000002::object::ID, u16>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'initialize', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function transition(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + '0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0000000000000000000000000000000000000000000000000000000000000002::object::ID, u16>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'transition', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function shards(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'shards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'inner', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function to_inner(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'to_inner', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { empty, initialize, transition, shards, size, inner, to_inner }; +} diff --git a/packages/walrus/src/contracts/walrus/encoding.ts b/packages/walrus/src/contracts/walrus/encoding.ts new file mode 100644 index 0000000..a7d87eb --- /dev/null +++ b/packages/walrus/src/contracts/walrus/encoding.ts @@ -0,0 +1,26 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function init(packageAddress: string) { + function encoded_blob_length(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['u64', 'u8', 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'encoding', + function: 'encoded_blob_length', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { encoded_blob_length }; +} diff --git a/packages/walrus/src/contracts/walrus/epoch_parameters.ts b/packages/walrus/src/contracts/walrus/epoch_parameters.ts new file mode 100644 index 0000000..67d32e8 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/epoch_parameters.ts @@ -0,0 +1,64 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function EpochParams() { + return bcs.struct('EpochParams', { + total_capacity_size: bcs.u64(), + storage_price_per_unit_size: bcs.u64(), + write_price_per_unit_size: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function capacity(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'epoch_parameters', + function: 'capacity', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_price(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'epoch_parameters', + function: 'storage_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function write_price(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'epoch_parameters', + function: 'write_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch_params_for_testing(options: { arguments: [] }) { + const argumentsTypes: [] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'epoch_parameters', + function: 'epoch_params_for_testing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { capacity, storage_price, write_price, epoch_params_for_testing }; +} diff --git a/packages/walrus/src/contracts/walrus/event_blob.ts b/packages/walrus/src/contracts/walrus/event_blob.ts new file mode 100644 index 0000000..37a392d --- /dev/null +++ b/packages/walrus/src/contracts/walrus/event_blob.ts @@ -0,0 +1,259 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import * as vec_map from '../deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function EventBlobAttestation() { + return bcs.struct('EventBlobAttestation', { + checkpoint_sequence_num: bcs.u64(), + epoch: bcs.u32(), + }); +} +export function EventBlob() { + return bcs.struct('EventBlob', { + blob_id: bcs.u256(), + ending_checkpoint_sequence_number: bcs.u64(), + }); +} +export function EventBlobCertificationState() { + return bcs.struct('EventBlobCertificationState', { + id: object.UID(), + latest_certified_blob: bcs.option(EventBlob()), + aggregate_weight_per_blob: vec_map.VecMap(bcs.u256(), bcs.u16()), + }); +} +export function init(packageAddress: string) { + function new_attestation(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'new_attestation', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function last_attested_event_blob_checkpoint_seq_num(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobAttestation', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'last_attested_event_blob_checkpoint_seq_num', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function last_attested_event_blob_epoch(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobAttestation', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'last_attested_event_blob_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function new_event_blob(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u256']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'new_event_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function ending_checkpoint_sequence_number(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'ending_checkpoint_sequence_number', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function create_with_empty_state(options: { arguments: [] }) { + const argumentsTypes: [] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'create_with_empty_state', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_latest_certified_blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'get_latest_certified_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_latest_certified_checkpoint_sequence_number(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'get_latest_certified_checkpoint_sequence_number', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_blob_already_certified(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'is_blob_already_certified', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function update_latest_certified_event_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + 'u64', + 'u256', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'update_latest_certified_event_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function update_aggregate_weight(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + 'u256', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'update_aggregate_weight', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function start_tracking_blob(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + 'u256', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'start_tracking_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function stop_tracking_blob(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + 'u256', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'stop_tracking_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function reset(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'reset', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + new_attestation, + last_attested_event_blob_checkpoint_seq_num, + last_attested_event_blob_epoch, + new_event_blob, + blob_id, + ending_checkpoint_sequence_number, + create_with_empty_state, + get_latest_certified_blob_id, + get_latest_certified_checkpoint_sequence_number, + is_blob_already_certified, + update_latest_certified_event_blob, + update_aggregate_weight, + start_tracking_blob, + stop_tracking_blob, + reset, + }; +} diff --git a/packages/walrus/src/contracts/walrus/events.ts b/packages/walrus/src/contracts/walrus/events.ts new file mode 100644 index 0000000..898263c --- /dev/null +++ b/packages/walrus/src/contracts/walrus/events.ts @@ -0,0 +1,230 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function BlobRegistered() { + return bcs.struct('BlobRegistered', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + size: bcs.u64(), + encoding_type: bcs.u8(), + end_epoch: bcs.u32(), + deletable: bcs.bool(), + object_id: bcs.Address, + }); +} +export function BlobCertified() { + return bcs.struct('BlobCertified', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + end_epoch: bcs.u32(), + deletable: bcs.bool(), + object_id: bcs.Address, + is_extension: bcs.bool(), + }); +} +export function BlobDeleted() { + return bcs.struct('BlobDeleted', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + end_epoch: bcs.u32(), + object_id: bcs.Address, + was_certified: bcs.bool(), + }); +} +export function InvalidBlobID() { + return bcs.struct('InvalidBlobID', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + }); +} +export function EpochChangeStart() { + return bcs.struct('EpochChangeStart', { + epoch: bcs.u32(), + }); +} +export function EpochChangeDone() { + return bcs.struct('EpochChangeDone', { + epoch: bcs.u32(), + }); +} +export function ShardsReceived() { + return bcs.struct('ShardsReceived', { + epoch: bcs.u32(), + shards: bcs.vector(bcs.u16()), + }); +} +export function EpochParametersSelected() { + return bcs.struct('EpochParametersSelected', { + next_epoch: bcs.u32(), + }); +} +export function ShardRecoveryStart() { + return bcs.struct('ShardRecoveryStart', { + epoch: bcs.u32(), + shards: bcs.vector(bcs.u16()), + }); +} +export function init(packageAddress: string) { + function emit_blob_registered(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'u256', + 'u64', + 'u8', + 'u32', + 'bool', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_blob_registered', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_blob_certified(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'u256', + 'u32', + 'bool', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'bool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_blob_certified', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_invalid_blob_id(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'u256']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_invalid_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_blob_deleted(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'u256', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'bool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_blob_deleted', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_epoch_change_start(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_epoch_change_start', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_epoch_change_done(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_epoch_change_done', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_shards_received(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'vector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_shards_received', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_epoch_parameters_selected(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = ['u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_epoch_parameters_selected', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_shard_recovery_start(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'vector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_shard_recovery_start', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + emit_blob_registered, + emit_blob_certified, + emit_invalid_blob_id, + emit_blob_deleted, + emit_epoch_change_start, + emit_epoch_change_done, + emit_shards_received, + emit_epoch_parameters_selected, + emit_shard_recovery_start, + }; +} diff --git a/packages/walrus/src/contracts/walrus/init.ts b/packages/walrus/src/contracts/walrus/init.ts new file mode 100644 index 0000000..c5a0100 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/init.ts @@ -0,0 +1,65 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function InitCap() { + return bcs.struct('InitCap', { + id: object.UID(), + }); +} +export function init(packageAddress: string) { + function init(options: { arguments: [] }) { + const argumentsTypes: [] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'init', + function: 'init', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function initialize_walrus(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::init::InitCap', + 'u64', + 'u64', + 'u16', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'init', + function: 'initialize_walrus', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function destroy(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::init::InitCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'init', + function: 'destroy', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { init, initialize_walrus, destroy }; +} diff --git a/packages/walrus/src/contracts/walrus/messages.ts b/packages/walrus/src/contracts/walrus/messages.ts new file mode 100644 index 0000000..26d942f --- /dev/null +++ b/packages/walrus/src/contracts/walrus/messages.ts @@ -0,0 +1,275 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function ProofOfPossessionMessage() { + return bcs.struct('ProofOfPossessionMessage', { + intent_type: bcs.u8(), + intent_version: bcs.u8(), + intent_app: bcs.u8(), + epoch: bcs.u32(), + sui_address: bcs.Address, + bls_key: bcs.vector(bcs.u8()), + }); +} +export function CertifiedMessage() { + return bcs.struct('CertifiedMessage', { + intent_type: bcs.u8(), + intent_version: bcs.u8(), + cert_epoch: bcs.u32(), + stake_support: bcs.u16(), + message: bcs.vector(bcs.u8()), + }); +} +export function CertifiedBlobMessage() { + return bcs.struct('CertifiedBlobMessage', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + }); +} +export function CertifiedInvalidBlobId() { + return bcs.struct('CertifiedInvalidBlobId', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + }); +} +export function init(packageAddress: string) { + function new_proof_of_possession_msg(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['u32', 'address', 'vector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'new_proof_of_possession_msg', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function to_bcs(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::ProofOfPossessionMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'to_bcs', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function verify_proof_of_possession(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::ProofOfPossessionMessage', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'verify_proof_of_possession', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function new_certified_message(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['vector', 'u32', 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'new_certified_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certify_blob_message(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'certify_blob_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certified_event_blob_message(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'u256']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'certified_event_blob_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function invalid_blob_id_message(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'invalid_blob_id_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function intent_type(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'intent_type', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function intent_version(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'intent_version', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function cert_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'cert_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function stake_support(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'stake_support', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function message(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function into_message(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'into_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certified_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedBlobMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'certified_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certified_blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedBlobMessage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'certified_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certified_invalid_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedInvalidBlobId', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'certified_invalid_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function invalid_blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedInvalidBlobId', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'invalid_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + new_proof_of_possession_msg, + to_bcs, + verify_proof_of_possession, + new_certified_message, + certify_blob_message, + certified_event_blob_message, + invalid_blob_id_message, + intent_type, + intent_version, + cert_epoch, + stake_support, + message, + into_message, + certified_epoch, + certified_blob_id, + certified_invalid_epoch, + invalid_blob_id, + }; +} diff --git a/packages/walrus/src/contracts/walrus/metadata.ts b/packages/walrus/src/contracts/walrus/metadata.ts new file mode 100644 index 0000000..4cf3b2e --- /dev/null +++ b/packages/walrus/src/contracts/walrus/metadata.ts @@ -0,0 +1,52 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as vec_map from '../deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function Metadata() { + return bcs.struct('Metadata', { + metadata: vec_map.VecMap(bcs.string(), bcs.string()), + }); +} +export function init(packageAddress: string) { + function insert_or_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::metadata::Metadata', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'metadata', + function: 'insert_or_update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function remove(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::metadata::Metadata', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'metadata', + function: 'remove', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { insert_or_update, remove }; +} diff --git a/packages/walrus/src/contracts/walrus/pending_values.ts b/packages/walrus/src/contracts/walrus/pending_values.ts new file mode 100644 index 0000000..f26b55e --- /dev/null +++ b/packages/walrus/src/contracts/walrus/pending_values.ts @@ -0,0 +1,121 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as vec_map from '../deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function PendingValues() { + return bcs.struct('PendingValues', { + pos0: vec_map.VecMap(bcs.u32(), bcs.u64()), + }); +} +export function init(packageAddress: string) { + function empty(options: { arguments: [] }) { + const argumentsTypes: [] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function insert_or_add(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + 'u32', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'insert_or_add', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function reduce(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + 'u32', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'reduce', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function value_at(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'value_at', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function flush(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'flush', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function unwrap(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'unwrap', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_empty(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'is_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { empty, insert_or_add, reduce, value_at, flush, unwrap, is_empty }; +} diff --git a/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts b/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts new file mode 100644 index 0000000..a6cee39 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts @@ -0,0 +1,58 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function PoolExchangeRate() { + return bcs.struct('PoolExchangeRate', { + wal_amount: bcs.u128(), + pool_token_amount: bcs.u128(), + }); +} +export function init(packageAddress: string) { + function empty(options: { arguments: [] }) { + const argumentsTypes: [] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + + function get_wal_amount(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pool_exchange_rate::PoolExchangeRate', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'get_wal_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_token_amount(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::pool_exchange_rate::PoolExchangeRate', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'get_token_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { empty, get_wal_amount, get_token_amount }; +} diff --git a/packages/walrus/src/contracts/walrus/redstuff.ts b/packages/walrus/src/contracts/walrus/redstuff.ts new file mode 100644 index 0000000..53c4fcb --- /dev/null +++ b/packages/walrus/src/contracts/walrus/redstuff.ts @@ -0,0 +1,103 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import type { Transaction } from '@mysten/sui/transactions'; + +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function init(packageAddress: string) { + function encoded_blob_length(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'encoded_blob_length', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function source_symbols_primary(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'source_symbols_primary', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function source_symbols_secondary(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'source_symbols_secondary', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function n_source_symbols(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'n_source_symbols', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function symbol_size(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'symbol_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function metadata_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'metadata_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function decoding_safety_limit(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'decoding_safety_limit', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function max_byzantine(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'redstuff', + function: 'max_byzantine', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + encoded_blob_length, + source_symbols_primary, + source_symbols_secondary, + n_source_symbols, + symbol_size, + metadata_size, + decoding_safety_limit, + max_byzantine, + }; +} diff --git a/packages/walrus/src/contracts/walrus/shared_blob.ts b/packages/walrus/src/contracts/walrus/shared_blob.ts new file mode 100644 index 0000000..119a660 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/shared_blob.ts @@ -0,0 +1,56 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as balance from '../deps/0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import * as blob from './blob.js'; + +export function SharedBlob() { + return bcs.struct('SharedBlob', { + id: object.UID(), + blob: blob.Blob(), + funds: balance.Balance(), + }); +} +export function init(packageAddress: string) { + function fund(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::shared_blob::SharedBlob', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'shared_blob', + function: 'fund', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::shared_blob::SharedBlob', + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'shared_blob', + function: 'extend', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { fund, extend }; +} diff --git a/packages/walrus/src/contracts/walrus/staked_wal.ts b/packages/walrus/src/contracts/walrus/staked_wal.ts new file mode 100644 index 0000000..ff6add3 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/staked_wal.ts @@ -0,0 +1,222 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as balance from '../deps/0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export type { BcsType } from '@mysten/sui/bcs'; + +export function StakedWal() { + return bcs.struct('StakedWal', { + id: object.UID(), + state: StakedWalState(), + node_id: bcs.Address, + principal: balance.Balance(), + activation_epoch: bcs.u32(), + }); +} +export function StakedWalState() { + return bcs.enum('StakedWalState', { + Staked: null, + Withdrawing: bcs.tuple([bcs.u32(), bcs.u64()]), + }); +} +export function init(packageAddress: string) { + function mint(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'mint', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function into_balance(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'into_balance', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_withdrawing(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + 'u32', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'set_withdrawing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function node_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'node_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function value(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'value', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function activation_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'activation_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_staked(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'is_staked', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_withdrawing(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'is_withdrawing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'withdraw_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function pool_token_amount(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'pool_token_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function join(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'join', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function split(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'split', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function destroy_zero(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'destroy_zero', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + mint, + into_balance, + set_withdrawing, + node_id, + value, + activation_epoch, + is_staked, + is_withdrawing, + withdraw_epoch, + pool_token_amount, + join, + split, + destroy_zero, + }; +} diff --git a/packages/walrus/src/contracts/walrus/staking.ts b/packages/walrus/src/contracts/walrus/staking.ts new file mode 100644 index 0000000..d47ec2f --- /dev/null +++ b/packages/walrus/src/contracts/walrus/staking.ts @@ -0,0 +1,441 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function Staking() { + return bcs.struct('Staking', { + id: object.UID(), + version: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function create(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u64', + 'u64', + 'u16', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'create', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function register_candidate(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + 'vector', + 'vector', + 'vector', + 'u64', + 'u64', + 'u64', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'register_candidate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_node(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'withdraw_node', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_commission(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_next_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function collect_commission(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'collect_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_storage_price_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_storage_price_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_write_price_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_write_price_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_node_capacity_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_node_capacity_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_public_key(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_next_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_name(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_name', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_address(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_network_address', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_public_key(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_network_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function voting_end(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'voting_end', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function initiate_epoch_change(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'initiate_epoch_change', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function shard_transfer_failed(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'shard_transfer_failed', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch_sync_done(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'epoch_sync_done', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function stake_with_pool(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'stake_with_pool', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function request_withdraw_stake(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'request_withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_stake(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner_mut(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'inner_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'inner', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + create, + register_candidate, + withdraw_node, + set_next_commission, + collect_commission, + set_storage_price_vote, + set_write_price_vote, + set_node_capacity_vote, + set_next_public_key, + set_name, + set_network_address, + set_network_public_key, + voting_end, + initiate_epoch_change, + shard_transfer_failed, + epoch_sync_done, + stake_with_pool, + request_withdraw_stake, + withdraw_stake, + inner_mut, + inner, + }; +} diff --git a/packages/walrus/src/contracts/walrus/staking_inner.ts b/packages/walrus/src/contracts/walrus/staking_inner.ts new file mode 100644 index 0000000..b9a1a16 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/staking_inner.ts @@ -0,0 +1,687 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as balance from '../deps/0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object_table from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.js'; +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import * as active_set from './active_set.js'; +import * as committee from './committee.js'; +import * as epoch_parameters from './epoch_parameters.js'; + +export function StakingInnerV1() { + return bcs.struct('StakingInnerV1', { + id: object.UID(), + n_shards: bcs.u16(), + epoch_duration: bcs.u64(), + first_epoch_start: bcs.u64(), + pools: object_table.ObjectTable(), + epoch: bcs.u32(), + active_set: active_set.ActiveSet(), + next_committee: bcs.option(committee.Committee()), + committee: committee.Committee(), + previous_committee: committee.Committee(), + next_epoch_params: bcs.option(epoch_parameters.EpochParams()), + epoch_state: EpochState(), + leftover_rewards: balance.Balance(), + }); +} +export function EpochState() { + return bcs.enum('EpochState', { + EpochChangeSync: bcs.u16(), + EpochChangeDone: bcs.u64(), + NextParamsSelected: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function create_pool(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + 'vector', + 'vector', + 'vector', + 'u64', + 'u64', + 'u64', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'create_pool', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_node(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'withdraw_node', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function collect_commission(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'collect_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function voting_end(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'voting_end', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function calculate_votes(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'calculate_votes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function quorum_above(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'quorum_above', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function quorum_below(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'quorum_below', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function take_threshold_value(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'take_threshold_value', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_commission(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_next_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_storage_price_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_storage_price_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_write_price_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_write_price_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_node_capacity_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_node_capacity_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_public_key(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_next_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_name(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_name', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_address(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_network_address', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_public_key(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_network_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_withdrawing(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_withdrawing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function destroy_empty_pool(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'destroy_empty_pool', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function stake_with_pool(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'stake_with_pool', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function request_withdraw_stake(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'request_withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_stake(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function select_committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'select_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function apportionment(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'apportionment', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function dhondt(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['vector', 'u16', 'vector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'dhondt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function initiate_epoch_change(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'initiate_epoch_change', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function advance_epoch(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'advance_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch_sync_done(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'epoch_sync_done', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function shard_transfer_failed(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'shard_transfer_failed', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function next_committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'next_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function next_epoch_params(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'next_epoch_params', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function previous_committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'previous_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function next_bls_committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'next_bls_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function has_pool(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'has_pool', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function new_walrus_context(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'new_walrus_context', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_quorum(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u16', 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'is_quorum', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + create_pool, + withdraw_node, + collect_commission, + voting_end, + calculate_votes, + quorum_above, + quorum_below, + take_threshold_value, + set_next_commission, + set_storage_price_vote, + set_write_price_vote, + set_node_capacity_vote, + set_next_public_key, + set_name, + set_network_address, + set_network_public_key, + set_withdrawing, + destroy_empty_pool, + stake_with_pool, + request_withdraw_stake, + withdraw_stake, + select_committee, + apportionment, + dhondt, + initiate_epoch_change, + advance_epoch, + epoch_sync_done, + shard_transfer_failed, + next_committee, + next_epoch_params, + epoch, + committee, + previous_committee, + next_bls_committee, + has_pool, + new_walrus_context, + is_quorum, + }; +} diff --git a/packages/walrus/src/contracts/walrus/staking_pool.ts b/packages/walrus/src/contracts/walrus/staking_pool.ts new file mode 100644 index 0000000..0eba538 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/staking_pool.ts @@ -0,0 +1,501 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as balance from '../deps/0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import * as table from '../deps/0000000000000000000000000000000000000000000000000000000000000002/table.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import * as pending_values from './pending_values.js'; +import * as storage_node from './storage_node.js'; + +export function VotingParams() { + return bcs.struct('VotingParams', { + storage_price: bcs.u64(), + write_price: bcs.u64(), + node_capacity: bcs.u64(), + }); +} +export function StakingPool() { + return bcs.struct('StakingPool', { + id: object.UID(), + state: PoolState(), + voting_params: VotingParams(), + node_info: storage_node.StorageNodeInfo(), + activation_epoch: bcs.u32(), + latest_epoch: bcs.u32(), + wal_balance: bcs.u64(), + pool_token_balance: bcs.u64(), + pending_pool_token_withdraw: pending_values.PendingValues(), + commission_rate: bcs.u64(), + exchange_rates: table.Table(), + pending_stake: pending_values.PendingValues(), + rewards_pool: balance.Balance(), + }); +} +export function PoolState() { + return bcs.enum('PoolState', { + New: null, + Active: null, + Withdrawing: bcs.u32(), + Withdrawn: null, + }); +} +export function init(packageAddress: string) { + function set_withdrawing(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_withdrawing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function stake(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function request_withdraw_stake(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'request_withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function withdraw_stake(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function advance_epoch(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'advance_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function process_pending_stake(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'process_pending_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_commission(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_next_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_storage_price(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_next_storage_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_write_price(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_next_write_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_node_capacity(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_next_node_capacity', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_public_key(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'vector', + 'vector', + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_next_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_name(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_name', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_address(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_network_address', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_public_key(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_network_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function destroy_empty(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'destroy_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function exchange_rate_at_epoch(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'exchange_rate_at_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function wal_balance_at_epoch(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'wal_balance_at_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function commission_rate(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'commission_rate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function rewards_amount(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'rewards_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function wal_balance(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'wal_balance', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_price(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'storage_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function write_price(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'write_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function node_capacity(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'node_capacity', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function activation_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'activation_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function node_info(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'node_info', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_new(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'is_new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_active(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'is_active', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_withdrawing(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'is_withdrawing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_empty(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'is_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + set_withdrawing, + stake, + request_withdraw_stake, + withdraw_stake, + advance_epoch, + process_pending_stake, + set_next_commission, + set_next_storage_price, + set_next_write_price, + set_next_node_capacity, + set_next_public_key, + set_name, + set_network_address, + set_network_public_key, + destroy_empty, + exchange_rate_at_epoch, + wal_balance_at_epoch, + commission_rate, + rewards_amount, + wal_balance, + storage_price, + write_price, + node_capacity, + activation_epoch, + node_info, + is_new, + is_active, + is_withdrawing, + is_empty, + }; +} diff --git a/packages/walrus/src/contracts/walrus/storage_accounting.ts b/packages/walrus/src/contracts/walrus/storage_accounting.ts new file mode 100644 index 0000000..58ca81a --- /dev/null +++ b/packages/walrus/src/contracts/walrus/storage_accounting.ts @@ -0,0 +1,200 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as balance from '../deps/0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function FutureAccounting() { + return bcs.struct('FutureAccounting', { + epoch: bcs.u32(), + storage_to_reclaim: bcs.u64(), + rewards_to_distribute: balance.Balance(), + }); +} +export function FutureAccountingRingBuffer() { + return bcs.struct('FutureAccountingRingBuffer', { + current_index: bcs.u32(), + length: bcs.u32(), + ring_buffer: bcs.vector(FutureAccounting()), + }); +} +export function init(packageAddress: string) { + function new_future_accounting(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'u64', + '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'new_future_accounting', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_to_reclaim(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'storage_to_reclaim', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function increase_storage_to_reclaim(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'increase_storage_to_reclaim', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function decrease_storage_to_reclaim(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'decrease_storage_to_reclaim', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function rewards_balance(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'rewards_balance', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function delete_empty_future_accounting(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'delete_empty_future_accounting', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function unwrap_balance(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'unwrap_balance', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function ring_new(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'ring_new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function ring_lookup_mut(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccountingRingBuffer', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'ring_lookup_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function ring_pop_expand(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccountingRingBuffer', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'ring_pop_expand', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function max_epochs_ahead(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccountingRingBuffer', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_accounting', + function: 'max_epochs_ahead', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + new_future_accounting, + epoch, + storage_to_reclaim, + increase_storage_to_reclaim, + decrease_storage_to_reclaim, + rewards_balance, + delete_empty_future_accounting, + unwrap_balance, + ring_new, + ring_lookup_mut, + ring_pop_expand, + max_epochs_ahead, + }; +} diff --git a/packages/walrus/src/contracts/walrus/storage_node.ts b/packages/walrus/src/contracts/walrus/storage_node.ts new file mode 100644 index 0000000..472ec1e --- /dev/null +++ b/packages/walrus/src/contracts/walrus/storage_node.ts @@ -0,0 +1,233 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as group_ops from '../deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.js'; +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import * as event_blob from './event_blob.js'; + +export function StorageNodeInfo() { + return bcs.struct('StorageNodeInfo', { + name: bcs.string(), + node_id: bcs.Address, + network_address: bcs.string(), + public_key: group_ops.Element(), + next_epoch_public_key: bcs.option(group_ops.Element()), + network_public_key: bcs.vector(bcs.u8()), + }); +} +export function StorageNodeCap() { + return bcs.struct('StorageNodeCap', { + id: object.UID(), + node_id: bcs.Address, + last_epoch_sync_done: bcs.u32(), + last_event_blob_attestation: bcs.option(event_blob.EventBlobAttestation()), + }); +} +export function init(packageAddress: string) { + function new_cap(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'new_cap', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function public_key(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function next_epoch_public_key(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'next_epoch_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function node_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'node_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function last_epoch_sync_done(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'last_epoch_sync_done', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function last_event_blob_attestation(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'last_event_blob_attestation', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_last_epoch_sync_done(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_last_epoch_sync_done', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_last_event_blob_attestation(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobAttestation', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_last_event_blob_attestation', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_public_key(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_next_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_name(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_name', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_address(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + '0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_network_address', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_network_public_key(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_network_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function rotate_public_key(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'rotate_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + new_cap, + public_key, + next_epoch_public_key, + id, + node_id, + last_epoch_sync_done, + last_event_blob_attestation, + set_last_epoch_sync_done, + set_last_event_blob_attestation, + set_next_public_key, + set_name, + set_network_address, + set_network_public_key, + rotate_public_key, + }; +} diff --git a/packages/walrus/src/contracts/walrus/storage_resource.ts b/packages/walrus/src/contracts/walrus/storage_resource.ts new file mode 100644 index 0000000..47def44 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/storage_resource.ts @@ -0,0 +1,186 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function Storage() { + return bcs.struct('Storage', { + id: object.UID(), + start_epoch: bcs.u32(), + end_epoch: bcs.u32(), + storage_size: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function start_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'start_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function end_epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'end_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'storage_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function create_storage(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['u32', 'u32', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'create_storage', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend_end_epoch(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'extend_end_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function split_by_epoch(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'split_by_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function split_by_size(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'split_by_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function fuse_periods(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'fuse_periods', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function fuse_amount(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'fuse_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function fuse(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'fuse', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function destroy(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_resource', + function: 'destroy', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + start_epoch, + end_epoch, + storage_size, + create_storage, + extend_end_epoch, + split_by_epoch, + split_by_size, + fuse_periods, + fuse_amount, + fuse, + destroy, + }; +} diff --git a/packages/walrus/src/contracts/walrus/system.ts b/packages/walrus/src/contracts/walrus/system.ts new file mode 100644 index 0000000..5a02edb --- /dev/null +++ b/packages/walrus/src/contracts/walrus/system.ts @@ -0,0 +1,335 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; + +export function System() { + return bcs.struct('System', { + id: object.UID(), + version: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function create_empty(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'create_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function invalidate_blob_id(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'invalidate_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certify_event_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u256', + 'u256', + 'u64', + 'u8', + 'u64', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'certify_event_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function reserve_space(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + 'u64', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'reserve_space', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function register_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + 'u256', + 'u256', + 'u64', + 'u8', + 'bool', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'register_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certify_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'certify_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function delete_blob(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'delete_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend_blob_with_resource(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'extend_blob_with_resource', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'extend_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function total_capacity_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'total_capacity_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function used_capacity_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'used_capacity_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function n_shards(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'n_shards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function advance_epoch(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'advance_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner_mut(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'inner_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system::System', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'inner', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + create_empty, + invalidate_blob_id, + certify_event_blob, + reserve_space, + register_blob, + certify_blob, + delete_blob, + extend_blob_with_resource, + extend_blob, + epoch, + total_capacity_size, + used_capacity_size, + n_shards, + committee, + advance_epoch, + inner_mut, + inner, + }; +} diff --git a/packages/walrus/src/contracts/walrus/system_state_inner.ts b/packages/walrus/src/contracts/walrus/system_state_inner.ts new file mode 100644 index 0000000..45f7882 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/system_state_inner.ts @@ -0,0 +1,393 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as object from '../deps/0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import type { RawTransactionArgument } from '../utils/index.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import * as bls_aggregate from './bls_aggregate.js'; +import * as event_blob from './event_blob.js'; +import * as storage_accounting from './storage_accounting.js'; + +export function SystemStateInnerV1() { + return bcs.struct('SystemStateInnerV1', { + id: object.UID(), + committee: bls_aggregate.BlsCommittee(), + total_capacity_size: bcs.u64(), + used_capacity_size: bcs.u64(), + storage_price_per_unit_size: bcs.u64(), + write_price_per_unit_size: bcs.u64(), + future_accounting: storage_accounting.FutureAccountingRingBuffer(), + event_blob_certification_state: event_blob.EventBlobCertificationState(), + }); +} +export function init(packageAddress: string) { + function create_empty(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'create_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function advance_epoch(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'advance_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function reserve_space(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + 'u64', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'reserve_space', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function reserve_space_without_payment(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + 'u64', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'reserve_space_without_payment', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function invalidate_blob_id(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'invalidate_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function register_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + 'u256', + 'u256', + 'u64', + 'u8', + 'bool', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'register_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certify_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'certify_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function delete_blob(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'delete_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend_blob_with_resource(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'extend_blob_with_resource', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extend_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'extend_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function process_storage_payments(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + 'u64', + 'u32', + 'u32', + '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'process_storage_payments', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certify_event_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + 'u256', + 'u256', + 'u64', + 'u8', + 'u64', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'certify_event_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function total_capacity_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'total_capacity_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function used_capacity_size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'used_capacity_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function n_shards(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'n_shards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function write_price(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'write_price', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_units_from_size(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = ['u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'storage_units_from_size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + create_empty, + advance_epoch, + reserve_space, + reserve_space_without_payment, + invalidate_blob_id, + register_blob, + certify_blob, + delete_blob, + extend_blob_with_resource, + extend_blob, + process_storage_payments, + certify_event_blob, + epoch, + total_capacity_size, + used_capacity_size, + committee, + n_shards, + write_price, + storage_units_from_size, + }; +} diff --git a/packages/walrus/src/contracts/walrus/walrus_context.ts b/packages/walrus/src/contracts/walrus/walrus_context.ts new file mode 100644 index 0000000..8a1bf02 --- /dev/null +++ b/packages/walrus/src/contracts/walrus/walrus_context.ts @@ -0,0 +1,56 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { bcs } from '@mysten/sui/bcs'; +import type { Transaction } from '@mysten/sui/transactions'; + +import * as vec_map from '../deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import { normalizeMoveArguments } from '../utils/index.js'; +import type { RawTransactionArgument } from '../utils/index.js'; + +export function WalrusContext() { + return bcs.struct('WalrusContext', { + epoch: bcs.u32(), + committee_selected: bcs.bool(), + committee: vec_map.VecMap(bcs.Address, bcs.vector(bcs.u16())), + }); +} +export function init(packageAddress: string) { + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'walrus_context', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function committee_selected(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'walrus_context', + function: 'committee_selected', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'walrus_context', + function: 'committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + + return { epoch, committee_selected, committee }; +} diff --git a/packages/walrus/src/index.ts b/packages/walrus/src/index.ts new file mode 100644 index 0000000..ce7832d --- /dev/null +++ b/packages/walrus/src/index.ts @@ -0,0 +1,4 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +export {}; diff --git a/packages/walrus/tsconfig.esm.json b/packages/walrus/tsconfig.esm.json new file mode 100644 index 0000000..5048bdf --- /dev/null +++ b/packages/walrus/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "dist/esm" + } +} diff --git a/packages/walrus/tsconfig.json b/packages/walrus/tsconfig.json new file mode 100644 index 0000000..ba15435 --- /dev/null +++ b/packages/walrus/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../build-scripts/tsconfig.shared.json", + "include": ["src"], + "compilerOptions": { + "module": "CommonJS", + "outDir": "dist/cjs", + "isolatedModules": true, + "rootDir": "src" + } + // "references": [{ "path": "../wallet-standard" }, { "path": "../typescript" }] +} diff --git a/packages/walrus/typedoc.json b/packages/walrus/typedoc.json new file mode 100644 index 0000000..ccb323f --- /dev/null +++ b/packages/walrus/typedoc.json @@ -0,0 +1,6 @@ +{ + "entryPoints": ["src"], + "excludeInternal": true, + "excludePrivate": true, + "intentionallyNotExported": [] +} diff --git a/packages/walrus/vitest.config.mts b/packages/walrus/vitest.config.mts new file mode 100644 index 0000000..bdc36a5 --- /dev/null +++ b/packages/walrus/vitest.config.mts @@ -0,0 +1,6 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { defineConfig } from 'vitest/config'; + +export default defineConfig({}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5eeeb4e..f68ff8f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -879,6 +879,28 @@ importers: specifier: ^0.65.1 version: 0.65.1(@swc/core@1.10.4(@swc/helpers@0.5.5)) + packages/walrus: + dependencies: + '@mysten/bcs': + specifier: workspace:* + version: link:../bcs + '@mysten/sui': + specifier: workspace:* + version: link:../typescript + devDependencies: + '@mysten/build-scripts': + specifier: workspace:* + version: link:../build-scripts + '@types/node': + specifier: ^22.10.5 + version: 22.10.5 + typescript: + specifier: ^5.7.2 + version: 5.7.2 + vitest: + specifier: ^2.1.8 + version: 2.1.8(@types/node@22.10.5)(happy-dom@16.3.0)(jsdom@25.0.1)(msw@2.7.0(@types/node@22.10.5)(typescript@5.7.2)) + packages/zksend: dependencies: '@mysten/sui': From b72958beb13c2578bda5af374fc208626b73e361 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Thu, 9 Jan 2025 16:47:42 -0800 Subject: [PATCH 2/6] make walrus sdk private until its ready to be published --- packages/walrus/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/walrus/package.json b/packages/walrus/package.json index 0a8aa42..73456ad 100644 --- a/packages/walrus/package.json +++ b/packages/walrus/package.json @@ -1,6 +1,7 @@ { "name": "@mysten/walrus", "version": "0.0.0", + "private": true, "description": "Walrus SDK", "license": "Apache-2.0", "author": "Mysten Labs ", From 539168a540867d6d0d7fa9e9a052101b4ef6f641 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Thu, 9 Jan 2025 17:01:02 -0800 Subject: [PATCH 3/6] Expose isArgument util from @mysten/sui/transactions --- .changeset/witty-ducks-poke.md | 5 +++++ packages/typescript/src/transactions/index.ts | 2 ++ packages/typescript/src/transactions/utils.ts | 7 +++++++ packages/walrus/src/contracts/utils/index.ts | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/witty-ducks-poke.md diff --git a/.changeset/witty-ducks-poke.md b/.changeset/witty-ducks-poke.md new file mode 100644 index 0000000..1e9ca34 --- /dev/null +++ b/.changeset/witty-ducks-poke.md @@ -0,0 +1,5 @@ +--- +'@mysten/sui': minor +--- + +expose isArgument util from @mysten/sui/transactions diff --git a/packages/typescript/src/transactions/index.ts b/packages/typescript/src/transactions/index.ts index 26699bd..cb4032e 100644 --- a/packages/typescript/src/transactions/index.ts +++ b/packages/typescript/src/transactions/index.ts @@ -54,3 +54,5 @@ export { } from './plugins/NamedPackagesPlugin.js'; export { type NamedPackagesPluginCache } from './plugins/utils.js'; + +export { isArgument } from './utils.js'; diff --git a/packages/typescript/src/transactions/utils.ts b/packages/typescript/src/transactions/utils.ts index 3f67dba..40681c0 100644 --- a/packages/typescript/src/transactions/utils.ts +++ b/packages/typescript/src/transactions/utils.ts @@ -1,8 +1,11 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { is } from 'valibot'; + import type { SuiMoveNormalizedType } from '../client/index.js'; import { normalizeSuiAddress } from '../utils/sui-types.js'; +import { Argument } from './data/internal.js'; import type { CallArg } from './data/internal.js'; export function extractMutableReference( @@ -64,3 +67,7 @@ export function getIdFromCallArg(arg: string | CallArg) { return undefined; } + +export function isArgument(value: unknown): value is Argument { + return is(Argument, value); +} diff --git a/packages/walrus/src/contracts/utils/index.ts b/packages/walrus/src/contracts/utils/index.ts index 6c17816..dade9ef 100644 --- a/packages/walrus/src/contracts/utils/index.ts +++ b/packages/walrus/src/contracts/utils/index.ts @@ -3,8 +3,8 @@ import type { BcsType, TypeTag } from '@mysten/sui/bcs'; import { bcs, TypeTagSerializer } from '@mysten/sui/bcs'; -import type { TransactionArgument } from '@mysten/sui/transactions'; import { isArgument } from '@mysten/sui/transactions'; +import type { TransactionArgument } from '@mysten/sui/transactions'; import { normalizeSuiAddress } from '@mysten/sui/utils'; const MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1'); From 215de4630ffc6784d67fea94b1888c1e6f1ce28a Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Fri, 10 Jan 2025 10:28:48 -0800 Subject: [PATCH 4/6] fix addresses --- packages/walrus/src/contracts/wal/wal.ts | 8 +- .../contracts/wal_exchange/wal_exchange.ts | 86 ++++---- .../walrus/src/contracts/walrus/active_set.ts | 54 ++--- packages/walrus/src/contracts/walrus/blob.ts | 117 ++++------- .../src/contracts/walrus/bls_aggregate.ts | 66 +++--- .../walrus/src/contracts/walrus/committee.ts | 32 ++- .../walrus/src/contracts/walrus/encoding.ts | 4 +- .../src/contracts/walrus/epoch_parameters.ts | 22 +- .../walrus/src/contracts/walrus/event_blob.ts | 70 +++---- .../walrus/src/contracts/walrus/events.ts | 20 +- packages/walrus/src/contracts/walrus/init.ts | 14 +- .../walrus/src/contracts/walrus/messages.ts | 90 +++----- .../walrus/src/contracts/walrus/metadata.ts | 10 +- .../src/contracts/walrus/pending_values.ts | 38 ++-- .../contracts/walrus/pool_exchange_rate.ts | 12 +- .../walrus/src/contracts/walrus/redstuff.ts | 18 +- .../src/contracts/walrus/shared_blob.ts | 14 +- .../walrus/src/contracts/walrus/staked_wal.ts | 81 +++----- .../walrus/src/contracts/walrus/staking.ts | 120 ++++++----- .../src/contracts/walrus/staking_inner.ts | 194 ++++++++---------- .../src/contracts/walrus/staking_pool.ts | 187 +++++++---------- .../contracts/walrus/storage_accounting.ts | 58 +++--- .../src/contracts/walrus/storage_node.ts | 75 +++---- .../src/contracts/walrus/storage_resource.ts | 67 +++--- .../walrus/src/contracts/walrus/system.ts | 106 +++++----- .../contracts/walrus/system_state_inner.ts | 110 +++++----- .../src/contracts/walrus/walrus_context.ts | 20 +- 27 files changed, 697 insertions(+), 996 deletions(-) diff --git a/packages/walrus/src/contracts/wal/wal.ts b/packages/walrus/src/contracts/wal/wal.ts index ed1da28..0eb19b9 100644 --- a/packages/walrus/src/contracts/wal/wal.ts +++ b/packages/walrus/src/contracts/wal/wal.ts @@ -11,14 +11,12 @@ export function WAL() { dummy_field: bcs.bool(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { wal: string }) { function init(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal::WAL', - ]; + const argumentsTypes = [`${packageAddresses.wal}::wal::WAL`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal, module: 'wal', function: 'init', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts b/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts index 25ab05e..7d8c3d5 100644 --- a/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts +++ b/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts @@ -28,14 +28,14 @@ export function ExchangeRate() { sui: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { wal: string; wal_exchange: string }) { function new_exchange_rate(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = ['u64', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'new_exchange_rate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -44,13 +44,10 @@ export function init(packageAddress: string) { function wal_to_sui(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::ExchangeRate', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.wal_exchange}::wal_exchange::ExchangeRate`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'wal_to_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -59,13 +56,10 @@ export function init(packageAddress: string) { function sui_to_wal(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::ExchangeRate', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.wal_exchange}::wal_exchange::ExchangeRate`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'sui_to_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -76,12 +70,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'new_funded', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -95,13 +89,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'add_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -115,13 +109,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'add_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -131,12 +125,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'add_all_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -146,12 +140,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'add_all_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -161,12 +155,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'check_admin', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -180,13 +174,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, 'u64', - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'withdraw_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -200,13 +194,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, 'u64', - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'withdraw_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -221,14 +215,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, 'u64', 'u64', - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::AdminCap', + `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'set_exchange_rate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -238,12 +232,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'exchange_all_for_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -257,13 +251,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'exchange_for_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -273,12 +267,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'exchange_all_for_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -292,13 +286,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::wal_exchange::Exchange', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.wal_exchange, module: 'wal_exchange', function: 'exchange_for_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/active_set.ts b/packages/walrus/src/contracts/walrus/active_set.ts index 60c6b42..d2ff29c 100644 --- a/packages/walrus/src/contracts/walrus/active_set.ts +++ b/packages/walrus/src/contracts/walrus/active_set.ts @@ -20,7 +20,7 @@ export function ActiveSet() { total_stake: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function insert_or_update(options: { arguments: [ RawTransactionArgument, @@ -29,13 +29,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + `${packageAddresses.walrus}::active_set::ActiveSet`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'insert_or_update', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -49,13 +49,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + `${packageAddresses.walrus}::active_set::ActiveSet`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'update', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -69,13 +69,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + `${packageAddresses.walrus}::active_set::ActiveSet`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'insert', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -85,84 +85,72 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', + `${packageAddresses.walrus}::active_set::ActiveSet`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'remove', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function max_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'max_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function active_ids(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'active_ids', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function active_ids_and_stake(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'active_ids_and_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function threshold_stake(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'threshold_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function total_stake(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::active_set::ActiveSet', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'active_set', function: 'total_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/blob.ts b/packages/walrus/src/contracts/walrus/blob.ts index b56c2e6..bedeb66 100644 --- a/packages/walrus/src/contracts/walrus/blob.ts +++ b/packages/walrus/src/contracts/walrus/blob.ts @@ -27,74 +27,62 @@ export function BlobIdDerivation() { root_hash: bcs.u256(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function registered_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'registered_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function encoding_type(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'encoding_type', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function certified_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'certified_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'storage', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -103,37 +91,30 @@ export function init(packageAddress: string) { function encoded_size(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - 'u16', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`, 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'encoded_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_mut(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'storage_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function end_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'end_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -142,13 +123,10 @@ export function init(packageAddress: string) { function assert_certified_not_expired(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'assert_certified_not_expired', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -164,7 +142,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u256', 'u8', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'derive_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -179,13 +157,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::blob::Blob`, 'u32', - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedBlobMessage', + `${packageAddresses.walrus}::messages::CertifiedBlobMessage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'certify_with_certified_msg', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -193,12 +171,10 @@ export function init(packageAddress: string) { } function burn(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'burn', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -212,13 +188,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::blob::Blob`, + `${packageAddresses.walrus}::storage_resource::Storage`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'extend_with_resource', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -227,13 +203,10 @@ export function init(packageAddress: string) { function emit_certified(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - 'bool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`, 'bool']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'emit_certified', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -243,36 +216,32 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - '0000000000000000000000000000000000000000000000000000000000000000::metadata::Metadata', + `${packageAddresses.walrus}::blob::Blob`, + `${packageAddresses.walrus}::metadata::Metadata`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'add_metadata', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function take_metadata(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'take_metadata', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function metadata(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'metadata', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -286,13 +255,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::blob::Blob`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'insert_or_update_metadata_pair', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -302,12 +271,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::blob::Blob`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'blob', function: 'remove_metadata_pair', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/bls_aggregate.ts b/packages/walrus/src/contracts/walrus/bls_aggregate.ts index 0386f47..d804800 100644 --- a/packages/walrus/src/contracts/walrus/bls_aggregate.ts +++ b/packages/walrus/src/contracts/walrus/bls_aggregate.ts @@ -21,17 +21,17 @@ export function BlsCommittee() { epoch: bcs.u32(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function new_bls_committee(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ 'u32', - 'vector<0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommitteeMember>', + `vector<${packageAddresses.walrus}::bls_aggregate::BlsCommitteeMember>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'new_bls_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -51,43 +51,37 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'new_bls_committee_member', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommitteeMember', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommitteeMember`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'node_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function n_shards(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'n_shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -96,13 +90,10 @@ export function init(packageAddress: string) { function get_idx(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'get_idx', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -112,12 +103,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'contains', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -127,12 +118,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'get_member_weight', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -142,24 +133,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'find_index', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function to_vec_map(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'to_vec_map', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -174,14 +163,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, 'vector', 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'verify_quorum_in_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -190,13 +179,10 @@ export function init(packageAddress: string) { function verify_quorum(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - 'u16', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'verify_quorum', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -211,14 +197,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, 'vector', 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'bls_aggregate', function: 'verify_certificate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/committee.ts b/packages/walrus/src/contracts/walrus/committee.ts index 56b6751..87cdd62 100644 --- a/packages/walrus/src/contracts/walrus/committee.ts +++ b/packages/walrus/src/contracts/walrus/committee.ts @@ -12,12 +12,12 @@ export function Committee() { pos0: vec_map.VecMap(bcs.Address, bcs.vector(bcs.u16())), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function empty(options: { arguments: [] }) { const argumentsTypes: [] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -29,7 +29,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'initialize', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -39,12 +39,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + `${packageAddresses.walrus}::committee::Committee`, '0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0000000000000000000000000000000000000000000000000000000000000002::object::ID, u16>', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'transition', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -54,48 +54,42 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', + `${packageAddresses.walrus}::committee::Committee`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::committee::Committee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::committee::Committee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'inner', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function to_inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::committee::Committee', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::committee::Committee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'committee', function: 'to_inner', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/encoding.ts b/packages/walrus/src/contracts/walrus/encoding.ts index a7d87eb..393628d 100644 --- a/packages/walrus/src/contracts/walrus/encoding.ts +++ b/packages/walrus/src/contracts/walrus/encoding.ts @@ -5,7 +5,7 @@ import type { Transaction } from '@mysten/sui/transactions'; import type { RawTransactionArgument } from '../utils/index.js'; import { normalizeMoveArguments } from '../utils/index.js'; -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function encoded_blob_length(options: { arguments: [ RawTransactionArgument, @@ -16,7 +16,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u64', 'u8', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'encoding', function: 'encoded_blob_length', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/epoch_parameters.ts b/packages/walrus/src/contracts/walrus/epoch_parameters.ts index 67d32e8..bad6456 100644 --- a/packages/walrus/src/contracts/walrus/epoch_parameters.ts +++ b/packages/walrus/src/contracts/walrus/epoch_parameters.ts @@ -13,38 +13,32 @@ export function EpochParams() { write_price_per_unit_size: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function capacity(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::epoch_parameters::EpochParams`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'epoch_parameters', function: 'capacity', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::epoch_parameters::EpochParams`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'epoch_parameters', function: 'storage_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function write_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::epoch_parameters::EpochParams`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'epoch_parameters', function: 'write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -54,7 +48,7 @@ export function init(packageAddress: string) { const argumentsTypes: [] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'epoch_parameters', function: 'epoch_params_for_testing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/event_blob.ts b/packages/walrus/src/contracts/walrus/event_blob.ts index 37a392d..0ded530 100644 --- a/packages/walrus/src/contracts/walrus/event_blob.ts +++ b/packages/walrus/src/contracts/walrus/event_blob.ts @@ -27,14 +27,14 @@ export function EventBlobCertificationState() { aggregate_weight_per_blob: vec_map.VecMap(bcs.u256(), bcs.u16()), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function new_attestation(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = ['u64', 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'new_attestation', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -43,12 +43,10 @@ export function init(packageAddress: string) { function last_attested_event_blob_checkpoint_seq_num(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobAttestation', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobAttestation`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'last_attested_event_blob_checkpoint_seq_num', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -57,12 +55,10 @@ export function init(packageAddress: string) { function last_attested_event_blob_epoch(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobAttestation', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobAttestation`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'last_attested_event_blob_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -74,19 +70,17 @@ export function init(packageAddress: string) { const argumentsTypes = ['u64', 'u256']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'new_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -95,12 +89,10 @@ export function init(packageAddress: string) { function ending_checkpoint_sequence_number(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlob', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'ending_checkpoint_sequence_number', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -110,19 +102,17 @@ export function init(packageAddress: string) { const argumentsTypes: [] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'create_with_empty_state', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function get_latest_certified_blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobCertificationState`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'get_latest_certified_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -131,12 +121,10 @@ export function init(packageAddress: string) { function get_latest_certified_checkpoint_sequence_number(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobCertificationState`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'get_latest_certified_checkpoint_sequence_number', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -146,12 +134,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'is_blob_already_certified', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -165,13 +153,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, 'u64', 'u256', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'update_latest_certified_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -185,13 +173,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, 'u256', 'u16', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'update_aggregate_weight', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -201,12 +189,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, 'u256', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'start_tracking_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -216,24 +204,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', + `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, 'u256', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'stop_tracking_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function reset(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobCertificationState', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobCertificationState`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'event_blob', function: 'reset', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/events.ts b/packages/walrus/src/contracts/walrus/events.ts index 898263c..1960bbc 100644 --- a/packages/walrus/src/contracts/walrus/events.ts +++ b/packages/walrus/src/contracts/walrus/events.ts @@ -69,7 +69,7 @@ export function ShardRecoveryStart() { shards: bcs.vector(bcs.u16()), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function emit_blob_registered(options: { arguments: [ RawTransactionArgument, @@ -92,7 +92,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_blob_registered', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -118,7 +118,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_blob_certified', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -130,7 +130,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32', 'u256']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_invalid_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -154,7 +154,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_blob_deleted', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -164,7 +164,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_epoch_change_start', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -174,7 +174,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_epoch_change_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -186,7 +186,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_shards_received', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -198,7 +198,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_epoch_parameters_selected', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -210,7 +210,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'events', function: 'emit_shard_recovery_start', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/init.ts b/packages/walrus/src/contracts/walrus/init.ts index c5a0100..b95962f 100644 --- a/packages/walrus/src/contracts/walrus/init.ts +++ b/packages/walrus/src/contracts/walrus/init.ts @@ -12,12 +12,12 @@ export function InitCap() { id: object.UID(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function init(options: { arguments: [] }) { const argumentsTypes: [] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'init', function: 'init', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -34,7 +34,7 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::init::InitCap', + `${packageAddresses.walrus}::init::InitCap`, 'u64', 'u64', 'u16', @@ -43,19 +43,17 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'init', function: 'initialize_walrus', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function destroy(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::init::InitCap', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::init::InitCap`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'init', function: 'destroy', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/messages.ts b/packages/walrus/src/contracts/walrus/messages.ts index 26d942f..0428077 100644 --- a/packages/walrus/src/contracts/walrus/messages.ts +++ b/packages/walrus/src/contracts/walrus/messages.ts @@ -37,7 +37,7 @@ export function CertifiedInvalidBlobId() { blob_id: bcs.u256(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function new_proof_of_possession_msg(options: { arguments: [ RawTransactionArgument, @@ -48,19 +48,17 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32', 'address', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'new_proof_of_possession_msg', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function to_bcs(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::ProofOfPossessionMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::ProofOfPossessionMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'to_bcs', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -70,12 +68,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::ProofOfPossessionMessage', + `${packageAddresses.walrus}::messages::ProofOfPossessionMessage`, 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'verify_proof_of_possession', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -91,19 +89,17 @@ export function init(packageAddress: string) { const argumentsTypes = ['vector', 'u32', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'new_certified_message', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function certify_blob_message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'certify_blob_message', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -115,139 +111,117 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32', 'u256']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'certified_event_blob_message', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function invalid_blob_id_message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'invalid_blob_id_message', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function intent_type(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'intent_type', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function intent_version(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'intent_version', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function cert_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'cert_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function stake_support(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'stake_support', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'message', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function into_message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'into_message', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function certified_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedBlobMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedBlobMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'certified_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function certified_blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedBlobMessage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedBlobMessage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'certified_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function certified_invalid_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedInvalidBlobId', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedInvalidBlobId`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'certified_invalid_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function invalid_blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::messages::CertifiedInvalidBlobId', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedInvalidBlobId`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'messages', function: 'invalid_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/metadata.ts b/packages/walrus/src/contracts/walrus/metadata.ts index 4cf3b2e..befa804 100644 --- a/packages/walrus/src/contracts/walrus/metadata.ts +++ b/packages/walrus/src/contracts/walrus/metadata.ts @@ -12,7 +12,7 @@ export function Metadata() { metadata: vec_map.VecMap(bcs.string(), bcs.string()), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function insert_or_update(options: { arguments: [ RawTransactionArgument, @@ -21,13 +21,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::metadata::Metadata', + `${packageAddresses.walrus}::metadata::Metadata`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'metadata', function: 'insert_or_update', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -37,12 +37,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::metadata::Metadata', + `${packageAddresses.walrus}::metadata::Metadata`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'metadata', function: 'remove', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/pending_values.ts b/packages/walrus/src/contracts/walrus/pending_values.ts index f26b55e..8a4b2ea 100644 --- a/packages/walrus/src/contracts/walrus/pending_values.ts +++ b/packages/walrus/src/contracts/walrus/pending_values.ts @@ -12,12 +12,12 @@ export function PendingValues() { pos0: vec_map.VecMap(bcs.u32(), bcs.u64()), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function empty(options: { arguments: [] }) { const argumentsTypes: [] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -31,13 +31,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + `${packageAddresses.walrus}::pending_values::PendingValues`, 'u32', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'insert_or_add', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -51,13 +51,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', + `${packageAddresses.walrus}::pending_values::PendingValues`, 'u32', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'reduce', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -66,13 +66,10 @@ export function init(packageAddress: string) { function value_at(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'value_at', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -81,37 +78,30 @@ export function init(packageAddress: string) { function flush(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'flush', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function unwrap(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'unwrap', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pending_values::PendingValues', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pending_values', function: 'is_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts b/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts index a6cee39..a6b1d4a 100644 --- a/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts +++ b/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts @@ -12,12 +12,12 @@ export function PoolExchangeRate() { pool_token_amount: bcs.u128(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function empty(options: { arguments: [] }) { const argumentsTypes: [] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pool_exchange_rate', function: 'empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -28,12 +28,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pool_exchange_rate::PoolExchangeRate', + `${packageAddresses.walrus}::pool_exchange_rate::PoolExchangeRate`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pool_exchange_rate', function: 'get_wal_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -43,12 +43,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::pool_exchange_rate::PoolExchangeRate', + `${packageAddresses.walrus}::pool_exchange_rate::PoolExchangeRate`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'pool_exchange_rate', function: 'get_token_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/redstuff.ts b/packages/walrus/src/contracts/walrus/redstuff.ts index 53c4fcb..452f414 100644 --- a/packages/walrus/src/contracts/walrus/redstuff.ts +++ b/packages/walrus/src/contracts/walrus/redstuff.ts @@ -5,14 +5,14 @@ import type { Transaction } from '@mysten/sui/transactions'; import type { RawTransactionArgument } from '../utils/index.js'; import { normalizeMoveArguments } from '../utils/index.js'; -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function encoded_blob_length(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = ['u64', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'encoded_blob_length', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -22,7 +22,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'source_symbols_primary', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -32,7 +32,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'source_symbols_secondary', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -42,7 +42,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'n_source_symbols', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -54,7 +54,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u64', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'symbol_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -64,7 +64,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'metadata_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -74,7 +74,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'decoding_safety_limit', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -84,7 +84,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'redstuff', function: 'max_byzantine', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/shared_blob.ts b/packages/walrus/src/contracts/walrus/shared_blob.ts index 119a660..14ea080 100644 --- a/packages/walrus/src/contracts/walrus/shared_blob.ts +++ b/packages/walrus/src/contracts/walrus/shared_blob.ts @@ -16,17 +16,17 @@ export function SharedBlob() { funds: balance.Balance(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function fund(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::shared_blob::SharedBlob', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.walrus}::shared_blob::SharedBlob`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'shared_blob', function: 'fund', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -40,13 +40,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::shared_blob::SharedBlob', - '0000000000000000000000000000000000000000000000000000000000000000::system::System', + `${packageAddresses.walrus}::shared_blob::SharedBlob`, + `${packageAddresses.walrus}::system::System`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'shared_blob', function: 'extend', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/staked_wal.ts b/packages/walrus/src/contracts/walrus/staked_wal.ts index ff6add3..073b54a 100644 --- a/packages/walrus/src/contracts/walrus/staked_wal.ts +++ b/packages/walrus/src/contracts/walrus/staked_wal.ts @@ -25,7 +25,7 @@ export function StakedWalState() { Withdrawing: bcs.tuple([bcs.u32(), bcs.u64()]), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function mint(options: { arguments: [ RawTransactionArgument, @@ -35,24 +35,22 @@ export function init(packageAddress: string) { }) { const argumentsTypes = [ '0000000000000000000000000000000000000000000000000000000000000002::object::ID', - '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'mint', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function into_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'into_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -65,98 +63,80 @@ export function init(packageAddress: string) { RawTransactionArgument, ]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - 'u32', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`, 'u32', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'set_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'node_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function value(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'value', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function activation_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'activation_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_staked(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'is_staked', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_withdrawing(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'is_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function withdraw_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'withdraw_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function pool_token_amount(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'pool_token_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -166,12 +146,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + `${packageAddresses.walrus}::staked_wal::StakedWal`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'join', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -180,25 +160,20 @@ export function init(packageAddress: string) { function split(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'split', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function destroy_zero(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staked_wal', function: 'destroy_zero', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/staking.ts b/packages/walrus/src/contracts/walrus/staking.ts index d47ec2f..29afe3e 100644 --- a/packages/walrus/src/contracts/walrus/staking.ts +++ b/packages/walrus/src/contracts/walrus/staking.ts @@ -13,7 +13,7 @@ export function Staking() { version: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function create(options: { arguments: [ RawTransactionArgument, @@ -30,7 +30,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'create', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -51,7 +51,7 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + `${packageAddresses.walrus}::staking::Staking`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', '0000000000000000000000000000000000000000000000000000000000000001::string::String', 'vector', @@ -64,7 +64,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'register_candidate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -74,12 +74,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'withdraw_node', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -93,13 +93,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_next_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -109,12 +109,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'collect_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -128,13 +128,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_storage_price_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -148,13 +148,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_write_price_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -168,13 +168,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_node_capacity_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -189,14 +189,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_next_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -210,13 +210,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_name', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -230,13 +230,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_network_address', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -250,13 +250,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'set_network_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -266,12 +266,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', + `${packageAddresses.walrus}::staking::Staking`, '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'voting_end', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -285,13 +285,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::system::System', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::system::System`, '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'initiate_epoch_change', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -306,14 +306,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'shard_transfer_failed', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -328,14 +328,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u32', '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'epoch_sync_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -349,13 +349,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.walrus}::staking::Staking`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'stake_with_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -365,12 +365,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'request_withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -380,36 +380,32 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + `${packageAddresses.walrus}::staking::Staking`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function inner_mut(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking::Staking`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'inner_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking::Staking', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking::Staking`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking', function: 'inner', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/staking_inner.ts b/packages/walrus/src/contracts/walrus/staking_inner.ts index b9a1a16..ab8469b 100644 --- a/packages/walrus/src/contracts/walrus/staking_inner.ts +++ b/packages/walrus/src/contracts/walrus/staking_inner.ts @@ -36,7 +36,7 @@ export function EpochState() { NextParamsSelected: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function create_pool(options: { arguments: [ RawTransactionArgument, @@ -52,7 +52,7 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', '0000000000000000000000000000000000000000000000000000000000000001::string::String', 'vector', @@ -65,7 +65,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'create_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -75,12 +75,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'withdraw_node', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -90,12 +90,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'collect_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -105,24 +105,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'voting_end', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function calculate_votes(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'calculate_votes', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -137,7 +135,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'quorum_above', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -152,7 +150,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'quorum_below', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -167,7 +165,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'take_threshold_value', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -181,13 +179,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_next_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -201,13 +199,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_storage_price_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -221,13 +219,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_write_price_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -241,13 +239,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_node_capacity_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -262,14 +260,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_next_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -283,13 +281,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_name', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -303,13 +301,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_network_address', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -323,13 +321,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_network_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -339,12 +337,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'set_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -354,12 +352,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'destroy_empty_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -373,13 +371,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'stake_with_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -389,12 +387,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'request_withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -404,36 +402,32 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function select_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'select_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function apportionment(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'apportionment', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -449,7 +443,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['vector', 'u16', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'dhondt', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -463,13 +457,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', - '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'initiate_epoch_change', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -479,12 +473,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -499,14 +493,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u32', '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'epoch_sync_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -521,86 +515,74 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'shard_transfer_failed', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function next_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'next_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function next_epoch_params(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'next_epoch_params', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function previous_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'previous_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function next_bls_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'next_bls_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -610,24 +592,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', + `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'has_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function new_walrus_context(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_inner::StakingInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'new_walrus_context', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -639,7 +619,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u16', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_inner', function: 'is_quorum', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/staking_pool.ts b/packages/walrus/src/contracts/walrus/staking_pool.ts index 0eba538..077fe84 100644 --- a/packages/walrus/src/contracts/walrus/staking_pool.ts +++ b/packages/walrus/src/contracts/walrus/staking_pool.ts @@ -43,17 +43,17 @@ export function PoolState() { Withdrawn: null, }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function set_withdrawing(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::staking_pool::StakingPool`, + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -67,13 +67,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::staking_pool::StakingPool`, + `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -87,13 +87,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::staking_pool::StakingPool`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'request_withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -107,13 +107,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - '0000000000000000000000000000000000000000000000000000000000000000::staked_wal::StakedWal', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::staking_pool::StakingPool`, + `${packageAddresses.walrus}::staked_wal::StakedWal`, + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -127,13 +127,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::staking_pool::StakingPool`, + `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -143,12 +143,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::staking_pool::StakingPool`, + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'process_pending_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -157,13 +157,10 @@ export function init(packageAddress: string) { function set_next_commission(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_next_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -172,13 +169,10 @@ export function init(packageAddress: string) { function set_next_storage_price(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_next_storage_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -187,13 +181,10 @@ export function init(packageAddress: string) { function set_next_write_price(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_next_write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -202,13 +193,10 @@ export function init(packageAddress: string) { function set_next_node_capacity(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_next_node_capacity', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -223,14 +211,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + `${packageAddresses.walrus}::staking_pool::StakingPool`, 'vector', 'vector', - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', + `${packageAddresses.walrus}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_next_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -240,12 +228,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + `${packageAddresses.walrus}::staking_pool::StakingPool`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_name', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -255,12 +243,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', + `${packageAddresses.walrus}::staking_pool::StakingPool`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_network_address', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -269,25 +257,20 @@ export function init(packageAddress: string) { function set_network_public_key(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'vector', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'set_network_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function destroy_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'destroy_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -296,13 +279,10 @@ export function init(packageAddress: string) { function exchange_rate_at_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'exchange_rate_at_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -311,157 +291,130 @@ export function init(packageAddress: string) { function wal_balance_at_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'wal_balance_at_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function commission_rate(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'commission_rate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function rewards_amount(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'rewards_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function wal_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'wal_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'storage_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function write_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_capacity(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'node_capacity', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function activation_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'activation_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_info(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'node_info', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_new(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'is_new', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_active(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'is_active', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_withdrawing(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'is_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::staking_pool::StakingPool', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'staking_pool', function: 'is_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/storage_accounting.ts b/packages/walrus/src/contracts/walrus/storage_accounting.ts index 58ca81a..ceb2fec 100644 --- a/packages/walrus/src/contracts/walrus/storage_accounting.ts +++ b/packages/walrus/src/contracts/walrus/storage_accounting.ts @@ -21,7 +21,7 @@ export function FutureAccountingRingBuffer() { ring_buffer: bcs.vector(FutureAccounting()), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function new_future_accounting(options: { arguments: [ RawTransactionArgument, @@ -32,35 +32,31 @@ export function init(packageAddress: string) { const argumentsTypes = [ 'u32', 'u64', - '0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'new_future_accounting', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_to_reclaim(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'storage_to_reclaim', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -70,12 +66,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + `${packageAddresses.walrus}::storage_accounting::FutureAccounting`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'increase_storage_to_reclaim', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -85,24 +81,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', + `${packageAddresses.walrus}::storage_accounting::FutureAccounting`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'decrease_storage_to_reclaim', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function rewards_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'rewards_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -111,24 +105,20 @@ export function init(packageAddress: string) { function delete_empty_future_accounting(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'delete_empty_future_accounting', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function unwrap_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccounting', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'unwrap_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -138,7 +128,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'ring_new', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -148,12 +138,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccountingRingBuffer', + `${packageAddresses.walrus}::storage_accounting::FutureAccountingRingBuffer`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'ring_lookup_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -161,11 +151,11 @@ export function init(packageAddress: string) { } function ring_pop_expand(options: { arguments: [RawTransactionArgument] }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccountingRingBuffer', + `${packageAddresses.walrus}::storage_accounting::FutureAccountingRingBuffer`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'ring_pop_expand', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -173,11 +163,11 @@ export function init(packageAddress: string) { } function max_epochs_ahead(options: { arguments: [RawTransactionArgument] }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_accounting::FutureAccountingRingBuffer', + `${packageAddresses.walrus}::storage_accounting::FutureAccountingRingBuffer`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_accounting', function: 'max_epochs_ahead', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/storage_node.ts b/packages/walrus/src/contracts/walrus/storage_node.ts index 472ec1e..1052f54 100644 --- a/packages/walrus/src/contracts/walrus/storage_node.ts +++ b/packages/walrus/src/contracts/walrus/storage_node.ts @@ -27,86 +27,74 @@ export function StorageNodeCap() { last_event_blob_attestation: bcs.option(event_blob.EventBlobAttestation()), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function new_cap(options: { arguments: [RawTransactionArgument] }) { const argumentsTypes = [ '0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'new_cap', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function public_key(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function next_epoch_public_key(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'next_epoch_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'node_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function last_epoch_sync_done(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'last_epoch_sync_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function last_event_blob_attestation(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'last_event_blob_attestation', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -115,13 +103,10 @@ export function init(packageAddress: string) { function set_last_epoch_sync_done(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'set_last_epoch_sync_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -131,12 +116,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', - '0000000000000000000000000000000000000000000000000000000000000000::event_blob::EventBlobAttestation', + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddresses.walrus}::event_blob::EventBlobAttestation`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'set_last_event_blob_attestation', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -146,12 +131,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'set_next_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -161,12 +146,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'set_name', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -176,12 +161,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, '0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'set_network_address', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -191,24 +176,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', + `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'set_network_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function rotate_public_key(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeInfo', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_node', function: 'rotate_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/storage_resource.ts b/packages/walrus/src/contracts/walrus/storage_resource.ts index 47def44..fd7b51f 100644 --- a/packages/walrus/src/contracts/walrus/storage_resource.ts +++ b/packages/walrus/src/contracts/walrus/storage_resource.ts @@ -15,38 +15,32 @@ export function Storage() { storage_size: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function start_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'start_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function end_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'end_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'storage_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -62,7 +56,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u32', 'u32', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'create_storage', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -71,13 +65,10 @@ export function init(packageAddress: string) { function extend_end_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'extend_end_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -86,13 +77,10 @@ export function init(packageAddress: string) { function split_by_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - 'u32', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'split_by_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -101,13 +89,10 @@ export function init(packageAddress: string) { function split_by_size(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - 'u64', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'split_by_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -117,12 +102,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddresses.walrus}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'fuse_periods', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -132,12 +117,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddresses.walrus}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'fuse_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -147,24 +132,22 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddresses.walrus}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'fuse', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function destroy(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'storage_resource', function: 'destroy', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/system.ts b/packages/walrus/src/contracts/walrus/system.ts index 5a02edb..375c788 100644 --- a/packages/walrus/src/contracts/walrus/system.ts +++ b/packages/walrus/src/contracts/walrus/system.ts @@ -13,12 +13,12 @@ export function System() { version: bcs.u64(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function create_empty(options: { arguments: [RawTransactionArgument] }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'create_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -33,14 +33,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', + `${packageAddresses.walrus}::system::System`, 'vector', 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'invalidate_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -59,8 +59,8 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u256', 'u256', 'u64', @@ -70,7 +70,7 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'certify_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -85,14 +85,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', + `${packageAddresses.walrus}::system::System`, 'u64', 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'reserve_space', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -111,18 +111,18 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::storage_resource::Storage`, 'u256', 'u256', 'u64', 'u8', 'bool', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'register_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -138,15 +138,15 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::blob::Blob`, 'vector', 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'certify_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -156,12 +156,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::blob::Blob`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'delete_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -175,13 +175,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::blob::Blob`, + `${packageAddresses.walrus}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'extend_blob_with_resource', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -196,74 +196,64 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::blob::Blob`, 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'extend_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function total_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'total_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function used_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'used_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function n_shards(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'n_shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -277,37 +267,33 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + `${packageAddresses.walrus}::system::System`, + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, + `${packageAddresses.walrus}::epoch_parameters::EpochParams`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function inner_mut(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'inner_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system::System', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system', function: 'inner', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/system_state_inner.ts b/packages/walrus/src/contracts/walrus/system_state_inner.ts index 45f7882..282dd88 100644 --- a/packages/walrus/src/contracts/walrus/system_state_inner.ts +++ b/packages/walrus/src/contracts/walrus/system_state_inner.ts @@ -22,12 +22,12 @@ export function SystemStateInnerV1() { event_blob_certification_state: event_blob.EventBlobCertificationState(), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string; wal: string }) { function create_empty(options: { arguments: [RawTransactionArgument] }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'create_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -41,13 +41,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::bls_aggregate::BlsCommittee', - '0000000000000000000000000000000000000000000000000000000000000000::epoch_parameters::EpochParams', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, + `${packageAddresses.walrus}::epoch_parameters::EpochParams`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -62,14 +62,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, 'u64', 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'reserve_space', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -83,13 +83,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, 'u64', 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'reserve_space_without_payment', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -104,14 +104,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, 'vector', 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'invalidate_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -130,18 +130,18 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::storage_resource::Storage`, 'u256', 'u256', 'u64', 'u8', 'bool', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'register_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -157,15 +157,15 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::blob::Blob`, 'vector', 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'certify_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -175,12 +175,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::blob::Blob`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'delete_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -194,13 +194,13 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', - '0000000000000000000000000000000000000000000000000000000000000000::storage_resource::Storage', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::blob::Blob`, + `${packageAddresses.walrus}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'extend_blob_with_resource', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -215,14 +215,14 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::blob::Blob', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::blob::Blob`, 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'extend_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -238,15 +238,15 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, 'u64', 'u32', 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000000::wal::WAL>', + `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'process_storage_payments', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -265,8 +265,8 @@ export function init(packageAddress: string) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - '0000000000000000000000000000000000000000000000000000000000000000::storage_node::StorageNodeCap', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u256', 'u256', 'u64', @@ -276,67 +276,57 @@ export function init(packageAddress: string) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'certify_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function total_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'total_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function used_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'used_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function n_shards(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'n_shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -346,12 +336,12 @@ export function init(packageAddress: string) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::system_state_inner::SystemStateInnerV1', + `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -363,7 +353,7 @@ export function init(packageAddress: string) { const argumentsTypes = ['u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'system_state_inner', function: 'storage_units_from_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/walrus/walrus_context.ts b/packages/walrus/src/contracts/walrus/walrus_context.ts index 8a1bf02..6ffa730 100644 --- a/packages/walrus/src/contracts/walrus/walrus_context.ts +++ b/packages/walrus/src/contracts/walrus/walrus_context.ts @@ -14,38 +14,32 @@ export function WalrusContext() { committee: vec_map.VecMap(bcs.Address, bcs.vector(bcs.u16())), }); } -export function init(packageAddress: string) { +export function init(packageAddresses: { walrus: string }) { function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::walrus_context::WalrusContext`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'walrus_context', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee_selected(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::walrus_context::WalrusContext`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'walrus_context', function: 'committee_selected', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000000::walrus_context::WalrusContext', - ]; + const argumentsTypes = [`${packageAddresses.walrus}::walrus_context::WalrusContext`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddress, + package: packageAddresses.walrus, module: 'walrus_context', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), From 4a9f8a0a370669e319f98e1518e365476663a491 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Fri, 10 Jan 2025 10:35:07 -0800 Subject: [PATCH 5/6] fix flaky build issue --- packages/build-scripts/src/utils/buildPackage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/build-scripts/src/utils/buildPackage.ts b/packages/build-scripts/src/utils/buildPackage.ts index 2e578dc..0a70140 100755 --- a/packages/build-scripts/src/utils/buildPackage.ts +++ b/packages/build-scripts/src/utils/buildPackage.ts @@ -171,7 +171,7 @@ async function buildImportDirectories({ exports, sideEffects }: PackageJSON) { async function createEmptyDir(path: string) { if (existsSync(path)) { - await fs.rm(path, { recursive: true }); + await fs.rm(path, { recursive: true, force: true }); } await fs.mkdir(path, { recursive: true }); From 0c56ebaac9a8d4aac4160a033af168038e627b65 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Fri, 10 Jan 2025 11:31:51 -0800 Subject: [PATCH 6/6] remove commented out reference in tsconfig --- packages/walrus/tsconfig.json | 1 - packages/zksend/tsconfig.json | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/walrus/tsconfig.json b/packages/walrus/tsconfig.json index ba15435..4453986 100644 --- a/packages/walrus/tsconfig.json +++ b/packages/walrus/tsconfig.json @@ -7,5 +7,4 @@ "isolatedModules": true, "rootDir": "src" } - // "references": [{ "path": "../wallet-standard" }, { "path": "../typescript" }] } diff --git a/packages/zksend/tsconfig.json b/packages/zksend/tsconfig.json index ba15435..4453986 100644 --- a/packages/zksend/tsconfig.json +++ b/packages/zksend/tsconfig.json @@ -7,5 +7,4 @@ "isolatedModules": true, "rootDir": "src" } - // "references": [{ "path": "../wallet-standard" }, { "path": "../typescript" }] }