diff --git a/packages/walrus/src/client.ts b/packages/walrus/src/client.ts index a7609b5..a3e5abf 100644 --- a/packages/walrus/src/client.ts +++ b/packages/walrus/src/client.ts @@ -4,11 +4,11 @@ import { SuiClient } from '@mysten/sui/client'; import { TESTNET_WALRUS_PACKAGE_CONFIG } from './constants.js'; -import { StakingInnerV1 } from './contracts/walrus/staking_inner.js'; -import { StakingPool } from './contracts/walrus/staking_pool.js'; -import { Staking } from './contracts/walrus/staking.js'; -import { SystemStateInnerV1 } from './contracts/walrus/system_state_inner.js'; -import { System } from './contracts/walrus/system.js'; +import { StakingInnerV1 } from './contracts/staking_inner.js'; +import { StakingPool } from './contracts/staking_pool.js'; +import { Staking } from './contracts/staking.js'; +import { SystemStateInnerV1 } from './contracts/system_state_inner.js'; +import { System } from './contracts/system.js'; import { BlobMetadataWithId, SliverData } from './utils/bcs.js'; import { getPrimarySourceSymbols, getShardIndicesByNodeId, toShardIndex } from './utils/index.js'; import { SuiObjectDataLoader } from './utils/object-loader.js'; diff --git a/packages/walrus/src/contracts/walrus/active_set.ts b/packages/walrus/src/contracts/active_set.ts similarity index 67% rename from packages/walrus/src/contracts/walrus/active_set.ts rename to packages/walrus/src/contracts/active_set.ts index d2ff29c..4c1906a 100644 --- a/packages/walrus/src/contracts/walrus/active_set.ts +++ b/packages/walrus/src/contracts/active_set.ts @@ -1,10 +1,11 @@ // 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'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function ActiveSetEntry() { return bcs.struct('ActiveSetEntry', { @@ -20,7 +21,19 @@ export function ActiveSet() { total_stake: bcs.u64(), }); } -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { + function _new(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u16', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'active_set', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function insert_or_update(options: { arguments: [ RawTransactionArgument, @@ -29,13 +42,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::active_set::ActiveSet`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::active_set::ActiveSet`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'insert_or_update', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -49,13 +62,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::active_set::ActiveSet`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::active_set::ActiveSet`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'update', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -69,13 +82,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::active_set::ActiveSet`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::active_set::ActiveSet`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'insert', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -85,78 +98,79 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::active_set::ActiveSet`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::active_set::ActiveSet`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'remove', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function max_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; + const argumentsTypes = [`${packageAddress}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'max_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; + const argumentsTypes = [`${packageAddress}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function active_ids(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; + const argumentsTypes = [`${packageAddress}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'active_ids', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function active_ids_and_stake(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; + const argumentsTypes = [`${packageAddress}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'active_ids_and_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function threshold_stake(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; + const argumentsTypes = [`${packageAddress}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'threshold_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function total_stake(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::active_set::ActiveSet`]; + const argumentsTypes = [`${packageAddress}::active_set::ActiveSet`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'active_set', function: 'total_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } return { + _new, insert_or_update, update, insert, diff --git a/packages/walrus/src/contracts/apportionment_queue.ts b/packages/walrus/src/contracts/apportionment_queue.ts new file mode 100644 index 0000000..23abf20 --- /dev/null +++ b/packages/walrus/src/contracts/apportionment_queue.ts @@ -0,0 +1,126 @@ +// 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 type { Transaction } from '@mysten/sui/transactions'; + +import * as uq64_64 from './deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq64_64.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function ApportionmentQueue>(...typeParameters: [T0]) { + return bcs.struct('ApportionmentQueue', { + entries: bcs.vector(Entry(typeParameters[0])), + }); +} +export function Entry>(...typeParameters: [T0]) { + return bcs.struct('Entry', { + priority: uq64_64.UQ64_64(), + tie_breaker: bcs.u64(), + value: typeParameters[0], + }); +} +export function init(packageAddress: string) { + function _new(options: { arguments: []; typeArguments: [string] }) { + const argumentsTypes: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'apportionment_queue', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function pop_max(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::apportionment_queue::ApportionmentQueue<${options.typeArguments[0]}>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'apportionment_queue', + function: 'pop_max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function insert>(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::apportionment_queue::ApportionmentQueue<${options.typeArguments[0]}>`, + '0x0000000000000000000000000000000000000000000000000000000000000001::uq64_64::UQ64_64', + 'u64', + `${options.typeArguments[0]}`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'apportionment_queue', + function: 'insert', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function bubble_down(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `vector<${packageAddress}::apportionment_queue::Entry<${options.typeArguments[0]}>>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'apportionment_queue', + function: 'bubble_down', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function bubble_up(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `vector<${packageAddress}::apportionment_queue::Entry<${options.typeArguments[0]}>>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'apportionment_queue', + function: 'bubble_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function higher_priority_than(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::apportionment_queue::Entry<${options.typeArguments[0]}>`, + `${packageAddress}::apportionment_queue::Entry<${options.typeArguments[0]}>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'apportionment_queue', + function: 'higher_priority_than', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + return { _new, pop_max, insert, bubble_down, bubble_up, higher_priority_than }; +} diff --git a/packages/walrus/src/contracts/auth.ts b/packages/walrus/src/contracts/auth.ts new file mode 100644 index 0000000..f6c0d94 --- /dev/null +++ b/packages/walrus/src/contracts/auth.ts @@ -0,0 +1,92 @@ +// 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 type { Transaction } from '@mysten/sui/transactions'; + +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function Authenticated() { + return bcs.enum('Authenticated', { + Sender: bcs.Address, + Object: bcs.Address, + }); +} +export function Authorized() { + return bcs.enum('Authorized', { + Address: bcs.Address, + ObjectID: bcs.Address, + }); +} +export function init(packageAddress: string) { + function authenticate_sender(options: { arguments: [] }) { + const argumentsTypes: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auth', + function: 'authenticate_sender', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function authenticate_with_object>(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [`${options.typeArguments[0]}`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auth', + function: 'authenticate_with_object', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function authorized_address(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = ['address']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auth', + function: 'authorized_address', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function authorized_object(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auth', + function: 'authorized_object', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function matches(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auth', + function: 'matches', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + authenticate_sender, + authenticate_with_object, + authorized_address, + authorized_object, + matches, + }; +} diff --git a/packages/walrus/src/contracts/walrus/blob.ts b/packages/walrus/src/contracts/blob.ts similarity index 65% rename from packages/walrus/src/contracts/walrus/blob.ts rename to packages/walrus/src/contracts/blob.ts index bedeb66..aa9857d 100644 --- a/packages/walrus/src/contracts/walrus/blob.ts +++ b/packages/walrus/src/contracts/blob.ts @@ -1,12 +1,13 @@ // 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 object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; import * as storage_resource from './storage_resource.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function Blob() { return bcs.struct('Blob', { @@ -27,62 +28,72 @@ export function BlobIdDerivation() { root_hash: bcs.u256(), }); } -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { + function object_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::blob::Blob`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'object_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function registered_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'registered_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function encoding_type(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'encoding_type', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function certified_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'certified_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'storage', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -91,30 +102,30 @@ export function init(packageAddresses: { walrus: string }) { function encoded_size(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`, 'u16']; + const argumentsTypes = [`${packageAddress}::blob::Blob`, 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'encoded_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_mut(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'storage_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function end_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'end_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -123,10 +134,10 @@ export function init(packageAddresses: { walrus: string }) { function assert_certified_not_expired(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`, 'u32']; + const argumentsTypes = [`${packageAddress}::blob::Blob`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'assert_certified_not_expired', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -142,13 +153,42 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u256', 'u8', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'derive_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - + function _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::storage_resource::Storage`, + 'u256', + 'u256', + 'u64', + 'u8', + 'bool', + 'u32', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function certify_with_certified_msg(options: { arguments: [ RawTransactionArgument, @@ -157,24 +197,35 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::blob::Blob`, + `${packageAddress}::blob::Blob`, 'u32', - `${packageAddresses.walrus}::messages::CertifiedBlobMessage`, + `${packageAddress}::messages::CertifiedBlobMessage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'certify_with_certified_msg', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - + function _delete(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::blob::Blob`, 'u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'blob', + function: 'delete', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function burn(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'burn', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -188,13 +239,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::blob::Blob`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::blob::Blob`, + `${packageAddress}::storage_resource::Storage`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'extend_with_resource', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -203,10 +254,10 @@ export function init(packageAddresses: { walrus: string }) { function emit_certified(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`, 'bool']; + const argumentsTypes = [`${packageAddress}::blob::Blob`, 'bool']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'emit_certified', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -216,32 +267,32 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::blob::Blob`, - `${packageAddresses.walrus}::metadata::Metadata`, + `${packageAddress}::blob::Blob`, + `${packageAddress}::metadata::Metadata`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'add_metadata', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function take_metadata(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'take_metadata', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function metadata(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::blob::Blob`]; + const argumentsTypes = [`${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'metadata', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -255,13 +306,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::blob::Blob`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::blob::Blob`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'insert_or_update_metadata_pair', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -271,18 +322,19 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::blob::Blob`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::blob::Blob`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'blob', function: 'remove_metadata_pair', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } return { + object_id, registered_epoch, blob_id, size, @@ -294,7 +346,9 @@ export function init(packageAddresses: { walrus: string }) { end_epoch, assert_certified_not_expired, derive_blob_id, + _new, certify_with_certified_msg, + _delete, burn, extend_with_resource, emit_certified, diff --git a/packages/walrus/src/contracts/walrus/bls_aggregate.ts b/packages/walrus/src/contracts/bls_aggregate.ts similarity index 55% rename from packages/walrus/src/contracts/walrus/bls_aggregate.ts rename to packages/walrus/src/contracts/bls_aggregate.ts index d804800..5f56471 100644 --- a/packages/walrus/src/contracts/walrus/bls_aggregate.ts +++ b/packages/walrus/src/contracts/bls_aggregate.ts @@ -1,11 +1,12 @@ // 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'; +import * as group_ops from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/group_ops.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function BlsCommitteeMember() { return bcs.struct('BlsCommitteeMember', { @@ -19,19 +20,23 @@ export function BlsCommittee() { members: bcs.vector(BlsCommitteeMember()), n_shards: bcs.u16(), epoch: bcs.u32(), + total_aggregated_key: group_ops.Element(), + }); +} +export function RequiredWeight() { + return bcs.enum('RequiredWeight', { + Quorum: null, + OneCorrectNode: null, }); } -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { function new_bls_committee(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - 'u32', - `vector<${packageAddresses.walrus}::bls_aggregate::BlsCommitteeMember>`, - ]; + const argumentsTypes = ['u32', `vector<${packageAddress}::bls_aggregate::BlsCommitteeMember>`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'new_bls_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -45,55 +50,65 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::group_ops::Element<0000000000000000000000000000000000000000000000000000000000000002::bls12381::G1>', + '0x0000000000000000000000000000000000000000000000000000000000000002::group_ops::Element<0x0000000000000000000000000000000000000000000000000000000000000002::bls12381::UncompressedG1>', 'u16', - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'new_bls_committee_member', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommitteeMember`]; + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommitteeMember`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'node_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`]; + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function n_shards(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`]; + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'n_shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function n_members(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'n_members', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function get_idx(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, 'u64']; + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'get_idx', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -103,12 +118,12 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::bls_aggregate::BlsCommittee`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'contains', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -118,12 +133,12 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::bls_aggregate::BlsCommittee`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'get_member_weight', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -133,22 +148,22 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::bls_aggregate::BlsCommittee`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'find_index', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function to_vec_map(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`]; + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'to_vec_map', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -163,50 +178,86 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, + `${packageAddress}::bls_aggregate::BlsCommittee`, + 'vector', 'vector', - 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', function: 'verify_quorum_in_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function verify_quorum(options: { + function is_quorum(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`, 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'is_quorum', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function verify_one_correct_node_in_epoch(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::bls_aggregate::BlsCommittee`, + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bls_aggregate', + function: 'verify_one_correct_node_in_epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function includes_one_correct_node(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, 'u16']; + const argumentsTypes = [`${packageAddress}::bls_aggregate::BlsCommittee`, 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', - function: 'verify_quorum', + function: 'includes_one_correct_node', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function verify_certificate(options: { + function verify_certificate_and_weight(options: { arguments: [ RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, + RawTransactionArgument, ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, + `${packageAddress}::bls_aggregate::BlsCommittee`, + 'vector', 'vector', - 'vector', 'vector', + `${packageAddress}::bls_aggregate::RequiredWeight`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'bls_aggregate', - function: 'verify_certificate', + function: 'verify_certificate_and_weight', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } @@ -216,13 +267,16 @@ export function init(packageAddresses: { walrus: string }) { node_id, epoch, n_shards, + n_members, get_idx, contains, get_member_weight, find_index, to_vec_map, verify_quorum_in_epoch, - verify_quorum, - verify_certificate, + is_quorum, + verify_one_correct_node_in_epoch, + includes_one_correct_node, + verify_certificate_and_weight, }; } diff --git a/packages/walrus/src/contracts/committee.ts b/packages/walrus/src/contracts/committee.ts new file mode 100644 index 0000000..be90cf3 --- /dev/null +++ b/packages/walrus/src/contracts/committee.ts @@ -0,0 +1,130 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } 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: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function contains(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::committee::Committee`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'contains', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function initialize(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::committee::Committee`, + '0x0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::committee::Committee`, + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::committee::Committee`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'to_inner', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function diff(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::committee::Committee`, + `${packageAddress}::committee::Committee`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'committee', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { empty, contains, initialize, transition, shards, size, inner, to_inner, diff }; +} diff --git a/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000000/wal.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000000/wal.ts new file mode 100644 index 0000000..790a3b9 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000000/wal.ts @@ -0,0 +1,10 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { bcs } from '@mysten/sui/bcs'; + +export function WAL() { + return bcs.struct('WAL', { + dummy_field: bcs.bool(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000000/wal_exchange.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000000/wal_exchange.ts new file mode 100644 index 0000000..a678ef0 --- /dev/null +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000000/wal_exchange.ts @@ -0,0 +1,28 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { bcs } from '@mysten/sui/bcs'; + +import * as balance from '../0x0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from '../0x0000000000000000000000000000000000000000000000000000000000000002/object.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(), + }); +} diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/ascii.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/ascii.ts similarity index 100% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/ascii.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/ascii.ts diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts similarity index 100% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/bit_vector.ts diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts similarity index 100% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/fixed_point32.ts diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/option.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/option.ts index 86002a3..cc146a6 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/option.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/option.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/string.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/string.ts index 9544a33..a2bf323 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/string.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/string.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function String() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts index a777803..a08d335 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/type_name.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/type_name.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function TypeName() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts index 8c2aab8..a8833eb 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq32_32.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function UQ32_32() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts index 9587bd5..67b535d 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000001/uq64_64.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function UQ64_64() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts index 51c9678..37392e5 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/authenticator_state.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bag.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bag.ts index e6e7337..25b81cb 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bag.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bag.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts index 11963a9..1a3df4d 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/balance.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function Supply() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bcs.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bcs.ts index 281c5aa..95a9a25 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bcs.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bcs.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function BCS() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts index c113e4e..256e5b1 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/bls12381.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function Scalar() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/borrow.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/borrow.ts index 7ee2df0..a9fed2f 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/borrow.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/borrow.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/clock.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/clock.ts index 3735c90..d928dc0 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/clock.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/clock.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/coin.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/coin.ts index 618dbf1..eb48f73 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/coin.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/coin.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as balance from './balance.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/config.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/config.ts index e3350bc..98cf0f3 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/config.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/config.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts index 3fa131e..5f2c8e1 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/deny_list.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as bag from './bag.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/display.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/display.ts index a74cc05..e5e711c 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/display.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/display.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts index b811658..46d3fbb 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/dynamic_field.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts index 72a3c91..55794cd 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/dynamic_object_field.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/groth16.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/groth16.ts index 98256d4..61d6a5d 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/groth16.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/groth16.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function Curve() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts index c55a196..ce7bc2a 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/group_ops.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function Element() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts index bed6579..e25a301 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/kiosk.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as balance from './balance.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts index f198fcb..3ab4b99 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/kiosk_extension.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as bag from './bag.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts similarity index 84% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts index 5e40f2f..b5faef5 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/linked_table.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; @@ -19,12 +20,6 @@ export function Node, T1 extends BcsType>( 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; - }, + value: typeParameters[1], }); } diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.ts index ace8451..2b86485 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function ID() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts index 4d7a56e..b60e7df 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_bag.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_table.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_table.ts index 4926668..11ccd1e 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/object_table.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_table.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts index 07b3290..f2b7a10 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/package.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts index 66d6cfb..8a3ec08 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/priority_queue.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/random.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/random.ts index 9d7b0e1..380264f 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/random.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/random.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/sui.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/sui.ts index 922da4f..5339b7b 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/sui.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/sui.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function SUI() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts index 4886ff5..dfca1d8 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts index c310eaf..239a4e4 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/table_vec.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as table from './table.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/token.ts similarity index 91% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/token.ts index 0edb732..45e0396 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/token.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/token.ts @@ -1,8 +1,9 @@ // 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 type_name from '../0x0000000000000000000000000000000000000000000000000000000000000001/type_name.js'; import * as balance from './balance.js'; import * as object from './object.js'; import * as vec_map from './vec_map.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/transfer.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/transfer.ts index 1f9dcf4..32ac50d 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/transfer.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function Receiving() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts similarity index 90% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts index 1cf4637..75a9d86 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/transfer_policy.ts @@ -1,8 +1,9 @@ // 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 type_name from '../0x0000000000000000000000000000000000000000000000000000000000000001/type_name.js'; import * as balance from './balance.js'; import * as object from './object.js'; import * as vec_set from './vec_set.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts index 60cec52..730a20f 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/tx_context.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function TxContext() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/url.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/url.ts index 04fa1f2..ef427b8 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/url.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/url.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; export function Url() { diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts index 943ed5d..6d811dd 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts index 35c16c5..5e1ecc3 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_set.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import type { BcsType } from '@mysten/sui/bcs'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/versioned.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/versioned.ts index 3aab82a..71166c7 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/versioned.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/versioned.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts index 1c47d1f..c86c00c 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_id.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts similarity index 99% rename from packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts rename to packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts index b45b6e5..16d57b1 100644 --- a/packages/walrus/src/contracts/deps/0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts +++ b/packages/walrus/src/contracts/deps/0x0000000000000000000000000000000000000000000000000000000000000002/zklogin_verified_issuer.ts @@ -1,5 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 + import { bcs } from '@mysten/sui/bcs'; import * as object from './object.js'; diff --git a/packages/walrus/src/contracts/walrus/encoding.ts b/packages/walrus/src/contracts/encoding.ts similarity index 72% rename from packages/walrus/src/contracts/walrus/encoding.ts rename to packages/walrus/src/contracts/encoding.ts index 393628d..28d8dfc 100644 --- a/packages/walrus/src/contracts/walrus/encoding.ts +++ b/packages/walrus/src/contracts/encoding.ts @@ -1,11 +1,12 @@ // 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'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { function encoded_blob_length(options: { arguments: [ RawTransactionArgument, @@ -16,7 +17,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u64', 'u8', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, 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/epoch_parameters.ts similarity index 61% rename from packages/walrus/src/contracts/walrus/epoch_parameters.ts rename to packages/walrus/src/contracts/epoch_parameters.ts index bad6456..833cae9 100644 --- a/packages/walrus/src/contracts/walrus/epoch_parameters.ts +++ b/packages/walrus/src/contracts/epoch_parameters.ts @@ -1,10 +1,11 @@ // 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'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function EpochParams() { return bcs.struct('EpochParams', { @@ -13,46 +14,52 @@ export function EpochParams() { write_price_per_unit_size: bcs.u64(), }); } -export function init(packageAddresses: { walrus: string }) { - function capacity(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::epoch_parameters::EpochParams`]; +export function init(packageAddress: string) { + function _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['u64', 'u64', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'epoch_parameters', - function: 'capacity', + function: 'new', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function storage_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::epoch_parameters::EpochParams`]; + function capacity(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::epoch_parameters::EpochParams`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'epoch_parameters', - function: 'storage_price', + function: 'capacity', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function write_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::epoch_parameters::EpochParams`]; + function storage_price(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::epoch_parameters::EpochParams`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'epoch_parameters', - function: 'write_price', + function: 'storage_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function epoch_params_for_testing(options: { arguments: [] }) { - const argumentsTypes: [] = []; + function write_price(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::epoch_parameters::EpochParams`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'epoch_parameters', - function: 'epoch_params_for_testing', + function: 'write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - return { capacity, storage_price, write_price, epoch_params_for_testing }; + return { _new, capacity, storage_price, write_price }; } diff --git a/packages/walrus/src/contracts/walrus/event_blob.ts b/packages/walrus/src/contracts/event_blob.ts similarity index 71% rename from packages/walrus/src/contracts/walrus/event_blob.ts rename to packages/walrus/src/contracts/event_blob.ts index 0ded530..9bd2b93 100644 --- a/packages/walrus/src/contracts/walrus/event_blob.ts +++ b/packages/walrus/src/contracts/event_blob.ts @@ -1,12 +1,12 @@ // 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'; +import * as vec_map from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function EventBlobAttestation() { return bcs.struct('EventBlobAttestation', { @@ -22,19 +22,18 @@ export function EventBlob() { } 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(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { function new_attestation(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = ['u64', 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'new_attestation', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -43,10 +42,10 @@ export function init(packageAddresses: { walrus: string }) { function last_attested_event_blob_checkpoint_seq_num(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobAttestation`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobAttestation`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'last_attested_event_blob_checkpoint_seq_num', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -55,10 +54,10 @@ export function init(packageAddresses: { walrus: string }) { function last_attested_event_blob_epoch(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobAttestation`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobAttestation`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'last_attested_event_blob_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -70,17 +69,17 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u64', 'u256']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'new_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlob`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -89,30 +88,30 @@ export function init(packageAddresses: { walrus: string }) { function ending_checkpoint_sequence_number(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlob`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'ending_checkpoint_sequence_number', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function create_with_empty_state(options: { arguments: [] }) { - const argumentsTypes: [] = []; + const argumentsTypes: string[] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + 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 = [`${packageAddresses.walrus}::event_blob::EventBlobCertificationState`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobCertificationState`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'get_latest_certified_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -121,25 +120,32 @@ export function init(packageAddresses: { walrus: string }) { function get_latest_certified_checkpoint_sequence_number(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobCertificationState`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobCertificationState`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'get_latest_certified_checkpoint_sequence_number', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function get_num_tracked_blobs(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobCertificationState`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'event_blob', + function: 'get_num_tracked_blobs', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function is_blob_already_certified(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, - 'u64', - ]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobCertificationState`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'is_blob_already_certified', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -153,13 +159,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, + `${packageAddress}::event_blob::EventBlobCertificationState`, 'u64', 'u256', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'update_latest_certified_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -173,13 +179,13 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, + `${packageAddress}::event_blob::EventBlobCertificationState`, 'u256', 'u16', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'update_aggregate_weight', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -188,38 +194,20 @@ export function init(packageAddresses: { walrus: string }) { function start_tracking_blob(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, - 'u256', - ]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobCertificationState`, 'u256']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'start_tracking_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function stop_tracking_blob(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::event_blob::EventBlobCertificationState`, - 'u256', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'event_blob', - function: 'stop_tracking_blob', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } function reset(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::event_blob::EventBlobCertificationState`]; + const argumentsTypes = [`${packageAddress}::event_blob::EventBlobCertificationState`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'event_blob', function: 'reset', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -235,11 +223,11 @@ export function init(packageAddresses: { walrus: string }) { create_with_empty_state, get_latest_certified_blob_id, get_latest_certified_checkpoint_sequence_number, + get_num_tracked_blobs, 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/events.ts similarity index 53% rename from packages/walrus/src/contracts/walrus/events.ts rename to packages/walrus/src/contracts/events.ts index 1960bbc..769b827 100644 --- a/packages/walrus/src/contracts/walrus/events.ts +++ b/packages/walrus/src/contracts/events.ts @@ -1,10 +1,11 @@ // 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'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function BlobRegistered() { return bcs.struct('BlobRegistered', { @@ -69,7 +70,48 @@ export function ShardRecoveryStart() { shards: bcs.vector(bcs.u16()), }); } -export function init(packageAddresses: { walrus: string }) { +export function ContractUpgraded() { + return bcs.struct('ContractUpgraded', { + epoch: bcs.u32(), + package_id: bcs.Address, + version: bcs.u64(), + }); +} +export function RegisterDenyListUpdate() { + return bcs.struct('RegisterDenyListUpdate', { + epoch: bcs.u32(), + root: bcs.u256(), + sequence_number: bcs.u64(), + node_id: bcs.Address, + }); +} +export function DenyListUpdate() { + return bcs.struct('DenyListUpdate', { + epoch: bcs.u32(), + root: bcs.u256(), + sequence_number: bcs.u64(), + node_id: bcs.Address, + }); +} +export function DenyListBlobDeleted() { + return bcs.struct('DenyListBlobDeleted', { + epoch: bcs.u32(), + blob_id: bcs.u256(), + }); +} +export function ContractUpgradeProposed() { + return bcs.struct('ContractUpgradeProposed', { + epoch: bcs.u32(), + package_digest: bcs.vector(bcs.u8()), + }); +} +export function ContractUpgradeQuorumReached() { + return bcs.struct('ContractUpgradeQuorumReached', { + epoch: bcs.u32(), + package_digest: bcs.vector(bcs.u8()), + }); +} +export function init(packageAddress: string) { function emit_blob_registered(options: { arguments: [ RawTransactionArgument, @@ -88,11 +130,11 @@ export function init(packageAddresses: { walrus: string }) { 'u8', 'u32', 'bool', - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_blob_registered', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -113,12 +155,12 @@ export function init(packageAddresses: { walrus: string }) { 'u256', 'u32', 'bool', - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'bool', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_blob_certified', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -130,7 +172,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32', 'u256']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_invalid_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -149,12 +191,12 @@ export function init(packageAddresses: { walrus: string }) { 'u32', 'u256', 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'bool', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_blob_deleted', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -164,7 +206,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_epoch_change_start', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -174,7 +216,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_epoch_change_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -186,7 +228,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_shards_received', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -198,7 +240,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_epoch_parameters_selected', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -210,12 +252,112 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'events', function: 'emit_shard_recovery_start', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function emit_contract_upgraded(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_contract_upgraded', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_register_deny_list_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'u256', + 'u64', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_register_deny_list_update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_deny_list_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'u256', + 'u64', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_deny_list_update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_deny_listed_blob_deleted(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'u256']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_deny_listed_blob_deleted', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_contract_upgrade_proposed(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'vector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_contract_upgrade_proposed', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function emit_contract_upgrade_quorum_reached(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u32', 'vector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'events', + function: 'emit_contract_upgrade_quorum_reached', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } return { emit_blob_registered, emit_blob_certified, @@ -226,5 +368,11 @@ export function init(packageAddresses: { walrus: string }) { emit_shards_received, emit_epoch_parameters_selected, emit_shard_recovery_start, + emit_contract_upgraded, + emit_register_deny_list_update, + emit_deny_list_update, + emit_deny_listed_blob_deleted, + emit_contract_upgrade_proposed, + emit_contract_upgrade_quorum_reached, }; } diff --git a/packages/walrus/src/contracts/extended_field.ts b/packages/walrus/src/contracts/extended_field.ts new file mode 100644 index 0000000..57149b4 --- /dev/null +++ b/packages/walrus/src/contracts/extended_field.ts @@ -0,0 +1,103 @@ +// 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 type { Transaction } from '@mysten/sui/transactions'; + +import * as object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function ExtendedField() { + return bcs.struct('ExtendedField', { + id: object.UID(), + }); +} +export function Key() { + return bcs.struct('Key', { + dummy_field: bcs.bool(), + }); +} +export function init(packageAddress: string) { + function _new>(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [`${options.typeArguments[0]}`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'extended_field', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function borrow(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::extended_field::ExtendedField<${options.typeArguments[0]}>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'extended_field', + function: 'borrow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function borrow_mut(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::extended_field::ExtendedField<${options.typeArguments[0]}>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'extended_field', + function: 'borrow_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function swap>(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::extended_field::ExtendedField<${options.typeArguments[0]}>`, + `${options.typeArguments[0]}`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'extended_field', + function: 'swap', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + function destroy(options: { + arguments: [RawTransactionArgument]; + typeArguments: [string]; + }) { + const argumentsTypes = [ + `${packageAddress}::extended_field::ExtendedField<${options.typeArguments[0]}>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'extended_field', + function: 'destroy', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + typeArguments: options.typeArguments, + }); + } + return { _new, borrow, borrow_mut, swap, destroy }; +} diff --git a/packages/walrus/src/contracts/walrus/init.ts b/packages/walrus/src/contracts/init.ts similarity index 51% rename from packages/walrus/src/contracts/walrus/init.ts rename to packages/walrus/src/contracts/init.ts index b95962f..f99751c 100644 --- a/packages/walrus/src/contracts/walrus/init.ts +++ b/packages/walrus/src/contracts/init.ts @@ -1,23 +1,24 @@ // 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 object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function InitCap() { return bcs.struct('InitCap', { id: object.UID(), }); } -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { function init(options: { arguments: [] }) { - const argumentsTypes: [] = []; + const argumentsTypes: string[] = []; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'init', function: 'init', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -25,6 +26,7 @@ export function init(packageAddresses: { walrus: string }) { } function initialize_walrus(options: { arguments: [ + RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, @@ -34,30 +36,46 @@ export function init(packageAddresses: { walrus: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::init::InitCap`, + `${packageAddress}::init::InitCap`, + '0x0000000000000000000000000000000000000000000000000000000000000002::package::UpgradeCap', 'u64', 'u64', 'u16', 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + '0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'init', function: 'initialize_walrus', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function migrate(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::system::System`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'init', + function: 'migrate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function destroy(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::init::InitCap`]; + const argumentsTypes = [`${packageAddress}::init::InitCap`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'init', function: 'destroy', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - return { init, initialize_walrus, destroy }; + return { init, initialize_walrus, migrate, destroy }; } diff --git a/packages/walrus/src/contracts/messages.ts b/packages/walrus/src/contracts/messages.ts new file mode 100644 index 0000000..bbed598 --- /dev/null +++ b/packages/walrus/src/contracts/messages.ts @@ -0,0 +1,368 @@ +// 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 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(), + message: bcs.vector(bcs.u8()), + stake_support: bcs.u16(), + }); +} +export function CertifiedBlobMessage() { + return bcs.struct('CertifiedBlobMessage', { + blob_id: bcs.u256(), + blob_persistence_type: BlobPersistenceType(), + }); +} +export function CertifiedInvalidBlobId() { + return bcs.struct('CertifiedInvalidBlobId', { + blob_id: bcs.u256(), + }); +} +export function DenyListUpdateMessage() { + return bcs.struct('DenyListUpdateMessage', { + storage_node_id: bcs.Address, + deny_list_sequence_number: bcs.u64(), + deny_list_size: bcs.u64(), + deny_list_root: bcs.u256(), + }); +} +export function DenyListBlobDeleted() { + return bcs.struct('DenyListBlobDeleted', { + blob_id: bcs.u256(), + }); +} +export function BlobPersistenceType() { + return bcs.enum('BlobPersistenceType', { + Permanent: null, + Deletable: bcs.Address, + }); +} +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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::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]; + }) { + const argumentsTypes = ['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 = [`${packageAddress}::messages::CertifiedMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'invalid_blob_id_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function deny_list_update_message(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::CertifiedMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'deny_list_update_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function deny_list_blob_deleted_message(options: { + arguments: [RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::messages::CertifiedMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'deny_list_blob_deleted_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function intent_type(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::messages::CertifiedMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'into_message', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function certified_blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::CertifiedBlobMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'certified_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function blob_persistence_type(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::CertifiedBlobMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'blob_persistence_type', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function invalid_blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::CertifiedInvalidBlobId`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'invalid_blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function storage_node_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::DenyListUpdateMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'storage_node_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function sequence_number(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::DenyListUpdateMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'sequence_number', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function size(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::DenyListUpdateMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'size', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function root(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::DenyListUpdateMessage`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'root', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function blob_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::DenyListBlobDeleted`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'blob_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_deletable(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::BlobPersistenceType`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'is_deletable', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function object_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::messages::BlobPersistenceType`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'object_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function peel_blob_persistence_type(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000002::bcs::BCS', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'messages', + function: 'peel_blob_persistence_type', + 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, + deny_list_update_message, + deny_list_blob_deleted_message, + intent_type, + intent_version, + cert_epoch, + stake_support, + message, + into_message, + certified_blob_id, + blob_persistence_type, + invalid_blob_id, + storage_node_id, + sequence_number, + size, + root, + blob_id, + is_deletable, + object_id, + peel_blob_persistence_type, + }; +} diff --git a/packages/walrus/src/contracts/metadata.ts b/packages/walrus/src/contracts/metadata.ts new file mode 100644 index 0000000..a22c98b --- /dev/null +++ b/packages/walrus/src/contracts/metadata.ts @@ -0,0 +1,63 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } 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 _new(options: { arguments: [] }) { + const argumentsTypes: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'metadata', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function insert_or_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::metadata::Metadata`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::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 = [ + `${packageAddress}::metadata::Metadata`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'metadata', + function: 'remove', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { _new, insert_or_update, remove }; +} diff --git a/packages/walrus/src/contracts/node_metadata.ts b/packages/walrus/src/contracts/node_metadata.ts new file mode 100644 index 0000000..dbd75c9 --- /dev/null +++ b/packages/walrus/src/contracts/node_metadata.ts @@ -0,0 +1,162 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function NodeMetadata() { + return bcs.struct('NodeMetadata', { + image_url: bcs.string(), + project_url: bcs.string(), + description: bcs.string(), + extra_fields: vec_map.VecMap(bcs.string(), bcs.string()), + }); +} +export function init(packageAddress: string) { + function _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_image_url(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::node_metadata::NodeMetadata`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'set_image_url', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_project_url(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::node_metadata::NodeMetadata`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'set_project_url', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_description(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::node_metadata::NodeMetadata`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'set_description', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_extra_fields(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::node_metadata::NodeMetadata`, + '0x0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0x0000000000000000000000000000000000000000000000000000000000000001::string::String, 0x0000000000000000000000000000000000000000000000000000000000000001::string::String>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'set_extra_fields', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function image_url(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::node_metadata::NodeMetadata`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'image_url', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function project_url(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::node_metadata::NodeMetadata`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'project_url', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function description(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::node_metadata::NodeMetadata`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'description', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function extra_fields(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::node_metadata::NodeMetadata`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'extra_fields', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function _default(options: { arguments: [] }) { + const argumentsTypes: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'node_metadata', + function: 'default', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + _new, + set_image_url, + set_project_url, + set_description, + set_extra_fields, + image_url, + project_url, + description, + extra_fields, + _default, + }; +} diff --git a/packages/walrus/src/contracts/pending_values.ts b/packages/walrus/src/contracts/pending_values.ts new file mode 100644 index 0000000..49a444e --- /dev/null +++ b/packages/walrus/src/contracts/pending_values.ts @@ -0,0 +1,151 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/vec_map.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } 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: string[] = []; + 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 = [`${packageAddress}::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 insert_or_replace(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [`${packageAddress}::pending_values::PendingValues`, 'u32', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'insert_or_replace', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function reduce(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::pending_values::PendingValues`, 'u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'flush', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::pending_values::PendingValues`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'inner', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner_mut(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::pending_values::PendingValues`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pending_values', + function: 'inner_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function unwrap(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::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 = [`${packageAddress}::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, + insert_or_replace, + reduce, + value_at, + flush, + inner, + inner_mut, + unwrap, + is_empty, + }; +} diff --git a/packages/walrus/src/contracts/pool_exchange_rate.ts b/packages/walrus/src/contracts/pool_exchange_rate.ts new file mode 100644 index 0000000..5605872 --- /dev/null +++ b/packages/walrus/src/contracts/pool_exchange_rate.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 { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function PoolExchangeRate() { + return bcs.enum('PoolExchangeRate', { + Flat: null, + Variable: bcs.tuple([bcs.u128(), bcs.u128()]), + }); +} +export function init(packageAddress: string) { + function flat(options: { arguments: [] }) { + const argumentsTypes: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'flat', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function _new(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function convert_to_wal_amount(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::pool_exchange_rate::PoolExchangeRate`, 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'convert_to_wal_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function convert_to_share_amount(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::pool_exchange_rate::PoolExchangeRate`, 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'pool_exchange_rate', + function: 'convert_to_share_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { flat, _new, convert_to_wal_amount, convert_to_share_amount }; +} diff --git a/packages/walrus/src/contracts/walrus/redstuff.ts b/packages/walrus/src/contracts/redstuff.ts similarity index 85% rename from packages/walrus/src/contracts/walrus/redstuff.ts rename to packages/walrus/src/contracts/redstuff.ts index 452f414..5c9a8af 100644 --- a/packages/walrus/src/contracts/walrus/redstuff.ts +++ b/packages/walrus/src/contracts/redstuff.ts @@ -1,18 +1,19 @@ // 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'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { function encoded_blob_length(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = ['u64', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'encoded_blob_length', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -22,7 +23,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'source_symbols_primary', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -32,7 +33,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'source_symbols_secondary', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -42,7 +43,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'n_source_symbols', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -54,7 +55,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u64', 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'symbol_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -64,7 +65,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'metadata_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -74,7 +75,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'decoding_safety_limit', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -84,7 +85,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'redstuff', function: 'max_byzantine', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/shared_blob.ts b/packages/walrus/src/contracts/shared_blob.ts new file mode 100644 index 0000000..5d76a4c --- /dev/null +++ b/packages/walrus/src/contracts/shared_blob.ts @@ -0,0 +1,82 @@ +// 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 blob from './blob.js'; +import * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function SharedBlob() { + return bcs.struct('SharedBlob', { + id: object.UID(), + blob: blob.Blob(), + funds: balance.Balance(), + }); +} +export function init(packageAddress: string) { + function _new(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::blob::Blob`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'shared_blob', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function new_funded(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::blob::Blob`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'shared_blob', + function: 'new_funded', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function fund(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::shared_blob::SharedBlob`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::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 = [ + `${packageAddress}::shared_blob::SharedBlob`, + `${packageAddress}::system::System`, + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'shared_blob', + function: 'extend', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { _new, new_funded, fund, extend }; +} diff --git a/packages/walrus/src/contracts/walrus/staked_wal.ts b/packages/walrus/src/contracts/staked_wal.ts similarity index 63% rename from packages/walrus/src/contracts/walrus/staked_wal.ts rename to packages/walrus/src/contracts/staked_wal.ts index 073b54a..882b404 100644 --- a/packages/walrus/src/contracts/walrus/staked_wal.ts +++ b/packages/walrus/src/contracts/staked_wal.ts @@ -1,14 +1,13 @@ // 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'; +import * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function StakedWal() { return bcs.struct('StakedWal', { @@ -22,10 +21,10 @@ export function StakedWal() { export function StakedWalState() { return bcs.enum('StakedWalState', { Staked: null, - Withdrawing: bcs.tuple([bcs.u32(), bcs.u64()]), + Withdrawing: bcs.u32(), }); } -export function init(packageAddresses: { walrus: string; wal: string }) { +export function init(packageAddress: string) { function mint(options: { arguments: [ RawTransactionArgument, @@ -34,124 +33,130 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', - `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `0x0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddress}::wal::WAL>`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'mint', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function into_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'into_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function set_withdrawing(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`, 'u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staked_wal', + function: 'set_withdrawing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function can_withdraw_early(options: { arguments: [ RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, ]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`, 'u32', 'u64']; + const argumentsTypes = [ + `${packageAddress}::staked_wal::StakedWal`, + 'bool', + `${packageAddress}::walrus_context::WalrusContext`, + ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', - function: 'set_withdrawing', + function: 'can_withdraw_early', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'node_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function value(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'value', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function activation_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'activation_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_staked(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'is_staked', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_withdrawing(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'is_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function withdraw_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'withdraw_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function pool_token_amount(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staked_wal', - function: 'pool_token_amount', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } function join(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staked_wal::StakedWal`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, + `${packageAddress}::staked_wal::StakedWal`, + `${packageAddress}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'join', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -160,20 +165,20 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function split(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`, 'u64']; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'split', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function destroy_zero(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staked_wal::StakedWal`]; + const argumentsTypes = [`${packageAddress}::staked_wal::StakedWal`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staked_wal', function: 'destroy_zero', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -183,13 +188,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { mint, into_balance, set_withdrawing, + can_withdraw_early, 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/staking.ts b/packages/walrus/src/contracts/staking.ts new file mode 100644 index 0000000..ee5c3ed --- /dev/null +++ b/packages/walrus/src/contracts/staking.ts @@ -0,0 +1,678 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function Staking() { + return bcs.struct('Staking', { + id: object.UID(), + version: bcs.u64(), + package_id: bcs.Address, + new_package_id: bcs.option(bcs.Address), + }); +} +export function init(packageAddress: string) { + function create(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u64', + 'u64', + 'u16', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0x0000000000000000000000000000000000000000000000000000000000000002::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, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::node_metadata::NodeMetadata`, + 'vector', + 'vector', + 'vector', + 'u16', + '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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'u16', + ]; + 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, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'collect_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_commission_receiver(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_commission_receiver', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_governance_authorized(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_governance_authorized', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function check_governance_authorization(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'check_governance_authorization', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_current_node_weight(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'get_current_node_weight', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function compute_next_committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking::Staking`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'compute_next_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_storage_price_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_node_capacity_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function node_metadata(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'node_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_next_public_key(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + '0x0000000000000000000000000000000000000000000000000000000000000001::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + '0x0000000000000000000000000000000000000000000000000000000000000001::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_network_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_node_metadata(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + `${packageAddress}::node_metadata::NodeMetadata`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_node_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function voting_end(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::system::System`, + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'u32', + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::staking::Staking`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::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 = [ + `${packageAddress}::staking::Staking`, + `${packageAddress}::staked_wal::StakedWal`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'withdraw_stake', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function package_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking::Staking`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'package_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function version(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking::Staking`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'version', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking::Staking`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'epoch', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function is_quorum(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::staking::Staking`, 'u16']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'is_quorum', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function calculate_rewards(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u64', + 'u32', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'calculate_rewards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_new_package_id(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking::Staking`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'set_new_package_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function migrate(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking::Staking`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking', + function: 'migrate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function inner_mut(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::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 = [`${packageAddress}::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_commission_receiver, + set_governance_authorized, + check_governance_authorization, + get_current_node_weight, + compute_next_committee, + set_storage_price_vote, + set_write_price_vote, + set_node_capacity_vote, + node_metadata, + set_next_public_key, + set_name, + set_network_address, + set_network_public_key, + set_node_metadata, + voting_end, + initiate_epoch_change, + shard_transfer_failed, + epoch_sync_done, + stake_with_pool, + request_withdraw_stake, + withdraw_stake, + package_id, + version, + epoch, + is_quorum, + calculate_rewards, + set_new_package_id, + migrate, + inner_mut, + inner, + }; +} diff --git a/packages/walrus/src/contracts/walrus/staking_inner.ts b/packages/walrus/src/contracts/staking_inner.ts similarity index 53% rename from packages/walrus/src/contracts/walrus/staking_inner.ts rename to packages/walrus/src/contracts/staking_inner.ts index ab8469b..487067d 100644 --- a/packages/walrus/src/contracts/walrus/staking_inner.ts +++ b/packages/walrus/src/contracts/staking_inner.ts @@ -1,32 +1,30 @@ // 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 object_table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object_table.js'; import * as epoch_parameters from './epoch_parameters.js'; +import * as extended_field from './extended_field.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.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(), + active_set: extended_field.ExtendedField(), 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(), + next_epoch_public_keys: extended_field.ExtendedField(), }); } export function EpochState() { @@ -36,36 +34,60 @@ export function EpochState() { NextParamsSelected: bcs.u64(), }); } -export function init(packageAddresses: { walrus: string; wal: string }) { +export function init(packageAddress: string) { + function _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u64', + 'u64', + 'u16', + '0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function create_pool(options: { arguments: [ RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, + RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, - RawTransactionArgument, + RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, RawTransactionArgument, ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::node_metadata::NodeMetadata`, 'vector', 'vector', 'vector', - 'u64', + 'u16', 'u64', 'u64', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'create_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -75,27 +97,54 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'withdraw_node', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function set_commission_receiver(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_commission_receiver', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function collect_commission(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'collect_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -105,22 +154,22 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'voting_end', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function calculate_votes(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'calculate_votes', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -130,12 +179,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', + '0x0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', 'u16', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'quorum_above', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -145,12 +194,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', + '0x0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', 'u16', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'quorum_below', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -160,32 +209,89 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', + '0x0000000000000000000000000000000000000000000000000000000000000002::priority_queue::PriorityQueue', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'take_threshold_value', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function set_governance_authorized(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_governance_authorized', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function check_governance_authorization(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::auth::Authenticated`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'check_governance_authorization', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function get_current_node_weight(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'get_current_node_weight', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function set_next_commission(options: { arguments: [ RawTransactionArgument, RawTransactionArgument, - RawTransactionArgument, + RawTransactionArgument, ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'u64', + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'u16', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_next_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -199,13 +305,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_storage_price_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -219,13 +325,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_write_price_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -239,13 +345,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_node_capacity_vote', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -260,14 +366,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_next_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -281,13 +387,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_name', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -301,13 +407,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_network_address', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -321,28 +427,48 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_network_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function set_node_metadata(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + `${packageAddress}::node_metadata::NodeMetadata`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'set_node_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function set_withdrawing(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'set_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -352,12 +478,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'destroy_empty_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -371,13 +497,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::staking_inner::StakingInnerV1`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'stake_with_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -387,12 +513,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'request_withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -402,32 +528,42 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::staked_wal::StakedWal`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function compute_next_committee(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'compute_next_committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function select_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'select_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function apportionment(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'apportionment', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -443,12 +579,24 @@ export function init(packageAddresses: { walrus: string; wal: string }) { const argumentsTypes = ['vector', 'u16', 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'dhondt', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function max_shards_per_node(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = ['u64', 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'max_shards_per_node', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function initiate_epoch_change(options: { arguments: [ RawTransactionArgument, @@ -457,13 +605,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', - `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + `0x0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0x0000000000000000000000000000000000000000000000000000000000000002::object::ID, 0x0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddress}::wal::WAL>>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'initiate_epoch_change', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -473,12 +621,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `0x0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0x0000000000000000000000000000000000000000000000000000000000000002::object::ID, 0x0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddress}::wal::WAL>>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -493,14 +641,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', + '0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'epoch_sync_done', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -515,74 +663,89 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::staking_inner::StakingInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'shard_transfer_failed', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function node_metadata(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'node_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function next_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'next_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function next_epoch_params(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'next_epoch_params', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function previous_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'previous_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function next_bls_committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'next_bls_committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -592,48 +755,87 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_inner::StakingInnerV1`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'has_pool', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function n_shards(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'n_shards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function calculate_rewards(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_inner::StakingInnerV1`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u64', + 'u32', + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_inner', + function: 'calculate_rewards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function new_walrus_context(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_inner::StakingInnerV1`]; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'new_walrus_context', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_quorum(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; + arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = ['u16', 'u16']; + const argumentsTypes = [`${packageAddress}::staking_inner::StakingInnerV1`, 'u16']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_inner', function: 'is_quorum', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } return { + _new, create_pool, withdraw_node, + set_commission_receiver, collect_commission, voting_end, calculate_votes, quorum_above, quorum_below, take_threshold_value, + set_governance_authorized, + check_governance_authorization, + get_current_node_weight, set_next_commission, set_storage_price_vote, set_write_price_vote, @@ -642,18 +844,22 @@ export function init(packageAddresses: { walrus: string; wal: string }) { set_name, set_network_address, set_network_public_key, + set_node_metadata, set_withdrawing, destroy_empty_pool, stake_with_pool, request_withdraw_stake, withdraw_stake, + compute_next_committee, select_committee, apportionment, dhondt, + max_shards_per_node, initiate_epoch_change, advance_epoch, epoch_sync_done, shard_transfer_failed, + node_metadata, next_committee, next_epoch_params, epoch, @@ -661,6 +867,8 @@ export function init(packageAddresses: { walrus: string; wal: string }) { previous_committee, next_bls_committee, has_pool, + n_shards, + calculate_rewards, new_walrus_context, is_quorum, }; diff --git a/packages/walrus/src/contracts/walrus/staking_pool.ts b/packages/walrus/src/contracts/staking_pool.ts similarity index 51% rename from packages/walrus/src/contracts/walrus/staking_pool.ts rename to packages/walrus/src/contracts/staking_pool.ts index 077fe84..1c83667 100644 --- a/packages/walrus/src/contracts/walrus/staking_pool.ts +++ b/packages/walrus/src/contracts/staking_pool.ts @@ -1,15 +1,18 @@ // 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 auth from './auth.js'; +import * as bag from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/bag.js'; +import * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import * as table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.js'; import * as pending_values from './pending_values.js'; import * as storage_node from './storage_node.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function VotingParams() { return bcs.struct('VotingParams', { @@ -27,33 +30,74 @@ export function StakingPool() { 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(), + num_shares: bcs.u64(), + pending_shares_withdraw: pending_values.PendingValues(), + pre_active_withdrawals: pending_values.PendingValues(), + pending_commission_rate: pending_values.PendingValues(), + commission_rate: bcs.u16(), exchange_rates: table.Table(), pending_stake: pending_values.PendingValues(), rewards_pool: balance.Balance(), + commission: balance.Balance(), + commission_receiver: auth.Authorized(), + governance_authorized: auth.Authorized(), + extra_fields: bag.Bag(), }); } export function PoolState() { return bcs.enum('PoolState', { - New: null, Active: null, Withdrawing: bcs.u32(), Withdrawn: null, }); } -export function init(packageAddresses: { walrus: string; wal: string }) { +export function init(packageAddress: string) { + function _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::node_metadata::NodeMetadata`, + 'vector', + 'vector', + 'vector', + 'u16', + 'u64', + 'u64', + 'u64', + `${packageAddress}::walrus_context::WalrusContext`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function set_withdrawing(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -67,13 +111,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::staking_pool::StakingPool`, + `0x0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddress}::wal::WAL>`, + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -83,17 +127,21 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [ RawTransactionArgument, RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, RawTransactionArgument, ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::staked_wal::StakedWal`, + 'bool', + 'bool', + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'request_withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -103,17 +151,21 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [ RawTransactionArgument, RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, RawTransactionArgument, ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::staked_wal::StakedWal`, + 'bool', + 'bool', + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'withdraw_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -127,13 +179,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::staking_pool::StakingPool`, + `0x0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddress}::wal::WAL>`, + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -143,24 +195,32 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'process_pending_stake', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function set_next_commission(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; + const argumentsTypes = [ + `${packageAddress}::staking_pool::StakingPool`, + 'u16', + `${packageAddress}::walrus_context::WalrusContext`, + ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_next_commission', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -169,10 +229,10 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function set_next_storage_price(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_next_storage_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -181,10 +241,10 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function set_next_write_price(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_next_write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -193,10 +253,10 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function set_next_node_capacity(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u64']; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_next_node_capacity', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -211,14 +271,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, + `${packageAddress}::staking_pool::StakingPool`, 'vector', 'vector', - `${packageAddresses.walrus}::walrus_context::WalrusContext`, + `${packageAddress}::walrus_context::WalrusContext`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_next_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -228,12 +288,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::staking_pool::StakingPool`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_name', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -243,12 +303,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::staking_pool::StakingPool`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', + `${packageAddress}::staking_pool::StakingPool`, + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_network_address', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -257,20 +317,35 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function set_network_public_key(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'vector']; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'vector']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'set_network_public_key', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function set_node_metadata(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::node_metadata::NodeMetadata`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_node_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function destroy_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'destroy_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -279,10 +354,10 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function exchange_rate_at_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u32']; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'exchange_rate_at_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -291,136 +366,229 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function wal_balance_at_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`, 'u32']; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'wal_balance_at_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function governance_authorized(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'governance_authorized', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_governance_authorized(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_governance_authorized', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function commission_receiver(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'commission_receiver', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_commission_receiver(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::auth::Authenticated`, + `${packageAddress}::auth::Authorized`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'set_commission_receiver', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function commission_rate(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'commission_rate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function commission_amount(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'commission_amount', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function collect_commission(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::staking_pool::StakingPool`, + `${packageAddress}::auth::Authenticated`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'collect_commission', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function rewards_amount(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'rewards_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function wal_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'wal_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'storage_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function write_price(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'write_price', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_capacity(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'node_capacity', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function activation_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'activation_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function node_info(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'node_info', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function is_new(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking_pool', - function: 'is_new', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } function is_active(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'is_active', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_withdrawing(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'is_withdrawing', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function is_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking_pool::StakingPool`]; + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'staking_pool', function: 'is_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function calculate_rewards(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [`${packageAddress}::staking_pool::StakingPool`, 'u64', 'u32', 'u32']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'staking_pool', + function: 'calculate_rewards', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } return { + _new, set_withdrawing, stake, request_withdraw_stake, @@ -435,10 +603,17 @@ export function init(packageAddresses: { walrus: string; wal: string }) { set_name, set_network_address, set_network_public_key, + set_node_metadata, destroy_empty, exchange_rate_at_epoch, wal_balance_at_epoch, + governance_authorized, + set_governance_authorized, + commission_receiver, + set_commission_receiver, commission_rate, + commission_amount, + collect_commission, rewards_amount, wal_balance, storage_price, @@ -446,9 +621,9 @@ export function init(packageAddresses: { walrus: string; wal: string }) { node_capacity, activation_epoch, node_info, - is_new, is_active, is_withdrawing, is_empty, + calculate_rewards, }; } diff --git a/packages/walrus/src/contracts/walrus/storage_accounting.ts b/packages/walrus/src/contracts/storage_accounting.ts similarity index 71% rename from packages/walrus/src/contracts/walrus/storage_accounting.ts rename to packages/walrus/src/contracts/storage_accounting.ts index ceb2fec..3917e0b 100644 --- a/packages/walrus/src/contracts/walrus/storage_accounting.ts +++ b/packages/walrus/src/contracts/storage_accounting.ts @@ -1,11 +1,12 @@ // 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'; +import * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function FutureAccounting() { return bcs.struct('FutureAccounting', { @@ -21,7 +22,7 @@ export function FutureAccountingRingBuffer() { ring_buffer: bcs.vector(FutureAccounting()), }); } -export function init(packageAddresses: { walrus: string; wal: string }) { +export function init(packageAddress: string) { function new_future_accounting(options: { arguments: [ RawTransactionArgument, @@ -32,31 +33,31 @@ export function init(packageAddresses: { walrus: string; wal: string }) { const argumentsTypes = [ 'u32', 'u64', - `0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::balance::Balance<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'new_future_accounting', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_to_reclaim(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'storage_to_reclaim', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -65,13 +66,10 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function increase_storage_to_reclaim(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_accounting::FutureAccounting`, - 'u64', - ]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'increase_storage_to_reclaim', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -80,23 +78,20 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function decrease_storage_to_reclaim(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_accounting::FutureAccounting`, - 'u64', - ]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'decrease_storage_to_reclaim', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function rewards_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'rewards_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -105,20 +100,20 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function delete_empty_future_accounting(options: { arguments: [RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'delete_empty_future_accounting', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function unwrap_balance(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_accounting::FutureAccounting`]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccounting`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'unwrap_balance', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -128,7 +123,7 @@ export function init(packageAddresses: { walrus: string; wal: string }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'ring_new', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -138,36 +133,32 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::storage_accounting::FutureAccountingRingBuffer`, + `${packageAddress}::storage_accounting::FutureAccountingRingBuffer`, 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'ring_lookup_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function ring_pop_expand(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_accounting::FutureAccountingRingBuffer`, - ]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccountingRingBuffer`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'ring_pop_expand', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function max_epochs_ahead(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_accounting::FutureAccountingRingBuffer`, - ]; + const argumentsTypes = [`${packageAddress}::storage_accounting::FutureAccountingRingBuffer`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_accounting', function: 'max_epochs_ahead', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), diff --git a/packages/walrus/src/contracts/storage_node.ts b/packages/walrus/src/contracts/storage_node.ts new file mode 100644 index 0000000..0fd1be7 --- /dev/null +++ b/packages/walrus/src/contracts/storage_node.ts @@ -0,0 +1,326 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/group_ops.js'; +import * as object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import * as event_blob from './event_blob.js'; +import * as extended_field from './extended_field.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.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()), + metadata: extended_field.ExtendedField(), + }); +} +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()), + deny_list_root: bcs.u256(), + deny_list_sequence: bcs.u64(), + deny_list_size: bcs.u64(), + }); +} +export function init(packageAddress: string) { + function _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + '0x0000000000000000000000000000000000000000000000000000000000000001::string::String', + 'vector', + 'vector', + `${packageAddress}::node_metadata::NodeMetadata`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function new_cap(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000002::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 = [`${packageAddress}::storage_node::StorageNodeInfo`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function metadata(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::storage_node::StorageNodeInfo`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function next_epoch_public_key(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::storage_node::StorageNodeCap`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'last_event_blob_attestation', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function deny_list_root(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::storage_node::StorageNodeCap`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'deny_list_root', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function deny_list_sequence(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::storage_node::StorageNodeCap`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'deny_list_sequence', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_last_epoch_sync_done(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::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 = [ + `${packageAddress}::storage_node::StorageNodeCap`, + `${packageAddress}::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 = [`${packageAddress}::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 = [ + `${packageAddress}::storage_node::StorageNodeInfo`, + '0x0000000000000000000000000000000000000000000000000000000000000001::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 = [ + `${packageAddress}::storage_node::StorageNodeInfo`, + '0x0000000000000000000000000000000000000000000000000000000000000001::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 = [`${packageAddress}::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 set_node_metadata(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::storage_node::StorageNodeInfo`, + `${packageAddress}::node_metadata::NodeMetadata`, + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_node_metadata', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function rotate_public_key(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::storage_node::StorageNodeInfo`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'rotate_public_key', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function destroy(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::storage_node::StorageNodeInfo`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'destroy', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_deny_list_properties(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::storage_node::StorageNodeCap`, + 'u256', + 'u64', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'storage_node', + function: 'set_deny_list_properties', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + _new, + new_cap, + public_key, + metadata, + next_epoch_public_key, + id, + node_id, + last_epoch_sync_done, + last_event_blob_attestation, + deny_list_root, + deny_list_sequence, + set_last_epoch_sync_done, + set_last_event_blob_attestation, + set_next_public_key, + set_name, + set_network_address, + set_network_public_key, + set_node_metadata, + rotate_public_key, + destroy, + set_deny_list_properties, + }; +} diff --git a/packages/walrus/src/contracts/walrus/storage_resource.ts b/packages/walrus/src/contracts/storage_resource.ts similarity index 70% rename from packages/walrus/src/contracts/walrus/storage_resource.ts rename to packages/walrus/src/contracts/storage_resource.ts index fd7b51f..68c9c2f 100644 --- a/packages/walrus/src/contracts/walrus/storage_resource.ts +++ b/packages/walrus/src/contracts/storage_resource.ts @@ -1,11 +1,12 @@ // 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 object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function Storage() { return bcs.struct('Storage', { @@ -15,32 +16,32 @@ export function Storage() { storage_size: bcs.u64(), }); } -export function init(packageAddresses: { walrus: string }) { +export function init(packageAddress: string) { function start_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'start_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function end_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'end_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function storage_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'storage_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -56,7 +57,7 @@ export function init(packageAddresses: { walrus: string }) { const argumentsTypes = ['u32', 'u32', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'create_storage', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -65,10 +66,10 @@ export function init(packageAddresses: { walrus: string }) { function extend_end_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`, 'u32']; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'extend_end_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -77,10 +78,10 @@ export function init(packageAddresses: { walrus: string }) { function split_by_epoch(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`, 'u32']; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`, 'u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'split_by_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -89,10 +90,10 @@ export function init(packageAddresses: { walrus: string }) { function split_by_size(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`, 'u64']; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'split_by_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -102,12 +103,12 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::storage_resource::Storage`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::storage_resource::Storage`, + `${packageAddress}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'fuse_periods', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -117,12 +118,12 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::storage_resource::Storage`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::storage_resource::Storage`, + `${packageAddress}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'fuse_amount', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -132,22 +133,22 @@ export function init(packageAddresses: { walrus: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::storage_resource::Storage`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::storage_resource::Storage`, + `${packageAddress}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'storage_resource', function: 'fuse', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function destroy(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_resource::Storage`]; + const argumentsTypes = [`${packageAddress}::storage_resource::Storage`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, 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/system.ts similarity index 50% rename from packages/walrus/src/contracts/walrus/system.ts rename to packages/walrus/src/contracts/system.ts index 375c788..8a488a7 100644 --- a/packages/walrus/src/contracts/walrus/system.ts +++ b/packages/walrus/src/contracts/system.ts @@ -1,24 +1,32 @@ // 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 object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function System() { return bcs.struct('System', { id: object.UID(), version: bcs.u64(), + package_id: bcs.Address, + new_package_id: bcs.option(bcs.Address), }); } -export function init(packageAddresses: { walrus: string; wal: string }) { - function create_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = ['u32']; +export function init(packageAddress: string) { + function create_empty(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + 'u32', + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'create_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -33,14 +41,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, + `${packageAddress}::system::System`, + 'vector', 'vector', - 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'invalidate_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -59,8 +67,8 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::system::System`, + `${packageAddress}::storage_node::StorageNodeCap`, 'u256', 'u256', 'u64', @@ -70,7 +78,7 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'certify_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -85,14 +93,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, + `${packageAddress}::system::System`, 'u64', 'u32', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'reserve_space', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -111,18 +119,18 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::system::System`, + `${packageAddress}::storage_resource::Storage`, 'u256', 'u256', 'u64', 'u8', 'bool', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'register_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -138,15 +146,15 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::blob::Blob`, + `${packageAddress}::system::System`, + `${packageAddress}::blob::Blob`, + 'vector', 'vector', - 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'certify_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -155,13 +163,10 @@ export function init(packageAddresses: { walrus: string; wal: string }) { function delete_blob(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::blob::Blob`, - ]; + const argumentsTypes = [`${packageAddress}::system::System`, `${packageAddress}::blob::Blob`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'delete_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -175,13 +180,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::blob::Blob`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::system::System`, + `${packageAddress}::blob::Blob`, + `${packageAddress}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'extend_blob_with_resource', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -196,64 +201,152 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::blob::Blob`, + `${packageAddress}::system::System`, + `${packageAddress}::blob::Blob`, 'u32', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'extend_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function add_subsidy(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::system::System`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'add_subsidy', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function register_deny_list_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::system::System`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'u256', + 'u64', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'register_deny_list_update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function update_deny_list(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::system::System`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'update_deny_list', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function delete_deny_listed_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::system::System`, + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'delete_deny_listed_blob', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function total_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'total_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function used_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'used_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function n_shards(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'n_shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -267,33 +360,78 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system::System`, - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, - `${packageAddresses.walrus}::epoch_parameters::EpochParams`, + `${packageAddress}::system::System`, + `${packageAddress}::bls_aggregate::BlsCommittee`, + `${packageAddress}::epoch_parameters::EpochParams`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function package_id(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::system::System`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'package_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function version(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::system::System`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'version', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function set_new_package_id(options: { + arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [ + `${packageAddress}::system::System`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'set_new_package_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function migrate(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::system::System`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system', + function: 'migrate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function inner_mut(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'inner_mut', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system::System`]; + const argumentsTypes = [`${packageAddress}::system::System`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system', function: 'inner', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -309,12 +447,20 @@ export function init(packageAddresses: { walrus: string; wal: string }) { delete_blob, extend_blob_with_resource, extend_blob, + add_subsidy, + register_deny_list_update, + update_deny_list, + delete_deny_listed_blob, epoch, total_capacity_size, used_capacity_size, n_shards, committee, advance_epoch, + package_id, + version, + set_new_package_id, + migrate, inner_mut, inner, }; diff --git a/packages/walrus/src/contracts/walrus/system_state_inner.ts b/packages/walrus/src/contracts/system_state_inner.ts similarity index 61% rename from packages/walrus/src/contracts/walrus/system_state_inner.ts rename to packages/walrus/src/contracts/system_state_inner.ts index 282dd88..4c744c9 100644 --- a/packages/walrus/src/contracts/walrus/system_state_inner.ts +++ b/packages/walrus/src/contracts/system_state_inner.ts @@ -1,18 +1,18 @@ // 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 extended_field from './extended_field.js'; import * as storage_accounting from './storage_accounting.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.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(), @@ -20,14 +20,15 @@ export function SystemStateInnerV1() { write_price_per_unit_size: bcs.u64(), future_accounting: storage_accounting.FutureAccountingRingBuffer(), event_blob_certification_state: event_blob.EventBlobCertificationState(), + deny_list_sizes: extended_field.ExtendedField(), }); } -export function init(packageAddresses: { walrus: string; wal: string }) { +export function init(packageAddress: string) { function create_empty(options: { arguments: [RawTransactionArgument] }) { const argumentsTypes = ['u32']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'create_empty', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -41,13 +42,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::bls_aggregate::BlsCommittee`, - `${packageAddresses.walrus}::epoch_parameters::EpochParams`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::bls_aggregate::BlsCommittee`, + `${packageAddress}::epoch_parameters::EpochParams`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'advance_epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -62,14 +63,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, 'u64', 'u32', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'reserve_space', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -83,13 +84,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, 'u64', 'u32', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'reserve_space_without_payment', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -104,14 +105,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + 'vector', 'vector', - 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'invalidate_blob_id', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -130,18 +131,18 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::storage_resource::Storage`, 'u256', 'u256', 'u64', 'u8', 'bool', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'register_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -157,15 +158,15 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::blob::Blob`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::blob::Blob`, + 'vector', 'vector', - 'vector', 'vector', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'certify_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -175,12 +176,12 @@ export function init(packageAddresses: { walrus: string; wal: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::blob::Blob`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::blob::Blob`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'delete_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -194,13 +195,13 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::blob::Blob`, - `${packageAddresses.walrus}::storage_resource::Storage`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::blob::Blob`, + `${packageAddress}::storage_resource::Storage`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'extend_blob_with_resource', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -215,14 +216,14 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::blob::Blob`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::blob::Blob`, 'u32', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'extend_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -238,15 +239,15 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, 'u64', 'u32', 'u32', - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'process_storage_payments', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -265,8 +266,8 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, 'u256', 'u256', 'u64', @@ -276,57 +277,77 @@ export function init(packageAddresses: { walrus: string; wal: string }) { ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'certify_event_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } + function add_subsidy(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, + 'u32', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'add_subsidy', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; + const argumentsTypes = [`${packageAddress}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'epoch', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function total_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; + const argumentsTypes = [`${packageAddress}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'total_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function used_capacity_size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; + const argumentsTypes = [`${packageAddress}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'used_capacity_size', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; + const argumentsTypes = [`${packageAddress}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'committee', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } function n_shards(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`]; + const argumentsTypes = [`${packageAddress}::system_state_inner::SystemStateInnerV1`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', function: 'n_shards', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -334,28 +355,81 @@ export function init(packageAddresses: { walrus: string; wal: string }) { } function write_price(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; + }) { + const argumentsTypes = [`${packageAddress}::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 register_deny_list_update(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; }) { const argumentsTypes = [ - `${packageAddresses.walrus}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'u256', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', - function: 'write_price', + function: 'register_deny_list_update', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function update_deny_list(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + `${packageAddress}::storage_node::StorageNodeCap`, + 'vector', + 'vector', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'system_state_inner', + function: 'update_deny_list', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - function storage_units_from_size(options: { - arguments: [RawTransactionArgument]; + function delete_deny_listed_blob(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; }) { - const argumentsTypes = ['u64']; + const argumentsTypes = [ + `${packageAddress}::system_state_inner::SystemStateInnerV1`, + 'vector', + 'vector', + 'vector', + ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.walrus, + package: packageAddress, module: 'system_state_inner', - function: 'storage_units_from_size', + function: 'delete_deny_listed_blob', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } @@ -372,12 +446,15 @@ export function init(packageAddresses: { walrus: string; wal: string }) { extend_blob, process_storage_payments, certify_event_blob, + add_subsidy, epoch, total_capacity_size, used_capacity_size, committee, n_shards, write_price, - storage_units_from_size, + register_deny_list_update, + update_deny_list, + delete_deny_listed_blob, }; } diff --git a/packages/walrus/src/contracts/upgrade.ts b/packages/walrus/src/contracts/upgrade.ts new file mode 100644 index 0000000..e688a1e --- /dev/null +++ b/packages/walrus/src/contracts/upgrade.ts @@ -0,0 +1,217 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import * as _package from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/package.js'; +import * as table from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/table.js'; +import * as vec_set from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/vec_set.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; + +export function PackageDigest() { + return bcs.struct('PackageDigest', { + pos0: bcs.vector(bcs.u8()), + }); +} +export function UpgradeProposal() { + return bcs.struct('UpgradeProposal', { + epoch: bcs.u32(), + digest: PackageDigest(), + version: bcs.u64(), + voting_weight: bcs.u16(), + voters: vec_set.VecSet(bcs.Address), + }); +} +export function UpgradeManager() { + return bcs.struct('UpgradeManager', { + id: object.UID(), + cap: _package.UpgradeCap(), + upgrade_proposals: table.Table(), + }); +} +export function EmergencyUpgradeCap() { + return bcs.struct('EmergencyUpgradeCap', { + id: object.UID(), + upgrade_manager_id: bcs.Address, + }); +} +export function init(packageAddress: string) { + function _new(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [ + '0x0000000000000000000000000000000000000000000000000000000000000002::package::UpgradeCap', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function vote_for_upgrade(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::upgrade::UpgradeManager`, + `${packageAddress}::staking::Staking`, + `${packageAddress}::auth::Authenticated`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'vote_for_upgrade', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function authorize_upgrade(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::upgrade::UpgradeManager`, + `${packageAddress}::staking::Staking`, + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'authorize_upgrade', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function authorize_emergency_upgrade(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::upgrade::UpgradeManager`, + `${packageAddress}::upgrade::EmergencyUpgradeCap`, + 'vector', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'authorize_emergency_upgrade', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function commit_upgrade(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::upgrade::UpgradeManager`, + `${packageAddress}::staking::Staking`, + `${packageAddress}::system::System`, + '0x0000000000000000000000000000000000000000000000000000000000000002::package::UpgradeReceipt', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'commit_upgrade', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function cleanup_upgrade_proposals(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::upgrade::UpgradeManager`, + `${packageAddress}::staking::Staking`, + 'vector>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'cleanup_upgrade_proposals', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function burn_emergency_upgrade_cap(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::upgrade::EmergencyUpgradeCap`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'burn_emergency_upgrade_cap', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function fresh_proposal(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = ['u32', `${packageAddress}::upgrade::PackageDigest`, 'u64']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'fresh_proposal', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function add_vote(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + `${packageAddress}::upgrade::UpgradeProposal`, + '0x0000000000000000000000000000000000000000000000000000000000000002::object::ID', + 'u16', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'upgrade', + function: 'add_vote', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { + _new, + vote_for_upgrade, + authorize_upgrade, + authorize_emergency_upgrade, + commit_upgrade, + cleanup_upgrade_proposals, + burn_emergency_upgrade_cap, + fresh_proposal, + add_vote, + }; +} diff --git a/packages/walrus/src/contracts/utils/index.ts b/packages/walrus/src/contracts/utils/index.ts index dade9ef..71d2d44 100644 --- a/packages/walrus/src/contracts/utils/index.ts +++ b/packages/walrus/src/contracts/utils/index.ts @@ -1,8 +1,8 @@ // 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 { BcsType, TypeTag } from '@mysten/sui/bcs'; import { isArgument } from '@mysten/sui/transactions'; import type { TransactionArgument } from '@mysten/sui/transactions'; import { normalizeSuiAddress } from '@mysten/sui/utils'; diff --git a/packages/walrus/src/contracts/wal/wal.ts b/packages/walrus/src/contracts/wal.ts similarity index 65% rename from packages/walrus/src/contracts/wal/wal.ts rename to packages/walrus/src/contracts/wal.ts index 0eb19b9..2c6ed2c 100644 --- a/packages/walrus/src/contracts/wal/wal.ts +++ b/packages/walrus/src/contracts/wal.ts @@ -1,22 +1,23 @@ // 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'; +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(packageAddresses: { wal: string }) { +export function init(packageAddress: string) { function init(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.wal}::wal::WAL`]; + const argumentsTypes = [`${packageAddress}::wal::WAL`]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal, + package: packageAddress, 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.ts similarity index 65% rename from packages/walrus/src/contracts/wal_exchange/wal_exchange.ts rename to packages/walrus/src/contracts/wal_exchange.ts index 7d8c3d5..8208d4d 100644 --- a/packages/walrus/src/contracts/wal_exchange/wal_exchange.ts +++ b/packages/walrus/src/contracts/wal_exchange.ts @@ -1,12 +1,13 @@ // 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'; +import * as balance from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/balance.js'; +import * as object from './deps/0x0000000000000000000000000000000000000000000000000000000000000002/object.js'; +import { normalizeMoveArguments } from './utils/index.js'; +import type { RawTransactionArgument } from './utils/index.js'; export function Exchange() { return bcs.struct('Exchange', { @@ -28,14 +29,14 @@ export function ExchangeRate() { sui: bcs.u64(), }); } -export function init(packageAddresses: { wal: string; wal_exchange: string }) { +export function init(packageAddress: string) { function new_exchange_rate(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = ['u64', 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'new_exchange_rate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -44,10 +45,10 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { function wal_to_sui(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.wal_exchange}::wal_exchange::ExchangeRate`, 'u64']; + const argumentsTypes = [`${packageAddress}::wal_exchange::ExchangeRate`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'wal_to_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -56,26 +57,35 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { function sui_to_wal(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { - const argumentsTypes = [`${packageAddresses.wal_exchange}::wal_exchange::ExchangeRate`, 'u64']; + const argumentsTypes = [`${packageAddress}::wal_exchange::ExchangeRate`, 'u64']; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'sui_to_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), }); } - + function _new(options: { arguments: [] }) { + const argumentsTypes: string[] = []; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'wal_exchange', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } function new_funded(options: { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'new_funded', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -89,13 +99,13 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `${packageAddress}::wal_exchange::Exchange`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'add_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -109,13 +119,13 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + `${packageAddress}::wal_exchange::Exchange`, + '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'add_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -125,12 +135,12 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `${packageAddress}::wal_exchange::Exchange`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'add_all_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -140,12 +150,12 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + `${packageAddress}::wal_exchange::Exchange`, + '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'add_all_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -155,12 +165,12 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, + `${packageAddress}::wal_exchange::Exchange`, + `${packageAddress}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'check_admin', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -174,13 +184,13 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `${packageAddress}::wal_exchange::Exchange`, 'u64', - `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, + `${packageAddress}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'withdraw_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -194,13 +204,13 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `${packageAddress}::wal_exchange::Exchange`, 'u64', - `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, + `${packageAddress}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'withdraw_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -215,14 +225,14 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, + `${packageAddress}::wal_exchange::Exchange`, 'u64', 'u64', - `${packageAddresses.wal_exchange}::wal_exchange::AdminCap`, + `${packageAddress}::wal_exchange::AdminCap`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'set_exchange_rate', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -232,12 +242,12 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + `${packageAddress}::wal_exchange::Exchange`, + '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'exchange_all_for_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -251,13 +261,13 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - '0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', + `${packageAddress}::wal_exchange::Exchange`, + '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>', 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'exchange_for_wal', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -267,12 +277,12 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { arguments: [RawTransactionArgument, RawTransactionArgument]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `${packageAddress}::wal_exchange::Exchange`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'exchange_all_for_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -286,13 +296,13 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { ]; }) { const argumentsTypes = [ - `${packageAddresses.wal_exchange}::wal_exchange::Exchange`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, + `${packageAddress}::wal_exchange::Exchange`, + `0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddress}::wal::WAL>`, 'u64', ]; return (tx: Transaction) => tx.moveCall({ - package: packageAddresses.wal_exchange, + package: packageAddress, module: 'wal_exchange', function: 'exchange_for_sui', arguments: normalizeMoveArguments(options.arguments, argumentsTypes), @@ -302,6 +312,7 @@ export function init(packageAddresses: { wal: string; wal_exchange: string }) { new_exchange_rate, wal_to_sui, sui_to_wal, + _new, new_funded, add_wal, add_sui, diff --git a/packages/walrus/src/contracts/walrus/committee.ts b/packages/walrus/src/contracts/walrus/committee.ts deleted file mode 100644 index 87cdd62..0000000 --- a/packages/walrus/src/contracts/walrus/committee.ts +++ /dev/null @@ -1,99 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function empty(options: { arguments: [] }) { - const argumentsTypes: [] = []; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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: packageAddresses.walrus, - module: 'committee', - function: 'initialize', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function transition(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::committee::Committee`, - '0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0000000000000000000000000000000000000000000000000000000000000002::object::ID, u16>', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'committee', - function: 'transition', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function shards(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::committee::Committee`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'committee', - function: 'shards', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function size(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::committee::Committee`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'committee', - function: 'size', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::committee::Committee`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'committee', - function: 'inner', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function to_inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::committee::Committee`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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/messages.ts b/packages/walrus/src/contracts/walrus/messages.ts deleted file mode 100644 index 0428077..0000000 --- a/packages/walrus/src/contracts/walrus/messages.ts +++ /dev/null @@ -1,249 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function new_proof_of_possession_msg(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = ['u32', 'address', 'vector']; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'new_proof_of_possession_msg', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function to_bcs(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::ProofOfPossessionMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'to_bcs', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function verify_proof_of_possession(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::messages::ProofOfPossessionMessage`, - 'vector', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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: packageAddresses.walrus, - module: 'messages', - function: 'new_certified_message', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function certify_blob_message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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: packageAddresses.walrus, - module: 'messages', - function: 'certified_event_blob_message', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function invalid_blob_id_message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'invalid_blob_id_message', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function intent_type(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'intent_type', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function intent_version(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'intent_version', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function cert_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'cert_epoch', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function stake_support(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'stake_support', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'message', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function into_message(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'into_message', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function certified_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedBlobMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'certified_epoch', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function certified_blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedBlobMessage`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'certified_blob_id', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function certified_invalid_epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedInvalidBlobId`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'messages', - function: 'certified_invalid_epoch', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function invalid_blob_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::messages::CertifiedInvalidBlobId`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 deleted file mode 100644 index befa804..0000000 --- a/packages/walrus/src/contracts/walrus/metadata.ts +++ /dev/null @@ -1,52 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function insert_or_update(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::metadata::Metadata`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'metadata', - function: 'insert_or_update', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function remove(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::metadata::Metadata`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 deleted file mode 100644 index 8a4b2ea..0000000 --- a/packages/walrus/src/contracts/walrus/pending_values.ts +++ /dev/null @@ -1,111 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function empty(options: { arguments: [] }) { - const argumentsTypes: [] = []; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pending_values', - function: 'empty', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function insert_or_add(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::pending_values::PendingValues`, - 'u32', - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pending_values', - function: 'insert_or_add', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function reduce(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::pending_values::PendingValues`, - 'u32', - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pending_values', - function: 'reduce', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function value_at(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`, 'u32']; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pending_values', - function: 'value_at', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function flush(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`, 'u32']; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pending_values', - function: 'flush', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function unwrap(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pending_values', - function: 'unwrap', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function is_empty(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::pending_values::PendingValues`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 deleted file mode 100644 index a6b1d4a..0000000 --- a/packages/walrus/src/contracts/walrus/pool_exchange_rate.ts +++ /dev/null @@ -1,58 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function empty(options: { arguments: [] }) { - const argumentsTypes: [] = []; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pool_exchange_rate', - function: 'empty', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - - function get_wal_amount(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::pool_exchange_rate::PoolExchangeRate`, - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'pool_exchange_rate', - function: 'get_wal_amount', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function get_token_amount(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::pool_exchange_rate::PoolExchangeRate`, - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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/shared_blob.ts b/packages/walrus/src/contracts/walrus/shared_blob.ts deleted file mode 100644 index 14ea080..0000000 --- a/packages/walrus/src/contracts/walrus/shared_blob.ts +++ /dev/null @@ -1,56 +0,0 @@ -// 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(packageAddresses: { walrus: string; wal: string }) { - function fund(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::shared_blob::SharedBlob`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'shared_blob', - function: 'fund', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function extend(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::shared_blob::SharedBlob`, - `${packageAddresses.walrus}::system::System`, - 'u32', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'shared_blob', - function: 'extend', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - return { fund, extend }; -} diff --git a/packages/walrus/src/contracts/walrus/staking.ts b/packages/walrus/src/contracts/walrus/staking.ts deleted file mode 100644 index 29afe3e..0000000 --- a/packages/walrus/src/contracts/walrus/staking.ts +++ /dev/null @@ -1,437 +0,0 @@ -// 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(packageAddresses: { walrus: string; wal: string }) { - function create(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - 'u64', - 'u64', - 'u16', - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 = [ - `${packageAddresses.walrus}::staking::Staking`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - 'vector', - 'vector', - 'vector', - 'u64', - 'u64', - 'u64', - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'register_candidate', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function withdraw_node(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'withdraw_node', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_next_commission(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_next_commission', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function collect_commission(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'collect_commission', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_storage_price_vote(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_storage_price_vote', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_write_price_vote(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_write_price_vote', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_node_capacity_vote(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'u64', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'vector', - 'vector', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_next_public_key', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_name(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_name', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_network_address(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_network_address', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_network_public_key(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'vector', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'set_network_public_key', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function voting_end(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'voting_end', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function initiate_epoch_change(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::system::System`, - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'initiate_epoch_change', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function shard_transfer_failed(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', - 'vector', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'shard_transfer_failed', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function epoch_sync_done(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - 'u32', - '0000000000000000000000000000000000000000000000000000000000000002::clock::Clock', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'epoch_sync_done', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function stake_with_pool(options: { - arguments: [ - RawTransactionArgument, - RawTransactionArgument, - RawTransactionArgument, - ]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${packageAddresses.wal}::wal::WAL>`, - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'stake_with_pool', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function request_withdraw_stake(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'request_withdraw_stake', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function withdraw_stake(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::staking::Staking`, - `${packageAddresses.walrus}::staked_wal::StakedWal`, - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'withdraw_stake', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function inner_mut(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking::Staking`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'staking', - function: 'inner_mut', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function inner(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::staking::Staking`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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/storage_node.ts b/packages/walrus/src/contracts/walrus/storage_node.ts deleted file mode 100644 index 1052f54..0000000 --- a/packages/walrus/src/contracts/walrus/storage_node.ts +++ /dev/null @@ -1,216 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function new_cap(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [ - '0000000000000000000000000000000000000000000000000000000000000002::object::ID', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'new_cap', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function public_key(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'public_key', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function next_epoch_public_key(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'next_epoch_public_key', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'id', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function node_id(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'node_id', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function last_epoch_sync_done(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`]; - return (tx: Transaction) => - tx.moveCall({ - 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 = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 = [`${packageAddresses.walrus}::storage_node::StorageNodeCap`, 'u32']; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 = [ - `${packageAddresses.walrus}::storage_node::StorageNodeCap`, - `${packageAddresses.walrus}::event_blob::EventBlobAttestation`, - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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 = [ - `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, - 'vector', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'set_next_public_key', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_name(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'set_name', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_network_address(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, - '0000000000000000000000000000000000000000000000000000000000000001::string::String', - ]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'storage_node', - function: 'set_network_address', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function set_network_public_key(options: { - arguments: [RawTransactionArgument, RawTransactionArgument]; - }) { - const argumentsTypes = [ - `${packageAddresses.walrus}::storage_node::StorageNodeInfo`, - 'vector', - ]; - return (tx: Transaction) => - tx.moveCall({ - 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 = [`${packageAddresses.walrus}::storage_node::StorageNodeInfo`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - 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/walrus_context.ts b/packages/walrus/src/contracts/walrus/walrus_context.ts deleted file mode 100644 index 6ffa730..0000000 --- a/packages/walrus/src/contracts/walrus/walrus_context.ts +++ /dev/null @@ -1,50 +0,0 @@ -// 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(packageAddresses: { walrus: string }) { - function epoch(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::walrus_context::WalrusContext`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'walrus_context', - function: 'epoch', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function committee_selected(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::walrus_context::WalrusContext`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'walrus_context', - function: 'committee_selected', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - function committee(options: { arguments: [RawTransactionArgument] }) { - const argumentsTypes = [`${packageAddresses.walrus}::walrus_context::WalrusContext`]; - return (tx: Transaction) => - tx.moveCall({ - package: packageAddresses.walrus, - module: 'walrus_context', - function: 'committee', - arguments: normalizeMoveArguments(options.arguments, argumentsTypes), - }); - } - - return { epoch, committee_selected, committee }; -} diff --git a/packages/walrus/src/contracts/walrus_context.ts b/packages/walrus/src/contracts/walrus_context.ts new file mode 100644 index 0000000..3bb4570 --- /dev/null +++ b/packages/walrus/src/contracts/walrus_context.ts @@ -0,0 +1,70 @@ +// 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/0x0000000000000000000000000000000000000000000000000000000000000002/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 _new(options: { + arguments: [ + RawTransactionArgument, + RawTransactionArgument, + RawTransactionArgument, + ]; + }) { + const argumentsTypes = [ + 'u32', + 'bool', + '0x0000000000000000000000000000000000000000000000000000000000000002::vec_map::VecMap<0x0000000000000000000000000000000000000000000000000000000000000002::object::ID, vector>', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'walrus_context', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + function epoch(options: { arguments: [RawTransactionArgument] }) { + const argumentsTypes = [`${packageAddress}::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 = [`${packageAddress}::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 = [`${packageAddress}::walrus_context::WalrusContext`]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'walrus_context', + function: 'committee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes), + }); + } + return { _new, epoch, committee_selected, committee }; +}