ptokens-utils
Version:
repo holding some utils needed by other packages
2,166 lines (2,136 loc) • 83.8 kB
JavaScript
import algosdk, { makeAssetTransferTxnWithSuggestedParamsFromObject, getApplicationAddress, makeApplicationCallTxnFromObject, encodeUint64, decodeAddress, assignGroupID, waitForConfirmation } from 'algosdk';
import validate from 'bitcoin-address-validation';
import axios from 'axios';
import polling from 'light-async-polling';
import BigNumber from 'bignumber.js';
import Web3PromiEvent from 'web3-core-promievent';
import { JsonRpc, Api } from 'eosjs';
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig';
import fetch from 'node-fetch';
import encoding from 'text-encoding';
import { encode } from '@msgpack/msgpack';
function isValidAddress(str, allowAppId = false) {
if (allowAppId && parseInt(str)) return true;
return algosdk.isValidAddress(str);
}
const waitForTransactionConfirmation = (_client, _txIdx) => algosdk.waitForConfirmation(_client, _txIdx, 4);
var algo = /*#__PURE__*/Object.freeze({
__proto__: null,
isValidAddress: isValidAddress,
waitForTransactionConfirmation: waitForTransactionConfirmation
});
const Eosio = 'eosio';
const Ethereum = 'ethereum';
const Bitcoin = 'bitcoin';
const Litecoin = 'litecoin';
const Telos = 'telos';
const Dogecoin = 'dogecoin';
const BinanceSmartChain = 'binance-smart-chain';
const Polygon = 'polygon';
const Xdai = 'xdai';
const Ravencoin = 'ravencoin';
const Lbry = 'lbry';
const Ultra = 'ultra';
const Arbitrum = 'arbitrum';
const Luxochain = 'luxochain';
const Algorand = 'algorand';
const Fantom = 'fantom';
const Ore = 'ore';
const Libre = 'libre';
const Testnet = 'testnet';
const Mainnet = 'mainnet';
const BitcoinMainnet = 'mainnet';
const BitcoinTestnet = 'testnet';
const EthereumMainnet = 'mainnet';
const EthereumRopsten = 'testnet_ropsten';
const EosioMainnet = 'mainnet';
const EosioJungle3 = 'testnet_jungle3';
const LitecoinMainnet = 'mainnet';
const LitecoinTestnet = 'testnet';
const TelosMainnet = 'mainnet';
const DogecoinMainnet = 'mainnet';
const BinanceSmartChainMainnet = 'mainnet';
const PolygonMainnet = 'mainnet';
const XdaiMainnet = 'mainnet';
const RavencoinMainnet = 'mainnet';
const LbryMainnet = 'mainnet';
const UltraMainnet = 'mainnet';
const UltraTestnet = 'testnet';
const ArbitrumMainnet = 'mainnet';
const LuxochainMainnet = 'mainnet';
const AlgorandMainnet = 'mainnet';
const FantomMainnet = 'mainnet';
const OreMainnet = 'mainnet';
const LibreMainnet = 'mainnet';
const pBTC = 'pbtc';
const pLTC = 'pltc';
const pETH = 'peth';
const pWETH = 'pweth';
const pMKR = 'pmkr';
const pLINK = 'plink';
const pYFI = 'pyfi';
const PNT = 'pnt';
const PTERIA = 'pteria';
const pUNI = 'puni';
const pBAND = 'pband';
const pBAL = 'pbal';
const pCOMP = 'pcomp';
const pSNX = 'psnx';
const pOMG = 'pomg';
const pDAI = 'pdai';
const pANT = 'pant';
const pLRC = 'plrc';
const pUOS = 'puos';
const pBAT = 'pbat';
const pREP = 'prep';
const pZRX = 'pzrx';
const pPNK = 'ppnk';
const pDOGE = 'pdoge';
const pEOS = 'peos';
const IQ = 'iq';
const TLOS = 'tlos';
const pOPIUM = 'popium';
const pBCP = 'pbcp';
const pDEFIPlusPlus = 'pdefiplusplus';
const CGG = 'cgg';
const pUSDC = 'pusdc';
const pUSDT = 'pusdt';
const pRVN = 'prvn';
const pOPEN = 'popen';
const OCP = 'ocp';
const ANRX = 'anrx';
const TFF = 'tff';
const pSAFEMOON = 'psafemoon';
const EFX = 'efx';
const pSEEDS = 'pseeds';
const pLBC = 'plbc';
const USDO = 'usdo';
const GALA = 'gala';
const ZMT = 'zmt';
const BIST = 'bist';
const pVAI = 'pvai';
const WSB = 'wsb';
const LUXO = 'luxo';
const pTET = 'ptet';
const pKEYS = 'pkeys';
const OATH = 'oath';
const pFTM = 'pftm';
const pWFTM = 'pwftm';
const NUCO = 'nuco';
const ORE = 'ore';
const BLOCKSTREAM_BASE_TESTNET_ENDPOINT = 'https://blockstream.info/testnet/api/';
const BLOCKSTREAM_BASE_MAINNET_ENDPOINT = 'https://blockstream.info/api/';
const _getEsploraApi = _network => axios.create({
baseURL: _network === Mainnet ? BLOCKSTREAM_BASE_MAINNET_ENDPOINT : BLOCKSTREAM_BASE_TESTNET_ENDPOINT,
timeout: 50000,
headers: {
'Content-Type': 'text/plain'
}
});
const _makeEsploraApiCall = (_network, _callType, _apiPath, _params) => new Promise((resolve, reject) => {
_getEsploraApi(_network)[_callType.toLowerCase()](_apiPath, _params).then(_res => resolve(_res.data)).catch(_err => reject(_err));
});
const broadcastTransaction = (_network, _tx) => _makeEsploraApiCall(_network, 'POST', '/tx', _tx);
const getUtxoByAddress = (_network, _address) => _makeEsploraApiCall(_network, 'GET', `/address/${_address}/utxo`);
const getTransactionHexById = (_network, _txId) => _makeEsploraApiCall(_network, 'GET', `/tx/${_txId}/hex`);
const isValidAddress$1 = _address => Boolean(validate(_address));
const monitorUtxoByAddress = async (_network, _address, _eventEmitter, _pollingTime, _broadcastEventName, _confirmationEventName, _maxRetries = 5) => {
let isBroadcasted = false;
let txId = null;
let utxos = [];
let retries = 0;
await polling(async () => {
try {
utxos = await _makeEsploraApiCall(_network, 'GET', `/address/${_address}/utxo`);
if (utxos.length > 0) {
if (utxos[0].status.confirmed) {
if (!isBroadcasted) {
_eventEmitter.emit(_broadcastEventName, utxos[0]);
_eventEmitter.emit('onBtcTxBroadcasted', utxos[0]);
}
_eventEmitter.emit(_confirmationEventName, utxos[0]);
_eventEmitter.emit('onBtcTxConfirmed', utxos[0]);
txId = utxos[0].txid;
return true;
} else if (!isBroadcasted) {
isBroadcasted = true;
_eventEmitter.emit(_broadcastEventName, utxos[0]);
_eventEmitter.emit('onBtcTxBroadcasted', utxos[0]);
return false;
}
} else {
return false;
}
} catch (_err) {
if (retries === _maxRetries) throw _err;
retries += 1;
return false;
}
}, _pollingTime);
return txId;
};
const waitForTransactionConfirmation$1 = async (_network, _tx, _pollingTime) => {
let transaction = null;
await polling(async () => {
try {
transaction = await _makeEsploraApiCall(_network, 'GET', `/tx/${_tx}`);
if (!transaction || !transaction.status) return false;
return transaction.status.confirmed;
} catch (err) {
return false;
}
}, _pollingTime);
return transaction;
};
var btc = /*#__PURE__*/Object.freeze({
__proto__: null,
broadcastTransaction: broadcastTransaction,
isValidAddress: isValidAddress$1,
getUtxoByAddress: getUtxoByAddress,
getTransactionHexById: getTransactionHexById,
monitorUtxoByAddress: monitorUtxoByAddress,
waitForTransactionConfirmation: waitForTransactionConfirmation$1
});
const DOGE_CHAIN_API = 'https://dogechain.info/api/v1';
const _getDogeChainApi = _network => {
if (_network === Testnet) throw new Error('Dogecoin on Testnet is not supported');
return axios.create({
baseURL: DOGE_CHAIN_API,
timeout: 50000,
headers: {
'Content-Type': 'application/json'
}
});
};
const _makeDogeChainApiCall = (_network, _callType, _apiPath, _params) => new Promise((resolve, reject) => {
_getDogeChainApi(_network)[_callType.toLowerCase()](_apiPath, _params).then(_res => resolve(_res.data)).catch(_err => reject(_err));
});
const broadcastTransaction$1 = (_network, _tx) => _makeDogeChainApiCall(_network, 'POST', '/pushtx', {
tx: _tx
});
const getUtxoByAddress$1 = (_network, _address) => new Promise((_resolve, _reject) => _makeDogeChainApiCall(_network, 'GET', `/unspent/${_address}/`).then(({
unspent_outputs,
success,
error
}) => success ? _resolve(unspent_outputs) : _reject(error)).catch(_reject));
const isValidAddress$2 = _address => {
const res = _address.match(/D{1}[5-9A-HJ-NP-U]{1}[1-9A-HJ-NP-Za-km-z]{32}/g);
if (!res) return false;
return res[0] === _address;
};
const monitorUtxoByAddress$1 = async (_network, _address, _eventEmitter, _pollingTime, _broadcastEventName, _confirmationEventName, _confirmations = 1) => {
let isBroadcasted = false;
let utxo = null;
await polling(async () => {
const utxos = await getUtxoByAddress$1(_network, _address);
if (utxos.length > 0) {
if (utxos[0].confirmations > 0) {
if (!isBroadcasted) {
_eventEmitter.emit(_broadcastEventName, utxos[0]);
isBroadcasted = true;
}
if (utxos[0].confirmations >= _confirmations) {
_eventEmitter.emit(_confirmationEventName, utxos[0]);
utxo = utxos[0].tx_hash;
return true;
}
return false;
} else if (!isBroadcasted) {
isBroadcasted = true;
_eventEmitter.emit(_broadcastEventName, utxos[0]);
return false;
}
} else {
return false;
}
}, _pollingTime);
return utxo.startsWith('0x') ? utxo : '0x' + utxo;
};
const waitForTransactionConfirmation$2 = async (_network, _transactionHash, _pollingTime) => {
let transactionToReturn = null;
await polling(async () => {
try {
const {
transaction
} = await _makeDogeChainApiCall(_network, 'GET', `/transaction/${_transactionHash}/`);
transactionToReturn = transaction;
return transaction.confirmations > 0;
} catch (_err) {
return false;
}
}, _pollingTime);
return transactionToReturn;
};
var doge = /*#__PURE__*/Object.freeze({
__proto__: null,
broadcastTransaction: broadcastTransaction$1,
isValidAddress: isValidAddress$2,
getUtxoByAddress: getUtxoByAddress$1,
monitorUtxoByAddress: monitorUtxoByAddress$1,
waitForTransactionConfirmation: waitForTransactionConfirmation$2
});
const LTC_PTOKENS_NODE_TESTNET_API = 'https://ltc-testnet-node-1.ptokens.io/insight-lite-api';
const LTC_PTOKENS_NODE_MAINNET_API = 'https://ltc-node-1.ptokens.io/insight-lite-api';
const _getInsightLiteApi = _network => axios.create({
baseURL: _network === Mainnet ? LTC_PTOKENS_NODE_MAINNET_API : LTC_PTOKENS_NODE_TESTNET_API,
timeout: 50000,
headers: {
'Content-Type': 'application/json'
}
});
const _makeInsightLiteApiCall = (_network, _callType, _apiPath, _params) => new Promise((resolve, reject) => {
_getInsightLiteApi(_network)[_callType.toLowerCase()](_apiPath, _params).then(_res => resolve(_res.data)).catch(_err => reject(_err));
});
const broadcastTransaction$2 = (_network, _tx) => _makeInsightLiteApiCall(_network, 'POST', '/tx/send', {
rawtx: _tx
});
const getUtxoByAddress$2 = (_network, _address) => _makeInsightLiteApiCall(_network, 'GET', `/addrs/${_address}/utxo`);
const getTransactionHexById$1 = (_network, _txId) => _makeInsightLiteApiCall(_network, 'GET', `/rawtx/${_txId}`);
const isValidAddress$3 = _address => {
const res = _address.match(/(ltc1|[LM3Q2mn])[a-zA-HJ-NP-Z0-9]{26,40}/g);
if (!res) return false;
return res[0] === _address;
};
const monitorUtxoByAddress$2 = async (_network, _address, _eventEmitter, _pollingTime, _broadcastEventName, _confirmationEventName, _confirmations = 1) => {
let isBroadcasted = false;
let utxo = null;
let utxos = [];
await polling(async () => {
utxos = await _makeInsightLiteApiCall(_network, 'GET', `/addrs/${_address}/utxo`);
if (utxos.length > 0) {
if (utxos[0].confirmations > 0) {
if (!isBroadcasted) {
_eventEmitter.emit(_broadcastEventName, utxos[0]);
_eventEmitter.emit('onLtcTxBroadcasted', utxos[0]);
isBroadcasted = true;
}
if (utxos[0].confirmations >= _confirmations) {
_eventEmitter.emit(_confirmationEventName, utxos[0]);
_eventEmitter.emit('onLtcTxConfirmed', utxos[0]);
utxo = utxos[0].txid;
return true;
}
return false;
} else if (!isBroadcasted) {
isBroadcasted = true;
_eventEmitter.emit(_broadcastEventName, utxos[0]);
_eventEmitter.emit('onLtcTxBroadcasted', utxos[0]);
return false;
}
} else {
return false;
}
}, _pollingTime);
return utxo;
};
const waitForTransactionConfirmation$3 = async (_network, _tx, _pollingTime) => {
let transaction = null;
await polling(async () => {
try {
transaction = await _makeInsightLiteApiCall(_network, 'GET', `/tx/${_tx}/`);
return transaction.confirmations > 0;
} catch (_err) {
return false;
}
}, _pollingTime);
return transaction;
};
var ltc = /*#__PURE__*/Object.freeze({
__proto__: null,
broadcastTransaction: broadcastTransaction$2,
isValidAddress: isValidAddress$3,
getUtxoByAddress: getUtxoByAddress$2,
getTransactionHexById: getTransactionHexById$1,
monitorUtxoByAddress: monitorUtxoByAddress$2,
waitForTransactionConfirmation: waitForTransactionConfirmation$3
});
const UINT32_MAX = Math.pow(2, 32);
const decodeUint64le = _buffer => {
const rem = _buffer.readUInt32LE(0);
const top = _buffer.readUInt32LE(4);
return top * UINT32_MAX + rem;
};
const encodeUint64le = _number => {
const buffer = Buffer.alloc(8);
const top = Math.floor(_number / UINT32_MAX);
const rem = _number - top * UINT32_MAX;
buffer.writeUInt32LE(rem, 0);
buffer.writeUInt32LE(top, 4);
return buffer;
};
var converters = /*#__PURE__*/Object.freeze({
__proto__: null,
decodeUint64le: decodeUint64le,
encodeUint64le: encodeUint64le
});
const HEX_PREFIX = '0x';
const zeroEther = '0x00';
const zeroAddress = '0x0000000000000000000000000000000000000000';
const addHexPrefix = _string => isHexPrefixed(_string) ? _string : HEX_PREFIX + _string;
const removeHexPrefix = _string => isHexPrefixed(_string) ? _string.substr(2) : _string;
const onChainFormat = (_amount, _decimals) => _amount.multipliedBy(new BigNumber(Math.pow(10, _decimals)));
const offChainFormat = (_amount, _decimals) => _amount.dividedBy(new BigNumber(Math.pow(10, _decimals)));
const getAccount = _web3 => new Promise((_resolve, _reject) => {
_web3.eth.defaultAccount ? _resolve(_web3.eth.defaultAccount) : _web3.eth.getAccounts().then(accounts => _resolve(accounts[0])).catch(err => _reject(err));
});
const getContract = (_web3, _abi, _contractAddress, _account) => {
const contract = new _web3.eth.Contract(_abi, _contractAddress, {
defaultAccount: _account
});
return contract;
};
const getGasLimit = _web3 => new Promise((_resolve, _reject) => {
_web3.eth.getBlock('latest').then(_block => _resolve(_block.gasLimit)).catch(_err => _reject(_err));
});
const isHexPrefixed = _string => _string.slice(0, 2) === HEX_PREFIX;
const makeContractCall = async (_web3, _method, _options, _params = []) => {
try {
const {
abi,
contractAddress
} = _options;
const account = await getAccount(_web3);
const contract = getContract(_web3, abi, contractAddress, account);
return contract.methods[_method](..._params).call();
} catch (err) {
throw new Error(err.message);
}
};
const makeContractSend = (_web3, _method, _options, _params = []) => {
const promiEvent = Web3PromiEvent();
const start = async () => {
try {
const {
abi,
contractAddress,
value,
gasPrice,
gas
} = _options;
const account = await getAccount(_web3, true);
const contract = getContract(_web3, abi, contractAddress, account);
contract.methods[_method](..._params).send({
from: account,
value,
gasPrice,
gas
}).once('transactionHash', _hash => promiEvent.eventEmitter.emit('transactionHash', _hash)).once('receipt', _receipt => promiEvent.eventEmitter.emit('receipt', _receipt)).once('error', _error => promiEvent.eventEmitter.emit('error', _error)).then(() => promiEvent.resolve());
} catch (_err) {
promiEvent.reject(_err);
}
};
start();
return promiEvent.eventEmitter;
};
const sendSignedMethodTx = (_web3, _method, _options, _params) => {
const promiEvent = Web3PromiEvent();
const start = async () => {
try {
const {
abi,
contractAddress,
value,
gas,
gasPrice,
privateKey
} = _options;
const contract = getContract(_web3, abi, _web3.eth.defaultAccount);
const nonce = await _web3.eth.getTransactionCount(_web3.eth.defaultAccount, 'pending');
const {
rawTransaction
} = await _web3.eth.accounts.signTransaction({
nonce,
gasPrice: gasPrice || (await _web3.eth.getGasPrice()),
gasLimit: gas || (await getGasLimit(_web3)),
to: contractAddress,
value,
data: contract.methods[_method](..._params).encodeABI()
}, privateKey);
_web3.eth.sendSignedTransaction(rawTransaction).once('transactionHash', _hash => promiEvent.eventEmitter.emit('transactionHash', _hash)).once('receipt', _receipt => promiEvent.eventEmitter.emit('receipt', _receipt)).once('error', _error => promiEvent.eventEmitter.emit('error', _error)).then(() => promiEvent.resolve());
} catch (_err) {
promiEvent.reject(_err);
}
};
start();
return promiEvent.eventEmitter;
};
const waitForTransactionConfirmation$4 = async (_web3, _tx, _pollingTime = 5000) => {
let receipt = null;
await polling(async () => {
try {
receipt = await _web3.eth.getTransactionReceipt(_tx);
if (!receipt) return false;else if (receipt.status) return true;else return false;
} catch (_err) {
return false;
}
}, _pollingTime);
return receipt;
};
var eth = /*#__PURE__*/Object.freeze({
__proto__: null,
addHexPrefix: addHexPrefix,
removeHexPrefix: removeHexPrefix,
onChainFormat: onChainFormat,
offChainFormat: offChainFormat,
getAccount: getAccount,
getContract: getContract,
getGasLimit: getGasLimit,
isHexPrefixed: isHexPrefixed,
makeContractCall: makeContractCall,
makeContractSend: makeContractSend,
sendSignedMethodTx: sendSignedMethodTx,
waitForTransactionConfirmation: waitForTransactionConfirmation$4,
zeroEther: zeroEther,
zeroAddress: zeroAddress
});
const EOS_TRANSACTION_EXECUTED = 'executed';
const getApi = (_privateKey, _rpc, _signatureProvider = null) => {
if (_rpc && !_privateKey && !_signatureProvider) {
const rpc = typeof _rpc === 'string' ? new JsonRpc(_rpc, {
fetch
}) : _rpc;
return new Api({
rpc,
textDecoder: new encoding.TextDecoder(),
textEncoder: new encoding.TextEncoder()
});
}
const signatureProvider = _signatureProvider || new JsSignatureProvider([_privateKey]);
const rpc = typeof _rpc === 'string' ? new JsonRpc(_rpc, {
fetch
}) : _rpc;
return new Api({
rpc,
signatureProvider,
textDecoder: new encoding.TextDecoder(),
textEncoder: new encoding.TextEncoder()
});
};
const getAmountInEosFormat = (_amount, _decimals = 4, symbol) => {
return `${parseFloat(_amount).toFixed(_decimals)} ${symbol}`;
};
const isValidAccountName = _accountName => new RegExp('(^[a-z1-5.]{0,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)').test(_accountName);
const waitForTransactionConfirmation$5 = async (_api, _tx, _pollingTime = 2000) => {
let receipt = null;
await polling(async () => {
try {
receipt = await _api.rpc.history_get_transaction(_tx);
if (receipt && receipt.trx.receipt.status === EOS_TRANSACTION_EXECUTED) return true;else return false;
} catch (err) {
return false;
}
}, _pollingTime);
return receipt;
};
var eos = /*#__PURE__*/Object.freeze({
__proto__: null,
getApi: getApi,
getAmountInEosFormat: getAmountInEosFormat,
isValidAccountName: isValidAccountName,
waitForTransactionConfirmation: waitForTransactionConfirmation$5
});
const RVN_PTOKENS_NODE_MAINNET_API = 'https://corsproxy.ptokens.io/v1/?apiurl=https://api.ravencoin.org/api';
const _getInsightLiteApi$1 = _network => {
if (_network === Testnet) throw new Error('Ravecoin Testnet is not supported');
return axios.create({
baseURL: RVN_PTOKENS_NODE_MAINNET_API,
timeout: 50000,
headers: {
'Content-Type': 'application/json'
}
});
};
const _makeInsightLiteApiCall$1 = (_network, _callType, _apiPath, _params) => new Promise((resolve, reject) => {
_getInsightLiteApi$1(_network)[_callType.toLowerCase()](_apiPath, _params).then(_res => resolve(_res.data)).catch(_err => reject(_err));
});
const broadcastTransaction$3 = (_network, _tx) => _makeInsightLiteApiCall$1(_network, 'POST', '/tx/send', {
rawtx: _tx
});
const getUtxoByAddress$3 = (_network, _address) => _makeInsightLiteApiCall$1(_network, 'GET', `/addrs/${_address}/utxo`);
const getTransactionHexById$2 = (_network, _txId) => _makeInsightLiteApiCall$1(_network, 'GET', `/rawtx/${_txId}`);
const isValidAddress$4 = _address => {
const res = _address.match(/(r|R)[a-zA-HJ-NP-Z0-9]{26,40}/g);
if (!res) return false;
return res[0] === _address;
};
const monitorUtxoByAddress$3 = async (_network, _address, _eventEmitter, _pollingTime, _broadcastEventName, _confirmationEventName, _confirmations = 1) => {
let isBroadcasted = false;
let utxo = null;
let utxos = [];
await polling(async () => {
utxos = await _makeInsightLiteApiCall$1(_network, 'GET', `/addrs/${_address}/utxo`);
if (utxos.length > 0) {
if (utxos[0].confirmations > 0) {
if (!isBroadcasted) {
_eventEmitter.emit(_broadcastEventName, utxos[0]);
isBroadcasted = true;
}
if (utxos[0].confirmations >= _confirmations) {
_eventEmitter.emit(_confirmationEventName, utxos[0]);
utxo = utxos[0].txid;
return true;
}
return false;
} else if (!isBroadcasted) {
isBroadcasted = true;
_eventEmitter.emit(_broadcastEventName, utxos[0]);
return false;
}
} else {
return false;
}
}, _pollingTime);
return utxo;
};
const waitForTransactionConfirmation$6 = async (_network, _tx, _pollingTime = 3000) => {
let transaction = null;
await polling(async () => {
try {
transaction = await _makeInsightLiteApiCall$1(_network, 'GET', `/tx/${_tx}/`);
return transaction.confirmations > 0;
} catch (_err) {
return false;
}
}, _pollingTime);
return transaction;
};
var rvn = /*#__PURE__*/Object.freeze({
__proto__: null,
broadcastTransaction: broadcastTransaction$3,
isValidAddress: isValidAddress$4,
getUtxoByAddress: getUtxoByAddress$3,
getTransactionHexById: getTransactionHexById$2,
monitorUtxoByAddress: monitorUtxoByAddress$3,
waitForTransactionConfirmation: waitForTransactionConfirmation$6
});
const blockchainTypes = {
ethereum: Ethereum,
eth: Ethereum,
eosio: Eosio,
eos: Eosio,
bitcoin: Bitcoin,
btc: Bitcoin,
ltc: Litecoin,
litecoin: Litecoin,
telos: Telos,
dogecoin: Dogecoin,
doge: Dogecoin,
'binance-smart-chain': BinanceSmartChain,
bsc: BinanceSmartChain,
matic: Polygon,
polygon: Polygon,
xdai: Xdai,
ravencoin: Ravencoin,
rvn: Ravencoin,
lbc: Lbry,
lbry: Lbry,
ultra: Ultra,
uos: Ultra,
arbitrum: Arbitrum,
luxochain: Luxochain,
algorand: Algorand,
fantom: Fantom,
ore: Ore,
libre: Libre
};
const blockchainShortTypes = {
ethereum: 'eth',
eosio: 'eos',
bitcoin: 'btc',
litecoin: 'ltc',
telos: 'telos',
dogecoin: 'doge',
'binance-smart-chain': 'bsc',
matic: 'polygon',
polygon: 'polygon',
xdai: 'xdai',
ravencoin: 'rvn',
lbc: 'lbc',
lbry: 'lbc',
ultra: 'ultra',
arbitrum: 'arbitrum',
luxochain: 'luxochain',
algorand: 'algo',
fantom: 'fantom',
ftm: 'fantom',
ore: 'ore',
libre: 'libre'
};
const pTokenNativeBlockchain = {
pbtc: Bitcoin,
pltc: Litecoin,
pweth: Ethereum,
peth: Ethereum,
plink: Ethereum,
pyfi: Ethereum,
pmkr: Ethereum,
pnt: Ethereum,
pteria: Ethereum,
puni: Ethereum,
pband: Ethereum,
pbal: Ethereum,
pcomp: Ethereum,
psnx: Ethereum,
pomg: Ethereum,
pdai: Ethereum,
pant: Ethereum,
plrc: Ethereum,
puos: Ethereum,
pbat: Ethereum,
prep: Ethereum,
pzrx: Ethereum,
ppnk: Ethereum,
pdoge: Dogecoin,
peos: Eosio,
iq: Eosio,
tlos: Telos,
popium: Ethereum,
pbcp: Ethereum,
pdefiplusplus: Ethereum,
cgg: Ethereum,
pusdc: Ethereum,
pusdt: Ethereum,
prvn: Ravencoin,
popen: Ethereum,
ocp: BinanceSmartChain,
anrx: Ethereum,
tff: BinanceSmartChain,
psafemoon: BinanceSmartChain,
efx: Eosio,
pseeds: Telos,
plbc: Lbry,
usdo: BinanceSmartChain,
gala: Ethereum,
pzmt: Ethereum,
bist: Ethereum,
pvai: BinanceSmartChain,
wsb: BinanceSmartChain,
luxo: Luxochain,
ptet: BinanceSmartChain,
pkeys: Ethereum,
oath: Fantom,
pftm: Fantom,
pwftm: Fantom,
nuco: Ethereum,
pkeys: Ethereum,
ore: Ore,
libre: Libre
};
const networkLabels = {
ethereum: {
testnet: EthereumRopsten,
testnet_ropsten: EthereumRopsten,
mainnet: EthereumMainnet
},
eosio: {
testnet: EosioJungle3,
testnet_jungle3: EosioJungle3,
mainnet: EosioMainnet
},
bitcoin: {
bitcoin: Bitcoin,
mainnet: BitcoinMainnet,
testnet: BitcoinTestnet
},
litecoin: {
testnet: LitecoinTestnet,
mainnet: LitecoinMainnet,
litecoin: LitecoinMainnet
},
telos: {
mainnet: TelosMainnet
},
dogecoin: {
mainnet: DogecoinMainnet,
dogecoin: DogecoinMainnet
},
'binance-smart-chain': {
mainnet: BinanceSmartChainMainnet
},
polygon: {
mainnet: PolygonMainnet
},
matic: {
mainnet: PolygonMainnet
},
xdai: {
mainnet: XdaiMainnet
},
ravencoin: {
mainnet: RavencoinMainnet,
ravencoin: RavencoinMainnet
},
lbry: {
mainnet: LbryMainnet
},
ultra: {
mainnet: UltraMainnet,
testnet: UltraTestnet
},
arbitrum: {
mainnet: ArbitrumMainnet
},
luxochain: {
mainnet: LuxochainMainnet
},
algorand: {
mainnet: AlgorandMainnet
},
fantom: {
mainnet: FantomMainnet
},
ore: {
mainnet: OreMainnet
},
libre: {
mainnet: LibreMainnet
}
};
const networkLabelType = {
testnet_ropsten: Testnet,
testnet_jungle3: Testnet,
testnet: Testnet,
mainnet: Mainnet
};
const pTokensAvailables = [pBTC, pLTC, pWETH, pETH, pYFI, pMKR, PNT, pLINK, PTERIA, pUNI, pBAND, pBAL, pCOMP, pSNX, pOMG, pDAI, pANT, pLRC, pUOS, pBAT, pREP, pZRX, pPNK, pDOGE, pEOS, IQ, TLOS, pOPIUM, pBCP, pDEFIPlusPlus, CGG, pUSDT, pUSDC, pRVN, pOPEN, OCP, ANRX, TFF, pSAFEMOON, EFX, pSEEDS, pLBC, USDO, GALA, ZMT, BIST, pVAI, WSB, LUXO, pTET, pKEYS, OATH, pFTM, pWFTM, NUCO, ORE];
const getNetworkType = _network => networkLabelType[_network.toLowerCase()];
const getBlockchainType = _blockchain => blockchainTypes[_blockchain.toLowerCase()];
const getBlockchainShortType = _blockchain => blockchainShortTypes[_blockchain.toLowerCase()];
const getNativeBlockchainFromPtokenName = _name => pTokenNativeBlockchain[_name.toLowerCase()];
const isValidPTokenName = _name => Boolean(pTokensAvailables.includes(_name.toLowerCase()));
const parseParams = (_params, _nativeBlockchain) => {
let parsedHostBlockchain;
let parsedHostNetwork;
let parsedNativeBlockchain;
let parsedNativeNetwork;
const {
blockchain,
network,
hostBlockchain,
hostNetwork,
nativeBlockchain,
nativeNetwork
} = _params;
if (Boolean(hostBlockchain) === Boolean(blockchain) || Boolean(hostNetwork) === Boolean(network)) throw new Error('Bad initialization');
if (hostBlockchain) parsedHostBlockchain = blockchainTypes[hostBlockchain.toLowerCase()];else if (blockchain) parsedHostBlockchain = blockchainTypes[blockchain.toLowerCase()];
if (!parsedHostBlockchain) throw new Error('Invalid hostBlockchain value');
if (hostNetwork) parsedHostNetwork = networkLabels[parsedHostBlockchain][hostNetwork.toLowerCase()];else if (network) parsedHostNetwork = networkLabels[parsedHostBlockchain][network.toLowerCase()];
if (!parsedHostNetwork) throw new Error('Invalid hostNetwork value');
parsedNativeNetwork = nativeNetwork ? networkLabels[nativeNetwork.toLowerCase()] : null;
if (!parsedNativeNetwork && parsedHostNetwork.includes(Testnet)) parsedNativeNetwork = Testnet;else parsedNativeNetwork = Mainnet;
parsedNativeBlockchain = nativeBlockchain ? blockchainTypes[nativeBlockchain.toLowerCase()] : _nativeBlockchain;
return {
hostBlockchain: parsedHostBlockchain,
hostNetwork: parsedHostNetwork,
nativeBlockchain: parsedNativeBlockchain,
nativeNetwork: parsedNativeNetwork
};
};
var helpers = /*#__PURE__*/Object.freeze({
__proto__: null,
getNetworkType: getNetworkType,
getBlockchainType: getBlockchainType,
getBlockchainShortType: getBlockchainShortType,
getNativeBlockchainFromPtokenName: getNativeBlockchainFromPtokenName,
isValidPTokenName: isValidPTokenName,
parseParams: parseParams
});
var tokens = {
[Ethereum]: {
[EthereumMainnet]: {
ETH: '0x0000000000000000000000000000000000000000',
WETH: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
PNT: '0x89ab32156e46f46d02ade3fecbe5fc4243b9aaed',
MKR: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2',
LINK: '0x514910771af9ca656af840dff83e8264ecf986ca',
YFI: '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
PTERIA: '0x02eca910cb3a7d43ebc7e8028652ed5c6b70259b',
UNI: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
BAND: '0xba11d00c5f74255f56a5e366f4f77f5a186d7f55',
BAL: '0xba100000625a3754423978a60c9317c58a424e3d',
COMP: '0xc00e94cb662c3520282e6f5717214004a7f26888',
SNX: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
OMG: '0xd26114cd6ee289accf82350c8d8487fedb8a0c07',
DAI: '0x6b175474e89094c44da98b954eedeac495271d0f',
ANT: '0xa117000000f279d81a1d3cc75430faa017fa5a2e',
LRC: '0xbbbbca6a901c926f240b89eacb641d8aec7aeafd',
UOS: '0xd13c7342e1ef687c5ad21b27c2b65d772cab5c8c',
BAT: '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
REP: '0x221657776846890989a759ba2973e427dff5c9bb',
ZRX: '0xe41d2489571d322189246dafa5ebde1f4699f498',
PNK: '0x93ed3fbe21207ec2e8f2d3c3de6e058cb73bc04d',
OPIUM: '0x888888888889c00c67689029d7856aac1065ec11',
BCP: '0xe4f726adc8e89c6a6017f01eada77865db22da14',
'DEFI++': '0x8d1ce361eb68e9e05573443c407d4a3bed23b033',
CGG: '0x1fe24f25b1cf609b9c4e7e12d802e3640dfa5e43',
USDT: '0xdac17f958d2ee523a2206206994597c13d831ec7',
USDC: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
OPEN: '0x69e8b9528cabda89fe846c67675b5d73d463a916',
ANRX: '0xcae72a7a0fd9046cf6b165ca54c9e3a3872109e0',
GALA: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da',
ZMT: '0xaa602dE53347579f86b996D2Add74bb6F79462b2',
BIST: '0x6e8908cfa881c9f6f2c64d3436e7b80b1bf0093f',
LUXO: '0xd39a2cecba2657e125ba6a5c98ad2f6b6d7e83fd',
KEYS: '0xe0a189C975e4928222978A74517442239a0b86ff',
NCDT: '0xE0C8b298db4cfFE05d1bEA0bb1BA414522B33C1B'
},
[EthereumRopsten]: {
UOS: '0x92829bc1a5b405fe14a0b7c38a5bad9a91b1dc02'
}
},
[BinanceSmartChain]: {
[BinanceSmartChainMainnet]: {
OCP: '0x3c70260eee0a2bfc4b375feb810325801f289fbd',
TFF: '0x2d69c55baecefc6ec815239da0a985747b50db6e',
SAFEMOON: '0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3',
USDO: '0x5801d0e1c7d977d78e4890880b8e579eb4943276',
VAI: '0x4bd17003473389a42daf6a0a729f6fdb328bbbd7',
WSB: '0x8244609023097aef71c702ccbaefc0bde5b48694',
pTET: '0x87b92df541869fcabb7e5d4e3bfc3025eb3e7577'
}
},
[Eosio]: {
[EosioMainnet]: {
EOS: 'eosio.token',
IQ: 'everipediaiq',
EFX: 'effecttokens'
}
},
[Telos]: {
[TelosMainnet]: {
TLOS: 'eosio.token',
SEEDS: 'token.seeds'
}
},
[Fantom]: {
[FantomMainnet]: {
OATH: '0x21ada0d2ac28c3a5fa3cd2ee30882da8812279b6'
}
},
[Ore]: {
[OreMainnet]: {
ORE: 'eosio.token'
}
}
};
const blockchains = {
Bitcoin,
Eosio,
Ethereum,
Litecoin,
Telos,
Dogecoin,
BinanceSmartChain,
Polygon,
Xdai,
Ravencoin,
Lbry,
Ultra,
Arbitrum,
Luxochain,
Algorand,
Fantom,
Ore,
Libre
};
const networks = {
Mainnet,
Testnet,
BitcoinMainnet,
BitcoinTestnet,
EthereumMainnet,
EthereumRopsten,
EosioMainnet,
EosioJungle3,
LitecoinMainnet,
LitecoinTestnet,
TelosMainnet,
DogecoinMainnet,
BinanceSmartChainMainnet,
PolygonMainnet,
XdaiMainnet,
RavencoinMainnet,
LbryMainnet,
UltraMainnet,
UltraTestnet,
ArbitrumMainnet,
LuxochainMainnet,
AlgorandMainnet,
FantomMainnet,
OreMainnet,
LibreMainnet
};
const chainIds = {
[Ethereum]: {
[EthereumMainnet]: '0x005fe7f9',
[EthereumRopsten]: '0x0069c322'
},
[Arbitrum]: {
[ArbitrumMainnet]: '0x00ce98c4'
},
[Luxochain]: {
[LuxochainMainnet]: '0x00d5beb0'
},
[BinanceSmartChain]: {
[BinanceSmartChainMainnet]: '0x00e4b170'
},
[Algorand]: {
[AlgorandMainnet]: '0x03c38e67'
},
[Bitcoin]: {
[BitcoinMainnet]: '0x01ec97de',
[BitcoinTestnet]: '0x018afeb2'
},
[Fantom]: {
[FantomMainnet]: '0x0022af98'
},
[Telos]: {
[TelosMainnet]: '0x028c7109'
},
[Libre]: {
[LibreMainnet]: '0x026776fa'
}
};
const pTokens = {
pBTC,
pLTC,
pETH,
pWETH,
pLINK,
pMKR,
pYFI,
PNT,
PTERIA,
pUNI,
pBAND,
pBAL,
pCOMP,
pSNX,
pOMG,
pDAI,
pANT,
pLRC,
pUOS,
pBAT,
pREP,
pZRX,
pPNK,
pDOGE,
pEOS,
IQ,
TLOS,
pOPIUM,
pBCP,
pDEFIPlusPlus,
CGG,
pUSDT,
pUSDC,
pRVN,
pOPEN,
OCP,
ANRX,
TFF,
pSAFEMOON,
EFX,
pSEEDS,
pLBC,
USDO,
GALA,
ZMT,
BIST,
pVAI,
WSB,
LUXO,
pTET,
pKEYS,
OATH,
pFTM,
pWFTM,
NUCO,
ORE
};
var constants = /*#__PURE__*/Object.freeze({
__proto__: null,
blockchains: blockchains,
networks: networks,
pTokens: pTokens,
tokens: tokens,
chainIds: chainIds
});
function encodeStringForArgs(str) {
return new Uint8Array(Buffer.from(str));
}
function parseHexString(str) {
let inStr = str;
var result = [];
while (inStr.length >= 2) {
result.push(parseInt(inStr.substring(0, 2), 16));
inStr = inStr.substring(2, inStr.length);
}
return result;
}
const decodeBlob = _blob => new Uint8Array(Buffer.from(_blob, 'base64').toString('binary').split('').map(x => x.charCodeAt(0)));
const redeemFromAlgorand = async ({
amount,
to,
from,
assetIndex,
destinationChainId,
nativeAccount,
client,
provider,
eventEmitter,
swapInfo
}) => {
const suggestedParams = await client.getTransactionParams().do();
const encodedDestinationChainId = parseHexString(destinationChainId.substring(2));
const asaTransferTx = makeAssetTransferTxnWithSuggestedParamsFromObject({
from,
to: swapInfo ? getApplicationAddress(parseInt(swapInfo.appId)) : to,
assetIndex: parseInt(swapInfo ? swapInfo.inputAssetId : assetIndex),
amount: parseInt(amount, 10),
suggestedParams,
note: encode([0, encodedDestinationChainId, nativeAccount, []])
});
let appCallTx;
if (swapInfo) {
appCallTx = makeApplicationCallTxnFromObject({
from,
suggestedParams,
appIndex: parseInt(swapInfo.appId),
appArgs: [encodeStringForArgs('swap'), encodeUint64(parseInt(assetIndex, 10)), decodeAddress(to).publicKey],
foreignAssets: [parseInt(assetIndex), parseInt(swapInfo.inputAssetId)],
accounts: [to]
});
assignGroupID([asaTransferTx, appCallTx]);
} else {
assignGroupID([asaTransferTx]);
}
const toBeSignedTxs = [asaTransferTx];
if (swapInfo) toBeSignedTxs.push(appCallTx);
const signedTxs = await provider.signTxn(toBeSignedTxs);
const binaryAsaTransferSignedTx = decodeBlob(signedTxs[0].blob ? signedTxs[0].blob : signedTxs[0]);
let binarySignedTxs = [binaryAsaTransferSignedTx];
if (swapInfo) binarySignedTxs.push(decodeBlob(signedTxs[1].blob ? signedTxs[1].blob : signedTxs[1]));
await client.sendRawTransaction(binarySignedTxs).do();
eventEmitter.emit('hostTxBroadcasted', asaTransferTx.group.toString('base64'));
await waitForConfirmation(client, asaTransferTx.txID(), 10);
return swapInfo ? appCallTx : asaTransferTx;
};
var ____comment = "This file was generated with eosio-abigen. DO NOT EDIT ";
var version = "eosio::abi/1.1";
var types = [
];
var structs = [
{
name: "changeissuer",
base: "",
fields: [
{
name: "issuer",
type: "name"
},
{
name: "new_issuer",
type: "name"
},
{
name: "sym",
type: "symbol"
}
]
},
{
name: "close",
base: "",
fields: [
{
name: "owner",
type: "name"
},
{
name: "symbol",
type: "symbol"
}
]
},
{
name: "create",
base: "",
fields: [
{
name: "issuer",
type: "name"
},
{
name: "maximum_supply",
type: "asset"
}
]
},
{
name: "currency_stats",
base: "",
fields: [
{
name: "supply",
type: "asset"
},
{
name: "max_supply",
type: "asset"
},
{
name: "issuer",
type: "name"
}
]
},
{
name: "issue",
base: "",
fields: [
{
name: "to",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
},
{
name: "open",
base: "",
fields: [
{
name: "owner",
type: "name"
},
{
name: "symbol",
type: "symbol"
},
{
name: "ram_payer",
type: "name"
}
]
},
{
name: "redeem",
base: "",
fields: [
{
name: "sender",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
},
{
name: "retire",
base: "",
fields: [
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
},
{
name: "token_account",
base: "",
fields: [
{
name: "balance",
type: "asset"
}
]
},
{
name: "transfer",
base: "",
fields: [
{
name: "from",
type: "name"
},
{
name: "to",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
}
];
var actions = [
{
name: "changeissuer",
type: "changeissuer",
ricardian_contract: ""
},
{
name: "close",
type: "close",
ricardian_contract: ""
},
{
name: "create",
type: "create",
ricardian_contract: ""
},
{
name: "issue",
type: "issue",
ricardian_contract: ""
},
{
name: "open",
type: "open",
ricardian_contract: ""
},
{
name: "redeem",
type: "redeem",
ricardian_contract: ""
},
{
name: "retire",
type: "retire",
ricardian_contract: ""
},
{
name: "transfer",
type: "transfer",
ricardian_contract: ""
}
];
var tables = [
{
name: "accounts",
type: "token_account",
index_type: "i64",
key_names: [
],
key_types: [
]
},
{
name: "stat",
type: "currency_stats",
index_type: "i64",
key_names: [
],
key_types: [
]
}
];
var ricardian_clauses = [
];
var variants = [
];
var pTokenOnEosAbi = {
____comment: ____comment,
version: version,
types: types,
structs: structs,
actions: actions,
tables: tables,
ricardian_clauses: ricardian_clauses,
variants: variants
};
var ____comment$1 = "This file was generated with eosio-abigen. DO NOT EDIT ";
var version$1 = "eosio::abi/1.2";
var types$1 = [
];
var structs$1 = [
{
name: "close",
base: "",
fields: [
{
name: "owner",
type: "name"
},
{
name: "symbol",
type: "symbol"
}
]
},
{
name: "create",
base: "",
fields: [
{
name: "issuer",
type: "name"
},
{
name: "maximum_supply",
type: "asset"
}
]
},
{
name: "currency_stats",
base: "",
fields: [
{
name: "supply",
type: "asset"
},
{
name: "max_supply",
type: "asset"
},
{
name: "issuer",
type: "name"
}
]
},
{
name: "issue",
base: "",
fields: [
{
name: "to",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
},
{
name: "issuewdata",
base: "",
fields: [
{
name: "to",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
},
{
name: "metadata",
type: "bytes"
}
]
},
{
name: "open",
base: "",
fields: [
{
name: "owner",
type: "name"
},
{
name: "symbol",
type: "symbol"
},
{
name: "ram_payer",
type: "name"
}
]
},
{
name: "redeem",
base: "",
fields: [
{
name: "sender",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
},
{
name: "redeem2",
base: "",
fields: [
{
name: "sender",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
},
{
name: "user_data",
type: "bytes"
},
{
name: "chain_id",
type: "bytes"
}
]
},
{
name: "retire",
base: "",
fields: [
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
},
{
name: "token_account",
base: "",
fields: [
{
name: "balance",
type: "asset"
}
]
},
{
name: "transfer",
base: "",
fields: [
{
name: "from",
type: "name"
},
{
name: "to",
type: "name"
},
{
name: "quantity",
type: "asset"
},
{
name: "memo",
type: "string"
}
]
}
];
var actions$1 = [
{
name: "close",
type: "close",
ricardian_contract: ""
},
{
name: "create",
type: "create",
ricardian_contract: ""
},
{
name: "issue",
type: "issue",
ricardian_contract: ""
},
{
name: "issuewdata",
type: "issuewdata",
ricardian_contract: ""
},
{
name: "open",
type: "open",
ricardian_contract: ""
},
{
name: "redeem",
type: "redeem",
ricardian_contract: ""
},
{
name: "redeem2",
type: "redeem2",
ricardian_contract: ""
},
{
name: "retire",
type: "retire",
ricardian_contract: ""
},
{
name: "transfer",
type: "transfer",
ricardian_contract: ""
}
];
var tables$1 = [
{
name: "accounts",
type: "token_account",
index_type: "i64",
key_names: [
],
key_types: [
]
},
{
name: "stat",
type: "currency_stats",
index_type: "i64",
key_names: [
],
key_types: [
]
}
];
var kv_tables = {
};
var ricardian_clauses$1 = [
];
var variants$1 = [
];
var action_results = [
];
var pTokenOnEosAbiV2 = {
____comment: ____comment$1,
version: version$1,
types: types$1,
structs: structs$1,
actions: actions$1,
tables: tables$1,
kv_tables: kv_tables,
ricardian_clauses: ricardian_clauses$1,
variants: variants$1,
action_results: action_results
};
const redeemFromEosio = (_api, _amount, _nativeAddress, _decimals, _contractAddress, _pToken, _options) => {
try {
const {
blocksBehind,
expireSeconds,
permission,
actor,
destinationChainId,
version = 'v1'
} = _options;
_api.cachedAbis.set(_contractAddress, {
abi: version === 'v1' ? pTokenOnEosAbi : pTokenOnEosAbiV2,
rawAbi: null
});
const data = {
sender: actor,
quantity: getAmountInEosFormat(_amount, _decimals, _pToken.toUpperCase()),
memo: _nativeAddress
};
if (version === 'v2') {
data.user_data = '';
data.chain_id = destinationChainId.substring(2);
}
return _api.transact({
actions: [{
account: _contractAddress,
name: version === 'v1' ? 'redeem' : 'redeem2',
authorization: [{
actor,
permission
}],
data
}]
}, {
blocksBehind,
expireSeconds
});
} catch (_err) {
throw new Error(_err.message);
}
};
var pTokenOnEthAbi = [
{
constant: true,
inputs: [
],
name: "decimals",
outputs: [
{
name: "",
type: "uint8"
}
],
payable: false,
stateMutability: "pure",
type: "function"
},
{
constant: false,
inputs: [
{
name: "amount",
type: "uint256"
},
{
name: "underlyingAssetRecipient",
type: "string"
}
],
name: "redeem",
outputs: [
{
name: "",
type: "bool"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "amount",
type: "uint256"
},
{
name: "userData",
type: "bytes"
},
{
name: "underlyingAssetRecipient",
type: "string"
}
],
name: "redeem",
outputs: [
{
name: "",
type: "bool"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
}
];
var pTokenOnEthV2 = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "oldOperator",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "newOperator",
type: "address"
}
],
name: "AdminOperatorChange",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "operator",
type: "address"
}
],
name: "AdminTransferInvoked",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "owner",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "spender",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256"
}
],
name: "Approval",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "operator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "tokenHolder",
type: "address"
}
],
name: "AuthorizedOperator",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "operator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "from",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
},
{
indexed: false,
internalType: "bytes",
name: "data",
type: "bytes"
},
{
indexed: false,
internalType: "bytes",
name: "operatorData",
type: "bytes"
}
],
name: "Burned",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "operator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "to",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
},
{
indexed: false,
internalType: "bytes",
name: "data",
type: "bytes"
},
{
indexed: false,
internalType: "bytes",
name: "operatorData",
type: "bytes"
}
],
name: "Minted",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "OwnershipTransferred",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "redeemer",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256"
},
{
indexed: false,
internalType: "string",
name: "underlyingAssetRecipient",
type: "string"
},
{
indexed: false,
internalType: "bytes",
name: "userData",
type: "bytes"
},
{
indexed: false,
internalType: "bytes4",
name: "originChainId",
type: "bytes4"
},
{
indexed: false,
internalType: "bytes4",
name: "destinationChainId",
type: "bytes4"
}
],
name: "Redeem",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "oldRelayHub",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "newRelayHub",
type: "address"
}
],
name: "RelayHubChanged",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "operator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "tokenHolder",
type: "address"
}
],
name: "RevokedOperator",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "bytes32",
name: "role",
type: "bytes32"
},
{
indexed: true,
internalType: "bytes32",
name: "previousAdminRole",
type: "bytes32"
},
{
indexed: true,
internalType: "bytes32",
name: "newAdminRole",
type: "bytes32"
}
],
name: "RoleAdminChanged",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "bytes32",
name: "role",
type: "bytes32"
},
{
indexed: true,
internalType: "address",
name: "account",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "sender",
type: "address"
}
],
name: "RoleGranted",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "bytes32",
name: "role",
type: "bytes32"
},
{
indexed: true,
internalType: "address",
name: "account",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "sender",
type: "address"
}
],
name: "RoleRevoked",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "operator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "from",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "to",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
},
{
indexed: false,
internalType: "bytes",
name: "data",
type: "bytes"
},
{
indexed: false,
internalType: "bytes",
name: "operatorData",
type: "bytes"
}
],
name: "Sent",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "from",