@alphafi/alphafi-sdk 0.0.39 → 0.0.41

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 (322) hide show
  1. package/dist/cjs/adminFunctions.d.ts.map +1 -1
  2. package/dist/cjs/adminFunctions.js +9 -1
  3. package/dist/cjs/adminFunctions.js.map +1 -1
  4. package/dist/cjs/common/coins.d.ts.map +1 -1
  5. package/dist/cjs/common/coins.js +18 -0
  6. package/dist/cjs/common/coins.js.map +1 -1
  7. package/dist/cjs/common/constants.d.ts +288 -0
  8. package/dist/cjs/common/constants.d.ts.map +1 -1
  9. package/dist/cjs/common/constants.js +214 -8
  10. package/dist/cjs/common/constants.js.map +1 -1
  11. package/dist/cjs/common/maps.d.ts +1 -0
  12. package/dist/cjs/common/maps.d.ts.map +1 -1
  13. package/dist/cjs/common/maps.js +207 -14
  14. package/dist/cjs/common/maps.js.map +1 -1
  15. package/dist/cjs/common/types.d.ts +58 -5
  16. package/dist/cjs/common/types.d.ts.map +1 -1
  17. package/dist/cjs/common/types.js.map +1 -1
  18. package/dist/cjs/graphql/getMultiReceipts.d.ts.map +1 -1
  19. package/dist/cjs/graphql/getMultiReceipts.js +49 -36
  20. package/dist/cjs/graphql/getMultiReceipts.js.map +1 -1
  21. package/dist/cjs/index.d.ts +5 -9
  22. package/dist/cjs/index.d.ts.map +1 -1
  23. package/dist/cjs/index.js +17 -8
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.d.ts.map +1 -1
  26. package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.js +2 -3
  27. package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.js.map +1 -1
  28. package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.d.ts.map +1 -1
  29. package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.js +6 -12
  30. package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.js.map +1 -1
  31. package/dist/cjs/sui-sdk/functions/getReceipts.d.ts +6 -3
  32. package/dist/cjs/sui-sdk/functions/getReceipts.d.ts.map +1 -1
  33. package/dist/cjs/sui-sdk/functions/getReceipts.js +42 -26
  34. package/dist/cjs/sui-sdk/functions/getReceipts.js.map +1 -1
  35. package/dist/cjs/transactions/7k.d.ts +13 -0
  36. package/dist/cjs/transactions/7k.d.ts.map +1 -0
  37. package/dist/cjs/transactions/7k.js +46 -0
  38. package/dist/cjs/transactions/7k.js.map +1 -0
  39. package/dist/cjs/transactions/alpha.d.ts.map +1 -1
  40. package/dist/cjs/transactions/alpha.js +1 -0
  41. package/dist/cjs/transactions/alpha.js.map +1 -1
  42. package/dist/cjs/transactions/bluefin.d.ts +12 -0
  43. package/dist/cjs/transactions/bluefin.d.ts.map +1 -1
  44. package/dist/cjs/transactions/bluefin.js +937 -91
  45. package/dist/cjs/transactions/bluefin.js.map +1 -1
  46. package/dist/cjs/transactions/cetus.d.ts +0 -3
  47. package/dist/cjs/transactions/cetus.d.ts.map +1 -1
  48. package/dist/cjs/transactions/cetus.js +4 -63
  49. package/dist/cjs/transactions/cetus.js.map +1 -1
  50. package/dist/cjs/transactions/deposit.d.ts +3 -0
  51. package/dist/cjs/transactions/deposit.d.ts.map +1 -1
  52. package/dist/cjs/transactions/deposit.js +77 -1
  53. package/dist/cjs/transactions/deposit.js.map +1 -1
  54. package/dist/cjs/transactions/deposit1.d.ts +1 -0
  55. package/dist/cjs/transactions/deposit1.d.ts.map +1 -0
  56. package/dist/cjs/transactions/deposit1.js +86 -0
  57. package/dist/cjs/transactions/deposit1.js.map +1 -0
  58. package/dist/cjs/transactions/types.d.ts +14 -0
  59. package/dist/cjs/transactions/types.d.ts.map +1 -0
  60. package/dist/cjs/transactions/types.js +3 -0
  61. package/dist/cjs/transactions/types.js.map +1 -0
  62. package/dist/cjs/transactions/withdraw.d.ts.map +1 -1
  63. package/dist/cjs/transactions/withdraw.js +17 -2
  64. package/dist/cjs/transactions/withdraw.js.map +1 -1
  65. package/dist/cjs/transactions/zapDeposit.d.ts +9 -0
  66. package/dist/cjs/transactions/zapDeposit.d.ts.map +1 -1
  67. package/dist/cjs/transactions/zapDeposit.js +1117 -725
  68. package/dist/cjs/transactions/zapDeposit.js.map +1 -1
  69. package/dist/esm/adminFunctions.d.ts.map +1 -1
  70. package/dist/esm/adminFunctions.js +10 -2
  71. package/dist/esm/adminFunctions.js.map +1 -1
  72. package/dist/esm/common/coins.d.ts.map +1 -1
  73. package/dist/esm/common/coins.js +18 -0
  74. package/dist/esm/common/coins.js.map +1 -1
  75. package/dist/esm/common/constants.d.ts +288 -0
  76. package/dist/esm/common/constants.d.ts.map +1 -1
  77. package/dist/esm/common/constants.js +214 -8
  78. package/dist/esm/common/constants.js.map +1 -1
  79. package/dist/esm/common/maps.d.ts +1 -0
  80. package/dist/esm/common/maps.d.ts.map +1 -1
  81. package/dist/esm/common/maps.js +206 -13
  82. package/dist/esm/common/maps.js.map +1 -1
  83. package/dist/esm/common/types.d.ts +58 -5
  84. package/dist/esm/common/types.d.ts.map +1 -1
  85. package/dist/esm/common/types.js.map +1 -1
  86. package/dist/esm/graphql/getMultiReceipts.d.ts.map +1 -1
  87. package/dist/esm/graphql/getMultiReceipts.js +49 -36
  88. package/dist/esm/graphql/getMultiReceipts.js.map +1 -1
  89. package/dist/esm/index.d.ts +5 -9
  90. package/dist/esm/index.d.ts.map +1 -1
  91. package/dist/esm/index.js +5 -9
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.d.ts.map +1 -1
  94. package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.js +2 -3
  95. package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.js.map +1 -1
  96. package/dist/esm/sui-sdk/functions/getPortfolioAmounts.d.ts.map +1 -1
  97. package/dist/esm/sui-sdk/functions/getPortfolioAmounts.js +7 -13
  98. package/dist/esm/sui-sdk/functions/getPortfolioAmounts.js.map +1 -1
  99. package/dist/esm/sui-sdk/functions/getReceipts.d.ts +6 -3
  100. package/dist/esm/sui-sdk/functions/getReceipts.d.ts.map +1 -1
  101. package/dist/esm/sui-sdk/functions/getReceipts.js +43 -26
  102. package/dist/esm/sui-sdk/functions/getReceipts.js.map +1 -1
  103. package/dist/esm/transactions/7k.d.ts +13 -0
  104. package/dist/esm/transactions/7k.d.ts.map +1 -0
  105. package/dist/esm/transactions/7k.js +42 -0
  106. package/dist/esm/transactions/7k.js.map +1 -0
  107. package/dist/esm/transactions/alpha.d.ts.map +1 -1
  108. package/dist/esm/transactions/alpha.js +1 -0
  109. package/dist/esm/transactions/alpha.js.map +1 -1
  110. package/dist/esm/transactions/bluefin.d.ts +12 -0
  111. package/dist/esm/transactions/bluefin.d.ts.map +1 -1
  112. package/dist/esm/transactions/bluefin.js +928 -86
  113. package/dist/esm/transactions/bluefin.js.map +1 -1
  114. package/dist/esm/transactions/cetus.d.ts +0 -3
  115. package/dist/esm/transactions/cetus.d.ts.map +1 -1
  116. package/dist/esm/transactions/cetus.js +2 -57
  117. package/dist/esm/transactions/cetus.js.map +1 -1
  118. package/dist/esm/transactions/deposit.d.ts +3 -0
  119. package/dist/esm/transactions/deposit.d.ts.map +1 -1
  120. package/dist/esm/transactions/deposit.js +74 -2
  121. package/dist/esm/transactions/deposit.js.map +1 -1
  122. package/dist/esm/transactions/deposit1.d.ts +2 -0
  123. package/dist/esm/transactions/deposit1.d.ts.map +1 -0
  124. package/dist/esm/transactions/deposit1.js +86 -0
  125. package/dist/esm/transactions/deposit1.js.map +1 -0
  126. package/dist/esm/transactions/types.d.ts +14 -0
  127. package/dist/esm/transactions/types.d.ts.map +1 -0
  128. package/dist/esm/transactions/types.js +2 -0
  129. package/dist/esm/transactions/types.js.map +1 -0
  130. package/dist/esm/transactions/withdraw.d.ts.map +1 -1
  131. package/dist/esm/transactions/withdraw.js +18 -3
  132. package/dist/esm/transactions/withdraw.js.map +1 -1
  133. package/dist/esm/transactions/zapDeposit.d.ts +9 -1
  134. package/dist/esm/transactions/zapDeposit.d.ts.map +1 -1
  135. package/dist/esm/transactions/zapDeposit.js +1113 -726
  136. package/dist/esm/transactions/zapDeposit.js.map +1 -1
  137. package/docs/assets/highlight.css +78 -0
  138. package/docs/assets/icons.js +18 -0
  139. package/docs/assets/icons.svg +1 -0
  140. package/docs/assets/main.js +60 -0
  141. package/docs/assets/navigation.js +1 -0
  142. package/docs/assets/search.js +1 -0
  143. package/docs/assets/style.css +1493 -0
  144. package/docs/functions/alphaLpBreakdown.html +1 -0
  145. package/docs/functions/cetusLpBreakdown.html +1 -0
  146. package/docs/functions/claimRewardTxb.html +1 -0
  147. package/docs/functions/coinAmountToXTokensDoubleAsset.html +1 -0
  148. package/docs/functions/coinAmountToXTokensSingleAsset.html +1 -0
  149. package/docs/functions/coinsInPool.html +1 -0
  150. package/docs/functions/collectRewards.html +1 -0
  151. package/docs/functions/deposit.html +1 -0
  152. package/docs/functions/depositDoubleAssetTxb.html +1 -0
  153. package/docs/functions/depositSingleAssetTxb.html +1 -0
  154. package/docs/functions/fetchAfterTransactionEvents.html +1 -0
  155. package/docs/functions/fetchAutoCompoundingEvents.html +1 -0
  156. package/docs/functions/fetchAutoCompoundingEventsGql.html +1 -0
  157. package/docs/functions/fetchCetusPools.html +1 -0
  158. package/docs/functions/fetchChainIdentifier.html +1 -0
  159. package/docs/functions/fetchCheckRatioEvents.html +1 -0
  160. package/docs/functions/fetchLiquidityChangeEvents.html +1 -0
  161. package/docs/functions/fetchMultiReceipts.html +1 -0
  162. package/docs/functions/fetchNftHolders.html +1 -0
  163. package/docs/functions/fetchPools.html +1 -0
  164. package/docs/functions/fetchPortfolioData.html +1 -0
  165. package/docs/functions/fetchProtocolData.html +1 -0
  166. package/docs/functions/fetchTVL.html +1 -0
  167. package/docs/functions/fetchUserVaultBalances.html +1 -0
  168. package/docs/functions/fetchUserVaults.html +1 -0
  169. package/docs/functions/fetchUserWalletData.html +1 -0
  170. package/docs/functions/fetchWithdrawV2Events.html +1 -0
  171. package/docs/functions/getAirdropShare.html +1 -0
  172. package/docs/functions/getAllDoubleAssetVaults.html +1 -0
  173. package/docs/functions/getAllSingleAssetVaults.html +1 -0
  174. package/docs/functions/getAllVaultBalances.html +1 -0
  175. package/docs/functions/getAllVaults.html +1 -0
  176. package/docs/functions/getAlphaUnlocks.html +1 -0
  177. package/docs/functions/getAlphaVaultBalance.html +1 -0
  178. package/docs/functions/getAmounts.html +1 -0
  179. package/docs/functions/getApr.html +1 -0
  180. package/docs/functions/getAprs.html +1 -0
  181. package/docs/functions/getApy.html +1 -0
  182. package/docs/functions/getApys.html +1 -0
  183. package/docs/functions/getCetusInvestorTicksMap.html +1 -0
  184. package/docs/functions/getCetusSqrtPriceMap.html +1 -0
  185. package/docs/functions/getCoinAmountsFromLiquidity.html +1 -0
  186. package/docs/functions/getConf.html +1 -0
  187. package/docs/functions/getCurrentTick.html +1 -0
  188. package/docs/functions/getDoubleAssetVaultBalance.html +1 -0
  189. package/docs/functions/getDoubleAssetVaults.html +1 -0
  190. package/docs/functions/getHoldersFromTransactions.html +1 -0
  191. package/docs/functions/getInvestor.html +1 -0
  192. package/docs/functions/getInvestorPoolMap.html +1 -0
  193. package/docs/functions/getLastAutoCompoundTime.html +1 -0
  194. package/docs/functions/getLatestPrices.html +1 -0
  195. package/docs/functions/getLiquidity.html +1 -0
  196. package/docs/functions/getMultiInvestor.html +1 -0
  197. package/docs/functions/getMultiLatestPrices.html +1 -0
  198. package/docs/functions/getMultiParentPool.html +1 -0
  199. package/docs/functions/getMultiPool.html +1 -0
  200. package/docs/functions/getMultiReceipts.html +1 -0
  201. package/docs/functions/getParentPool.html +1 -0
  202. package/docs/functions/getPool.html +1 -0
  203. package/docs/functions/getPoolExchangeRateMap.html +1 -0
  204. package/docs/functions/getPositionRange.html +1 -0
  205. package/docs/functions/getPositionTicks.html +1 -0
  206. package/docs/functions/getPriceToTick.html +1 -0
  207. package/docs/functions/getRebalanceHistories.html +1 -0
  208. package/docs/functions/getRebalanceHistory.html +1 -0
  209. package/docs/functions/getReceipts.html +1 -0
  210. package/docs/functions/getSingleAssetVaultBalance.html +1 -0
  211. package/docs/functions/getSingleAssetVaults.html +1 -0
  212. package/docs/functions/getSuiClient.html +3 -0
  213. package/docs/functions/getSuiNodeUrl.html +3 -0
  214. package/docs/functions/getTVLs.html +1 -0
  215. package/docs/functions/getTickToPrice.html +1 -0
  216. package/docs/functions/getUserTokensFromTransactions.html +1 -0
  217. package/docs/functions/getUserTokensInUsdFromTransactions.html +1 -0
  218. package/docs/functions/getVaultBalance.html +1 -0
  219. package/docs/functions/getVaultBalanceForActiveUsers.html +1 -0
  220. package/docs/functions/getVaults.html +1 -0
  221. package/docs/functions/getXTokenVaultBalanceForActiveUsers.html +1 -0
  222. package/docs/functions/getZapAmounts.html +1 -0
  223. package/docs/functions/lastAutocompoundTime.html +1 -0
  224. package/docs/functions/liquidityToTokens.html +1 -0
  225. package/docs/functions/multiLiquidityToTokens.html +1 -0
  226. package/docs/functions/multiTokensToUsd.html +1 -0
  227. package/docs/functions/multiXTokensToLiquidity.html +1 -0
  228. package/docs/functions/parseUserWalletData.html +1 -0
  229. package/docs/functions/setSuiClient.html +7 -0
  230. package/docs/functions/setSuiNodeUrl.html +5 -0
  231. package/docs/functions/withdraw.html +1 -0
  232. package/docs/functions/withdrawAlphaTxb.html +1 -0
  233. package/docs/functions/withdrawTxb.html +1 -0
  234. package/docs/functions/zapDepositTxb.html +1 -0
  235. package/docs/index.html +76 -0
  236. package/docs/interfaces/Coin.html +12 -0
  237. package/docs/interfaces/CoinPair.html +3 -0
  238. package/docs/interfaces/NaviVoloData.html +3 -0
  239. package/docs/interfaces/RebalanceHistoryType.html +9 -0
  240. package/docs/modules.html +177 -0
  241. package/docs/types/AfterTransactionEventNode.html +1 -0
  242. package/docs/types/Allocator.html +1 -0
  243. package/docs/types/AlphaFiDoubleAssetVault.html +1 -0
  244. package/docs/types/AlphaFiMultiVaultBalance.html +1 -0
  245. package/docs/types/AlphaFiSingleAssetVault.html +1 -0
  246. package/docs/types/AlphaFiVault.html +1 -0
  247. package/docs/types/AlphaFiVaultBalance.html +1 -0
  248. package/docs/types/AlphaPoolType.html +1 -0
  249. package/docs/types/AlphaReceipt.html +1 -0
  250. package/docs/types/AlphaReceiptFields.html +1 -0
  251. package/docs/types/AlphaVaultBalance.html +1 -0
  252. package/docs/types/AutoCompoundingEventNode.html +1 -0
  253. package/docs/types/BluefinInvestor.html +1 -0
  254. package/docs/types/BluefinPoolType.html +1 -0
  255. package/docs/types/BucketInvestor.html +1 -0
  256. package/docs/types/CetusInvestor.html +1 -0
  257. package/docs/types/CetusPoolType.html +1 -0
  258. package/docs/types/CetusSwapOptions.html +1 -0
  259. package/docs/types/CoinAmounts.html +1 -0
  260. package/docs/types/CoinName.html +1 -0
  261. package/docs/types/CoinType.html +1 -0
  262. package/docs/types/CommonInvestorFields.html +1 -0
  263. package/docs/types/CreatePoolOptions.html +1 -0
  264. package/docs/types/Distributor.html +1 -0
  265. package/docs/types/DoubleAssetMultiVaultBalance.html +1 -0
  266. package/docs/types/DoubleAssetPoolNames.html +1 -0
  267. package/docs/types/DoubleAssetTokenHoldings.html +1 -0
  268. package/docs/types/DoubleAssetVaultBalance.html +1 -0
  269. package/docs/types/GetHoldersParams.html +1 -0
  270. package/docs/types/GetTokenHoldingsParams.html +1 -0
  271. package/docs/types/GetUserTokensFromTransactionsParams.html +1 -0
  272. package/docs/types/GetUserTokensInUsdFromTransactionsParams.html +1 -0
  273. package/docs/types/GetVaultBalanceForActiveUsersParams.html +1 -0
  274. package/docs/types/GetVaultBalanceParams.html +1 -0
  275. package/docs/types/HoldingsObj.html +1 -0
  276. package/docs/types/Icon.html +1 -0
  277. package/docs/types/Investor.html +1 -0
  278. package/docs/types/LiquidityChangeEventNode.html +1 -0
  279. package/docs/types/LiquidityToTokensParams.html +1 -0
  280. package/docs/types/LiquidityToUsdParams.html +1 -0
  281. package/docs/types/LoopingDebt.html +1 -0
  282. package/docs/types/LpBreakdownType.html +1 -0
  283. package/docs/types/MemberPoolDataType.html +1 -0
  284. package/docs/types/MemberType.html +1 -0
  285. package/docs/types/MultiGetVaultBalancesParams.html +1 -0
  286. package/docs/types/NaviInvestor.html +1 -0
  287. package/docs/types/OtherReceiptFields.html +1 -0
  288. package/docs/types/PoolName.html +1 -0
  289. package/docs/types/PoolReceipt.html +1 -0
  290. package/docs/types/PoolType.html +1 -0
  291. package/docs/types/Receipt.html +1 -0
  292. package/docs/types/ReceiptGQL.html +1 -0
  293. package/docs/types/SingleAssetMultiVaultBalance.html +1 -0
  294. package/docs/types/SingleAssetPoolNames.html +1 -0
  295. package/docs/types/SingleAssetTokenHoldings.html +1 -0
  296. package/docs/types/SingleAssetVaultBalance.html +1 -0
  297. package/docs/types/SingleGetVaultBalancesParams.html +1 -0
  298. package/docs/types/StrategyType.html +1 -0
  299. package/docs/types/SuiNetwork.html +1 -0
  300. package/docs/types/SwapOptions.html +1 -0
  301. package/docs/types/TickSpacing.html +1 -0
  302. package/docs/types/TotalWeightType.html +1 -0
  303. package/docs/types/TransactionBlockType.html +1 -0
  304. package/docs/types/UserPoolLiquidity.html +1 -0
  305. package/docs/types/UserPoolTokenHoldings.html +1 -0
  306. package/docs/types/UserUsdHoldings.html +1 -0
  307. package/docs/types/VaultBalance.html +1 -0
  308. package/docs/types/WithdrawV2EventNode.html +1 -0
  309. package/docs/variables/bluefinPoolMap.html +1 -0
  310. package/docs/variables/cetusPoolMap.html +1 -0
  311. package/docs/variables/coinsList.html +1 -0
  312. package/docs/variables/defunctPoolsSet.html +1 -0
  313. package/docs/variables/doubleAssetPoolCoinMap.html +1 -0
  314. package/docs/variables/ignoredWalletsForDailyRevenue.html +1 -0
  315. package/docs/variables/loopingAccountAddresses.html +1 -0
  316. package/docs/variables/loopingPoolCoinMap.html +1 -0
  317. package/docs/variables/naviAssetMap.html +1 -0
  318. package/docs/variables/poolIdPoolNameMap.html +1 -0
  319. package/docs/variables/poolInfo.html +1 -0
  320. package/docs/variables/singleAssetPoolCoinMap.html +1 -0
  321. package/docs/variables/stableCoins.html +1 -0
  322. package/package.json +2 -1
@@ -1,730 +1,1117 @@
1
- // import {
2
- // Transaction,
3
- // TransactionObjectArgument,
4
- // } from "@mysten/sui/transactions";
5
- // import { CoinStruct } from "@mysten/sui/client";
6
- // import { coinsList } from "../common/coins.js";
7
- // import {
8
- // cetusPoolMap,
9
- // doubleAssetPoolCoinMap,
10
- // poolInfo,
11
- // } from "../common/maps.js";
12
- // import { CoinName, PoolName, Receipt, SwapOptions } from "../common/types.js";
13
- // import { getReceipts } from "../sui-sdk/functions/getReceipts.js";
14
- // import { getConf } from "../common/constants.js";
15
- // import { getSuiClient } from "../sui-sdk/client.js";
16
- // import BN from "bn.js";
17
- // import { PythPriceIdPair } from "../common/pyth.js";
18
- // import { getLatestPrices } from "../utils/prices.js";
19
- // import { getAmounts } from "./cetus.js";
20
- export {};
21
- // export async function zapDepositTxb(
22
- // inputCoinName: CoinName,
23
- // inputCoinAmount: number,
1
+ import { Transaction, } from "@mysten/sui/transactions";
2
+ import BN from "bn.js";
3
+ import { getSuiClient } from "../sui-sdk/client.js";
4
+ import { bluefinPoolMap, cetusPoolMap, doubleAssetPoolCoinMap, poolInfo, } from "../common/maps.js";
5
+ import { coinsList } from "../common/coins.js";
6
+ import { getAmounts } from "./deposit.js";
7
+ import { SevenKGateway } from "./7k.js";
8
+ import { getConf } from "../common/constants.js";
9
+ import { getReceipts } from "../sui-sdk/functions/getReceipts.js";
10
+ import { getLatestPrices } from "../utils/prices.js";
11
+ export async function zapDepositTxb(inputCoinName, inputCoinAmount, poolName, slippage, // 0.01 --> 1%, 0.001 --> 0.1%
12
+ options) {
13
+ let txb = new Transaction();
14
+ const suiClient = getSuiClient();
15
+ const address = options.address;
16
+ const coinTypeA = doubleAssetPoolCoinMap[poolName].coin1;
17
+ const coinTypeB = doubleAssetPoolCoinMap[poolName].coin2;
18
+ const swapObjectA = coinsList[coinTypeA];
19
+ const swapObjectB = coinsList[coinTypeB];
20
+ const inputObject = coinsList[inputCoinName];
21
+ let coin1, coin2;
22
+ const amounts = await getAmounts(poolName, true, "100000001");
23
+ if (amounts) {
24
+ const amount1 = Number(amounts[0]);
25
+ const amount2 = Number(amounts[1]);
26
+ const swapGateway = new SevenKGateway();
27
+ const swapOptions = {
28
+ pair: {
29
+ coinA: swapObjectA,
30
+ coinB: swapObjectB,
31
+ },
32
+ senderAddress: address,
33
+ inAmount: new BN(amount1),
34
+ slippage: slippage,
35
+ };
36
+ const ratioQuote = await swapGateway.getQuote(swapOptions);
37
+ if (ratioQuote) {
38
+ const amount1InCoinType2 = Number(ratioQuote.returnAmountWithDecimal);
39
+ const totalAmount = amount2 + amount1InCoinType2;
40
+ const inputAmountToType1 = Math.floor((inputCoinAmount * amount1InCoinType2) / totalAmount);
41
+ const inputAmountToType2 = Math.floor((inputCoinAmount * amount2) / totalAmount);
42
+ let amountA, amountB;
43
+ const swapOptionsI2A = {
44
+ pair: {
45
+ coinA: inputObject,
46
+ coinB: swapObjectA,
47
+ },
48
+ senderAddress: address,
49
+ inAmount: new BN(inputAmountToType1),
50
+ slippage: slippage,
51
+ };
52
+ const swapOptionsI2B = {
53
+ pair: {
54
+ coinA: inputObject,
55
+ coinB: swapObjectB,
56
+ },
57
+ senderAddress: address,
58
+ inAmount: new BN(inputAmountToType2),
59
+ slippage: slippage,
60
+ };
61
+ if (inputCoinName === coinTypeA) {
62
+ const quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
63
+ if (quoteResponse) {
64
+ amountB = quoteResponse.returnAmountWithDecimal;
65
+ const result = await swapGateway.getTransactionBlock(swapOptionsI2B, quoteResponse, txb);
66
+ txb = result.tx;
67
+ if (result.coinOut) {
68
+ coin2 = result.coinOut;
69
+ }
70
+ }
71
+ amountA = inputAmountToType1.toString();
72
+ if (coinTypeA === "SUI") {
73
+ [coin1] = txb.splitCoins(txb.gas, [amountA]);
74
+ }
75
+ else {
76
+ let currentCursor = null;
77
+ let coins1 = [];
78
+ do {
79
+ const response = await suiClient.getCoins({
80
+ owner: address,
81
+ coinType: coinsList[coinTypeA].type,
82
+ cursor: currentCursor,
83
+ });
84
+ coins1 = coins1.concat(response.data);
85
+ if (response.hasNextPage && response.nextCursor) {
86
+ currentCursor = response.nextCursor;
87
+ }
88
+ else
89
+ break;
90
+ } while (true);
91
+ [coin1] = txb.splitCoins(txb.object(coins1[0].coinObjectId), [0]);
92
+ txb.mergeCoins(coin1, coins1.map((c) => c.coinObjectId));
93
+ }
94
+ }
95
+ else if (inputCoinName === coinTypeB) {
96
+ const quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
97
+ if (quoteResponse) {
98
+ amountA = quoteResponse.returnAmountWithDecimal;
99
+ const result = await swapGateway.getTransactionBlock(swapOptionsI2A, quoteResponse, txb);
100
+ txb = result.tx;
101
+ if (result.coinOut) {
102
+ coin1 = result.coinOut;
103
+ }
104
+ }
105
+ amountB = inputAmountToType2.toString();
106
+ if (coinTypeB === "SUI") {
107
+ [coin2] = txb.splitCoins(txb.gas, [amountB]);
108
+ }
109
+ else {
110
+ let currentCursor = null;
111
+ let coins2 = [];
112
+ do {
113
+ const response = await suiClient.getCoins({
114
+ owner: address,
115
+ coinType: coinsList[coinTypeB].type,
116
+ cursor: currentCursor,
117
+ });
118
+ coins2 = coins2.concat(response.data);
119
+ if (response.hasNextPage && response.nextCursor) {
120
+ currentCursor = response.nextCursor;
121
+ }
122
+ else
123
+ break;
124
+ } while (true);
125
+ [coin2] = txb.splitCoins(txb.object(coins2[0].coinObjectId), [0]);
126
+ txb.mergeCoins(coin2, coins2.map((c) => c.coinObjectId));
127
+ }
128
+ }
129
+ else {
130
+ let quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
131
+ if (quoteResponse) {
132
+ amountA = quoteResponse.returnAmountWithDecimal;
133
+ const result = await swapGateway.getTransactionBlock(swapOptionsI2A, quoteResponse, txb);
134
+ txb = result.tx;
135
+ if (result.coinOut) {
136
+ coin1 = result.coinOut;
137
+ }
138
+ }
139
+ quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
140
+ if (quoteResponse) {
141
+ amountB = quoteResponse.returnAmountWithDecimal;
142
+ const result = await swapGateway.getTransactionBlock(swapOptionsI2B, quoteResponse, txb);
143
+ txb = result.tx;
144
+ if (result.coinOut) {
145
+ coin2 = result.coinOut;
146
+ }
147
+ }
148
+ }
149
+ if (amountA && amountB) {
150
+ if (coin1 && coin2) {
151
+ // fee charge
152
+ const fee_address = getConf().FEE_ADDRESS;
153
+ const feePercentage = 0.05;
154
+ const amountAFee = ((Number(amountA) * feePercentage) / 100).toFixed(0);
155
+ const amountBFee = ((Number(amountB) * feePercentage) / 100).toFixed(0);
156
+ const [feeCoinA] = txb.splitCoins(coin1, [amountAFee]);
157
+ const [feeCoinB] = txb.splitCoins(coin2, [amountBFee]);
158
+ txb.transferObjects([feeCoinA, feeCoinB], fee_address);
159
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
160
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
161
+ if (poolInfo[poolName].parentProtocolName === "CETUS") {
162
+ if (pool1 === "CETUS" && pool2 === "SUI") {
163
+ txb = await depositCetusSuiTxb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
164
+ }
165
+ else if (pool2 === "SUI") {
166
+ txb = await depositCetusAlphaSuiTxb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
167
+ }
168
+ else {
169
+ txb = await depositCetus(amountA, amountB, poolName, { address }, txb, coin1, coin2);
170
+ }
171
+ }
172
+ else if (poolInfo[poolName].parentProtocolName === "BLUEFIN") {
173
+ if (poolName === "BLUEFIN-NAVX-VSUI" ||
174
+ poolName === "BLUEFIN-ALPHA-USDC" ||
175
+ poolName === "BLUEFIN-BLUE-USDC") {
176
+ txb = await depositBluefinType2Txb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
177
+ }
178
+ else if (pool1 === "SUI") {
179
+ txb = await depositBluefinSuiFirstTxb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
180
+ }
181
+ else if (pool2 === "SUI") {
182
+ txb = await depositBluefinSuiSecondTxb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
183
+ }
184
+ else if (pool1 === "STSUI") {
185
+ txb = await depositBluefinStsuiTxb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
186
+ }
187
+ else {
188
+ txb = await depositBluefinType1Txb(amountA, amountB, poolName, { address }, txb, coin1, coin2);
189
+ }
190
+ }
191
+ }
192
+ }
193
+ txb.setGasBudget(100000000);
194
+ return txb;
195
+ }
196
+ }
197
+ return undefined;
198
+ }
199
+ const depositCetus = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
200
+ const address = options.address;
201
+ let txb;
202
+ if (transaction)
203
+ txb = transaction;
204
+ else
205
+ txb = new Transaction();
206
+ poolName = poolName.toUpperCase();
207
+ const poolinfo = poolInfo[poolName];
208
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
209
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
210
+ const receipt = await getReceipts(poolName, address, true);
211
+ amountA = (Number(amountA) * 0.999).toString();
212
+ amountB = (Number(amountB) * 0.999).toString();
213
+ let amounts = await getAmounts(poolName, true, amountA);
214
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
215
+ amounts = await getAmounts(poolName, false, amountB);
216
+ }
217
+ if (amounts && coin1Arg !== undefined && coin2Arg !== undefined) {
218
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
219
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
220
+ let someReceipt;
221
+ if (receipt.length == 0) {
222
+ [someReceipt] = txb.moveCall({
223
+ target: `0x1::option::none`,
224
+ typeArguments: [poolInfo[poolName].receiptType],
225
+ arguments: [],
226
+ });
227
+ }
228
+ else {
229
+ [someReceipt] = txb.moveCall({
230
+ target: `0x1::option::some`,
231
+ typeArguments: [receipt[0].content.type],
232
+ arguments: [txb.object(receipt[0].objectId)],
233
+ });
234
+ }
235
+ if (poolName == "WUSDC-WBTC" ||
236
+ poolName == "USDC-USDT" ||
237
+ poolName == "USDC-WUSDC" ||
238
+ poolName == "USDC-ETH") {
239
+ txb.moveCall({
240
+ target: `${getConf().ALPHA_LATEST_PACKAGE_ID}::alphafi_cetus_pool_base_a::user_deposit`,
241
+ typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
242
+ arguments: [
243
+ txb.object(getConf().VERSION),
244
+ someReceipt,
245
+ txb.object(poolinfo.poolId),
246
+ depositCoinA,
247
+ depositCoinB,
248
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
249
+ txb.object(poolinfo.investorId),
250
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
251
+ txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
252
+ txb.object(cetusPoolMap[`${pool1}-SUI`]),
253
+ txb.object(cetusPoolMap["CETUS-SUI"]),
254
+ txb.object(cetusPoolMap[poolName]),
255
+ txb.object(getConf().CLOCK_PACKAGE_ID),
256
+ ],
257
+ });
258
+ }
259
+ else {
260
+ txb.moveCall({
261
+ target: `${getConf().ALPHA_LATEST_PACKAGE_ID}::alphafi_cetus_pool::user_deposit`,
262
+ typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
263
+ arguments: [
264
+ txb.object(getConf().VERSION),
265
+ someReceipt,
266
+ txb.object(poolinfo.poolId),
267
+ depositCoinA,
268
+ depositCoinB,
269
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
270
+ txb.object(poolinfo.investorId),
271
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
272
+ txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
273
+ txb.object(cetusPoolMap[`${pool2}-SUI`]),
274
+ txb.object(cetusPoolMap["CETUS-SUI"]),
275
+ txb.object(cetusPoolMap[poolName]),
276
+ txb.object(getConf().CLOCK_PACKAGE_ID),
277
+ ],
278
+ });
279
+ }
280
+ txb.transferObjects([coin1Arg, coin2Arg], address);
281
+ }
282
+ else {
283
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
284
+ }
285
+ return txb;
286
+ };
287
+ const depositCetusAlphaSuiTxb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
288
+ const address = options.address;
289
+ let txb;
290
+ if (transaction)
291
+ txb = transaction;
292
+ else
293
+ txb = new Transaction();
294
+ poolName = poolName.toUpperCase();
295
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
296
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
297
+ const receipt = await getReceipts(poolName, address, true);
298
+ amountA = (Number(amountA) * 0.999).toString();
299
+ amountB = (Number(amountB) * 0.999).toString();
300
+ let amounts = await getAmounts(poolName, true, amountA);
301
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
302
+ amounts = await getAmounts(poolName, false, amountB);
303
+ }
304
+ if (amounts && coin1Arg != undefined && coin2Arg !== undefined) {
305
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
306
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
307
+ const poolinfo = poolInfo[poolName];
308
+ let someReceipt;
309
+ if (receipt.length == 0) {
310
+ [someReceipt] = txb.moveCall({
311
+ target: `0x1::option::none`,
312
+ typeArguments: [poolinfo.receiptType],
313
+ arguments: [],
314
+ });
315
+ }
316
+ else {
317
+ [someReceipt] = txb.moveCall({
318
+ target: `0x1::option::some`,
319
+ typeArguments: [receipt[0].content.type],
320
+ arguments: [txb.object(receipt[0].objectId)],
321
+ });
322
+ }
323
+ txb.moveCall({
324
+ target: `${getConf().ALPHA_LATEST_PACKAGE_ID}::alphafi_cetus_sui_pool::user_deposit`,
325
+ typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
326
+ arguments: [
327
+ txb.object(getConf().VERSION),
328
+ someReceipt,
329
+ txb.object(poolinfo.poolId),
330
+ depositCoinA,
331
+ depositCoinB,
332
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
333
+ txb.object(poolinfo.investorId),
334
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
335
+ txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
336
+ txb.object(cetusPoolMap["CETUS-SUI"]),
337
+ txb.object(poolinfo.parentPoolId),
338
+ txb.object(getConf().CLOCK_PACKAGE_ID),
339
+ ],
340
+ });
341
+ txb.transferObjects([coin1Arg, coin2Arg], address);
342
+ }
343
+ else {
344
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
345
+ }
346
+ return txb;
347
+ };
348
+ const depositCetusSuiTxb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
349
+ const address = options.address;
350
+ let txb;
351
+ if (transaction)
352
+ txb = transaction;
353
+ else
354
+ txb = new Transaction();
355
+ poolName = poolName.toUpperCase();
356
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
357
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
358
+ const receipt = await getReceipts(poolName, address, true);
359
+ amountA = (Number(amountA) * 0.999).toString();
360
+ amountB = (Number(amountB) * 0.999).toString();
361
+ let amounts = await getAmounts(poolName, true, amountA);
362
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
363
+ amounts = await getAmounts(poolName, false, amountB);
364
+ }
365
+ if (amounts && coin1Arg && coin2Arg) {
366
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
367
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
368
+ const poolinfo = poolInfo[poolName];
369
+ let someReceipt;
370
+ if (receipt.length == 0) {
371
+ [someReceipt] = txb.moveCall({
372
+ target: `0x1::option::none`,
373
+ typeArguments: [poolinfo.receiptType],
374
+ arguments: [],
375
+ });
376
+ }
377
+ else {
378
+ [someReceipt] = txb.moveCall({
379
+ target: `0x1::option::some`,
380
+ typeArguments: [receipt[0].content.type],
381
+ arguments: [txb.object(receipt[0].objectId)],
382
+ });
383
+ }
384
+ txb.moveCall({
385
+ target: `${poolinfo.packageId}::alphafi_cetus_sui_pool::user_deposit`,
386
+ typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
387
+ arguments: [
388
+ txb.object(getConf().ALPHA_2_VERSION),
389
+ txb.object(getConf().VERSION),
390
+ someReceipt,
391
+ txb.object(poolinfo.poolId),
392
+ depositCoinA,
393
+ depositCoinB,
394
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
395
+ txb.object(poolinfo.investorId),
396
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
397
+ txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
398
+ txb.object(cetusPoolMap[poolName]),
399
+ txb.object(getConf().CLOCK_PACKAGE_ID),
400
+ ],
401
+ });
402
+ txb.transferObjects([coin1Arg, coin2Arg], address);
403
+ }
404
+ else {
405
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
406
+ }
407
+ return txb;
408
+ };
409
+ const depositBluefinSuiFirstTxb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
410
+ const address = options.address;
411
+ let txb;
412
+ if (transaction)
413
+ txb = transaction;
414
+ else
415
+ txb = new Transaction();
416
+ poolName = poolName.toUpperCase();
417
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
418
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
419
+ const receipt = await getReceipts(poolName, address, true);
420
+ amountA = (Number(amountA) * 0.999).toString();
421
+ amountB = (Number(amountB) * 0.999).toString();
422
+ let amounts = await getAmounts(poolName, true, amountA);
423
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
424
+ amounts = await getAmounts(poolName, false, amountB);
425
+ }
426
+ if (amounts && coin1Arg && coin2Arg) {
427
+ const [depositCoinA] = txb.splitCoins(txb.gas, [amounts[0]]);
428
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
429
+ const poolinfo = poolInfo[poolName];
430
+ let someReceipt;
431
+ if (receipt.length == 0) {
432
+ [someReceipt] = txb.moveCall({
433
+ target: `0x1::option::none`,
434
+ typeArguments: [poolinfo.receiptType],
435
+ arguments: [],
436
+ });
437
+ }
438
+ else {
439
+ [someReceipt] = txb.moveCall({
440
+ target: `0x1::option::some`,
441
+ typeArguments: [receipt[0].content.type],
442
+ arguments: [txb.object(receipt[0].objectId)],
443
+ });
444
+ }
445
+ if (poolName === "BLUEFIN-SUI-USDC") {
446
+ txb.moveCall({
447
+ target: `${poolinfo.packageId}::alphafi_bluefin_sui_first_pool::user_deposit`,
448
+ typeArguments: [
449
+ coinsList[pool1].type,
450
+ coinsList[pool2].type,
451
+ coinsList["BLUE"].type,
452
+ coinsList["SUI"].type,
453
+ ],
454
+ arguments: [
455
+ txb.object(getConf().ALPHA_4_VERSION),
456
+ txb.object(getConf().VERSION),
457
+ someReceipt,
458
+ txb.object(poolinfo.poolId),
459
+ depositCoinA,
460
+ depositCoinB,
461
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
462
+ txb.object(poolinfo.investorId),
463
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
464
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
465
+ txb.object(getConf().BLUEFIN_SUI_USDC_POOL),
466
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
467
+ txb.object(cetusPoolMap["USDC-SUI"]),
468
+ txb.object(getConf().CLOCK_PACKAGE_ID),
469
+ ],
470
+ });
471
+ }
472
+ else if (poolName === "BLUEFIN-SUI-BUCK") {
473
+ txb.moveCall({
474
+ target: `${poolinfo.packageId}::alphafi_bluefin_sui_first_pool::user_deposit`,
475
+ typeArguments: [
476
+ coinsList[pool1].type,
477
+ coinsList[pool2].type,
478
+ coinsList["BLUE"].type,
479
+ coinsList["SUI"].type,
480
+ ],
481
+ arguments: [
482
+ txb.object(getConf().ALPHA_4_VERSION),
483
+ txb.object(getConf().VERSION),
484
+ someReceipt,
485
+ txb.object(poolinfo.poolId),
486
+ depositCoinA,
487
+ depositCoinB,
488
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
489
+ txb.object(poolinfo.investorId),
490
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
491
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
492
+ txb.object(getConf().BLUEFIN_SUI_BUCK_POOL),
493
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
494
+ txb.object(cetusPoolMap["BUCK-SUI"]),
495
+ txb.object(getConf().CLOCK_PACKAGE_ID),
496
+ ],
497
+ });
498
+ }
499
+ else if (poolName === "BLUEFIN-SUI-AUSD") {
500
+ txb.moveCall({
501
+ target: `${poolinfo.packageId}::alphafi_bluefin_sui_first_pool::user_deposit`,
502
+ typeArguments: [
503
+ coinsList[pool1].type,
504
+ coinsList[pool2].type,
505
+ coinsList["BLUE"].type,
506
+ coinsList["SUI"].type,
507
+ ],
508
+ arguments: [
509
+ txb.object(getConf().ALPHA_4_VERSION),
510
+ txb.object(getConf().VERSION),
511
+ someReceipt,
512
+ txb.object(poolinfo.poolId),
513
+ depositCoinA,
514
+ depositCoinB,
515
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
516
+ txb.object(poolinfo.investorId),
517
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
518
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
519
+ txb.object(getConf().BLUEFIN_SUI_AUSD_POOL),
520
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
521
+ txb.object(cetusPoolMap["AUSD-SUI"]),
522
+ txb.object(getConf().CLOCK_PACKAGE_ID),
523
+ ],
524
+ });
525
+ }
526
+ txb.transferObjects([coin1Arg, coin2Arg], address);
527
+ }
528
+ else {
529
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
530
+ }
531
+ return txb;
532
+ };
533
+ const depositBluefinType1Txb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
534
+ const address = options.address;
535
+ let txb;
536
+ if (transaction)
537
+ txb = transaction;
538
+ else
539
+ txb = new Transaction();
540
+ poolName = poolName.toUpperCase();
541
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
542
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
543
+ const receipt = await getReceipts(poolName, address, true);
544
+ amountA = (Number(amountA) * 0.999).toString();
545
+ amountB = (Number(amountB) * 0.999).toString();
546
+ let amounts = await getAmounts(poolName, true, amountA);
547
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
548
+ amounts = await getAmounts(poolName, false, amountB);
549
+ }
550
+ if (amounts && coin1Arg && coin2Arg) {
551
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
552
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
553
+ const poolinfo = poolInfo[poolName];
554
+ let someReceipt;
555
+ if (receipt.length == 0) {
556
+ [someReceipt] = txb.moveCall({
557
+ target: `0x1::option::none`,
558
+ typeArguments: [poolinfo.receiptType],
559
+ arguments: [],
560
+ });
561
+ }
562
+ else {
563
+ [someReceipt] = txb.moveCall({
564
+ target: `0x1::option::some`,
565
+ typeArguments: [receipt[0].content.type],
566
+ arguments: [txb.object(receipt[0].objectId)],
567
+ });
568
+ }
569
+ if (poolName === "BLUEFIN-USDT-USDC") {
570
+ txb.moveCall({
571
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_1_pool::user_deposit`,
572
+ typeArguments: [
573
+ coinsList[pool1].type,
574
+ coinsList[pool2].type,
575
+ coinsList["BLUE"].type,
576
+ coinsList["SUI"].type,
577
+ ],
578
+ arguments: [
579
+ txb.object(getConf().ALPHA_4_VERSION),
580
+ txb.object(getConf().VERSION),
581
+ someReceipt,
582
+ txb.object(poolinfo.poolId),
583
+ depositCoinA,
584
+ depositCoinB,
585
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
586
+ txb.object(poolinfo.investorId),
587
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
588
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
589
+ txb.object(getConf().BLUEFIN_USDT_USDC_POOL),
590
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
591
+ txb.object(cetusPoolMap["USDC-USDT"]),
592
+ txb.object(cetusPoolMap["USDC-SUI"]),
593
+ txb.object(getConf().CLOCK_PACKAGE_ID),
594
+ ],
595
+ });
596
+ }
597
+ else if (poolName === "BLUEFIN-AUSD-USDC") {
598
+ txb.moveCall({
599
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_1_pool::user_deposit`,
600
+ typeArguments: [
601
+ coinsList[pool1].type,
602
+ coinsList[pool2].type,
603
+ coinsList["BLUE"].type,
604
+ coinsList["SUI"].type,
605
+ ],
606
+ arguments: [
607
+ txb.object(getConf().ALPHA_4_VERSION),
608
+ txb.object(getConf().VERSION),
609
+ someReceipt,
610
+ txb.object(poolinfo.poolId),
611
+ depositCoinA,
612
+ depositCoinB,
613
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
614
+ txb.object(poolinfo.investorId),
615
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
616
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
617
+ txb.object(getConf().BLUEFIN_AUSD_USDC_POOL),
618
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
619
+ txb.object(cetusPoolMap["USDC-AUSD"]),
620
+ txb.object(cetusPoolMap["USDC-SUI"]),
621
+ txb.object(getConf().CLOCK_PACKAGE_ID),
622
+ ],
623
+ });
624
+ }
625
+ else if (poolName === "BLUEFIN-WBTC-USDC") {
626
+ txb.moveCall({
627
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_1_pool::user_deposit`,
628
+ typeArguments: [
629
+ coinsList[pool1].type,
630
+ coinsList[pool2].type,
631
+ coinsList["BLUE"].type,
632
+ coinsList["SUI"].type,
633
+ ],
634
+ arguments: [
635
+ txb.object(getConf().ALPHA_4_VERSION),
636
+ txb.object(getConf().VERSION),
637
+ someReceipt,
638
+ txb.object(poolinfo.poolId),
639
+ depositCoinA,
640
+ depositCoinB,
641
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
642
+ txb.object(poolinfo.investorId),
643
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
644
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
645
+ txb.object(getConf().BLUEFIN_WBTC_USDC_POOL),
646
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
647
+ txb.object(cetusPoolMap["USDC-WBTC"]),
648
+ txb.object(cetusPoolMap["USDC-SUI"]),
649
+ txb.object(getConf().CLOCK_PACKAGE_ID),
650
+ ],
651
+ });
652
+ }
653
+ else if (poolName === "BLUEFIN-SEND-USDC") {
654
+ txb.moveCall({
655
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_1_pool::user_deposit`,
656
+ typeArguments: [
657
+ coinsList[pool1].type,
658
+ coinsList[pool2].type,
659
+ coinsList["BLUE"].type,
660
+ coinsList["SUI"].type,
661
+ ],
662
+ arguments: [
663
+ txb.object(getConf().ALPHA_4_VERSION),
664
+ txb.object(getConf().VERSION),
665
+ someReceipt,
666
+ txb.object(poolinfo.poolId),
667
+ depositCoinA,
668
+ depositCoinB,
669
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
670
+ txb.object(poolinfo.investorId),
671
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
672
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
673
+ txb.object(getConf().BLUEFIN_SEND_USDC_POOL),
674
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
675
+ txb.object(cetusPoolMap["USDC-SEND"]),
676
+ txb.object(cetusPoolMap["USDC-SUI"]),
677
+ txb.object(getConf().CLOCK_PACKAGE_ID),
678
+ ],
679
+ });
680
+ }
681
+ txb.transferObjects([coin1Arg, coin2Arg], address);
682
+ }
683
+ else {
684
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
685
+ }
686
+ return txb;
687
+ };
688
+ const depositBluefinType2Txb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
689
+ const address = options.address;
690
+ let txb;
691
+ if (transaction)
692
+ txb = transaction;
693
+ else
694
+ txb = new Transaction();
695
+ poolName = poolName.toUpperCase();
696
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
697
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
698
+ const receipt = await getReceipts(poolName, address, true);
699
+ amountA = (Number(amountA) * 0.999).toString();
700
+ amountB = (Number(amountB) * 0.999).toString();
701
+ let amounts = await getAmounts(poolName, true, amountA);
702
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
703
+ amounts = await getAmounts(poolName, false, amountB);
704
+ }
705
+ if (amounts && coin1Arg && coin2Arg) {
706
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
707
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
708
+ const poolinfo = poolInfo[poolName];
709
+ let someReceipt;
710
+ if (receipt.length == 0) {
711
+ [someReceipt] = txb.moveCall({
712
+ target: `0x1::option::none`,
713
+ typeArguments: [poolinfo.receiptType],
714
+ arguments: [],
715
+ });
716
+ }
717
+ else {
718
+ [someReceipt] = txb.moveCall({
719
+ target: `0x1::option::some`,
720
+ typeArguments: [receipt[0].content.type],
721
+ arguments: [txb.object(receipt[0].objectId)],
722
+ });
723
+ }
724
+ if (poolName === "BLUEFIN-ALPHA-USDC") {
725
+ txb.moveCall({
726
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_2_pool::user_deposit`,
727
+ typeArguments: [
728
+ coinsList[pool1].type,
729
+ coinsList[pool2].type,
730
+ coinsList["BLUE"].type,
731
+ coinsList["SUI"].type,
732
+ ],
733
+ arguments: [
734
+ txb.object(getConf().ALPHA_4_VERSION),
735
+ txb.object(getConf().VERSION),
736
+ someReceipt,
737
+ txb.object(poolinfo.poolId),
738
+ depositCoinA,
739
+ depositCoinB,
740
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
741
+ txb.object(poolinfo.investorId),
742
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
743
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
744
+ txb.object(getConf().BLUEFIN_ALPHA_USDC_POOL),
745
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
746
+ txb.object(cetusPoolMap["ALPHA-USDC"]),
747
+ txb.object(cetusPoolMap["USDC-SUI"]),
748
+ txb.object(getConf().CLOCK_PACKAGE_ID),
749
+ ],
750
+ });
751
+ }
752
+ else if (poolName === "BLUEFIN-NAVX-VSUI") {
753
+ txb.moveCall({
754
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_2_pool::user_deposit`,
755
+ typeArguments: [
756
+ coinsList[pool1].type,
757
+ coinsList[pool2].type,
758
+ coinsList["BLUE"].type,
759
+ coinsList["SUI"].type,
760
+ ],
761
+ arguments: [
762
+ txb.object(getConf().ALPHA_4_VERSION),
763
+ txb.object(getConf().VERSION),
764
+ someReceipt,
765
+ txb.object(poolinfo.poolId),
766
+ depositCoinA,
767
+ depositCoinB,
768
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
769
+ txb.object(poolinfo.investorId),
770
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
771
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
772
+ txb.object(getConf().BLUEFIN_NAVX_VSUI_POOL),
773
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
774
+ txb.object(cetusPoolMap["NAVX-VSUI"]),
775
+ txb.object(cetusPoolMap["VSUI-SUI"]),
776
+ txb.object(getConf().CLOCK_PACKAGE_ID),
777
+ ],
778
+ });
779
+ }
780
+ else if (poolName === "BLUEFIN-BLUE-USDC") {
781
+ txb.moveCall({
782
+ target: `${poolinfo.packageId}::alphafi_bluefin_type_2_pool::user_deposit`,
783
+ typeArguments: [
784
+ coinsList[pool1].type,
785
+ coinsList[pool2].type,
786
+ coinsList["DEEP"].type,
787
+ coinsList["SUI"].type,
788
+ ],
789
+ arguments: [
790
+ txb.object(getConf().ALPHA_4_VERSION),
791
+ txb.object(getConf().VERSION),
792
+ someReceipt,
793
+ txb.object(poolinfo.poolId),
794
+ depositCoinA,
795
+ depositCoinB,
796
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
797
+ txb.object(poolinfo.investorId),
798
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
799
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
800
+ txb.object(getConf().BLUEFIN_BLUE_USDC_POOL),
801
+ txb.object(getConf().BLUEFIN_DEEP_SUI_POOL),
802
+ txb.object(cetusPoolMap["BLUE-USDC"]),
803
+ txb.object(cetusPoolMap["USDC-SUI"]),
804
+ txb.object(getConf().CLOCK_PACKAGE_ID),
805
+ ],
806
+ });
807
+ }
808
+ txb.transferObjects([coin1Arg, coin2Arg], address);
809
+ }
810
+ else {
811
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
812
+ }
813
+ return txb;
814
+ };
815
+ const depositBluefinSuiSecondTxb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
816
+ const address = options.address;
817
+ let txb;
818
+ if (transaction)
819
+ txb = transaction;
820
+ else
821
+ txb = new Transaction();
822
+ poolName = poolName.toUpperCase();
823
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
824
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
825
+ const receipt = await getReceipts(poolName, address, true);
826
+ amountA = (Number(amountA) * 0.999).toString();
827
+ amountB = (Number(amountB) * 0.999).toString();
828
+ let amounts = await getAmounts(poolName, true, amountA);
829
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
830
+ amounts = await getAmounts(poolName, false, amountB);
831
+ }
832
+ if (amounts && coin1Arg && coin2Arg) {
833
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
834
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
835
+ const poolinfo = poolInfo[poolName];
836
+ let someReceipt;
837
+ if (receipt.length == 0) {
838
+ [someReceipt] = txb.moveCall({
839
+ target: `0x1::option::none`,
840
+ typeArguments: [poolinfo.receiptType],
841
+ arguments: [],
842
+ });
843
+ }
844
+ else {
845
+ [someReceipt] = txb.moveCall({
846
+ target: `0x1::option::some`,
847
+ typeArguments: [receipt[0].content.type],
848
+ arguments: [txb.object(receipt[0].objectId)],
849
+ });
850
+ }
851
+ if (poolName === "BLUEFIN-BLUE-SUI") {
852
+ txb.moveCall({
853
+ target: `${poolinfo.packageId}::alphafi_bluefin_sui_second_pool::user_deposit`,
854
+ typeArguments: [
855
+ coinsList[pool1].type,
856
+ coinsList[pool2].type,
857
+ coinsList["DEEP"].type,
858
+ coinsList["SUI"].type,
859
+ ],
860
+ arguments: [
861
+ txb.object(getConf().ALPHA_4_VERSION),
862
+ txb.object(getConf().VERSION),
863
+ someReceipt,
864
+ txb.object(poolinfo.poolId),
865
+ depositCoinA,
866
+ depositCoinB,
867
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
868
+ txb.object(poolinfo.investorId),
869
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
870
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
871
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL),
872
+ txb.object(getConf().BLUEFIN_DEEP_SUI_POOL),
873
+ txb.object(cetusPoolMap["BLUE-SUI"]),
874
+ txb.object(getConf().CLOCK_PACKAGE_ID),
875
+ ],
876
+ });
877
+ }
878
+ else if (poolName === "BLUEFIN-WBTC-SUI") {
879
+ txb.moveCall({
880
+ target: `${poolinfo.packageId}::alphafi_bluefin_sui_second_pool::user_deposit`,
881
+ typeArguments: [
882
+ coinsList[pool1].type,
883
+ coinsList[pool2].type,
884
+ coinsList["BLUE"].type,
885
+ coinsList["SUI"].type,
886
+ ],
887
+ arguments: [
888
+ txb.object(getConf().ALPHA_4_VERSION),
889
+ txb.object(getConf().VERSION),
890
+ someReceipt,
891
+ txb.object(poolinfo.poolId),
892
+ depositCoinA,
893
+ depositCoinB,
894
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
895
+ txb.object(poolinfo.investorId),
896
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
897
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
898
+ txb.object(getConf().BLUEFIN_WBTC_SUI_POOL),
899
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL),
900
+ txb.object(cetusPoolMap["WBTC-SUI"]),
901
+ txb.object(getConf().CLOCK_PACKAGE_ID),
902
+ ],
903
+ });
904
+ }
905
+ else if (poolName === "BLUEFIN-DEEP-SUI") {
906
+ txb.moveCall({
907
+ target: `${poolinfo.packageId}::alphafi_bluefin_sui_second_pool::user_deposit`,
908
+ typeArguments: [
909
+ coinsList[pool1].type,
910
+ coinsList[pool2].type,
911
+ coinsList["BLUE"].type,
912
+ coinsList["SUI"].type,
913
+ ],
914
+ arguments: [
915
+ txb.object(getConf().ALPHA_4_VERSION),
916
+ txb.object(getConf().VERSION),
917
+ someReceipt,
918
+ txb.object(poolinfo.poolId),
919
+ depositCoinA,
920
+ depositCoinB,
921
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
922
+ txb.object(poolinfo.investorId),
923
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
924
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
925
+ txb.object(getConf().BLUEFIN_DEEP_SUI_POOL),
926
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL),
927
+ txb.object(cetusPoolMap["DEEP-SUI"]),
928
+ txb.object(getConf().CLOCK_PACKAGE_ID),
929
+ ],
930
+ });
931
+ }
932
+ txb.transferObjects([coin1Arg, coin2Arg], address);
933
+ }
934
+ else {
935
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
936
+ }
937
+ return txb;
938
+ };
939
+ const depositBluefinStsuiTxb = async (amountA, amountB, poolName, options, transaction = undefined, coin1Arg, coin2Arg) => {
940
+ const address = options.address;
941
+ let txb;
942
+ if (transaction)
943
+ txb = transaction;
944
+ else
945
+ txb = new Transaction();
946
+ poolName = poolName.toUpperCase();
947
+ const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
948
+ const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
949
+ const receipt = await getReceipts(poolName, address, true);
950
+ amountA = (Number(amountA) * 0.999).toString();
951
+ amountB = (Number(amountB) * 0.999).toString();
952
+ let amounts = await getAmounts(poolName, true, amountA);
953
+ if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
954
+ amounts = await getAmounts(poolName, false, amountB);
955
+ }
956
+ if (amounts && coin1Arg && coin2Arg) {
957
+ const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
958
+ const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
959
+ const poolinfo = poolInfo[poolName];
960
+ let someReceipt;
961
+ if (receipt.length == 0) {
962
+ [someReceipt] = txb.moveCall({
963
+ target: `0x1::option::none`,
964
+ typeArguments: [poolinfo.receiptType],
965
+ arguments: [],
966
+ });
967
+ }
968
+ else {
969
+ [someReceipt] = txb.moveCall({
970
+ target: `0x1::option::some`,
971
+ typeArguments: [receipt[0].content.type],
972
+ arguments: [txb.object(receipt[0].objectId)],
973
+ });
974
+ }
975
+ if (poolName === "BLUEFIN-STSUI-USDC") {
976
+ txb.moveCall({
977
+ target: `${poolinfo.packageId}::alphafi_bluefin_stsui_first_pool::user_deposit`,
978
+ typeArguments: [
979
+ coinsList[pool1].type,
980
+ coinsList[pool2].type,
981
+ coinsList["BLUE"].type,
982
+ ],
983
+ arguments: [
984
+ txb.object(getConf().ALPHA_STSUI_VERSION),
985
+ txb.object(getConf().VERSION),
986
+ someReceipt,
987
+ txb.object(poolinfo.poolId),
988
+ depositCoinA,
989
+ depositCoinB,
990
+ txb.object(getConf().ALPHA_DISTRIBUTOR),
991
+ txb.object(poolinfo.investorId),
992
+ txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
993
+ txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
994
+ txb.object(getConf().BLUEFIN_STSUI_USDC_POOL),
995
+ txb.object(getConf().BLUEFIN_BLUE_SUI_POOL_AUTOCOMPOUND),
996
+ txb.object(cetusPoolMap["USDC-SUI"]),
997
+ txb.object(bluefinPoolMap["SUI-USDC"]),
998
+ txb.object(getConf().LST_INFO),
999
+ txb.object(getConf().SUI_SYSTEM_STATE),
1000
+ txb.pure.bool(true),
1001
+ txb.object(getConf().CLOCK_PACKAGE_ID),
1002
+ ],
1003
+ });
1004
+ }
1005
+ txb.transferObjects([coin1Arg, coin2Arg], address);
1006
+ }
1007
+ else {
1008
+ throw new Error(`No ${pool1} or ${pool2} Coins`);
1009
+ }
1010
+ return txb;
1011
+ };
1012
+ export async function getZapAmounts(inputCoinAmount, inputCoinName, poolName, slippage, options, ignoreCache) {
1013
+ const address = options.address;
1014
+ const coinTypeA = doubleAssetPoolCoinMap[poolName].coin1;
1015
+ const coinTypeB = doubleAssetPoolCoinMap[poolName].coin2;
1016
+ const swapObjectA = coinsList[coinTypeA];
1017
+ const swapObjectB = coinsList[coinTypeB];
1018
+ const inputObject = coinsList[inputCoinName];
1019
+ const amounts = await getAmounts(poolName, true, "100000001");
1020
+ if (amounts) {
1021
+ const amount1 = Number(amounts[0]);
1022
+ const amount2 = Number(amounts[1]);
1023
+ const swapGateway = new SevenKGateway();
1024
+ const swapOptions = {
1025
+ pair: {
1026
+ coinA: swapObjectA,
1027
+ coinB: swapObjectB,
1028
+ },
1029
+ senderAddress: address,
1030
+ inAmount: new BN(amount1),
1031
+ slippage: slippage,
1032
+ };
1033
+ const ratioQuote = await swapGateway.getQuote(swapOptions);
1034
+ if (ratioQuote) {
1035
+ const amount1InCoinType2 = Number(ratioQuote.returnAmountWithDecimal);
1036
+ const totalAmount = amount2 + amount1InCoinType2;
1037
+ const inputAmountToType1 = Math.floor((inputCoinAmount * amount1InCoinType2) / totalAmount);
1038
+ const inputAmountToType2 = Math.floor((inputCoinAmount * amount2) / totalAmount);
1039
+ let amountA, amountB;
1040
+ const swapOptionsI2A = {
1041
+ pair: {
1042
+ coinA: inputObject,
1043
+ coinB: swapObjectA,
1044
+ },
1045
+ senderAddress: address,
1046
+ inAmount: new BN(inputAmountToType1),
1047
+ slippage: slippage,
1048
+ };
1049
+ const swapOptionsI2B = {
1050
+ pair: {
1051
+ coinA: inputObject,
1052
+ coinB: swapObjectB,
1053
+ },
1054
+ senderAddress: address,
1055
+ inAmount: new BN(inputAmountToType2),
1056
+ slippage: slippage,
1057
+ };
1058
+ if (inputCoinName === coinTypeA) {
1059
+ const quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
1060
+ if (quoteResponse) {
1061
+ amountB = quoteResponse.returnAmountWithDecimal;
1062
+ }
1063
+ amountA = inputAmountToType1.toString();
1064
+ }
1065
+ else if (inputCoinName === coinTypeB) {
1066
+ const quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
1067
+ if (quoteResponse) {
1068
+ amountA = quoteResponse.returnAmountWithDecimal;
1069
+ }
1070
+ amountB = inputAmountToType2.toString();
1071
+ }
1072
+ else {
1073
+ let quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
1074
+ if (quoteResponse) {
1075
+ amountA = quoteResponse.returnAmountWithDecimal;
1076
+ }
1077
+ quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
1078
+ if (quoteResponse) {
1079
+ amountB = quoteResponse.returnAmountWithDecimal;
1080
+ }
1081
+ }
1082
+ if (amountA && amountB) {
1083
+ const [coin1Price, coin2Price] = await getLatestPrices([
1084
+ `${swapObjectA.name}/USD`,
1085
+ `${swapObjectB.name}/USD`,
1086
+ ], ignoreCache);
1087
+ const coin1InUSD = Number(amountA) * Number(coin1Price);
1088
+ const coin2InUSD = Number(amountB) * Number(coin2Price);
1089
+ return [
1090
+ amountA.toString(),
1091
+ coin1InUSD.toString(),
1092
+ amountB.toString(),
1093
+ coin2InUSD.toString(),
1094
+ ];
1095
+ }
1096
+ }
1097
+ }
1098
+ }
1099
+ // export async function zapWithdraw(
1100
+ // amount: string,
24
1101
  // poolName: PoolName,
25
- // slippage: number, // 0.01 --> 1%, 0.001 --> 0.1%
26
- // options: { address: string },
27
- // ): Promise<Transaction | undefined> {
28
- // let txb = new Transaction();
29
- // const suiClient = getSuiClient();
1102
+ // outputCoinName: string,
1103
+ // options: { suiClient: SuiClient; address: string },
1104
+ // ) {
1105
+ // const suiClient = options.suiClient;
30
1106
  // const address = options.address;
31
- // const coinTypeA = doubleAssetPoolCoinMap[poolName].coin1;
32
- // const coinTypeB = doubleAssetPoolCoinMap[poolName].coin2;
33
- // const swapObjectA = coinsList[coinTypeA];
34
- // const swapObjectB = coinsList[coinTypeB];
35
- // const inputObject = coinsList[inputCoinName];
36
- // let coin1, coin2;
37
- // const amounts = await getAmounts(poolName, true, "100000001");
38
- // if (amounts) {
39
- // const amount1 = Number(amounts[0]);
40
- // const amount2 = Number(amounts[1]);
41
- // const swapGateway = new SevenKGateway();
42
- // const swapOptions: SwapOptions = {
43
- // pair: {
44
- // coinA: swapObjectA,
45
- // coinB: swapObjectB,
46
- // },
47
- // senderAddress: address,
48
- // inAmount: new BN(amount1),
49
- // slippage: slippage,
50
- // };
51
- // const ratioQuote = await swapGateway.getQuote(swapOptions);
52
- // if (ratioQuote) {
53
- // const amount1InCoinType2 = Number(ratioQuote.returnAmountWithDecimal);
54
- // const totalAmount = amount2 + amount1InCoinType2;
55
- // const inputAmountToType1 = Math.floor(
56
- // (inputCoinAmount * amount1InCoinType2) / totalAmount,
57
- // );
58
- // const inputAmountToType2 = Math.floor(
59
- // (inputCoinAmount * amount2) / totalAmount,
60
- // );
61
- // let amountA, amountB;
62
- // const swapOptionsI2A = {
63
- // pair: {
64
- // coinA: inputObject,
65
- // coinB: swapObjectA,
66
- // },
67
- // senderAddress: address,
68
- // inAmount: new BN(inputAmountToType1),
69
- // slippage: slippage,
70
- // };
71
- // const swapOptionsI2B = {
72
- // pair: {
73
- // coinA: inputObject,
74
- // coinB: swapObjectB,
75
- // },
76
- // senderAddress: address,
77
- // inAmount: new BN(inputAmountToType2),
78
- // slippage: slippage,
79
- // };
80
- // if (inputCoinName === coinTypeA) {
81
- // const quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
82
- // if (quoteResponse) {
83
- // amountB = quoteResponse.returnAmountWithDecimal;
84
- // const result = await swapGateway.getTransactionBlock(
85
- // swapOptionsI2B,
86
- // quoteResponse,
87
- // txb,
88
- // );
89
- // txb = result.tx;
90
- // if (result.coinOut) {
91
- // coin2 = result.coinOut;
92
- // }
93
- // }
94
- // amountA = inputAmountToType1.toString();
95
- // if (coinTypeA === "SUI") {
96
- // [coin1] = txb.splitCoins(txb.gas, [amountA]);
97
- // } else {
98
- // let currentCursor: string | null | undefined = null;
99
- // let coins1: CoinStruct[] = [];
100
- // do {
101
- // const response = await suiClient.getCoins({
102
- // owner: address,
103
- // coinType: coinsList[coinTypeA].type,
104
- // cursor: currentCursor,
105
- // });
106
- // coins1 = coins1.concat(response.data);
107
- // if (response.hasNextPage && response.nextCursor) {
108
- // currentCursor = response.nextCursor;
109
- // } else break;
110
- // } while (true);
111
- // [coin1] = txb.splitCoins(txb.object(coins1[0].coinObjectId), [0]);
112
- // txb.mergeCoins(
113
- // coin1,
114
- // coins1.map((c) => c.coinObjectId),
115
- // );
116
- // }
117
- // } else if (inputCoinName === coinTypeB) {
118
- // const quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
119
- // if (quoteResponse) {
120
- // amountA = quoteResponse.returnAmountWithDecimal;
121
- // const result = await swapGateway.getTransactionBlock(
122
- // swapOptionsI2A,
123
- // quoteResponse,
124
- // txb,
125
- // );
126
- // txb = result.tx;
127
- // if (result.coinOut) {
128
- // coin1 = result.coinOut;
129
- // }
130
- // }
131
- // amountB = inputAmountToType2.toString();
132
- // if (coinTypeB === "SUI") {
133
- // [coin2] = txb.splitCoins(txb.gas, [amountB]);
134
- // } else {
135
- // let currentCursor: string | null | undefined = null;
136
- // let coins2: CoinStruct[] = [];
137
- // do {
138
- // const response = await suiClient.getCoins({
139
- // owner: address,
140
- // coinType: coinsList[coinTypeB].type,
141
- // cursor: currentCursor,
142
- // });
143
- // coins2 = coins2.concat(response.data);
144
- // if (response.hasNextPage && response.nextCursor) {
145
- // currentCursor = response.nextCursor;
146
- // } else break;
147
- // } while (true);
148
- // [coin2] = txb.splitCoins(txb.object(coins2[0].coinObjectId), [0]);
149
- // txb.mergeCoins(
150
- // coin2,
151
- // coins2.map((c) => c.coinObjectId),
152
- // );
153
- // }
154
- // } else {
155
- // let quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
156
- // if (quoteResponse) {
157
- // amountA = quoteResponse.returnAmountWithDecimal;
158
- // const result = await swapGateway.getTransactionBlock(
159
- // swapOptionsI2A,
160
- // quoteResponse,
161
- // txb,
162
- // );
163
- // txb = result.tx;
164
- // if (result.coinOut) {
165
- // coin1 = result.coinOut;
166
- // }
167
- // }
168
- // quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
169
- // if (quoteResponse) {
170
- // amountB = quoteResponse.returnAmountWithDecimal;
171
- // const result = await swapGateway.getTransactionBlock(
172
- // swapOptionsI2B,
173
- // quoteResponse,
174
- // txb,
175
- // );
176
- // txb = result.tx;
177
- // if (result.coinOut) {
178
- // coin2 = result.coinOut;
179
- // }
180
- // }
181
- // }
182
- // if (amountA && amountB) {
183
- // if (coin1 && coin2) {
184
- // // fee charge
185
- // const fee_address = getConf().FEE_ADDRESS;
186
- // const feePercentage = 0.05;
187
- // const amountAFee = ((Number(amountA) * feePercentage) / 100).toFixed(
188
- // 0,
189
- // );
190
- // const amountBFee = ((Number(amountB) * feePercentage) / 100).toFixed(
191
- // 0,
192
- // );
193
- // const [feeCoinA] = txb.splitCoins(coin1, [amountAFee]);
194
- // const [feeCoinB] = txb.splitCoins(coin2, [amountBFee]);
195
- // txb.transferObjects([feeCoinA, feeCoinB], fee_address);
196
- // if (
197
- // poolName === "ALPHA-SUI" ||
198
- // poolName === "WUSDC-SUI" ||
199
- // poolName === "NAVX-SUI" ||
200
- // poolName === "USDC-SUI" ||
201
- // poolName === "BUCK-SUI" ||
202
- // poolName === "DEEP-SUI" ||
203
- // poolName === "FUD-SUI"
204
- // ) {
205
- // txb = await depositCetusAlphaSuiTxb(
206
- // amountA,
207
- // amountB,
208
- // poolName,
209
- // { address },
210
- // txb,
211
- // coin1,
212
- // coin2,
213
- // );
214
- // } else if (poolName === "CETUS-SUI") {
215
- // txb = await depositCetusSuiTxb(
216
- // amountA,
217
- // amountB,
218
- // poolName,
219
- // { address },
220
- // txb,
221
- // coin1,
222
- // coin2,
223
- // );
224
- // } else if (poolName === "BLUEFIN-SUI-USDC") {
225
- // txb = await depositBluefinSuiFirstTxb(
226
- // amountA,
227
- // amountB,
228
- // poolName,
229
- // { address },
230
- // txb,
231
- // coin1,
232
- // coin2,
233
- // );
234
- // } else if (poolName === "BLUEFIN-USDT-USDC") {
235
- // txb = await depositBluefinType1Txb(
236
- // amountA,
237
- // amountB,
238
- // poolName,
239
- // { address },
240
- // txb,
241
- // coin1,
242
- // coin2,
243
- // );
244
- // } else {
245
- // txb = await depositCetus(
246
- // amountA,
247
- // amountB,
248
- // poolName,
249
- // { address },
250
- // txb,
251
- // coin1,
252
- // coin2,
253
- // );
254
- // }
255
- // }
256
- // }
257
- // txb.setGasBudget(100000000);
258
- // return txb;
259
- // }
260
- // }
261
- // return undefined;
262
- // }
263
- // const depositCetus = async (
264
- // amountA: string,
265
- // amountB: string,
266
- // poolName: PoolName,
267
- // options: { address: string },
268
- // transaction: Transaction | undefined = undefined,
269
- // coin1Arg: TransactionObjectArgument | undefined,
270
- // coin2Arg: TransactionObjectArgument | undefined,
271
- // ): Promise<Transaction> => {
272
- // const address = options.address;
273
- // let txb;
274
- // if (transaction) txb = transaction;
275
- // else txb = new Transaction();
276
- // poolName = poolName.toUpperCase() as PoolName;
277
- // const poolinfo = poolInfo[poolName];
278
- // const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
279
- // const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
280
- // const receipt: Receipt[] = await getReceipts(poolName, address, true);
281
- // amountA = (Number(amountA) * 0.999).toString();
282
- // amountB = (Number(amountB) * 0.999).toString();
283
- // let amounts = await getAmounts(poolName, true, amountA);
284
- // if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
285
- // amounts = await getAmounts(poolName, false, amountB);
286
- // }
287
- // if (amounts && coin1Arg !== undefined && coin2Arg !== undefined) {
288
- // const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
289
- // const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
290
- // let someReceipt: any;
291
- // if (receipt.length == 0) {
292
- // [someReceipt] = txb.moveCall({
293
- // target: `0x1::option::none`,
294
- // typeArguments: [poolInfo[poolName].receiptType],
295
- // arguments: [],
296
- // });
297
- // } else {
298
- // [someReceipt] = txb.moveCall({
299
- // target: `0x1::option::some`,
300
- // typeArguments: [receipt[0].content.type],
301
- // arguments: [txb.object(receipt[0].objectId)],
302
- // });
303
- // }
304
- // if (
305
- // poolName == "WUSDC-WBTC" ||
306
- // poolName == "USDC-USDT" ||
307
- // poolName == "USDC-WUSDC" ||
308
- // poolName == "USDC-ETH"
309
- // ) {
310
- // txb.moveCall({
311
- // target: `${getConf().ALPHA_LATEST_PACKAGE_ID}::alphafi_cetus_pool_base_a::user_deposit`,
312
- // typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
313
- // arguments: [
314
- // txb.object(getConf().VERSION),
315
- // someReceipt,
316
- // txb.object(poolinfo.poolId),
317
- // depositCoinA,
318
- // depositCoinB,
319
- // txb.object(getConf().ALPHA_DISTRIBUTOR),
320
- // txb.object(poolinfo.investorId),
321
- // txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
322
- // txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
323
- // txb.object(cetusPoolMap[`${pool1}-SUI`]),
324
- // txb.object(cetusPoolMap["CETUS-SUI"]),
325
- // txb.object(cetusPoolMap[poolName]),
326
- // txb.object(getConf().CLOCK_PACKAGE_ID),
327
- // ],
328
- // });
329
- // } else {
330
- // txb.moveCall({
331
- // target: `${getConf().ALPHA_LATEST_PACKAGE_ID}::alphafi_cetus_pool::user_deposit`,
332
- // typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
333
- // arguments: [
334
- // txb.object(getConf().VERSION),
335
- // someReceipt,
336
- // txb.object(poolinfo.poolId),
337
- // depositCoinA,
338
- // depositCoinB,
339
- // txb.object(getConf().ALPHA_DISTRIBUTOR),
340
- // txb.object(poolinfo.investorId),
341
- // txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
342
- // txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
343
- // txb.object(cetusPoolMap[`${pool2}-SUI`]),
344
- // txb.object(cetusPoolMap["CETUS-SUI"]),
345
- // txb.object(cetusPoolMap[poolName]),
346
- // txb.object(getConf().CLOCK_PACKAGE_ID),
347
- // ],
348
- // });
349
- // }
350
- // txb.transferObjects([coin1Arg, coin2Arg], address);
351
- // } else {
352
- // throw new Error(`No ${pool1} or ${pool2} Coins`);
353
- // }
354
- // return txb;
355
- // };
356
- // const depositCetusAlphaSuiTxb = async (
357
- // amountA: string,
358
- // amountB: string,
359
- // poolName: PoolName,
360
- // options: { address: string },
361
- // transaction: Transaction | undefined = undefined,
362
- // coin1Arg: TransactionObjectArgument | undefined,
363
- // coin2Arg: TransactionObjectArgument | undefined,
364
- // ): Promise<Transaction> => {
365
- // const address = options.address;
366
- // let txb;
367
- // if (transaction) txb = transaction;
368
- // else txb = new Transaction();
369
- // poolName = poolName.toUpperCase() as PoolName;
370
- // const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
371
- // const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
372
- // const receipt: Receipt[] = await getReceipts(poolName, address, true);
373
- // amountA = (Number(amountA) * 0.999).toString();
374
- // amountB = (Number(amountB) * 0.999).toString();
375
- // let amounts = await getAmounts(poolName, true, amountA);
376
- // if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
377
- // amounts = await getAmounts(poolName, false, amountB);
378
- // }
379
- // if (amounts && coin1Arg != undefined && coin2Arg !== undefined) {
380
- // const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
381
- // const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
382
- // const poolinfo = poolInfo[poolName];
383
- // let someReceipt: any;
384
- // if (receipt.length == 0) {
385
- // [someReceipt] = txb.moveCall({
386
- // target: `0x1::option::none`,
387
- // typeArguments: [poolinfo.receiptType],
388
- // arguments: [],
389
- // });
390
- // } else {
391
- // [someReceipt] = txb.moveCall({
392
- // target: `0x1::option::some`,
393
- // typeArguments: [receipt[0].content.type],
394
- // arguments: [txb.object(receipt[0].objectId)],
395
- // });
396
- // }
397
- // txb.moveCall({
398
- // target: `${getConf().ALPHA_LATEST_PACKAGE_ID}::alphafi_cetus_sui_pool::user_deposit`,
399
- // typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
400
- // arguments: [
401
- // txb.object(getConf().VERSION),
402
- // someReceipt,
403
- // txb.object(poolinfo.poolId),
404
- // depositCoinA,
405
- // depositCoinB,
406
- // txb.object(getConf().ALPHA_DISTRIBUTOR),
407
- // txb.object(poolinfo.investorId),
408
- // txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
409
- // txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
410
- // txb.object(cetusPoolMap["CETUS-SUI"]),
411
- // txb.object(poolinfo.parentPoolId),
412
- // txb.object(getConf().CLOCK_PACKAGE_ID),
413
- // ],
414
- // });
415
- // txb.transferObjects([coin1Arg, coin2Arg], address);
416
- // } else {
417
- // throw new Error(`No ${pool1} or ${pool2} Coins`);
418
- // }
419
- // return txb;
420
- // };
421
- // const depositCetusSuiTxb = async (
422
- // amountA: string,
423
- // amountB: string,
424
- // poolName: PoolName,
425
- // options: { address: string },
426
- // transaction: Transaction | undefined = undefined,
427
- // coin1Arg: TransactionObjectArgument | undefined,
428
- // coin2Arg: TransactionObjectArgument | undefined,
429
- // ): Promise<Transaction> => {
430
- // const address = options.address;
431
- // let txb;
432
- // if (transaction) txb = transaction;
433
- // else txb = new Transaction();
434
- // poolName = poolName.toUpperCase() as PoolName;
435
- // const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
436
- // const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
437
- // const receipt: Receipt[] = await getReceipts(poolName, address, true);
438
- // amountA = (Number(amountA) * 0.999).toString();
439
- // amountB = (Number(amountB) * 0.999).toString();
440
- // let amounts = await getAmounts(poolName, true, amountA);
441
- // if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
442
- // amounts = await getAmounts(poolName, false, amountB);
443
- // }
444
- // if (amounts && coin1Arg && coin2Arg) {
445
- // const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
446
- // const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
447
- // const poolinfo = poolInfo[poolName];
448
- // let someReceipt: any;
449
- // if (receipt.length == 0) {
450
- // [someReceipt] = txb.moveCall({
451
- // target: `0x1::option::none`,
452
- // typeArguments: [poolinfo.receiptType],
453
- // arguments: [],
454
- // });
455
- // } else {
456
- // [someReceipt] = txb.moveCall({
457
- // target: `0x1::option::some`,
458
- // typeArguments: [receipt[0].content.type],
459
- // arguments: [txb.object(receipt[0].objectId)],
460
- // });
461
- // }
462
- // txb.moveCall({
463
- // target: `${poolinfo.packageId}::alphafi_cetus_sui_pool::user_deposit`,
464
- // typeArguments: [coinsList[pool1].type, coinsList[pool2].type],
465
- // arguments: [
466
- // txb.object(getConf().ALPHA_2_VERSION),
467
- // txb.object(getConf().VERSION),
468
- // someReceipt,
469
- // txb.object(poolinfo.poolId),
470
- // depositCoinA,
471
- // depositCoinB,
472
- // txb.object(getConf().ALPHA_DISTRIBUTOR),
473
- // txb.object(poolinfo.investorId),
474
- // txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
475
- // txb.object(getConf().CETUS_REWARDER_GLOBAL_VAULT_ID),
476
- // txb.object(cetusPoolMap[poolName]),
477
- // txb.object(getConf().CLOCK_PACKAGE_ID),
478
- // ],
479
- // });
480
- // txb.transferObjects([coin1Arg, coin2Arg], address);
481
- // } else {
482
- // throw new Error(`No ${pool1} or ${pool2} Coins`);
483
- // }
484
- // return txb;
485
- // };
486
- // const depositBluefinSuiFirstTxb = async (
487
- // amountA: string,
488
- // amountB: string,
489
- // poolName: PoolName,
490
- // options: { address: string },
491
- // transaction: Transaction | undefined = undefined,
492
- // coin1Arg: TransactionObjectArgument | undefined,
493
- // coin2Arg: TransactionObjectArgument | undefined,
494
- // ): Promise<Transaction> => {
495
- // const address = options.address;
496
- // let txb;
497
- // if (transaction) txb = transaction;
498
- // else txb = new Transaction();
499
- // poolName = poolName.toUpperCase() as PoolName;
500
- // const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
501
- // const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
502
- // const receipt: Receipt[] = await getReceipts(poolName, address, true);
503
- // amountA = (Number(amountA) * 0.999).toString();
504
- // amountB = (Number(amountB) * 0.999).toString();
505
- // let amounts = await getAmounts(poolName, true, amountA);
506
- // if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
507
- // amounts = await getAmounts(poolName, false, amountB);
508
- // }
509
- // if (amounts && coin1Arg && coin2Arg) {
510
- // const [depositCoinA] = txb.splitCoins(txb.gas, [amounts[0]]);
511
- // const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
512
- // const poolinfo = poolInfo[poolName];
513
- // let someReceipt: any;
514
- // if (receipt.length == 0) {
515
- // [someReceipt] = txb.moveCall({
516
- // target: `0x1::option::none`,
517
- // typeArguments: [poolinfo.receiptType],
518
- // arguments: [],
519
- // });
520
- // } else {
521
- // [someReceipt] = txb.moveCall({
522
- // target: `0x1::option::some`,
523
- // typeArguments: [receipt[0].content.type],
524
- // arguments: [txb.object(receipt[0].objectId)],
525
- // });
526
- // }
527
- // txb.moveCall({
528
- // target: `${poolinfo.packageId}::alphafi_bluefin_sui_first_pool::user_deposit`,
529
- // typeArguments: [
530
- // coinsList[pool1].type,
531
- // coinsList[pool2].type,
532
- // coinsList["DEEP"].type,
533
- // coinsList["SUI"].type,
534
- // ],
535
- // arguments: [
536
- // txb.object(getConf().ALPHA_4_VERSION),
537
- // txb.object(getConf().VERSION),
538
- // someReceipt,
539
- // txb.object(poolinfo.poolId),
540
- // depositCoinA,
541
- // depositCoinB,
542
- // txb.object(getConf().ALPHA_DISTRIBUTOR),
543
- // txb.object(poolinfo.investorId),
544
- // txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
545
- // txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
546
- // txb.object(getConf().BLUEFIN_SUI_USDC_POOL),
547
- // txb.object(getConf().BLUEFIN_DEEP_SUI_POOL),
548
- // txb.object(cetusPoolMap["USDC-SUI"]),
549
- // txb.object(getConf().CLOCK_PACKAGE_ID),
550
- // ],
551
- // });
552
- // txb.transferObjects([coin1Arg, coin2Arg], address);
553
- // } else {
554
- // throw new Error(`No ${pool1} or ${pool2} Coins`);
555
- // }
556
- // return txb;
557
- // };
558
- // const depositBluefinType1Txb = async (
559
- // amountA: string,
560
- // amountB: string,
561
- // poolName: PoolName,
562
- // options: { address: string },
563
- // transaction: Transaction | undefined = undefined,
564
- // coin1Arg: TransactionObjectArgument | undefined,
565
- // coin2Arg: TransactionObjectArgument | undefined,
566
- // ): Promise<Transaction> => {
567
- // const address = options.address;
568
- // let txb;
569
- // if (transaction) txb = transaction;
570
- // else txb = new Transaction();
571
- // poolName = poolName.toUpperCase() as PoolName;
572
- // const pool1 = doubleAssetPoolCoinMap[poolName].coin1;
573
- // const pool2 = doubleAssetPoolCoinMap[poolName].coin2;
574
- // const receipt: Receipt[] = await getReceipts(poolName, address, true);
575
- // amountA = (Number(amountA) * 0.999).toString();
576
- // amountB = (Number(amountB) * 0.999).toString();
577
- // let amounts = await getAmounts(poolName, true, amountA);
578
- // if (amounts === undefined || amounts[0] > amountA || amounts[1] > amountB) {
579
- // amounts = await getAmounts(poolName, false, amountB);
580
- // }
581
- // if (amounts && coin1Arg && coin2Arg) {
582
- // const [depositCoinA] = txb.splitCoins(coin1Arg, [amounts[0]]);
583
- // const [depositCoinB] = txb.splitCoins(coin2Arg, [amounts[1]]);
584
- // const poolinfo = poolInfo[poolName];
585
- // let someReceipt: any;
586
- // if (receipt.length == 0) {
587
- // [someReceipt] = txb.moveCall({
588
- // target: `0x1::option::none`,
589
- // typeArguments: [poolinfo.receiptType],
590
- // arguments: [],
591
- // });
592
- // } else {
593
- // [someReceipt] = txb.moveCall({
594
- // target: `0x1::option::some`,
595
- // typeArguments: [receipt[0].content.type],
596
- // arguments: [txb.object(receipt[0].objectId)],
597
- // });
598
- // }
599
- // txb.moveCall({
600
- // target: `${poolinfo.packageId}::alphafi_bluefin_type_1_pool::user_deposit`,
601
- // typeArguments: [
602
- // coinsList[pool1].type,
603
- // coinsList[pool2].type,
604
- // coinsList["DEEP"].type,
605
- // coinsList["SUI"].type,
606
- // ],
607
- // arguments: [
608
- // txb.object(getConf().ALPHA_4_VERSION),
609
- // txb.object(getConf().VERSION),
610
- // someReceipt,
611
- // txb.object(poolinfo.poolId),
612
- // depositCoinA,
613
- // depositCoinB,
614
- // txb.object(getConf().ALPHA_DISTRIBUTOR),
615
- // txb.object(poolinfo.investorId),
616
- // txb.object(getConf().BLUEFIN_GLOBAL_CONFIG),
617
- // txb.object(getConf().CETUS_GLOBAL_CONFIG_ID),
618
- // txb.object(getConf().BLUEFIN_USDT_USDC_POOL),
619
- // txb.object(getConf().BLUEFIN_DEEP_SUI_POOL),
620
- // txb.object(cetusPoolMap["USDC-USDT"]),
621
- // txb.object(cetusPoolMap["USDC-SUI"]),
622
- // txb.object(getConf().CLOCK_PACKAGE_ID),
623
- // ],
624
- // });
625
- // txb.transferObjects([coin1Arg, coin2Arg], address);
626
- // } else {
627
- // throw new Error(`No ${pool1} or ${pool2} Coins`);
628
- // }
629
- // return txb;
630
- // };
631
- // export async function getZapAmounts(
632
- // inputCoinAmount: number,
633
- // inputCoinName: CoinName,
634
- // poolName: PoolName,
635
- // slippage: number,
636
- // options: { address: string },
637
- // ignoreCache: boolean,
638
- // ): Promise<[string, string, string, string] | undefined> {
639
- // const address = options.address;
640
- // const coinTypeA = doubleAssetPoolCoinMap[poolName].coin1;
641
- // const coinTypeB = doubleAssetPoolCoinMap[poolName].coin2;
642
- // const swapObjectA = coinsList[coinTypeA];
643
- // const swapObjectB = coinsList[coinTypeB];
644
- // const inputObject = coinsList[inputCoinName];
645
- // const amounts = await getAmounts(poolName, true, "100000001");
646
- // if (amounts) {
647
- // const amount1 = Number(amounts[0]);
648
- // const amount2 = Number(amounts[1]);
649
- // const swapGateway = new SevenKGateway();
650
- // const swapOptions: SwapOptions = {
651
- // pair: {
652
- // coinA: swapObjectA,
653
- // coinB: swapObjectB,
654
- // },
655
- // senderAddress: address,
656
- // inAmount: new BN(amount1),
657
- // slippage: slippage,
658
- // };
659
- // const ratioQuote = await swapGateway.getQuote(swapOptions);
660
- // if (ratioQuote) {
661
- // const amount1InCoinType2 = Number(ratioQuote.returnAmountWithDecimal);
662
- // const totalAmount = amount2 + amount1InCoinType2;
663
- // const inputAmountToType1 = Math.floor(
664
- // (inputCoinAmount * amount1InCoinType2) / totalAmount,
665
- // );
666
- // const inputAmountToType2 = Math.floor(
667
- // (inputCoinAmount * amount2) / totalAmount,
668
- // );
669
- // let amountA, amountB;
670
- // const swapOptionsI2A = {
671
- // pair: {
672
- // coinA: inputObject,
673
- // coinB: swapObjectA,
674
- // },
675
- // senderAddress: address,
676
- // inAmount: new BN(inputAmountToType1),
677
- // slippage: slippage,
678
- // };
679
- // const swapOptionsI2B = {
680
- // pair: {
681
- // coinA: inputObject,
682
- // coinB: swapObjectB,
683
- // },
684
- // senderAddress: address,
685
- // inAmount: new BN(inputAmountToType2),
686
- // slippage: slippage,
687
- // };
688
- // if (inputCoinName === coinTypeA) {
689
- // const quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
690
- // if (quoteResponse) {
691
- // amountB = quoteResponse.returnAmountWithDecimal;
692
- // }
693
- // amountA = inputAmountToType1.toString();
694
- // } else if (inputCoinName === coinTypeB) {
695
- // const quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
696
- // if (quoteResponse) {
697
- // amountA = quoteResponse.returnAmountWithDecimal;
698
- // }
699
- // amountB = inputAmountToType2.toString();
700
- // } else {
701
- // let quoteResponse = await swapGateway.getQuote(swapOptionsI2A);
702
- // if (quoteResponse) {
703
- // amountA = quoteResponse.returnAmountWithDecimal;
704
- // }
705
- // quoteResponse = await swapGateway.getQuote(swapOptionsI2B);
706
- // if (quoteResponse) {
707
- // amountB = quoteResponse.returnAmountWithDecimal;
708
- // }
709
- // }
710
- // if (amountA && amountB) {
711
- // const [coin1Price, coin2Price] = await getLatestPrices(
712
- // [
713
- // `${swapObjectA.name}/USD` as PythPriceIdPair,
714
- // `${swapObjectB.name}/USD` as PythPriceIdPair,
715
- // ],
716
- // ignoreCache,
717
- // );
718
- // const coin1InUSD = Number(amountA) * Number(coin1Price);
719
- // const coin2InUSD = Number(amountB) * Number(coin2Price);
720
- // return [
721
- // amountA.toString(),
722
- // coin1InUSD.toString(),
723
- // amountB.toString(),
724
- // coin2InUSD.toString(),
725
- // ];
726
- // }
727
- // }
728
- // }
1107
+ // const txb = new Transaction();
1108
+ // const pool1 = doubleAssetPoolCoinMap[poolName].pool1;
1109
+ // const pool2 = doubleAssetPoolCoinMap[poolName].pool2;
729
1110
  // }
1111
+ //calculate ratio of both coins in terms of coin-type 2
1112
+ //convert outputAmount in coinType2
1113
+ //then calculate coinType1 and coinType2 based on previous ratio
1114
+ //convert those amounts to liquidity
1115
+ //pass that liquidity into cetusWithdrawTxb
1116
+ //swap the amount withdrawn to outputAmountType.
730
1117
  //# sourceMappingURL=zapDeposit.js.map