@scallop-io/sui-scallop-sdk 0.37.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +276 -0
  3. package/dist/constants/common.d.ts +7 -0
  4. package/dist/constants/index.d.ts +1 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +1487 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +1444 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/models/index.d.ts +4 -0
  11. package/dist/models/scallop.d.ts +46 -0
  12. package/dist/models/scallopAddress.d.ts +107 -0
  13. package/dist/models/scallopClient.d.ts +151 -0
  14. package/dist/models/scallopUtils.d.ts +56 -0
  15. package/dist/queries/index.d.ts +2 -0
  16. package/dist/queries/market.d.ts +4 -0
  17. package/dist/queries/obligation.d.ts +8 -0
  18. package/dist/txBuilders/coin.d.ts +67 -0
  19. package/dist/txBuilders/index.d.ts +1 -0
  20. package/dist/txBuilders/normalMethods.d.ts +3 -0
  21. package/dist/txBuilders/oracle.d.ts +7 -0
  22. package/dist/txBuilders/quickMethods.d.ts +7 -0
  23. package/dist/types/data.d.ts +127 -0
  24. package/dist/types/index.d.ts +3 -0
  25. package/dist/types/model.d.ts +9 -0
  26. package/dist/types/txBuilder.d.ts +66 -0
  27. package/package.json +147 -0
  28. package/src/constants/common.ts +36 -0
  29. package/src/constants/index.ts +1 -0
  30. package/src/index.ts +3 -0
  31. package/src/models/index.ts +4 -0
  32. package/src/models/scallop.ts +76 -0
  33. package/src/models/scallopAddress.ts +460 -0
  34. package/src/models/scallopClient.ts +461 -0
  35. package/src/models/scallopUtils.ts +133 -0
  36. package/src/queries/index.ts +2 -0
  37. package/src/queries/market.ts +16 -0
  38. package/src/queries/obligation.ts +44 -0
  39. package/src/txBuilders/coin.ts +38 -0
  40. package/src/txBuilders/index.ts +1 -0
  41. package/src/txBuilders/normalMethods.ts +216 -0
  42. package/src/txBuilders/oracle.ts +376 -0
  43. package/src/txBuilders/quickMethods.ts +231 -0
  44. package/src/types/data.ts +170 -0
  45. package/src/types/index.ts +3 -0
  46. package/src/types/model.ts +15 -0
  47. package/src/types/txBuilder.ts +136 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants/common.ts","../src/models/scallop.ts","../src/models/scallopAddress.ts","../src/models/scallopClient.ts","../src/models/scallopUtils.ts","../src/queries/market.ts","../src/queries/obligation.ts","../src/txBuilders/normalMethods.ts","../src/txBuilders/oracle.ts","../src/txBuilders/coin.ts","../src/txBuilders/quickMethods.ts"],"sourcesContent":["export const API_BASE_URL = 'https://sui.api.scallop.io';\n\nexport const ADDRESSES_ID = '6462a088a7ace142bb6d7e9b';\n\nexport const SUPPORT_ASSET_COINS = [\n 'eth',\n 'btc',\n 'usdc',\n 'usdt',\n 'sui',\n] as const;\nexport const SUPPORT_COLLATERAL_COINS = [\n 'eth',\n 'btc',\n 'usdc',\n 'usdt',\n 'sui',\n] as const;\n\nexport const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;\n\nexport const SUPPORT_PACKAGES = [\n 'coinDecimalsRegistry',\n 'math',\n 'whitelist',\n 'x',\n 'protocol',\n 'query',\n 'supra',\n 'pyth',\n 'switchboard',\n 'xOracle',\n 'testCoin',\n] as const;\n\nexport const SUI_COIN_TYPE_ARG_REGEX = /^0x(0*)2::sui::SUI$/;\n","import { SuiKit } from '@scallop-io/sui-kit';\nimport { ScallopAddress } from './scallopAddress';\nimport { ScallopClient } from './scallopClient';\nimport { ScallopUtils } from './scallopUtils';\nimport { newScallopTxBlock } from '../txBuilders';\nimport { ADDRESSES_ID } from '../constants';\nimport type { NetworkType } from '@scallop-io/sui-kit';\nimport type { ScallopParams, ScallopTxBlock } from '../types';\n\n/**\n * ### Scallop\n *\n * The main instance that controls interaction with the Scallop contract.\n *\n * #### Usage\n *\n * ```typescript\n * const sdk = new Scallop(<parameters>);\n * ```\n */\nexport class Scallop {\n public params: ScallopParams;\n public suiKit: SuiKit;\n public address: ScallopAddress;\n\n public constructor(params: ScallopParams) {\n this.params = params;\n this.suiKit = new SuiKit(params);\n this.address = new ScallopAddress({\n id: ADDRESSES_ID,\n network: params?.networkType,\n });\n }\n\n /**\n * Create an instance to operate the transaction block, making it more convenient to organize transaction combinations.\n * @return Scallop Transaction Builder\n */\n public async createTxBuilder() {\n await this.address.read();\n const scallopUtils = new ScallopUtils(this.params);\n const suiKit = new SuiKit(this.params);\n const isTestnet = this.params.networkType === 'testnet';\n return {\n createTxBlock: () => {\n return newScallopTxBlock(suiKit, this.address, scallopUtils, isTestnet);\n },\n signAndSendTxBlock: (txBlock: ScallopTxBlock) => {\n return suiKit.signAndSendTxn(txBlock);\n },\n };\n }\n\n /**\n * Create an instance to collect the addresses, making it easier to get object addresses from lending contract.\n *\n * @param id - The API id of the addresses.\n * @param auth - The authentication API key.\n * @param network - Specifies which network's addresses you want to set.\n * @return Scallop Address\n */\n public createAddress(id: string, auth: string, network: NetworkType) {\n return new ScallopAddress({ id, auth, network });\n }\n\n /**\n * Create an instance that provides contract interaction operations for general users.\n *\n * @param walletAddress - When user cannot provide a secret key or mnemonic, the scallop client cannot directly derive the address of the transaction the user wants to sign. This argument specifies the wallet address for signing the transaction.\n * @return Scallop Client\n */\n public async createScallopClient(walletAddress?: string) {\n await this.address.read();\n return new ScallopClient(this.params, this.address, walletAddress);\n }\n}\n","import axios, { AxiosInstance } from 'axios';\nimport { API_BASE_URL } from '../constants';\nimport type { NetworkType } from '@scallop-io/sui-kit';\nimport type {\n ScallopAddressParams,\n AddressesInterface,\n AddressStringPath,\n} from '../types';\n\n/**\n * it provides methods for managing addresses.\n */\nexport class ScallopAddress {\n private _apiClient: AxiosInstance;\n private _id?: string;\n private readonly _auth?: string;\n private readonly _network: NetworkType;\n private _addresses?: AddressesInterface;\n private _addressesMap: Map<NetworkType, AddressesInterface>;\n\n public constructor(params: ScallopAddressParams) {\n const { id, auth, network } = params;\n\n if (auth) this._auth = auth;\n this._id = id;\n this._network = network || 'mainnet';\n this._addressesMap = new Map();\n this._apiClient = axios.create({\n baseURL: API_BASE_URL,\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n timeout: 30000,\n });\n }\n\n /**\n * Get addresses API id.\n *\n * @returns The addresses API id.\n */\n public getId() {\n return this._id;\n }\n\n /**\n * Get the address at the provided path.\n *\n * @param path - The path of the address to get.\n * @returns The address at the provided path.\n */\n public get(path: AddressStringPath) {\n if (this._addresses) {\n const value = path\n .split('.')\n .reduce(\n (nestedAddressObj: any, key: string) =>\n typeof nestedAddressObj === 'object'\n ? nestedAddressObj[key]\n : nestedAddressObj,\n this._addresses\n );\n return value || undefined;\n } else {\n return undefined;\n }\n }\n\n /**\n * Set the address at the provided path.\n *\n * @param path - The path of the address to set.\n * @param address - The address be setted to the tartget path.\n * @returns The addresses.\n */\n public set(path: AddressStringPath, address: string) {\n if (this._addresses) {\n const keys = path.split('.');\n keys.reduce((nestedAddressObj: any, key: string, index) => {\n if (index === keys.length - 1) {\n nestedAddressObj[key] = address;\n } else {\n return nestedAddressObj[key];\n }\n }, this._addresses);\n }\n return this._addresses;\n }\n\n /**\n * Get the addresses.\n *\n * @param network - Specifies which network's addresses you want to get.\n * @returns The addresses.\n */\n public getAddresses(network?: NetworkType) {\n if (network) {\n return this._addressesMap.get(network);\n } else {\n return this._addresses;\n }\n }\n\n /**\n * Set the addresses into addresses map.\n *\n * @param network - Specifies which network's addresses you want to set.\n * @param addresses - The addresses be setted to the tartget network.\n * @returns The addresses.\n */\n public setAddresses(network?: NetworkType, addresses?: AddressesInterface) {\n const targetNetwork = network || this._network;\n const targetAddresses = addresses || this._addresses || undefined;\n if (targetAddresses) {\n this._addressesMap.set(targetNetwork, targetAddresses);\n } else {\n // TODO: change to new format version\n this._addressesMap.set(targetNetwork, {\n core: {\n version: '',\n versionCap: '',\n market: '',\n adminCap: '',\n coinDecimalsRegistry: '',\n coins: {\n btc: {\n id: '',\n metaData: '',\n treasury: '',\n oracle: {\n supra: '',\n switchboard: '',\n pyth: {\n feed: '',\n feedObject: '',\n },\n },\n },\n eth: {\n id: '',\n metaData: '',\n treasury: '',\n oracle: {\n supra: '',\n switchboard: '',\n pyth: {\n feed: '',\n feedObject: '',\n },\n },\n },\n usdc: {\n id: '',\n metaData: '',\n treasury: '',\n oracle: {\n supra: '',\n switchboard: '',\n pyth: {\n feed: '',\n feedObject: '',\n },\n },\n },\n usdt: {\n id: '',\n metaData: '',\n treasury: '',\n oracle: {\n supra: '',\n switchboard: '',\n pyth: {\n feed: '',\n feedObject: '',\n },\n },\n },\n sui: {\n id: '',\n metaData: '',\n treasury: '',\n oracle: {\n supra: '',\n switchboard: '',\n pyth: {\n feed: '',\n feedObject: '',\n },\n },\n },\n },\n oracles: {\n xOracle: '',\n xOracleCap: '',\n supra: {\n registry: '',\n registryCap: '',\n holder: '',\n },\n switchboard: {\n registry: '',\n registryCap: '',\n },\n pyth: {\n registry: '',\n registryCap: '',\n state: '',\n wormhole: '',\n wormholeState: '',\n },\n },\n packages: {\n coinDecimalsRegistry: {\n id: '',\n upgradeCap: '',\n },\n math: {\n id: '',\n upgradeCap: '',\n },\n whitelist: {\n id: '',\n upgradeCap: '',\n },\n x: {\n id: '',\n upgradeCap: '',\n },\n protocol: {\n id: '',\n upgradeCap: '',\n },\n query: {\n id: '',\n upgradeCap: '',\n },\n // Deploy by pyth on testnet\n pyth: {\n id: '',\n upgradeCap: '',\n },\n // Deploy by ourself on testnet\n switchboard: {\n id: '',\n upgradeCap: '',\n },\n xOracle: {\n id: '',\n upgradeCap: '',\n },\n // Deploy for faucet on testnet\n testCoin: {\n id: '',\n upgradeCap: '',\n },\n },\n },\n });\n }\n }\n\n /**\n * Get all addresses.\n *\n * @returns All addresses.\n */\n public getAllAddresses() {\n return Object.fromEntries(this._addressesMap);\n }\n\n /**\n * Create a new address through the API and synchronize it back to the\n * instance. If the `network` is not specified, the mainnet is used by default.\n * If no `addresses` is provided, an addresses with all empty strings is created\n * by default.\n *\n * This function only allows for one addresses to be input into a specific network\n * at a time, and does not provide an addresses map for setting addresses\n * across all networks at once.\n *\n * @param network - Specifies which network's addresses you want to set.\n * @param addresses - The addresses be setted to the tartget network.\n * @param auth - The authentication API key.\n * @returns The addresses.\n */\n public async create(\n network?: NetworkType,\n addresses?: AddressesInterface,\n auth?: string\n ) {\n const apiKey = auth || this._auth || undefined;\n const targetNetwork = network || this._network;\n const targetAddresses = addresses || this._addresses || undefined;\n if (apiKey !== undefined) {\n this._addressesMap.clear();\n this.setAddresses(targetNetwork, targetAddresses);\n const response = await this._apiClient.post(\n `${API_BASE_URL}/addresses`,\n JSON.stringify(Object.fromEntries(this._addressesMap)),\n {\n headers: {\n 'Content-Type': 'application/json',\n 'api-key': auth || this._auth,\n },\n }\n );\n\n if (response.status === 201) {\n for (const [network, addresses] of Object.entries<AddressesInterface>(\n response.data\n )) {\n if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {\n if (network === this._network) this._addresses = addresses;\n this._addressesMap.set(network as NetworkType, addresses);\n }\n }\n this._id = response.data.id;\n return this._addresses;\n } else {\n throw Error('Failed to create addresses.');\n }\n } else {\n throw Error(\"You don't have permission to access this request.\");\n }\n }\n\n /**\n * It doesn't read the data stored in the address instance, but reads and\n * synchronizes the data from the API into instance.\n *\n * @param id - The id of the addresses to get.\n * @returns The addresses.\n */\n public async read(id?: string) {\n const addressesId = id || this._id || undefined;\n\n if (addressesId !== undefined) {\n const response = await this._apiClient.get(\n `${API_BASE_URL}/addresses/${addressesId}`,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n }\n );\n\n if (response.status === 200) {\n for (const [network, addresses] of Object.entries<AddressesInterface>(\n response.data\n )) {\n if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {\n if (network === this._network) this._addresses = addresses;\n this._addressesMap.set(network as NetworkType, addresses);\n }\n }\n this._id = response.data.id;\n return this._addresses;\n } else {\n throw Error('Failed to create addresses.');\n }\n }\n }\n\n /**\n * Update the address through the API and synchronize it back to the\n * instance. If the `network` is not specified, the mainnet is used by default.\n * If no `addresses` is provided, an addresses with all empty strings is created\n * by default.\n *\n * This function only allows for one addresses to be input into a specific network\n * at a time, and does not provide an addresses map for setting addresses\n * across all networks at once.\n *\n * @param id - The id of the addresses to update.\n * @param network - Specifies which network's addresses you want to set.\n * @param addresses - The addresses be setted to the tartget network.\n * @param auth - The authentication api key.\n * @returns The addresses.\n */\n public async update(\n id?: string,\n network?: NetworkType,\n addresses?: AddressesInterface,\n auth?: string\n ) {\n const apiKey = auth || this._auth || undefined;\n const targetId = id || this._id || undefined;\n const targetNetwork = network || this._network;\n const targetAddresses = addresses || this._addresses || undefined;\n if (targetId === undefined) throw Error('Require addresses id.');\n if (apiKey !== undefined) {\n if (id !== this._id) {\n this._addressesMap.clear();\n }\n this.setAddresses(targetNetwork, targetAddresses);\n const response = await this._apiClient.put(\n `${API_BASE_URL}/addresses/${targetId}`,\n JSON.stringify(Object.fromEntries(this._addressesMap)),\n {\n headers: {\n 'Content-Type': 'application/json',\n 'api-key': auth || this._auth,\n },\n }\n );\n\n if (response.status === 200) {\n for (const [network, addresses] of Object.entries<AddressesInterface>(\n response.data\n )) {\n if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {\n if (network === this._network) this._addresses = addresses;\n this._addressesMap.set(network as NetworkType, addresses);\n }\n }\n this._id = response.data.id;\n return this._addresses;\n } else {\n throw Error('Failed to update addresses.');\n }\n } else {\n throw Error(\"You don't have permission to access this request.\");\n }\n }\n\n /**\n * Deletes all addresses of a specified id through the API and synchronizes\n * them back to the instance.\n *\n * @param id - The id of the addresses to delete.\n * @param auth - The authentication API key.\n */\n public async delete(id?: string, auth?: string) {\n const apiKey = auth || this._auth || undefined;\n const targetId = id || this._id || undefined;\n if (targetId === undefined) throw Error('Require addresses id.');\n if (apiKey !== undefined) {\n const response = await this._apiClient.delete(\n `${API_BASE_URL}/addresses/${targetId}`,\n {\n headers: {\n 'Content-Type': 'application/json',\n 'api-key': auth || this._auth,\n },\n }\n );\n\n if (response.status === 200) {\n this._id = undefined;\n this._addresses = undefined;\n this._addressesMap.clear();\n } else {\n throw Error('Failed to delete addresses.');\n }\n } else {\n throw Error(\"You don't have permission to access this request.\");\n }\n }\n}\n","import { normalizeSuiAddress } from '@mysten/sui.js';\nimport { SuiKit } from '@scallop-io/sui-kit';\nimport { ScallopAddress } from './scallopAddress';\nimport { ScallopUtils } from './scallopUtils';\nimport { newScallopTxBlock } from '../txBuilders';\nimport { queryObligation, queryMarket, getObligations } from '../queries';\nimport type {\n TransactionArgument,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js';\nimport type { SuiTxArg } from '@scallop-io/sui-kit';\nimport type {\n ScallopClientFnReturnType,\n ScallopParams,\n SupportAssetCoins,\n SupportCollateralCoins,\n SupportCoins,\n ScallopTxBlock,\n} from '../types';\n\n/**\n * ### Scallop Client\n *\n * it provides contract interaction operations for general users.\n *\n * #### Usage\n *\n * ```typescript\n * const client = new Scallop(<parameters>);\n * client.<interact functions>();\n * ```\n */\nexport class ScallopClient {\n public suiKit: SuiKit;\n public address: ScallopAddress;\n public walletAddress: string;\n\n private readonly _utils: ScallopUtils;\n private readonly _isTestnet: boolean;\n\n public constructor(\n params: ScallopParams,\n address: ScallopAddress,\n walletAddress?: string,\n isTestnet?: boolean\n ) {\n this.suiKit = new SuiKit(params);\n this.address = address;\n this.walletAddress = normalizeSuiAddress(\n walletAddress || this.suiKit.currentAddress()\n );\n this._utils = new ScallopUtils(params);\n this._isTestnet =\n isTestnet ||\n (params.networkType ? params.networkType === 'testnet' : false);\n }\n\n createTxBlock() {\n return newScallopTxBlock(\n this.suiKit,\n this.address,\n this._utils,\n this._isTestnet\n );\n }\n\n /**\n * Query market data.\n *\n * @return Market data\n */\n public async queryMarket() {\n return queryMarket(this.address, this.suiKit);\n }\n\n /**\n * Query obligations data.\n *\n * @param ownerAddress - The owner address.\n * @return Obligations data\n */\n async getObligations(ownerAddress?: string) {\n const owner = ownerAddress || this.walletAddress;\n return getObligations(owner, this.address, this.suiKit);\n }\n\n /**\n * Query obligation data.\n *\n * @param obligationId - The obligation id from protocol package.\n * @return Obligation data\n */\n public async queryObligation(obligationId: string) {\n return queryObligation(obligationId, this.address, this.suiKit);\n }\n\n /**\n * Open obligation.\n *\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @return Transaction block response or transaction block\n */\n public async openObligation(): Promise<SuiTransactionBlockResponse>;\n public async openObligation<S extends boolean>(\n sign?: S\n ): Promise<ScallopClientFnReturnType<S>>;\n public async openObligation<S extends boolean>(\n sign: S = true as S\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n txBlock.openObligationEntry();\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * Deposit collateral into the specific pool.\n *\n * @param coinName - Types of collateral coin.\n * @param amount - The amount of coins would deposit.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @param obligationId - The obligation object.\n * @param walletAddress - The wallet address of the owner.\n * @return Transaction block response or transaction block\n */\n public async depositCollateral(\n coinName: SupportCollateralCoins,\n amount: number\n ): Promise<SuiTransactionBlockResponse>;\n public async depositCollateral<S extends boolean>(\n coinName: SupportCollateralCoins,\n amount: number,\n sign?: S,\n obligationId?: SuiTxArg,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>>;\n public async depositCollateral<S extends boolean>(\n coinName: SupportCollateralCoins,\n amount: number,\n sign: S = true as S,\n obligationId?: SuiTxArg,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const sender = walletAddress || this.walletAddress;\n txBlock.setSender(sender);\n\n if (obligationId) {\n await txBlock.addCollateralQuick(amount, coinName, obligationId);\n } else {\n const [obligation, obligationKey, hotPotato] = txBlock.openObligation();\n await txBlock.addCollateralQuick(amount, coinName, obligation);\n txBlock.returnObligation(obligation, hotPotato);\n txBlock.transferObjects([obligationKey], sender);\n }\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * Withdraw collateral from the specific pool.\n *\n * @param coinName - Types of collateral coin.\n * @param amount - The amount of coins would deposit.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @param obligationId - The obligation object.\n * @param obligationKey - The obligation key object to verifying obligation authority.\n * @param walletAddress - The wallet address of the owner.\n * @return Transaction block response or transaction block\n */\n public async withdrawCollateral<S extends boolean>(\n coinName: SupportCollateralCoins,\n amount: number,\n sign: S = true as S,\n obligationId: string,\n obligationKey: string,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const sender = walletAddress || this.walletAddress;\n txBlock.setSender(sender);\n\n const collateralCoin = await txBlock.takeCollateralQuick(\n amount,\n coinName,\n obligationId,\n obligationKey\n );\n txBlock.transferObjects([collateralCoin], sender);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * Deposit asset into the specific pool.\n *\n * @param coinName - Types of asset coin.\n * @param amount - The amount of coins would deposit.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @param walletAddress - The wallet address of the owner.\n * @return Transaction block response or transaction block\n */\n public async deposit(\n coinName: SupportAssetCoins,\n amount: number\n ): Promise<SuiTransactionBlockResponse>;\n public async deposit<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n sign?: S,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>>;\n public async deposit<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n sign: S = true as S,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const sender = walletAddress || this.walletAddress;\n txBlock.setSender(sender);\n\n const marketCoin = await txBlock.depositQuick(amount, coinName);\n txBlock.transferObjects([marketCoin], sender);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * Withdraw asset from the specific pool, must return market coin.\n *\n * @param coinName - Types of asset coin.\n * @param amount - The amount of coins would withdraw.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @param walletAddress - The wallet address of the owner.\n * @return Transaction block response or transaction block\n */\n public async withdraw(\n coinName: SupportAssetCoins,\n amount: number\n ): Promise<SuiTransactionBlockResponse>;\n public async withdraw<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n sign?: S,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>>;\n public async withdraw<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n sign: S = true as S,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const sender = walletAddress || this.walletAddress;\n txBlock.setSender(sender);\n\n const coin = await txBlock.withdrawQuick(amount, coinName);\n txBlock.transferObjects([coin], sender);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * borrow asset from the specific pool.\n *\n * @param coinName - Types of asset coin.\n * @param amount - The amount of coins would borrow.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @param obligationId - The obligation object.\n * @param obligationKey - The obligation key object to verifying obligation authority.\n * @param walletAddress - The wallet address of the owner.\n * @return Transaction block response or transaction block\n */\n public async borrow<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n sign: S = true as S,\n obligationId: string,\n obligationKey: string,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const sender = walletAddress || this.walletAddress;\n txBlock.setSender(sender);\n\n const coin = await txBlock.borrowQuick(\n amount,\n coinName,\n obligationId,\n obligationKey\n );\n txBlock.transferObjects([coin], sender);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * Repay asset into the specific pool.\n *\n * @param coinName - Types of asset coin.\n * @param amount - The amount of coins would repay.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @param obligationId - The obligation object.\n * @param walletAddress - The wallet address of the owner.\n * @return Transaction block response or transaction block\n */\n public async repay<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n sign: S = true as S,\n obligationId: string,\n walletAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const sender = walletAddress || this.walletAddress;\n txBlock.setSender(sender);\n\n await txBlock.repayQuick(amount, coinName, obligationId);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * FlashLoan asset from the specific pool.\n *\n * @param coinName - Types of asset coin.\n * @param amount - The amount of coins would repay.\n * @param callback - The callback function to build transaction block and return coin argument.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @return Transaction block response or transaction block\n */\n public async flashLoan(\n coinName: SupportAssetCoins,\n amount: number,\n callback: (\n txBlock: ScallopTxBlock,\n coin: TransactionArgument\n ) => TransactionArgument\n ): Promise<SuiTransactionBlockResponse>;\n public async flashLoan<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n callback: (\n txBlock: ScallopTxBlock,\n coin: TransactionArgument\n ) => TransactionArgument,\n sign?: S\n ): Promise<ScallopClientFnReturnType<S>>;\n public async flashLoan<S extends boolean>(\n coinName: SupportAssetCoins,\n amount: number,\n callback: (\n txBlock: ScallopTxBlock,\n coin: TransactionArgument\n ) => TransactionArgument,\n sign: S = true as S\n ): Promise<ScallopClientFnReturnType<S>> {\n const txBlock = this.createTxBlock();\n const [coin, loan] = txBlock.borrowFlashLoan(amount, coinName);\n txBlock.repayFlashLoan(callback(txBlock, coin), loan, coinName);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n\n /**\n * Mint and get test coin.\n *\n * @remarks\n * Only be used on the test network.\n *\n * @param coinName - Types of coins supported on the test network.\n * @param amount - The amount of coins minted and received.\n * @param receiveAddress - The wallet address that receives the coins.\n * @param sign - Decide to directly sign the transaction or return the transaction block.\n * @return Transaction block response or transaction block\n */\n public async mintTestCoin(\n coinName: Exclude<SupportCoins, 'sui'>,\n amount: number\n ): Promise<SuiTransactionBlockResponse>;\n public async mintTestCoin<S extends boolean>(\n coinName: Exclude<SupportCoins, 'sui'>,\n amount: number,\n sign?: S,\n receiveAddress?: string\n ): Promise<ScallopClientFnReturnType<S>>;\n public async mintTestCoin<S extends boolean>(\n coinName: Exclude<SupportCoins, 'sui'>,\n amount: number,\n sign: S = true as S,\n receiveAddress?: string\n ): Promise<ScallopClientFnReturnType<S>> {\n if (!this._isTestnet) {\n throw new Error('Only be used on the test network.');\n }\n\n const txBlock = this.createTxBlock();\n const recipient = receiveAddress || this.walletAddress;\n const packageId = this.address.get('core.packages.testCoin.id');\n const treasuryId = this.address.get(`core.coins.${coinName}.treasury`);\n const target = `${packageId}::${coinName}::mint`;\n const coin = txBlock.moveCall(target, [treasuryId, amount]);\n txBlock.transferObjects([coin], recipient);\n\n if (sign) {\n return (await this.suiKit.signAndSendTxn(\n txBlock\n )) as ScallopClientFnReturnType<S>;\n } else {\n return txBlock.txBlock as ScallopClientFnReturnType<S>;\n }\n }\n}\n","import {\n SUI_FRAMEWORK_ADDRESS,\n SUI_TYPE_ARG,\n normalizeStructTag,\n} from '@mysten/sui.js';\nimport { SuiKit } from '@scallop-io/sui-kit';\nimport { PriceServiceConnection } from '@pythnetwork/price-service-client';\nimport type { ScallopParams, SupportCoins } from '../types';\n\n/**\n * ### Scallop Utils\n *\n * Integrates some helper functions frequently used in interactions with the Scallop contract.\n *\n * #### Usage\n *\n * ```typescript\n * const utils = new ScallopUtils(<parameters>);\n * utils.<help functions>();\n * ```\n */\nexport class ScallopUtils {\n private _suiKit: SuiKit;\n\n public constructor(params: ScallopParams) {\n this._suiKit = new SuiKit(params);\n }\n\n /**\n * @description Select coin id that add up to the given amount as transaction arguments.\n * @param owner The address of the owner.\n * @param amount The amount that is needed for the coin.\n * @param coinType The coin type, default is 0x2::SUI::SUI.\n * @return The selected transaction coin arguments.\n */\n public async selectCoins(\n owner: string,\n amount: number,\n coinType: string = SUI_TYPE_ARG\n ) {\n const coins = await this._suiKit.rpcProvider.selectCoins(\n owner,\n amount,\n coinType\n );\n return coins.map((c) => c.objectId);\n }\n\n /**\n * @description Fetch price feed VAAs of interest from the Pyth.\n * @param priceIds Array of hex-encoded price ids.\n * @param isTestnet Specify whether it is a test network.\n * @return Array of base64 encoded VAAs.\n */\n public async getVaas(priceIds: string[], isTestnet?: boolean) {\n const connection = new PriceServiceConnection(\n isTestnet\n ? 'https://xc-testnet.pyth.network'\n : 'https://xc-mainnet.pyth.network',\n {\n priceFeedRequestConfig: {\n binary: true,\n },\n }\n );\n return await connection.getLatestVaas(priceIds);\n }\n\n /**\n * @description Handle non-standard coins.\n * @param coinPackageId Package id of coin.\n * @param coinName specific support coin name.\n * @return coinType.\n */\n public parseCoinType(coinPackageId: string, coinName: string) {\n if (coinName === 'sui') return normalizeStructTag(SUI_TYPE_ARG);\n const wormHoleCoins = [\n // USDC\n '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf',\n // USDT\n '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c',\n ];\n if (wormHoleCoins.includes(coinPackageId)) {\n return `${coinPackageId}::coin::COIN`;\n } else {\n return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;\n }\n }\n\n /**\n * @description Handle non-standard coin names.\n * @param coinPackageId Package id of coin.\n * @param coinName specific support coin name.\n * @return coinType.\n */\n public getCoinNameFromCoinType(coinType: string) {\n const wormHoleCoinTypes = [\n // USDC\n '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',\n // USDT\n '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN',\n ];\n\n if (coinType === wormHoleCoinTypes[0]) {\n return 'usdc';\n } else if (coinType === wormHoleCoinTypes[1]) {\n return 'usdt';\n } else {\n return coinType.split('::')[2].toLowerCase() as SupportCoins;\n }\n }\n\n /**\n * @description Handle market coin types.\n *\n * @param coinPackageId Package id of coin.\n * @param protocolPkgId Package id of protocol.\n * @param coinName specific support coin name.\n *\n * @return marketCoinType.\n */\n public parseMarketCoinType(\n coinPackageId: string,\n protocolPkgId: string,\n coinName: string\n ) {\n const coinType = this.parseCoinType(\n coinName === 'sui' ? SUI_FRAMEWORK_ADDRESS : coinPackageId,\n coinName\n );\n return `${protocolPkgId}::reserve::MarketCoin<${coinType}>`;\n }\n}\n","import { SuiKit, SuiTxBlock } from '@scallop-io/sui-kit';\nimport { ScallopAddress } from '../models';\nimport { MarketInterface } from '../types';\n\nexport const queryMarket = async (\n scallopAddress: ScallopAddress,\n suiKit: SuiKit\n) => {\n const packageId = scallopAddress.get('core.packages.query.id');\n const marketId = scallopAddress.get('core.market');\n const txBlock = new SuiTxBlock();\n const queryTarget = `${packageId}::market_query::market_data`;\n txBlock.moveCall(queryTarget, [marketId]);\n const queryResult = await suiKit.inspectTxn(txBlock);\n return queryResult.events[0].parsedJson as MarketInterface;\n};\n","import { SuiKit, SuiTxBlock } from '@scallop-io/sui-kit';\nimport { ScallopAddress } from '../models';\nimport { ObligationInterface } from '../types';\n\nexport const queryObligation = async (\n obligationId: string,\n scallopAddress: ScallopAddress,\n suiKit: SuiKit\n) => {\n const packageId = scallopAddress.get('core.packages.query.id');\n const queryTarget = `${packageId}::obligation_query::obligation_data`;\n const txBlock = new SuiTxBlock();\n txBlock.moveCall(queryTarget, [obligationId]);\n const queryResult = await suiKit.inspectTxn(txBlock);\n return queryResult.events[0].parsedJson as ObligationInterface;\n};\n\nexport const getObligations = async (\n ownerAddress: string,\n scallopAddress: ScallopAddress,\n suiKit: SuiKit\n) => {\n const owner = ownerAddress || suiKit.currentAddress();\n const keyObjectRefs = await suiKit.provider().getOwnedObjects({\n owner,\n filter: {\n StructType: `${scallopAddress.get(\n 'core.packages.protocol.id'\n )}::obligation::ObligationKey`,\n },\n });\n const keyIds = keyObjectRefs.data\n .map((ref: any) => ref?.data?.objectId)\n .filter((id: any) => id !== undefined) as string[];\n const keyObjects = await suiKit.getObjects(keyIds);\n const obligations: { id: string; keyId: string }[] = [];\n for (const keyObject of keyObjects) {\n const keyId = keyObject.objectId;\n const fields = keyObject.objectFields as any;\n const obligationId = fields['ownership']['fields']['of'];\n obligations.push({ id: obligationId, keyId });\n }\n return obligations;\n};\n","import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui.js';\nimport { SuiTxBlock } from '@scallop-io/sui-kit';\nimport { ScallopAddress, ScallopUtils } from '../models';\nimport type {\n ScallopNormalMethodsHandler,\n SuiTxBlockWithNormalScallopMethods,\n CoreIds,\n} from '../types';\n\nconst scallopNormalMethodsHandler: ScallopNormalMethodsHandler = {\n openObligation:\n ({ txBlock, coreIds }) =>\n () =>\n txBlock.moveCall(\n `${coreIds.protocolPkg}::open_obligation::open_obligation`,\n [coreIds.version]\n ),\n returnObligation:\n ({ txBlock, coreIds }) =>\n (obligation, obligationHotPotato) =>\n txBlock.moveCall(\n `${coreIds.protocolPkg}::open_obligation::return_obligation`,\n [coreIds.version, obligation, obligationHotPotato]\n ),\n openObligationEntry:\n ({ txBlock, coreIds }) =>\n () =>\n txBlock.moveCall(\n `${coreIds.protocolPkg}::open_obligation::open_obligation_entry`,\n [coreIds.version]\n ),\n addCollateral:\n ({ txBlock, coreIds, scallopUtils, scallopAddress }) =>\n (obligation, coin, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::deposit_collateral::deposit_collateral`,\n [coreIds.version, obligation, coreIds.market, coin],\n [coinType]\n );\n },\n takeCollateral:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (obligation, obligationKey, amount, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::withdraw_collateral::withdraw_collateral`,\n [\n coreIds.version,\n obligation,\n obligationKey,\n coreIds.market,\n coreIds.dmlR,\n amount,\n coreIds.oracle,\n SUI_CLOCK_OBJECT_ID,\n ],\n [coinType]\n );\n },\n deposit:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (coin, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::mint::mint`,\n [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID],\n [coinType]\n );\n },\n depositEntry:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (coin, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::mint::mint_entry`,\n [coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID],\n [coinType]\n );\n },\n withdraw:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (marketCoin, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::redeem::redeem`,\n [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID],\n [coinType]\n );\n },\n withdrawEntry:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (marketCoin, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::redeem::redeem_entry`,\n [coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID],\n [coinType]\n );\n },\n borrow:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (obligation, obligationKey, amount, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::borrow::borrow`,\n [\n coreIds.version,\n obligation,\n obligationKey,\n coreIds.market,\n coreIds.dmlR,\n amount,\n coreIds.oracle,\n SUI_CLOCK_OBJECT_ID,\n ],\n [coinType]\n );\n },\n borrowEntry:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (obligation, obligationKey, amount, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::borrow::borrow_entry`,\n [\n coreIds.version,\n obligation,\n obligationKey,\n coreIds.market,\n coreIds.dmlR,\n amount,\n coreIds.oracle,\n SUI_CLOCK_OBJECT_ID,\n ],\n [coinType]\n );\n },\n repay:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (obligation, coin, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::repay::repay`,\n [\n coreIds.version,\n obligation,\n coreIds.market,\n coin,\n SUI_CLOCK_OBJECT_ID,\n ],\n [coinType]\n );\n },\n borrowFlashLoan:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (amount, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::flash_loan::borrow_flash_loan`,\n [coreIds.version, coreIds.market, amount],\n [coinType]\n );\n },\n repayFlashLoan:\n ({ txBlock, coreIds, scallopAddress, scallopUtils }) =>\n (coin, loan, coinName) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n return txBlock.moveCall(\n `${coreIds.protocolPkg}::flash_loan::repay_flash_loan`,\n [coreIds.version, coreIds.market, coin, loan],\n [coinType]\n );\n },\n};\n\nexport const newTxBlock = (\n scallopAddress: ScallopAddress,\n scallopUtils: ScallopUtils\n) => {\n const coreIds: CoreIds = {\n protocolPkg: scallopAddress.get('core.packages.protocol.id'),\n market: scallopAddress.get('core.market'),\n version: scallopAddress.get('core.version'),\n dmlR: scallopAddress.get('core.coinDecimalsRegistry'),\n oracle: scallopAddress.get('core.oracles.xOracle'),\n };\n const txBlock = new SuiTxBlock();\n const txBlockProxy = new Proxy(txBlock, {\n get: (target, prop) => {\n if (prop in scallopNormalMethodsHandler) {\n return scallopNormalMethodsHandler[\n prop as keyof ScallopNormalMethodsHandler\n ]({\n txBlock: target,\n coreIds,\n scallopAddress,\n scallopUtils,\n });\n }\n return target[prop as keyof SuiTxBlock];\n },\n });\n return txBlockProxy as SuiTxBlockWithNormalScallopMethods;\n};\n","import { fromB64 } from '@mysten/bcs';\nimport { SUI_CLOCK_OBJECT_ID, TransactionArgument } from '@mysten/sui.js';\nimport { SuiTxBlock, SuiKit } from '@scallop-io/sui-kit';\nimport { ScallopAddress, ScallopUtils } from '../models';\nimport { SupportCoins, SupportAssetCoins, SupportOracleType } from '../types';\nimport { queryObligation } from '../queries';\n\nexport const updateOraclesForWithdrawCollateral = async (\n txBlock: SuiTxBlock,\n address: ScallopAddress,\n scallopUtils: ScallopUtils,\n suiKit: SuiKit,\n obligationId: string,\n isTestnet: boolean\n) => {\n const obligationCoinNames = await getObligationCoinNames(\n suiKit,\n obligationId,\n address,\n scallopUtils\n );\n return updateOracles(\n txBlock,\n address,\n scallopUtils,\n obligationCoinNames,\n isTestnet\n );\n};\n\nexport const updateOraclesForLiquidation = async (\n txBlock: SuiTxBlock,\n address: ScallopAddress,\n scallopUtils: ScallopUtils,\n suiKit: SuiKit,\n obligationId: string,\n isTestnet: boolean\n) => {\n const obligationCoinNames = await getObligationCoinNames(\n suiKit,\n obligationId,\n address,\n scallopUtils\n );\n return updateOracles(\n txBlock,\n address,\n scallopUtils,\n obligationCoinNames,\n isTestnet\n );\n};\n\nexport const updateOraclesForBorrow = async (\n txBlock: SuiTxBlock,\n address: ScallopAddress,\n scallopUtils: ScallopUtils,\n suiKit: SuiKit,\n obligationId: string,\n borrowCoinName: SupportAssetCoins,\n isTestnet: boolean\n) => {\n const obligationCoinNames = await getObligationCoinNames(\n suiKit,\n obligationId,\n address,\n scallopUtils\n );\n const updateCoinNames = [\n ...new Set([...obligationCoinNames, borrowCoinName]),\n ];\n return updateOracles(\n txBlock,\n address,\n scallopUtils,\n updateCoinNames,\n isTestnet\n );\n};\n\nconst getObligationCoinNames = async (\n suiKit: SuiKit,\n obligationId: string,\n address: ScallopAddress,\n scallopUtils: ScallopUtils\n) => {\n const obligation = await queryObligation(obligationId, address, suiKit);\n const collateralCoinTypes = obligation.collaterals.map((collateral) => {\n return `0x${collateral.type.name}`;\n });\n const debtCoinTypes = obligation.debts.map((debt) => {\n return `0x${debt.type.name}`;\n });\n const obligationCoinTypes = [\n ...new Set([...collateralCoinTypes, ...debtCoinTypes]),\n ];\n const obligationCoinNames = obligationCoinTypes.map((coinType) => {\n return scallopUtils.getCoinNameFromCoinType(coinType);\n });\n return obligationCoinNames;\n};\n\nexport const updateOracles = async (\n txBlock: SuiTxBlock,\n address: ScallopAddress,\n scallopUtils: ScallopUtils,\n coinNames: SupportCoins[],\n isTestnet: boolean\n) => {\n const updateCoinTypes = [...new Set(coinNames)];\n for (const coinName of updateCoinTypes) {\n await updateOracle(txBlock, address, scallopUtils, coinName, isTestnet);\n }\n};\n\nconst updateOracle = async (\n txBlock: SuiTxBlock,\n address: ScallopAddress,\n scallopUtils: ScallopUtils,\n coinName: SupportCoins,\n isTestnet: boolean\n) => {\n const coinPackageId = address.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n const [vaaFromFeeId] = await scallopUtils.getVaas(\n [address.get(`core.coins.${coinName}.oracle.pyth.feed`)],\n isTestnet\n );\n\n updatePrice(\n txBlock,\n isTestnet ? ['pyth'] : ['pyth'],\n address.get('core.packages.xOracle.id'),\n address.get('core.oracles.xOracle'),\n address.get('core.packages.pyth.id'),\n address.get('core.oracles.pyth.registry'),\n address.get('core.oracles.pyth.state'),\n address.get('core.oracles.pyth.wormholeState'),\n address.get(`core.coins.${coinName}.oracle.pyth.feedObject`),\n vaaFromFeeId,\n address.get('core.packages.switchboard.id'),\n address.get('core.oracles.switchboard.registry'),\n address.get(`core.coins.${coinName}.oracle.switchboard`),\n address.get('core.packages.supra.id'),\n address.get('core.oracles.supra.registry'),\n address.get(`core.oracles.supra.holder`),\n coinType\n );\n};\n\n/**\n * Construct a transaction block for update the price.\n *\n * @param txBlock - The transaction block.\n * @param rules - The oracle rules.\n * @param xOraclePackageId - The xOracle package id.\n * @param xOracleId - The xOracle Id from xOracle package.\n * @param pythPackageId - The pyth package id.\n * @param pythRegistryId - The registry id from pyth package.\n * @param pythStateId - The price state id from pyth package.\n * @param pythWormholeStateId - The whormhole state id from pyth package.\n * @param pythFeedObjectId - The feed object id from pyth package.\n * @param pythVaaFromFeeId - The vaa from pyth api with feed id.\n * @param switchboardPackageId - The switchboard package id.\n * @param switchboardRegistryId - The registry id from switchboard package.\n * @param switchboardAggregatorId - The aggregator id from switchboard package.\n * @param supraPackageId - The supra package id.\n * @param supraRegistryId - The registry id from supra package.\n * @param supraHolderId - The holder id from supra package.\n * @param coinType - The type of coin.\n * @returns Sui-Kit type transaction block.\n */\nfunction updatePrice(\n txBlock: SuiTxBlock,\n rules: SupportOracleType[],\n xOraclePackageId: string,\n xOracleId: TransactionArgument | string,\n pythPackageId: string,\n pythRegistryId: TransactionArgument | string,\n pythStateId: TransactionArgument | string,\n pythWormholeStateId: TransactionArgument | string,\n pythFeedObjectId: TransactionArgument | string,\n pythVaaFromFeeId: string,\n switchboardPackageId: string,\n switchboardRegistryId: TransactionArgument | string,\n switchboardAggregatorId: TransactionArgument | string,\n supraPackageId: string,\n supraRegistryId: TransactionArgument | string,\n supraHolderId: TransactionArgument | string,\n coinType: string\n) {\n const request = priceUpdateRequest(\n txBlock,\n xOraclePackageId,\n xOracleId,\n coinType\n );\n if (rules.includes('pyth')) {\n updatePythPrice(\n txBlock,\n pythPackageId,\n request,\n pythStateId,\n pythWormholeStateId,\n pythFeedObjectId,\n pythVaaFromFeeId,\n pythRegistryId,\n coinType\n );\n }\n if (rules.includes('switchboard')) {\n updateSwitchboardPrice(\n txBlock,\n switchboardPackageId,\n request,\n switchboardAggregatorId,\n switchboardRegistryId,\n coinType\n );\n }\n if (rules.includes('supra')) {\n updateSupraPrice(\n txBlock,\n supraPackageId,\n request,\n supraHolderId,\n supraRegistryId,\n coinType\n );\n }\n confirmPriceUpdateRequest(\n txBlock,\n xOraclePackageId,\n xOracleId,\n request,\n coinType\n );\n return txBlock;\n}\n\n/**\n * Construct a transaction block for request price update.\n *\n * @param txBlock - The transaction block.\n * @param packageId - The xOracle package id.\n * @param xOracleId - The xOracle Id from xOracle package.\n * @param coinType - The type of coin.\n * @returns Sui-Kit type transaction block.\n */\nfunction priceUpdateRequest(\n txBlock: SuiTxBlock,\n packageId: string,\n xOracleId: TransactionArgument | string,\n coinType: string\n) {\n const target = `${packageId}::x_oracle::price_update_request`;\n const typeArgs = [coinType];\n return txBlock.moveCall(target, [xOracleId], typeArgs);\n}\n\n/**\n * Construct a transaction block for confirm price update request.\n *\n * @param txBlock - The transaction block.\n * @param packageId - The xOracle package id.\n * @param xOracleId - The xOracle Id from xOracle package.\n * @param request - The result of the request.\n * @param coinType - The type of coin.\n * @returns Sui-Kit type transaction block.\n */\nfunction confirmPriceUpdateRequest(\n txBlock: SuiTxBlock,\n packageId: string,\n xOracleId: TransactionArgument | string,\n request: TransactionArgument,\n coinType: string\n) {\n const target = `${packageId}::x_oracle::confirm_price_update_request`;\n const typeArgs = [coinType];\n txBlock.moveCall(target, [xOracleId, request, SUI_CLOCK_OBJECT_ID], typeArgs);\n return txBlock;\n}\n\n/**\n * Construct a transaction block for update supra price.\n *\n * @param txBlock - The transaction block.\n * @param packageId - The supra package id.\n * @param request - The result of the request.\n * @param holderId - The holder id from supra package.\n * @param registryId - The registry id from supra package.\n * @param coinType - The type of coin.\n * @returns Sui-Kit type transaction block.\n */\nfunction updateSupraPrice(\n txBlock: SuiTxBlock,\n packageId: string,\n request: TransactionArgument,\n holderId: TransactionArgument | string,\n registryId: TransactionArgument | string,\n coinType: string\n) {\n txBlock.moveCall(\n `${packageId}::rule::set_price`,\n [request, holderId, registryId, SUI_CLOCK_OBJECT_ID],\n [coinType]\n );\n}\n\n/**\n * Construct a transaction block for update switchboard price.\n *\n * @param txBlock - The transaction block.\n * @param packageId - The switchboard package id.\n * @param request - The result of the request.\n * @param aggregatorId - The aggregator id from switchboard package.\n * @param registryId - The registry id from switchboard package.\n * @param coinType - The type of coin.\n * @returns Sui-Kit type transaction block.\n */\nfunction updateSwitchboardPrice(\n txBlock: SuiTxBlock,\n packageId: string,\n request: TransactionArgument,\n aggregatorId: TransactionArgument | string,\n registryId: TransactionArgument | string,\n coinType: string\n) {\n txBlock.moveCall(\n `${packageId}::rule::set_price`,\n [request, aggregatorId, registryId, SUI_CLOCK_OBJECT_ID],\n [coinType]\n );\n}\n\n/**\n * Construct a transaction block for update pyth price.\n *\n * @param txBlock - The transaction block.\n * @param packageId - The pyth package id.\n * @param request - The result of the request.\n * @param stateId - The price state id from pyth package.\n * @param wormholeStateId - The whormhole state id from pyth package.\n * @param feedObjectId - The feed object id from pyth package.\n * @param vaaFromFeeId - The vaa from pyth api with feed id.\n * @param registryId - The registry id from pyth package.\n * @param coinType - The type of coin.\n * @returns Sui-Kit type transaction block.\n */\nfunction updatePythPrice(\n txBlock: SuiTxBlock,\n packageId: string,\n request: TransactionArgument,\n stateId: TransactionArgument | string,\n wormholeStateId: TransactionArgument | string,\n feedObjectId: TransactionArgument | string,\n vaaFromFeeId: string,\n registryId: TransactionArgument | string,\n coinType: string\n) {\n const [updateFee] = txBlock.splitSUIFromGas([1]);\n txBlock.moveCall(\n `${packageId}::rule::set_price`,\n [\n request,\n wormholeStateId,\n stateId,\n feedObjectId,\n registryId,\n txBlock.pure([...fromB64(vaaFromFeeId)]),\n updateFee,\n SUI_CLOCK_OBJECT_ID,\n ],\n [coinType]\n );\n}\n","import { SuiTxBlock } from '@scallop-io/sui-kit';\nimport { ScallopAddress, ScallopUtils } from '../models';\nimport { SupportCoins } from '../types';\n\nexport const selectCoin = async (\n txBlock: SuiTxBlock,\n scallopAddress: ScallopAddress,\n scallopUtils: ScallopUtils,\n coinName: SupportCoins,\n amount: number,\n sender: string\n) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);\n const coins = await scallopUtils.selectCoins(sender, amount, coinType);\n const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);\n return { takeCoin, leftCoin };\n};\n\nexport const selectMarketCoin = async (\n txBlock: SuiTxBlock,\n scallopAddress: ScallopAddress,\n scallopUtils: ScallopUtils,\n coinName: SupportCoins,\n amount: number,\n sender: string\n) => {\n const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);\n const protocolPackageId = scallopAddress.get('core.packages.protocol.id');\n const coinType = scallopUtils.parseMarketCoinType(\n coinPackageId,\n protocolPackageId,\n coinName\n );\n const coins = await scallopUtils.selectCoins(sender, amount, coinType);\n const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);\n return { takeCoin, leftCoin };\n};\n","/**\n * This file contains the complex transaction builder, which contains multiple calls in a single transaction.\n */\nimport { SuiTxBlock, SuiKit } from '@scallop-io/sui-kit';\nimport { ScallopAddress, ScallopUtils } from '../models';\nimport { getObligations } from '../queries';\nimport { newTxBlock } from './normalMethods';\nimport {\n updateOraclesForBorrow,\n updateOraclesForWithdrawCollateral,\n updateOracles,\n} from './oracle';\nimport { selectCoin, selectMarketCoin } from './coin';\nimport type { SuiTxArg } from '@scallop-io/sui-kit';\nimport type { ScallopQuickMethodsHandler, ScallopTxBlock } from '../types';\n\nconst requireSender = (txBlock: SuiTxBlock) => {\n const sender = txBlock.blockData.sender;\n if (!sender) {\n throw new Error('Sender is required');\n }\n return sender;\n};\n\nconst requireObligationInfo = async (\n ...args: [\n txBlock: SuiTxBlock,\n scallopAddress: ScallopAddress,\n suiKit: SuiKit,\n obligationId?: SuiTxArg | undefined,\n obligationKey?: SuiTxArg | undefined\n ]\n) => {\n const [txBlock, scallopAddress, suiKit, obligationId, obligationKey] = args;\n if (args.length === 4 && obligationId) return { obligationId };\n if (args.length === 5 && obligationId && obligationKey)\n return { obligationId, obligationKey };\n const sender = requireSender(txBlock);\n const obligations = await getObligations(sender, scallopAddress, suiKit);\n if (obligations.length === 0) {\n throw new Error(`No obligation found for sender ${sender}`);\n }\n return {\n obligationId: obligations[0].id,\n obligationKey: obligations[0].keyId,\n };\n};\n\nconst scallopQuickMethodsHandler: ScallopQuickMethodsHandler = {\n addCollateralQuick:\n ({ txBlock, scallopAddress, scallopUtils, suiKit }) =>\n async (amount, coinName, obligationId) => {\n const sender = requireSender(txBlock);\n const { obligationId: obligationArg } = await requireObligationInfo(\n txBlock,\n scallopAddress,\n suiKit,\n obligationId\n );\n\n if (coinName === 'sui') {\n const [suiCoin] = txBlock.splitSUIFromGas([amount]);\n txBlock.addCollateral(obligationArg, suiCoin, coinName);\n } else {\n const { leftCoin, takeCoin } = await selectCoin(\n txBlock,\n scallopAddress,\n scallopUtils,\n coinName,\n amount,\n sender\n );\n txBlock.addCollateral(obligationArg, takeCoin, coinName);\n txBlock.transferObjects([leftCoin], sender);\n }\n },\n takeCollateralQuick:\n ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) =>\n async (amount, coinName, obligationId, obligationKey) => {\n const { obligationId: obligationArg, obligationKey: obligationKeyArg } =\n await requireObligationInfo(\n txBlock,\n scallopAddress,\n suiKit,\n obligationId,\n obligationKey\n );\n\n await updateOraclesForWithdrawCollateral(\n txBlock,\n scallopAddress,\n scallopUtils,\n suiKit,\n obligationArg as string,\n isTestnet\n );\n return txBlock.takeCollateral(\n obligationArg,\n obligationKeyArg as SuiTxArg,\n amount,\n coinName\n );\n },\n depositQuick:\n ({ txBlock, scallopUtils, scallopAddress }) =>\n async (amount, coinName) => {\n const sender = requireSender(txBlock);\n if (coinName === 'sui') {\n const [suiCoin] = txBlock.splitSUIFromGas([amount]);\n return txBlock.deposit(suiCoin, coinName);\n } else {\n const { leftCoin, takeCoin } = await selectCoin(\n txBlock,\n scallopAddress,\n scallopUtils,\n coinName,\n amount,\n sender\n );\n txBlock.transferObjects([leftCoin], sender);\n return txBlock.deposit(takeCoin, coinName);\n }\n },\n withdrawQuick:\n ({ txBlock, scallopUtils, scallopAddress }) =>\n async (amount, coinName) => {\n const sender = requireSender(txBlock);\n const { leftCoin, takeCoin } = await selectMarketCoin(\n txBlock,\n scallopAddress,\n scallopUtils,\n coinName,\n amount,\n sender\n );\n txBlock.transferObjects([leftCoin], sender);\n return txBlock.withdraw(takeCoin, coinName);\n },\n borrowQuick:\n ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) =>\n async (amount, coinName, obligationId, obligationKey) => {\n const { obligationId: obligationArg, obligationKey: obligationKeyArg } =\n await requireObligationInfo(\n txBlock,\n scallopAddress,\n suiKit,\n obligationId,\n obligationKey\n );\n\n await updateOraclesForBorrow(\n txBlock,\n scallopAddress,\n scallopUtils,\n suiKit,\n obligationArg as string,\n coinName,\n isTestnet\n );\n return txBlock.borrow(\n obligationArg,\n obligationKeyArg as SuiTxArg,\n amount,\n coinName\n );\n },\n repayQuick:\n ({ txBlock, suiKit, scallopUtils, scallopAddress }) =>\n async (amount, coinName, obligationId) => {\n const sender = requireSender(txBlock);\n const { obligationId: obligationArg } = await requireObligationInfo(\n txBlock,\n scallopAddress,\n suiKit,\n obligationId\n );\n\n if (coinName === 'sui') {\n const [suiCoin] = txBlock.splitSUIFromGas([amount]);\n return txBlock.repay(obligationArg, suiCoin, coinName);\n } else {\n const { leftCoin, takeCoin } = await selectCoin(\n txBlock,\n scallopAddress,\n scallopUtils,\n coinName,\n amount,\n sender\n );\n txBlock.transferObjects([leftCoin], sender);\n return txBlock.repay(obligationArg, takeCoin, coinName);\n }\n },\n updateAssetPricesQuick:\n ({ txBlock, scallopUtils, scallopAddress, isTestnet }) =>\n async (coinNames) => {\n return updateOracles(\n txBlock,\n scallopAddress,\n scallopUtils,\n coinNames,\n isTestnet\n );\n },\n};\n\nexport const newScallopTxBlock = (\n suiKit: SuiKit,\n scallopAddress: ScallopAddress,\n scallopUtils: ScallopUtils,\n isTestnet: boolean\n) => {\n const txBlock = newTxBlock(scallopAddress, scallopUtils);\n const txBlockProxy = new Proxy(txBlock, {\n get: (target, prop) => {\n if (prop in scallopQuickMethodsHandler) {\n return scallopQuickMethodsHandler[\n prop as keyof ScallopQuickMethodsHandler\n ]({\n txBlock: target,\n suiKit,\n scallopAddress,\n scallopUtils,\n isTestnet,\n });\n }\n return target[prop as keyof SuiTxBlock];\n },\n });\n return txBlockProxy as ScallopTxBl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export * from './scallop';
2
+ export * from './scallopClient';
3
+ export * from './scallopUtils';
4
+ export * from './scallopAddress';
@@ -0,0 +1,46 @@
1
+ import { SuiKit } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress } from './scallopAddress';
3
+ import { ScallopClient } from './scallopClient';
4
+ import type { NetworkType } from '@scallop-io/sui-kit';
5
+ import type { ScallopParams, ScallopTxBlock } from '../types';
6
+ /**
7
+ * ### Scallop
8
+ *
9
+ * The main instance that controls interaction with the Scallop contract.
10
+ *
11
+ * #### Usage
12
+ *
13
+ * ```typescript
14
+ * const sdk = new Scallop(<parameters>);
15
+ * ```
16
+ */
17
+ export declare class Scallop {
18
+ params: ScallopParams;
19
+ suiKit: SuiKit;
20
+ address: ScallopAddress;
21
+ constructor(params: ScallopParams);
22
+ /**
23
+ * Create an instance to operate the transaction block, making it more convenient to organize transaction combinations.
24
+ * @return Scallop Transaction Builder
25
+ */
26
+ createTxBuilder(): Promise<{
27
+ createTxBlock: () => ScallopTxBlock;
28
+ signAndSendTxBlock: (txBlock: ScallopTxBlock) => Promise<Infer<any>>;
29
+ }>;
30
+ /**
31
+ * Create an instance to collect the addresses, making it easier to get object addresses from lending contract.
32
+ *
33
+ * @param id - The API id of the addresses.
34
+ * @param auth - The authentication API key.
35
+ * @param network - Specifies which network's addresses you want to set.
36
+ * @return Scallop Address
37
+ */
38
+ createAddress(id: string, auth: string, network: NetworkType): ScallopAddress;
39
+ /**
40
+ * Create an instance that provides contract interaction operations for general users.
41
+ *
42
+ * @param walletAddress - When user cannot provide a secret key or mnemonic, the scallop client cannot directly derive the address of the transaction the user wants to sign. This argument specifies the wallet address for signing the transaction.
43
+ * @return Scallop Client
44
+ */
45
+ createScallopClient(walletAddress?: string): Promise<ScallopClient>;
46
+ }
@@ -0,0 +1,107 @@
1
+ import type { NetworkType } from '@scallop-io/sui-kit';
2
+ import type { ScallopAddressParams, AddressesInterface, AddressStringPath } from '../types';
3
+ /**
4
+ * it provides methods for managing addresses.
5
+ */
6
+ export declare class ScallopAddress {
7
+ private _apiClient;
8
+ private _id?;
9
+ private readonly _auth?;
10
+ private readonly _network;
11
+ private _addresses?;
12
+ private _addressesMap;
13
+ constructor(params: ScallopAddressParams);
14
+ /**
15
+ * Get addresses API id.
16
+ *
17
+ * @returns The addresses API id.
18
+ */
19
+ getId(): string | undefined;
20
+ /**
21
+ * Get the address at the provided path.
22
+ *
23
+ * @param path - The path of the address to get.
24
+ * @returns The address at the provided path.
25
+ */
26
+ get(path: AddressStringPath): any;
27
+ /**
28
+ * Set the address at the provided path.
29
+ *
30
+ * @param path - The path of the address to set.
31
+ * @param address - The address be setted to the tartget path.
32
+ * @returns The addresses.
33
+ */
34
+ set(path: AddressStringPath, address: string): AddressesInterface | undefined;
35
+ /**
36
+ * Get the addresses.
37
+ *
38
+ * @param network - Specifies which network's addresses you want to get.
39
+ * @returns The addresses.
40
+ */
41
+ getAddresses(network?: NetworkType): AddressesInterface | undefined;
42
+ /**
43
+ * Set the addresses into addresses map.
44
+ *
45
+ * @param network - Specifies which network's addresses you want to set.
46
+ * @param addresses - The addresses be setted to the tartget network.
47
+ * @returns The addresses.
48
+ */
49
+ setAddresses(network?: NetworkType, addresses?: AddressesInterface): void;
50
+ /**
51
+ * Get all addresses.
52
+ *
53
+ * @returns All addresses.
54
+ */
55
+ getAllAddresses(): {
56
+ [k: string]: AddressesInterface;
57
+ };
58
+ /**
59
+ * Create a new address through the API and synchronize it back to the
60
+ * instance. If the `network` is not specified, the mainnet is used by default.
61
+ * If no `addresses` is provided, an addresses with all empty strings is created
62
+ * by default.
63
+ *
64
+ * This function only allows for one addresses to be input into a specific network
65
+ * at a time, and does not provide an addresses map for setting addresses
66
+ * across all networks at once.
67
+ *
68
+ * @param network - Specifies which network's addresses you want to set.
69
+ * @param addresses - The addresses be setted to the tartget network.
70
+ * @param auth - The authentication API key.
71
+ * @returns The addresses.
72
+ */
73
+ create(network?: NetworkType, addresses?: AddressesInterface, auth?: string): Promise<AddressesInterface | undefined>;
74
+ /**
75
+ * It doesn't read the data stored in the address instance, but reads and
76
+ * synchronizes the data from the API into instance.
77
+ *
78
+ * @param id - The id of the addresses to get.
79
+ * @returns The addresses.
80
+ */
81
+ read(id?: string): Promise<AddressesInterface | undefined>;
82
+ /**
83
+ * Update the address through the API and synchronize it back to the
84
+ * instance. If the `network` is not specified, the mainnet is used by default.
85
+ * If no `addresses` is provided, an addresses with all empty strings is created
86
+ * by default.
87
+ *
88
+ * This function only allows for one addresses to be input into a specific network
89
+ * at a time, and does not provide an addresses map for setting addresses
90
+ * across all networks at once.
91
+ *
92
+ * @param id - The id of the addresses to update.
93
+ * @param network - Specifies which network's addresses you want to set.
94
+ * @param addresses - The addresses be setted to the tartget network.
95
+ * @param auth - The authentication api key.
96
+ * @returns The addresses.
97
+ */
98
+ update(id?: string, network?: NetworkType, addresses?: AddressesInterface, auth?: string): Promise<AddressesInterface | undefined>;
99
+ /**
100
+ * Deletes all addresses of a specified id through the API and synchronizes
101
+ * them back to the instance.
102
+ *
103
+ * @param id - The id of the addresses to delete.
104
+ * @param auth - The authentication API key.
105
+ */
106
+ delete(id?: string, auth?: string): Promise<void>;
107
+ }
@@ -0,0 +1,151 @@
1
+ import { SuiKit } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress } from './scallopAddress';
3
+ import type { TransactionArgument, SuiTransactionBlockResponse } from '@mysten/sui.js';
4
+ import type { SuiTxArg } from '@scallop-io/sui-kit';
5
+ import type { ScallopClientFnReturnType, ScallopParams, SupportAssetCoins, SupportCollateralCoins, SupportCoins, ScallopTxBlock } from '../types';
6
+ /**
7
+ * ### Scallop Client
8
+ *
9
+ * it provides contract interaction operations for general users.
10
+ *
11
+ * #### Usage
12
+ *
13
+ * ```typescript
14
+ * const client = new Scallop(<parameters>);
15
+ * client.<interact functions>();
16
+ * ```
17
+ */
18
+ export declare class ScallopClient {
19
+ suiKit: SuiKit;
20
+ address: ScallopAddress;
21
+ walletAddress: string;
22
+ private readonly _utils;
23
+ private readonly _isTestnet;
24
+ constructor(params: ScallopParams, address: ScallopAddress, walletAddress?: string, isTestnet?: boolean);
25
+ createTxBlock(): ScallopTxBlock;
26
+ /**
27
+ * Query market data.
28
+ *
29
+ * @return Market data
30
+ */
31
+ queryMarket(): Promise<import("../types").MarketInterface>;
32
+ /**
33
+ * Query obligations data.
34
+ *
35
+ * @param ownerAddress - The owner address.
36
+ * @return Obligations data
37
+ */
38
+ getObligations(ownerAddress?: string): Promise<{
39
+ id: string;
40
+ keyId: string;
41
+ }[]>;
42
+ /**
43
+ * Query obligation data.
44
+ *
45
+ * @param obligationId - The obligation id from protocol package.
46
+ * @return Obligation data
47
+ */
48
+ queryObligation(obligationId: string): Promise<import("../types").ObligationInterface>;
49
+ /**
50
+ * Open obligation.
51
+ *
52
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
53
+ * @return Transaction block response or transaction block
54
+ */
55
+ openObligation(): Promise<SuiTransactionBlockResponse>;
56
+ openObligation<S extends boolean>(sign?: S): Promise<ScallopClientFnReturnType<S>>;
57
+ /**
58
+ * Deposit collateral into the specific pool.
59
+ *
60
+ * @param coinName - Types of collateral coin.
61
+ * @param amount - The amount of coins would deposit.
62
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
63
+ * @param obligationId - The obligation object.
64
+ * @param walletAddress - The wallet address of the owner.
65
+ * @return Transaction block response or transaction block
66
+ */
67
+ depositCollateral(coinName: SupportCollateralCoins, amount: number): Promise<SuiTransactionBlockResponse>;
68
+ depositCollateral<S extends boolean>(coinName: SupportCollateralCoins, amount: number, sign?: S, obligationId?: SuiTxArg, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
69
+ /**
70
+ * Withdraw collateral from the specific pool.
71
+ *
72
+ * @param coinName - Types of collateral coin.
73
+ * @param amount - The amount of coins would deposit.
74
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
75
+ * @param obligationId - The obligation object.
76
+ * @param obligationKey - The obligation key object to verifying obligation authority.
77
+ * @param walletAddress - The wallet address of the owner.
78
+ * @return Transaction block response or transaction block
79
+ */
80
+ withdrawCollateral<S extends boolean>(coinName: SupportCollateralCoins, amount: number, sign: S | undefined, obligationId: string, obligationKey: string, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
81
+ /**
82
+ * Deposit asset into the specific pool.
83
+ *
84
+ * @param coinName - Types of asset coin.
85
+ * @param amount - The amount of coins would deposit.
86
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
87
+ * @param walletAddress - The wallet address of the owner.
88
+ * @return Transaction block response or transaction block
89
+ */
90
+ deposit(coinName: SupportAssetCoins, amount: number): Promise<SuiTransactionBlockResponse>;
91
+ deposit<S extends boolean>(coinName: SupportAssetCoins, amount: number, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
92
+ /**
93
+ * Withdraw asset from the specific pool, must return market coin.
94
+ *
95
+ * @param coinName - Types of asset coin.
96
+ * @param amount - The amount of coins would withdraw.
97
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
98
+ * @param walletAddress - The wallet address of the owner.
99
+ * @return Transaction block response or transaction block
100
+ */
101
+ withdraw(coinName: SupportAssetCoins, amount: number): Promise<SuiTransactionBlockResponse>;
102
+ withdraw<S extends boolean>(coinName: SupportAssetCoins, amount: number, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
103
+ /**
104
+ * borrow asset from the specific pool.
105
+ *
106
+ * @param coinName - Types of asset coin.
107
+ * @param amount - The amount of coins would borrow.
108
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
109
+ * @param obligationId - The obligation object.
110
+ * @param obligationKey - The obligation key object to verifying obligation authority.
111
+ * @param walletAddress - The wallet address of the owner.
112
+ * @return Transaction block response or transaction block
113
+ */
114
+ borrow<S extends boolean>(coinName: SupportAssetCoins, amount: number, sign: S | undefined, obligationId: string, obligationKey: string, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
115
+ /**
116
+ * Repay asset into the specific pool.
117
+ *
118
+ * @param coinName - Types of asset coin.
119
+ * @param amount - The amount of coins would repay.
120
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
121
+ * @param obligationId - The obligation object.
122
+ * @param walletAddress - The wallet address of the owner.
123
+ * @return Transaction block response or transaction block
124
+ */
125
+ repay<S extends boolean>(coinName: SupportAssetCoins, amount: number, sign: S | undefined, obligationId: string, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
126
+ /**
127
+ * FlashLoan asset from the specific pool.
128
+ *
129
+ * @param coinName - Types of asset coin.
130
+ * @param amount - The amount of coins would repay.
131
+ * @param callback - The callback function to build transaction block and return coin argument.
132
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
133
+ * @return Transaction block response or transaction block
134
+ */
135
+ flashLoan(coinName: SupportAssetCoins, amount: number, callback: (txBlock: ScallopTxBlock, coin: TransactionArgument) => TransactionArgument): Promise<SuiTransactionBlockResponse>;
136
+ flashLoan<S extends boolean>(coinName: SupportAssetCoins, amount: number, callback: (txBlock: ScallopTxBlock, coin: TransactionArgument) => TransactionArgument, sign?: S): Promise<ScallopClientFnReturnType<S>>;
137
+ /**
138
+ * Mint and get test coin.
139
+ *
140
+ * @remarks
141
+ * Only be used on the test network.
142
+ *
143
+ * @param coinName - Types of coins supported on the test network.
144
+ * @param amount - The amount of coins minted and received.
145
+ * @param receiveAddress - The wallet address that receives the coins.
146
+ * @param sign - Decide to directly sign the transaction or return the transaction block.
147
+ * @return Transaction block response or transaction block
148
+ */
149
+ mintTestCoin(coinName: Exclude<SupportCoins, 'sui'>, amount: number): Promise<SuiTransactionBlockResponse>;
150
+ mintTestCoin<S extends boolean>(coinName: Exclude<SupportCoins, 'sui'>, amount: number, sign?: S, receiveAddress?: string): Promise<ScallopClientFnReturnType<S>>;
151
+ }
@@ -0,0 +1,56 @@
1
+ import type { ScallopParams, SupportCoins } from '../types';
2
+ /**
3
+ * ### Scallop Utils
4
+ *
5
+ * Integrates some helper functions frequently used in interactions with the Scallop contract.
6
+ *
7
+ * #### Usage
8
+ *
9
+ * ```typescript
10
+ * const utils = new ScallopUtils(<parameters>);
11
+ * utils.<help functions>();
12
+ * ```
13
+ */
14
+ export declare class ScallopUtils {
15
+ private _suiKit;
16
+ constructor(params: ScallopParams);
17
+ /**
18
+ * @description Select coin id that add up to the given amount as transaction arguments.
19
+ * @param owner The address of the owner.
20
+ * @param amount The amount that is needed for the coin.
21
+ * @param coinType The coin type, default is 0x2::SUI::SUI.
22
+ * @return The selected transaction coin arguments.
23
+ */
24
+ selectCoins(owner: string, amount: number, coinType?: string): Promise<string[]>;
25
+ /**
26
+ * @description Fetch price feed VAAs of interest from the Pyth.
27
+ * @param priceIds Array of hex-encoded price ids.
28
+ * @param isTestnet Specify whether it is a test network.
29
+ * @return Array of base64 encoded VAAs.
30
+ */
31
+ getVaas(priceIds: string[], isTestnet?: boolean): Promise<string[]>;
32
+ /**
33
+ * @description Handle non-standard coins.
34
+ * @param coinPackageId Package id of coin.
35
+ * @param coinName specific support coin name.
36
+ * @return coinType.
37
+ */
38
+ parseCoinType(coinPackageId: string, coinName: string): string;
39
+ /**
40
+ * @description Handle non-standard coin names.
41
+ * @param coinPackageId Package id of coin.
42
+ * @param coinName specific support coin name.
43
+ * @return coinType.
44
+ */
45
+ getCoinNameFromCoinType(coinType: string): SupportCoins;
46
+ /**
47
+ * @description Handle market coin types.
48
+ *
49
+ * @param coinPackageId Package id of coin.
50
+ * @param protocolPkgId Package id of protocol.
51
+ * @param coinName specific support coin name.
52
+ *
53
+ * @return marketCoinType.
54
+ */
55
+ parseMarketCoinType(coinPackageId: string, protocolPkgId: string, coinName: string): string;
56
+ }
@@ -0,0 +1,2 @@
1
+ export { queryMarket } from './market';
2
+ export { queryObligation, getObligations } from './obligation';
@@ -0,0 +1,4 @@
1
+ import { SuiKit } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress } from '../models';
3
+ import { MarketInterface } from '../types';
4
+ export declare const queryMarket: (scallopAddress: ScallopAddress, suiKit: SuiKit) => Promise<MarketInterface>;
@@ -0,0 +1,8 @@
1
+ import { SuiKit } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress } from '../models';
3
+ import { ObligationInterface } from '../types';
4
+ export declare const queryObligation: (obligationId: string, scallopAddress: ScallopAddress, suiKit: SuiKit) => Promise<ObligationInterface>;
5
+ export declare const getObligations: (ownerAddress: string, scallopAddress: ScallopAddress, suiKit: SuiKit) => Promise<{
6
+ id: string;
7
+ keyId: string;
8
+ }[]>;