forked from hummingbot/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import abi from '../ethereum/ethereum.abi.json'; | ||
import { logger } from '../../services/logger'; | ||
import { Contract, Transaction, Wallet } from 'ethers'; | ||
import { EthereumBase } from '../ethereum/ethereum-base'; | ||
import { getEthereumConfig as getPolygonConfig } from '../ethereum/ethereum.config'; | ||
import { Provider } from '@ethersproject/abstract-provider'; | ||
import { UniswapConfig } from '../../connectors/uniswap/uniswap.config'; | ||
import { Ethereumish } from '../../services/common-interfaces'; | ||
import { ConfigManagerV2 } from '../../services/config-manager-v2'; | ||
|
||
export class Xdc extends EthereumBase implements Ethereumish { | ||
private static _instances: { [name: string]: Xdc }; | ||
private _gasPrice: number; | ||
private _nativeTokenSymbol: string; | ||
private _chain: string; | ||
|
||
private constructor(network: string) { | ||
const config = getPolygonConfig('xdc', network); | ||
super( | ||
'xdc', | ||
config.network.chainID, | ||
config.network.nodeURL, | ||
config.network.tokenListSource, | ||
config.network.tokenListType, | ||
config.manualGasPrice, | ||
config.gasLimitTransaction, | ||
ConfigManagerV2.getInstance().get('server.nonceDbPath'), | ||
ConfigManagerV2.getInstance().get('server.transactionDbPath') | ||
); | ||
this._chain = config.network.name; | ||
this._nativeTokenSymbol = config.nativeCurrencySymbol; | ||
this._gasPrice = config.manualGasPrice; | ||
} | ||
|
||
public static getInstance(network: string): Xdc { | ||
if (Xdc._instances === undefined) { | ||
Xdc._instances = {}; | ||
} | ||
if (!(network in Xdc._instances)) { | ||
Xdc._instances[network] = new Xdc(network); | ||
} | ||
|
||
return Xdc._instances[network]; | ||
} | ||
|
||
public static getConnectedInstances(): { [name: string]: Xdc } { | ||
return Xdc._instances; | ||
} | ||
|
||
public get gasPrice(): number { | ||
return this._gasPrice; | ||
} | ||
|
||
public get nativeTokenSymbol(): string { | ||
return this._nativeTokenSymbol; | ||
} | ||
|
||
public get chain(): string { | ||
return this._chain; | ||
} | ||
|
||
getContract(tokenAddress: string, signerOrProvider?: Wallet | Provider) { | ||
return new Contract(tokenAddress, abi.ERC20Abi, signerOrProvider); | ||
} | ||
|
||
getSpender(reqSpender: string): string { | ||
let spender: string; | ||
if (reqSpender === 'uniswap') { | ||
spender = UniswapConfig.config.uniswapV3SmartOrderRouterAddress( | ||
this._chain | ||
); | ||
} else { | ||
spender = reqSpender; | ||
} | ||
return spender; | ||
} | ||
|
||
// cancel transaction | ||
async cancelTx(wallet: Wallet, nonce: number): Promise<Transaction> { | ||
logger.info( | ||
'Canceling any existing transaction(s) with nonce number ' + nonce + '.' | ||
); | ||
return super.cancelTxWithGasPrice(wallet, nonce, this._gasPrice * 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
mkRequestValidator, | ||
mkValidator, | ||
RequestValidator, | ||
Validator, | ||
validateAmount, | ||
validateToken, | ||
validateTokenSymbols, | ||
} from '../../services/validators'; | ||
import { | ||
isAddress, | ||
validateNonce, | ||
validateAddress, | ||
} from '../ethereum/ethereum.validators'; | ||
|
||
export const invalidSpenderError: string = | ||
'The spender param is not a valid xdc address (0x followed by 40 hexidecimal characters).'; | ||
|
||
// given a request, look for a key called spender that is 'uniswap', 'sushi' or an Ethereum address | ||
export const validateSpender: Validator = mkValidator( | ||
'spender', | ||
invalidSpenderError, | ||
(val) => typeof val === 'string' && (val === 'uniswap' || isAddress(val)) | ||
); | ||
|
||
export const validateXdcApproveRequest: RequestValidator = | ||
mkRequestValidator([ | ||
validateAddress, | ||
validateSpender, | ||
validateToken, | ||
validateAmount, | ||
validateNonce, | ||
]); | ||
|
||
export const validateXdcAllowancesRequest: RequestValidator = | ||
mkRequestValidator([validateAddress, validateSpender, validateTokenSymbols]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "apothem", | ||
"tokens": [ | ||
{ | ||
"symbol": "WXDC", | ||
"chainId": 51, | ||
"address": "0x2a5c77b016Df1b3b0AE4E79a68F8adF64Ee741ba", | ||
"decimals": 18 | ||
}, | ||
{ | ||
"symbol": "WBTC2", | ||
"chainId": 51, | ||
"address": "0x01B0500f82EF188D0410a46f2E8940133E213e83", | ||
"decimals": 8 | ||
}, | ||
{ | ||
"symbol": "YFI2", | ||
"chainId": 51, | ||
"address": "0x22e4Eb82FF59c53B275aDEacd4EE4Bc47fc4f16d", | ||
"decimals": 18 | ||
}, | ||
{ | ||
"symbol": "MKR2", | ||
"chainId": 51, | ||
"address": "0x258E445fEf3F41429e38ee124DA63aBfb08edc70", | ||
"decimals": 18 | ||
}, | ||
{ | ||
"symbol": "AAVE2", | ||
"chainId": 51, | ||
"address": "0x3042207876c47D3c206df99b3279d97813B34Ea1", | ||
"decimals": 18 | ||
}, | ||
{ | ||
"symbol": "UNI2", | ||
"chainId": 51, | ||
"address": "0xD9e33607d06cBB1Fef59488b9969426b10F310B8", | ||
"decimals": 18 | ||
}, | ||
{ | ||
"symbol": "USDC2", | ||
"chainId": 51, | ||
"address": "0xF83B9Dc502A3F76c042b4043B6C1B5eBBE574389", | ||
"decimals": 6 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# list the xdc networks available to gateway | ||
networks: | ||
xinfin: | ||
chainID: 50 | ||
nodeURL: https://erpc.xinfin.network | ||
tokenListType: 'URL' | ||
tokenListSource: 'https://raw.githubusercontent.com/pro100skm/xdc-token-list/master/mainnet.tokenlist.json' | ||
nativeCurrencySymbol: 'XDC' | ||
apothem: | ||
chainID: 51 | ||
nodeURL: https://erpc.apothem.network | ||
tokenListType: 'FILE' | ||
tokenListSource: 'src/chains/xdc/xdc_tokens_apothem.json' | ||
nativeCurrencySymbol: 'XDC' | ||
|
||
manualGasPrice: 1 | ||
gasLimitTransaction: 3000000 |