four-flap-meme-sdk 1.9.28 → 1.9.31
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.
- package/dist/chains/bsc/index.d.ts +1 -1
- package/dist/chains/bsc/index.js +1 -1
- package/dist/chains/bsc/platforms/iro/api.d.ts +12 -4
- package/dist/chains/bsc/platforms/iro/api.js +25 -9
- package/dist/chains/bsc/platforms/iro/factory.js +5 -4
- package/dist/chains/bsc/platforms/iro/index.d.ts +1 -1
- package/dist/chains/bsc/platforms/iro/index.js +1 -1
- package/dist/chains/bsc/platforms/iro/pool.d.ts +2 -1
- package/dist/chains/bsc/platforms/iro/pool.js +13 -13
- package/dist/chains/bsc/platforms/iro/token.d.ts +4 -1
- package/dist/chains/bsc/platforms/iro/token.js +15 -13
- package/dist/chains/bsc/platforms/iro/types.d.ts +8 -0
- package/dist/chains/eni/constants.d.ts +9 -0
- package/dist/chains/eni/constants.js +4 -0
- package/dist/chains/eni/index.d.ts +2 -0
- package/dist/chains/eni/index.js +4 -0
- package/dist/chains/eni/platforms/index.d.ts +1 -0
- package/dist/chains/eni/platforms/index.js +2 -0
- package/dist/chains/eni/platforms/iro/api.d.ts +37 -0
- package/dist/chains/eni/platforms/iro/api.js +64 -0
- package/dist/chains/eni/platforms/iro/constants.d.ts +24 -0
- package/dist/chains/eni/platforms/iro/constants.js +87 -0
- package/dist/chains/eni/platforms/iro/factory.d.ts +36 -0
- package/dist/chains/eni/platforms/iro/factory.js +116 -0
- package/dist/chains/eni/platforms/iro/index.d.ts +16 -0
- package/dist/chains/eni/platforms/iro/index.js +28 -0
- package/dist/chains/eni/platforms/iro/pool.d.ts +43 -0
- package/dist/chains/eni/platforms/iro/pool.js +94 -0
- package/dist/chains/eni/platforms/iro/token.d.ts +69 -0
- package/dist/chains/eni/platforms/iro/token.js +163 -0
- package/dist/chains/eni/platforms/iro/types.d.ts +113 -0
- package/dist/chains/eni/platforms/iro/types.js +6 -0
- package/dist/dex/direct-router.d.ts +10 -5
- package/dist/dex/direct-router.js +14 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/shared/constants/addresses.d.ts +15 -1
- package/dist/shared/constants/addresses.js +21 -3
- package/dist/shared/constants/profit.js +7 -6
- package/dist/utils/lp-inspect.d.ts +1 -1
- package/dist/utils/lp-inspect.js +22 -1
- package/package.json +1 -1
|
@@ -7,4 +7,4 @@ export * from './constants.js';
|
|
|
7
7
|
export * as platforms from './platforms/index.js';
|
|
8
8
|
export { disperseWithBundleMerkle, sweepWithBundleMerkle, pairwiseTransferWithBundleMerkle, fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle, fourBundleBuyFirstMerkle, submitBundleToMerkle, submitBundleToBlockRazor, submitDirectToRpc, submitDirectToRpcSmart, approveFourTokenManagerBatch, } from './platforms/four/index.js';
|
|
9
9
|
export { pancakeBundleSwapMerkle, pancakeBatchSwapMerkle, pancakeQuickBatchSwapMerkle, pancakeCrossSwapMerkle, pancakeBundleBuyFirstMerkle, } from './platforms/pancake/index.js';
|
|
10
|
-
export { IroFactoryQuery, createProject as iroCreateProject, encodeCreateProjectCall as iroEncodeCreateProjectCall, parseCreateProjectEvent as iroParseCreateProjectEvent, IroTokenQuery, subscribe as iroSubscribe, pledge as iroPledge, batchSubscribe as iroBatchSubscribe, batchSubscribeForSubmit as iroBatchSubscribeForSubmit, IroPoolQuery, poolRemovePledge as iroPoolRemovePledge, poolExtract as iroPoolExtract, poolTransferAwards as iroPoolTransferAwards, batchExtract as iroBatchExtract, IRO_FACTORY_ADDRESS, IRO_FACTORY_ABI, IRO_TOKEN_ABI, IRO_POOL_ABI, IRO_PLATFORM_URL, setIroApiBase, iroApiCreateProject, iroApiUploadImage, } from './platforms/iro/index.js';
|
|
10
|
+
export { IroFactoryQuery, createProject as iroCreateProject, encodeCreateProjectCall as iroEncodeCreateProjectCall, parseCreateProjectEvent as iroParseCreateProjectEvent, IroTokenQuery, subscribe as iroSubscribe, pledge as iroPledge, batchSubscribe as iroBatchSubscribe, batchSubscribeForSubmit as iroBatchSubscribeForSubmit, IroPoolQuery, poolRemovePledge as iroPoolRemovePledge, poolExtract as iroPoolExtract, poolTransferAwards as iroPoolTransferAwards, batchExtract as iroBatchExtract, IRO_FACTORY_ADDRESS, IRO_FACTORY_ABI, IRO_TOKEN_ABI, IRO_POOL_ABI, IRO_PLATFORM_URL, IRO_TESTNET_PLATFORM_URL, setIroApiBase, setIroTestApiBase, iroApiCreateProject, iroApiUploadImage, } from './platforms/iro/index.js';
|
package/dist/chains/bsc/index.js
CHANGED
|
@@ -38,4 +38,4 @@ IroPoolQuery, poolRemovePledge as iroPoolRemovePledge, poolExtract as iroPoolExt
|
|
|
38
38
|
// 常量
|
|
39
39
|
IRO_FACTORY_ADDRESS, IRO_FACTORY_ABI, IRO_TOKEN_ABI, IRO_POOL_ABI,
|
|
40
40
|
// API (IRO 平台后端)
|
|
41
|
-
IRO_PLATFORM_URL, setIroApiBase, iroApiCreateProject, iroApiUploadImage, } from './platforms/iro/index.js';
|
|
41
|
+
IRO_PLATFORM_URL, IRO_TESTNET_PLATFORM_URL, setIroApiBase, setIroTestApiBase, iroApiCreateProject, iroApiUploadImage, } from './platforms/iro/index.js';
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* IRO 平台后端 API
|
|
3
3
|
*
|
|
4
|
-
* Base URL: https://dapp-iro.ironetwork.com
|
|
4
|
+
* 主网 Base URL: https://dapp-iro.ironetwork.com
|
|
5
|
+
* 测试网 Base URL: https://test-api.ironetwork.com
|
|
5
6
|
* 无需 X-Signature 校验
|
|
6
7
|
*/
|
|
7
8
|
export declare const IRO_PLATFORM_URL = "https://dapp-iro.ironetwork.com";
|
|
9
|
+
export declare const IRO_TESTNET_PLATFORM_URL = "https://test-api.ironetwork.com";
|
|
8
10
|
/**
|
|
9
|
-
* 设置 IRO API 的 base URL
|
|
11
|
+
* 设置 IRO 主网 API 的 base URL
|
|
10
12
|
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/iro-api'
|
|
11
13
|
*/
|
|
12
14
|
export declare function setIroApiBase(base: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* 设置 IRO 测试网 API 的 base URL
|
|
17
|
+
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/iro-test-api'
|
|
18
|
+
*/
|
|
19
|
+
export declare function setIroTestApiBase(base: string): void;
|
|
13
20
|
export interface IroApiCreateProjectRequest {
|
|
14
21
|
/** 代币 LOGO 图片 URL (先通过上传接口获取) */
|
|
15
22
|
logo: string;
|
|
@@ -47,12 +54,13 @@ export interface IroApiUploadImageResponse {
|
|
|
47
54
|
* POST /api/community/create/open
|
|
48
55
|
* @returns projectID 字符串 (如 "20241009014234831377")
|
|
49
56
|
*/
|
|
50
|
-
export declare function iroApiCreateProject(params: IroApiCreateProjectRequest): Promise<string>;
|
|
57
|
+
export declare function iroApiCreateProject(params: IroApiCreateProjectRequest, testnet?: boolean): Promise<string>;
|
|
51
58
|
/**
|
|
52
59
|
* 上传图片 — 获取 LOGO URL
|
|
53
60
|
*
|
|
54
61
|
* POST /api/upload/image
|
|
55
62
|
* 参数: img (file binary, 必填)
|
|
63
|
+
* 允许扩展名: .png .jpg .jpeg .gif
|
|
56
64
|
* @returns 图片 URL (data.path)
|
|
57
65
|
*/
|
|
58
|
-
export declare function iroApiUploadImage(file: File | Blob, filename?: string): Promise<string>;
|
|
66
|
+
export declare function iroApiUploadImage(file: File | Blob, filename?: string, testnet?: boolean): Promise<string>;
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* IRO 平台后端 API
|
|
3
3
|
*
|
|
4
|
-
* Base URL: https://dapp-iro.ironetwork.com
|
|
4
|
+
* 主网 Base URL: https://dapp-iro.ironetwork.com
|
|
5
|
+
* 测试网 Base URL: https://test-api.ironetwork.com
|
|
5
6
|
* 无需 X-Signature 校验
|
|
6
7
|
*/
|
|
7
8
|
// ============================================================================
|
|
8
9
|
// 常量
|
|
9
10
|
// ============================================================================
|
|
10
11
|
export const IRO_PLATFORM_URL = 'https://dapp-iro.ironetwork.com';
|
|
12
|
+
export const IRO_TESTNET_PLATFORM_URL = 'https://test-api.ironetwork.com';
|
|
11
13
|
let _iroApiBase = IRO_PLATFORM_URL;
|
|
14
|
+
let _iroTestApiBase = IRO_TESTNET_PLATFORM_URL;
|
|
12
15
|
/**
|
|
13
|
-
* 设置 IRO API 的 base URL
|
|
16
|
+
* 设置 IRO 主网 API 的 base URL
|
|
14
17
|
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/iro-api'
|
|
15
18
|
*/
|
|
16
19
|
export function setIroApiBase(base) {
|
|
17
20
|
_iroApiBase = base.replace(/\/+$/, '');
|
|
18
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* 设置 IRO 测试网 API 的 base URL
|
|
24
|
+
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/iro-test-api'
|
|
25
|
+
*/
|
|
26
|
+
export function setIroTestApiBase(base) {
|
|
27
|
+
_iroTestApiBase = base.replace(/\/+$/, '');
|
|
28
|
+
}
|
|
29
|
+
/** 根据是否测试网获取对应的 API base URL */
|
|
30
|
+
function getApiBase(testnet) {
|
|
31
|
+
return testnet ? _iroTestApiBase : _iroApiBase;
|
|
32
|
+
}
|
|
19
33
|
// ============================================================================
|
|
20
34
|
// 内部请求工具
|
|
21
35
|
// ============================================================================
|
|
22
|
-
async function request(path, options = {}) {
|
|
23
|
-
const url = `${
|
|
36
|
+
async function request(path, options = {}, testnet) {
|
|
37
|
+
const url = `${getApiBase(testnet)}${path}`;
|
|
24
38
|
const res = await fetch(url, {
|
|
25
39
|
...options,
|
|
26
40
|
headers: {
|
|
@@ -42,7 +56,7 @@ async function request(path, options = {}) {
|
|
|
42
56
|
* POST /api/community/create/open
|
|
43
57
|
* @returns projectID 字符串 (如 "20241009014234831377")
|
|
44
58
|
*/
|
|
45
|
-
export async function iroApiCreateProject(params) {
|
|
59
|
+
export async function iroApiCreateProject(params, testnet) {
|
|
46
60
|
const body = new FormData();
|
|
47
61
|
body.append('logo', params.logo);
|
|
48
62
|
body.append('name', params.name);
|
|
@@ -54,7 +68,7 @@ export async function iroApiCreateProject(params) {
|
|
|
54
68
|
const res = await request('/api/community/create/open', {
|
|
55
69
|
method: 'POST',
|
|
56
70
|
body,
|
|
57
|
-
});
|
|
71
|
+
}, testnet);
|
|
58
72
|
if (res.status !== 200 || !res.data?.projectID) {
|
|
59
73
|
throw new Error(`IRO API createProject failed: ${res.message || 'unknown'}`);
|
|
60
74
|
}
|
|
@@ -65,15 +79,17 @@ export async function iroApiCreateProject(params) {
|
|
|
65
79
|
*
|
|
66
80
|
* POST /api/upload/image
|
|
67
81
|
* 参数: img (file binary, 必填)
|
|
82
|
+
* 允许扩展名: .png .jpg .jpeg .gif
|
|
68
83
|
* @returns 图片 URL (data.path)
|
|
69
84
|
*/
|
|
70
|
-
export async function iroApiUploadImage(file, filename) {
|
|
85
|
+
export async function iroApiUploadImage(file, filename, testnet) {
|
|
86
|
+
const uploadName = filename || (file instanceof File ? file.name : 'logo.png');
|
|
71
87
|
const body = new FormData();
|
|
72
|
-
body.append('img', file,
|
|
88
|
+
body.append('img', file, uploadName);
|
|
73
89
|
const res = await request('/api/upload/image', {
|
|
74
90
|
method: 'POST',
|
|
75
91
|
body,
|
|
76
|
-
});
|
|
92
|
+
}, testnet);
|
|
77
93
|
if (res.status !== 200 || !res.data?.path) {
|
|
78
94
|
throw new Error(`IRO API uploadImage failed: ${res.message || 'unknown'}`);
|
|
79
95
|
}
|
|
@@ -15,7 +15,8 @@ const factoryIface = new Interface(IRO_FACTORY_ABI);
|
|
|
15
15
|
export class IroFactoryQuery {
|
|
16
16
|
constructor(config = {}) {
|
|
17
17
|
const rpcUrl = config.rpcUrl ?? BSC_RPC_URL;
|
|
18
|
-
|
|
18
|
+
const chainId = config.chainId ?? BSC_CHAIN_ID;
|
|
19
|
+
this.provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
19
20
|
const addr = config.factoryAddress ?? IRO_FACTORY_ADDRESS;
|
|
20
21
|
if (!addr)
|
|
21
22
|
throw new Error('IRO Factory address not configured');
|
|
@@ -87,11 +88,11 @@ export function encodeCreateProjectCall(params) {
|
|
|
87
88
|
* 注意: 调用者必须是 IROOwner 中注册的 broker
|
|
88
89
|
*/
|
|
89
90
|
export async function createProject(params) {
|
|
90
|
-
const { rpcUrl = BSC_RPC_URL, privateKey, factoryAddress, params: projectParams, gasPrice, } = params;
|
|
91
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, privateKey, factoryAddress, params: projectParams, gasPrice, } = params;
|
|
91
92
|
const targetFactory = factoryAddress ?? IRO_FACTORY_ADDRESS;
|
|
92
93
|
if (!targetFactory)
|
|
93
94
|
throw new Error('IRO Factory address not configured');
|
|
94
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
95
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
95
96
|
const wallet = new Wallet(privateKey, provider);
|
|
96
97
|
const calldata = encodeCreateProjectCall(projectParams);
|
|
97
98
|
const nonce = await wallet.getNonce();
|
|
@@ -100,7 +101,7 @@ export async function createProject(params) {
|
|
|
100
101
|
to: targetFactory,
|
|
101
102
|
data: calldata,
|
|
102
103
|
nonce,
|
|
103
|
-
chainId
|
|
104
|
+
chainId,
|
|
104
105
|
type: 0,
|
|
105
106
|
gasPrice: gasPrice ?? feeData.gasPrice ?? 3000000000n,
|
|
106
107
|
gasLimit: CREATE_PROJECT_GAS_LIMIT,
|
|
@@ -12,5 +12,5 @@ export { IroFactoryQuery, encodeCreateProjectCall, createProject, parseCreatePro
|
|
|
12
12
|
export { IroTokenQuery, subscribe, pledge, batchSubscribe, batchSubscribeForSubmit, } from './token.js';
|
|
13
13
|
export type { IroBatchSubscribeForSubmitParams, IroBatchSubscribeForSubmitResult, } from './token.js';
|
|
14
14
|
export { IroPoolQuery, poolRemovePledge, poolExtract, poolTransferAwards, batchExtract, } from './pool.js';
|
|
15
|
-
export { IRO_PLATFORM_URL, setIroApiBase, iroApiCreateProject, iroApiUploadImage, } from './api.js';
|
|
15
|
+
export { IRO_PLATFORM_URL, IRO_TESTNET_PLATFORM_URL, setIroApiBase, setIroTestApiBase, iroApiCreateProject, iroApiUploadImage, } from './api.js';
|
|
16
16
|
export type { IroApiCreateProjectRequest, IroApiCreateProjectResponse, IroApiUploadImageResponse, } from './api.js';
|
|
@@ -25,4 +25,4 @@ export { IroPoolQuery, poolRemovePledge, poolExtract, poolTransferAwards, batchE
|
|
|
25
25
|
// ============================================================================
|
|
26
26
|
// API (IRO 平台后端)
|
|
27
27
|
// ============================================================================
|
|
28
|
-
export { IRO_PLATFORM_URL, setIroApiBase, iroApiCreateProject, iroApiUploadImage, } from './api.js';
|
|
28
|
+
export { IRO_PLATFORM_URL, IRO_TESTNET_PLATFORM_URL, setIroApiBase, setIroTestApiBase, iroApiCreateProject, iroApiUploadImage, } from './api.js';
|
|
@@ -14,7 +14,7 @@ export declare class IroPoolQuery {
|
|
|
14
14
|
private provider;
|
|
15
15
|
private pool;
|
|
16
16
|
readonly poolAddress: string;
|
|
17
|
-
constructor(poolAddress: string, rpcUrl?: string);
|
|
17
|
+
constructor(poolAddress: string, rpcUrl?: string, chainId?: number);
|
|
18
18
|
/** 获取绑定的 token 地址 */
|
|
19
19
|
token(): Promise<string>;
|
|
20
20
|
/** 获取总份额 */
|
|
@@ -60,6 +60,7 @@ export declare function poolTransferAwards(params: IroPoolTransferAwardsParams):
|
|
|
60
60
|
*/
|
|
61
61
|
export declare function batchExtract(params: {
|
|
62
62
|
rpcUrl?: string;
|
|
63
|
+
chainId?: number;
|
|
63
64
|
poolAddress: string;
|
|
64
65
|
wallets: Array<{
|
|
65
66
|
privateKey: string;
|
|
@@ -16,9 +16,9 @@ const poolIface = new Interface(IRO_POOL_ABI);
|
|
|
16
16
|
// 查询
|
|
17
17
|
// ============================================================================
|
|
18
18
|
export class IroPoolQuery {
|
|
19
|
-
constructor(poolAddress, rpcUrl) {
|
|
19
|
+
constructor(poolAddress, rpcUrl, chainId) {
|
|
20
20
|
this.poolAddress = poolAddress;
|
|
21
|
-
this.provider = new JsonRpcProvider(rpcUrl ?? BSC_RPC_URL, BSC_CHAIN_ID, { staticNetwork: true });
|
|
21
|
+
this.provider = new JsonRpcProvider(rpcUrl ?? BSC_RPC_URL, chainId ?? BSC_CHAIN_ID, { staticNetwork: true });
|
|
22
22
|
this.pool = new Contract(poolAddress, IRO_POOL_ABI, this.provider);
|
|
23
23
|
}
|
|
24
24
|
/** 获取绑定的 token 地址 */
|
|
@@ -74,8 +74,8 @@ export class IroPoolQuery {
|
|
|
74
74
|
* removePledge() — 用户直接调用
|
|
75
75
|
*/
|
|
76
76
|
export async function poolRemovePledge(params) {
|
|
77
|
-
const { rpcUrl = BSC_RPC_URL, privateKey, poolAddress, gasPrice, } = params;
|
|
78
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
77
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, privateKey, poolAddress, gasPrice, } = params;
|
|
78
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
79
79
|
const wallet = new Wallet(privateKey, provider);
|
|
80
80
|
const calldata = poolIface.encodeFunctionData('removePledge', []);
|
|
81
81
|
const nonce = await wallet.getNonce();
|
|
@@ -84,7 +84,7 @@ export async function poolRemovePledge(params) {
|
|
|
84
84
|
to: poolAddress,
|
|
85
85
|
data: calldata,
|
|
86
86
|
nonce,
|
|
87
|
-
chainId
|
|
87
|
+
chainId,
|
|
88
88
|
type: 0,
|
|
89
89
|
gasPrice: gasPrice ?? feeData.gasPrice ?? 3000000000n,
|
|
90
90
|
gasLimit: POOL_OPERATION_GAS_LIMIT,
|
|
@@ -96,8 +96,8 @@ export async function poolRemovePledge(params) {
|
|
|
96
96
|
* extract(uint256 amount) — 用户直接调用
|
|
97
97
|
*/
|
|
98
98
|
export async function poolExtract(params) {
|
|
99
|
-
const { rpcUrl = BSC_RPC_URL, privateKey, poolAddress, amount, gasPrice, } = params;
|
|
100
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
99
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, privateKey, poolAddress, amount, gasPrice, } = params;
|
|
100
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
101
101
|
const wallet = new Wallet(privateKey, provider);
|
|
102
102
|
const calldata = poolIface.encodeFunctionData('extract', [amount]);
|
|
103
103
|
const nonce = await wallet.getNonce();
|
|
@@ -106,7 +106,7 @@ export async function poolExtract(params) {
|
|
|
106
106
|
to: poolAddress,
|
|
107
107
|
data: calldata,
|
|
108
108
|
nonce,
|
|
109
|
-
chainId
|
|
109
|
+
chainId,
|
|
110
110
|
type: 0,
|
|
111
111
|
gasPrice: gasPrice ?? feeData.gasPrice ?? 3000000000n,
|
|
112
112
|
gasLimit: POOL_OPERATION_GAS_LIMIT,
|
|
@@ -118,8 +118,8 @@ export async function poolExtract(params) {
|
|
|
118
118
|
* transferAwards(address[] recipients, uint256[] TKAAmounts) — 用户直接调用
|
|
119
119
|
*/
|
|
120
120
|
export async function poolTransferAwards(params) {
|
|
121
|
-
const { rpcUrl = BSC_RPC_URL, privateKey, poolAddress, recipients, amounts, gasPrice, } = params;
|
|
122
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
121
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, privateKey, poolAddress, recipients, amounts, gasPrice, } = params;
|
|
122
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
123
123
|
const wallet = new Wallet(privateKey, provider);
|
|
124
124
|
const calldata = poolIface.encodeFunctionData('transferAwards', [recipients, amounts]);
|
|
125
125
|
const nonce = await wallet.getNonce();
|
|
@@ -128,7 +128,7 @@ export async function poolTransferAwards(params) {
|
|
|
128
128
|
to: poolAddress,
|
|
129
129
|
data: calldata,
|
|
130
130
|
nonce,
|
|
131
|
-
chainId
|
|
131
|
+
chainId,
|
|
132
132
|
type: 0,
|
|
133
133
|
gasPrice: gasPrice ?? feeData.gasPrice ?? 3000000000n,
|
|
134
134
|
gasLimit: POOL_OPERATION_GAS_LIMIT,
|
|
@@ -139,8 +139,8 @@ export async function poolTransferAwards(params) {
|
|
|
139
139
|
* 批量提取收益 — 多钱包同时 extract
|
|
140
140
|
*/
|
|
141
141
|
export async function batchExtract(params) {
|
|
142
|
-
const { rpcUrl = BSC_RPC_URL, poolAddress, wallets, gasPrice } = params;
|
|
143
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
142
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, poolAddress, wallets, gasPrice } = params;
|
|
143
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
144
144
|
const feeData = await provider.getFeeData();
|
|
145
145
|
const resolvedGasPrice = gasPrice ?? feeData.gasPrice ?? 3000000000n;
|
|
146
146
|
const signedTransactions = [];
|
|
@@ -12,7 +12,7 @@ export declare class IroTokenQuery {
|
|
|
12
12
|
private provider;
|
|
13
13
|
private token;
|
|
14
14
|
readonly tokenAddress: string;
|
|
15
|
-
constructor(tokenAddress: string, rpcUrl?: string);
|
|
15
|
+
constructor(tokenAddress: string, rpcUrl?: string, chainId?: number);
|
|
16
16
|
name(): Promise<string>;
|
|
17
17
|
symbol(): Promise<string>;
|
|
18
18
|
decimals(): Promise<number>;
|
|
@@ -72,6 +72,7 @@ export declare function pledge(params: IroPledgeParams): Promise<IroTxResult>;
|
|
|
72
72
|
*/
|
|
73
73
|
export declare function batchSubscribe(params: {
|
|
74
74
|
rpcUrl?: string;
|
|
75
|
+
chainId?: number;
|
|
75
76
|
tokenAddress: string;
|
|
76
77
|
subscribers: Array<{
|
|
77
78
|
privateKey: string;
|
|
@@ -86,6 +87,8 @@ export declare function batchSubscribe(params: {
|
|
|
86
87
|
}>;
|
|
87
88
|
export interface IroBatchSubscribeForSubmitParams {
|
|
88
89
|
rpcUrl?: string;
|
|
90
|
+
/** 链 ID (默认 BSC 主网 56) */
|
|
91
|
+
chainId?: number;
|
|
89
92
|
tokenAddress: string;
|
|
90
93
|
subscribers: Array<{
|
|
91
94
|
privateKey: string;
|
|
@@ -16,9 +16,9 @@ const tokenIface = new Interface(IRO_TOKEN_ABI);
|
|
|
16
16
|
// 查询
|
|
17
17
|
// ============================================================================
|
|
18
18
|
export class IroTokenQuery {
|
|
19
|
-
constructor(tokenAddress, rpcUrl) {
|
|
19
|
+
constructor(tokenAddress, rpcUrl, chainId) {
|
|
20
20
|
this.tokenAddress = tokenAddress;
|
|
21
|
-
this.provider = new JsonRpcProvider(rpcUrl ?? BSC_RPC_URL, BSC_CHAIN_ID, { staticNetwork: true });
|
|
21
|
+
this.provider = new JsonRpcProvider(rpcUrl ?? BSC_RPC_URL, chainId ?? BSC_CHAIN_ID, { staticNetwork: true });
|
|
22
22
|
this.token = new Contract(tokenAddress, IRO_TOKEN_ABI, this.provider);
|
|
23
23
|
}
|
|
24
24
|
async name() {
|
|
@@ -132,8 +132,8 @@ export class IroTokenQuery {
|
|
|
132
132
|
* 4. msg.sender 和 _user 都不能是合约地址 (只能 EOA)
|
|
133
133
|
*/
|
|
134
134
|
export async function subscribe(params) {
|
|
135
|
-
const { rpcUrl = BSC_RPC_URL, privateKey, tokenAddress, user, amount, value, gasPrice, } = params;
|
|
136
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
135
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, privateKey, tokenAddress, user, amount, value, gasPrice, } = params;
|
|
136
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
137
137
|
const wallet = new Wallet(privateKey, provider);
|
|
138
138
|
const calldata = tokenIface.encodeFunctionData('subscribe', [user, amount]);
|
|
139
139
|
const nonce = await wallet.getNonce();
|
|
@@ -143,7 +143,7 @@ export async function subscribe(params) {
|
|
|
143
143
|
data: calldata,
|
|
144
144
|
value: value ?? 0n,
|
|
145
145
|
nonce,
|
|
146
|
-
chainId
|
|
146
|
+
chainId,
|
|
147
147
|
type: 0,
|
|
148
148
|
gasPrice: gasPrice ?? feeData.gasPrice ?? 3000000000n,
|
|
149
149
|
gasLimit: SUBSCRIBE_GAS_LIMIT,
|
|
@@ -161,8 +161,8 @@ export async function subscribe(params) {
|
|
|
161
161
|
* 注意: pledge 内部会用一半金额 swap 买入代币,另一半添加 LP
|
|
162
162
|
*/
|
|
163
163
|
export async function pledge(params) {
|
|
164
|
-
const { rpcUrl = BSC_RPC_URL, privateKey, tokenAddress, user, amount, value, gasPrice, } = params;
|
|
165
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
164
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, privateKey, tokenAddress, user, amount, value, gasPrice, } = params;
|
|
165
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
166
166
|
const wallet = new Wallet(privateKey, provider);
|
|
167
167
|
const calldata = tokenIface.encodeFunctionData('pledge', [user, amount]);
|
|
168
168
|
const nonce = await wallet.getNonce();
|
|
@@ -172,7 +172,7 @@ export async function pledge(params) {
|
|
|
172
172
|
data: calldata,
|
|
173
173
|
value: value ?? 0n,
|
|
174
174
|
nonce,
|
|
175
|
-
chainId
|
|
175
|
+
chainId,
|
|
176
176
|
type: 0,
|
|
177
177
|
gasPrice: gasPrice ?? feeData.gasPrice ?? 3000000000n,
|
|
178
178
|
gasLimit: SUBSCRIBE_GAS_LIMIT,
|
|
@@ -183,8 +183,8 @@ export async function pledge(params) {
|
|
|
183
183
|
* 批量认购 — 多钱包同时认购
|
|
184
184
|
*/
|
|
185
185
|
export async function batchSubscribe(params) {
|
|
186
|
-
const { rpcUrl = BSC_RPC_URL, tokenAddress, subscribers, gasPrice } = params;
|
|
187
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
186
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, tokenAddress, subscribers, gasPrice } = params;
|
|
187
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
188
188
|
const feeData = await provider.getFeeData();
|
|
189
189
|
const resolvedGasPrice = gasPrice ?? feeData.gasPrice ?? 3000000000n;
|
|
190
190
|
const signedTransactions = [];
|
|
@@ -192,6 +192,7 @@ export async function batchSubscribe(params) {
|
|
|
192
192
|
for (const sub of subscribers) {
|
|
193
193
|
const result = await subscribe({
|
|
194
194
|
rpcUrl,
|
|
195
|
+
chainId,
|
|
195
196
|
privateKey: sub.privateKey,
|
|
196
197
|
tokenAddress,
|
|
197
198
|
user: sub.user,
|
|
@@ -216,11 +217,11 @@ export async function batchSubscribe(params) {
|
|
|
216
217
|
* 后端 submit_blockrazor 会验证最后 3 笔是利润交易,然后去掉后广播业务交易
|
|
217
218
|
*/
|
|
218
219
|
export async function batchSubscribeForSubmit(params) {
|
|
219
|
-
const { rpcUrl = BSC_RPC_URL, tokenAddress, subscribers, approvalTxs = [], gasPrice } = params;
|
|
220
|
+
const { rpcUrl = BSC_RPC_URL, chainId = BSC_CHAIN_ID, tokenAddress, subscribers, approvalTxs = [], gasPrice } = params;
|
|
220
221
|
if (subscribers.length === 0) {
|
|
221
222
|
return { signedTransactions: [...approvalTxs], subscribeResults: [], profitAmount: 0n };
|
|
222
223
|
}
|
|
223
|
-
const provider = new JsonRpcProvider(rpcUrl,
|
|
224
|
+
const provider = new JsonRpcProvider(rpcUrl, chainId, { staticNetwork: true });
|
|
224
225
|
const feeData = await provider.getFeeData();
|
|
225
226
|
const resolvedGasPrice = gasPrice ?? feeData.gasPrice ?? 3000000000n;
|
|
226
227
|
const subscribeTxs = [];
|
|
@@ -230,6 +231,7 @@ export async function batchSubscribeForSubmit(params) {
|
|
|
230
231
|
for (const sub of subscribers) {
|
|
231
232
|
const result = await subscribe({
|
|
232
233
|
rpcUrl,
|
|
234
|
+
chainId,
|
|
233
235
|
privateKey: sub.privateKey,
|
|
234
236
|
tokenAddress,
|
|
235
237
|
user: sub.user,
|
|
@@ -266,7 +268,7 @@ export async function batchSubscribeForSubmit(params) {
|
|
|
266
268
|
profitRecipient: getProfitRecipient(),
|
|
267
269
|
hopCount: PROFIT_HOP_COUNT,
|
|
268
270
|
gasPrice: resolvedGasPrice,
|
|
269
|
-
chainId
|
|
271
|
+
chainId,
|
|
270
272
|
txType: 0,
|
|
271
273
|
startNonce: payerNonce,
|
|
272
274
|
});
|
|
@@ -41,6 +41,8 @@ export interface IroFactoryTokenInfo {
|
|
|
41
41
|
}
|
|
42
42
|
export interface IroSubscribeParams {
|
|
43
43
|
rpcUrl?: string;
|
|
44
|
+
/** 链 ID (默认 BSC 主网 56) */
|
|
45
|
+
chainId?: number;
|
|
44
46
|
privateKey: string;
|
|
45
47
|
/** IRO 代币合约地址 */
|
|
46
48
|
tokenAddress: string;
|
|
@@ -54,6 +56,7 @@ export interface IroSubscribeParams {
|
|
|
54
56
|
}
|
|
55
57
|
export interface IroPledgeParams {
|
|
56
58
|
rpcUrl?: string;
|
|
59
|
+
chainId?: number;
|
|
57
60
|
privateKey: string;
|
|
58
61
|
/** IRO 代币合约地址 */
|
|
59
62
|
tokenAddress: string;
|
|
@@ -75,12 +78,14 @@ export interface IroTokenPrice {
|
|
|
75
78
|
}
|
|
76
79
|
export interface IroPoolRemovePledgeParams {
|
|
77
80
|
rpcUrl?: string;
|
|
81
|
+
chainId?: number;
|
|
78
82
|
privateKey: string;
|
|
79
83
|
poolAddress: string;
|
|
80
84
|
gasPrice?: bigint;
|
|
81
85
|
}
|
|
82
86
|
export interface IroPoolExtractParams {
|
|
83
87
|
rpcUrl?: string;
|
|
88
|
+
chainId?: number;
|
|
84
89
|
privateKey: string;
|
|
85
90
|
poolAddress: string;
|
|
86
91
|
/** 提取收益数量 (wei) */
|
|
@@ -89,6 +94,7 @@ export interface IroPoolExtractParams {
|
|
|
89
94
|
}
|
|
90
95
|
export interface IroPoolTransferAwardsParams {
|
|
91
96
|
rpcUrl?: string;
|
|
97
|
+
chainId?: number;
|
|
92
98
|
privateKey: string;
|
|
93
99
|
poolAddress: string;
|
|
94
100
|
/** 接收者地址列表 */
|
|
@@ -121,10 +127,12 @@ export interface IroCreateProjectResult extends IroTxResult {
|
|
|
121
127
|
}
|
|
122
128
|
export interface IroQueryConfig {
|
|
123
129
|
rpcUrl?: string;
|
|
130
|
+
chainId?: number;
|
|
124
131
|
factoryAddress?: string;
|
|
125
132
|
}
|
|
126
133
|
export interface IroCreateParams {
|
|
127
134
|
rpcUrl?: string;
|
|
135
|
+
chainId?: number;
|
|
128
136
|
privateKey: string;
|
|
129
137
|
factoryAddress?: string;
|
|
130
138
|
params: IroCreateProjectParams;
|
|
@@ -23,6 +23,11 @@ export declare const ENI_ADDRESSES: {
|
|
|
23
23
|
readonly DswapV3Router02: "0xcdE487F5B460a516f31FaC520D4e18BA1C8cda49";
|
|
24
24
|
readonly Multicall3: "0xde8bbd91FFd778E8Fc4df66d808159b6245b3D51";
|
|
25
25
|
readonly BatchRouter: "0xDe44dC76cE29f743FbC250930a92a847Bf1662F2";
|
|
26
|
+
readonly IroFactory: "0x556b2aeEcc69AF2084Cfc9282BdeB5888130a566";
|
|
27
|
+
readonly IroOwner: "0x8865b811A402c2669439880B1d57a74B391204a0";
|
|
28
|
+
readonly IroSellFeeContract: "0xec5Fb1FEaAfBf86c7B139fEd5D1c3EA8FFC0b1c5";
|
|
29
|
+
readonly IroSwapV2Router: "0x93b1199fA96f6b9b1f993AA0226eB6076968a9BF";
|
|
30
|
+
readonly IroSwapV2Factory: "0xdE4360F6Cd386FD70Db1386F920138177e3967df";
|
|
26
31
|
};
|
|
27
32
|
export declare const WEGAS: "0x6d1e851446f4d004ae2a72f9afed85e8829a205e";
|
|
28
33
|
export declare const USDT: "0xDC1a8A35b0BaA3229b13f348ED708a2fd50b5e3a";
|
|
@@ -33,6 +38,10 @@ export declare const TOKEN_FACTORY: "0x720ba3aac040543837e306039b0e395b02e9bba9"
|
|
|
33
38
|
export declare const POOL_FACTORY: "0x3f5636a7bd02762625d24769a8f2963de5fbf80c";
|
|
34
39
|
export declare const DSWAP_V2_ROUTER: "0x97ed8be49d9a8b86247090aa41e908e76b8fcf22";
|
|
35
40
|
export declare const DSWAP_V2_FACTORY: "0x548c0e26ce90b333c07abb6d55546304d46d269d";
|
|
41
|
+
export declare const IRO_FACTORY: "0x556b2aeEcc69AF2084Cfc9282BdeB5888130a566";
|
|
42
|
+
export declare const IRO_OWNER: "0x8865b811A402c2669439880B1d57a74B391204a0";
|
|
43
|
+
export declare const IROSWAP_V2_ROUTER: "0x93b1199fA96f6b9b1f993AA0226eB6076968a9BF";
|
|
44
|
+
export declare const IROSWAP_V2_FACTORY: "0xdE4360F6Cd386FD70Db1386F920138177e3967df";
|
|
36
45
|
export declare const ENI_MULTICALL3: "0xde8bbd91FFd778E8Fc4df66d808159b6245b3D51";
|
|
37
46
|
export declare const NATIVE_TRANSFER_GAS_LIMIT: 21055n;
|
|
38
47
|
export declare const ERC20_TRANSFER_GAS_LIMIT: 65000n;
|
|
@@ -25,6 +25,10 @@ export const TOKEN_FACTORY = ADDRESSES.ENI.TokenFactory;
|
|
|
25
25
|
export const POOL_FACTORY = ADDRESSES.ENI.PoolFactory;
|
|
26
26
|
export const DSWAP_V2_ROUTER = ADDRESSES.ENI.DswapV2Router;
|
|
27
27
|
export const DSWAP_V2_FACTORY = ADDRESSES.ENI.DswapV2Factory;
|
|
28
|
+
export const IRO_FACTORY = ADDRESSES.ENI.IroFactory;
|
|
29
|
+
export const IRO_OWNER = ADDRESSES.ENI.IroOwner;
|
|
30
|
+
export const IROSWAP_V2_ROUTER = ADDRESSES.ENI.IroSwapV2Router;
|
|
31
|
+
export const IROSWAP_V2_FACTORY = ADDRESSES.ENI.IroSwapV2Factory;
|
|
28
32
|
export const ENI_MULTICALL3 = ADDRESSES.ENI.Multicall3;
|
|
29
33
|
// ============================================================================
|
|
30
34
|
// Gas 配置
|
|
@@ -18,3 +18,5 @@ export { FairPoolQuery, claimFromPool, claimFromPoolForSubmit, batchClaimForSubm
|
|
|
18
18
|
export type { PoolOverview, PoolClaimParams, PoolClaimResult, } from './platforms/fair-launch/index.js';
|
|
19
19
|
export { getLPPairInfo, batchGetLPPairInfo, getPairAddress, addLiquidityETHForSubmit, removeLiquidityETHForSubmit, addLiquidityForSubmit, removeLiquidityForSubmit, } from './platforms/dswap/index.js';
|
|
20
20
|
export type { LPPairInfo, GetLPInfoParams, BatchGetLPInfoParams, AddLiquidityETHParams, RemoveLiquidityETHParams, AddLiquidityParams, RemoveLiquidityParams, LiquidityTxResult, LiquidityForSubmitResult, } from './platforms/dswap/index.js';
|
|
21
|
+
export { IroFactoryQuery as EniIroFactoryQuery, encodeCreateProjectCall as eniIroEncodeCreateProjectCall, createProject as eniIroCreateProject, parseCreateProjectEvent as eniIroParseCreateProjectEvent, IroTokenQuery as EniIroTokenQuery, subscribe as eniIroSubscribe, pledge as eniIroPledge, batchSubscribe as eniIroBatchSubscribe, batchSubscribeForSubmit as eniIroBatchSubscribeForSubmit, IroPoolQuery as EniIroPoolQuery, poolRemovePledge as eniIroPoolRemovePledge, poolExtract as eniIroPoolExtract, poolTransferAwards as eniIroPoolTransferAwards, batchExtract as eniIroBatchExtract, ENI_IRO_FACTORY_ADDRESS, ENI_IRO_OWNER_ADDRESS, ENI_IRO_SELL_FEE_CONTRACT, ENI_IROSWAP_V2_ROUTER, ENI_IROSWAP_V2_FACTORY, IRO_FACTORY_ABI as ENI_IRO_FACTORY_ABI, IRO_TOKEN_ABI as ENI_IRO_TOKEN_ABI, IRO_POOL_ABI as ENI_IRO_POOL_ABI, ENI_IRO_PLATFORM_URL, setIroApiBase as setEniIroApiBase, iroApiCreateProject as eniIroApiCreateProject, iroApiUploadImage as eniIroApiUploadImage, } from './platforms/iro/index.js';
|
|
22
|
+
export type { WhiteListQuota as EniWhiteListQuota, IroCreateProjectParams as EniIroCreateProjectParams, IroSubscribeParams as EniIroSubscribeParams, IroPledgeParams as EniIroPledgeParams, IroTokenInfo as EniIroTokenInfo, IroTxResult as EniIroTxResult, IroCreateProjectResult as EniIroCreateProjectResult, IroQueryConfig as EniIroQueryConfig, IroCreateParams as EniIroCreateParams, IroBatchSubscribeForSubmitParams as EniIroBatchSubscribeForSubmitParams, IroBatchSubscribeForSubmitResult as EniIroBatchSubscribeForSubmitResult, } from './platforms/iro/index.js';
|
package/dist/chains/eni/index.js
CHANGED
|
@@ -27,3 +27,7 @@ export { FairPoolQuery, claimFromPool, claimFromPoolForSubmit, batchClaimForSubm
|
|
|
27
27
|
// 快捷导出 - DSWAP V2 (流动性管理)
|
|
28
28
|
// ============================================================================
|
|
29
29
|
export { getLPPairInfo, batchGetLPPairInfo, getPairAddress, addLiquidityETHForSubmit, removeLiquidityETHForSubmit, addLiquidityForSubmit, removeLiquidityForSubmit, } from './platforms/dswap/index.js';
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// 快捷导出 - IRO (Initial Rights Offering)
|
|
32
|
+
// ============================================================================
|
|
33
|
+
export { IroFactoryQuery as EniIroFactoryQuery, encodeCreateProjectCall as eniIroEncodeCreateProjectCall, createProject as eniIroCreateProject, parseCreateProjectEvent as eniIroParseCreateProjectEvent, IroTokenQuery as EniIroTokenQuery, subscribe as eniIroSubscribe, pledge as eniIroPledge, batchSubscribe as eniIroBatchSubscribe, batchSubscribeForSubmit as eniIroBatchSubscribeForSubmit, IroPoolQuery as EniIroPoolQuery, poolRemovePledge as eniIroPoolRemovePledge, poolExtract as eniIroPoolExtract, poolTransferAwards as eniIroPoolTransferAwards, batchExtract as eniIroBatchExtract, ENI_IRO_FACTORY_ADDRESS, ENI_IRO_OWNER_ADDRESS, ENI_IRO_SELL_FEE_CONTRACT, ENI_IROSWAP_V2_ROUTER, ENI_IROSWAP_V2_FACTORY, IRO_FACTORY_ABI as ENI_IRO_FACTORY_ABI, IRO_TOKEN_ABI as ENI_IRO_TOKEN_ABI, IRO_POOL_ABI as ENI_IRO_POOL_ABI, ENI_IRO_PLATFORM_URL, setIroApiBase as setEniIroApiBase, iroApiCreateProject as eniIroApiCreateProject, iroApiUploadImage as eniIroApiUploadImage, } from './platforms/iro/index.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ENI IRO 平台后端 API
|
|
3
|
+
*
|
|
4
|
+
* 正式服 Base URL: https://eni-api.ironetwork.com
|
|
5
|
+
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/eni-iro-api'
|
|
6
|
+
*/
|
|
7
|
+
export declare const ENI_IRO_PLATFORM_URL = "https://eni-api.ironetwork.com";
|
|
8
|
+
/**
|
|
9
|
+
* 设置 ENI IRO API 的 base URL
|
|
10
|
+
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/eni-iro-api'
|
|
11
|
+
*/
|
|
12
|
+
export declare function setIroApiBase(base: string): void;
|
|
13
|
+
export interface IroApiCreateProjectRequest {
|
|
14
|
+
logo: string;
|
|
15
|
+
name: string;
|
|
16
|
+
symbol: string;
|
|
17
|
+
totalSupply: string;
|
|
18
|
+
description: string;
|
|
19
|
+
hardCap: string;
|
|
20
|
+
initPrice: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IroApiCreateProjectResponse {
|
|
23
|
+
status: number;
|
|
24
|
+
message: string;
|
|
25
|
+
data: {
|
|
26
|
+
projectID: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface IroApiUploadImageResponse {
|
|
30
|
+
status: number;
|
|
31
|
+
message: string;
|
|
32
|
+
data: {
|
|
33
|
+
path: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare function iroApiCreateProject(params: IroApiCreateProjectRequest): Promise<string>;
|
|
37
|
+
export declare function iroApiUploadImage(file: File | Blob, filename?: string): Promise<string>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ENI IRO 平台后端 API
|
|
3
|
+
*
|
|
4
|
+
* 正式服 Base URL: https://eni-api.ironetwork.com
|
|
5
|
+
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/eni-iro-api'
|
|
6
|
+
*/
|
|
7
|
+
export const ENI_IRO_PLATFORM_URL = 'https://eni-api.ironetwork.com';
|
|
8
|
+
let _eniIroApiBase = ENI_IRO_PLATFORM_URL;
|
|
9
|
+
/**
|
|
10
|
+
* 设置 ENI IRO API 的 base URL
|
|
11
|
+
* 浏览器环境下需要通过 Vite 代理绕过 CORS,例如传入 '/eni-iro-api'
|
|
12
|
+
*/
|
|
13
|
+
export function setIroApiBase(base) {
|
|
14
|
+
_eniIroApiBase = base.replace(/\/+$/, '');
|
|
15
|
+
}
|
|
16
|
+
function getApiBase() {
|
|
17
|
+
return _eniIroApiBase;
|
|
18
|
+
}
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// 内部请求工具
|
|
21
|
+
// ============================================================================
|
|
22
|
+
async function request(path, options = {}) {
|
|
23
|
+
const url = `${getApiBase()}${path}`;
|
|
24
|
+
const res = await fetch(url, { ...options, headers: { ...options.headers } });
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const text = await res.text().catch(() => '');
|
|
27
|
+
throw new Error(`ENI IRO API error (${res.status}): ${text || res.statusText}`);
|
|
28
|
+
}
|
|
29
|
+
return (await res.json());
|
|
30
|
+
}
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// 公开 API
|
|
33
|
+
// ============================================================================
|
|
34
|
+
export async function iroApiCreateProject(params) {
|
|
35
|
+
const body = new FormData();
|
|
36
|
+
body.append('logo', params.logo);
|
|
37
|
+
body.append('name', params.name);
|
|
38
|
+
body.append('symbol', params.symbol);
|
|
39
|
+
body.append('total_supply', params.totalSupply);
|
|
40
|
+
body.append('description', params.description);
|
|
41
|
+
body.append('max', params.hardCap);
|
|
42
|
+
body.append('price', params.initPrice);
|
|
43
|
+
const res = await request('/api/community/create/open', {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body,
|
|
46
|
+
});
|
|
47
|
+
if (res.status !== 200 || !res.data?.projectID) {
|
|
48
|
+
throw new Error(`ENI IRO API createProject failed: ${res.message || 'unknown'}`);
|
|
49
|
+
}
|
|
50
|
+
return res.data.projectID;
|
|
51
|
+
}
|
|
52
|
+
export async function iroApiUploadImage(file, filename) {
|
|
53
|
+
const uploadName = filename || (file instanceof File ? file.name : 'logo.png');
|
|
54
|
+
const body = new FormData();
|
|
55
|
+
body.append('img', file, uploadName);
|
|
56
|
+
const res = await request('/api/upload/image', {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
body,
|
|
59
|
+
});
|
|
60
|
+
if (res.status !== 200 || !res.data?.path) {
|
|
61
|
+
throw new Error(`ENI IRO API uploadImage failed: ${res.message || 'unknown'}`);
|
|
62
|
+
}
|
|
63
|
+
return res.data.path;
|
|
64
|
+
}
|