@shapeshiftoss/contracts 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/constants.d.ts +0 -6596
- package/dist/cjs/constants.js +1 -31
- package/dist/cjs/contractManager.d.ts +8 -11
- package/dist/cjs/contractManager.js +38 -63
- package/dist/cjs/ethersProviderSingleton.d.ts +0 -3
- package/dist/cjs/ethersProviderSingleton.js +2 -23
- package/dist/cjs/types.d.ts +1 -18
- package/dist/cjs/types.js +0 -7
- package/dist/cjs/viemClient.d.ts +6414 -6418
- package/dist/cjs/viemClient.js +48 -147
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/constants.d.ts +0 -6596
- package/dist/esm/constants.js +0 -30
- package/dist/esm/contractManager.d.ts +8 -11
- package/dist/esm/contractManager.js +39 -65
- package/dist/esm/ethersProviderSingleton.d.ts +0 -3
- package/dist/esm/ethersProviderSingleton.js +1 -20
- package/dist/esm/types.d.ts +1 -18
- package/dist/esm/types.js +1 -6
- package/dist/esm/viemClient.d.ts +6414 -6418
- package/dist/esm/viemClient.js +47 -146
- package/package.json +4 -5
package/dist/esm/constants.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { erc20Abi } from 'viem';
|
|
2
|
-
import { EVERGREEN_FARMING_ABI } from './abis/evergreenFarming.js';
|
|
3
|
-
import { FARMING_ABI } from './abis/farming.js';
|
|
4
|
-
import { I_UNISWAP_V2_PAIR_ABI } from './abis/iUniswapV2Pair.js';
|
|
5
|
-
import { THORCHAIN_ROUTER_ABI } from './abis/thorchainRouter.js';
|
|
6
|
-
import { UNISWAP_V2_ROUTER_02_ABI } from './abis/uniswapV2Router02.js';
|
|
7
|
-
import { ContractType } from './types.js';
|
|
8
1
|
export const WETH_TOKEN_CONTRACT = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
9
|
-
export const FOX_TOKEN_CONTRACT = '0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d';
|
|
10
2
|
// Staking contract addresses as string literals
|
|
11
3
|
export const ETH_FOX_STAKING_V1_CONTRACT = '0xdd80e21669a664bce83e3ad9a0d74f8dad5d9e72';
|
|
12
4
|
export const ETH_FOX_STAKING_V2_CONTRACT = '0xc54b9f82c1c54e9d4d274d633c7523f2299c42a0';
|
|
@@ -46,28 +38,6 @@ export const RFOX_ARB_UNI_V2_ETH_FOX_PROXY_CONTRACT = '0x83B51B7605d2E277E03A7D6
|
|
|
46
38
|
export const RFOX_ETH_PROXY_CONTRACT = '0x7AC9c77263473A9e1DC9621F97b886c1e90Ddd33';
|
|
47
39
|
export const RFOX_REWARD_RATE = 1n * 10n ** 27n;
|
|
48
40
|
export const RFOX_WAD = 1n * 10n ** 18n;
|
|
49
|
-
export const CONTRACT_ADDRESS_TO_ABI = {
|
|
50
|
-
[ETH_FOX_POOL_CONTRACT]: I_UNISWAP_V2_PAIR_ABI,
|
|
51
|
-
[ETH_FOX_STAKING_V1_CONTRACT]: FARMING_ABI,
|
|
52
|
-
[ETH_FOX_STAKING_V2_CONTRACT]: FARMING_ABI,
|
|
53
|
-
[ETH_FOX_STAKING_V3_CONTRACT]: FARMING_ABI,
|
|
54
|
-
[ETH_FOX_STAKING_V4_CONTRACT]: FARMING_ABI,
|
|
55
|
-
[ETH_FOX_STAKING_V5_CONTRACT]: FARMING_ABI,
|
|
56
|
-
[ETH_FOX_STAKING_V6_CONTRACT]: FARMING_ABI,
|
|
57
|
-
[ETH_FOX_STAKING_V7_CONTRACT]: FARMING_ABI,
|
|
58
|
-
[ETH_FOX_STAKING_V8_CONTRACT]: FARMING_ABI,
|
|
59
|
-
[ETH_FOX_STAKING_V9_CONTRACT]: FARMING_ABI,
|
|
60
|
-
[ETH_FOX_STAKING_EVERGREEN_CONTRACT]: EVERGREEN_FARMING_ABI,
|
|
61
|
-
[FOX_TOKEN_CONTRACT]: erc20Abi,
|
|
62
|
-
[UNISWAP_V2_ROUTER_02_CONTRACT_MAINNET]: UNISWAP_V2_ROUTER_02_ABI,
|
|
63
|
-
// THOR Router Mainnet
|
|
64
|
-
[THOR_ROUTER_CONTRACT_MAINNET]: THORCHAIN_ROUTER_ABI,
|
|
65
|
-
};
|
|
66
|
-
export const CONTRACT_TYPE_TO_ABI = {
|
|
67
|
-
[ContractType.UniV2Pair]: I_UNISWAP_V2_PAIR_ABI,
|
|
68
|
-
[ContractType.ERC20]: erc20Abi,
|
|
69
|
-
[ContractType.ThorRouter]: THORCHAIN_ROUTER_ABI,
|
|
70
|
-
};
|
|
71
41
|
// 0x proxy contracts - all EVM chains except Optimism have the same address
|
|
72
42
|
export const ZRX_ETHEREUM_PROXY_CONTRACT = '0xDef1C0ded9bec7F1a1670819833240f027b25EfF';
|
|
73
43
|
export const ZRX_OPTIMISM_PROXY_CONTRACT = '0xDEF1ABE32c034e558Cdd535791643C58a13aCC10';
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { AssetId
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
chainId: ChainId;
|
|
10
|
-
}) => KnownContractByType<A, T>;
|
|
11
|
-
export declare const fetchUniV2PairData: ((pairAssetId: AssetId) => Promise<import("@uniswap/sdk").Pair>) & import("lodash").MemoizedFunction;
|
|
1
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { Pair } from '@uniswap/sdk';
|
|
3
|
+
import type { Address, GetContractReturnType, PublicClient } from 'viem';
|
|
4
|
+
import { I_UNISWAP_V2_PAIR_ABI } from './abis/index.js';
|
|
5
|
+
import type { FoxEthStakingContractAbi, FoxEthStakingContractAddress } from './types.js';
|
|
6
|
+
export declare const getFoxEthStakingContract: (address: FoxEthStakingContractAddress) => GetContractReturnType<FoxEthStakingContractAbi, PublicClient, Address>;
|
|
7
|
+
export declare const getEthFoxPoolContract: () => GetContractReturnType<typeof I_UNISWAP_V2_PAIR_ABI, PublicClient, Address>;
|
|
8
|
+
export declare const fetchUniV2PairData: (pairAssetId: AssetId) => Promise<Pair>;
|
|
@@ -1,69 +1,43 @@
|
|
|
1
|
-
import { fromAssetId,
|
|
2
|
-
import {
|
|
3
|
-
import { Fetcher } from '@uniswap/sdk';
|
|
4
|
-
import assert from 'assert';
|
|
1
|
+
import { fromAssetId, fromChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { Pair, Token, TokenAmount } from '@uniswap/sdk';
|
|
5
3
|
import memoize from 'lodash/memoize';
|
|
6
|
-
import { getAddress, getContract } from 'viem';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
address: checksumAddress,
|
|
22
|
-
client: viemEthMainnetClient,
|
|
23
|
-
});
|
|
24
|
-
definedContracts[checksumAddress] = contract;
|
|
25
|
-
return contract;
|
|
26
|
-
};
|
|
27
|
-
export const getOrCreateContractByType = ({ address, type, chainId, }) => {
|
|
28
|
-
const checksumAddress = getAddress(address);
|
|
29
|
-
const definedContract = definedContracts[checksumAddress];
|
|
30
|
-
if (definedContract !== undefined) {
|
|
31
|
-
return definedContract;
|
|
32
|
-
}
|
|
33
|
-
const publicClient = viemClientByChainId[chainId];
|
|
34
|
-
assert(publicClient !== undefined, `no public client found for chainId '${chainId}'`);
|
|
35
|
-
const contract = getContract({
|
|
36
|
-
abi: CONTRACT_TYPE_TO_ABI[type],
|
|
37
|
-
address: checksumAddress,
|
|
38
|
-
client: publicClient,
|
|
39
|
-
});
|
|
40
|
-
definedContracts[checksumAddress] = contract;
|
|
41
|
-
return contract;
|
|
42
|
-
};
|
|
43
|
-
export const fetchUniV2PairData = memoize(async (pairAssetId) => {
|
|
4
|
+
import { erc20Abi, getAddress, getContract } from 'viem';
|
|
5
|
+
import { EVERGREEN_FARMING_ABI, FARMING_ABI, I_UNISWAP_V2_PAIR_ABI } from './abis/index.js';
|
|
6
|
+
import { ETH_FOX_POOL_CONTRACT, ETH_FOX_STAKING_EVERGREEN_CONTRACT } from './constants.js';
|
|
7
|
+
import { assertGetViemClient, viemEthMainnetClient } from './viemClient.js';
|
|
8
|
+
export const getFoxEthStakingContract = (address) => getContract({
|
|
9
|
+
abi: address === ETH_FOX_STAKING_EVERGREEN_CONTRACT ? EVERGREEN_FARMING_ABI : FARMING_ABI,
|
|
10
|
+
address: getAddress(address),
|
|
11
|
+
client: viemEthMainnetClient,
|
|
12
|
+
});
|
|
13
|
+
export const getEthFoxPoolContract = () => getContract({
|
|
14
|
+
abi: I_UNISWAP_V2_PAIR_ABI,
|
|
15
|
+
address: ETH_FOX_POOL_CONTRACT,
|
|
16
|
+
client: viemEthMainnetClient,
|
|
17
|
+
});
|
|
18
|
+
const getUniV2PairTokens = memoize(async (pairAssetId) => {
|
|
44
19
|
const { assetReference, chainId } = fromAssetId(pairAssetId);
|
|
45
|
-
const
|
|
46
|
-
const pair =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
const ethersV5Provider = getEthersV5Provider();
|
|
52
|
-
const token0Address = await pair.read.token0();
|
|
53
|
-
const token1Address = await pair.read.token1();
|
|
54
|
-
const token0AssetId = toAssetId({
|
|
55
|
-
chainId,
|
|
56
|
-
assetNamespace: 'erc20',
|
|
57
|
-
assetReference: token0Address,
|
|
58
|
-
});
|
|
59
|
-
const token1AssetId = toAssetId({
|
|
60
|
-
chainId,
|
|
61
|
-
assetNamespace: 'erc20',
|
|
62
|
-
assetReference: token1Address,
|
|
20
|
+
const client = assertGetViemClient(chainId);
|
|
21
|
+
const pair = getContract({
|
|
22
|
+
abi: I_UNISWAP_V2_PAIR_ABI,
|
|
23
|
+
address: getAddress(assetReference),
|
|
24
|
+
client,
|
|
63
25
|
});
|
|
64
|
-
const
|
|
65
|
-
const {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
26
|
+
const [token0Address, token1Address] = await Promise.all([pair.read.token0(), pair.read.token1()]);
|
|
27
|
+
const [decimals0, decimals1] = await Promise.all([token0Address, token1Address].map(address => client.readContract({ address, abi: erc20Abi, functionName: 'decimals' })));
|
|
28
|
+
const evmChainId = Number(fromChainId(chainId).chainReference);
|
|
29
|
+
return {
|
|
30
|
+
pair,
|
|
31
|
+
token0: new Token(evmChainId, token0Address, decimals0),
|
|
32
|
+
token1: new Token(evmChainId, token1Address, decimals1),
|
|
33
|
+
};
|
|
69
34
|
});
|
|
35
|
+
export const fetchUniV2PairData = async (pairAssetId) => {
|
|
36
|
+
const { pair, token0, token1 } = await getUniV2PairTokens(pairAssetId).catch(err => {
|
|
37
|
+
getUniV2PairTokens.cache.delete(pairAssetId);
|
|
38
|
+
throw err;
|
|
39
|
+
});
|
|
40
|
+
const [reserve0, reserve1] = await pair.read.getReserves();
|
|
41
|
+
// a uniswap v2 pair's token0 always sorts before token1, so reserves are already in token order
|
|
42
|
+
return new Pair(new TokenAmount(token0, reserve0.toString()), new TokenAmount(token1, reserve1.toString()));
|
|
43
|
+
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import type { EvmChainId } from '@shapeshiftoss/types';
|
|
2
|
-
import { JsonRpcProvider } from 'ethers';
|
|
3
2
|
import { ethers as ethersV5 } from 'ethers5';
|
|
4
|
-
export declare const rpcUrlByChainId: (chainId: EvmChainId) => string;
|
|
5
|
-
export declare const getEthersProvider: (chainId: EvmChainId) => JsonRpcProvider;
|
|
6
3
|
export declare const getEthersV5Provider: (chainId?: EvmChainId) => ethersV5.providers.JsonRpcProvider;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
2
|
import { assertUnreachable } from '@shapeshiftoss/utils';
|
|
3
|
-
import { JsonRpcProvider } from 'ethers';
|
|
4
3
|
import { ethers as ethersV5 } from 'ethers5';
|
|
5
4
|
import { PUBLIC_RPC_URLS } from './publicRpcUrls.js';
|
|
6
|
-
|
|
5
|
+
const rpcUrlByChainId = (chainId) => {
|
|
7
6
|
const url = (() => {
|
|
8
7
|
switch (chainId) {
|
|
9
8
|
// First-class chains: env-driven with public fallback
|
|
@@ -89,25 +88,7 @@ export const rpcUrlByChainId = (chainId) => {
|
|
|
89
88
|
}
|
|
90
89
|
return url;
|
|
91
90
|
};
|
|
92
|
-
const ethersProviders = new Map();
|
|
93
91
|
const ethersV5Providers = new Map();
|
|
94
|
-
export const getEthersProvider = (chainId) => {
|
|
95
|
-
if (!ethersProviders.has(chainId)) {
|
|
96
|
-
const provider = new JsonRpcProvider(rpcUrlByChainId(chainId), undefined, {
|
|
97
|
-
staticNetwork: true,
|
|
98
|
-
});
|
|
99
|
-
ethersProviders.set(chainId, provider);
|
|
100
|
-
return provider;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
// This really should be defined but I guess enough safety never hurts mang...
|
|
104
|
-
const provider = ethersProviders.get(chainId);
|
|
105
|
-
if (!provider) {
|
|
106
|
-
throw new Error(`No provider found for chainId ${chainId}`);
|
|
107
|
-
}
|
|
108
|
-
return provider;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
92
|
// For backwards-compatibility for libraries still stuck in v5
|
|
112
93
|
export const getEthersV5Provider = (chainId = KnownChainIds.EthereumMainnet) => {
|
|
113
94
|
if (!ethersV5Providers.has(chainId)) {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import type { Address, GetContractReturnType, PublicClient } from 'viem';
|
|
2
1
|
import type { EVERGREEN_FARMING_ABI, FARMING_ABI } from './abis/index.js';
|
|
3
|
-
import type {
|
|
4
|
-
export declare enum ContractType {
|
|
5
|
-
UniV2Pair = "UniV2Pair",
|
|
6
|
-
ERC20 = "ERC20",
|
|
7
|
-
ThorRouter = "ThorRouter"
|
|
8
|
-
}
|
|
9
|
-
export type KnownContractAbiByAddress<T extends KnownContractAddress> = (typeof CONTRACT_ADDRESS_TO_ABI)[T];
|
|
10
|
-
export type KnownContractAbiByType<T extends ContractType> = (typeof CONTRACT_TYPE_TO_ABI)[T];
|
|
11
|
-
export type KnownContractByAddress<T extends KnownContractAddress> = GetContractReturnType<KnownContractAbiByAddress<T>, PublicClient, T>;
|
|
12
|
-
export type KnownContract = KnownContractByAddress<KnownContractAddress>;
|
|
13
|
-
export type KnownContractByType<A extends KnownContractAddress, T extends ContractType> = GetContractReturnType<KnownContractAbiByType<T>, PublicClient, A>;
|
|
14
|
-
export type KnownContractAddress = typeof ETH_FOX_POOL_CONTRACT | FoxEthStakingContractAddress | typeof FOX_TOKEN_CONTRACT | typeof UNISWAP_V2_ROUTER_02_CONTRACT_MAINNET | typeof THOR_ROUTER_CONTRACT_MAINNET;
|
|
15
|
-
export type DefinedContract = {
|
|
16
|
-
contract: KnownContractByAddress<KnownContractAddress>;
|
|
17
|
-
address: KnownContractAddress;
|
|
18
|
-
};
|
|
2
|
+
import type { foxEthStakingContractAddresses } from './constants.js';
|
|
19
3
|
export type FoxEthStakingContractAddress = (typeof foxEthStakingContractAddresses)[number];
|
|
20
4
|
export type FoxEthStakingContractAbi = typeof FARMING_ABI | typeof EVERGREEN_FARMING_ABI;
|
|
21
|
-
export type FoxEthStakingContract<T extends FoxEthStakingContractAbi> = T extends typeof FARMING_ABI ? GetContractReturnType<typeof FARMING_ABI, PublicClient, Address> : GetContractReturnType<typeof EVERGREEN_FARMING_ABI, PublicClient, Address>;
|