four-flap-meme-sdk 2.0.0 → 2.2.0

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 (220) hide show
  1. package/dist/__tests__/subpath-exports.test.js +64 -0
  2. package/dist/chains/bsc/iro.d.ts +5 -0
  3. package/dist/chains/bsc/iro.js +4 -0
  4. package/dist/chains/eni/flat-aliases.d.ts +10 -0
  5. package/dist/chains/eni/flat-aliases.js +8 -0
  6. package/dist/chains/eni/index.d.ts +1 -0
  7. package/dist/chains/eni/index.js +1 -0
  8. package/dist/chains/index.d.ts +13 -0
  9. package/dist/chains/index.js +13 -0
  10. package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +13 -0
  11. package/dist/chains/xlayer/eip7702/flat-aliases.js +10 -0
  12. package/dist/chains/xlayer/eip7702/index.d.ts +1 -0
  13. package/dist/chains/xlayer/eip7702/index.js +1 -0
  14. package/dist/chains/xlayer/index.d.ts +3 -2
  15. package/dist/chains/xlayer/index.js +4 -7
  16. package/dist/flap/index.d.ts +10 -0
  17. package/dist/flap/index.js +8 -0
  18. package/dist/merkle/index.d.ts +12 -0
  19. package/dist/merkle/index.js +11 -0
  20. package/dist/shared/constants/index.d.ts +2 -0
  21. package/dist/shared/index.d.ts +2 -0
  22. package/dist/vanity/index.d.ts +5 -0
  23. package/dist/vanity/index.js +5 -0
  24. package/package.json +93 -2
  25. package/dist/chains/bsc/four/disperse.d.ts +0 -12
  26. package/dist/chains/bsc/four/disperse.js +0 -470
  27. package/dist/chains/bsc/four/pairwise.d.ts +0 -7
  28. package/dist/chains/bsc/four/pairwise.js +0 -308
  29. package/dist/chains/bsc/four/submit/blockrazor.d.ts +0 -18
  30. package/dist/chains/bsc/four/submit/blockrazor.js +0 -86
  31. package/dist/chains/bsc/four/submit/direct.d.ts +0 -66
  32. package/dist/chains/bsc/four/submit/direct.js +0 -452
  33. package/dist/chains/bsc/four/submit/helpers.d.ts +0 -18
  34. package/dist/chains/bsc/four/submit/helpers.js +0 -57
  35. package/dist/chains/bsc/four/submit/index.d.ts +0 -12
  36. package/dist/chains/bsc/four/submit/index.js +0 -11
  37. package/dist/chains/bsc/four/submit/merkle.d.ts +0 -18
  38. package/dist/chains/bsc/four/submit/merkle.js +0 -74
  39. package/dist/chains/bsc/four/submit/types.d.ts +0 -143
  40. package/dist/chains/bsc/four/swap/index.d.ts +0 -32
  41. package/dist/chains/bsc/four/swap/index.js +0 -829
  42. package/dist/chains/bsc/four/swap/types.d.ts +0 -70
  43. package/dist/chains/bsc/four/swap/types.js +0 -1
  44. package/dist/chains/bsc/four/sweep.d.ts +0 -13
  45. package/dist/chains/bsc/four/sweep.js +0 -788
  46. package/dist/chains/bsc/four/utils/index.d.ts +0 -20
  47. package/dist/chains/bsc/four/utils/index.js +0 -1558
  48. package/dist/chains/bsc/four/utils/types.d.ts +0 -1
  49. package/dist/chains/bsc/four/utils/types.js +0 -1
  50. package/dist/chains/bsc/pancake/bundle-buy-first/index.d.ts +0 -8
  51. package/dist/chains/bsc/pancake/bundle-buy-first/index.js +0 -907
  52. package/dist/chains/bsc/pancake/bundle-buy-first/types.d.ts +0 -73
  53. package/dist/chains/bsc/pancake/bundle-buy-first/types.js +0 -1
  54. package/dist/chains/bsc/pancake/bundle-swap/helpers.d.ts +0 -102
  55. package/dist/chains/bsc/pancake/bundle-swap/helpers.js +0 -572
  56. package/dist/chains/bsc/pancake/bundle-swap/index.d.ts +0 -50
  57. package/dist/chains/bsc/pancake/bundle-swap/index.js +0 -1066
  58. package/dist/chains/bsc/pancake/bundle-swap/types.d.ts +0 -202
  59. package/dist/chains/bsc/pancake/bundle-swap/types.js +0 -3
  60. package/dist/chains/xlayer/eip7702/bundle-swap/index.d.ts +0 -72
  61. package/dist/chains/xlayer/eip7702/bundle-swap/index.js +0 -921
  62. package/dist/chains/xlayer/eip7702/bundle-swap/types.d.ts +0 -65
  63. package/dist/chains/xlayer/eip7702/bundle-swap/types.js +0 -1
  64. package/dist/chains/xlayer/eip7702/multi-hop-transfer/index.d.ts +0 -128
  65. package/dist/chains/xlayer/eip7702/multi-hop-transfer/index.js +0 -857
  66. package/dist/chains/xlayer/eip7702/multi-hop-transfer/types.d.ts +0 -85
  67. package/dist/chains/xlayer/eip7702/multi-hop-transfer/types.js +0 -1
  68. package/dist/chains/xlayer/eip7702/volume/index.d.ts +0 -96
  69. package/dist/chains/xlayer/eip7702/volume/index.js +0 -793
  70. package/dist/chains/xlayer/eip7702/volume/types.d.ts +0 -124
  71. package/dist/chains/xlayer/eip7702/volume/types.js +0 -1
  72. package/dist/chains/xlayer/eoa/types-core.d.ts +0 -363
  73. package/dist/chains/xlayer/eoa/types-core.js +0 -53
  74. package/dist/chains/xlayer/eoa/types-create.d.ts +0 -413
  75. package/dist/chains/xlayer/eoa/types-create.js +0 -9
  76. package/dist/chains/xlayer/eoa/types-volume.d.ts +0 -209
  77. package/dist/chains/xlayer/eoa/types-volume.js +0 -13
  78. package/dist/dex/direct-router/index.d.ts +0 -70
  79. package/dist/dex/direct-router/index.js +0 -1410
  80. package/dist/dex/direct-router/types.d.ts +0 -81
  81. package/dist/dex/direct-router/types.js +0 -1
  82. package/dist/shared/abis/TaxToken.json +0 -969
  83. package/dist/shared/abis/TokenManager.json +0 -836
  84. package/dist/shared/abis/TokenManager2.json +0 -136
  85. package/dist/shared/abis/TokenManagerHelper3.json +0 -993
  86. package/dist/shared/abis 2/TaxToken.json +0 -105
  87. package/dist/shared/abis 2/TokenManager.json +0 -836
  88. package/dist/shared/abis 2/TokenManager2.json +0 -60
  89. package/dist/shared/abis 2/TokenManagerHelper3.json +0 -993
  90. package/dist/shared/abis 2/common.d.ts +0 -85
  91. package/dist/shared/abis 2/common.js +0 -254
  92. package/dist/shared/abis 2/index.d.ts +0 -8
  93. package/dist/shared/abis 2/index.js +0 -8
  94. package/dist/shared/clients 2/blockrazor.d.ts +0 -314
  95. package/dist/shared/clients 2/blockrazor.js +0 -596
  96. package/dist/shared/clients 2/club48.d.ts +0 -154
  97. package/dist/shared/clients 2/club48.js +0 -331
  98. package/dist/shared/clients 2/emitservice.d.ts +0 -47
  99. package/dist/shared/clients 2/emitservice.js +0 -44
  100. package/dist/shared/clients 2/four.d.ts +0 -132
  101. package/dist/shared/clients 2/four.js +0 -281
  102. package/dist/shared/clients 2/merkle.d.ts +0 -210
  103. package/dist/shared/clients 2/merkle.js +0 -400
  104. package/dist/shared/flap/__tests__/curve.test.d.ts +0 -1
  105. package/dist/shared/flap/__tests__/curve.test.js +0 -85
  106. package/dist/shared/flap/portal/index.d.ts +0 -12
  107. package/dist/shared/flap/portal/index.js +0 -11
  108. package/dist/shared/flap/portal/portal.d.ts +0 -47
  109. package/dist/shared/flap/portal/portal.js +0 -218
  110. package/dist/shared/flap/portal/types.d.ts +0 -227
  111. package/dist/shared/flap/portal/types.js +0 -80
  112. package/dist/shared/flap/portal/writer.d.ts +0 -121
  113. package/dist/shared/flap/portal/writer.js +0 -265
  114. package/dist/shared/flap/portal-bundle-merkle/core/index.d.ts +0 -18
  115. package/dist/shared/flap/portal-bundle-merkle/core/index.js +0 -938
  116. package/dist/shared/flap/portal-bundle-merkle/core/types.d.ts +0 -1
  117. package/dist/shared/flap/portal-bundle-merkle/core/types.js +0 -1
  118. package/dist/shared/flap/portal-bundle-merkle/swap/index.d.ts +0 -42
  119. package/dist/shared/flap/portal-bundle-merkle/swap/index.js +0 -1448
  120. package/dist/shared/flap/portal-bundle-merkle/swap/types.d.ts +0 -84
  121. package/dist/shared/flap/portal-bundle-merkle/swap/types.js +0 -1
  122. package/dist/shared/flap/portal-bundle-merkle/utils/index.d.ts +0 -17
  123. package/dist/shared/flap/portal-bundle-merkle/utils/index.js +0 -1024
  124. package/dist/shared/flap/portal-bundle-merkle/utils/types.d.ts +0 -16
  125. package/dist/shared/flap/portal-bundle-merkle/utils/types.js +0 -1
  126. package/dist/shared/flap/portal-bundle-merkle/utils-helpers.d.ts +0 -100
  127. package/dist/shared/flap/portal-bundle-merkle/utils-helpers.js +0 -133
  128. package/dist/shared/flap 2/__tests__/curve.test.d.ts +0 -1
  129. package/dist/shared/flap 2/__tests__/curve.test.js +0 -85
  130. package/dist/shared/flap 2/abi.d.ts +0 -4
  131. package/dist/shared/flap 2/abi.js +0 -4
  132. package/dist/shared/flap 2/constants.d.ts +0 -128
  133. package/dist/shared/flap 2/constants.js +0 -143
  134. package/dist/shared/flap 2/curve.d.ts +0 -33
  135. package/dist/shared/flap 2/curve.js +0 -84
  136. package/dist/shared/flap 2/errors.d.ts +0 -37
  137. package/dist/shared/flap 2/errors.js +0 -114
  138. package/dist/shared/flap 2/index.d.ts +0 -22
  139. package/dist/shared/flap 2/index.js +0 -33
  140. package/dist/shared/flap 2/ipfs.d.ts +0 -21
  141. package/dist/shared/flap 2/ipfs.js +0 -38
  142. package/dist/shared/flap 2/meta.d.ts +0 -30
  143. package/dist/shared/flap 2/meta.js +0 -195
  144. package/dist/shared/flap 2/permit.d.ts +0 -16
  145. package/dist/shared/flap 2/permit.js +0 -67
  146. package/dist/shared/flap 2/pinata.d.ts +0 -40
  147. package/dist/shared/flap 2/pinata.js +0 -106
  148. package/dist/shared/flap 2/portal-bundle-merkle/config.d.ts +0 -79
  149. package/dist/shared/flap 2/portal-bundle-merkle/config.js +0 -133
  150. package/dist/shared/flap 2/portal-bundle-merkle/core.d.ts +0 -18
  151. package/dist/shared/flap 2/portal-bundle-merkle/core.js +0 -938
  152. package/dist/shared/flap 2/portal-bundle-merkle/create-to-dex.d.ts +0 -125
  153. package/dist/shared/flap 2/portal-bundle-merkle/create-to-dex.js +0 -665
  154. package/dist/shared/flap 2/portal-bundle-merkle/curve-to-dex.d.ts +0 -88
  155. package/dist/shared/flap 2/portal-bundle-merkle/curve-to-dex.js +0 -446
  156. package/dist/shared/flap 2/portal-bundle-merkle/index.d.ts +0 -14
  157. package/dist/shared/flap 2/portal-bundle-merkle/index.js +0 -26
  158. package/dist/shared/flap 2/portal-bundle-merkle/pancake-proxy.d.ts +0 -28
  159. package/dist/shared/flap 2/portal-bundle-merkle/pancake-proxy.js +0 -701
  160. package/dist/shared/flap 2/portal-bundle-merkle/private.d.ts +0 -17
  161. package/dist/shared/flap 2/portal-bundle-merkle/private.js +0 -549
  162. package/dist/shared/flap 2/portal-bundle-merkle/swap-buy-first.d.ts +0 -65
  163. package/dist/shared/flap 2/portal-bundle-merkle/swap-buy-first.js +0 -831
  164. package/dist/shared/flap 2/portal-bundle-merkle/swap.d.ts +0 -201
  165. package/dist/shared/flap 2/portal-bundle-merkle/swap.js +0 -1359
  166. package/dist/shared/flap 2/portal-bundle-merkle/types.d.ts +0 -358
  167. package/dist/shared/flap 2/portal-bundle-merkle/types.js +0 -1
  168. package/dist/shared/flap 2/portal-bundle-merkle/utils.d.ts +0 -89
  169. package/dist/shared/flap 2/portal-bundle-merkle/utils.js +0 -963
  170. package/dist/shared/flap 2/portal-bundle.d.ts +0 -119
  171. package/dist/shared/flap 2/portal-bundle.js +0 -584
  172. package/dist/shared/flap 2/portal.d.ts +0 -392
  173. package/dist/shared/flap 2/portal.js +0 -559
  174. package/dist/shared/flap 2/vanity.d.ts +0 -48
  175. package/dist/shared/flap 2/vanity.js +0 -110
  176. package/dist/shared/flap 2/vault.d.ts +0 -240
  177. package/dist/shared/flap 2/vault.js +0 -366
  178. package/dist/shared/four 2/index.d.ts +0 -7
  179. package/dist/shared/four 2/index.js +0 -22
  180. package/dist/shared/four 2/tax-token.d.ts +0 -176
  181. package/dist/shared/four 2/tax-token.js +0 -302
  182. package/dist/shared/index 2.js +0 -10
  183. package/dist/shared/index.d 2.ts +0 -10
  184. package/dist/types/distribute.d.ts +0 -72
  185. package/dist/types/distribute.js +0 -1
  186. package/dist/types 2/errors.d.ts +0 -27
  187. package/dist/types 2/errors.js +0 -34
  188. package/dist/utils/__tests__/errors.test.d.ts +0 -1
  189. package/dist/utils/__tests__/errors.test.js +0 -76
  190. package/dist/utils/airdrop-sweep-types.d.ts +0 -1
  191. package/dist/utils/airdrop-sweep-types.js +0 -1
  192. package/dist/utils/erc20/index.d.ts +0 -242
  193. package/dist/utils/erc20/index.js +0 -645
  194. package/dist/utils/erc20/types.d.ts +0 -77
  195. package/dist/utils/erc20/types.js +0 -1
  196. package/dist/utils/erc20-types.d.ts +0 -1
  197. package/dist/utils/erc20-types.js +0 -1
  198. package/dist/utils/holders-maker/helpers.d.ts +0 -43
  199. package/dist/utils/holders-maker/helpers.js +0 -371
  200. package/dist/utils/holders-maker/index.d.ts +0 -26
  201. package/dist/utils/holders-maker/index.js +0 -218
  202. package/dist/utils/holders-maker/types.d.ts +0 -72
  203. package/dist/utils/holders-maker/types.js +0 -4
  204. package/dist/utils/holders-maker-types.d.ts +0 -1
  205. package/dist/utils/holders-maker-types.js +0 -1
  206. package/dist/utils/lp-inspect/index.d.ts +0 -44
  207. package/dist/utils/lp-inspect/index.js +0 -937
  208. package/dist/utils/lp-inspect/types.d.ts +0 -100
  209. package/dist/utils/lp-inspect/types.js +0 -1
  210. package/dist/utils/lp-inspect-types.d.ts +0 -1
  211. package/dist/utils/lp-inspect-types.js +0 -1
  212. package/dist/utils/private-sale-types.d.ts +0 -1
  213. package/dist/utils/private-sale-types.js +0 -1
  214. package/dist/utils/quote-helpers/index.d.ts +0 -107
  215. package/dist/utils/quote-helpers/index.js +0 -346
  216. package/dist/utils/quote-helpers/types.d.ts +0 -16
  217. package/dist/utils/quote-helpers/types.js +0 -1
  218. package/dist/utils/quote-helpers-types.d.ts +0 -1
  219. package/dist/utils/quote-helpers-types.js +0 -1
  220. /package/dist/{chains/bsc/four/submit/types.js → __tests__/subpath-exports.test.d.ts} +0 -0
@@ -1,218 +0,0 @@
1
- import { Contract, JsonRpcProvider, formatEther, FixedNumber } from 'ethers';
2
- import { PORTAL_ABI } from '../../../abis/flap/portal.js';
3
- import { FLAP_PORTAL_ADDRESSES, FLAP_DEFAULT_FEE_RATES } from '../constants.js';
4
- import { CDPV2 } from '../curve.js';
5
- export class FlapPortal {
6
- constructor(cfg) {
7
- this.rpcUrl = cfg.rpcUrl;
8
- this.portal = cfg.addressOverride ?? FLAP_PORTAL_ADDRESSES[cfg.chain];
9
- // 使用链对应的默认费率,如果用户指定了费率则覆盖
10
- const defaultFees = FLAP_DEFAULT_FEE_RATES[cfg.chain];
11
- this.buyFeeRate = cfg.buyFeeRate ?? defaultFees.buy;
12
- this.sellFeeRate = cfg.sellFeeRate ?? defaultFees.sell;
13
- // 使用 ethers v6 创建只读合约实例
14
- const provider = new JsonRpcProvider(this.rpcUrl);
15
- this.contract = new Contract(this.portal, PORTAL_ABI, provider);
16
- }
17
- async getTokenV2(token) {
18
- const r = await this.contract.getTokenV2(token);
19
- return {
20
- status: r[0], reserve: r[1], circulatingSupply: r[2], price: r[3], tokenVersion: r[4], r: r[5], dexSupplyThresh: r[6],
21
- };
22
- }
23
- async getTokenV3(token) {
24
- const r = await this.contract.getTokenV3(token);
25
- return {
26
- status: r[0], reserve: r[1], circulatingSupply: r[2], price: r[3], tokenVersion: r[4], r: r[5], dexSupplyThresh: r[6], quoteTokenAddress: r[7], nativeToQuoteSwapEnabled: r[8],
27
- };
28
- }
29
- async getTokenV4(token) {
30
- const raw = await this.contract.getTokenV4(token);
31
- return {
32
- status: raw[0],
33
- reserve: raw[1],
34
- circulatingSupply: raw[2],
35
- price: raw[3],
36
- tokenVersion: raw[4],
37
- r: raw[5],
38
- dexSupplyThresh: raw[6],
39
- quoteTokenAddress: raw[7],
40
- nativeToQuoteSwapEnabled: raw[8],
41
- extensionID: raw[9],
42
- };
43
- }
44
- async getTokenV5(token) {
45
- const raw = await this.contract.getTokenV5(token);
46
- return {
47
- status: raw[0],
48
- reserve: raw[1],
49
- circulatingSupply: raw[2],
50
- price: raw[3],
51
- tokenVersion: raw[4],
52
- r: raw[5],
53
- h: raw[6],
54
- k: raw[7],
55
- dexSupplyThresh: raw[8],
56
- quoteTokenAddress: raw[9],
57
- nativeToQuoteSwapEnabled: raw[10],
58
- extensionID: raw[11],
59
- };
60
- }
61
- /**
62
- * 获取代币状态 V7(包含毕业相关信息)
63
- * 注意:仅部分链支持 V7(如 XLayer v5.7+),不支持的链会 revert
64
- */
65
- async getTokenV7(token) {
66
- const raw = await this.contract.getTokenV7(token);
67
- return {
68
- status: raw[0],
69
- reserve: raw[1],
70
- circulatingSupply: raw[2],
71
- price: raw[3],
72
- tokenVersion: raw[4],
73
- r: raw[5],
74
- h: raw[6],
75
- k: raw[7],
76
- dexSupplyThresh: raw[8],
77
- quoteTokenAddress: raw[9],
78
- nativeToQuoteSwapEnabled: raw[10],
79
- extensionID: raw[11],
80
- taxRate: raw[12],
81
- pool: raw[13],
82
- progress: raw[14],
83
- lpFeeProfile: Number(raw[15]),
84
- };
85
- }
86
- /**
87
- * 计算距离毕业还需多少 OKB/ETH(含手续费)
88
- * @param state TokenStateV5 或 TokenStateV7
89
- * @returns 毕业相关信息
90
- */
91
- computeRemainingToGraduation(state) {
92
- const r = Number(formatEther(state.r));
93
- const h = Number(formatEther(state.h));
94
- const k = Number(formatEther(state.k));
95
- const curve = new CDPV2(r, h, k);
96
- const currentReserve = formatEther(state.reserve);
97
- const dexSupplyThresh = formatEther(state.dexSupplyThresh);
98
- const circulatingSupply = formatEther(state.circulatingSupply);
99
- // 计算毕业时的储备
100
- const graduationReserve = curve.estimateReserve(dexSupplyThresh);
101
- const graduationReserveNum = parseFloat(graduationReserve.toString());
102
- const currentReserveNum = parseFloat(currentReserve);
103
- // 是否已毕业 (status == 4 表示 DEX)
104
- const isGraduated = state.status === 4;
105
- // 还需多少(净值)
106
- const remainingNet = Math.max(0, graduationReserveNum - currentReserveNum);
107
- // 含手续费(1% buy fee)
108
- const remainingWithFee = remainingNet / (1 - this.buyFeeRate);
109
- // 计算进度
110
- const progressPercent = isGraduated
111
- ? '100.00'
112
- : (currentReserveNum / graduationReserveNum * 100).toFixed(2);
113
- return {
114
- remainingOkb: remainingWithFee.toFixed(6),
115
- graduationReserve: graduationReserveNum.toFixed(6),
116
- currentReserve: currentReserveNum.toFixed(6),
117
- isGraduated,
118
- progressPercent,
119
- };
120
- }
121
- // 价格/进度
122
- computePriceAndProgress(state) {
123
- // 使用合约返回的实时价格,而不是重新计算
124
- // 合约的 price 字段会在每次买卖后更新,是最准确的实时价格
125
- const price = formatEther(state.price);
126
- // 计算进度(保留4位小数,格式如 "0.5432" 或 "1.0000")
127
- let progress;
128
- const supply = formatEther(state.circulatingSupply);
129
- const dexThresh = formatEther(state.dexSupplyThresh);
130
- const supplyNum = FixedNumber.fromString(supply);
131
- const dexThreshNum = FixedNumber.fromString(dexThresh);
132
- if (supplyNum.gte(dexThreshNum)) {
133
- // 如果已达到或超过 DEX 阈值,进度为 100%
134
- progress = '1.0000';
135
- }
136
- else {
137
- // 使用曲线计算当前和预期的储备量
138
- const curve = new CDPV2(Number(formatEther(state.r)), Number(formatEther(state.h)), Number(formatEther(state.k)));
139
- const currReserve = curve.estimateReserve(supply);
140
- const expectReserve = curve.estimateReserve(dexThresh);
141
- if (expectReserve.isZero() || parseFloat(expectReserve.toString()) <= 0) {
142
- // 如果预期储备量为 0 或负数,进度为 0
143
- progress = '0.0000';
144
- }
145
- else {
146
- // 使用 FixedNumber 进行精度计算,保留 4 位小数
147
- const progressNum = currReserve.div(expectReserve);
148
- progress = parseFloat(progressNum.toString()).toFixed(4);
149
- }
150
- }
151
- return { price, progress };
152
- }
153
- // 示例报价(离线)
154
- quoteBuy(state, inputEth) {
155
- const curve = new CDPV2(Number(formatEther(state.r)), Number(formatEther(state.h)), Number(formatEther(state.k)));
156
- const supply = formatEther(state.circulatingSupply);
157
- const dexThresh = formatEther(state.dexSupplyThresh);
158
- const currReserve = curve.estimateReserve(supply);
159
- const maxReserve = curve.estimateReserve(dexThresh);
160
- // 使用 FixedNumber 进行精度计算
161
- const inputAfterFee = FixedNumber.fromString(inputEth).mul(FixedNumber.fromValue(1 - this.buyFeeRate));
162
- let newReserve;
163
- if (curve.h === 0) {
164
- newReserve = currReserve.add(inputAfterFee);
165
- }
166
- else {
167
- const availableReserve = maxReserve.sub(currReserve);
168
- const actualInput = parseFloat(inputAfterFee.toString()) <= parseFloat(availableReserve.toString())
169
- ? inputAfterFee
170
- : availableReserve;
171
- newReserve = currReserve.add(actualInput);
172
- }
173
- const newSupply = curve.estimateSupply(newReserve.toString());
174
- const outputTokens = newSupply.sub(FixedNumber.fromString(supply));
175
- return outputTokens.toString();
176
- }
177
- quoteSell(state, inputToken) {
178
- const curve = new CDPV2(Number(formatEther(state.r)), Number(formatEther(state.h)), Number(formatEther(state.k)));
179
- const currSupply = FixedNumber.fromString(formatEther(state.circulatingSupply));
180
- const inputAmt = FixedNumber.fromString(inputToken);
181
- // 使用 FixedNumber 进行精度计算
182
- const currReserve = curve.estimateReserve(currSupply.toString());
183
- const newSupply = currSupply.sub(inputAmt);
184
- const newReserve = curve.estimateReserve(newSupply.toString());
185
- const beforeFee = currReserve.sub(newReserve);
186
- const afterFee = beforeFee.mul(FixedNumber.fromValue(1 - this.sellFeeRate));
187
- return afterFee.toString();
188
- }
189
- // 合约链上报价(买入)
190
- async previewBuy(token, ethAmount) {
191
- return await this.contract.previewBuy(token, ethAmount);
192
- }
193
- // 合约链上报价(卖出)
194
- async previewSell(token, tokenAmount) {
195
- return await this.contract.previewSell(token, tokenAmount);
196
- }
197
- // 合约 quote(使用 staticCall 模拟)
198
- async quoteExactInput(params) {
199
- return await this.contract.quoteExactInput.staticCall(params);
200
- }
201
- // 获取平台手续费率
202
- async getFeeRate() {
203
- const result = await this.contract.getFeeRate();
204
- return { buyFeeRate: result[0], sellFeeRate: result[1] };
205
- }
206
- // 获取合约 nonce
207
- async nonce() {
208
- return await this.contract.nonce();
209
- }
210
- // 获取合约版本
211
- async version() {
212
- return await this.contract.version();
213
- }
214
- // 获取代币的锁仓信息
215
- async getLocks(token) {
216
- return await this.contract.getLocks(token);
217
- }
218
- }
@@ -1,227 +0,0 @@
1
- export declare enum TokenStatus {
2
- Invalid = 0,
3
- Tradable = 1,
4
- InDuel = 2,
5
- Killed = 3,
6
- DEX = 4
7
- }
8
- export declare enum TokenVersion {
9
- TOKEN_LEGACY_MINT_NO_PERMIT = 0,
10
- TOKEN_LEGACY_MINT_NO_PERMIT_DUPLICATE = 1,
11
- TOKEN_V2_PERMIT = 2,
12
- TOKEN_GOPLUS = 3,
13
- TOKEN_TAXED = 4
14
- }
15
- export declare enum DexThreshType {
16
- TWO_THIRDS = 0,
17
- FOUR_FIFTHS = 1,
18
- HALF = 2,
19
- _95_PERCENT = 3,
20
- _81_PERCENT = 4,
21
- _1_PERCENT = 5
22
- }
23
- export declare enum MigratorType {
24
- V3_MIGRATOR = 0,
25
- V2_MIGRATOR = 1
26
- }
27
- /**
28
- * V3 LP 费率档位
29
- * 决定代币迁移到 Uniswap V3 或 PancakeSwap V3 时使用的费率
30
- */
31
- export declare enum V3LPFeeProfile {
32
- /** 标准费率: PancakeSwap 0.25%, Uniswap 0.3% */
33
- LP_FEE_PROFILE_STANDARD = 0,
34
- /** 低费率: PancakeSwap 0.01%, Uniswap 0.05% (BNB 链需要白名单) */
35
- LP_FEE_PROFILE_LOW = 1,
36
- /** 高费率: 1% (适用于特殊交易对) */
37
- LP_FEE_PROFILE_HIGH = 2
38
- }
39
- /**
40
- * DEX ID
41
- * 决定代币迁移到哪个 DEX
42
- * - BSC: DEX0 = PancakeSwap
43
- * - xLayer: DEX0 = PotatoSwap
44
- * - Monad: DEX0 = Uniswap, DEX1 = PancakeSwap, DEX2 = Monday
45
- */
46
- export declare enum DEXId {
47
- DEX0 = 0,
48
- DEX1 = 1,
49
- DEX2 = 2
50
- }
51
- export type TokenStateV2 = {
52
- status: number;
53
- reserve: bigint;
54
- circulatingSupply: bigint;
55
- price: bigint;
56
- tokenVersion: number;
57
- r: bigint;
58
- dexSupplyThresh: bigint;
59
- };
60
- export type TokenStateV3 = {
61
- status: number;
62
- reserve: bigint;
63
- circulatingSupply: bigint;
64
- price: bigint;
65
- tokenVersion: number;
66
- r: bigint;
67
- dexSupplyThresh: bigint;
68
- quoteTokenAddress: string;
69
- nativeToQuoteSwapEnabled: boolean;
70
- };
71
- export type TokenStateV4 = {
72
- status: number;
73
- reserve: bigint;
74
- circulatingSupply: bigint;
75
- price: bigint;
76
- tokenVersion: number;
77
- r: bigint;
78
- dexSupplyThresh: bigint;
79
- quoteTokenAddress: string;
80
- nativeToQuoteSwapEnabled: boolean;
81
- extensionID: `0x${string}`;
82
- };
83
- export type TokenStateV5 = {
84
- status: number;
85
- reserve: bigint;
86
- circulatingSupply: bigint;
87
- price: bigint;
88
- tokenVersion: number;
89
- r: bigint;
90
- h: bigint;
91
- k: bigint;
92
- dexSupplyThresh: bigint;
93
- quoteTokenAddress: string;
94
- nativeToQuoteSwapEnabled: boolean;
95
- extensionID: `0x${string}`;
96
- };
97
- /**
98
- * TokenStateV7 - 包含毕业相关信息(pool, progress, lpFeeProfile)
99
- * 用于 XLayer 等支持 V7 的链
100
- */
101
- export type TokenStateV7 = TokenStateV5 & {
102
- taxRate: bigint;
103
- pool: string;
104
- progress: bigint;
105
- lpFeeProfile: number;
106
- };
107
- /**
108
- * 将 lpFeeProfile 转换为 V3 fee 值
109
- */
110
- export declare function lpFeeProfileToV3Fee(profile: number): number;
111
- /**
112
- * Flap Portal 支持的链
113
- */
114
- export type FlapChain = 'BSC' | 'BASE' | 'XLAYER' | 'MORPH' | 'MONAD';
115
- /**
116
- * Flap Portal 配置
117
- */
118
- export type PortalConfig = {
119
- chain: FlapChain;
120
- rpcUrl: string;
121
- addressOverride?: string;
122
- buyFeeRate?: number;
123
- sellFeeRate?: number;
124
- };
125
- export type QuoteExactInputParams = {
126
- inputToken: string;
127
- outputToken: string;
128
- inputAmount: bigint;
129
- };
130
- export type ExactInputParams = {
131
- inputToken: string;
132
- outputToken: string;
133
- inputAmount: bigint;
134
- minOutputAmount: bigint;
135
- permitData?: string;
136
- };
137
- export type ExactInputV3Params = {
138
- inputToken: string;
139
- outputToken: string;
140
- inputAmount: bigint;
141
- minOutputAmount: bigint;
142
- permitData?: string;
143
- extensionData?: string;
144
- };
145
- export type NewTokenV3Params = {
146
- name: string;
147
- symbol: string;
148
- meta: string;
149
- dexThresh: number;
150
- salt: string;
151
- taxRate: number;
152
- migratorType: number;
153
- quoteToken: string;
154
- quoteAmt: bigint;
155
- beneficiary: string;
156
- permitData?: string;
157
- extensionID: string;
158
- extensionData?: string;
159
- };
160
- /**
161
- * newTokenV4 参数
162
- * 相比 V3 新增了 DEX 选择和 LP 费率配置
163
- */
164
- export type NewTokenV4Params = {
165
- name: string;
166
- symbol: string;
167
- meta: string;
168
- dexThresh: number;
169
- salt: string;
170
- taxRate: number;
171
- migratorType: number;
172
- quoteToken: string;
173
- quoteAmt: bigint;
174
- beneficiary: string;
175
- permitData?: string;
176
- extensionID: string;
177
- extensionData?: string;
178
- dexId: number;
179
- lpFeeProfile: number;
180
- };
181
- /**
182
- * newTokenV5 参数
183
- * 相比 V4 新增了 Tax Token V2 高级税收分配功能
184
- * 当 taxRate > 0 时,支持多种税收分配方式:营销、销毁、分红、流动性
185
- */
186
- export type NewTokenV5Params = {
187
- name: string;
188
- symbol: string;
189
- meta: string;
190
- dexThresh: number;
191
- salt: string;
192
- taxRate: number;
193
- migratorType: number;
194
- quoteToken: string;
195
- quoteAmt: bigint;
196
- beneficiary: string;
197
- permitData?: string;
198
- extensionID: string;
199
- extensionData?: string;
200
- dexId: number;
201
- lpFeeProfile: number;
202
- taxDuration: bigint;
203
- antiFarmerDuration: bigint;
204
- mktBps: number;
205
- deflationBps: number;
206
- dividendBps: number;
207
- lpBps: number;
208
- minimumShareBalance: bigint;
209
- };
210
- /**
211
- * 税收分配配置(用于 UI)
212
- * 注意:mktBps + deflationBps + dividendBps + lpBps 必须等于 10000 (100%)
213
- */
214
- export type TaxDistributionConfig = {
215
- mktBps: number;
216
- deflationBps: number;
217
- dividendBps: number;
218
- lpBps: number;
219
- minimumShareBalance?: bigint;
220
- };
221
- /**
222
- * 验证税收分配是否有效
223
- */
224
- export declare function validateTaxDistribution(config: TaxDistributionConfig): {
225
- valid: boolean;
226
- error?: string;
227
- };
@@ -1,80 +0,0 @@
1
- export var TokenStatus;
2
- (function (TokenStatus) {
3
- TokenStatus[TokenStatus["Invalid"] = 0] = "Invalid";
4
- TokenStatus[TokenStatus["Tradable"] = 1] = "Tradable";
5
- TokenStatus[TokenStatus["InDuel"] = 2] = "InDuel";
6
- TokenStatus[TokenStatus["Killed"] = 3] = "Killed";
7
- TokenStatus[TokenStatus["DEX"] = 4] = "DEX";
8
- })(TokenStatus || (TokenStatus = {}));
9
- export var TokenVersion;
10
- (function (TokenVersion) {
11
- TokenVersion[TokenVersion["TOKEN_LEGACY_MINT_NO_PERMIT"] = 0] = "TOKEN_LEGACY_MINT_NO_PERMIT";
12
- TokenVersion[TokenVersion["TOKEN_LEGACY_MINT_NO_PERMIT_DUPLICATE"] = 1] = "TOKEN_LEGACY_MINT_NO_PERMIT_DUPLICATE";
13
- TokenVersion[TokenVersion["TOKEN_V2_PERMIT"] = 2] = "TOKEN_V2_PERMIT";
14
- TokenVersion[TokenVersion["TOKEN_GOPLUS"] = 3] = "TOKEN_GOPLUS";
15
- TokenVersion[TokenVersion["TOKEN_TAXED"] = 4] = "TOKEN_TAXED";
16
- })(TokenVersion || (TokenVersion = {}));
17
- export var DexThreshType;
18
- (function (DexThreshType) {
19
- DexThreshType[DexThreshType["TWO_THIRDS"] = 0] = "TWO_THIRDS";
20
- DexThreshType[DexThreshType["FOUR_FIFTHS"] = 1] = "FOUR_FIFTHS";
21
- DexThreshType[DexThreshType["HALF"] = 2] = "HALF";
22
- DexThreshType[DexThreshType["_95_PERCENT"] = 3] = "_95_PERCENT";
23
- DexThreshType[DexThreshType["_81_PERCENT"] = 4] = "_81_PERCENT";
24
- DexThreshType[DexThreshType["_1_PERCENT"] = 5] = "_1_PERCENT";
25
- })(DexThreshType || (DexThreshType = {}));
26
- export var MigratorType;
27
- (function (MigratorType) {
28
- MigratorType[MigratorType["V3_MIGRATOR"] = 0] = "V3_MIGRATOR";
29
- MigratorType[MigratorType["V2_MIGRATOR"] = 1] = "V2_MIGRATOR";
30
- })(MigratorType || (MigratorType = {}));
31
- /**
32
- * V3 LP 费率档位
33
- * 决定代币迁移到 Uniswap V3 或 PancakeSwap V3 时使用的费率
34
- */
35
- export var V3LPFeeProfile;
36
- (function (V3LPFeeProfile) {
37
- /** 标准费率: PancakeSwap 0.25%, Uniswap 0.3% */
38
- V3LPFeeProfile[V3LPFeeProfile["LP_FEE_PROFILE_STANDARD"] = 0] = "LP_FEE_PROFILE_STANDARD";
39
- /** 低费率: PancakeSwap 0.01%, Uniswap 0.05% (BNB 链需要白名单) */
40
- V3LPFeeProfile[V3LPFeeProfile["LP_FEE_PROFILE_LOW"] = 1] = "LP_FEE_PROFILE_LOW";
41
- /** 高费率: 1% (适用于特殊交易对) */
42
- V3LPFeeProfile[V3LPFeeProfile["LP_FEE_PROFILE_HIGH"] = 2] = "LP_FEE_PROFILE_HIGH";
43
- })(V3LPFeeProfile || (V3LPFeeProfile = {}));
44
- /**
45
- * DEX ID
46
- * 决定代币迁移到哪个 DEX
47
- * - BSC: DEX0 = PancakeSwap
48
- * - xLayer: DEX0 = PotatoSwap
49
- * - Monad: DEX0 = Uniswap, DEX1 = PancakeSwap, DEX2 = Monday
50
- */
51
- export var DEXId;
52
- (function (DEXId) {
53
- DEXId[DEXId["DEX0"] = 0] = "DEX0";
54
- DEXId[DEXId["DEX1"] = 1] = "DEX1";
55
- DEXId[DEXId["DEX2"] = 2] = "DEX2";
56
- })(DEXId || (DEXId = {}));
57
- /**
58
- * 将 lpFeeProfile 转换为 V3 fee 值
59
- */
60
- export function lpFeeProfileToV3Fee(profile) {
61
- switch (profile) {
62
- case V3LPFeeProfile.LP_FEE_PROFILE_STANDARD: return 2500;
63
- case V3LPFeeProfile.LP_FEE_PROFILE_LOW: return 100;
64
- case V3LPFeeProfile.LP_FEE_PROFILE_HIGH: return 10000;
65
- default: return 2500; // 默认 STANDARD
66
- }
67
- }
68
- /**
69
- * 验证税收分配是否有效
70
- */
71
- export function validateTaxDistribution(config) {
72
- const total = config.mktBps + config.deflationBps + config.dividendBps + config.lpBps;
73
- if (total !== 10000) {
74
- return { valid: false, error: `税收分配总计必须为 100%,当前为 ${total / 100}%` };
75
- }
76
- if (config.dividendBps > 0 && (!config.minimumShareBalance || config.minimumShareBalance < 10000n * 10n ** 18n)) {
77
- return { valid: false, error: '启用分红时,最低持仓门槛必须至少为 10,000 个代币' };
78
- }
79
- return { valid: true };
80
- }
@@ -1,121 +0,0 @@
1
- import { FlapPortal } from './portal.js';
2
- import type { PortalConfig, ExactInputParams, ExactInputV3Params, NewTokenV3Params, NewTokenV4Params, NewTokenV5Params } from './types.js';
3
- export declare class FlapPortalWriter extends FlapPortal {
4
- private wallet;
5
- constructor(cfg: PortalConfig, privateKey: string);
6
- buy(token: string, to: string, minAmount: bigint, msgValue: bigint): Promise<any>;
7
- sell(token: string, amount: bigint, minEth: bigint): Promise<any>;
8
- swapExactInput(params: ExactInputParams, msgValue?: bigint): Promise<any>;
9
- swapExactInputBuy(params: ExactInputParams, msgValue?: bigint): Promise<any>;
10
- swapExactInputSell(params: ExactInputParams): Promise<any>;
11
- swapExactInputV3(params: ExactInputV3Params, msgValue?: bigint): Promise<any>;
12
- newTokenV2(args: {
13
- name: string;
14
- symbol: string;
15
- meta: string;
16
- dexThresh: number;
17
- salt: string;
18
- taxRate: number;
19
- migratorType: number;
20
- quoteToken: string;
21
- quoteAmt: bigint;
22
- beneficiary: string;
23
- permitData?: string;
24
- msgValue?: bigint;
25
- }): Promise<any>;
26
- newTokenV3(args: NewTokenV3Params & {
27
- msgValue?: bigint;
28
- }): Promise<any>;
29
- /**
30
- * 创建代币 V4 版本
31
- * 相比 V3 新增了 DEX 选择和 LP 费率配置
32
- *
33
- * @param args 创建代币参数
34
- * @param args.dexId DEX ID,选择迁移到哪个 DEX(使用 DEXId 枚举)
35
- * @param args.lpFeeProfile LP 费率档位(使用 V3LPFeeProfile 枚举)
36
- *
37
- * @example
38
- * ```typescript
39
- * await portal.newTokenV4({
40
- * name: 'My Token',
41
- * symbol: 'MTK',
42
- * meta: 'bafkreicwlkpvrcqg4bbhyp2fnhdwbqos5ghka6gdjra3tdkgxxs74hqsze',
43
- * dexThresh: DexThreshType.FOUR_FIFTHS,
44
- * salt: '0x...',
45
- * taxRate: 0,
46
- * migratorType: MigratorType.V3_MIGRATOR,
47
- * quoteToken: '0x0000000000000000000000000000000000000000',
48
- * quoteAmt: 0n,
49
- * beneficiary: '0x...',
50
- * extensionID: '0x0000000000000000000000000000000000000000000000000000000000000000',
51
- * dexId: DEXId.DEX0,
52
- * lpFeeProfile: V3LPFeeProfile.LP_FEE_PROFILE_STANDARD,
53
- * msgValue: parseEther('0.01'),
54
- * });
55
- * ```
56
- *
57
- * @note BNB 链上使用 LP_FEE_PROFILE_LOW (0.01%) 需要白名单地址
58
- */
59
- newTokenV4(args: NewTokenV4Params & {
60
- msgValue?: bigint;
61
- }): Promise<any>;
62
- /**
63
- * 创建 Token V5(支持 Tax Token V2 高级税收分配)
64
- *
65
- * 当 taxRate > 0 时,支持以下税收分配:
66
- * - mktBps: 营销分配(发送到 beneficiary 地址)
67
- * - deflationBps: 通缩销毁(直接销毁)
68
- * - dividendBps: 持有者分红(发送到分红合约)
69
- * - lpBps: 流动性提供(LP 发送到 dead address)
70
- *
71
- * 注意:mktBps + deflationBps + dividendBps + lpBps 必须等于 10000 (100%)
72
- *
73
- * @example
74
- * ```typescript
75
- * // 创建一个 3% 税率的代币,税收分配:40% 营销,30% 销毁,20% 分红,10% 流动性
76
- * await portal.newTokenV5({
77
- * name: 'My Tax Token',
78
- * symbol: 'MTT',
79
- * meta: 'bafkrei...',
80
- * dexThresh: DexThreshType.FOUR_FIFTHS,
81
- * salt: '0x...',
82
- * taxRate: 300, // 3%
83
- * migratorType: MigratorType.V2_MIGRATOR, // 税代币必须使用 V2 迁移器
84
- * quoteToken: '0x0000000000000000000000000000000000000000',
85
- * quoteAmt: 0n,
86
- * beneficiary: '0x...',
87
- * extensionID: '0x0000000000000000000000000000000000000000000000000000000000000000',
88
- * dexId: DEXId.DEX0,
89
- * lpFeeProfile: V3LPFeeProfile.LP_FEE_PROFILE_STANDARD,
90
- * taxDuration: 365n * 24n * 60n * 60n, // 1 年
91
- * antiFarmerDuration: 60n * 60n, // 1 小时
92
- * mktBps: 4000, // 40%
93
- * deflationBps: 3000, // 30%
94
- * dividendBps: 2000, // 20%
95
- * lpBps: 1000, // 10%
96
- * minimumShareBalance: 10000n * 10n ** 18n, // 10K 代币
97
- * msgValue: parseEther('0.01'),
98
- * });
99
- * ```
100
- *
101
- * @note 税代币(taxRate > 0)必须使用 V2_MIGRATOR
102
- */
103
- newTokenV5(args: NewTokenV5Params & {
104
- msgValue?: bigint;
105
- }): Promise<any>;
106
- claim(token: string): Promise<{
107
- txHash: string;
108
- tokenAmount: bigint;
109
- ethAmount: bigint;
110
- }>;
111
- delegateClaim(token: string): Promise<{
112
- txHash: string;
113
- tokenAmount: bigint;
114
- ethAmount: bigint;
115
- }>;
116
- /**
117
- * 获取当前使用的 Portal 合约地址
118
- * 用于事件监听等场景
119
- */
120
- getContractAddress(): string;
121
- }