@galliun/sofi-sdk
Version:
SDK for interacting with the Galliun SocialFi protocol
595 lines (569 loc) • 15.1 kB
text/typescript
import type { Transaction, TransactionResult } from '@mysten/sui/transactions';
import type { ObjectInput } from '../util';
import { objectArg } from '../util';
import { type } from 'os';
import { Link } from '../SoFiObjects';
import { config } from 'process';
/**
* Build transactions for the profile module.
* Handles profile creation, updates, and social interactions.
*/
export const ProfileModule = {
/**
* Creates a new profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param config Global config object
* @param owner The address that owns the profile
* @param username The username for the profile
* @param bio Profile bio
* @param description Profile description
* @param display_name Display name for the profile
* @param profile_picture URL for profile picture
* @param background_picture URL for background picture
* @param profileRegistry The object ID of the profile registry
* @returns Transaction result
*/
new: (
tx: Transaction,
packageId: string,
config: ObjectInput,
username: string,
bio: string,
display_name: string,
profile_picture: string,
background_picture: string,
profileRegistry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::new_profile`,
typeArguments: [],
arguments: [
objectArg(tx, config),
tx.pure.string(username),
tx.pure.string(bio),
tx.pure.string(display_name),
tx.pure.string(profile_picture),
tx.pure.string(background_picture),
objectArg(tx, profileRegistry),
tx.object.clock(),
],
}),
/**
* Updates a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param config Global config object
* @param profile Profile object to update
* @param display_name New display name
* @param profile_picture New profile picture URL
* @param background_picture New background picture URL
* @returns Transaction result
*/
update: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
display_name: string,
bio: string,
profile_picture: string,
background_picture: string,
accept_tips: boolean,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::update_profile`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.string(display_name),
tx.pure.string(bio),
tx.pure.string(profile_picture),
tx.pure.string(background_picture),
tx.pure.bool(accept_tips),
],
}),
/**
* Follows a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @returns Transaction result
*/
buyPremium: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
config: ObjectInput,
coin_type: string,
payment_coin: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::buy_premium`,
typeArguments: [coin_type],
arguments: [
objectArg(tx, profile),
objectArg(tx, config),
objectArg(tx, payment_coin),
tx.object.clock(),
],
}),
/**
* Follows a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile_id ID of the profile doing the following
* @param target_profile_id ID of the profile to follow
* @returns Transaction result
*/
toggleFavourite: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
target_profile: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::toggle_favourite`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
objectArg(tx, target_profile),
tx.object.clock(),
],
}),
/**
* Updates the username of a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param username New username for the profile
* @param profileRegistry The object ID of the username registry
* @returns Transaction result
*/
updateUsername: (
tx: Transaction,
packageId: string,
config: ObjectInput,
profile: ObjectInput,
username: string,
profileRegistry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::update_username`,
typeArguments: [],
arguments: [
objectArg(tx, config),
objectArg(tx, profile),
tx.pure.string(username),
objectArg(tx, profileRegistry),
],
}),
/**
* Updates an existing link in the profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param name The name of the link to update
* @param url The new URL for the link
* @returns Transaction result
*/
updateLink: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
name: string,
url: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::update_link`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.string(name),
tx.pure.string(url),
],
}),
/**
* Adds a new link to the profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param name The name of the link to add
* @param url The URL for the link
* @returns Transaction result
*/
addLink: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
name: string,
url: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::add_link`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.string(name),
tx.pure.string(url),
],
}),
/**
* Updates an existing link or adds a new one if it doesn't exist
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param name The name of the link to update or add
* @param url The URL for the link
* @returns Transaction result
*/
updateLinks: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
names: string[],
urls: string[],
media: string[],
positions: number[],
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::update_links`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.vector(
'string',
names
),
tx.pure.vector(
'string',
urls
),
tx.pure.vector(
'string',
media
),
tx.pure.vector(
'u64',
positions
),
tx.object.clock(),
],
}),
/**
* Removes a link from the profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param name The name of the link to remove
* @returns Transaction result
*/
removeLink: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
name: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::remove_link`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.string(name),
],
}),
/**
* Toggles whether a profile accepts tips
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @returns Transaction result
*/
toggleAcceptTips: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::toggle_accept_tips`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
],
}),
/**
* Checks if a username is valid
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param username Username to check
* @returns Transaction result
*/
isValidUsername: (
tx: Transaction,
packageId: string,
username: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::is_valid_username`,
typeArguments: [],
arguments: [
tx.pure.string(username),
],
}),
/**
* Checks if a username is reserved
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param username Username to check
* @param config The object ID of the config
* @returns Transaction result
*/
isReservedWord: (
tx: Transaction,
packageId: string,
username: string,
config: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::config::is_reserved_word`,
typeArguments: [],
arguments: [
objectArg(tx, config),
tx.pure.string(username),
],
}),
/**
* Checks if a profile is unique for the sender
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param registry The object ID of the username registry
* @returns Transaction result
*/
isUniqueProfile: (
tx: Transaction,
packageId: string,
registry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::is_unique_profile`,
typeArguments: [],
arguments: [
objectArg(tx, registry),
],
}),
/**
* Checks if a username is unique
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param username Username to check
* @param registry The object ID of the username registry
* @returns Transaction result
*/
isUniqueUsername: (
tx: Transaction,
packageId: string,
username: string,
registry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::is_unique_username`,
typeArguments: [],
arguments: [
tx.pure.string(username),
objectArg(tx, registry),
],
}),
/**
* Checks if a profile is accepting tips
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to check
* @returns Transaction result
*/
isAcceptingTips: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::is_accepting_tips`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
],
}),
/**
* Find a profile by username
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param username Username to search for
* @param registry The object ID of the username registry
* @returns Transaction result
*/
findProfileByUsername: (
tx: Transaction,
packageId: string,
username: string,
registry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::find_profile_by_username`,
typeArguments: [],
arguments: [
tx.pure.string(username),
objectArg(tx, registry),
],
}),
/**
* Find a profile by address
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param address Address to search for
* @param registry The object ID of the username registry
* @returns Transaction result
*/
findProfileByAddress: (
tx: Transaction,
packageId: string,
address: string,
registry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::find_profile_by_address`,
typeArguments: [],
arguments: [
tx.pure.address(address),
objectArg(tx, registry),
],
}),
/**
* Gets all links from a profile as arrays of names and URLs
* @param tx The transaction to add the command to
* @param packageId The package ID
* @param profile The profile to get links from
* @returns The transaction with the command added
*/
getProfileLinks: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::get_profile_links`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
],
}),
/**
* Updates the accepted coin type of a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param coinType The coin type to update
* @returns Transaction result
*/
updateAcceptedCoinType: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
config: ObjectInput,
coinType: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::update_accepted_coin_type`,
typeArguments: [coinType],
arguments: [
objectArg(tx, profile),
objectArg(tx, config),
],
}),
/**
* Removes the accepted coin type of a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to update
* @param coinType The coin type to remove
* @returns Transaction result
*/
removeAcceptedCoinType: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
config: ObjectInput,
coinType: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::remove_accepted_coin_type`,
typeArguments: [coinType],
arguments: [
objectArg(tx, profile),
objectArg(tx, config),
],
}),
/**
* Checks if a coin type is accepted by a profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to check
* @param coinType The coin type to check
* @returns Transaction result
*/
isAcceptedCoinType: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
coinType: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::is_coin_type_accepted`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.string(coinType),
],
}),
/**
* Checks if a profile exists for an address
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param address Address to check
* @param registry The object ID of the username registry
* @returns Transaction result
*/
hasProfile: (
tx: Transaction,
packageId: string,
address: string,
registry: ObjectInput,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::has_profile`,
typeArguments: [],
arguments: [
tx.pure.address(address),
objectArg(tx, registry),
],
}),
/**
* Checks if a profile is a favourite of another profile
* @param tx Transaction to build on
* @param packageId Package ID of the protocol contract
* @param profile Profile object to check
* @param favouriteId The ID of the profile to check if it is a favourite
* @returns Transaction result
*/
isFavourite: (
tx: Transaction,
packageId: string,
profile: ObjectInput,
favouriteId: string,
): TransactionResult =>
tx.moveCall({
target: `${packageId}::profile::is_favourite`,
typeArguments: [],
arguments: [
objectArg(tx, profile),
tx.pure.address(favouriteId),
],
}),
};