@berachain/berajs 0.2.0 → 0.2.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/{transactionStore-BvStaXf3.d.ts → BexStatusProvider-nS3NcdxI.d.cts} +1 -41
- package/dist/{transactionStore-CQrGYSY2.d.cts → BexStatusProvider-nS3NcdxI.d.ts} +1 -41
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/actions/exports.cjs +1 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.d.cts +4 -5
- package/dist/actions/exports.d.ts +4 -5
- package/dist/actions/exports.mjs +1 -1
- package/dist/{chunk-OS5AJMYJ.cjs → chunk-22J3YJDN.cjs} +2 -2
- package/dist/chunk-22J3YJDN.cjs.map +1 -0
- package/dist/{chunk-MTS5SZLA.mjs → chunk-2LL3P5PN.mjs} +2 -2
- package/dist/chunk-3YXSUBA5.mjs +2 -0
- package/dist/{chunk-H2QSRMVS.mjs.map → chunk-3YXSUBA5.mjs.map} +1 -1
- package/dist/chunk-55L7STYD.mjs +2 -0
- package/dist/chunk-55L7STYD.mjs.map +1 -0
- package/dist/{chunk-BOYZVULX.cjs → chunk-6LDOG5RL.cjs} +2 -2
- package/dist/chunk-6LDOG5RL.cjs.map +1 -0
- package/dist/{chunk-UQUWMHVF.cjs → chunk-7LNBSOVV.cjs} +2 -2
- package/dist/chunk-7LNBSOVV.cjs.map +1 -0
- package/dist/{chunk-ZQRACIGR.mjs → chunk-7SMWQ6SN.mjs} +2 -2
- package/dist/{chunk-7GWTHOLO.mjs → chunk-7WRTK7RJ.mjs} +2 -2
- package/dist/chunk-A4UDYSB6.mjs +4 -0
- package/dist/chunk-A4UDYSB6.mjs.map +1 -0
- package/dist/chunk-AX2YQQFQ.mjs +2 -0
- package/dist/chunk-AX2YQQFQ.mjs.map +1 -0
- package/dist/chunk-C6ZGUO4H.cjs +2 -0
- package/dist/chunk-C6ZGUO4H.cjs.map +1 -0
- package/dist/chunk-CYKCYPFR.cjs.map +1 -1
- package/dist/chunk-ECRMUMTA.mjs +2 -0
- package/dist/chunk-ECRMUMTA.mjs.map +1 -0
- package/dist/{chunk-ZAKA4TGK.cjs → chunk-FCWDGE62.cjs} +2 -2
- package/dist/chunk-FCWDGE62.cjs.map +1 -0
- package/dist/chunk-FL2N3XHK.cjs.map +1 -1
- package/dist/chunk-MUCEYO3E.cjs +4 -0
- package/dist/chunk-MUCEYO3E.cjs.map +1 -0
- package/dist/chunk-OIYXOKTT.cjs.map +1 -1
- package/dist/chunk-P2Q7CMUD.cjs +2 -0
- package/dist/chunk-P2Q7CMUD.cjs.map +1 -0
- package/dist/chunk-PKXAW6MO.cjs +2 -0
- package/dist/chunk-PKXAW6MO.cjs.map +1 -0
- package/dist/chunk-SWMJQOH6.cjs.map +1 -1
- package/dist/{chunk-YQGZMWDT.mjs → chunk-THATXCJK.mjs} +2 -2
- package/dist/chunk-VP7XUOSI.cjs.map +1 -1
- package/dist/chunk-VXL2ZZ4X.cjs.map +1 -1
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -1
- package/dist/chunk-XNJLSA6P.cjs.map +1 -1
- package/dist/chunk-YZV5LKIP.cjs +2 -0
- package/dist/chunk-YZV5LKIP.cjs.map +1 -0
- package/dist/contexts/exports.cjs +1 -1
- package/dist/contexts/exports.cjs.map +1 -1
- package/dist/contexts/exports.d.cts +2 -10
- package/dist/contexts/exports.d.ts +2 -10
- package/dist/contexts/exports.mjs +1 -1
- package/dist/contexts/exports.mjs.map +1 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/enum/exports.d.cts +1 -2
- package/dist/enum/exports.d.ts +1 -2
- package/dist/errors/exports.cjs +1 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/errors/exports.d.cts +25 -2
- package/dist/errors/exports.d.ts +25 -2
- package/dist/errors/exports.mjs +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-It0GsdvQ.d.cts → getValidatorQueuedOperatorAddress-Dstyaomr.d.cts} +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-BX35p2Lv.d.ts → getValidatorQueuedOperatorAddress-RW4OMcD1.d.ts} +1 -1
- package/dist/{global.d-Ba-NIojH.d.cts → global.d-CN6l2b9E.d.cts} +1 -2
- package/dist/{global.d-By70bEv2.d.ts → global.d-wYu8G8IQ.d.ts} +1 -2
- package/dist/hooks/exports.cjs +2 -2
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.d.cts +7 -15
- package/dist/hooks/exports.d.ts +7 -15
- package/dist/hooks/exports.mjs +3 -3
- package/dist/hooks/exports.mjs.map +1 -1
- package/dist/{txnEnum-BYNbCxla.d.ts → txnEnum-BlBYhNRl.d.cts} +74 -1
- package/dist/{txnEnum-BYNbCxla.d.cts → txnEnum-BlBYhNRl.d.ts} +74 -1
- package/dist/types/exports.cjs.map +1 -1
- package/dist/types/exports.d.cts +2 -3
- package/dist/types/exports.d.ts +2 -3
- package/dist/utils/exports.cjs +1 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/dist/utils/exports.mjs +1 -1
- package/dist/utils/exports.mjs.map +1 -1
- package/package.json +3 -3
- package/src/actions/dex/aggregators/haiku.ts +1 -1
- package/src/actions/dex/aggregators/oogabooga.ts +1 -1
- package/src/actions/pol/getEarnedStakedBeraVault.ts +1 -1
- package/src/actions/pol/getStakingDailyAssets.ts +4 -1
- package/src/actions/tokens/getWalletBalances.integration.test.ts +1 -1
- package/src/contexts/exports.ts +0 -1
- package/src/data/contracts.ts +1 -1
- package/src/errors/BeraError.ts +11 -2
- package/src/errors/RequestError.ts +27 -1
- package/src/errors/errorMap.ts +7 -6
- package/src/errors/getErrorMessage.ts +59 -20
- package/src/errors/getRevertReason.integration.test.ts +1 -1
- package/src/hooks/exports.ts +0 -4
- package/src/hooks/pol/useStakedData.ts +1 -1
- package/dist/chunk-7SC4VD3U.cjs +0 -2
- package/dist/chunk-7SC4VD3U.cjs.map +0 -1
- package/dist/chunk-BHNQX4XC.mjs +0 -2
- package/dist/chunk-BHNQX4XC.mjs.map +0 -1
- package/dist/chunk-BOYZVULX.cjs.map +0 -1
- package/dist/chunk-C3G5KXCH.mjs +0 -2
- package/dist/chunk-C3G5KXCH.mjs.map +0 -1
- package/dist/chunk-G6NA6NSM.mjs +0 -4
- package/dist/chunk-G6NA6NSM.mjs.map +0 -1
- package/dist/chunk-H2QSRMVS.mjs +0 -2
- package/dist/chunk-IJM76AWK.cjs +0 -4
- package/dist/chunk-IJM76AWK.cjs.map +0 -1
- package/dist/chunk-MUNAP5TM.cjs +0 -2
- package/dist/chunk-MUNAP5TM.cjs.map +0 -1
- package/dist/chunk-OS5AJMYJ.cjs.map +0 -1
- package/dist/chunk-TJWKS54T.mjs +0 -2
- package/dist/chunk-TJWKS54T.mjs.map +0 -1
- package/dist/chunk-UQUWMHVF.cjs.map +0 -1
- package/dist/chunk-UXUWSRVV.cjs +0 -2
- package/dist/chunk-UXUWSRVV.cjs.map +0 -1
- package/dist/chunk-WTCBORPB.cjs +0 -2
- package/dist/chunk-WTCBORPB.cjs.map +0 -1
- package/dist/chunk-ZAKA4TGK.cjs.map +0 -1
- package/dist/contracts-CQIPk0Jc.d.cts +0 -74
- package/dist/contracts-CQIPk0Jc.d.ts +0 -74
- package/src/contexts/TransactionStoreContext.tsx +0 -87
- package/src/hooks/transactions/transactionStore.ts +0 -296
- package/src/hooks/transactions/transactionStore.unit.test.ts +0 -561
- package/src/hooks/transactions/useAddRecentTransaction.ts +0 -29
- package/src/hooks/transactions/useRecentTransactions.ts +0 -27
- package/src/hooks/transactions/useSetTransactionStatus.ts +0 -31
- /package/dist/{chunk-MTS5SZLA.mjs.map → chunk-2LL3P5PN.mjs.map} +0 -0
- /package/dist/{chunk-ZQRACIGR.mjs.map → chunk-7SMWQ6SN.mjs.map} +0 -0
- /package/dist/{chunk-7GWTHOLO.mjs.map → chunk-7WRTK7RJ.mjs.map} +0 -0
- /package/dist/{chunk-YQGZMWDT.mjs.map → chunk-THATXCJK.mjs.map} +0 -0
package/dist/chunk-WTCBORPB.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunkOS5AJMYJcjs = require('./chunk-OS5AJMYJ.cjs');function m(e){return{...e,..._chunkOS5AJMYJcjs.e.call(void 0, e,"BERA")&&_chunkOS5AJMYJcjs.c}}function d(e){return e.map(r=>m(r))}var _bignumberjs = require('@berachain/utils/pkg/bignumber.js'); var _bignumberjs2 = _interopRequireDefault(_bignumberjs);var g=(e,r,i,o)=>{if(!e||!r||!i||!o)return 0;let t=new (0, _bignumberjs2.default)(e).times(i),n=new (0, _bignumberjs2.default)(r).times(o);if(t.lt(.01)||n.lt(.01)||t.isZero()||n.isZero())return 0;let u=n.div(t);return Number(new (0, _bignumberjs2.default)(1).minus(u).toFixed())};exports.a = m; exports.b = d; exports.c = g;
|
|
2
|
-
//# sourceMappingURL=chunk-WTCBORPB.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/pong/coding/monobera/packages/berajs/dist/chunk-WTCBORPB.cjs","../src/utils/tokenWrapping.ts","../src/utils/math.ts"],"names":["wrapNativeToken","token","isToken","wBeraToken","wrapNativeTokens","tokens","computePriceImpact","tokenInPrice","tokenOutPrice","inAmount","outAmount","usdIn","BigNumber","usdOut","ratio"],"mappings":"AAAA,iOAA+C,SCM/BA,CAAAA,CAAqCC,CAAAA,CAAa,CAChE,MAAO,CACL,GAAGA,CAAAA,CACH,GAAIC,iCAAAA,CAAQD,CAAO,MAAM,CAAA,EAAKE,mBAChC,CACF,CAEO,SAASC,CAAAA,CAAsCC,CAAAA,CAAkB,CACtE,OAAOA,CAAAA,CAAO,GAAA,CAAKJ,CAAAA,EAAUD,CAAAA,CAAgBC,CAAK,CAAC,CACrD,CCfA,0HAAsB,IAUTK,CAAAA,CAAqB,CAChCC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAAAA,EACW,CACX,EAAA,CAAI,CAACH,CAAAA,EAAgB,CAACC,CAAAA,EAAiB,CAACC,CAAAA,EAAY,CAACC,CAAAA,CAAW,OAAO,CAAA,CAEvE,IAAMC,CAAAA,CAAQ,IAAIC,0BAAAA,CAAUL,CAAY,CAAA,CAAE,KAAA,CAAME,CAAQ,CAAA,CAClDI,CAAAA,CAAS,IAAID,0BAAAA,CAAUJ,CAAa,CAAA,CAAE,KAAA,CAAME,CAAS,CAAA,CAI3D,EAAA,CADIC,CAAAA,CAAM,EAAA,CAAG,GAAI,CAAA,EAAKE,CAAAA,CAAO,EAAA,CAAG,GAAI,CAAA,EAChCF,CAAAA,CAAM,MAAA,CAAO,CAAA,EAAKE,CAAAA,CAAO,MAAA,CAAO,CAAA,CAAG,OAAO,CAAA,CAE9C,IAAMC,CAAAA,CAAQD,CAAAA,CAAO,GAAA,CAAIF,CAAK,CAAA,CAC9B,OAAO,MAAA,CAAO,IAAIC,0BAAAA,CAAU,CAAC,CAAA,CAAE,KAAA,CAAME,CAAK,CAAA,CAAE,OAAA,CAAQ,CAAC,CACvD,CAAA,CAAA,4CAAA","file":"/Users/pong/coding/monobera/packages/berajs/dist/chunk-WTCBORPB.cjs","sourcesContent":[null,"import { isToken, wBeraToken } from \"./tokens\";\n\ntype BaseToken = {\n address: string;\n};\n\nexport function wrapNativeToken<T extends BaseToken>(token: T): T {\n return {\n ...token,\n ...(isToken(token, \"BERA\") && wBeraToken),\n };\n}\n\nexport function wrapNativeTokens<T extends BaseToken>(tokens: T[]): T[] {\n return tokens.map((token) => wrapNativeToken(token));\n}\n","import BigNumber from \"@berachain/utils/pkg/bignumber.js\";\n\n/**\n * Compute the price impact of a swap\n * @param {string} tokenInPrice - The price of the input token\n * @param {string} tokenOutPrice - The price of the output token\n * @param {string} inAmount - The amount of the input token\n * @param {string} outAmount - The amount of the output token\n * @returns {number} The price impact of the swap\n */\nexport const computePriceImpact = (\n tokenInPrice: string,\n tokenOutPrice: string,\n inAmount: string,\n outAmount: string,\n): number => {\n if (!tokenInPrice || !tokenOutPrice || !inAmount || !outAmount) return 0;\n\n const usdIn = new BigNumber(tokenInPrice).times(inAmount);\n const usdOut = new BigNumber(tokenOutPrice).times(outAmount);\n\n // is the amount is close to 0, return 0\n if (usdIn.lt(0.01) || usdOut.lt(0.01)) return 0;\n if (usdIn.isZero() || usdOut.isZero()) return 0;\n\n const ratio = usdOut.div(usdIn);\n return Number(new BigNumber(1).minus(ratio).toFixed());\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/pong/coding/monobera/packages/berajs/dist/chunk-ZAKA4TGK.cjs","../src/actions/clients/getEnsoClient.ts"],"names":["isProduction","getEnsoClient","useProxy","args","config","parseBaseArgs","EnsoClient"],"mappings":"AAAA,yuBAAwC,wDAAuD,wDAAgD,uCCApH,sDAED,IAIpBA,CAAAA,CACJ,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,aAAA,EAAiB,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,MAAA,CAE9D,SAASC,CAAAA,CAAc,CAC5B,QAAA,CAAAC,CAAAA,CAAWF,CAAAA,CACX,GAAGG,CACL,CAAA,CAAsD,CAAC,CAAA,CAAG,CACxD,GAAM,CAAE,MAAA,CAAAC,CAAO,CAAA,CAAIC,iCAAAA,CAAkB,CAAA,CACrC,OAAO,IAAIC,oBAAAA,CAAW,CACpB,OAAA,CAASJ,CAAAA,CACL,CAAA,EAAA","file":"/Users/pong/coding/monobera/packages/berajs/dist/chunk-ZAKA4TGK.cjs","sourcesContent":[null,"import { EnsoClient } from \"@ensofinance/sdk\";\n\nimport { appConfig } from \"@berachain/config/internal\";\n\nimport { parseBaseArgs } from \"~/utils/parseBaseArgs\";\n\nconst isProduction =\n process.env.NODE_ENV !== \"development\" && process.env.NODE_ENV !== \"test\";\n\nexport function getEnsoClient({\n useProxy = isProduction,\n ...args\n}: BeraJS.BaseFunctionArgs & { useProxy?: boolean } = {}) {\n const { config } = parseBaseArgs(args);\n return new EnsoClient({\n baseURL: useProxy\n ? `${config.bex.aggregatorsProxyUrl}/enso/api/v1/`\n : undefined,\n apiKey: useProxy\n ? // no API key since proxy has CORS for .berachain.com domains\n \"\"\n : appConfig.apiKeys.public.enso,\n });\n}\n"]}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Maps the proposal state from the governor contract to a more human-readable format.
|
|
3
|
-
* Don't edit this enum manually, it's synced with the governor contract.
|
|
4
|
-
*
|
|
5
|
-
* @see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/governance/IGovernor.sol
|
|
6
|
-
*/
|
|
7
|
-
declare enum ProposalState {
|
|
8
|
-
Pending = 0,
|
|
9
|
-
Active = 1,
|
|
10
|
-
Canceled = 2,
|
|
11
|
-
Defeated = 3,
|
|
12
|
-
Succeeded = 4,
|
|
13
|
-
Queued = 5,
|
|
14
|
-
Expired = 6,
|
|
15
|
-
Executed = 7
|
|
16
|
-
}
|
|
17
|
-
declare enum VoteEnum {
|
|
18
|
-
AGAINST = "no",
|
|
19
|
-
FOR = "yes",
|
|
20
|
-
ABSTAIN = "abstain"
|
|
21
|
-
}
|
|
22
|
-
declare enum ProposalErrorCodes {
|
|
23
|
-
REQUIRED = "Required",
|
|
24
|
-
INVALID_AMOUNT = "Invalid amount",
|
|
25
|
-
NEGATIVE_AMOUNT = "Negative amount",
|
|
26
|
-
INVALID_ADDRESS = "Invalid address",
|
|
27
|
-
INVALID_ACTION = "Invalid action",
|
|
28
|
-
INVALID_ABI = "Invalid ABI",
|
|
29
|
-
MUST_BE_HTTPS = "Must be HTTPS",
|
|
30
|
-
MUST_BE_HTTPS_OR_IPFS = "Must be HTTPS or IPFS",
|
|
31
|
-
INVALID_BASEPATH = "Must be a berachain forum link",
|
|
32
|
-
/**
|
|
33
|
-
* Mainly used when it's not a reward vault
|
|
34
|
-
*/
|
|
35
|
-
INVALID_CONTRACT = "This is not a valid contract"
|
|
36
|
-
}
|
|
37
|
-
declare enum ProposalTypeEnum {
|
|
38
|
-
CUSTOM_PROPOSAL = "custom-action",
|
|
39
|
-
WHITELIST_REWARD_VAULT = "whitelist-reward-vault",
|
|
40
|
-
BLACKLIST_REWARD_VAULT = "blacklist-reward-vault",
|
|
41
|
-
ERC20_TRANSFER = "erc20-transfer",
|
|
42
|
-
WHITELIST_REWARD_VAULT_INCENTIVE = "whitelist-reward-vault-incentive"
|
|
43
|
-
}
|
|
44
|
-
declare const VoteColorMap: {
|
|
45
|
-
readonly yes: "#059669";
|
|
46
|
-
readonly 1: "#059669";
|
|
47
|
-
readonly no: "#DC2629";
|
|
48
|
-
readonly 2: "#DC2629";
|
|
49
|
-
readonly veto: "#0284C7";
|
|
50
|
-
readonly 4: "#0284C7";
|
|
51
|
-
readonly abstain: "#78716c";
|
|
52
|
-
readonly 3: "#78716c";
|
|
53
|
-
readonly yes_secondary: "#ECFDF5";
|
|
54
|
-
readonly no_secondary: "#FEF2F2";
|
|
55
|
-
readonly veto_secondary: "#F0F9FF";
|
|
56
|
-
readonly abstain_secondary: "#E7E5E4";
|
|
57
|
-
readonly default: "#57534e";
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* A list of contract names that are not mapped in the devrel's contract mapping or that are generated by factories (e.g. RewardVault).
|
|
62
|
-
*/
|
|
63
|
-
declare enum ContractName {
|
|
64
|
-
ENSO_ROUTER = "enso.router",
|
|
65
|
-
POL_REWARD_VAULT = "pol.rewardVault",
|
|
66
|
-
BEX_POOL = "bex.pool",
|
|
67
|
-
ERC20 = "others.erc20",
|
|
68
|
-
ERC4626 = "others.erc4626",
|
|
69
|
-
POL_STAKE_VAULT = "pol.stakeVault",
|
|
70
|
-
BEX_EXPLOITED_FUND_DISTRIBUTOR = "bex.exploitedFundDistributor",
|
|
71
|
-
TW_MINIMAL_ACCOUNT = "thirdweb.minimalAccount"
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { ContractName as C, ProposalState as P, VoteEnum as V, ProposalErrorCodes as a, ProposalTypeEnum as b, VoteColorMap as c };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Maps the proposal state from the governor contract to a more human-readable format.
|
|
3
|
-
* Don't edit this enum manually, it's synced with the governor contract.
|
|
4
|
-
*
|
|
5
|
-
* @see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/governance/IGovernor.sol
|
|
6
|
-
*/
|
|
7
|
-
declare enum ProposalState {
|
|
8
|
-
Pending = 0,
|
|
9
|
-
Active = 1,
|
|
10
|
-
Canceled = 2,
|
|
11
|
-
Defeated = 3,
|
|
12
|
-
Succeeded = 4,
|
|
13
|
-
Queued = 5,
|
|
14
|
-
Expired = 6,
|
|
15
|
-
Executed = 7
|
|
16
|
-
}
|
|
17
|
-
declare enum VoteEnum {
|
|
18
|
-
AGAINST = "no",
|
|
19
|
-
FOR = "yes",
|
|
20
|
-
ABSTAIN = "abstain"
|
|
21
|
-
}
|
|
22
|
-
declare enum ProposalErrorCodes {
|
|
23
|
-
REQUIRED = "Required",
|
|
24
|
-
INVALID_AMOUNT = "Invalid amount",
|
|
25
|
-
NEGATIVE_AMOUNT = "Negative amount",
|
|
26
|
-
INVALID_ADDRESS = "Invalid address",
|
|
27
|
-
INVALID_ACTION = "Invalid action",
|
|
28
|
-
INVALID_ABI = "Invalid ABI",
|
|
29
|
-
MUST_BE_HTTPS = "Must be HTTPS",
|
|
30
|
-
MUST_BE_HTTPS_OR_IPFS = "Must be HTTPS or IPFS",
|
|
31
|
-
INVALID_BASEPATH = "Must be a berachain forum link",
|
|
32
|
-
/**
|
|
33
|
-
* Mainly used when it's not a reward vault
|
|
34
|
-
*/
|
|
35
|
-
INVALID_CONTRACT = "This is not a valid contract"
|
|
36
|
-
}
|
|
37
|
-
declare enum ProposalTypeEnum {
|
|
38
|
-
CUSTOM_PROPOSAL = "custom-action",
|
|
39
|
-
WHITELIST_REWARD_VAULT = "whitelist-reward-vault",
|
|
40
|
-
BLACKLIST_REWARD_VAULT = "blacklist-reward-vault",
|
|
41
|
-
ERC20_TRANSFER = "erc20-transfer",
|
|
42
|
-
WHITELIST_REWARD_VAULT_INCENTIVE = "whitelist-reward-vault-incentive"
|
|
43
|
-
}
|
|
44
|
-
declare const VoteColorMap: {
|
|
45
|
-
readonly yes: "#059669";
|
|
46
|
-
readonly 1: "#059669";
|
|
47
|
-
readonly no: "#DC2629";
|
|
48
|
-
readonly 2: "#DC2629";
|
|
49
|
-
readonly veto: "#0284C7";
|
|
50
|
-
readonly 4: "#0284C7";
|
|
51
|
-
readonly abstain: "#78716c";
|
|
52
|
-
readonly 3: "#78716c";
|
|
53
|
-
readonly yes_secondary: "#ECFDF5";
|
|
54
|
-
readonly no_secondary: "#FEF2F2";
|
|
55
|
-
readonly veto_secondary: "#F0F9FF";
|
|
56
|
-
readonly abstain_secondary: "#E7E5E4";
|
|
57
|
-
readonly default: "#57534e";
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* A list of contract names that are not mapped in the devrel's contract mapping or that are generated by factories (e.g. RewardVault).
|
|
62
|
-
*/
|
|
63
|
-
declare enum ContractName {
|
|
64
|
-
ENSO_ROUTER = "enso.router",
|
|
65
|
-
POL_REWARD_VAULT = "pol.rewardVault",
|
|
66
|
-
BEX_POOL = "bex.pool",
|
|
67
|
-
ERC20 = "others.erc20",
|
|
68
|
-
ERC4626 = "others.erc4626",
|
|
69
|
-
POL_STAKE_VAULT = "pol.stakeVault",
|
|
70
|
-
BEX_EXPLOITED_FUND_DISTRIBUTOR = "bex.exploitedFundDistributor",
|
|
71
|
-
TW_MINIMAL_ACCOUNT = "thirdweb.minimalAccount"
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { ContractName as C, ProposalState as P, VoteEnum as V, ProposalErrorCodes as a, ProposalTypeEnum as b, VoteColorMap as c };
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type React from "react";
|
|
2
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
-
import { useBeraWagmi, useConfig } from "@berachain/wagmi/hooks";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
createTransactionStore,
|
|
8
|
-
type TransactionStore,
|
|
9
|
-
} from "../hooks/transactions/transactionStore";
|
|
10
|
-
|
|
11
|
-
// Only allow a single instance of the store to exist at once
|
|
12
|
-
// so that multiple RainbowKitProvider instances can share the same store.
|
|
13
|
-
// We delay the creation of the store until the first time it is used
|
|
14
|
-
// so that it always has access to a provider.
|
|
15
|
-
let storeSingleton: ReturnType<typeof createTransactionStore> | undefined;
|
|
16
|
-
|
|
17
|
-
const TransactionStoreContext = createContext<TransactionStore | null>(null);
|
|
18
|
-
|
|
19
|
-
export function TransactionStoreProvider({
|
|
20
|
-
children,
|
|
21
|
-
}: {
|
|
22
|
-
children: React.ReactNode;
|
|
23
|
-
}) {
|
|
24
|
-
const { account } = useBeraWagmi();
|
|
25
|
-
const address = account?.wallet?.address;
|
|
26
|
-
const config = useConfig();
|
|
27
|
-
|
|
28
|
-
// Use existing store if it exists, or lazily create one
|
|
29
|
-
const [store] = useState(
|
|
30
|
-
() =>
|
|
31
|
-
storeSingleton ??
|
|
32
|
-
(storeSingleton = createTransactionStore({
|
|
33
|
-
config,
|
|
34
|
-
})),
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// Refresh pending transactions when address changes and periodically after.
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (!address) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const refresh = () => {
|
|
44
|
-
void store.refreshPendingTransactions(address);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
refresh();
|
|
48
|
-
|
|
49
|
-
// periodic refresh catches pending txs loaded from storage when no useTxn callbacks will fire.
|
|
50
|
-
// and are also not caught by the visibilitychange event when still pending.
|
|
51
|
-
const intervalId = setInterval(refresh, 120_000);
|
|
52
|
-
|
|
53
|
-
// refresh txs when the tab becomes visible again to catch txs confirmed while hidden.
|
|
54
|
-
const onVisibilityChange = () => {
|
|
55
|
-
if (document.visibilityState === "visible") {
|
|
56
|
-
refresh();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (typeof document !== "undefined") {
|
|
61
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return () => {
|
|
65
|
-
clearInterval(intervalId);
|
|
66
|
-
if (typeof document !== "undefined") {
|
|
67
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}, [store, address]);
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<TransactionStoreContext.Provider value={store}>
|
|
74
|
-
{children}
|
|
75
|
-
</TransactionStoreContext.Provider>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function useTransactionStore(): TransactionStore {
|
|
80
|
-
const store = useContext(TransactionStoreContext);
|
|
81
|
-
|
|
82
|
-
if (!store) {
|
|
83
|
-
throw new Error("Transaction hooks must be used within ");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return store;
|
|
87
|
-
}
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { type Config, getPublicClient } from "@wagmi/core";
|
|
2
|
-
import type { Address } from "viem";
|
|
3
|
-
|
|
4
|
-
import type { TransactionActionType } from "~/enum/txnEnum";
|
|
5
|
-
import { BeraMonitoring } from "~/errors/BeraMonitoring";
|
|
6
|
-
import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
|
|
7
|
-
import { initBeraError } from "~/errors/initBeraError";
|
|
8
|
-
|
|
9
|
-
const storageKeyLegacy = "rk-transactions";
|
|
10
|
-
const storageKey = "transactions";
|
|
11
|
-
|
|
12
|
-
export type TransactionStatus = "pending" | "confirmed" | "failed";
|
|
13
|
-
|
|
14
|
-
export interface Transaction {
|
|
15
|
-
hash: string;
|
|
16
|
-
description: string;
|
|
17
|
-
actionType?: TransactionActionType;
|
|
18
|
-
timestamp: number;
|
|
19
|
-
status: TransactionStatus;
|
|
20
|
-
confirmations?: number;
|
|
21
|
-
chainId: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type NewTransaction = Omit<Transaction, "status">;
|
|
25
|
-
|
|
26
|
-
export type DataLegacy = Record<
|
|
27
|
-
string,
|
|
28
|
-
Record<number, Transaction[] | undefined>
|
|
29
|
-
>;
|
|
30
|
-
export type Data = Record<string, Transaction[] | undefined>;
|
|
31
|
-
|
|
32
|
-
export function safeParseJsonData<T = DataLegacy | Data>(
|
|
33
|
-
string: string | null,
|
|
34
|
-
): T {
|
|
35
|
-
try {
|
|
36
|
-
const value = string ? JSON.parse(string) : {};
|
|
37
|
-
return typeof value === "object" ? value : {};
|
|
38
|
-
} catch {
|
|
39
|
-
return {} as T;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param legacyData - The legacy data to convert to the new data format.
|
|
45
|
-
* removes the nested chains and converts the data to a flat array.
|
|
46
|
-
* @returns Data in the new format with the chainId added to each transaction.
|
|
47
|
-
*/
|
|
48
|
-
export function convertLegacyDataToNewData(legacyData: DataLegacy): Data {
|
|
49
|
-
return Object.entries(legacyData).reduce((acc, [account, chains]) => {
|
|
50
|
-
return {
|
|
51
|
-
...acc,
|
|
52
|
-
[account]: Object.entries(chains).reduce(
|
|
53
|
-
(acc, [chainId, transactions]) => {
|
|
54
|
-
if (!transactions) {
|
|
55
|
-
return acc;
|
|
56
|
-
}
|
|
57
|
-
const transactionsArray = transactions.map(
|
|
58
|
-
(transaction): Transaction => ({
|
|
59
|
-
...transaction,
|
|
60
|
-
chainId: Number(chainId),
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
acc.push(...transactionsArray);
|
|
64
|
-
return acc;
|
|
65
|
-
},
|
|
66
|
-
[] as NewTransaction[],
|
|
67
|
-
),
|
|
68
|
-
};
|
|
69
|
-
}, {});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Filter out duplicate transactions by hash
|
|
74
|
-
*/
|
|
75
|
-
export const filterDuplicatefn = (
|
|
76
|
-
tx: Transaction,
|
|
77
|
-
idx: number,
|
|
78
|
-
arr: Transaction[],
|
|
79
|
-
) => arr.findIndex((otherTx) => otherTx.hash === tx.hash) === idx;
|
|
80
|
-
|
|
81
|
-
export function mergeData(legacyData: DataLegacy, newData: Data): Data {
|
|
82
|
-
const mergedData = convertLegacyDataToNewData(legacyData);
|
|
83
|
-
for (const [account, transactions] of Object.entries(newData)) {
|
|
84
|
-
if (mergedData[account] && transactions) {
|
|
85
|
-
// Merge and filter out duplicates by transaction hash
|
|
86
|
-
mergedData[account] = [...transactions, ...mergedData[account]].filter(
|
|
87
|
-
filterDuplicatefn,
|
|
88
|
-
);
|
|
89
|
-
} else {
|
|
90
|
-
mergedData[account] = transactions?.filter(filterDuplicatefn);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return mergedData;
|
|
94
|
-
}
|
|
95
|
-
function loadData(): Data {
|
|
96
|
-
const legacyData = safeParseJsonData<DataLegacy>(
|
|
97
|
-
typeof localStorage !== "undefined"
|
|
98
|
-
? localStorage.getItem(storageKeyLegacy)
|
|
99
|
-
: null,
|
|
100
|
-
);
|
|
101
|
-
const data = safeParseJsonData<Data>(
|
|
102
|
-
typeof localStorage !== "undefined"
|
|
103
|
-
? localStorage.getItem(storageKey)
|
|
104
|
-
: null,
|
|
105
|
-
);
|
|
106
|
-
return mergeData(legacyData, data);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const transactionHashRegex = /^0x([A-Fa-f0-9]{64})$/;
|
|
110
|
-
|
|
111
|
-
function validateTransaction(transaction: Transaction | NewTransaction): void {
|
|
112
|
-
if (!transactionHashRegex.test(transaction.hash)) {
|
|
113
|
-
throw new InvalidArgumentError({
|
|
114
|
-
property: "hash",
|
|
115
|
-
value: transaction.hash,
|
|
116
|
-
expected: "TransactionHash",
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (typeof transaction.description !== "string") {
|
|
121
|
-
throw new InvalidArgumentError({
|
|
122
|
-
property: "description",
|
|
123
|
-
value: transaction.description,
|
|
124
|
-
expected: "string",
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
typeof transaction.confirmations !== "undefined" &&
|
|
130
|
-
(!Number.isInteger(transaction.confirmations) ||
|
|
131
|
-
transaction.confirmations < 1)
|
|
132
|
-
) {
|
|
133
|
-
throw new InvalidArgumentError({
|
|
134
|
-
property: "confirmations",
|
|
135
|
-
value: transaction.confirmations,
|
|
136
|
-
expected: "positive integer",
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function createTransactionStore({ config }: { config: Config }) {
|
|
142
|
-
let data: Data = loadData();
|
|
143
|
-
const listeners: Set<() => void> = new Set();
|
|
144
|
-
const transactionRequestCache: Map<string, Promise<void>> = new Map();
|
|
145
|
-
|
|
146
|
-
function getTransactions(account: string): Transaction[] {
|
|
147
|
-
return data[account] ?? [];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function addTransaction(account: string, transaction: NewTransaction): void {
|
|
151
|
-
const normalized: Transaction = { ...transaction, status: "pending" };
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
validateTransaction(normalized);
|
|
155
|
-
|
|
156
|
-
updateTransactions(account, (transactions) => {
|
|
157
|
-
return [
|
|
158
|
-
normalized,
|
|
159
|
-
...transactions.filter(({ hash }) => {
|
|
160
|
-
// Omit any duplicate transactions
|
|
161
|
-
return hash !== normalized.hash;
|
|
162
|
-
}),
|
|
163
|
-
];
|
|
164
|
-
});
|
|
165
|
-
} catch (error) {
|
|
166
|
-
BeraMonitoring.captureException(initBeraError({ cause: error }));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function clearTransactions(account: string): void {
|
|
171
|
-
updateTransactions(account, () => {
|
|
172
|
-
return [];
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function setTransactionStatus(
|
|
177
|
-
account: string,
|
|
178
|
-
hash: string,
|
|
179
|
-
status: TransactionStatus,
|
|
180
|
-
): void {
|
|
181
|
-
updateTransactions(account, (transactions) => {
|
|
182
|
-
return transactions.map((transaction) =>
|
|
183
|
-
transaction.hash === hash ? { ...transaction, status } : transaction,
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async function refreshPendingTransactions(account: string): Promise<void> {
|
|
189
|
-
const pendingTransactions = getTransactions(account).filter(
|
|
190
|
-
(transaction) => transaction.status === "pending",
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
await Promise.allSettled(
|
|
194
|
-
pendingTransactions.map(async (transaction) => {
|
|
195
|
-
const { confirmations, hash, chainId } = transaction;
|
|
196
|
-
const existingRequest = transactionRequestCache.get(hash);
|
|
197
|
-
|
|
198
|
-
if (existingRequest) {
|
|
199
|
-
return await existingRequest;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const provider = getPublicClient(config, { chainId });
|
|
203
|
-
if (!provider) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const requestPromise = provider
|
|
208
|
-
.waitForTransactionReceipt({ confirmations, hash: hash as Address })
|
|
209
|
-
.then(({ status }) => {
|
|
210
|
-
if (status === undefined) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
setTransactionStatus(
|
|
215
|
-
account,
|
|
216
|
-
hash,
|
|
217
|
-
Number(status) === 0 ? "failed" : "confirmed",
|
|
218
|
-
);
|
|
219
|
-
})
|
|
220
|
-
.catch((error) => {
|
|
221
|
-
BeraMonitoring.captureException(initBeraError({ cause: error }));
|
|
222
|
-
})
|
|
223
|
-
.finally(() => {
|
|
224
|
-
transactionRequestCache.delete(hash);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
transactionRequestCache.set(hash, requestPromise);
|
|
228
|
-
|
|
229
|
-
return await requestPromise;
|
|
230
|
-
}),
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function updateTransactions(
|
|
235
|
-
account: string,
|
|
236
|
-
updateFn: (transactions: Transaction[]) => Transaction[],
|
|
237
|
-
): void {
|
|
238
|
-
// Ensure we’re always operating on the latest data in case we have
|
|
239
|
-
// multiple instances/tabs/etc. since we write all data back to
|
|
240
|
-
// local storage after updating
|
|
241
|
-
data = loadData();
|
|
242
|
-
|
|
243
|
-
data[account] = data[account] ?? [];
|
|
244
|
-
|
|
245
|
-
const MAX_TRANSACTIONS = 10;
|
|
246
|
-
const updatedTransactions = updateFn(data?.[account] ?? []);
|
|
247
|
-
|
|
248
|
-
const transactions = updatedTransactions
|
|
249
|
-
// Sort by timestamp (latest first) and keep only the latest 10
|
|
250
|
-
.sort((a, b) => b.timestamp - a.timestamp)
|
|
251
|
-
.slice(0, MAX_TRANSACTIONS);
|
|
252
|
-
|
|
253
|
-
data[account] =
|
|
254
|
-
transactions.length > 0
|
|
255
|
-
? transactions.filter(filterDuplicatefn)
|
|
256
|
-
: undefined;
|
|
257
|
-
|
|
258
|
-
persistData();
|
|
259
|
-
notifyListeners();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function persistData(): void {
|
|
263
|
-
if (typeof localStorage === "undefined") {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
localStorage.setItem(storageKey, JSON.stringify(data));
|
|
268
|
-
// remove legacy data now that it has been converted to the new data format and saved to the new key
|
|
269
|
-
localStorage.removeItem(storageKeyLegacy);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function notifyListeners(): void {
|
|
273
|
-
for (const listener of listeners) {
|
|
274
|
-
listener();
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function onChange(fn: () => void): () => void {
|
|
279
|
-
listeners.add(fn);
|
|
280
|
-
|
|
281
|
-
return () => {
|
|
282
|
-
listeners.delete(fn);
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return {
|
|
287
|
-
addTransaction,
|
|
288
|
-
clearTransactions,
|
|
289
|
-
getTransactions,
|
|
290
|
-
onChange,
|
|
291
|
-
refreshPendingTransactions,
|
|
292
|
-
setTransactionStatus,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export type TransactionStore = ReturnType<typeof createTransactionStore>;
|