Skip to content

Commit

Permalink
update contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes-mysten committed Jan 18, 2025
1 parent 69163e5 commit 77605de
Show file tree
Hide file tree
Showing 90 changed files with 4,353 additions and 2,075 deletions.
10 changes: 5 additions & 5 deletions packages/walrus/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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', {
Expand All @@ -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<number>, RawTransactionArgument<number | bigint>];
}) {
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<string>,
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -85,78 +98,79 @@ export function init(packageAddresses: { walrus: string }) {
arguments: [RawTransactionArgument<string>, RawTransactionArgument<string>];
}) {
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<string>] }) {
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<string>] }) {
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<string>] }) {
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<string>] }) {
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<string>] }) {
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<string>] }) {
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,
Expand Down
126 changes: 126 additions & 0 deletions packages/walrus/src/contracts/apportionment_queue.ts
Original file line number Diff line number Diff line change
@@ -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<T0 extends BcsType<any>>(...typeParameters: [T0]) {
return bcs.struct('ApportionmentQueue', {
entries: bcs.vector(Entry(typeParameters[0])),
});
}
export function Entry<T0 extends BcsType<any>>(...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<string>];
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<T0 extends BcsType<any>>(options: {
arguments: [
RawTransactionArgument<string>,
RawTransactionArgument<string>,
RawTransactionArgument<number | bigint>,
RawTransactionArgument<T0>,
];
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<string[]>];
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<string[]>];
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<string>, RawTransactionArgument<string>];
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 };
}
Loading

0 comments on commit 77605de

Please sign in to comment.