@kimafinance/kima-transaction-widget 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +88 -57
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +43 -25
- package/dist/index.modern.js.map +1 -1
- package/dist/store/optionSlice.d.ts +1 -3
- package/dist/store/selectors.d.ts +2 -3
- package/dist/utils/config.d.ts +1 -1
- package/dist/utils/constants.d.ts +1 -11
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ethers, BigNumber } from 'ethers';
|
|
|
9
9
|
import AnimatedNumber from 'animated-number-react';
|
|
10
10
|
import { WalletReadyState } from '@solana/wallet-adapter-base';
|
|
11
11
|
import { Contract } from '@ethersproject/contracts';
|
|
12
|
-
import { parseUnits } from '@ethersproject/units';
|
|
12
|
+
import { formatUnits, parseUnits } from '@ethersproject/units';
|
|
13
13
|
import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, AccountLayout } from '@solana/spl-token';
|
|
14
14
|
|
|
15
15
|
const Cross = ({
|
|
@@ -448,7 +448,7 @@ const Copy = ({
|
|
|
448
448
|
};
|
|
449
449
|
|
|
450
450
|
const SOLANA_USDK_ADDRESS = 'GkbnUDkymDTF4U6Z5wM5kKJn3GmGndMn2rN5typmyUHY';
|
|
451
|
-
const ETHEREUM_USDK_ADDRESS = '
|
|
451
|
+
const ETHEREUM_USDK_ADDRESS = '0x7C043d4D2b505740742dF6Fdb79C5caEe08728a5';
|
|
452
452
|
const POLYGON_USDK_ADDRESS = '0x5bd4865a6dEd507dA08ed1aBE3cd971a7e0405D7';
|
|
453
453
|
const AVAX_USDK_ADDRESS = '0x7C043d4D2b505740742dF6Fdb79C5caEe08728a5';
|
|
454
454
|
const FUSE_GDOLLAR_ADDRESS = '0x79BeecC4b165Ccf547662cB4f7C0e83b3796E5b3';
|
|
@@ -465,7 +465,7 @@ var ChainName;
|
|
|
465
465
|
})(ChainName || (ChainName = {}));
|
|
466
466
|
var SupportedChainId;
|
|
467
467
|
(function (SupportedChainId) {
|
|
468
|
-
SupportedChainId[SupportedChainId["ETHEREUM"] =
|
|
468
|
+
SupportedChainId[SupportedChainId["ETHEREUM"] = 11155111] = "ETHEREUM";
|
|
469
469
|
SupportedChainId[SupportedChainId["POLYGON"] = 80001] = "POLYGON";
|
|
470
470
|
SupportedChainId[SupportedChainId["AVALANCHE"] = 43113] = "AVALANCHE";
|
|
471
471
|
SupportedChainId[SupportedChainId["FUSE"] = 122] = "FUSE";
|
|
@@ -487,7 +487,7 @@ const CHAIN_NAMES_TO_STRING = {
|
|
|
487
487
|
[ChainName.SOLANA]: 'Solana'
|
|
488
488
|
};
|
|
489
489
|
const CHAIN_NAMES_TO_EXPLORER = {
|
|
490
|
-
[ChainName.ETHEREUM]: '
|
|
490
|
+
[ChainName.ETHEREUM]: 'sepolia.etherscan.io',
|
|
491
491
|
[ChainName.POLYGON]: 'mumbai.polygonscan.com',
|
|
492
492
|
[ChainName.AVALANCHE]: 'testnet.snowtrace.io',
|
|
493
493
|
[ChainName.FUSE]: 'explorer.fuse.io',
|
|
@@ -615,7 +615,6 @@ const initialState = {
|
|
|
615
615
|
isSubmitting: false,
|
|
616
616
|
isConfirming: false,
|
|
617
617
|
feeDeduct: false,
|
|
618
|
-
splAllowance: 0,
|
|
619
618
|
errorHandler: () => void 0,
|
|
620
619
|
closeHandler: () => void 0,
|
|
621
620
|
successHandler: () => void 0,
|
|
@@ -677,9 +676,6 @@ const optionSlice = createSlice({
|
|
|
677
676
|
setSubmitting: (state, action) => {
|
|
678
677
|
state.isSubmitting = action.payload;
|
|
679
678
|
},
|
|
680
|
-
setSplAllowance: (state, action) => {
|
|
681
|
-
state.splAllowance = action.payload;
|
|
682
|
-
},
|
|
683
679
|
setErrorHandler: (state, action) => {
|
|
684
680
|
state.errorHandler = action.payload;
|
|
685
681
|
},
|
|
@@ -731,7 +727,6 @@ const {
|
|
|
731
727
|
setApproving,
|
|
732
728
|
setSubmitting,
|
|
733
729
|
setConfirming,
|
|
734
|
-
setSplAllowance,
|
|
735
730
|
setErrorHandler,
|
|
736
731
|
setCloseHandler,
|
|
737
732
|
setSuccessHandler,
|
|
@@ -767,7 +762,6 @@ const selectTransactionOption = state => state.option.transactionOption;
|
|
|
767
762
|
const selectAmount = state => state.option.amount;
|
|
768
763
|
const selectApproving = state => state.option.isApproving;
|
|
769
764
|
const selectSubmitting = state => state.option.isSubmitting;
|
|
770
|
-
const selectSplAllowance = state => state.option.splAllowance;
|
|
771
765
|
const selectErrorHandler = state => state.option.errorHandler;
|
|
772
766
|
const selectCloseHandler = state => state.option.closeHandler;
|
|
773
767
|
const selectSuccessHandler = state => state.option.successHandler;
|
|
@@ -6194,7 +6188,7 @@ class TokenAmount extends bn {
|
|
|
6194
6188
|
|
|
6195
6189
|
function useAllowance() {
|
|
6196
6190
|
const dispatch = useDispatch();
|
|
6197
|
-
const [allowance, setAllowance] = useState(
|
|
6191
|
+
const [allowance, setAllowance] = useState(0);
|
|
6198
6192
|
const [decimals, setDecimals] = useState(null);
|
|
6199
6193
|
const {
|
|
6200
6194
|
signerAddress,
|
|
@@ -6212,8 +6206,6 @@ function useAllowance() {
|
|
|
6212
6206
|
}, [selectedNetwork, evmChainId]);
|
|
6213
6207
|
const amount = useSelector(selectAmount);
|
|
6214
6208
|
const serviceFee = useSelector(selectServiceFee);
|
|
6215
|
-
const isApproving = useSelector(selectApproving);
|
|
6216
|
-
const splAllowance = useSelector(selectSplAllowance);
|
|
6217
6209
|
const nodeProviderQuery = useSelector(selectNodeProviderQuery);
|
|
6218
6210
|
const {
|
|
6219
6211
|
connection
|
|
@@ -6228,12 +6220,8 @@ function useAllowance() {
|
|
|
6228
6220
|
}, [selectedCoin, sourceChain]);
|
|
6229
6221
|
const [targetAddress, setTargetAddress] = useState();
|
|
6230
6222
|
const isApproved = useMemo(() => {
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
}
|
|
6234
|
-
if (allowance && amount && allowance.gte(parseUnits((amount + serviceFee).toString(), decimals))) return true;
|
|
6235
|
-
return false;
|
|
6236
|
-
}, [decimals, sourceChain, allowance, amount, splAllowance, serviceFee]);
|
|
6223
|
+
return allowance >= amount + serviceFee;
|
|
6224
|
+
}, [allowance, amount, serviceFee]);
|
|
6237
6225
|
const updatePoolAddress = async () => {
|
|
6238
6226
|
try {
|
|
6239
6227
|
var _result$tssPubkey;
|
|
@@ -6260,11 +6248,9 @@ function useAllowance() {
|
|
|
6260
6248
|
if (!isEVMChain(sourceChain) && publicKey && tokenAddress && connection) {
|
|
6261
6249
|
var _accountInfo$value, _parsedAccountInfo$pa, _parsedAccountInfo$pa2, _parsedAccountInfo$pa3, _parsedAccountInfo$pa4, _parsedAccountInfo$pa5;
|
|
6262
6250
|
const mint = new PublicKey(tokenAddress);
|
|
6263
|
-
console.log(mint, publicKey, tokenAddress);
|
|
6264
6251
|
const fromTokenAccount = await getOrCreateAssociatedTokenAccount(connection, publicKey, mint, publicKey, signTransaction);
|
|
6265
|
-
console.log(fromTokenAccount);
|
|
6266
6252
|
const accountInfo = await connection.getParsedAccountInfo(fromTokenAccount.address);
|
|
6267
|
-
console.log(accountInfo);
|
|
6253
|
+
console.log('solana token account: ', accountInfo);
|
|
6268
6254
|
setDecimals(COIN_LIST['USDK'].decimals);
|
|
6269
6255
|
const parsedAccountInfo = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$value = accountInfo.value) === null || _accountInfo$value === void 0 ? void 0 : _accountInfo$value.data;
|
|
6270
6256
|
setAllowance(((_parsedAccountInfo$pa = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa === void 0 ? void 0 : (_parsedAccountInfo$pa2 = _parsedAccountInfo$pa.info) === null || _parsedAccountInfo$pa2 === void 0 ? void 0 : _parsedAccountInfo$pa2.delegate) === targetAddress ? (_parsedAccountInfo$pa3 = parsedAccountInfo.parsed) === null || _parsedAccountInfo$pa3 === void 0 ? void 0 : (_parsedAccountInfo$pa4 = _parsedAccountInfo$pa3.info) === null || _parsedAccountInfo$pa4 === void 0 ? void 0 : (_parsedAccountInfo$pa5 = _parsedAccountInfo$pa4.delegatedAmount) === null || _parsedAccountInfo$pa5 === void 0 ? void 0 : _parsedAccountInfo$pa5.uiAmount : 0);
|
|
@@ -6275,12 +6261,12 @@ function useAllowance() {
|
|
|
6275
6261
|
const decimals = await erc20Contract.decimals();
|
|
6276
6262
|
const userAllowance = await erc20Contract.allowance(signerAddress, targetAddress);
|
|
6277
6263
|
setDecimals(+decimals);
|
|
6278
|
-
setAllowance(userAllowance);
|
|
6264
|
+
setAllowance(+formatUnits(userAllowance, decimals));
|
|
6279
6265
|
} catch (error) {
|
|
6280
6266
|
errorHandler(error);
|
|
6281
6267
|
}
|
|
6282
6268
|
})();
|
|
6283
|
-
}, [signerAddress, tokenAddress, targetAddress,
|
|
6269
|
+
}, [signerAddress, tokenAddress, targetAddress, sourceChain, publicKey]);
|
|
6284
6270
|
const approve = useCallback(async () => {
|
|
6285
6271
|
if (isEVMChain(sourceChain)) {
|
|
6286
6272
|
if (!decimals || !tokenAddress || !signer || !targetAddress) return;
|
|
@@ -6290,6 +6276,7 @@ function useAllowance() {
|
|
|
6290
6276
|
const approve = await erc20Contract.approve(targetAddress, parseUnits((amount + serviceFee).toString(), decimals));
|
|
6291
6277
|
await approve.wait();
|
|
6292
6278
|
dispatch(setApproving(false));
|
|
6279
|
+
setAllowance(amount + serviceFee);
|
|
6293
6280
|
} catch (error) {
|
|
6294
6281
|
errorHandler(error);
|
|
6295
6282
|
dispatch(setApproving(false));
|
|
@@ -6308,7 +6295,7 @@ function useAllowance() {
|
|
|
6308
6295
|
transaction.recentBlockhash = await blockHash.blockhash;
|
|
6309
6296
|
const signed = await signTransaction(transaction);
|
|
6310
6297
|
await connection.sendRawTransaction(signed.serialize());
|
|
6311
|
-
|
|
6298
|
+
setAllowance(amount + serviceFee);
|
|
6312
6299
|
dispatch(setApproving(false));
|
|
6313
6300
|
} catch (e) {
|
|
6314
6301
|
errorHandler(e);
|
|
@@ -6456,6 +6443,17 @@ const TransferWidget = ({
|
|
|
6456
6443
|
options: selectedCoin
|
|
6457
6444
|
} = useCurrencyOptions();
|
|
6458
6445
|
const backendUrl = useSelector(selectBackendUrl);
|
|
6446
|
+
const nodeProviderQuery = useSelector(selectNodeProviderQuery);
|
|
6447
|
+
useEffect(() => {
|
|
6448
|
+
if (!nodeProviderQuery) return;
|
|
6449
|
+
(async function () {
|
|
6450
|
+
const res = await fetchWrapper.get(`${nodeProviderQuery}/kima-finance/kima/kima/pool_balance`);
|
|
6451
|
+
console.table(res.poolBalance.map(item => ({
|
|
6452
|
+
chain: CHAIN_NAMES_TO_STRING[item.chainName],
|
|
6453
|
+
balance: +item.balance
|
|
6454
|
+
})));
|
|
6455
|
+
})();
|
|
6456
|
+
}, [nodeProviderQuery]);
|
|
6459
6457
|
useEffect(() => {
|
|
6460
6458
|
dispatch(setCurrencyOptions(selectedCoin));
|
|
6461
6459
|
}, [selectedCoin]);
|
|
@@ -6468,6 +6466,22 @@ const TransferWidget = ({
|
|
|
6468
6466
|
useEffect(() => {
|
|
6469
6467
|
dispatch(setServiceFee(fee));
|
|
6470
6468
|
}, [fee]);
|
|
6469
|
+
const checkPoolBalance = async () => {
|
|
6470
|
+
const res = await fetchWrapper.get(`${nodeProviderQuery}/kima-finance/kima/kima/pool_balance`);
|
|
6471
|
+
const poolBalance = res.poolBalance;
|
|
6472
|
+
for (let i = 0; i < poolBalance.length; i++) {
|
|
6473
|
+
if (poolBalance[i].chainName === targetNetwork) {
|
|
6474
|
+
if (+poolBalance[i].balance >= amount + fee) {
|
|
6475
|
+
return true;
|
|
6476
|
+
}
|
|
6477
|
+
const symbol = targetNetwork === ChainName.FUSE || targetNetwork === ChainName.CELO ? 'G$' : 'USDK';
|
|
6478
|
+
console.log(`Tried to transfer ${amount} ${symbol}, but ${CHAIN_NAMES_TO_STRING[targetNetwork]} pool has only ${+poolBalance[i].balance} ${symbol}`);
|
|
6479
|
+
return false;
|
|
6480
|
+
}
|
|
6481
|
+
}
|
|
6482
|
+
console.log(`${CHAIN_NAMES_TO_STRING[targetNetwork]} pool error`);
|
|
6483
|
+
return false;
|
|
6484
|
+
};
|
|
6471
6485
|
const handleSubmit = async () => {
|
|
6472
6486
|
if (!isApproved) {
|
|
6473
6487
|
approve();
|
|
@@ -6475,6 +6489,10 @@ const TransferWidget = ({
|
|
|
6475
6489
|
}
|
|
6476
6490
|
try {
|
|
6477
6491
|
dispatch(setSubmitting(true));
|
|
6492
|
+
if (!(await checkPoolBalance())) {
|
|
6493
|
+
dispatch(setSubmitting(false));
|
|
6494
|
+
return;
|
|
6495
|
+
}
|
|
6478
6496
|
const params = JSON.stringify({
|
|
6479
6497
|
originAddress: walletAddress,
|
|
6480
6498
|
originChain: sourceChain,
|