@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,67 @@
1
+ import { SuiTxBlock } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress, ScallopUtils } from '../models';
3
+ import { SupportCoins } from '../types';
4
+ export declare const selectCoin: (txBlock: SuiTxBlock, scallopAddress: ScallopAddress, scallopUtils: ScallopUtils, coinName: SupportCoins, amount: number, sender: string) => Promise<{
5
+ takeCoin: {
6
+ kind: "Input";
7
+ index: number;
8
+ type?: "object" | "pure" | undefined;
9
+ value?: any;
10
+ } | {
11
+ kind: "GasCoin";
12
+ } | {
13
+ kind: "Result";
14
+ index: number;
15
+ } | {
16
+ kind: "NestedResult";
17
+ index: number;
18
+ resultIndex: number;
19
+ };
20
+ leftCoin: {
21
+ kind: "Input";
22
+ index: number;
23
+ type?: "object" | "pure" | undefined;
24
+ value?: any;
25
+ } | {
26
+ kind: "GasCoin";
27
+ } | {
28
+ kind: "Result";
29
+ index: number;
30
+ } | {
31
+ kind: "NestedResult";
32
+ index: number;
33
+ resultIndex: number;
34
+ };
35
+ }>;
36
+ export declare const selectMarketCoin: (txBlock: SuiTxBlock, scallopAddress: ScallopAddress, scallopUtils: ScallopUtils, coinName: SupportCoins, amount: number, sender: string) => Promise<{
37
+ takeCoin: {
38
+ kind: "Input";
39
+ index: number;
40
+ type?: "object" | "pure" | undefined;
41
+ value?: any;
42
+ } | {
43
+ kind: "GasCoin";
44
+ } | {
45
+ kind: "Result";
46
+ index: number;
47
+ } | {
48
+ kind: "NestedResult";
49
+ index: number;
50
+ resultIndex: number;
51
+ };
52
+ leftCoin: {
53
+ kind: "Input";
54
+ index: number;
55
+ type?: "object" | "pure" | undefined;
56
+ value?: any;
57
+ } | {
58
+ kind: "GasCoin";
59
+ } | {
60
+ kind: "Result";
61
+ index: number;
62
+ } | {
63
+ kind: "NestedResult";
64
+ index: number;
65
+ resultIndex: number;
66
+ };
67
+ }>;
@@ -0,0 +1 @@
1
+ export { newScallopTxBlock } from './quickMethods';
@@ -0,0 +1,3 @@
1
+ import { ScallopAddress, ScallopUtils } from '../models';
2
+ import type { SuiTxBlockWithNormalScallopMethods } from '../types';
3
+ export declare const newTxBlock: (scallopAddress: ScallopAddress, scallopUtils: ScallopUtils) => SuiTxBlockWithNormalScallopMethods;
@@ -0,0 +1,7 @@
1
+ import { SuiTxBlock, SuiKit } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress, ScallopUtils } from '../models';
3
+ import { SupportCoins, SupportAssetCoins } from '../types';
4
+ export declare const updateOraclesForWithdrawCollateral: (txBlock: SuiTxBlock, address: ScallopAddress, scallopUtils: ScallopUtils, suiKit: SuiKit, obligationId: string, isTestnet: boolean) => Promise<void>;
5
+ export declare const updateOraclesForLiquidation: (txBlock: SuiTxBlock, address: ScallopAddress, scallopUtils: ScallopUtils, suiKit: SuiKit, obligationId: string, isTestnet: boolean) => Promise<void>;
6
+ export declare const updateOraclesForBorrow: (txBlock: SuiTxBlock, address: ScallopAddress, scallopUtils: ScallopUtils, suiKit: SuiKit, obligationId: string, borrowCoinName: SupportAssetCoins, isTestnet: boolean) => Promise<void>;
7
+ export declare const updateOracles: (txBlock: SuiTxBlock, address: ScallopAddress, scallopUtils: ScallopUtils, coinNames: SupportCoins[], isTestnet: boolean) => Promise<void>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This file contains the complex transaction builder, which contains multiple calls in a single transaction.
3
+ */
4
+ import { SuiKit } from '@scallop-io/sui-kit';
5
+ import { ScallopAddress, ScallopUtils } from '../models';
6
+ import type { ScallopTxBlock } from '../types';
7
+ export declare const newScallopTxBlock: (suiKit: SuiKit, scallopAddress: ScallopAddress, scallopUtils: ScallopUtils, isTestnet: boolean) => ScallopTxBlock;
@@ -0,0 +1,127 @@
1
+ import { SUPPORT_ASSET_COINS, SUPPORT_COLLATERAL_COINS, SUPPORT_ORACLES, SUPPORT_PACKAGES } from '../constants/common';
2
+ export type SupportAssetCoins = (typeof SUPPORT_ASSET_COINS)[number];
3
+ export type SupportCollateralCoins = (typeof SUPPORT_COLLATERAL_COINS)[number];
4
+ export type SupportCoins = SupportAssetCoins | SupportCollateralCoins;
5
+ export type SupportOracleType = (typeof SUPPORT_ORACLES)[number];
6
+ export type SupportPackageType = (typeof SUPPORT_PACKAGES)[number];
7
+ export interface MarketInterface {
8
+ collaterals: {
9
+ collateralFactor: {
10
+ value: string;
11
+ };
12
+ liquidationDiscount: {
13
+ value: string;
14
+ };
15
+ liquidationFactor: {
16
+ value: string;
17
+ };
18
+ liquidationPanelty: {
19
+ value: string;
20
+ };
21
+ liquidationReserveFactor: {
22
+ value: string;
23
+ };
24
+ maxCollateralAmount: string;
25
+ totalCollateralAmount: string;
26
+ type: {
27
+ name: string;
28
+ };
29
+ }[];
30
+ pools: {
31
+ baseBorrowRatePerSec: {
32
+ value: string;
33
+ };
34
+ borrowIndex: string;
35
+ cash: string;
36
+ debt: string;
37
+ highSlope: {
38
+ value: string;
39
+ };
40
+ interestRate: {
41
+ value: string;
42
+ };
43
+ kink: {
44
+ value: string;
45
+ };
46
+ lastUpdated: string;
47
+ lowSlope: {
48
+ value: string;
49
+ };
50
+ marketCoinSupply: string;
51
+ minBorrowAmount: string;
52
+ reserve: string;
53
+ reserveFactor: {
54
+ value: string;
55
+ };
56
+ borrowWeight: {
57
+ value: string;
58
+ };
59
+ type: {
60
+ name: string;
61
+ };
62
+ }[];
63
+ }
64
+ export interface ObligationInterface {
65
+ collaterals: {
66
+ type: {
67
+ name: string;
68
+ };
69
+ amount: string;
70
+ }[];
71
+ debts: {
72
+ type: {
73
+ name: string;
74
+ };
75
+ amount: string;
76
+ borrowIndex: string;
77
+ }[];
78
+ }
79
+ export interface AddressesInterface {
80
+ core: {
81
+ version: string;
82
+ versionCap: string;
83
+ market: string;
84
+ adminCap: string;
85
+ coinDecimalsRegistry: string;
86
+ coins: Partial<Record<SupportCoins, {
87
+ id: string;
88
+ treasury: string;
89
+ metaData: string;
90
+ oracle: {
91
+ [K in SupportOracleType]: K extends (typeof SUPPORT_ORACLES)[0] ? string : K extends (typeof SUPPORT_ORACLES)[1] ? string : K extends (typeof SUPPORT_ORACLES)[2] ? {
92
+ feed: string;
93
+ feedObject: string;
94
+ } : never;
95
+ };
96
+ }>>;
97
+ oracles: {
98
+ [K in SupportOracleType]: K extends (typeof SUPPORT_ORACLES)[0] ? {
99
+ registry: string;
100
+ registryCap: string;
101
+ holder: string;
102
+ } : K extends (typeof SUPPORT_ORACLES)[1] ? {
103
+ registry: string;
104
+ registryCap: string;
105
+ } : K extends (typeof SUPPORT_ORACLES)[2] ? {
106
+ registry: string;
107
+ registryCap: string;
108
+ state: string;
109
+ wormhole: string;
110
+ wormholeState: string;
111
+ } : never;
112
+ } & {
113
+ xOracle: string;
114
+ xOracleCap: string;
115
+ };
116
+ packages: Partial<Record<SupportPackageType, {
117
+ id: string;
118
+ upgradeCap: string;
119
+ }>>;
120
+ };
121
+ }
122
+ type AddressPathsProps<T> = T extends string ? [] : {
123
+ [K in Extract<keyof T, string>]: [K, ...AddressPathsProps<T[K]>];
124
+ }[Extract<keyof T, string>];
125
+ type Join<T extends string[], D extends string> = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? `${F}${D}${Join<Extract<R, string[]>, D>}` : never : string;
126
+ export type AddressStringPath = Join<AddressPathsProps<AddressesInterface>, '.'>;
127
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './data';
2
+ export * from './model';
3
+ export * from './txBuilder';
@@ -0,0 +1,9 @@
1
+ import type { SuiTransactionBlockResponse, TransactionBlock } from '@mysten/sui.js';
2
+ import type { SuiKitParams, NetworkType } from '@scallop-io/sui-kit';
3
+ export type ScallopClientFnReturnType<T extends boolean> = T extends true ? SuiTransactionBlockResponse : TransactionBlock;
4
+ export type ScallopParams = {} & SuiKitParams;
5
+ export type ScallopAddressParams = {
6
+ id: string;
7
+ auth?: string;
8
+ network?: NetworkType;
9
+ };
@@ -0,0 +1,66 @@
1
+ import type { TransactionArgument } from '@mysten/sui.js';
2
+ import type { SuiTxBlock, SuiTxArg, SuiKit } from '@scallop-io/sui-kit';
3
+ import type { ScallopAddress, ScallopUtils } from '../models';
4
+ import type { SupportCollateralCoins, SupportAssetCoins } from './data';
5
+ type TransactionResult = TransactionArgument & TransactionArgument[];
6
+ /**
7
+ * ========== Scallop Normal Methods ==========
8
+ */
9
+ export type ScallopNormalMethods = {
10
+ openObligation: () => TransactionResult;
11
+ returnObligation: (obligation: SuiTxArg, obligationHotPotato: SuiTxArg) => void;
12
+ openObligationEntry: () => void;
13
+ addCollateral: (obligation: SuiTxArg, coin: SuiTxArg, coinName: SupportCollateralCoins) => void;
14
+ takeCollateral: (obligation: SuiTxArg, obligationKey: SuiTxArg, amount: number, coinName: SupportCollateralCoins) => TransactionResult;
15
+ deposit: (coin: SuiTxArg, coinName: SupportAssetCoins) => TransactionResult;
16
+ depositEntry: (coin: SuiTxArg, coinName: SupportAssetCoins) => void;
17
+ withdraw: (marketCoin: SuiTxArg, coinName: SupportAssetCoins) => TransactionResult;
18
+ withdrawEntry: (marketCoin: SuiTxArg, coinName: SupportAssetCoins) => void;
19
+ borrow: (obligation: SuiTxArg, obligationKey: SuiTxArg, amount: number, coinName: SupportAssetCoins) => TransactionResult;
20
+ borrowEntry: (obligation: SuiTxArg, obligationKey: SuiTxArg, amount: number, coinName: SupportAssetCoins) => void;
21
+ repay: (obligation: SuiTxArg, coin: SuiTxArg, coinName: SupportAssetCoins) => void;
22
+ borrowFlashLoan: (amount: number, coinName: SupportAssetCoins) => TransactionResult;
23
+ repayFlashLoan: (coin: SuiTxArg, loan: SuiTxArg, coinName: SupportAssetCoins) => void;
24
+ };
25
+ export type CoreIds = {
26
+ protocolPkg: string;
27
+ market: string;
28
+ version: string;
29
+ dmlR: string;
30
+ oracle: string;
31
+ };
32
+ export type ScallopNormalMethodsHandler = {
33
+ [key in keyof ScallopNormalMethods]: (params: {
34
+ txBlock: SuiTxBlock;
35
+ coreIds: CoreIds;
36
+ scallopAddress: ScallopAddress;
37
+ scallopUtils: ScallopUtils;
38
+ }) => ScallopNormalMethods[key];
39
+ };
40
+ export type SuiTxBlockWithNormalScallopMethods = SuiTxBlock & ScallopNormalMethods;
41
+ /**
42
+ * ========== Scallop Quick Methods ==========
43
+ */
44
+ export type ScallopQuickMethods = {
45
+ addCollateralQuick: (amount: number, coinName: SupportCollateralCoins, obligationId?: SuiTxArg) => Promise<void>;
46
+ takeCollateralQuick: (amount: number, coinName: SupportCollateralCoins, obligationId?: string, obligationKey?: string) => Promise<TransactionResult>;
47
+ borrowQuick: (amount: number, coinName: SupportAssetCoins, obligationId?: string, obligationKey?: string) => Promise<TransactionResult>;
48
+ depositQuick: (amount: number, coinName: SupportAssetCoins) => Promise<TransactionResult>;
49
+ withdrawQuick: (amount: number, coinName: SupportAssetCoins) => Promise<TransactionResult>;
50
+ repayQuick: (amount: number, coinName: SupportAssetCoins, obligationId?: string) => Promise<void>;
51
+ updateAssetPricesQuick: (coinNames: SupportAssetCoins[]) => Promise<void>;
52
+ };
53
+ export type ScallopQuickMethodsHandler = {
54
+ [key in keyof ScallopQuickMethods]: (params: {
55
+ txBlock: SuiTxBlockWithNormalScallopMethods;
56
+ suiKit: SuiKit;
57
+ scallopAddress: ScallopAddress;
58
+ scallopUtils: ScallopUtils;
59
+ isTestnet: boolean;
60
+ }) => ScallopQuickMethods[key];
61
+ };
62
+ /**
63
+ * ========== Scallop Tx Block ==========
64
+ */
65
+ export type ScallopTxBlock = SuiTxBlockWithNormalScallopMethods & ScallopQuickMethods;
66
+ export {};
package/package.json ADDED
@@ -0,0 +1,147 @@
1
+ {
2
+ "name": "@scallop-io/sui-scallop-sdk",
3
+ "version": "0.37.3",
4
+ "description": "Tookit for interacting with Scallop on SUI",
5
+ "keywords": [
6
+ "sui",
7
+ "scallop labs",
8
+ "move",
9
+ "blockchain"
10
+ ],
11
+ "author": "team@scallop.io",
12
+ "homepage": "https://github.com/scallop-io/sui-scallop-sdk#readme",
13
+ "bugs": "https://github.com/scallop-io/sui-scallop-sdk/issues",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/scallop-io/sui-scallop-sdk.git"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "source": "./src/index.ts",
31
+ "import": "./dist/index.mjs",
32
+ "require": "./dist/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "src"
38
+ ],
39
+ "dependencies": {
40
+ "@mysten/bcs": "^0.7.3",
41
+ "@mysten/sui.js": "^0.37.1",
42
+ "@pythnetwork/price-service-client": "^1.6.0",
43
+ "@scallop-io/sui-kit": "^0.37.1",
44
+ "axios": "^1.4.0"
45
+ },
46
+ "devDependencies": {
47
+ "@commitlint/cli": "^17.6.6",
48
+ "@commitlint/config-conventional": "^17.6.6",
49
+ "@commitlint/prompt-cli": "^17.6.6",
50
+ "@types/node": "^20.3.2",
51
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
52
+ "@typescript-eslint/parser": "^5.60.1",
53
+ "dotenv": "^16.3.1",
54
+ "eslint": "^8.43.0",
55
+ "eslint-config-prettier": "^8.8.0",
56
+ "eslint-plugin-prettier": "^4.2.1",
57
+ "husky": "^8.0.3",
58
+ "lint-staged": "^13.2.3",
59
+ "prettier": "^2.8.8",
60
+ "tsconfig-paths": "^4.2.0",
61
+ "tsup": "^7.1.0",
62
+ "typedoc": "^0.24.8",
63
+ "typescript": "^5.0.4",
64
+ "vitest": "^0.32.2"
65
+ },
66
+ "peerDependencies": {
67
+ "@mysten/sui.js": "^0.37.1"
68
+ },
69
+ "lint-staged": {
70
+ "**/*.ts": [
71
+ "pnpm run format:fix",
72
+ "pnpm run lint:fix"
73
+ ],
74
+ "**/*.json|md": [
75
+ "pnpm run format:fix"
76
+ ]
77
+ },
78
+ "husky": {
79
+ "hooks": {
80
+ "pre-commit": "lint-staged"
81
+ }
82
+ },
83
+ "commitlint": {
84
+ "extends": [
85
+ "@commitlint/config-conventional"
86
+ ]
87
+ },
88
+ "prettier": {
89
+ "trailingComma": "es5",
90
+ "tabWidth": 2,
91
+ "semi": true,
92
+ "singleQuote": true,
93
+ "useTabs": false,
94
+ "quoteProps": "as-needed",
95
+ "bracketSpacing": true,
96
+ "arrowParens": "always",
97
+ "endOfLine": "lf"
98
+ },
99
+ "eslintConfig": {
100
+ "root": true,
101
+ "env": {
102
+ "browser": true,
103
+ "node": true,
104
+ "es2022": true
105
+ },
106
+ "extends": [
107
+ "eslint:recommended",
108
+ "plugin:@typescript-eslint/eslint-recommended",
109
+ "plugin:prettier/recommended"
110
+ ],
111
+ "plugins": [
112
+ "@typescript-eslint",
113
+ "prettier"
114
+ ],
115
+ "parser": "@typescript-eslint/parser",
116
+ "rules": {
117
+ "prettier/prettier": "warn",
118
+ "@typescript-eslint/no-explicit-any": "off",
119
+ "no-unused-vars": "off",
120
+ "@typescript-eslint/no-unused-vars": [
121
+ "error",
122
+ {
123
+ "argsIgnorePattern": "^_",
124
+ "varsIgnorePattern": "^_",
125
+ "caughtErrorsIgnorePattern": "^_"
126
+ }
127
+ ]
128
+ }
129
+ },
130
+ "scripts": {
131
+ "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
132
+ "build": "pnpm run build:types && pnpm run build:tsup",
133
+ "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap",
134
+ "build:types": "tsc --build",
135
+ "watch:tsup": "tsup ./src/index.ts --format esm,cjs --clean --splitting --watch",
136
+ "watch:types": "tsc --watch",
137
+ "watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
138
+ "test": "pnpm test:typecheck && pnpm test:unit",
139
+ "test:typecheck": "tsc -p ./test",
140
+ "test:unit": "vitest run --test-timeout=60000",
141
+ "test:watch": "vitest",
142
+ "format:fix": "prettier --ignore-path 'dist/* docs/*' --write '**/*.{ts,json,md}'",
143
+ "lint:fix": "eslint . --ignore-pattern dist --ext .ts --fix",
144
+ "commit": "commit",
145
+ "doc": "typedoc --out docs src/index.ts"
146
+ }
147
+ }
@@ -0,0 +1,36 @@
1
+ export const API_BASE_URL = 'https://sui.api.scallop.io';
2
+
3
+ export const ADDRESSES_ID = '6462a088a7ace142bb6d7e9b';
4
+
5
+ export const SUPPORT_ASSET_COINS = [
6
+ 'eth',
7
+ 'btc',
8
+ 'usdc',
9
+ 'usdt',
10
+ 'sui',
11
+ ] as const;
12
+ export const SUPPORT_COLLATERAL_COINS = [
13
+ 'eth',
14
+ 'btc',
15
+ 'usdc',
16
+ 'usdt',
17
+ 'sui',
18
+ ] as const;
19
+
20
+ export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
21
+
22
+ export const SUPPORT_PACKAGES = [
23
+ 'coinDecimalsRegistry',
24
+ 'math',
25
+ 'whitelist',
26
+ 'x',
27
+ 'protocol',
28
+ 'query',
29
+ 'supra',
30
+ 'pyth',
31
+ 'switchboard',
32
+ 'xOracle',
33
+ 'testCoin',
34
+ ] as const;
35
+
36
+ export const SUI_COIN_TYPE_ARG_REGEX = /^0x(0*)2::sui::SUI$/;
@@ -0,0 +1 @@
1
+ export * from './common';
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './constants';
2
+ export * from './models';
3
+ export * from './types';
@@ -0,0 +1,4 @@
1
+ export * from './scallop';
2
+ export * from './scallopClient';
3
+ export * from './scallopUtils';
4
+ export * from './scallopAddress';
@@ -0,0 +1,76 @@
1
+ import { SuiKit } from '@scallop-io/sui-kit';
2
+ import { ScallopAddress } from './scallopAddress';
3
+ import { ScallopClient } from './scallopClient';
4
+ import { ScallopUtils } from './scallopUtils';
5
+ import { newScallopTxBlock } from '../txBuilders';
6
+ import { ADDRESSES_ID } from '../constants';
7
+ import type { NetworkType } from '@scallop-io/sui-kit';
8
+ import type { ScallopParams, ScallopTxBlock } from '../types';
9
+
10
+ /**
11
+ * ### Scallop
12
+ *
13
+ * The main instance that controls interaction with the Scallop contract.
14
+ *
15
+ * #### Usage
16
+ *
17
+ * ```typescript
18
+ * const sdk = new Scallop(<parameters>);
19
+ * ```
20
+ */
21
+ export class Scallop {
22
+ public params: ScallopParams;
23
+ public suiKit: SuiKit;
24
+ public address: ScallopAddress;
25
+
26
+ public constructor(params: ScallopParams) {
27
+ this.params = params;
28
+ this.suiKit = new SuiKit(params);
29
+ this.address = new ScallopAddress({
30
+ id: ADDRESSES_ID,
31
+ network: params?.networkType,
32
+ });
33
+ }
34
+
35
+ /**
36
+ * Create an instance to operate the transaction block, making it more convenient to organize transaction combinations.
37
+ * @return Scallop Transaction Builder
38
+ */
39
+ public async createTxBuilder() {
40
+ await this.address.read();
41
+ const scallopUtils = new ScallopUtils(this.params);
42
+ const suiKit = new SuiKit(this.params);
43
+ const isTestnet = this.params.networkType === 'testnet';
44
+ return {
45
+ createTxBlock: () => {
46
+ return newScallopTxBlock(suiKit, this.address, scallopUtils, isTestnet);
47
+ },
48
+ signAndSendTxBlock: (txBlock: ScallopTxBlock) => {
49
+ return suiKit.signAndSendTxn(txBlock);
50
+ },
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Create an instance to collect the addresses, making it easier to get object addresses from lending contract.
56
+ *
57
+ * @param id - The API id of the addresses.
58
+ * @param auth - The authentication API key.
59
+ * @param network - Specifies which network's addresses you want to set.
60
+ * @return Scallop Address
61
+ */
62
+ public createAddress(id: string, auth: string, network: NetworkType) {
63
+ return new ScallopAddress({ id, auth, network });
64
+ }
65
+
66
+ /**
67
+ * Create an instance that provides contract interaction operations for general users.
68
+ *
69
+ * @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.
70
+ * @return Scallop Client
71
+ */
72
+ public async createScallopClient(walletAddress?: string) {
73
+ await this.address.read();
74
+ return new ScallopClient(this.params, this.address, walletAddress);
75
+ }
76
+ }