diff --git a/packages/suins/src/constants.ts b/packages/suins/src/constants.ts index 925e408d0..e660f4afe 100644 --- a/packages/suins/src/constants.ts +++ b/packages/suins/src/constants.ts @@ -56,6 +56,13 @@ export const mainPackage: Config = { }, }, registryTableId: '0xe64cd9db9f829c6cc405d9790bd71567ae07259855f4fba6f02c84f52298c106', + // TODO: Add marketplace constants once the contracts are deployed on mainnet + // marketplace: { + // packageId: '', + // originalPackageId: '', + // auctionTableId: '', + // offerTableId: '', + // }, }, testnet: { packageId: '0x40eee27b014a872f5c3330dcd5329aa55c7fe0fcc6e70c6498852e2e3727172e', @@ -102,5 +109,11 @@ export const mainPackage: Config = { }, }, registryTableId: '0xb120c0d55432630fce61f7854795a3463deb6e3b443cc4ae72e1282073ff56e4', + marketplace: { + packageId: '0xbd2b57cddef6674d5a4dfd14518583ea9bb194ec47207a8c1dcf00740babc2eb', + originalPackageId: '0xd421a8ebd93c4f93a4020e733b98108db3498be90a0d62ffed1ef926434aa569', + auctionTableId: '0x60ecc91870bd1d9c7b5ff74a05479aa53713096949c45aa830ef6f4d9cb6936b', + offerTableId: '0x1e848feb692bff38afc2d66c0757cd10cf062e2564697e6d4a1d8a1604304343', + }, }, }; diff --git a/packages/suins/src/contracts/suins_auction/address.ts b/packages/suins/src/contracts/suins_auction/address.ts new file mode 100644 index 000000000..9f52be541 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/address.ts @@ -0,0 +1,24 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** Provides a way to get address length since it's a platform-specific parameter. */ + +import { type Transaction } from '@mysten/sui/transactions'; +export interface LengthOptions { + package?: string; + arguments?: []; +} +/** + * Should be converted to a native function. Current implementation only works for + * Sui. + */ +export function length(options: LengthOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'address', + function: 'length', + }); +} diff --git a/packages/suins/src/contracts/suins_auction/ascii.ts b/packages/suins/src/contracts/suins_auction/ascii.ts new file mode 100644 index 000000000..7faaa5cfe --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/ascii.ts @@ -0,0 +1,448 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * The `ASCII` module defines basic string and char newtypes in Move that verify + * that characters are valid ASCII, and that strings consist of only valid ASCII + * characters. + */ + +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::ascii'; +export const String = new MoveStruct({ + name: `${$moduleName}::String`, + fields: { + bytes: bcs.vector(bcs.u8()), + }, +}); +export const Char = new MoveStruct({ + name: `${$moduleName}::Char`, + fields: { + byte: bcs.u8(), + }, +}); +export interface CharArguments { + byte: RawTransactionArgument; +} +export interface CharOptions { + package?: string; + arguments: CharArguments | [byte: RawTransactionArgument]; +} +/** Convert a `byte` into a `Char` that is checked to make sure it is valid ASCII. */ +export function char(options: CharOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8'] satisfies (string | null)[]; + const parameterNames = ['byte']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'char', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface StringArguments { + bytes: RawTransactionArgument; +} +export interface StringOptions { + package?: string; + arguments: StringArguments | [bytes: RawTransactionArgument]; +} +/** + * Convert a vector of bytes `bytes` into an `String`. Aborts if `bytes` contains + * non-ASCII characters. + */ +export function string(options: StringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector'] satisfies (string | null)[]; + const parameterNames = ['bytes']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryStringArguments { + bytes: RawTransactionArgument; +} +export interface TryStringOptions { + package?: string; + arguments: TryStringArguments | [bytes: RawTransactionArgument]; +} +/** + * Convert a vector of bytes `bytes` into an `String`. Returns + * `Some()` if the `bytes` contains all valid ASCII characters. + * Otherwise returns `None`. + */ +export function tryString(options: TryStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector'] satisfies (string | null)[]; + const parameterNames = ['bytes']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'try_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AllCharactersPrintableArguments { + string: RawTransactionArgument; +} +export interface AllCharactersPrintableOptions { + package?: string; + arguments: AllCharactersPrintableArguments | [string: RawTransactionArgument]; +} +/** + * Returns `true` if all characters in `string` are printable characters Returns + * `false` otherwise. Not all `String`s are printable strings. + */ +export function allCharactersPrintable(options: AllCharactersPrintableOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'all_characters_printable', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PushCharArguments { + string: RawTransactionArgument; + char: RawTransactionArgument; +} +export interface PushCharOptions { + package?: string; + arguments: + | PushCharArguments + | [string: RawTransactionArgument, char: RawTransactionArgument]; +} +/** Push a `Char` to the end of the `string`. */ +export function pushChar(options: PushCharOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['string', 'char']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'push_char', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PopCharArguments { + string: RawTransactionArgument; +} +export interface PopCharOptions { + package?: string; + arguments: PopCharArguments | [string: RawTransactionArgument]; +} +/** Pop a `Char` from the end of the `string`. */ +export function popChar(options: PopCharOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'pop_char', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LengthArguments { + string: RawTransactionArgument; +} +export interface LengthOptions { + package?: string; + arguments: LengthArguments | [string: RawTransactionArgument]; +} +/** Returns the length of the `string` in bytes. */ +export function length(options: LengthOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'length', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AppendArguments { + string: RawTransactionArgument; + other: RawTransactionArgument; +} +export interface AppendOptions { + package?: string; + arguments: + | AppendArguments + | [string: RawTransactionArgument, other: RawTransactionArgument]; +} +/** Append the `other` string to the end of `string`. */ +export function append(options: AppendOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['string', 'other']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'append', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface InsertArguments { + s: RawTransactionArgument; + at: RawTransactionArgument; + o: RawTransactionArgument; +} +export interface InsertOptions { + package?: string; + arguments: + | InsertArguments + | [ + s: RawTransactionArgument, + at: RawTransactionArgument, + o: RawTransactionArgument, + ]; +} +/** Insert the `other` string at the `at` index of `string`. */ +export function insert(options: InsertOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64', null] satisfies (string | null)[]; + const parameterNames = ['s', 'at', 'o']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'insert', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SubstringArguments { + string: RawTransactionArgument; + i: RawTransactionArgument; + j: RawTransactionArgument; +} +export interface SubstringOptions { + package?: string; + arguments: + | SubstringArguments + | [ + string: RawTransactionArgument, + i: RawTransactionArgument, + j: RawTransactionArgument, + ]; +} +/** Copy the slice of the `string` from `i` to `j` into a new `String`. */ +export function substring(options: SubstringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['string', 'i', 'j']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'substring', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AsBytesArguments { + string: RawTransactionArgument; +} +export interface AsBytesOptions { + package?: string; + arguments: AsBytesArguments | [string: RawTransactionArgument]; +} +/** Get the inner bytes of the `string` as a reference */ +export function asBytes(options: AsBytesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'as_bytes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntoBytesArguments { + string: RawTransactionArgument; +} +export interface IntoBytesOptions { + package?: string; + arguments: IntoBytesArguments | [string: RawTransactionArgument]; +} +/** Unpack the `string` to get its backing bytes */ +export function intoBytes(options: IntoBytesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'into_bytes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ByteArguments { + char: RawTransactionArgument; +} +export interface ByteOptions { + package?: string; + arguments: ByteArguments | [char: RawTransactionArgument]; +} +/** Unpack the `char` into its underlying bytes. */ +export function byte(options: ByteOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['char']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'byte', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IsValidCharArguments { + b: RawTransactionArgument; +} +export interface IsValidCharOptions { + package?: string; + arguments: IsValidCharArguments | [b: RawTransactionArgument]; +} +/** Returns `true` if `b` is a valid ASCII character. Returns `false` otherwise. */ +export function isValidChar(options: IsValidCharOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8'] satisfies (string | null)[]; + const parameterNames = ['b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'is_valid_char', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IsPrintableCharArguments { + byte: RawTransactionArgument; +} +export interface IsPrintableCharOptions { + package?: string; + arguments: IsPrintableCharArguments | [byte: RawTransactionArgument]; +} +/** + * Returns `true` if `byte` is a printable ASCII character. Returns `false` + * otherwise. + */ +export function isPrintableChar(options: IsPrintableCharOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8'] satisfies (string | null)[]; + const parameterNames = ['byte']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'is_printable_char', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IsEmptyArguments { + string: RawTransactionArgument; +} +export interface IsEmptyOptions { + package?: string; + arguments: IsEmptyArguments | [string: RawTransactionArgument]; +} +/** Returns `true` if `string` is empty. */ +export function isEmpty(options: IsEmptyOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'is_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToUppercaseArguments { + string: RawTransactionArgument; +} +export interface ToUppercaseOptions { + package?: string; + arguments: ToUppercaseArguments | [string: RawTransactionArgument]; +} +/** Convert a `string` to its uppercase equivalent. */ +export function toUppercase(options: ToUppercaseOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'to_uppercase', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToLowercaseArguments { + string: RawTransactionArgument; +} +export interface ToLowercaseOptions { + package?: string; + arguments: ToLowercaseArguments | [string: RawTransactionArgument]; +} +/** Convert a `string` to its lowercase equivalent. */ +export function toLowercase(options: ToLowercaseOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['string']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'to_lowercase', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IndexOfArguments { + string: RawTransactionArgument; + substr: RawTransactionArgument; +} +export interface IndexOfOptions { + package?: string; + arguments: + | IndexOfArguments + | [string: RawTransactionArgument, substr: RawTransactionArgument]; +} +/** + * Computes the index of the first occurrence of the `substr` in the `string`. + * Returns the length of the `string` if the `substr` is not found. Returns 0 if + * the `substr` is empty. + */ +export function indexOf(options: IndexOfOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['string', 'substr']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'ascii', + function: 'index_of', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/auction.ts b/packages/suins/src/contracts/suins_auction/auction.ts new file mode 100644 index 000000000..3a1543daa --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/auction.ts @@ -0,0 +1,518 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +import * as bf_hmac_encryption from './deps/seal/bf_hmac_encryption.js'; +import * as balance from './deps/sui/balance.js'; +import * as suins_registration from './deps/suins/suins_registration.js'; +import * as object_bag from './deps/sui/object_bag.js'; +import * as table from './deps/sui/table.js'; +import * as bag from './deps/sui/bag.js'; +import * as type_name from './deps/std/type_name.js'; +const $moduleName = '@suins/auction::auction'; +export const AuctionWitness = new MoveStruct({ + name: `${$moduleName}::AuctionWitness`, + fields: { + dummy_field: bcs.bool(), + }, +}); +export const AdminCap = new MoveStruct({ + name: `${$moduleName}::AdminCap`, + fields: { + id: bcs.Address, + }, +}); +export const Auction = new MoveStruct({ + name: `${$moduleName}::Auction`, + fields: { + id: bcs.Address, + owner: bcs.Address, + start_time: bcs.u64(), + end_time: bcs.u64(), + min_bid: bcs.u64(), + reserve_price: bcs.option(bf_hmac_encryption.EncryptedObject), + highest_bidder: bcs.Address, + highest_bid_balance: balance.Balance, + suins_registration: suins_registration.SuinsRegistration, + }, +}); +export const AuctionTable = new MoveStruct({ + name: `${$moduleName}::AuctionTable`, + fields: { + id: bcs.Address, + version: bcs.u64(), + bag: object_bag.ObjectBag, + allowed_tokens: table.Table, + /** The key servers that must be used for seal encryption. */ + key_servers: bcs.vector(bcs.Address), + /** The public keys for the key servers in the same order as `key_servers`. */ + public_keys: bcs.vector(bcs.vector(bcs.u8())), + /** The threshold for the vote. */ + threshold: bcs.u8(), + service_fee: bcs.u64(), + /** Accumulated service fees for each token type */ + fees: bag.Bag, + }, +}); +export const AuctionCreatedEvent = new MoveStruct({ + name: `${$moduleName}::AuctionCreatedEvent`, + fields: { + auction_id: bcs.Address, + domain_name: bcs.string(), + owner: bcs.Address, + start_time: bcs.u64(), + end_time: bcs.u64(), + min_bid: bcs.u64(), + reserve_price: bcs.option(bcs.vector(bcs.u8())), + token: type_name.TypeName, + }, +}); +export const BidPlacedEvent = new MoveStruct({ + name: `${$moduleName}::BidPlacedEvent`, + fields: { + auction_id: bcs.Address, + domain_name: bcs.string(), + bidder: bcs.Address, + amount: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const AuctionFinalizedEvent = new MoveStruct({ + name: `${$moduleName}::AuctionFinalizedEvent`, + fields: { + auction_id: bcs.Address, + domain_name: bcs.string(), + highest_bidder: bcs.Address, + amount: bcs.u64(), + reserve_price: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const AuctionCancelledEvent = new MoveStruct({ + name: `${$moduleName}::AuctionCancelledEvent`, + fields: { + auction_id: bcs.Address, + domain_name: bcs.string(), + owner: bcs.Address, + token: type_name.TypeName, + }, +}); +export const MigrateEvent = new MoveStruct({ + name: `${$moduleName}::MigrateEvent`, + fields: { + old_version: bcs.u64(), + new_version: bcs.u64(), + }, +}); +export const SetSealConfig = new MoveStruct({ + name: `${$moduleName}::SetSealConfig`, + fields: { + key_servers: bcs.vector(bcs.Address), + public_keys: bcs.vector(bcs.vector(bcs.u8())), + threshold: bcs.u8(), + }, +}); +export const SetServiceFee = new MoveStruct({ + name: `${$moduleName}::SetServiceFee`, + fields: { + service_fee: bcs.u64(), + }, +}); +export const AddAllowedToken = new MoveStruct({ + name: `${$moduleName}::AddAllowedToken`, + fields: { + token: type_name.TypeName, + }, +}); +export const RemoveAllowedToken = new MoveStruct({ + name: `${$moduleName}::RemoveAllowedToken`, + fields: { + token: type_name.TypeName, + }, +}); +export const WithdrawFees = new MoveStruct({ + name: `${$moduleName}::WithdrawFees`, + fields: { + token: type_name.TypeName, + amount: bcs.u64(), + recipient: bcs.Address, + }, +}); +export interface MigrateArguments { + _: RawTransactionArgument; + auctionTable: RawTransactionArgument; + offerTable: RawTransactionArgument; +} +export interface MigrateOptions { + package?: string; + arguments: + | MigrateArguments + | [ + _: RawTransactionArgument, + auctionTable: RawTransactionArgument, + offerTable: RawTransactionArgument, + ]; +} +export function migrate(options: MigrateOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, null] satisfies (string | null)[]; + const parameterNames = ['_', 'auctionTable', 'offerTable']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'migrate', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SetSealConfigArguments { + _: RawTransactionArgument; + auctionTable: RawTransactionArgument; + keyServers: RawTransactionArgument; + publicKeys: RawTransactionArgument; + threshold: RawTransactionArgument; +} +export interface SetSealConfigOptions { + package?: string; + arguments: + | SetSealConfigArguments + | [ + _: RawTransactionArgument, + auctionTable: RawTransactionArgument, + keyServers: RawTransactionArgument, + publicKeys: RawTransactionArgument, + threshold: RawTransactionArgument, + ]; +} +export function setSealConfig(options: SetSealConfigOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, 'vector
', 'vector>', 'u8'] satisfies ( + | string + | null + )[]; + const parameterNames = ['_', 'auctionTable', 'keyServers', 'publicKeys', 'threshold']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'set_seal_config', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SetServiceFeeArguments { + _: RawTransactionArgument; + auctionTable: RawTransactionArgument; + offerTable: RawTransactionArgument; + serviceFee: RawTransactionArgument; +} +export interface SetServiceFeeOptions { + package?: string; + arguments: + | SetServiceFeeArguments + | [ + _: RawTransactionArgument, + auctionTable: RawTransactionArgument, + offerTable: RawTransactionArgument, + serviceFee: RawTransactionArgument, + ]; +} +export function setServiceFee(options: SetServiceFeeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, null, 'u64'] satisfies (string | null)[]; + const parameterNames = ['_', 'auctionTable', 'offerTable', 'serviceFee']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'set_service_fee', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AddAllowedTokenArguments { + _: RawTransactionArgument; + auctionTable: RawTransactionArgument; + offerTable: RawTransactionArgument; +} +export interface AddAllowedTokenOptions { + package?: string; + arguments: + | AddAllowedTokenArguments + | [ + _: RawTransactionArgument, + auctionTable: RawTransactionArgument, + offerTable: RawTransactionArgument, + ]; + typeArguments: [string]; +} +export function addAllowedToken(options: AddAllowedTokenOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, null] satisfies (string | null)[]; + const parameterNames = ['_', 'auctionTable', 'offerTable']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'add_allowed_token', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface RemoveAllowedTokenArguments { + _: RawTransactionArgument; + auctionTable: RawTransactionArgument; + offerTable: RawTransactionArgument; +} +export interface RemoveAllowedTokenOptions { + package?: string; + arguments: + | RemoveAllowedTokenArguments + | [ + _: RawTransactionArgument, + auctionTable: RawTransactionArgument, + offerTable: RawTransactionArgument, + ]; + typeArguments: [string]; +} +export function removeAllowedToken(options: RemoveAllowedTokenOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, null] satisfies (string | null)[]; + const parameterNames = ['_', 'auctionTable', 'offerTable']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'remove_allowed_token', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface WithdrawFeesArguments { + _: RawTransactionArgument; + auctionTable: RawTransactionArgument; + offerTable: RawTransactionArgument; +} +export interface WithdrawFeesOptions { + package?: string; + arguments: + | WithdrawFeesArguments + | [ + _: RawTransactionArgument, + auctionTable: RawTransactionArgument, + offerTable: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Withdraw accumulated fees from both auction and offer tables */ +export function withdrawFees(options: WithdrawFeesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, null] satisfies (string | null)[]; + const parameterNames = ['_', 'auctionTable', 'offerTable']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'withdraw_fees', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface CreateAuctionArguments { + auctionTable: RawTransactionArgument; + startTime: RawTransactionArgument; + endTime: RawTransactionArgument; + minBid: RawTransactionArgument; + encryptedReservePrice: RawTransactionArgument; + suinsRegistration: RawTransactionArgument; +} +export interface CreateAuctionOptions { + package?: string; + arguments: + | CreateAuctionArguments + | [ + auctionTable: RawTransactionArgument, + startTime: RawTransactionArgument, + endTime: RawTransactionArgument, + minBid: RawTransactionArgument, + encryptedReservePrice: RawTransactionArgument, + suinsRegistration: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Create a new auction for a domain with a specific token required */ +export function createAuction(options: CreateAuctionOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + null, + 'u64', + 'u64', + 'u64', + '0x1::option::Option>', + null, + '0x2::clock::Clock', + ] satisfies (string | null)[]; + const parameterNames = [ + 'auctionTable', + 'startTime', + 'endTime', + 'minBid', + 'encryptedReservePrice', + 'suinsRegistration', + ]; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'create_auction', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface PlaceBidArguments { + auctionTable: RawTransactionArgument; + domainName: RawTransactionArgument; + coin: RawTransactionArgument; +} +export interface PlaceBidOptions { + package?: string; + arguments: + | PlaceBidArguments + | [ + auctionTable: RawTransactionArgument, + domainName: RawTransactionArgument, + coin: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Place a bid on an active auction */ +export function placeBid(options: PlaceBidOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, '0x1::string::String', null, '0x2::clock::Clock'] satisfies ( + | string + | null + )[]; + const parameterNames = ['auctionTable', 'domainName', 'coin']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'place_bid', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface FinalizeAuctionArguments { + suins: RawTransactionArgument; + auctionTable: RawTransactionArgument; + domainName: RawTransactionArgument; + derivedKeys: RawTransactionArgument; + keyServers: RawTransactionArgument; +} +export interface FinalizeAuctionOptions { + package?: string; + arguments: + | FinalizeAuctionArguments + | [ + suins: RawTransactionArgument, + auctionTable: RawTransactionArgument, + domainName: RawTransactionArgument, + derivedKeys: RawTransactionArgument, + keyServers: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Finalize an auction after it ends, transfer domain and funds */ +export function finalizeAuction(options: FinalizeAuctionOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + null, + null, + '0x1::string::String', + '0x1::option::Option>>', + '0x1::option::Option>', + '0x2::clock::Clock', + ] satisfies (string | null)[]; + const parameterNames = ['suins', 'auctionTable', 'domainName', 'derivedKeys', 'keyServers']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'finalize_auction', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface CancelAuctionArguments { + auctionTable: RawTransactionArgument; + domainName: RawTransactionArgument; +} +export interface CancelAuctionOptions { + package?: string; + arguments: + | CancelAuctionArguments + | [auctionTable: RawTransactionArgument, domainName: RawTransactionArgument]; + typeArguments: [string]; +} +/** Cancel an auction */ +export function cancelAuction(options: CancelAuctionOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, '0x1::string::String', '0x2::clock::Clock'] satisfies ( + | string + | null + )[]; + const parameterNames = ['auctionTable', 'domainName']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'cancel_auction', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface GetSuinsRegistrationFromAuctionArguments { + auction: RawTransactionArgument; +} +export interface GetSuinsRegistrationFromAuctionOptions { + package?: string; + arguments: GetSuinsRegistrationFromAuctionArguments | [auction: RawTransactionArgument]; + typeArguments: [string]; +} +export function getSuinsRegistrationFromAuction(options: GetSuinsRegistrationFromAuctionOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['auction']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'get_suins_registration_from_auction', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SealApproveArguments { + id: RawTransactionArgument; + auctionTable: RawTransactionArgument; +} +export interface SealApproveOptions { + package?: string; + arguments: + | SealApproveArguments + | [id: RawTransactionArgument, auctionTable: RawTransactionArgument]; + typeArguments: [string]; +} +export function sealApprove(options: SealApproveOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector', null, '0x2::clock::Clock'] satisfies (string | null)[]; + const parameterNames = ['id', 'auctionTable']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'auction', + function: 'seal_approve', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} diff --git a/packages/suins/src/contracts/suins_auction/bcs.ts b/packages/suins/src/contracts/suins_auction/bcs.ts new file mode 100644 index 000000000..b85a8c629 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/bcs.ts @@ -0,0 +1,40 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Utility for converting a Move value to its binary representation in BCS (Binary + * Canonical Serialization). BCS is the binary encoding for Move resources and + * other non-module values published on-chain. See + * https://github.com/diem/bcs#binary-canonical-serialization-bcs for more details + * on BCS. + */ + +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { type BcsType } from '@mysten/sui/bcs'; +export interface ToBytesArguments> { + v: RawTransactionArgument; +} +export interface ToBytesOptions> { + package?: string; + arguments: ToBytesArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return the binary representation of `v` in BCS (Binary Canonical Serialization) + * format + */ +export function toBytes>(options: ToBytesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bcs', + function: 'to_bytes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} diff --git a/packages/suins/src/contracts/suins_auction/bit_vector.ts b/packages/suins/src/contracts/suins_auction/bit_vector.ts new file mode 100644 index 000000000..7dd083163 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/bit_vector.ts @@ -0,0 +1,193 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::bit_vector'; +export const BitVector = new MoveStruct({ + name: `${$moduleName}::BitVector`, + fields: { + length: bcs.u64(), + bit_field: bcs.vector(bcs.bool()), + }, +}); +export interface NewArguments { + length: RawTransactionArgument; +} +export interface NewOptions { + package?: string; + arguments: NewArguments | [length: RawTransactionArgument]; +} +export function _new(options: NewOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['length']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'new', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SetArguments { + bitvector: RawTransactionArgument; + bitIndex: RawTransactionArgument; +} +export interface SetOptions { + package?: string; + arguments: + | SetArguments + | [ + bitvector: RawTransactionArgument, + bitIndex: RawTransactionArgument, + ]; +} +/** Set the bit at `bit_index` in the `bitvector` regardless of its previous state. */ +export function set(options: SetOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64'] satisfies (string | null)[]; + const parameterNames = ['bitvector', 'bitIndex']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'set', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface UnsetArguments { + bitvector: RawTransactionArgument; + bitIndex: RawTransactionArgument; +} +export interface UnsetOptions { + package?: string; + arguments: + | UnsetArguments + | [ + bitvector: RawTransactionArgument, + bitIndex: RawTransactionArgument, + ]; +} +/** + * Unset the bit at `bit_index` in the `bitvector` regardless of its previous + * state. + */ +export function unset(options: UnsetOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64'] satisfies (string | null)[]; + const parameterNames = ['bitvector', 'bitIndex']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'unset', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ShiftLeftArguments { + bitvector: RawTransactionArgument; + amount: RawTransactionArgument; +} +export interface ShiftLeftOptions { + package?: string; + arguments: + | ShiftLeftArguments + | [bitvector: RawTransactionArgument, amount: RawTransactionArgument]; +} +/** + * Shift the `bitvector` left by `amount`. If `amount` is greater than the + * bitvector's length the bitvector will be zeroed out. + */ +export function shiftLeft(options: ShiftLeftOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64'] satisfies (string | null)[]; + const parameterNames = ['bitvector', 'amount']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'shift_left', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IsIndexSetArguments { + bitvector: RawTransactionArgument; + bitIndex: RawTransactionArgument; +} +export interface IsIndexSetOptions { + package?: string; + arguments: + | IsIndexSetArguments + | [ + bitvector: RawTransactionArgument, + bitIndex: RawTransactionArgument, + ]; +} +/** + * Return the value of the bit at `bit_index` in the `bitvector`. `true` represents + * "1" and `false` represents a 0 + */ +export function isIndexSet(options: IsIndexSetOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64'] satisfies (string | null)[]; + const parameterNames = ['bitvector', 'bitIndex']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'is_index_set', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LengthArguments { + bitvector: RawTransactionArgument; +} +export interface LengthOptions { + package?: string; + arguments: LengthArguments | [bitvector: RawTransactionArgument]; +} +/** Return the length (number of usable bits) of this bitvector */ +export function length(options: LengthOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['bitvector']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'length', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LongestSetSequenceStartingAtArguments { + bitvector: RawTransactionArgument; + startIndex: RawTransactionArgument; +} +export interface LongestSetSequenceStartingAtOptions { + package?: string; + arguments: + | LongestSetSequenceStartingAtArguments + | [ + bitvector: RawTransactionArgument, + startIndex: RawTransactionArgument, + ]; +} +/** + * Returns the length of the longest sequence of set bits starting at (and + * including) `start_index` in the `bitvector`. If there is no such sequence, then + * `0` is returned. + */ +export function longestSetSequenceStartingAt(options: LongestSetSequenceStartingAtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64'] satisfies (string | null)[]; + const parameterNames = ['bitvector', 'startIndex']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'bit_vector', + function: 'longest_set_sequence_starting_at', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/constants.ts b/packages/suins/src/contracts/suins_auction/constants.ts new file mode 100644 index 000000000..0d4af8f02 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/constants.ts @@ -0,0 +1,102 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +export interface VersionOptions { + package?: string; + arguments?: []; +} +/** Returns the current version of the auction contract */ +export function version(options: VersionOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'version', + }); +} +export interface BidExtendTimeOptions { + package?: string; + arguments?: []; +} +/** Returns the bid extend time in seconds */ +export function bidExtendTime(options: BidExtendTimeOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'bid_extend_time', + }); +} +export interface MaxPercentageOptions { + package?: string; + arguments?: []; +} +/** Returns the maximum percentage value */ +export function maxPercentage(options: MaxPercentageOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'max_percentage', + }); +} +export interface MinBidIncreasePercentageOptions { + package?: string; + arguments?: []; +} +/** Returns the minimum bid increase percentage */ +export function minBidIncreasePercentage(options: MinBidIncreasePercentageOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'min_bid_increase_percentage', + }); +} +export interface DefaultFeePercentageOptions { + package?: string; + arguments?: []; +} +/** Returns the default service fee percentage */ +export function defaultFeePercentage(options: DefaultFeePercentageOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'default_fee_percentage', + }); +} +export interface MinAuctionTimeOptions { + package?: string; + arguments?: []; +} +/** Returns the minimum auction time */ +export function minAuctionTime(options: MinAuctionTimeOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'min_auction_time', + }); +} +export interface MaxAuctionTimeOptions { + package?: string; + arguments?: []; +} +/** Returns the maximum auction time */ +export function maxAuctionTime(options: MaxAuctionTimeOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'constants', + function: 'max_auction_time', + }); +} diff --git a/packages/suins/src/contracts/suins_auction/debug.ts b/packages/suins/src/contracts/suins_auction/debug.ts new file mode 100644 index 000000000..776e09c36 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/debug.ts @@ -0,0 +1,43 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** Module providing debug functionality. */ + +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { type BcsType } from '@mysten/sui/bcs'; +export interface PrintArguments> { + x: RawTransactionArgument; +} +export interface PrintOptions> { + package?: string; + arguments: PrintArguments | [x: RawTransactionArgument]; + typeArguments: [string]; +} +export function print>(options: PrintOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'debug', + function: 'print', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface PrintStackTraceOptions { + package?: string; + arguments?: []; +} +export function printStackTrace(options: PrintStackTraceOptions = {}) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'debug', + function: 'print_stack_trace', + }); +} diff --git a/packages/suins/src/contracts/suins_auction/decryption.ts b/packages/suins/src/contracts/suins_auction/decryption.ts new file mode 100644 index 000000000..0505eeec1 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/decryption.ts @@ -0,0 +1,30 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface GetEncryptionIdArguments { + startTime: RawTransactionArgument; + domainName: RawTransactionArgument; +} +export interface GetEncryptionIdOptions { + package?: string; + arguments: + | GetEncryptionIdArguments + | [ + startTime: RawTransactionArgument, + domainName: RawTransactionArgument, + ]; +} +export function getEncryptionId(options: GetEncryptionIdOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'vector'] satisfies (string | null)[]; + const parameterNames = ['startTime', 'domainName']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'decryption', + function: 'get_encryption_id', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/deps/seal/bf_hmac_encryption.ts b/packages/suins/src/contracts/suins_auction/deps/seal/bf_hmac_encryption.ts new file mode 100644 index 000000000..20902c3b0 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/seal/bf_hmac_encryption.ts @@ -0,0 +1,30 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Implementation of decryption for Seal using Boneh-Franklin over BLS12-381 as KEM + * and Hmac256Ctr as DEM. Refer usage at docs + * https://seal-docs.wal.app/UsingSeal/#on-chain-decryption + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import * as group_ops from '../sui/group_ops.js'; +const $moduleName = 'seal::bf_hmac_encryption'; +export const EncryptedObject = new MoveStruct({ + name: `${$moduleName}::EncryptedObject`, + fields: { + package_id: bcs.Address, + id: bcs.vector(bcs.u8()), + indices: bcs.vector(bcs.u8()), + services: bcs.vector(bcs.Address), + threshold: bcs.u8(), + nonce: group_ops.Element, + encrypted_shares: bcs.vector(bcs.vector(bcs.u8())), + encrypted_randomness: bcs.vector(bcs.u8()), + blob: bcs.vector(bcs.u8()), + aad: bcs.option(bcs.vector(bcs.u8())), + mac: bcs.vector(bcs.u8()), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/std/type_name.ts b/packages/suins/src/contracts/suins_auction/deps/std/type_name.ts new file mode 100644 index 000000000..91bdc2a3c --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/std/type_name.ts @@ -0,0 +1,24 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** Functionality for converting Move types into values. Use with care! */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = 'std::type_name'; +export const TypeName = new MoveStruct({ + name: `${$moduleName}::TypeName`, + fields: { + /** + * String representation of the type. All types are represented using their source + * syntax: "u8", "u64", "bool", "address", "vector", and so on for primitive types. + * Struct types are represented as fully qualified type names; e.g. + * `00000000000000000000000000000001::string::String` or + * `0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2>` + * Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or + * 32 depending on the Move platform) + */ + name: bcs.string(), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/sui/bag.ts b/packages/suins/src/contracts/suins_auction/deps/sui/bag.ts new file mode 100644 index 000000000..f8966dc9e --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/sui/bag.ts @@ -0,0 +1,41 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * A bag is a heterogeneous map-like collection. The collection is similar to + * `sui::table` in that its keys and values are not stored within the `Bag` value, + * but instead are stored using Sui's object system. The `Bag` struct acts only as + * a handle into the object system to retrieve those keys and values. Note that + * this means that `Bag` values with exactly the same key-value mapping will not be + * equal, with `==`, at runtime. For example + * + * ``` + * let bag1 = bag::new(); + * let bag2 = bag::new(); + * bag::add(&mut bag1, 0, false); + * bag::add(&mut bag1, 1, true); + * bag::add(&mut bag2, 0, false); + * bag::add(&mut bag2, 1, true); + * // bag1 does not equal bag2, despite having the same entries + * assert!(&bag1 != &bag2); + * ``` + * + * At it's core, `sui::bag` is a wrapper around `UID` that allows for access to + * `sui::dynamic_field` while preventing accidentally stranding field values. A + * `UID` can be deleted, even if it has dynamic fields associated with it, but a + * bag, on the other hand, must be empty to be destroyed. + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = '0x2::bag'; +export const Bag = new MoveStruct({ + name: `${$moduleName}::Bag`, + fields: { + /** the ID of this bag */ + id: bcs.Address, + /** the number of key-value pairs in the bag */ + size: bcs.u64(), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/sui/balance.ts b/packages/suins/src/contracts/suins_auction/deps/sui/balance.ts new file mode 100644 index 000000000..e0018f41a --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/sui/balance.ts @@ -0,0 +1,19 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * A storable handler for Balances in general. Is used in the `Coin` module to + * allow balance operations and can be used to implement custom coins with `Supply` + * and `Balance`s. + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = '0x2::balance'; +export const Balance = new MoveStruct({ + name: `${$moduleName}::Balance`, + fields: { + value: bcs.u64(), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/sui/group_ops.ts b/packages/suins/src/contracts/suins_auction/deps/sui/group_ops.ts new file mode 100644 index 000000000..3c2c1f8d7 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/sui/group_ops.ts @@ -0,0 +1,15 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** Generic Move and native functions for group operations. */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = '0x2::group_ops'; +export const Element = new MoveStruct({ + name: `${$moduleName}::Element`, + fields: { + bytes: bcs.vector(bcs.u8()), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/sui/object_bag.ts b/packages/suins/src/contracts/suins_auction/deps/sui/object_bag.ts new file mode 100644 index 000000000..8e7d56db1 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/sui/object_bag.ts @@ -0,0 +1,24 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Similar to `sui::bag`, an `ObjectBag` is a heterogeneous map-like collection. + * But unlike `sui::bag`, the values bound to these dynamic fields _must_ be + * objects themselves. This allows for the objects to still exist in storage, which + * may be important for external tools. The difference is otherwise not observable + * from within Move. + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = '0x2::object_bag'; +export const ObjectBag = new MoveStruct({ + name: `${$moduleName}::ObjectBag`, + fields: { + /** the ID of this bag */ + id: bcs.Address, + /** the number of key-value pairs in the bag */ + size: bcs.u64(), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/sui/table.ts b/packages/suins/src/contracts/suins_auction/deps/sui/table.ts new file mode 100644 index 000000000..41e18b1d1 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/sui/table.ts @@ -0,0 +1,36 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * A table is a map-like collection. But unlike a traditional collection, it's keys + * and values are not stored within the `Table` value, but instead are stored using + * Sui's object system. The `Table` struct acts only as a handle into the object + * system to retrieve those keys and values. Note that this means that `Table` + * values with exactly the same key-value mapping will not be equal, with `==`, at + * runtime. For example + * + * ``` + * let table1 = table::new(); + * let table2 = table::new(); + * table::add(&mut table1, 0, false); + * table::add(&mut table1, 1, true); + * table::add(&mut table2, 0, false); + * table::add(&mut table2, 1, true); + * // table1 does not equal table2, despite having the same entries + * assert!(&table1 != &table2); + * ``` + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = '0x2::table'; +export const Table = new MoveStruct({ + name: `${$moduleName}::Table`, + fields: { + /** the ID of this table */ + id: bcs.Address, + /** the number of key-value pairs in the table */ + size: bcs.u64(), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/suins/domain.ts b/packages/suins/src/contracts/suins_auction/deps/suins/domain.ts new file mode 100644 index 000000000..8542ac7c3 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/suins/domain.ts @@ -0,0 +1,28 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Defines the `Domain` type and helper functions. + * + * Domains are structured similar to their web2 counterpart and the rules + * determining what a valid domain is can be found here: + * https://en.wikipedia.org/wiki/Domain_name#Domain_name_syntax + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +const $moduleName = 'suins::domain'; +export const Domain = new MoveStruct({ + name: `${$moduleName}::Domain`, + fields: { + /** + * Vector of labels that make up a domain. + * + * Labels are stored in reverse order such that the TLD is always in position `0`. + * e.g. domain "pay.name.sui" will be stored in the vector as ["sui", "name", + * "pay"]. + */ + labels: bcs.vector(bcs.string()), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/deps/suins/suins_registration.ts b/packages/suins/src/contracts/suins_auction/deps/suins/suins_registration.ts new file mode 100644 index 000000000..893c036c8 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/deps/suins/suins_registration.ts @@ -0,0 +1,33 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Handles creation of the `SuinsRegistration`s. Separates the logic of creating a + * `SuinsRegistration`. New `SuinsRegistration`s can be created only by the + * `registry` and this module is tightly coupled with it. + * + * When reviewing the module, make sure that: + * + * - mutable functions can't be called directly by the owner + * - all getters are public and take an immutable reference + */ + +import { MoveStruct } from '../../../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import * as domain from './domain.js'; +const $moduleName = 'suins::suins_registration'; +export const SuinsRegistration = new MoveStruct({ + name: `${$moduleName}::SuinsRegistration`, + fields: { + id: bcs.Address, + /** The parsed domain. */ + domain: domain.Domain, + /** The domain name that the NFT is for. */ + domain_name: bcs.string(), + /** Timestamp in milliseconds when this NFT expires. */ + expiration_timestamp_ms: bcs.u64(), + /** Short IPFS hash of the image to be displayed for the NFT. */ + image_url: bcs.string(), + }, +}); diff --git a/packages/suins/src/contracts/suins_auction/fixed_point32.ts b/packages/suins/src/contracts/suins_auction/fixed_point32.ts new file mode 100644 index 000000000..d0cfa51f5 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/fixed_point32.ts @@ -0,0 +1,171 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Defines a fixed-point numeric type with a 32-bit integer part and a 32-bit + * fractional part. + */ + +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::fixed_point32'; +export const FixedPoint32 = new MoveStruct({ + name: `${$moduleName}::FixedPoint32`, + fields: { + value: bcs.u64(), + }, +}); +export interface MultiplyU64Arguments { + val: RawTransactionArgument; + multiplier: RawTransactionArgument; +} +export interface MultiplyU64Options { + package?: string; + arguments: + | MultiplyU64Arguments + | [val: RawTransactionArgument, multiplier: RawTransactionArgument]; +} +/** + * Multiply a u64 integer by a fixed-point number, truncating any fractional part + * of the product. This will abort if the product overflows. + */ +export function multiplyU64(options: MultiplyU64Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', null] satisfies (string | null)[]; + const parameterNames = ['val', 'multiplier']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'fixed_point32', + function: 'multiply_u64', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideU64Arguments { + val: RawTransactionArgument; + divisor: RawTransactionArgument; +} +export interface DivideU64Options { + package?: string; + arguments: + | DivideU64Arguments + | [val: RawTransactionArgument, divisor: RawTransactionArgument]; +} +/** + * Divide a u64 integer by a fixed-point number, truncating any fractional part of + * the quotient. This will abort if the divisor is zero or if the quotient + * overflows. + */ +export function divideU64(options: DivideU64Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', null] satisfies (string | null)[]; + const parameterNames = ['val', 'divisor']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'fixed_point32', + function: 'divide_u64', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface CreateFromRationalArguments { + numerator: RawTransactionArgument; + denominator: RawTransactionArgument; +} +export interface CreateFromRationalOptions { + package?: string; + arguments: + | CreateFromRationalArguments + | [ + numerator: RawTransactionArgument, + denominator: RawTransactionArgument, + ]; +} +/** + * Create a fixed-point value from a rational number specified by its numerator and + * denominator. Calling this function should be preferred for using + * `Self::create_from_raw_value` which is also available. This will abort if the + * denominator is zero. It will also abort if the numerator is nonzero and the + * ratio is not in the range 2^-32 .. 2^32-1. When specifying decimal fractions, be + * careful about rounding errors: if you round to display N digits after the + * decimal point, you can use a denominator of 10^N to avoid numbers where the very + * small imprecision in the binary representation could change the rounding, e.g., + * 0.0125 will round down to 0.012 instead of up to 0.013. + */ +export function createFromRational(options: CreateFromRationalOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['numerator', 'denominator']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'fixed_point32', + function: 'create_from_rational', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface CreateFromRawValueArguments { + value: RawTransactionArgument; +} +export interface CreateFromRawValueOptions { + package?: string; + arguments: CreateFromRawValueArguments | [value: RawTransactionArgument]; +} +/** Create a fixedpoint value from a raw value. */ +export function createFromRawValue(options: CreateFromRawValueOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['value']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'fixed_point32', + function: 'create_from_raw_value', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GetRawValueArguments { + num: RawTransactionArgument; +} +export interface GetRawValueOptions { + package?: string; + arguments: GetRawValueArguments | [num: RawTransactionArgument]; +} +/** + * Accessor for the raw u64 value. Other less common operations, such as adding or + * subtracting FixedPoint32 values, can be done using the raw values directly. + */ +export function getRawValue(options: GetRawValueOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['num']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'fixed_point32', + function: 'get_raw_value', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IsZeroArguments { + num: RawTransactionArgument; +} +export interface IsZeroOptions { + package?: string; + arguments: IsZeroArguments | [num: RawTransactionArgument]; +} +/** Returns true if the ratio is zero. */ +export function isZero(options: IsZeroOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['num']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'fixed_point32', + function: 'is_zero', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/hash.ts b/packages/suins/src/contracts/suins_auction/hash.ts new file mode 100644 index 000000000..114c1955c --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/hash.ts @@ -0,0 +1,51 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Module which defines SHA hashes for byte vectors. + * + * The functions in this module are natively declared both in the Move runtime as + * in the Move prover's prelude. + */ + +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface Sha2_256Arguments { + data: RawTransactionArgument; +} +export interface Sha2_256Options { + package?: string; + arguments: Sha2_256Arguments | [data: RawTransactionArgument]; +} +export function sha2_256(options: Sha2_256Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector'] satisfies (string | null)[]; + const parameterNames = ['data']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'hash', + function: 'sha2_256', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface Sha3_256Arguments { + data: RawTransactionArgument; +} +export interface Sha3_256Options { + package?: string; + arguments: Sha3_256Arguments | [data: RawTransactionArgument]; +} +export function sha3_256(options: Sha3_256Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector'] satisfies (string | null)[]; + const parameterNames = ['data']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'hash', + function: 'sha3_256', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/internal.ts b/packages/suins/src/contracts/suins_auction/internal.ts new file mode 100644 index 000000000..2f9b2af96 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/internal.ts @@ -0,0 +1,59 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Defines the `Permit` type, which can be used to constrain the logic of a generic + * function to be authorized only by the module that defines the type parameter. + * + * ```move + * module example::use_permit; + * + * public struct MyType { /* ... *\/ } + * + * public fun test_permit() { + * let permit = internal::permit(); + * /* external_module::call_with_permit(permit); *\/ + * } + * ``` + * + * To write a function that is guarded by a `Permit`, require it as an argument. + * + * ```move + * // Silly mockup of a type registry where a type can be registered only by + * // the module that defines the type. + * module example::type_registry; + * + * public fun register_type(_: internal::Permit /* ... *\/) { + * /* ... *\/ + * } + * ``` + */ + +import { MoveTuple } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::internal'; +export const Permit = new MoveTuple({ + name: `${$moduleName}::Permit`, + fields: [bcs.bool()], +}); +export interface PermitOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** + * Construct a new `Permit` for the type `T`. Can only be called by the module that + * defines the type `T`. + */ +export function permit(options: PermitOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'internal', + function: 'permit', + typeArguments: options.typeArguments, + }); +} diff --git a/packages/suins/src/contracts/suins_auction/offer.ts b/packages/suins/src/contracts/suins_auction/offer.ts new file mode 100644 index 000000000..524a7fe12 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/offer.ts @@ -0,0 +1,423 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +import * as table from './deps/sui/table.js'; +import * as object_bag from './deps/sui/object_bag.js'; +import * as bag from './deps/sui/bag.js'; +import * as balance from './deps/sui/balance.js'; +import * as suins_registration from './deps/suins/suins_registration.js'; +import * as type_name from './deps/std/type_name.js'; +const $moduleName = '@suins/auction::offer'; +export const OfferTable = new MoveStruct({ + name: `${$moduleName}::OfferTable`, + fields: { + id: bcs.Address, + version: bcs.u64(), + table: table.Table, + listings: object_bag.ObjectBag, + allowed_tokens: table.Table, + service_fee: bcs.u64(), + /** Accumulated service fees for each token type */ + fees: bag.Bag, + }, +}); +export const Offer = new MoveStruct({ + name: `${$moduleName}::Offer`, + fields: { + balance: balance.Balance, + counter_offer: bcs.u64(), + expires_at: bcs.option(bcs.u64()), + }, +}); +export const Listing = new MoveStruct({ + name: `${$moduleName}::Listing`, + fields: { + id: bcs.Address, + owner: bcs.Address, + price: bcs.u64(), + expires_at: bcs.option(bcs.u64()), + suins_registration: suins_registration.SuinsRegistration, + }, +}); +export const OfferPlacedEvent = new MoveStruct({ + name: `${$moduleName}::OfferPlacedEvent`, + fields: { + domain_name: bcs.string(), + address: bcs.Address, + value: bcs.u64(), + token: type_name.TypeName, + expires_at: bcs.option(bcs.u64()), + }, +}); +export const OfferCancelledEvent = new MoveStruct({ + name: `${$moduleName}::OfferCancelledEvent`, + fields: { + domain_name: bcs.string(), + address: bcs.Address, + value: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const OfferAcceptedEvent = new MoveStruct({ + name: `${$moduleName}::OfferAcceptedEvent`, + fields: { + domain_name: bcs.string(), + owner: bcs.Address, + buyer: bcs.Address, + value: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const OfferDeclinedEvent = new MoveStruct({ + name: `${$moduleName}::OfferDeclinedEvent`, + fields: { + domain_name: bcs.string(), + owner: bcs.Address, + buyer: bcs.Address, + value: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const MakeCounterOfferEvent = new MoveStruct({ + name: `${$moduleName}::MakeCounterOfferEvent`, + fields: { + domain_name: bcs.string(), + owner: bcs.Address, + buyer: bcs.Address, + value: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const AcceptCounterOfferEvent = new MoveStruct({ + name: `${$moduleName}::AcceptCounterOfferEvent`, + fields: { + domain_name: bcs.string(), + buyer: bcs.Address, + value: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const ListingCreatedEvent = new MoveStruct({ + name: `${$moduleName}::ListingCreatedEvent`, + fields: { + listing_id: bcs.Address, + domain_name: bcs.string(), + owner: bcs.Address, + price: bcs.u64(), + expires_at: bcs.option(bcs.u64()), + token: type_name.TypeName, + }, +}); +export const ListingBoughtEvent = new MoveStruct({ + name: `${$moduleName}::ListingBoughtEvent`, + fields: { + listing_id: bcs.Address, + domain_name: bcs.string(), + buyer: bcs.Address, + amount: bcs.u64(), + token: type_name.TypeName, + }, +}); +export const ListingCancelledEvent = new MoveStruct({ + name: `${$moduleName}::ListingCancelledEvent`, + fields: { + listing_id: bcs.Address, + domain_name: bcs.string(), + owner: bcs.Address, + token: type_name.TypeName, + }, +}); +export interface PlaceOfferArguments { + suins: RawTransactionArgument; + offerTable: RawTransactionArgument; + domainName: RawTransactionArgument; + coin: RawTransactionArgument; + expiresAt: RawTransactionArgument; +} +export interface PlaceOfferOptions { + package?: string; + arguments: + | PlaceOfferArguments + | [ + suins: RawTransactionArgument, + offerTable: RawTransactionArgument, + domainName: RawTransactionArgument, + coin: RawTransactionArgument, + expiresAt: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Place an offer on a domain */ +export function placeOffer(options: PlaceOfferOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + null, + null, + '0x1::string::String', + null, + '0x1::option::Option', + '0x2::clock::Clock', + ] satisfies (string | null)[]; + const parameterNames = ['suins', 'offerTable', 'domainName', 'coin', 'expiresAt']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'place_offer', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface CancelOfferArguments { + offerTable: RawTransactionArgument; + domainName: RawTransactionArgument; +} +export interface CancelOfferOptions { + package?: string; + arguments: + | CancelOfferArguments + | [offerTable: RawTransactionArgument, domainName: RawTransactionArgument]; + typeArguments: [string]; +} +/** Cancel an offer on a domain */ +export function cancelOffer(options: CancelOfferOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, '0x1::string::String'] satisfies (string | null)[]; + const parameterNames = ['offerTable', 'domainName']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'cancel_offer', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface AcceptOfferArguments { + suins: RawTransactionArgument; + offerTable: RawTransactionArgument; + suinsRegistration: RawTransactionArgument; + address: RawTransactionArgument; +} +export interface AcceptOfferOptions { + package?: string; + arguments: + | AcceptOfferArguments + | [ + suins: RawTransactionArgument, + offerTable: RawTransactionArgument, + suinsRegistration: RawTransactionArgument, + address: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Accept an offer */ +export function acceptOffer(options: AcceptOfferOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, null, 'address', '0x2::clock::Clock'] satisfies ( + | string + | null + )[]; + const parameterNames = ['suins', 'offerTable', 'suinsRegistration', 'address']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'accept_offer', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface DeclineOfferArguments { + offerTable: RawTransactionArgument; + suinsRegistration: RawTransactionArgument; + address: RawTransactionArgument; +} +export interface DeclineOfferOptions { + package?: string; + arguments: + | DeclineOfferArguments + | [ + offerTable: RawTransactionArgument, + suinsRegistration: RawTransactionArgument, + address: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Decline an offer */ +export function declineOffer(options: DeclineOfferOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, 'address'] satisfies (string | null)[]; + const parameterNames = ['offerTable', 'suinsRegistration', 'address']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'decline_offer', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface MakeCounterOfferArguments { + offerTable: RawTransactionArgument; + suinsRegistration: RawTransactionArgument; + address: RawTransactionArgument; + counterOfferValue: RawTransactionArgument; +} +export interface MakeCounterOfferOptions { + package?: string; + arguments: + | MakeCounterOfferArguments + | [ + offerTable: RawTransactionArgument, + suinsRegistration: RawTransactionArgument, + address: RawTransactionArgument, + counterOfferValue: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Make a counter offer */ +export function makeCounterOffer(options: MakeCounterOfferOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, 'address', 'u64'] satisfies (string | null)[]; + const parameterNames = ['offerTable', 'suinsRegistration', 'address', 'counterOfferValue']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'make_counter_offer', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface AcceptCounterOfferArguments { + offerTable: RawTransactionArgument; + domainName: RawTransactionArgument; + coin: RawTransactionArgument; +} +export interface AcceptCounterOfferOptions { + package?: string; + arguments: + | AcceptCounterOfferArguments + | [ + offerTable: RawTransactionArgument, + domainName: RawTransactionArgument, + coin: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Accept a counter offer */ +export function acceptCounterOffer(options: AcceptCounterOfferOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, '0x1::string::String', null] satisfies (string | null)[]; + const parameterNames = ['offerTable', 'domainName', 'coin']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'accept_counter_offer', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface CreateListingArguments { + offerTable: RawTransactionArgument; + price: RawTransactionArgument; + expiresAt: RawTransactionArgument; + suinsRegistration: RawTransactionArgument; +} +export interface CreateListingOptions { + package?: string; + arguments: + | CreateListingArguments + | [ + offerTable: RawTransactionArgument, + price: RawTransactionArgument, + expiresAt: RawTransactionArgument, + suinsRegistration: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Create a listing for a domain with a fixed price */ +export function createListing(options: CreateListingOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + null, + 'u64', + '0x1::option::Option', + null, + '0x2::clock::Clock', + ] satisfies (string | null)[]; + const parameterNames = ['offerTable', 'price', 'expiresAt', 'suinsRegistration']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'create_listing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface BuyListingArguments { + suins: RawTransactionArgument; + offerTable: RawTransactionArgument; + domainName: RawTransactionArgument; + payment: RawTransactionArgument; +} +export interface BuyListingOptions { + package?: string; + arguments: + | BuyListingArguments + | [ + suins: RawTransactionArgument, + offerTable: RawTransactionArgument, + domainName: RawTransactionArgument, + payment: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** Buy a listing */ +export function buyListing(options: BuyListingOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null, '0x1::string::String', null, '0x2::clock::Clock'] satisfies ( + | string + | null + )[]; + const parameterNames = ['suins', 'offerTable', 'domainName', 'payment']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'buy_listing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface CancelListingArguments { + offerTable: RawTransactionArgument; + domainName: RawTransactionArgument; +} +export interface CancelListingOptions { + package?: string; + arguments: + | CancelListingArguments + | [offerTable: RawTransactionArgument, domainName: RawTransactionArgument]; + typeArguments: [string]; +} +/** Cancel a listing */ +export function cancelListing(options: CancelListingOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, '0x1::string::String'] satisfies (string | null)[]; + const parameterNames = ['offerTable', 'domainName']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'offer', + function: 'cancel_listing', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} diff --git a/packages/suins/src/contracts/suins_auction/option.ts b/packages/suins/src/contracts/suins_auction/option.ts new file mode 100644 index 000000000..0c9e1c330 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/option.ts @@ -0,0 +1,449 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * This module defines the Option type and its methods to represent and handle an + * optional value. + */ + +import { type BcsType, bcs } from '@mysten/sui/bcs'; +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::option'; +/** + * Abstraction of a value that may or may not be present. Implemented with a vector + * of size zero or one because Move bytecode does not have ADTs. + */ +export function Option>(...typeParameters: [Element]) { + return new MoveStruct({ + name: `${$moduleName}::Option<${typeParameters[0].name as Element['name']}>`, + fields: { + vec: bcs.vector(typeParameters[0]), + }, + }); +} +export interface NoneOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** Return an empty `Option` */ +export function none(options: NoneOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'none', + typeArguments: options.typeArguments, + }); +} +export interface SomeArguments> { + e: RawTransactionArgument; +} +export interface SomeOptions> { + package?: string; + arguments: SomeArguments | [e: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return an `Option` containing `e` */ +export function some>(options: SomeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'some', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface IsNoneArguments { + t: RawTransactionArgument; +} +export interface IsNoneOptions { + package?: string; + arguments: IsNoneArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return true if `t` does not hold a value */ +export function isNone(options: IsNoneOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'is_none', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface IsSomeArguments { + t: RawTransactionArgument; +} +export interface IsSomeOptions { + package?: string; + arguments: IsSomeArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return true if `t` holds a value */ +export function isSome(options: IsSomeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'is_some', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface ContainsArguments> { + t: RawTransactionArgument; + eRef: RawTransactionArgument; +} +export interface ContainsOptions> { + package?: string; + arguments: + | ContainsArguments + | [t: RawTransactionArgument, eRef: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return true if the value in `t` is equal to `e_ref` Always returns `false` if + * `t` does not hold a value + */ +export function contains>(options: ContainsOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'eRef']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'contains', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface BorrowArguments { + t: RawTransactionArgument; +} +export interface BorrowOptions { + package?: string; + arguments: BorrowArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return an immutable reference to the value inside `t` Aborts if `t` does not + * hold a value + */ +export function borrow(options: BorrowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'borrow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface BorrowWithDefaultArguments> { + t: RawTransactionArgument; + defaultRef: RawTransactionArgument; +} +export interface BorrowWithDefaultOptions> { + package?: string; + arguments: + | BorrowWithDefaultArguments + | [t: RawTransactionArgument, defaultRef: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return a reference to the value inside `t` if it holds one Return `default_ref` + * if `t` does not hold a value + */ +export function borrowWithDefault>( + options: BorrowWithDefaultOptions, +) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'defaultRef']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'borrow_with_default', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface GetWithDefaultArguments> { + t: RawTransactionArgument; + default: RawTransactionArgument; +} +export interface GetWithDefaultOptions> { + package?: string; + arguments: GetWithDefaultArguments | [t: RawTransactionArgument]; + default: RawTransactionArgument; + typeArguments: [string]; +} +/** + * Return the value inside `t` if it holds one Return `default` if `t` does not + * hold a value + */ +export function getWithDefault>( + options: GetWithDefaultOptions, +) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'default']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'get_with_default', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface FillArguments> { + t: RawTransactionArgument; + e: RawTransactionArgument; +} +export interface FillOptions> { + package?: string; + arguments: + | FillArguments + | [t: RawTransactionArgument, e: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Convert the none option `t` to a some option by adding `e`. Aborts if `t` + * already holds a value + */ +export function fill>(options: FillOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'fill', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface ExtractArguments { + t: RawTransactionArgument; +} +export interface ExtractOptions { + package?: string; + arguments: ExtractArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Convert a `some` option to a `none` by removing and returning the value stored + * inside `t` Aborts if `t` does not hold a value + */ +export function extract(options: ExtractOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'extract', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface BorrowMutArguments { + t: RawTransactionArgument; +} +export interface BorrowMutOptions { + package?: string; + arguments: BorrowMutArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return a mutable reference to the value inside `t` Aborts if `t` does not hold a + * value + */ +export function borrowMut(options: BorrowMutOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'borrow_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SwapArguments> { + t: RawTransactionArgument; + e: RawTransactionArgument; +} +export interface SwapOptions> { + package?: string; + arguments: + | SwapArguments + | [t: RawTransactionArgument, e: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Swap the old value inside `t` with `e` and return the old value Aborts if `t` + * does not hold a value + */ +export function swap>(options: SwapOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'swap', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SwapOrFillArguments> { + t: RawTransactionArgument; + e: RawTransactionArgument; +} +export interface SwapOrFillOptions> { + package?: string; + arguments: + | SwapOrFillArguments + | [t: RawTransactionArgument, e: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Swap the old value inside `t` with `e` and return the old value; or if there is + * no old value, fill it with `e`. Different from swap(), swap_or_fill() allows for + * `t` not holding a value. + */ +export function swapOrFill>(options: SwapOrFillOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'swap_or_fill', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface DestroyWithDefaultArguments> { + t: RawTransactionArgument; + default: RawTransactionArgument; +} +export interface DestroyWithDefaultOptions> { + package?: string; + arguments: DestroyWithDefaultArguments | [t: RawTransactionArgument]; + default: RawTransactionArgument; + typeArguments: [string]; +} +/** Destroys `t.` If `t` holds a value, return it. Returns `default` otherwise */ +export function destroyWithDefault>( + options: DestroyWithDefaultOptions, +) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, `${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['t', 'default']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'destroy_with_default', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface DestroySomeArguments { + t: RawTransactionArgument; +} +export interface DestroySomeOptions { + package?: string; + arguments: DestroySomeArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** Unpack `t` and return its contents Aborts if `t` does not hold a value */ +export function destroySome(options: DestroySomeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'destroy_some', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface DestroyNoneArguments { + t: RawTransactionArgument; +} +export interface DestroyNoneOptions { + package?: string; + arguments: DestroyNoneArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** Unpack `t` Aborts if `t` holds a value */ +export function destroyNone(options: DestroyNoneOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'destroy_none', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface ToVecArguments { + t: RawTransactionArgument; +} +export interface ToVecOptions { + package?: string; + arguments: ToVecArguments | [t: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Convert `t` into a vector of length 1 if it is `Some`, and an empty vector + * otherwise + */ +export function toVec(options: ToVecOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['t']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'option', + function: 'to_vec', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} diff --git a/packages/suins/src/contracts/suins_auction/string.ts b/packages/suins/src/contracts/suins_auction/string.ts new file mode 100644 index 000000000..221081c2b --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/string.ts @@ -0,0 +1,364 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * The `string` module defines the `String` type which represents UTF8 encoded + * strings. + */ + +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::string'; +export const String = new MoveStruct({ + name: `${$moduleName}::String`, + fields: { + bytes: bcs.vector(bcs.u8()), + }, +}); +export interface Utf8Arguments { + bytes: RawTransactionArgument; +} +export interface Utf8Options { + package?: string; + arguments: Utf8Arguments | [bytes: RawTransactionArgument]; +} +/** + * Creates a new string from a sequence of bytes. Aborts if the bytes do not + * represent valid utf8. + */ +export function utf8(options: Utf8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector'] satisfies (string | null)[]; + const parameterNames = ['bytes']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'utf8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface FromAsciiArguments { + s: RawTransactionArgument; +} +export interface FromAsciiOptions { + package?: string; + arguments: FromAsciiArguments | [s: RawTransactionArgument]; +} +/** Convert an ASCII string to a UTF8 string */ +export function fromAscii(options: FromAsciiOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'from_ascii', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToAsciiArguments { + s: RawTransactionArgument; +} +export interface ToAsciiOptions { + package?: string; + arguments: ToAsciiArguments | [s: RawTransactionArgument]; +} +/** Convert an UTF8 string to an ASCII string. Aborts if `s` is not valid ASCII */ +export function toAscii(options: ToAsciiOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'to_ascii', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryUtf8Arguments { + bytes: RawTransactionArgument; +} +export interface TryUtf8Options { + package?: string; + arguments: TryUtf8Arguments | [bytes: RawTransactionArgument]; +} +/** Tries to create a new string from a sequence of bytes. */ +export function tryUtf8(options: TryUtf8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['vector'] satisfies (string | null)[]; + const parameterNames = ['bytes']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'try_utf8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AsBytesArguments { + s: RawTransactionArgument; +} +export interface AsBytesOptions { + package?: string; + arguments: AsBytesArguments | [s: RawTransactionArgument]; +} +/** Returns a reference to the underlying byte vector. */ +export function asBytes(options: AsBytesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'as_bytes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntoBytesArguments { + s: RawTransactionArgument; +} +export interface IntoBytesOptions { + package?: string; + arguments: IntoBytesArguments | [s: RawTransactionArgument]; +} +/** Unpack the `string` to get its underlying bytes. */ +export function intoBytes(options: IntoBytesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'into_bytes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IsEmptyArguments { + s: RawTransactionArgument; +} +export interface IsEmptyOptions { + package?: string; + arguments: IsEmptyArguments | [s: RawTransactionArgument]; +} +/** Checks whether this string is empty. */ +export function isEmpty(options: IsEmptyOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'is_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LengthArguments { + s: RawTransactionArgument; +} +export interface LengthOptions { + package?: string; + arguments: LengthArguments | [s: RawTransactionArgument]; +} +/** Returns the length of this string, in bytes. */ +export function length(options: LengthOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'length', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AppendArguments { + s: RawTransactionArgument; + r: RawTransactionArgument; +} +export interface AppendOptions { + package?: string; + arguments: + | AppendArguments + | [s: RawTransactionArgument, r: RawTransactionArgument]; +} +/** Appends a string. */ +export function append(options: AppendOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['s', 'r']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'append', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AppendUtf8Arguments { + s: RawTransactionArgument; + bytes: RawTransactionArgument; +} +export interface AppendUtf8Options { + package?: string; + arguments: + | AppendUtf8Arguments + | [s: RawTransactionArgument, bytes: RawTransactionArgument]; +} +/** Appends bytes which must be in valid utf8 format. */ +export function appendUtf8(options: AppendUtf8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'vector'] satisfies (string | null)[]; + const parameterNames = ['s', 'bytes']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'append_utf8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface InsertArguments { + s: RawTransactionArgument; + at: RawTransactionArgument; + o: RawTransactionArgument; +} +export interface InsertOptions { + package?: string; + arguments: + | InsertArguments + | [ + s: RawTransactionArgument, + at: RawTransactionArgument, + o: RawTransactionArgument, + ]; +} +/** + * Insert the other string at the byte index in given string. The index must be at + * a valid utf8 char boundary. + */ +export function insert(options: InsertOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64', null] satisfies (string | null)[]; + const parameterNames = ['s', 'at', 'o']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'insert', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SubstringArguments { + s: RawTransactionArgument; + i: RawTransactionArgument; + j: RawTransactionArgument; +} +export interface SubstringOptions { + package?: string; + arguments: + | SubstringArguments + | [ + s: RawTransactionArgument, + i: RawTransactionArgument, + j: RawTransactionArgument, + ]; +} +/** + * Returns a sub-string using the given byte indices, where `i` is the first byte + * position and `j` is the start of the first byte not included (or the length of + * the string). The indices must be at valid utf8 char boundaries, guaranteeing + * that the result is valid utf8. + */ +export function substring(options: SubstringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['s', 'i', 'j']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'substring', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IndexOfArguments { + s: RawTransactionArgument; + r: RawTransactionArgument; +} +export interface IndexOfOptions { + package?: string; + arguments: + | IndexOfArguments + | [s: RawTransactionArgument, r: RawTransactionArgument]; +} +/** + * Computes the index of the first occurrence of a string. Returns `s.length()` if + * no occurrence found. + */ +export function indexOf(options: IndexOfOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['s', 'r']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'index_of', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface BytesArguments { + s: RawTransactionArgument; +} +export interface BytesOptions { + package?: string; + arguments: BytesArguments | [s: RawTransactionArgument]; +} +export function bytes(options: BytesOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['s']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'bytes', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SubStringArguments { + s: RawTransactionArgument; + i: RawTransactionArgument; + j: RawTransactionArgument; +} +export interface SubStringOptions { + package?: string; + arguments: + | SubStringArguments + | [ + s: RawTransactionArgument, + i: RawTransactionArgument, + j: RawTransactionArgument, + ]; +} +export function subString(options: SubStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, 'u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['s', 'i', 'j']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'string', + function: 'sub_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/type_name.ts b/packages/suins/src/contracts/suins_auction/type_name.ts new file mode 100644 index 000000000..e40f1033b --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/type_name.ts @@ -0,0 +1,298 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** Functionality for converting Move types into values. Use with care! */ + +import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { type Transaction } from '@mysten/sui/transactions'; +import * as ascii from './ascii.js'; +const $moduleName = '@suins/auction::type_name'; +export const TypeName = new MoveStruct({ + name: `${$moduleName}::TypeName`, + fields: { + /** + * String representation of the type. All types are represented using their source + * syntax: "u8", "u64", "bool", "address", "vector", and so on for primitive types. + * Struct types are represented as fully qualified type names; e.g. + * `00000000000000000000000000000001::string::String` or + * `0000000000000000000000000000000a::module_name1::type_name1<0000000000000000000000000000000a::module_name2::type_name2>` + * Addresses are hex-encoded lowercase values of length ADDRESS_LENGTH (16, 20, or + * 32 depending on the Move platform) + */ + name: ascii.String, + }, +}); +export interface WithDefiningIdsOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** + * Return a value representation of the type `T`. Package IDs that appear in fully + * qualified type names in the output from this function are defining IDs (the ID + * of the package in storage that first introduced the type). + */ +export function withDefiningIds(options: WithDefiningIdsOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'with_defining_ids', + typeArguments: options.typeArguments, + }); +} +export interface WithOriginalIdsOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** + * Return a value representation of the type `T`. Package IDs that appear in fully + * qualified type names in the output from this function are original IDs (the ID + * of the first version of the package, even if the type in question was introduced + * in a later upgrade). + */ +export function withOriginalIds(options: WithOriginalIdsOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'with_original_ids', + typeArguments: options.typeArguments, + }); +} +export interface DefiningIdOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** + * Like `with_defining_ids`, this accesses the package ID that original defined the + * type `T`. + */ +export function definingId(options: DefiningIdOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'defining_id', + typeArguments: options.typeArguments, + }); +} +export interface OriginalIdOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** + * Like `with_original_ids`, this accesses the original ID of the package that + * defines type `T`, even if the type was introduced in a later version of the + * package. + */ +export function originalId(options: OriginalIdOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'original_id', + typeArguments: options.typeArguments, + }); +} +export interface IsPrimitiveArguments { + self: RawTransactionArgument; +} +export interface IsPrimitiveOptions { + package?: string; + arguments: IsPrimitiveArguments | [self: RawTransactionArgument]; +} +/** + * Returns true iff the TypeName represents a primitive type, i.e. one of u8, u16, + * u32, u64, u128, u256, bool, address, vector. + */ +export function isPrimitive(options: IsPrimitiveOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'is_primitive', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AsStringArguments { + self: RawTransactionArgument; +} +export interface AsStringOptions { + package?: string; + arguments: AsStringArguments | [self: RawTransactionArgument]; +} +/** Get the String representation of `self` */ +export function asString(options: AsStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'as_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AddressStringArguments { + self: RawTransactionArgument; +} +export interface AddressStringOptions { + package?: string; + arguments: AddressStringArguments | [self: RawTransactionArgument]; +} +/** + * Get Address string (Base16 encoded), first part of the TypeName. Aborts if given + * a primitive type. + */ +export function addressString(options: AddressStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'address_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ModuleStringArguments { + self: RawTransactionArgument; +} +export interface ModuleStringOptions { + package?: string; + arguments: ModuleStringArguments | [self: RawTransactionArgument]; +} +/** Get name of the module. Aborts if given a primitive type. */ +export function moduleString(options: ModuleStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'module_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntoStringArguments { + self: RawTransactionArgument; +} +export interface IntoStringOptions { + package?: string; + arguments: IntoStringArguments | [self: RawTransactionArgument]; +} +/** Convert `self` into its inner String */ +export function intoString(options: IntoStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'into_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GetOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +export function get(options: GetOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'get', + typeArguments: options.typeArguments, + }); +} +export interface GetWithOriginalIdsOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +export function getWithOriginalIds(options: GetWithOriginalIdsOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'get_with_original_ids', + typeArguments: options.typeArguments, + }); +} +export interface BorrowStringArguments { + self: RawTransactionArgument; +} +export interface BorrowStringOptions { + package?: string; + arguments: BorrowStringArguments | [self: RawTransactionArgument]; +} +export function borrowString(options: BorrowStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'borrow_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GetAddressArguments { + self: RawTransactionArgument; +} +export interface GetAddressOptions { + package?: string; + arguments: GetAddressArguments | [self: RawTransactionArgument]; +} +export function getAddress(options: GetAddressOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'get_address', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GetModuleArguments { + self: RawTransactionArgument; +} +export interface GetModuleOptions { + package?: string; + arguments: GetModuleArguments | [self: RawTransactionArgument]; +} +export function getModule(options: GetModuleOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['self']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'type_name', + function: 'get_module', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/u128.ts b/packages/suins/src/contracts/suins_auction/u128.ts new file mode 100644 index 000000000..17ecce2b7 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/u128.ts @@ -0,0 +1,290 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface BitwiseNotArguments { + x: RawTransactionArgument; +} +export interface BitwiseNotOptions { + package?: string; + arguments: BitwiseNotArguments | [x: RawTransactionArgument]; +} +/** + * Returns the bitwise not of the value. Each bit that is 1 becomes 0. Each bit + * that is 0 becomes 1. + */ +export function bitwiseNot(options: BitwiseNotOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'bitwise_not', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MaxArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MaxOptions { + package?: string; + arguments: + | MaxArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the larger of `x` and `y` */ +export function max(options: MaxOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', 'u128'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MinArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MinOptions { + package?: string; + arguments: + | MinArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the smaller of `x` and `y` */ +export function min(options: MinOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', 'u128'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'min', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DiffArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DiffOptions { + package?: string; + arguments: + | DiffArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the absolute value of x - y */ +export function diff(options: DiffOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', 'u128'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideAndRoundUpArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DivideAndRoundUpOptions { + package?: string; + arguments: + | DivideAndRoundUpArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Calculate x / y, but round up the result. */ +export function divideAndRoundUp(options: DivideAndRoundUpOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', 'u128'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'divide_and_round_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PowArguments { + base: RawTransactionArgument; + exponent: RawTransactionArgument; +} +export interface PowOptions { + package?: string; + arguments: + | PowArguments + | [base: RawTransactionArgument, exponent: RawTransactionArgument]; +} +/** Return the value of a base raised to a power */ +export function pow(options: PowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', 'u8'] satisfies (string | null)[]; + const parameterNames = ['base', 'exponent']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'pow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SqrtArguments { + x: RawTransactionArgument; +} +export interface SqrtOptions { + package?: string; + arguments: SqrtArguments | [x: RawTransactionArgument]; +} +/** + * Get a nearest lower integer Square Root for `x`. Given that this function can + * only operate with integers, it is impossible to get perfect (or precise) integer + * square root for some numbers. + * + * Example: + * + * ``` + * math::sqrt(9) => 3 + * math::sqrt(8) => 2 // the nearest lower square root is 4; + * ``` + * + * In integer math, one of the possible ways to get results with more precision is + * to use higher values or temporarily multiply the value by some bigger number. + * Ideally if this is a square of 10 or 100. + * + * Example: + * + * ``` + * math::sqrt(8) => 2; + * math::sqrt(8 * 10000) => 282; + * // now we can use this value as if it was 2.82; + * // but to get the actual result, this value needs + * // to be divided by 100 (because sqrt(10000)). + * + * + * math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + * ``` + */ +export function sqrt(options: SqrtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'sqrt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU8Arguments { + x: RawTransactionArgument; +} +export interface TryAsU8Options { + package?: string; + arguments: TryAsU8Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u128` to a `u8`. Returns `None` if the value is too large. */ +export function tryAsU8(options: TryAsU8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'try_as_u8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU16Arguments { + x: RawTransactionArgument; +} +export interface TryAsU16Options { + package?: string; + arguments: TryAsU16Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u128` to a `u16`. Returns `None` if the value is too large. */ +export function tryAsU16(options: TryAsU16Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'try_as_u16', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU32Arguments { + x: RawTransactionArgument; +} +export interface TryAsU32Options { + package?: string; + arguments: TryAsU32Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u128` to a `u32`. Returns `None` if the value is too large. */ +export function tryAsU32(options: TryAsU32Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'try_as_u32', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU64Arguments { + x: RawTransactionArgument; +} +export interface TryAsU64Options { + package?: string; + arguments: TryAsU64Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u128` to a `u64`. Returns `None` if the value is too large. */ +export function tryAsU64(options: TryAsU64Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'try_as_u64', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToStringArguments { + x: RawTransactionArgument; +} +export interface ToStringOptions { + package?: string; + arguments: ToStringArguments | [x: RawTransactionArgument]; +} +export function toString(options: ToStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u128', + function: 'to_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/u16.ts b/packages/suins/src/contracts/suins_auction/u16.ts new file mode 100644 index 000000000..827fc4d75 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/u16.ts @@ -0,0 +1,224 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface BitwiseNotArguments { + x: RawTransactionArgument; +} +export interface BitwiseNotOptions { + package?: string; + arguments: BitwiseNotArguments | [x: RawTransactionArgument]; +} +/** + * Returns the bitwise not of the value. Each bit that is 1 becomes 0. Each bit + * that is 0 becomes 1. + */ +export function bitwiseNot(options: BitwiseNotOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'bitwise_not', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MaxArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MaxOptions { + package?: string; + arguments: MaxArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the larger of `x` and `y` */ +export function max(options: MaxOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16', 'u16'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MinArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MinOptions { + package?: string; + arguments: MinArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the smaller of `x` and `y` */ +export function min(options: MinOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16', 'u16'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'min', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DiffArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DiffOptions { + package?: string; + arguments: DiffArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the absolute value of x - y */ +export function diff(options: DiffOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16', 'u16'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideAndRoundUpArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DivideAndRoundUpOptions { + package?: string; + arguments: + | DivideAndRoundUpArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Calculate x / y, but round up the result. */ +export function divideAndRoundUp(options: DivideAndRoundUpOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16', 'u16'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'divide_and_round_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PowArguments { + base: RawTransactionArgument; + exponent: RawTransactionArgument; +} +export interface PowOptions { + package?: string; + arguments: + | PowArguments + | [base: RawTransactionArgument, exponent: RawTransactionArgument]; +} +/** Return the value of a base raised to a power */ +export function pow(options: PowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16', 'u8'] satisfies (string | null)[]; + const parameterNames = ['base', 'exponent']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'pow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SqrtArguments { + x: RawTransactionArgument; +} +export interface SqrtOptions { + package?: string; + arguments: SqrtArguments | [x: RawTransactionArgument]; +} +/** + * Get a nearest lower integer Square Root for `x`. Given that this function can + * only operate with integers, it is impossible to get perfect (or precise) integer + * square root for some numbers. + * + * Example: + * + * ``` + * math::sqrt(9) => 3 + * math::sqrt(8) => 2 // the nearest lower square root is 4; + * ``` + * + * In integer math, one of the possible ways to get results with more precision is + * to use higher values or temporarily multiply the value by some bigger number. + * Ideally if this is a square of 10 or 100. + * + * Example: + * + * ``` + * math::sqrt(8) => 2; + * math::sqrt(8 * 10000) => 282; + * // now we can use this value as if it was 2.82; + * // but to get the actual result, this value needs + * // to be divided by 100 (because sqrt(10000)). + * + * + * math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + * ``` + */ +export function sqrt(options: SqrtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'sqrt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU8Arguments { + x: RawTransactionArgument; +} +export interface TryAsU8Options { + package?: string; + arguments: TryAsU8Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u16` to a `u8`. Returns `None` if the value is too large. */ +export function tryAsU8(options: TryAsU8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'try_as_u8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToStringArguments { + x: RawTransactionArgument; +} +export interface ToStringOptions { + package?: string; + arguments: ToStringArguments | [x: RawTransactionArgument]; +} +export function toString(options: ToStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u16'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u16', + function: 'to_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/u256.ts b/packages/suins/src/contracts/suins_auction/u256.ts new file mode 100644 index 000000000..497aa3de6 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/u256.ts @@ -0,0 +1,262 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface BitwiseNotArguments { + x: RawTransactionArgument; +} +export interface BitwiseNotOptions { + package?: string; + arguments: BitwiseNotArguments | [x: RawTransactionArgument]; +} +/** + * Returns the bitwise not of the value. Each bit that is 1 becomes 0. Each bit + * that is 0 becomes 1. + */ +export function bitwiseNot(options: BitwiseNotOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'bitwise_not', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MaxArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MaxOptions { + package?: string; + arguments: + | MaxArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the larger of `x` and `y` */ +export function max(options: MaxOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256', 'u256'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MinArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MinOptions { + package?: string; + arguments: + | MinArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the smaller of `x` and `y` */ +export function min(options: MinOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256', 'u256'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'min', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DiffArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DiffOptions { + package?: string; + arguments: + | DiffArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the absolute value of x - y */ +export function diff(options: DiffOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256', 'u256'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideAndRoundUpArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DivideAndRoundUpOptions { + package?: string; + arguments: + | DivideAndRoundUpArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Calculate x / y, but round up the result. */ +export function divideAndRoundUp(options: DivideAndRoundUpOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256', 'u256'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'divide_and_round_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PowArguments { + base: RawTransactionArgument; + exponent: RawTransactionArgument; +} +export interface PowOptions { + package?: string; + arguments: + | PowArguments + | [base: RawTransactionArgument, exponent: RawTransactionArgument]; +} +/** Return the value of a base raised to a power */ +export function pow(options: PowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256', 'u8'] satisfies (string | null)[]; + const parameterNames = ['base', 'exponent']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'pow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU8Arguments { + x: RawTransactionArgument; +} +export interface TryAsU8Options { + package?: string; + arguments: TryAsU8Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u256` to a `u8`. Returns `None` if the value is too large. */ +export function tryAsU8(options: TryAsU8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'try_as_u8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU16Arguments { + x: RawTransactionArgument; +} +export interface TryAsU16Options { + package?: string; + arguments: TryAsU16Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u256` to a `u16`. Returns `None` if the value is too large. */ +export function tryAsU16(options: TryAsU16Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'try_as_u16', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU32Arguments { + x: RawTransactionArgument; +} +export interface TryAsU32Options { + package?: string; + arguments: TryAsU32Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u256` to a `u32`. Returns `None` if the value is too large. */ +export function tryAsU32(options: TryAsU32Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'try_as_u32', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU64Arguments { + x: RawTransactionArgument; +} +export interface TryAsU64Options { + package?: string; + arguments: TryAsU64Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u256` to a `u64`. Returns `None` if the value is too large. */ +export function tryAsU64(options: TryAsU64Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'try_as_u64', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU128Arguments { + x: RawTransactionArgument; +} +export interface TryAsU128Options { + package?: string; + arguments: TryAsU128Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u256` to a `u128`. Returns `None` if the value is too large. */ +export function tryAsU128(options: TryAsU128Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'try_as_u128', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToStringArguments { + x: RawTransactionArgument; +} +export interface ToStringOptions { + package?: string; + arguments: ToStringArguments | [x: RawTransactionArgument]; +} +export function toString(options: ToStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u256'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u256', + function: 'to_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/u32.ts b/packages/suins/src/contracts/suins_auction/u32.ts new file mode 100644 index 000000000..ac21a9825 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/u32.ts @@ -0,0 +1,244 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface BitwiseNotArguments { + x: RawTransactionArgument; +} +export interface BitwiseNotOptions { + package?: string; + arguments: BitwiseNotArguments | [x: RawTransactionArgument]; +} +/** + * Returns the bitwise not of the value. Each bit that is 1 becomes 0. Each bit + * that is 0 becomes 1. + */ +export function bitwiseNot(options: BitwiseNotOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'bitwise_not', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MaxArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MaxOptions { + package?: string; + arguments: MaxArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the larger of `x` and `y` */ +export function max(options: MaxOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32', 'u32'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MinArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MinOptions { + package?: string; + arguments: MinArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the smaller of `x` and `y` */ +export function min(options: MinOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32', 'u32'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'min', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DiffArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DiffOptions { + package?: string; + arguments: DiffArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the absolute value of x - y */ +export function diff(options: DiffOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32', 'u32'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideAndRoundUpArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DivideAndRoundUpOptions { + package?: string; + arguments: + | DivideAndRoundUpArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Calculate x / y, but round up the result. */ +export function divideAndRoundUp(options: DivideAndRoundUpOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32', 'u32'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'divide_and_round_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PowArguments { + base: RawTransactionArgument; + exponent: RawTransactionArgument; +} +export interface PowOptions { + package?: string; + arguments: + | PowArguments + | [base: RawTransactionArgument, exponent: RawTransactionArgument]; +} +/** Return the value of a base raised to a power */ +export function pow(options: PowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32', 'u8'] satisfies (string | null)[]; + const parameterNames = ['base', 'exponent']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'pow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SqrtArguments { + x: RawTransactionArgument; +} +export interface SqrtOptions { + package?: string; + arguments: SqrtArguments | [x: RawTransactionArgument]; +} +/** + * Get a nearest lower integer Square Root for `x`. Given that this function can + * only operate with integers, it is impossible to get perfect (or precise) integer + * square root for some numbers. + * + * Example: + * + * ``` + * math::sqrt(9) => 3 + * math::sqrt(8) => 2 // the nearest lower square root is 4; + * ``` + * + * In integer math, one of the possible ways to get results with more precision is + * to use higher values or temporarily multiply the value by some bigger number. + * Ideally if this is a square of 10 or 100. + * + * Example: + * + * ``` + * math::sqrt(8) => 2; + * math::sqrt(8 * 10000) => 282; + * // now we can use this value as if it was 2.82; + * // but to get the actual result, this value needs + * // to be divided by 100 (because sqrt(10000)). + * + * + * math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + * ``` + */ +export function sqrt(options: SqrtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'sqrt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU8Arguments { + x: RawTransactionArgument; +} +export interface TryAsU8Options { + package?: string; + arguments: TryAsU8Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u32` to a `u8`. Returns `None` if the value is too large. */ +export function tryAsU8(options: TryAsU8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'try_as_u8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU16Arguments { + x: RawTransactionArgument; +} +export interface TryAsU16Options { + package?: string; + arguments: TryAsU16Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u32` to a `u16`. Returns `None` if the value is too large. */ +export function tryAsU16(options: TryAsU16Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'try_as_u16', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToStringArguments { + x: RawTransactionArgument; +} +export interface ToStringOptions { + package?: string; + arguments: ToStringArguments | [x: RawTransactionArgument]; +} +export function toString(options: ToStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u32', + function: 'to_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/u64.ts b/packages/suins/src/contracts/suins_auction/u64.ts new file mode 100644 index 000000000..b5ff10cdf --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/u64.ts @@ -0,0 +1,270 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface BitwiseNotArguments { + x: RawTransactionArgument; +} +export interface BitwiseNotOptions { + package?: string; + arguments: BitwiseNotArguments | [x: RawTransactionArgument]; +} +/** + * Returns the bitwise not of the value. Each bit that is 1 becomes 0. Each bit + * that is 0 becomes 1. + */ +export function bitwiseNot(options: BitwiseNotOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'bitwise_not', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MaxArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MaxOptions { + package?: string; + arguments: + | MaxArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the larger of `x` and `y` */ +export function max(options: MaxOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MinArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MinOptions { + package?: string; + arguments: + | MinArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the smaller of `x` and `y` */ +export function min(options: MinOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'min', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DiffArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DiffOptions { + package?: string; + arguments: + | DiffArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the absolute value of x - y */ +export function diff(options: DiffOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideAndRoundUpArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DivideAndRoundUpOptions { + package?: string; + arguments: + | DivideAndRoundUpArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Calculate x / y, but round up the result. */ +export function divideAndRoundUp(options: DivideAndRoundUpOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'divide_and_round_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PowArguments { + base: RawTransactionArgument; + exponent: RawTransactionArgument; +} +export interface PowOptions { + package?: string; + arguments: + | PowArguments + | [base: RawTransactionArgument, exponent: RawTransactionArgument]; +} +/** Return the value of a base raised to a power */ +export function pow(options: PowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u8'] satisfies (string | null)[]; + const parameterNames = ['base', 'exponent']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'pow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SqrtArguments { + x: RawTransactionArgument; +} +export interface SqrtOptions { + package?: string; + arguments: SqrtArguments | [x: RawTransactionArgument]; +} +/** + * Get a nearest lower integer Square Root for `x`. Given that this function can + * only operate with integers, it is impossible to get perfect (or precise) integer + * square root for some numbers. + * + * Example: + * + * ``` + * math::sqrt(9) => 3 + * math::sqrt(8) => 2 // the nearest lower square root is 4; + * ``` + * + * In integer math, one of the possible ways to get results with more precision is + * to use higher values or temporarily multiply the value by some bigger number. + * Ideally if this is a square of 10 or 100. + * + * Example: + * + * ``` + * math::sqrt(8) => 2; + * math::sqrt(8 * 10000) => 282; + * // now we can use this value as if it was 2.82; + * // but to get the actual result, this value needs + * // to be divided by 100 (because sqrt(10000)). + * + * + * math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + * ``` + */ +export function sqrt(options: SqrtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'sqrt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU8Arguments { + x: RawTransactionArgument; +} +export interface TryAsU8Options { + package?: string; + arguments: TryAsU8Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u64` to a `u8`. Returns `None` if the value is too large. */ +export function tryAsU8(options: TryAsU8Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'try_as_u8', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU16Arguments { + x: RawTransactionArgument; +} +export interface TryAsU16Options { + package?: string; + arguments: TryAsU16Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u64` to a `u16`. Returns `None` if the value is too large. */ +export function tryAsU16(options: TryAsU16Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'try_as_u16', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface TryAsU32Arguments { + x: RawTransactionArgument; +} +export interface TryAsU32Options { + package?: string; + arguments: TryAsU32Arguments | [x: RawTransactionArgument]; +} +/** Try to convert a `u64` to a `u32`. Returns `None` if the value is too large. */ +export function tryAsU32(options: TryAsU32Options) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'try_as_u32', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToStringArguments { + x: RawTransactionArgument; +} +export interface ToStringOptions { + package?: string; + arguments: ToStringArguments | [x: RawTransactionArgument]; +} +export function toString(options: ToStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u64', + function: 'to_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/u8.ts b/packages/suins/src/contracts/suins_auction/u8.ts new file mode 100644 index 000000000..dd40568fc --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/u8.ts @@ -0,0 +1,204 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +export interface BitwiseNotArguments { + x: RawTransactionArgument; +} +export interface BitwiseNotOptions { + package?: string; + arguments: BitwiseNotArguments | [x: RawTransactionArgument]; +} +/** + * Returns the bitwise not of the value. Each bit that is 1 becomes 0. Each bit + * that is 0 becomes 1. + */ +export function bitwiseNot(options: BitwiseNotOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'bitwise_not', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MaxArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MaxOptions { + package?: string; + arguments: MaxArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the larger of `x` and `y` */ +export function max(options: MaxOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8', 'u8'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'max', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MinArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface MinOptions { + package?: string; + arguments: MinArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the smaller of `x` and `y` */ +export function min(options: MinOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8', 'u8'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'min', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DiffArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DiffOptions { + package?: string; + arguments: DiffArguments | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Return the absolute value of x - y */ +export function diff(options: DiffOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8', 'u8'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'diff', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivideAndRoundUpArguments { + x: RawTransactionArgument; + y: RawTransactionArgument; +} +export interface DivideAndRoundUpOptions { + package?: string; + arguments: + | DivideAndRoundUpArguments + | [x: RawTransactionArgument, y: RawTransactionArgument]; +} +/** Calculate x / y, but round up the result. */ +export function divideAndRoundUp(options: DivideAndRoundUpOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8', 'u8'] satisfies (string | null)[]; + const parameterNames = ['x', 'y']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'divide_and_round_up', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface PowArguments { + base: RawTransactionArgument; + exponent: RawTransactionArgument; +} +export interface PowOptions { + package?: string; + arguments: + | PowArguments + | [base: RawTransactionArgument, exponent: RawTransactionArgument]; +} +/** Return the value of a base raised to a power */ +export function pow(options: PowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8', 'u8'] satisfies (string | null)[]; + const parameterNames = ['base', 'exponent']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'pow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SqrtArguments { + x: RawTransactionArgument; +} +export interface SqrtOptions { + package?: string; + arguments: SqrtArguments | [x: RawTransactionArgument]; +} +/** + * Get a nearest lower integer Square Root for `x`. Given that this function can + * only operate with integers, it is impossible to get perfect (or precise) integer + * square root for some numbers. + * + * Example: + * + * ``` + * math::sqrt(9) => 3 + * math::sqrt(8) => 2 // the nearest lower square root is 4; + * ``` + * + * In integer math, one of the possible ways to get results with more precision is + * to use higher values or temporarily multiply the value by some bigger number. + * Ideally if this is a square of 10 or 100. + * + * Example: + * + * ``` + * math::sqrt(8) => 2; + * math::sqrt(8 * 10000) => 282; + * // now we can use this value as if it was 2.82; + * // but to get the actual result, this value needs + * // to be divided by 100 (because sqrt(10000)). + * + * + * math::sqrt(8 * 1000000) => 2828; // same as above, 2828 / 1000 (2.828) + * ``` + */ +export function sqrt(options: SqrtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'sqrt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToStringArguments { + x: RawTransactionArgument; +} +export interface ToStringOptions { + package?: string; + arguments: ToStringArguments | [x: RawTransactionArgument]; +} +export function toString(options: ToStringOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u8'] satisfies (string | null)[]; + const parameterNames = ['x']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'u8', + function: 'to_string', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/uq32_32.ts b/packages/suins/src/contracts/suins_auction/uq32_32.ts new file mode 100644 index 000000000..6c3878e55 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/uq32_32.ts @@ -0,0 +1,369 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Defines an unsigned, fixed-point numeric type with a 32-bit integer part and a + * 32-bit fractional part. The notation `uq32_32` and `UQ32_32` is based on + * [Q notation](). `q` indicates + * it a fixed-point number. The `u` prefix indicates it is unsigned. The `32_32` + * suffix indicates the number of bits, where the first number indicates the number + * of bits in the integer part, and the second the number of bits in the fractional + * part--in this case 32 bits for each. + */ + +import { MoveTuple, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::uq32_32'; +export const UQ32_32 = new MoveTuple({ name: `${$moduleName}::UQ32_32`, fields: [bcs.u64()] }); +export interface FromQuotientArguments { + numerator: RawTransactionArgument; + denominator: RawTransactionArgument; +} +export interface FromQuotientOptions { + package?: string; + arguments: + | FromQuotientArguments + | [ + numerator: RawTransactionArgument, + denominator: RawTransactionArgument, + ]; +} +/** + * Create a fixed-point value from a quotient specified by its numerator and + * denominator. `from_quotient` and `from_int` should be preferred over using + * `from_raw`. Unless the denominator is a power of two, fractions can not be + * represented accurately, so be careful about rounding errors. Aborts if the + * denominator is zero. Aborts if the input is non-zero but so small that it will + * be represented as zero, e.g. smaller than 2^{-32}. Aborts if the input is too + * large, e.g. larger than or equal to 2^32. + */ +export function fromQuotient(options: FromQuotientOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', 'u64'] satisfies (string | null)[]; + const parameterNames = ['numerator', 'denominator']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'from_quotient', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface FromIntArguments { + integer: RawTransactionArgument; +} +export interface FromIntOptions { + package?: string; + arguments: FromIntArguments | [integer: RawTransactionArgument]; +} +/** + * Create a fixed-point value from an integer. `from_int` and `from_quotient` + * should be preferred over using `from_raw`. + */ +export function fromInt(options: FromIntOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u32'] satisfies (string | null)[]; + const parameterNames = ['integer']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'from_int', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AddArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface AddOptions { + package?: string; + arguments: AddArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Add two fixed-point numbers, `a + b`. Aborts if the sum overflows. */ +export function add(options: AddOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'add', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SubArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface SubOptions { + package?: string; + arguments: SubArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Subtract two fixed-point numbers, `a - b`. Aborts if `a < b`. */ +export function sub(options: SubOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'sub', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MulArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface MulOptions { + package?: string; + arguments: MulArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** + * Multiply two fixed-point numbers, truncating any fractional part of the product. + * Aborts if the product overflows. + */ +export function mul(options: MulOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'mul', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface DivOptions { + package?: string; + arguments: DivArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** + * Divide two fixed-point numbers, truncating any fractional part of the quotient. + * Aborts if the divisor is zero. Aborts if the quotient overflows. + */ +export function div(options: DivOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'div', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToIntArguments { + a: RawTransactionArgument; +} +export interface ToIntOptions { + package?: string; + arguments: ToIntArguments | [a: RawTransactionArgument]; +} +/** Convert a fixed-point number to an integer, truncating any fractional part. */ +export function toInt(options: ToIntOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['a']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'to_int', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntMulArguments { + val: RawTransactionArgument; + multiplier: RawTransactionArgument; +} +export interface IntMulOptions { + package?: string; + arguments: + | IntMulArguments + | [val: RawTransactionArgument, multiplier: RawTransactionArgument]; +} +/** + * Multiply a `u64` integer by a fixed-point number, truncating any fractional part + * of the product. Aborts if the product overflows. + */ +export function intMul(options: IntMulOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', null] satisfies (string | null)[]; + const parameterNames = ['val', 'multiplier']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'int_mul', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntDivArguments { + val: RawTransactionArgument; + divisor: RawTransactionArgument; +} +export interface IntDivOptions { + package?: string; + arguments: + | IntDivArguments + | [val: RawTransactionArgument, divisor: RawTransactionArgument]; +} +/** + * Divide a `u64` integer by a fixed-point number, truncating any fractional part + * of the quotient. Aborts if the divisor is zero. Aborts if the quotient + * overflows. + */ +export function intDiv(options: IntDivOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64', null] satisfies (string | null)[]; + const parameterNames = ['val', 'divisor']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'int_div', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LeArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface LeOptions { + package?: string; + arguments: LeArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Less than or equal to. Returns `true` if and only if `a <= a`. */ +export function le(options: LeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'le', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LtArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface LtOptions { + package?: string; + arguments: LtArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Less than. Returns `true` if and only if `a < b`. */ +export function lt(options: LtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'lt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GeArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface GeOptions { + package?: string; + arguments: GeArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Greater than or equal to. Returns `true` if and only if `a >= b`. */ +export function ge(options: GeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'ge', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GtArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface GtOptions { + package?: string; + arguments: GtArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Greater than. Returns `true` if and only if `a > b`. */ +export function gt(options: GtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'gt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToRawArguments { + a: RawTransactionArgument; +} +export interface ToRawOptions { + package?: string; + arguments: ToRawArguments | [a: RawTransactionArgument]; +} +/** + * Accessor for the raw u64 value. Can be paired with `from_raw` to perform less + * common operations on the raw values directly. + */ +export function toRaw(options: ToRawOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['a']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'to_raw', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface FromRawArguments { + rawValue: RawTransactionArgument; +} +export interface FromRawOptions { + package?: string; + arguments: FromRawArguments | [rawValue: RawTransactionArgument]; +} +/** + * Accessor for the raw u64 value. Can be paired with `to_raw` to perform less + * common operations on the raw values directly. + */ +export function fromRaw(options: FromRawOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['rawValue']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq32_32', + function: 'from_raw', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/uq64_64.ts b/packages/suins/src/contracts/suins_auction/uq64_64.ts new file mode 100644 index 000000000..a0afaef7e --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/uq64_64.ts @@ -0,0 +1,369 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * Defines an unsigned, fixed-point numeric type with a 64-bit integer part and a + * 64-bit fractional part. The notation `uq64_64` and `UQ64_64` is based on + * [Q notation](). `q` indicates + * it a fixed-point number. The `u` prefix indicates it is unsigned. The `64_64` + * suffix indicates the number of bits, where the first number indicates the number + * of bits in the integer part, and the second the number of bits in the fractional + * part--in this case 64 bits for each. + */ + +import { MoveTuple, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { bcs } from '@mysten/sui/bcs'; +import { type Transaction } from '@mysten/sui/transactions'; +const $moduleName = '@suins/auction::uq64_64'; +export const UQ64_64 = new MoveTuple({ name: `${$moduleName}::UQ64_64`, fields: [bcs.u128()] }); +export interface FromQuotientArguments { + numerator: RawTransactionArgument; + denominator: RawTransactionArgument; +} +export interface FromQuotientOptions { + package?: string; + arguments: + | FromQuotientArguments + | [ + numerator: RawTransactionArgument, + denominator: RawTransactionArgument, + ]; +} +/** + * Create a fixed-point value from a quotient specified by its numerator and + * denominator. `from_quotient` and `from_int` should be preferred over using + * `from_raw`. Unless the denominator is a power of two, fractions can not be + * represented accurately, so be careful about rounding errors. Aborts if the + * denominator is zero. Aborts if the input is non-zero but so small that it will + * be represented as zero, e.g. smaller than 2^{-64}. Aborts if the input is too + * large, e.g. larger than or equal to 2^64. + */ +export function fromQuotient(options: FromQuotientOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', 'u128'] satisfies (string | null)[]; + const parameterNames = ['numerator', 'denominator']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'from_quotient', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface FromIntArguments { + integer: RawTransactionArgument; +} +export interface FromIntOptions { + package?: string; + arguments: FromIntArguments | [integer: RawTransactionArgument]; +} +/** + * Create a fixed-point value from an integer. `from_int` and `from_quotient` + * should be preferred over using `from_raw`. + */ +export function fromInt(options: FromIntOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u64'] satisfies (string | null)[]; + const parameterNames = ['integer']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'from_int', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface AddArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface AddOptions { + package?: string; + arguments: AddArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Add two fixed-point numbers, `a + b`. Aborts if the sum overflows. */ +export function add(options: AddOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'add', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface SubArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface SubOptions { + package?: string; + arguments: SubArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Subtract two fixed-point numbers, `a - b`. Aborts if `a < b`. */ +export function sub(options: SubOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'sub', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface MulArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface MulOptions { + package?: string; + arguments: MulArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** + * Multiply two fixed-point numbers, truncating any fractional part of the product. + * Aborts if the product overflows. + */ +export function mul(options: MulOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'mul', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface DivArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface DivOptions { + package?: string; + arguments: DivArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** + * Divide two fixed-point numbers, truncating any fractional part of the quotient. + * Aborts if the divisor is zero. Aborts if the quotient overflows. + */ +export function div(options: DivOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'div', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToIntArguments { + a: RawTransactionArgument; +} +export interface ToIntOptions { + package?: string; + arguments: ToIntArguments | [a: RawTransactionArgument]; +} +/** Convert a fixed-point number to an integer, truncating any fractional part. */ +export function toInt(options: ToIntOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['a']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'to_int', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntMulArguments { + val: RawTransactionArgument; + multiplier: RawTransactionArgument; +} +export interface IntMulOptions { + package?: string; + arguments: + | IntMulArguments + | [val: RawTransactionArgument, multiplier: RawTransactionArgument]; +} +/** + * Multiply a `u128` integer by a fixed-point number, truncating any fractional + * part of the product. Aborts if the product overflows. + */ +export function intMul(options: IntMulOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', null] satisfies (string | null)[]; + const parameterNames = ['val', 'multiplier']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'int_mul', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface IntDivArguments { + val: RawTransactionArgument; + divisor: RawTransactionArgument; +} +export interface IntDivOptions { + package?: string; + arguments: + | IntDivArguments + | [val: RawTransactionArgument, divisor: RawTransactionArgument]; +} +/** + * Divide a `u128` integer by a fixed-point number, truncating any fractional part + * of the quotient. Aborts if the divisor is zero. Aborts if the quotient + * overflows. + */ +export function intDiv(options: IntDivOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128', null] satisfies (string | null)[]; + const parameterNames = ['val', 'divisor']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'int_div', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LeArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface LeOptions { + package?: string; + arguments: LeArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Less than or equal to. Returns `true` if and only if `a <= a`. */ +export function le(options: LeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'le', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface LtArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface LtOptions { + package?: string; + arguments: LtArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Less than. Returns `true` if and only if `a < b`. */ +export function lt(options: LtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'lt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GeArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface GeOptions { + package?: string; + arguments: GeArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Greater than or equal to. Returns `true` if and only if `a >= b`. */ +export function ge(options: GeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'ge', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface GtArguments { + a: RawTransactionArgument; + b: RawTransactionArgument; +} +export interface GtOptions { + package?: string; + arguments: GtArguments | [a: RawTransactionArgument, b: RawTransactionArgument]; +} +/** Greater than. Returns `true` if and only if `a > b`. */ +export function gt(options: GtOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null, null] satisfies (string | null)[]; + const parameterNames = ['a', 'b']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'gt', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface ToRawArguments { + a: RawTransactionArgument; +} +export interface ToRawOptions { + package?: string; + arguments: ToRawArguments | [a: RawTransactionArgument]; +} +/** + * Accessor for the raw u128 value. Can be paired with `from_raw` to perform less + * common operations on the raw values directly. + */ +export function toRaw(options: ToRawOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [null] satisfies (string | null)[]; + const parameterNames = ['a']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'to_raw', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} +export interface FromRawArguments { + rawValue: RawTransactionArgument; +} +export interface FromRawOptions { + package?: string; + arguments: FromRawArguments | [rawValue: RawTransactionArgument]; +} +/** + * Accessor for the raw u128 value. Can be paired with `to_raw` to perform less + * common operations on the raw values directly. + */ +export function fromRaw(options: FromRawOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = ['u128'] satisfies (string | null)[]; + const parameterNames = ['rawValue']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'uq64_64', + function: 'from_raw', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + }); +} diff --git a/packages/suins/src/contracts/suins_auction/vector.ts b/packages/suins/src/contracts/suins_auction/vector.ts new file mode 100644 index 000000000..68cdc0017 --- /dev/null +++ b/packages/suins/src/contracts/suins_auction/vector.ts @@ -0,0 +1,548 @@ +/************************************************************** + * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED * + **************************************************************/ + +/** + * A variable-sized container that can hold any type. Indexing is 0-based, and + * vectors are growable. This module has many native functions. + */ + +import { type Transaction } from '@mysten/sui/transactions'; +import { normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js'; +import { type BcsType } from '@mysten/sui/bcs'; +export interface EmptyOptions { + package?: string; + arguments?: []; + typeArguments: [string]; +} +/** Create an empty vector. */ +export function empty(options: EmptyOptions) { + const packageAddress = options.package ?? '@suins/auction'; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'empty', + typeArguments: options.typeArguments, + }); +} +export interface LengthArguments> { + v: RawTransactionArgument; +} +export interface LengthOptions> { + package?: string; + arguments: LengthArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return the length of the vector. */ +export function length>(options: LengthOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`] satisfies (string | null)[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'length', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface BorrowArguments> { + v: RawTransactionArgument; + i: RawTransactionArgument; +} +export interface BorrowOptions> { + package?: string; + arguments: + | BorrowArguments + | [v: RawTransactionArgument, i: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Acquire an immutable reference to the `i`th element of the vector `v`. Aborts if + * `i` is out of bounds. + */ +export function borrow>(options: BorrowOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64'] satisfies (string | null)[]; + const parameterNames = ['v', 'i']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'borrow', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface PushBackArguments> { + v: RawTransactionArgument; + e: RawTransactionArgument; +} +export interface PushBackOptions> { + package?: string; + arguments: + | PushBackArguments + | [v: RawTransactionArgument, e: RawTransactionArgument]; + typeArguments: [string]; +} +/** Add element `e` to the end of the vector `v`. */ +export function pushBack>(options: PushBackOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + `vector<${options.typeArguments[0]}>`, + `${options.typeArguments[0]}`, + ] satisfies (string | null)[]; + const parameterNames = ['v', 'e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'push_back', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface BorrowMutArguments> { + v: RawTransactionArgument; + i: RawTransactionArgument; +} +export interface BorrowMutOptions> { + package?: string; + arguments: + | BorrowMutArguments + | [v: RawTransactionArgument, i: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return a mutable reference to the `i`th element in the vector `v`. Aborts if `i` + * is out of bounds. + */ +export function borrowMut>(options: BorrowMutOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64'] satisfies (string | null)[]; + const parameterNames = ['v', 'i']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'borrow_mut', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface PopBackArguments> { + v: RawTransactionArgument; +} +export interface PopBackOptions> { + package?: string; + arguments: PopBackArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** Pop an element from the end of vector `v`. Aborts if `v` is empty. */ +export function popBack>(options: PopBackOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`] satisfies (string | null)[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'pop_back', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface DestroyEmptyArguments> { + v: RawTransactionArgument; +} +export interface DestroyEmptyOptions> { + package?: string; + arguments: DestroyEmptyArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** Destroy the vector `v`. Aborts if `v` is not empty. */ +export function destroyEmpty>(options: DestroyEmptyOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`] satisfies (string | null)[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'destroy_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SwapArguments> { + v: RawTransactionArgument; + i: RawTransactionArgument; + j: RawTransactionArgument; +} +export interface SwapOptions> { + package?: string; + arguments: + | SwapArguments + | [ + v: RawTransactionArgument, + i: RawTransactionArgument, + j: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** + * Swaps the elements at the `i`th and `j`th indices in the vector `v`. Aborts if + * `i` or `j` is out of bounds. + */ +export function swap>(options: SwapOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64', 'u64'] satisfies ( + | string + | null + )[]; + const parameterNames = ['v', 'i', 'j']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'swap', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SingletonArguments> { + e: RawTransactionArgument; +} +export interface SingletonOptions> { + package?: string; + arguments: SingletonArguments | [e: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return an vector of size one containing element `e`. */ +export function singleton>(options: SingletonOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`${options.typeArguments[0]}`] satisfies (string | null)[]; + const parameterNames = ['e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'singleton', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface ReverseArguments> { + v: RawTransactionArgument; +} +export interface ReverseOptions> { + package?: string; + arguments: ReverseArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** Reverses the order of the elements in the vector `v` in place. */ +export function reverse>(options: ReverseOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`] satisfies (string | null)[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'reverse', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface AppendArguments> { + lhs: RawTransactionArgument; + other: RawTransactionArgument; +} +export interface AppendOptions> { + package?: string; + arguments: + | AppendArguments + | [lhs: RawTransactionArgument, other: RawTransactionArgument]; + typeArguments: [string]; +} +/** Pushes all of the elements of the `other` vector into the `lhs` vector. */ +export function append>(options: AppendOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + `vector<${options.typeArguments[0]}>`, + `vector<${options.typeArguments[0]}>`, + ] satisfies (string | null)[]; + const parameterNames = ['lhs', 'other']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'append', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface IsEmptyArguments> { + v: RawTransactionArgument; +} +export interface IsEmptyOptions> { + package?: string; + arguments: IsEmptyArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return `true` if the vector `v` has no elements and `false` otherwise. */ +export function isEmpty>(options: IsEmptyOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`] satisfies (string | null)[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'is_empty', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface ContainsArguments> { + v: RawTransactionArgument; + e: RawTransactionArgument; +} +export interface ContainsOptions> { + package?: string; + arguments: + | ContainsArguments + | [v: RawTransactionArgument, e: RawTransactionArgument]; + typeArguments: [string]; +} +/** Return true if `e` is in the vector `v`. Otherwise, returns false. */ +export function contains>(options: ContainsOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + `vector<${options.typeArguments[0]}>`, + `${options.typeArguments[0]}`, + ] satisfies (string | null)[]; + const parameterNames = ['v', 'e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'contains', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface IndexOfArguments> { + v: RawTransactionArgument; + e: RawTransactionArgument; +} +export interface IndexOfOptions> { + package?: string; + arguments: + | IndexOfArguments + | [v: RawTransactionArgument, e: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return `(true, i)` if `e` is in the vector `v` at index `i`. Otherwise, returns + * `(false, 0)`. + */ +export function indexOf>(options: IndexOfOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + `vector<${options.typeArguments[0]}>`, + `${options.typeArguments[0]}`, + ] satisfies (string | null)[]; + const parameterNames = ['v', 'e']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'index_of', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface RemoveArguments> { + v: RawTransactionArgument; + i: RawTransactionArgument; +} +export interface RemoveOptions> { + package?: string; + arguments: + | RemoveArguments + | [v: RawTransactionArgument, i: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Remove the `i`th element of the vector `v`, shifting all subsequent elements. + * This is O(n) and preserves ordering of elements in the vector. Aborts if `i` is + * out of bounds. + */ +export function remove>(options: RemoveOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64'] satisfies (string | null)[]; + const parameterNames = ['v', 'i']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'remove', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface InsertArguments> { + v: RawTransactionArgument; + e: RawTransactionArgument; + i: RawTransactionArgument; +} +export interface InsertOptions> { + package?: string; + arguments: + | InsertArguments + | [ + v: RawTransactionArgument, + e: RawTransactionArgument, + i: RawTransactionArgument, + ]; + typeArguments: [string]; +} +/** + * Insert `e` at position `i` in the vector `v`. If `i` is in bounds, this shifts + * the old `v[i]` and all subsequent elements to the right. If `i == v.length()`, + * this adds `e` to the end of the vector. This is O(n) and preserves ordering of + * elements in the vector. Aborts if `i > v.length()` + */ +export function insert>(options: InsertOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [ + `vector<${options.typeArguments[0]}>`, + `${options.typeArguments[0]}`, + 'u64', + ] satisfies (string | null)[]; + const parameterNames = ['v', 'e', 'i']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'insert', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SwapRemoveArguments> { + v: RawTransactionArgument; + i: RawTransactionArgument; +} +export interface SwapRemoveOptions> { + package?: string; + arguments: + | SwapRemoveArguments + | [v: RawTransactionArgument, i: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Swap the `i`th element of the vector `v` with the last element and then pop the + * vector. This is O(1), but does not preserve ordering of elements in the vector. + * Aborts if `i` is out of bounds. + */ +export function swapRemove>(options: SwapRemoveOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64'] satisfies (string | null)[]; + const parameterNames = ['v', 'i']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'swap_remove', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface SkipArguments> { + v: RawTransactionArgument; + n: RawTransactionArgument; +} +export interface SkipOptions> { + package?: string; + arguments: + | SkipArguments + | [v: RawTransactionArgument, n: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Return a new vector containing the elements of `v` except the first `n` + * elements. If `n > length`, returns an empty vector. + */ +export function skip>(options: SkipOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64'] satisfies (string | null)[]; + const parameterNames = ['v', 'n']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'skip', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface TakeArguments> { + v: RawTransactionArgument; + n: RawTransactionArgument; +} +export interface TakeOptions> { + package?: string; + arguments: + | TakeArguments + | [v: RawTransactionArgument, n: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Take the first `n` elements of the vector `v` and drop the rest. Aborts if `n` + * is greater than the length of `v`. + */ +export function take>(options: TakeOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector<${options.typeArguments[0]}>`, 'u64'] satisfies (string | null)[]; + const parameterNames = ['v', 'n']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'take', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} +export interface FlattenArguments> { + v: RawTransactionArgument; +} +export interface FlattenOptions> { + package?: string; + arguments: FlattenArguments | [v: RawTransactionArgument]; + typeArguments: [string]; +} +/** + * Concatenate the vectors of `v` into a single vector, keeping the order of the + * elements. + */ +export function flatten>(options: FlattenOptions) { + const packageAddress = options.package ?? '@suins/auction'; + const argumentsTypes = [`vector>`] satisfies ( + | string + | null + )[]; + const parameterNames = ['v']; + return (tx: Transaction) => + tx.moveCall({ + package: packageAddress, + module: 'vector', + function: 'flatten', + arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames), + typeArguments: options.typeArguments, + }); +} diff --git a/packages/suins/src/index.ts b/packages/suins/src/index.ts index 3215e8fad..b377f716e 100644 --- a/packages/suins/src/index.ts +++ b/packages/suins/src/index.ts @@ -2,7 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 export { suins, SuinsClient, type SuinsExtensionOptions } from './suins-client.js'; export { SuinsTransaction } from './suins-transaction.js'; -export type { SuinsClientConfig, PackageInfo } from './types.js'; +export { SuinsMarketplaceTransaction } from './suins-marketplace-transaction.js'; +export type { + SuinsClientConfig, + PackageInfo, + MarketplacePackageInfo, + CreateListingParams, + BuyListingParams, + CancelListingParams, + PlaceOfferParams, + CancelOfferParams, + AcceptOfferParams, + DeclineOfferParams, + MakeCounterOfferParams, + AcceptCounterOfferParams, + CreateAuctionParams, + PlaceBidParams, + FinalizeAuctionParams, + CancelAuctionParams, + SealApproveParams, +} from './types.js'; export { ALLOWED_METADATA, mainPackage } from './constants.js'; export { isSubName, diff --git a/packages/suins/src/suins-marketplace-transaction.ts b/packages/suins/src/suins-marketplace-transaction.ts new file mode 100644 index 000000000..90e08e89d --- /dev/null +++ b/packages/suins/src/suins-marketplace-transaction.ts @@ -0,0 +1,466 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions'; +import { normalizeSuiNSName } from '@mysten/sui/utils'; + +import * as auction from './contracts/suins_auction/auction.js'; +import * as offer from './contracts/suins_auction/offer.js'; +import type { SuinsClient } from './suins-client.js'; +import type { + AcceptCounterOfferParams, + AcceptOfferParams, + BuyListingParams, + CancelAuctionParams, + CancelListingParams, + CancelOfferParams, + CreateAuctionParams, + CreateListingParams, + DeclineOfferParams, + FinalizeAuctionParams, + MakeCounterOfferParams, + PlaceBidParams, + PlaceOfferParams, + SealApproveParams, +} from './types.js'; + +export class SuinsMarketplaceTransaction { + suinsClient: SuinsClient; + transaction: Transaction; + + constructor(client: SuinsClient, transaction: Transaction) { + this.suinsClient = client; + this.transaction = transaction; + + if (!this.suinsClient.config.marketplace) { + throw new Error( + 'Marketplace config not found. Make sure marketplace is configured for your network.', + ); + } + } + + private get marketplaceConfig() { + return this.suinsClient.config.marketplace!; + } + + /** + * Creates a fixed-price listing for a SuiNS domain. + * + * The caller must own the SuinsRegistration NFT being listed. + * The domain must not be expired, and if an expiry is set, + * the domain must not expire before the listing does. + * + * @param params - The listing parameters + * @param params.coinType - The coin type to price the listing in (e.g. '0x2::sui::SUI') + * @param params.price - The fixed price in base units of the coin + * @param params.expiresAt - Optional expiration timestamp in seconds + * @param params.suinsRegistration - The SuinsRegistration NFT to list + */ + createListing(params: CreateListingParams): void { + const config = this.marketplaceConfig; + + this.transaction.add( + offer.createListing({ + package: config.packageId, + arguments: { + offerTable: config.offerTableId, + price: params.price, + expiresAt: params.expiresAt ?? null, + suinsRegistration: params.suinsRegistration as string, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Buys a listed domain at the fixed listing price. + * + * The payment coin must match the listing price exactly. + * The domain NFT is transferred to the buyer, and the + * payment (minus service fee) goes to the listing owner. + * + * @param params - The buy parameters + * @param params.coinType - The coin type the listing is priced in + * @param params.domainName - The domain name (e.g. 'example.sui') + * @param params.payment - The payment coin object + * @returns The SuinsRegistration NFT as a TransactionObjectArgument + */ + buyListing(params: BuyListingParams): TransactionObjectArgument { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + return this.transaction.add( + offer.buyListing({ + package: config.packageId, + arguments: { + suins: this.suinsClient.config.suins, + offerTable: config.offerTableId, + domainName, + payment: params.payment as string, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Cancels an active listing and returns the domain NFT to the owner. + * + * Only the original listing owner can cancel a listing. + * + * @param params - The cancel parameters + * @param params.coinType - The coin type the listing was created with + * @param params.domainName - The domain name to cancel the listing for + * @returns The SuinsRegistration NFT as a TransactionObjectArgument + */ + cancelListing(params: CancelListingParams): TransactionObjectArgument { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + return this.transaction.add( + offer.cancelListing({ + package: config.packageId, + arguments: { + offerTable: config.offerTableId, + domainName, + }, + typeArguments: [params.coinType], + }), + ); + } + + // ─── Offers ────────────────────────────────────────────────────── + + /** + * Places an offer on a registered domain. + * + * The domain must exist and not be expired. The caller attaches a payment + * coin as the offer value. An optional expiration timestamp can be set. + * + * @param params.coinType - The coin type for the offer + * @param params.domainName - The domain name to make an offer on + * @param params.coin - The payment coin for the offer + * @param params.expiresAt - Optional expiration timestamp in seconds + */ + placeOffer(params: PlaceOfferParams): void { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + this.transaction.add( + offer.placeOffer({ + package: config.packageId, + arguments: { + suins: this.suinsClient.config.suins, + offerTable: config.offerTableId, + domainName, + coin: params.coin as string, + expiresAt: params.expiresAt ?? null, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Cancels an offer and returns the payment coin to the caller. + * + * Only the original offer maker can cancel their offer. + * + * @param params.coinType - The coin type of the offer + * @param params.domainName - The domain name the offer was placed on + * @returns The refunded coin as a TransactionObjectArgument + */ + cancelOffer(params: CancelOfferParams): TransactionObjectArgument { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + return this.transaction.add( + offer.cancelOffer({ + package: config.packageId, + arguments: { + offerTable: config.offerTableId, + domainName, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Accepts an offer on a domain the caller owns. + * + * Transfers the SuinsRegistration NFT to the buyer, deducts the service + * fee, and returns the remaining payment to the domain owner. + * + * @param params.coinType - The coin type of the offer + * @param params.suinsRegistration - The SuinsRegistration NFT to transfer + * @param params.buyerAddress - The address of the offer maker + * @returns The payment coin (minus service fee) as a TransactionObjectArgument + */ + acceptOffer(params: AcceptOfferParams): TransactionObjectArgument { + const config = this.marketplaceConfig; + + return this.transaction.add( + offer.acceptOffer({ + package: config.packageId, + arguments: { + suins: this.suinsClient.config.suins, + offerTable: config.offerTableId, + suinsRegistration: params.suinsRegistration as string, + address: params.buyerAddress, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Declines an offer on a domain the caller owns. + * + * Refunds the payment coin to the offer maker. + * + * @param params.coinType - The coin type of the offer + * @param params.suinsRegistration - The SuinsRegistration NFT (read-only) + * @param params.buyerAddress - The address of the offer maker to refund + */ + declineOffer(params: DeclineOfferParams): void { + const config = this.marketplaceConfig; + + this.transaction.add( + offer.declineOffer({ + package: config.packageId, + arguments: { + offerTable: config.offerTableId, + suinsRegistration: params.suinsRegistration as string, + address: params.buyerAddress, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Makes a counter offer on an existing offer. + * + * The counter offer value must be higher than the current offer. + * Only the domain owner can make a counter offer. + * + * @param params.coinType - The coin type of the original offer + * @param params.suinsRegistration - The SuinsRegistration NFT (read-only) + * @param params.buyerAddress - The address of the original offer maker + * @param params.counterOfferValue - The counter price (must exceed original) + */ + makeCounterOffer(params: MakeCounterOfferParams): void { + const config = this.marketplaceConfig; + + this.transaction.add( + offer.makeCounterOffer({ + package: config.packageId, + arguments: { + offerTable: config.offerTableId, + suinsRegistration: params.suinsRegistration as string, + address: params.buyerAddress, + counterOfferValue: params.counterOfferValue, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Accepts a counter offer by topping up the payment. + * + * The payment coin must equal `counter_offer_value - original_offer_value`. + * Only the original offer maker can accept the counter offer. + * + * @param params.coinType - The coin type of the counter offer + * @param params.domainName - The domain name + * @param params.coin - The top-up payment coin + */ + acceptCounterOffer(params: AcceptCounterOfferParams): void { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + this.transaction.add( + offer.acceptCounterOffer({ + package: config.packageId, + arguments: { + offerTable: config.offerTableId, + domainName, + coin: params.coin as string, + }, + typeArguments: [params.coinType], + }), + ); + } + + // ─── Auctions ─────────────────────────────────────────────────── + + /** + * Creates a timed auction for a SuiNS domain. + * + * The caller must own the SuinsRegistration NFT. The domain must not expire + * before the auction ends. An optional encrypted reserve price can be set + * using Seal encryption. + * + * @param params.coinType - The coin type for the auction + * @param params.startTime - Auction start time (Unix timestamp in seconds) + * @param params.endTime - Auction end time (Unix timestamp in seconds) + * @param params.minBid - Minimum bid amount in base units of the coin + * @param params.suinsRegistration - The SuinsRegistration NFT to auction + * @param params.encryptedReservePrice - Optional pre-encrypted reserve price bytes + */ + createAuction(params: CreateAuctionParams): void { + const config = this.marketplaceConfig; + + this.transaction.add( + auction.createAuction({ + package: config.packageId, + arguments: { + auctionTable: config.auctionTableId, + startTime: params.startTime, + endTime: params.endTime, + minBid: params.minBid, + encryptedReservePrice: params.encryptedReservePrice + ? Array.from(params.encryptedReservePrice) + : null, + suinsRegistration: params.suinsRegistration as string, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Places a bid on an active auction. + * + * The bid must be at least 5% higher than the current highest bid. + * If the bid is placed within the last 5 minutes, the auction is + * automatically extended. + * + * @param params.coinType - The coin type the auction is denominated in + * @param params.domainName - The domain name being auctioned + * @param params.bid - The bid payment coin + */ + placeBid(params: PlaceBidParams): void { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + this.transaction.add( + auction.placeBid({ + package: config.packageId, + arguments: { + auctionTable: config.auctionTableId, + domainName, + coin: params.bid as string, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Finalizes an auction after its end time has passed. + * + * If the auction has an encrypted reserve price, derived keys and key + * server addresses must be provided for on-chain decryption. + * If the highest bid meets the reserve (or there is no reserve), + * the domain is transferred to the winner and payment to the owner. + * + * @param params.coinType - The coin type the auction is denominated in + * @param params.domainName - The domain name to finalize + * @param params.derivedKeys - Optional Seal derived keys for reserve decryption + * @param params.keyServers - Optional key server addresses for reserve decryption + */ + finalizeAuction(params: FinalizeAuctionParams): void { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + const hasSealData = + params.derivedKeys && + params.keyServers && + params.derivedKeys.length > 0 && + params.keyServers.length > 0; + + this.transaction.add( + auction.finalizeAuction({ + package: config.packageId, + arguments: { + suins: this.suinsClient.config.suins, + auctionTable: config.auctionTableId, + domainName, + derivedKeys: hasSealData ? params.derivedKeys! : null, + keyServers: hasSealData ? params.keyServers! : null, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Cancels an auction before any bids are placed. + * + * Only the original auction owner can cancel. Returns the SuinsRegistration NFT. + * + * @param params.coinType - The coin type the auction is denominated in + * @param params.domainName - The domain name to cancel the auction for + * @returns The SuinsRegistration NFT as a TransactionObjectArgument + */ + cancelAuction(params: CancelAuctionParams): TransactionObjectArgument { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + return this.transaction.add( + auction.cancelAuction({ + package: config.packageId, + arguments: { + auctionTable: config.auctionTableId, + domainName, + }, + typeArguments: [params.coinType], + }), + ); + } + + /** + * Builds the `seal_approve` moveCall used for Seal key derivation. + * + * This is needed when finalizing an auction that has an encrypted reserve + * price. The caller builds a transaction containing this moveCall, then + * passes the transaction bytes to `SealClient.getDerivedKeys()` to obtain + * the derived keys needed for `finalizeAuction`. + * + * The encryption ID is constructed as: BCS(start_time as u64) ++ domain_name_bytes, + * matching the format in `decryption.move::get_encryption_id`. + * + * @param params.coinType - The coin type the auction is denominated in + * @param params.domainName - The domain name being auctioned + * @param params.startTime - The auction start time in seconds + */ + sealApprove(params: SealApproveParams): void { + const config = this.marketplaceConfig; + const domainName = normalizeSuiNSName(params.domainName, 'dot'); + + // Build the encryption ID: BCS-encoded start_time (u64 LE) + domain name bytes + const startTimeBytes = new Uint8Array(8); + const view = new DataView(startTimeBytes.buffer); + view.setBigUint64(0, BigInt(params.startTime), true); // little-endian + + const domainNameBytes = new TextEncoder().encode(domainName); + const encryptionId = new Uint8Array(startTimeBytes.length + domainNameBytes.length); + encryptionId.set(startTimeBytes, 0); + encryptionId.set(domainNameBytes, startTimeBytes.length); + + this.transaction.add( + auction.sealApprove({ + package: config.packageId, + arguments: { + id: Array.from(encryptionId), + auctionTable: config.auctionTableId, + }, + typeArguments: [params.coinType], + }), + ); + } +} diff --git a/packages/suins/src/types.ts b/packages/suins/src/types.ts index ccbc131fa..df487e609 100644 --- a/packages/suins/src/types.ts +++ b/packages/suins/src/types.ts @@ -17,6 +17,13 @@ export interface DiscountInfo { isFreeClaim?: boolean; } +export interface MarketplacePackageInfo { + packageId: string; + originalPackageId: string; + auctionTableId: string; + offerTableId: string; +} + export interface PackageInfo { packageId: string; packageIdV1: string; @@ -47,6 +54,7 @@ export interface PackageInfo { packageId: string; }; coins: Record; + marketplace?: MarketplacePackageInfo; } export interface NameRecord { @@ -107,3 +115,152 @@ export type SuinsClientConfig = { export type SuinsPriceList = Map<[number, number], number>; export type CoinTypeDiscount = Map; + +// Marketplace types +// ----------------- + +export type CreateListingParams = { + /** The coin type to list in (e.g. '0x2::sui::SUI') */ + coinType: string; + /** The fixed price for the listing (in base units of the coin) */ + price: bigint; + /** Optional expiration timestamp in seconds */ + expiresAt?: number; + /** The SuinsRegistration NFT to list */ + suinsRegistration: TransactionObjectInput; +}; + +export type BuyListingParams = { + /** The coin type the listing is priced in */ + coinType: string; + /** The domain name (e.g. 'example.sui') */ + domainName: string; + /** The payment coin (must match the listing price exactly) */ + payment: TransactionObjectInput; +}; + +export type CancelListingParams = { + /** The coin type the listing was created with */ + coinType: string; + /** The domain name to cancel the listing for */ + domainName: string; +}; + +export type PlaceOfferParams = { + /** The coin type for the offer (e.g. '0x2::sui::SUI') */ + coinType: string; + /** The domain name to make an offer on (e.g. 'example.sui') */ + domainName: string; + /** The payment coin for the offer */ + coin: TransactionObjectInput; + /** Optional expiration timestamp in seconds */ + expiresAt?: number; +}; + +export type CancelOfferParams = { + /** The coin type of the offer */ + coinType: string; + /** The domain name the offer was placed on */ + domainName: string; +}; + +export type AcceptOfferParams = { + /** The coin type of the offer being accepted */ + coinType: string; + /** The SuinsRegistration NFT to transfer to the buyer */ + suinsRegistration: TransactionObjectInput; + /** The address of the offer maker (buyer) */ + buyerAddress: string; +}; + +export type DeclineOfferParams = { + /** The coin type of the offer being declined */ + coinType: string; + /** The SuinsRegistration NFT (read-only reference) */ + suinsRegistration: TransactionObjectInput; + /** The address of the offer maker to refund */ + buyerAddress: string; +}; + +export type MakeCounterOfferParams = { + /** The coin type of the original offer */ + coinType: string; + /** The SuinsRegistration NFT (read-only reference) */ + suinsRegistration: TransactionObjectInput; + /** The address of the original offer maker */ + buyerAddress: string; + /** The counter offer value (must be higher than original offer) */ + counterOfferValue: bigint; +}; + +export type AcceptCounterOfferParams = { + /** The coin type of the counter offer */ + coinType: string; + /** The domain name */ + domainName: string; + /** The top-up payment coin (counter_offer_value - original_offer_value) */ + coin: TransactionObjectInput; +}; + +// Auction types +// ------------- + +export type CreateAuctionParams = { + /** The coin type for the auction (e.g. '0x2::sui::SUI') */ + coinType: string; + /** Auction start time as a Unix timestamp in seconds */ + startTime: number; + /** Auction end time as a Unix timestamp in seconds */ + endTime: number; + /** Minimum bid amount in base units of the coin */ + minBid: bigint; + /** The SuinsRegistration NFT to auction */ + suinsRegistration: TransactionObjectInput; + /** + * Optional encrypted reserve price as a byte array (pre-encrypted using Seal). + * If not provided, the auction will have no reserve price. + */ + encryptedReservePrice?: number[] | Uint8Array; +}; + +export type PlaceBidParams = { + /** The coin type the auction is denominated in */ + coinType: string; + /** The domain name being auctioned (e.g. 'example.sui') */ + domainName: string; + /** The bid payment coin */ + bid: TransactionObjectInput; +}; + +export type FinalizeAuctionParams = { + /** The coin type the auction is denominated in */ + coinType: string; + /** The domain name to finalize (e.g. 'example.sui') */ + domainName: string; + /** + * Optional derived keys from Seal key servers for decrypting the reserve price. + * Required only if the auction has an encrypted reserve price. + */ + derivedKeys?: number[][]; + /** + * Optional key server addresses corresponding to the derived keys. + * Required only if the auction has an encrypted reserve price. + */ + keyServers?: string[]; +}; + +export type CancelAuctionParams = { + /** The coin type the auction is denominated in */ + coinType: string; + /** The domain name to cancel the auction for */ + domainName: string; +}; + +export type SealApproveParams = { + /** The coin type the auction is denominated in */ + coinType: string; + /** The domain name being auctioned */ + domainName: string; + /** The auction start time in seconds (must match the on-chain auction) */ + startTime: number; +}; diff --git a/packages/suins/sui-codegen.config.ts b/packages/suins/sui-codegen.config.ts index bdda5ad51..61dfc297e 100644 --- a/packages/suins/sui-codegen.config.ts +++ b/packages/suins/sui-codegen.config.ts @@ -15,6 +15,8 @@ const config: SuiCodegenConfig = { package: '@suins/subdomain-proxy', path: '../../../suins-contracts/packages/temp_subdomain_proxy', }, + // Marketplace (auction/offer/listing) contracts + { package: '@suins/auction', path: '../../../suins-contracts/packages/auction' }, // Pyth - only need State type to get upgrade_cap.package { package: '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837', diff --git a/packages/suins/test/marketplace-live.test.ts b/packages/suins/test/marketplace-live.test.ts new file mode 100644 index 000000000..2235a9c4e --- /dev/null +++ b/packages/suins/test/marketplace-live.test.ts @@ -0,0 +1,43 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from 'vitest'; + +import { + e2eMarketplaceListingFlow, + e2eMarketplaceOfferFlow, + e2eMarketplaceAuctionFlow, +} from './marketplace-pre-built.js'; + +describe('marketplace listings should work on live networks', () => { + it('should work on testnet', async () => { + const res = await e2eMarketplaceListingFlow('testnet'); + if (res.FailedTransaction) { + throw new Error(`Transaction failed: ${JSON.stringify(res.FailedTransaction?.status.error)}`); + } + + expect(res.Transaction.status.success).toEqual(true); + }); +}); + +describe('marketplace offers should work on live networks', () => { + it('should work on testnet', async () => { + const res = await e2eMarketplaceOfferFlow('testnet'); + if (res.FailedTransaction) { + throw new Error(`Transaction failed: ${JSON.stringify(res.FailedTransaction?.status.error)}`); + } + + expect(res.Transaction.status.success).toEqual(true); + }); +}); + +describe('marketplace auctions should work on live networks', () => { + it('should work on testnet', async () => { + const res = await e2eMarketplaceAuctionFlow('testnet'); + if (res.FailedTransaction) { + throw new Error(`Transaction failed: ${JSON.stringify(res.FailedTransaction?.status.error)}`); + } + + expect(res.Transaction.status.success).toEqual(true); + }); +}); diff --git a/packages/suins/test/marketplace-pre-built.ts b/packages/suins/test/marketplace-pre-built.ts new file mode 100644 index 000000000..21a2dade5 --- /dev/null +++ b/packages/suins/test/marketplace-pre-built.ts @@ -0,0 +1,246 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 +import { getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc'; +import { SuiGrpcClient } from '@mysten/sui/grpc'; +import { Transaction } from '@mysten/sui/transactions'; +import { MIST_PER_SUI, normalizeSuiAddress, SUI_TYPE_ARG } from '@mysten/sui/utils'; + +import { SuinsMarketplaceTransaction, SuinsTransaction, suins } from '../src/index.js'; + +/** + * Registers a unique SuiNS name and returns the NFT + remaining coin. + * Helper used by all marketplace flows. + */ +async function registerName(client: any, tx: Transaction, _sender: string) { + const coinConfig = client.suins.config.coins.SUI; // Specify the coin type used for the transaction + + // Split coins for registration and Pyth fee upfront + const [coinInput, pythFeeCoin] = tx.splitCoins(tx.gas, [10n * MIST_PER_SUI, MIST_PER_SUI]); + + const priceInfoObjectId = + coinConfig !== client.suins.config.coins.USDC + ? (await client.suins.getPriceInfoObject(tx, coinConfig.feed, pythFeeCoin))[0] + : null; + + const suinsTx = new SuinsTransaction(client.suins, tx); + const uniqueName = + (Date.now().toString(36) + Math.random().toString(36).substring(2)).repeat(2) + '.sui'; + + const nft = suinsTx.register({ + domain: uniqueName, + years: 2, + coinConfig, + coin: coinInput, + priceInfoObjectId, + }); + + return { nft, uniqueName, coinInput, pythFeeCoin }; +} + +/** + * Listing flow: register → createListing → buyListing → createListing → cancelListing + * + * Tests all three listing operations in a single transaction. + */ +export const e2eMarketplaceListingFlow = async (network: 'testnet') => { + const client = new SuiGrpcClient({ baseUrl: getJsonRpcFullnodeUrl(network), network }).$extend( + suins(), + ); + + const sender = normalizeSuiAddress('0x2'); + const tx = new Transaction(); + + // Register a name to get the NFT + const { nft, uniqueName, coinInput, pythFeeCoin } = await registerName(client, tx, sender); + + const marketplaceTx = new SuinsMarketplaceTransaction(client.suins, tx); + + // 1) Create a listing for the registered name + marketplaceTx.createListing({ + coinType: SUI_TYPE_ARG, + price: 1_000_000_000n, + suinsRegistration: nft, + }); + + // 2) Buy the listing back (returns the NFT) + const [paymentCoin] = tx.splitCoins(tx.gas, [1_000_000_000n]); + const boughtNft = marketplaceTx.buyListing({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + payment: paymentCoin, + }); + + // 3) Create another listing with the NFT we just bought + marketplaceTx.createListing({ + coinType: SUI_TYPE_ARG, + price: 2_000_000_000n, + suinsRegistration: boughtNft, + }); + + // 4) Cancel the listing (returns the NFT) + const cancelledNft = marketplaceTx.cancelListing({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + }); + + tx.transferObjects([cancelledNft, coinInput, pythFeeCoin], tx.pure.address(sender)); + tx.setSender(sender); + + return client.simulateTransaction({ + transaction: tx, + include: { effects: true }, + }); +}; + +/** + * Offer flow: register → placeOffer → cancelOffer → placeOffer → declineOffer + * → placeOffer → makeCounterOffer → acceptCounterOffer → acceptOffer + * + * Tests all six offer operations in a single transaction. + */ +export const e2eMarketplaceOfferFlow = async (network: 'testnet') => { + const client = new SuiGrpcClient({ baseUrl: getJsonRpcFullnodeUrl(network), network }).$extend( + suins(), + ); + + const sender = normalizeSuiAddress('0x2'); + const tx = new Transaction(); + + // Register a name so the domain exists on-chain + const { nft, uniqueName, coinInput, pythFeeCoin } = await registerName(client, tx, sender); + + const marketplaceTx = new SuinsMarketplaceTransaction(client.suins, tx); + + // 1) Place an offer + const [offerCoin1] = tx.splitCoins(tx.gas, [1n * MIST_PER_SUI]); + marketplaceTx.placeOffer({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + coin: offerCoin1, + }); + + // 2) Cancel the offer (returns the refunded coin) + const refundedCoin = marketplaceTx.cancelOffer({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + }); + + // 3) Place another offer + const [offerCoin2] = tx.splitCoins(tx.gas, [1n * MIST_PER_SUI]); + marketplaceTx.placeOffer({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + coin: offerCoin2, + }); + + // 4) Owner declines the offer (refunds the buyer) + marketplaceTx.declineOffer({ + coinType: SUI_TYPE_ARG, + suinsRegistration: nft, + buyerAddress: sender, + }); + + // 5) Place another offer + const [offerCoin3] = tx.splitCoins(tx.gas, [1n * MIST_PER_SUI]); + marketplaceTx.placeOffer({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + coin: offerCoin3, + }); + + // 6) Owner makes a counter offer (2 SUI) + marketplaceTx.makeCounterOffer({ + coinType: SUI_TYPE_ARG, + suinsRegistration: nft, + buyerAddress: sender, + counterOfferValue: 2n * MIST_PER_SUI, + }); + + // 7) Buyer accepts the counter offer (top-up of 1 SUI) + const [topUpCoin] = tx.splitCoins(tx.gas, [1n * MIST_PER_SUI]); + marketplaceTx.acceptCounterOffer({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + coin: topUpCoin, + }); + + // 8) Owner accepts the offer (returns the payment, NFT transferred by contract) + const paymentCoin = marketplaceTx.acceptOffer({ + coinType: SUI_TYPE_ARG, + suinsRegistration: nft, + buyerAddress: sender, + }); + + tx.transferObjects([refundedCoin, paymentCoin, coinInput, pythFeeCoin], tx.pure.address(sender)); + tx.setSender(sender); + + return client.simulateTransaction({ + transaction: tx, + include: { effects: true }, + }); +}; + +/** + * Auction flow: register → createAuction → cancelAuction → createAuction → placeBid + * + * Tests createAuction, cancelAuction, and placeBid in a single transaction. + * finalizeAuction is not tested because it requires the auction to have ended (time-based). + * sealApprove is not tested because it requires Seal encryption infrastructure. + * Times are in seconds. Min duration: 1h, Max duration: 30d. + */ +export const e2eMarketplaceAuctionFlow = async (network: 'testnet') => { + const client = new SuiGrpcClient({ baseUrl: getJsonRpcFullnodeUrl(network), network }).$extend( + suins(), + ); + const sender = normalizeSuiAddress('0x2'); + const tx = new Transaction(); + + // Register a name to get the NFT + const { nft, uniqueName, coinInput, pythFeeCoin } = await registerName(client, tx, sender); + + const nowSec = Math.floor(Date.now() / 1000); + const startTime = nowSec - 60; // slightly in the past so auction is active during simulation + const endTime = nowSec + 7_200; // 2 hours + + const marketplaceTx = new SuinsMarketplaceTransaction(client.suins, tx); + + // 1) Create an auction for the registered name + marketplaceTx.createAuction({ + coinType: SUI_TYPE_ARG, + startTime, + endTime, + minBid: 1_000_000_000n, + suinsRegistration: nft, + }); + + // 2) Cancel the auction before any bids (returns the NFT) + const cancelledNft = marketplaceTx.cancelAuction({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + }); + + // 3) Create another auction with the returned NFT + marketplaceTx.createAuction({ + coinType: SUI_TYPE_ARG, + startTime, + endTime, + minBid: 1_000_000_000n, + suinsRegistration: cancelledNft, + }); + + // 4) Place a bid on the auction + const [bidCoin] = tx.splitCoins(tx.gas, [1n * MIST_PER_SUI]); + marketplaceTx.placeBid({ + coinType: SUI_TYPE_ARG, + domainName: uniqueName, + bid: bidCoin, + }); + + tx.transferObjects([coinInput, pythFeeCoin], tx.pure.address(sender)); + tx.setSender(sender); + + return client.simulateTransaction({ + transaction: tx, + include: { effects: true }, + }); +};