UNPKG

@mysten/suins

Version:
1 lines 18 kB
{"version":3,"file":"suins.mjs","names":["balance.Balance"],"sources":["../../../src/contracts/suins/suins.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\n\n/**\n * The main module of the SuiNS application, defines the `SuiNS` object and the\n * authorization mechanism for interacting with the main data storage.\n *\n * Authorization mechanic: The Admin can authorize applications to access protected\n * features of the SuiNS, they're named with a prefix `app_*`. Once authorized,\n * application can get mutable access to the `Registry` and add to the application\n * `Balance`.\n *\n * At any moment any of the applications can be deathorized by the Admin making it\n * impossible for the deauthorized module to access the registry.\n *\n * ---\n *\n * Package Upgrades in mind:\n *\n * - None of the public functions of the SuiNS feature any specific types - instead\n * we use generics to define the actual types in arbitrary modules.\n * - The `Registry` itself (the main feature of the application) is stored as a\n * dynamic field so that we can change the type and the module that serves the\n * registry without breaking the SuiNS compatibility.\n * - Any of the old modules can be deauthorized hence disabling its access to the\n * registry and the balance.\n */\n\nimport { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';\nimport { bcs, type BcsType } from '@mysten/sui/bcs';\nimport { type Transaction } from '@mysten/sui/transactions';\nimport * as balance from './deps/sui/balance.js';\nconst $moduleName = '@suins/core::suins';\nexport const AdminCap = new MoveStruct({\n\tname: `${$moduleName}::AdminCap`,\n\tfields: {\n\t\tid: bcs.Address,\n\t},\n});\nexport const SuiNS = new MoveStruct({\n\tname: `${$moduleName}::SuiNS`,\n\tfields: {\n\t\tid: bcs.Address,\n\t\t/**\n\t\t * The total balance of the SuiNS. Can be added to by authorized apps. Can be\n\t\t * withdrawn only by the application Admin.\n\t\t */\n\t\tbalance: balance.Balance,\n\t},\n});\nexport const SUINS = new MoveStruct({\n\tname: `${$moduleName}::SUINS`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport const ConfigKey = new MoveStruct({\n\tname: `${$moduleName}::ConfigKey<phantom Config>`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport const RegistryKey = new MoveStruct({\n\tname: `${$moduleName}::RegistryKey<phantom Config>`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport const BalanceKey = new MoveStruct({\n\tname: `${$moduleName}::BalanceKey<phantom T>`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport const AppKey = new MoveStruct({\n\tname: `${$moduleName}::AppKey<phantom App>`,\n\tfields: {\n\t\tdummy_field: bcs.bool(),\n\t},\n});\nexport interface WithdrawArguments {\n\t_: RawTransactionArgument<string>;\n\tself: RawTransactionArgument<string>;\n}\nexport interface WithdrawOptions {\n\tpackage?: string;\n\targuments:\n\t\t| WithdrawArguments\n\t\t| [_: RawTransactionArgument<string>, self: RawTransactionArgument<string>];\n}\n/**\n * Withdraw from the SuiNS balance directly and access the Coins within the same\n * transaction. This is useful for the admin to withdraw funds from the SuiNS and\n * then send them somewhere specific or keep at the address.\n */\nexport function withdraw(options: WithdrawOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'withdraw',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface WithdrawCustomArguments {\n\tself: RawTransactionArgument<string>;\n\t_: RawTransactionArgument<string>;\n}\nexport interface WithdrawCustomOptions {\n\tpackage?: string;\n\targuments:\n\t\t| WithdrawCustomArguments\n\t\t| [self: RawTransactionArgument<string>, _: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Withdraw from the SuiNS balance of a custom coin type. */\nexport function withdrawCustom(options: WithdrawCustomOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null] satisfies (string | null)[];\n\tconst parameterNames = ['self', '_'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'withdraw_custom',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AuthorizeAppArguments {\n\t_: RawTransactionArgument<string>;\n\tself: RawTransactionArgument<string>;\n}\nexport interface AuthorizeAppOptions {\n\tpackage?: string;\n\targuments:\n\t\t| AuthorizeAppArguments\n\t\t| [_: RawTransactionArgument<string>, self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Authorize an application to access protected features of the SuiNS. */\nexport function authorizeApp(options: AuthorizeAppOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'authorize_app',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface DeauthorizeAppArguments {\n\t_: RawTransactionArgument<string>;\n\tself: RawTransactionArgument<string>;\n}\nexport interface DeauthorizeAppOptions {\n\tpackage?: string;\n\targuments:\n\t\t| DeauthorizeAppArguments\n\t\t| [_: RawTransactionArgument<string>, self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Deauthorize an application by removing its authorization key. */\nexport function deauthorizeApp(options: DeauthorizeAppOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'deauthorize_app',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface IsAppAuthorizedArguments {\n\tself: RawTransactionArgument<string>;\n}\nexport interface IsAppAuthorizedOptions {\n\tpackage?: string;\n\targuments: IsAppAuthorizedArguments | [self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Check if an application is authorized to access protected features of the SuiNS. */\nexport function isAppAuthorized(options: IsAppAuthorizedOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'is_app_authorized',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AssertAppIsAuthorizedArguments {\n\tself: RawTransactionArgument<string>;\n}\nexport interface AssertAppIsAuthorizedOptions {\n\tpackage?: string;\n\targuments: AssertAppIsAuthorizedArguments | [self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/**\n * Assert that an application is authorized to access protected features of the\n * SuiNS. Aborts with `EAppNotAuthorized` if not.\n */\nexport function assertAppIsAuthorized(options: AssertAppIsAuthorizedOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'assert_app_is_authorized',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AppAddBalanceArguments<App extends BcsType<any>> {\n\t_: RawTransactionArgument<App>;\n\tself: RawTransactionArgument<string>;\n\tbalance: RawTransactionArgument<string>;\n}\nexport interface AppAddBalanceOptions<App extends BcsType<any>> {\n\tpackage?: string;\n\targuments:\n\t\t| AppAddBalanceArguments<App>\n\t\t| [\n\t\t\t\t_: RawTransactionArgument<App>,\n\t\t\t\tself: RawTransactionArgument<string>,\n\t\t\t\tbalance: RawTransactionArgument<string>,\n\t\t ];\n\ttypeArguments: [string];\n}\n/** Adds balance to the SuiNS. */\nexport function appAddBalance<App extends BcsType<any>>(options: AppAddBalanceOptions<App>) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [`${options.typeArguments[0]}`, null, null] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self', 'balance'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'app_add_balance',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AppAddCustomBalanceArguments<App extends BcsType<any>> {\n\tself: RawTransactionArgument<string>;\n\t_: RawTransactionArgument<App>;\n\tbalance: RawTransactionArgument<string>;\n}\nexport interface AppAddCustomBalanceOptions<App extends BcsType<any>> {\n\tpackage?: string;\n\targuments:\n\t\t| AppAddCustomBalanceArguments<App>\n\t\t| [\n\t\t\t\tself: RawTransactionArgument<string>,\n\t\t\t\t_: RawTransactionArgument<App>,\n\t\t\t\tbalance: RawTransactionArgument<string>,\n\t\t ];\n\ttypeArguments: [string, string];\n}\n/** Adds a balance of type `T` to the SuiNS protocol as an authorized app. */\nexport function appAddCustomBalance<App extends BcsType<any>>(\n\toptions: AppAddCustomBalanceOptions<App>,\n) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, `${options.typeArguments[0]}`, null] satisfies (string | null)[];\n\tconst parameterNames = ['self', '_', 'balance'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'app_add_custom_balance',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AppRegistryMutArguments<App extends BcsType<any>> {\n\t_: RawTransactionArgument<App>;\n\tself: RawTransactionArgument<string>;\n}\nexport interface AppRegistryMutOptions<App extends BcsType<any>> {\n\tpackage?: string;\n\targuments:\n\t\t| AppRegistryMutArguments<App>\n\t\t| [_: RawTransactionArgument<App>, self: RawTransactionArgument<string>];\n\ttypeArguments: [string, string];\n}\n/**\n * Get a mutable access to the `Registry` object. Can only be performed by\n * authorized applications.\n */\nexport function appRegistryMut<App extends BcsType<any>>(options: AppRegistryMutOptions<App>) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [`${options.typeArguments[0]}`, null] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'app_registry_mut',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AddConfigArguments<Config extends BcsType<any>> {\n\t_: RawTransactionArgument<string>;\n\tself: RawTransactionArgument<string>;\n\tconfig: RawTransactionArgument<Config>;\n}\nexport interface AddConfigOptions<Config extends BcsType<any>> {\n\tpackage?: string;\n\targuments:\n\t\t| AddConfigArguments<Config>\n\t\t| [\n\t\t\t\t_: RawTransactionArgument<string>,\n\t\t\t\tself: RawTransactionArgument<string>,\n\t\t\t\tconfig: RawTransactionArgument<Config>,\n\t\t ];\n\ttypeArguments: [string];\n}\n/** Attach dynamic configuration object to the application. */\nexport function addConfig<Config extends BcsType<any>>(options: AddConfigOptions<Config>) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null, `${options.typeArguments[0]}`] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self', 'config'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'add_config',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface GetConfigArguments {\n\tself: RawTransactionArgument<string>;\n}\nexport interface GetConfigOptions {\n\tpackage?: string;\n\targuments: GetConfigArguments | [self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Borrow configuration object. Read-only mode for applications. */\nexport function getConfig(options: GetConfigOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'get_config',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface RemoveConfigArguments {\n\t_: RawTransactionArgument<string>;\n\tself: RawTransactionArgument<string>;\n}\nexport interface RemoveConfigOptions {\n\tpackage?: string;\n\targuments:\n\t\t| RemoveConfigArguments\n\t\t| [_: RawTransactionArgument<string>, self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/**\n * Get the configuration object for editing. The admin should put it back after\n * editing (no extra check performed). Can be used to swap configuration since the\n * `T` has `drop`. Eg nothing is stopping the admin from removing the configuration\n * object and adding a new one.\n *\n * Fully taking the config also allows for edits within a transaction.\n */\nexport function removeConfig(options: RemoveConfigOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'remove_config',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface RegistryArguments {\n\tself: RawTransactionArgument<string>;\n}\nexport interface RegistryOptions {\n\tpackage?: string;\n\targuments: RegistryArguments | [self: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Get a read-only access to the `Registry` object. */\nexport function registry(options: RegistryOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['self'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'registry',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface AddRegistryArguments<R extends BcsType<any>> {\n\t_: RawTransactionArgument<string>;\n\tself: RawTransactionArgument<string>;\n\tregistry: RawTransactionArgument<R>;\n}\nexport interface AddRegistryOptions<R extends BcsType<any>> {\n\tpackage?: string;\n\targuments:\n\t\t| AddRegistryArguments<R>\n\t\t| [\n\t\t\t\t_: RawTransactionArgument<string>,\n\t\t\t\tself: RawTransactionArgument<string>,\n\t\t\t\tregistry: RawTransactionArgument<R>,\n\t\t ];\n\ttypeArguments: [string];\n}\n/** Add a registry to the SuiNS. Can only be performed by the admin. */\nexport function addRegistry<R extends BcsType<any>>(options: AddRegistryOptions<R>) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, null, `${options.typeArguments[0]}`] satisfies (string | null)[];\n\tconst parameterNames = ['_', 'self', 'registry'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'suins',\n\t\t\tfunction: 'add_registry',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,cAAc;AACpB,MAAa,WAAW,IAAI,WAAW;CACtC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,IAAI,IAAI,SACR;CACD,CAAC;AACF,MAAa,QAAQ,IAAI,WAAW;CACnC,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,IAAI,IAAI;EAKR,SAASA;EACT;CACD,CAAC;AACF,MAAa,QAAQ,IAAI,WAAW;CACnC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC;AACF,MAAa,YAAY,IAAI,WAAW;CACvC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC;AACF,MAAa,cAAc,IAAI,WAAW;CACzC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC;AACF,MAAa,aAAa,IAAI,WAAW;CACxC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC;AACF,MAAa,SAAS,IAAI,WAAW;CACpC,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,aAAa,IAAI,MAAM,EACvB;CACD,CAAC"}