-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ava-labs/dev
v0.8.0
- Loading branch information
Showing
19 changed files
with
1,023 additions
and
416 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,22 @@ | ||
# CHANGELOG | ||
|
||
## v0.8.0 | ||
|
||
#### Notes | ||
|
||
- Init CHANGELOG | ||
|
||
#### Added | ||
|
||
- Created universal helper functions and `UniversalNode` class | ||
- `sendCustomEvmTx`, `canHaveBalanceOnChain`, `getTransactionsForBalance` in wallet classes | ||
|
||
#### Changed | ||
|
||
- `waitTxC` utils function uses getTx status to wait | ||
- Wallet AVM, EVM/C chain function now wait for confirmation and balance refresh before returning | ||
- Assets module `getContractData` renamed to `getContractDataErc20` | ||
|
||
#### Removed | ||
|
||
- `updateBalanceERC20` from wallet instances |
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 |
---|---|---|
@@ -1,216 +1,60 @@ | ||
import { Erc20Store, Erc20TokenData } from '@/Asset/types'; | ||
import { activeNetwork } from '@/Network/network'; | ||
import Erc20Token from '@/Asset/Erc20Token'; | ||
import { WalletBalanceERC20 } from '@/Wallet/types'; | ||
import { bnToLocaleString } from '@/utils/utils'; | ||
|
||
const DEFAULT_TOKENS: Erc20TokenData[] = [ | ||
{ | ||
chainId: 43114, | ||
address: '0x60781C2586D68229fde47564546784ab3fACA982', | ||
decimals: 18, | ||
name: 'Pangolin', | ||
symbol: 'PNG', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', | ||
decimals: 18, | ||
name: 'Wrapped AVAX', | ||
symbol: 'WAVAX', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xf20d962a6c8f70c731bd838a3a388D7d48fA6e15', | ||
decimals: 18, | ||
name: 'Ether', | ||
symbol: 'ETH', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xde3A24028580884448a5397872046a019649b084', | ||
decimals: 6, | ||
name: 'Tether USD', | ||
symbol: 'USDT', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xB3fe5374F67D7a22886A0eE082b2E2f9d2651651', | ||
decimals: 18, | ||
name: 'ChainLink Token', | ||
symbol: 'LINK', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x8cE2Dee54bB9921a2AE0A63dBb2DF8eD88B91dD9', | ||
decimals: 18, | ||
name: 'Aave Token', | ||
symbol: 'AAVE', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xf39f9671906d8630812f9d9863bBEf5D523c84Ab', | ||
decimals: 18, | ||
name: 'Uniswap', | ||
symbol: 'UNI', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x408D4cD0ADb7ceBd1F1A1C33A0Ba2098E1295bAB', | ||
decimals: 8, | ||
name: 'Wrapped BTC', | ||
symbol: 'WBTC', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x8DF92E9C0508aB0030d432DA9F2C65EB1Ee97620', | ||
decimals: 18, | ||
name: 'Maker', | ||
symbol: 'MKR', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x68e44C4619db40ae1a0725e77C02587bC8fBD1c9', | ||
decimals: 18, | ||
name: 'Synthetix Network Token', | ||
symbol: 'SNX', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x53CEedB4f6f277edfDDEdB91373B044FE6AB5958', | ||
decimals: 18, | ||
name: 'Compound', | ||
symbol: 'COMP', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x421b2a69b886BA17a61C7dAd140B9070d5Ef300B', | ||
decimals: 18, | ||
name: 'HuobiToken', | ||
symbol: 'HT', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0x39cf1BD5f15fb22eC3D9Ff86b0727aFc203427cc', | ||
decimals: 18, | ||
name: 'SushiToken', | ||
symbol: 'SUSHI', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xC84d7bfF2555955b44BDF6A307180810412D751B', | ||
decimals: 18, | ||
name: 'UMA Voting Token v1', | ||
symbol: 'UMA', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xaEb044650278731Ef3DC244692AB9F64C78FfaEA', | ||
decimals: 18, | ||
name: 'Binance USD', | ||
symbol: 'BUSD', | ||
}, | ||
{ | ||
chainId: 43114, | ||
address: '0xbA7dEebBFC5fA1100Fb055a87773e1E99Cd3507a', | ||
decimals: 18, | ||
name: 'Dai Stablecoin', | ||
symbol: 'DAI', | ||
}, | ||
]; | ||
export let erc20Cache: Erc20Store = {}; | ||
|
||
export let erc20Store: Erc20Store = {}; | ||
export let erc20StoreCustom: Erc20Store = {}; | ||
|
||
export function getErc20Store(): Erc20Store { | ||
export function getErc20Cache(): Erc20Store { | ||
return { | ||
...erc20Store, | ||
...erc20Cache, | ||
}; | ||
} | ||
|
||
export function getErc20StoreCustom(): Erc20Store { | ||
return { | ||
...erc20StoreCustom, | ||
}; | ||
/** | ||
* Clears the internal erc20 cache. | ||
*/ | ||
export function bustErc20Cache() { | ||
erc20Cache = {}; | ||
} | ||
|
||
/** | ||
* Fetches ERC20 data from the given contract address and adds the token to the given store. | ||
* @param address ERC20 Contract address | ||
* @param store Which ERC20 store to add to | ||
*/ | ||
export async function addErc20Token(address: string, store: Erc20Store = erc20StoreCustom): Promise<Erc20Token> { | ||
let existing = erc20Store[address] || erc20StoreCustom[address]; | ||
async function addErc20Token(address: string): Promise<Erc20Token> { | ||
let existing = erc20Cache[address]; | ||
if (existing) { | ||
return existing; | ||
} | ||
|
||
let data: Erc20TokenData = await Erc20Token.getData(address); | ||
let token = new Erc20Token(data); | ||
|
||
store[address] = token; | ||
erc20Cache[address] = token; | ||
return token; | ||
} | ||
|
||
export function addErc20TokenFromData(data: Erc20TokenData, store: Erc20Store = erc20StoreCustom): Erc20Token { | ||
function addErc20TokenFromData(data: Erc20TokenData): Erc20Token { | ||
let address = data.address; | ||
let existing = erc20Store[address] || erc20StoreCustom[address]; | ||
let existing = erc20Cache[address]; | ||
if (existing) { | ||
return existing; | ||
} | ||
|
||
let token = new Erc20Token(data); | ||
store[address] = token; | ||
erc20Cache[address] = token; | ||
return token; | ||
} | ||
|
||
export async function getContractData(address: string): Promise<Erc20TokenData> { | ||
export async function getContractDataErc20(address: string): Promise<Erc20TokenData> { | ||
let data: Erc20TokenData = await Erc20Token.getData(address); | ||
return data; | ||
} | ||
|
||
export async function getErc20Token(address: string): Promise<Erc20Token> { | ||
let storeItem = erc20Store[address] || erc20StoreCustom[address]; | ||
let storeItem = erc20Cache[address]; | ||
if (storeItem) { | ||
return storeItem; | ||
} else { | ||
return await addErc20Token(address); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the balance of the given address for each ERC20 Token in the SDK. | ||
* @param address EVM address `0x...` | ||
*/ | ||
export async function balanceOf(address: string): Promise<WalletBalanceERC20> { | ||
let balance: WalletBalanceERC20 = {}; | ||
|
||
let store = { | ||
...erc20Store, | ||
...erc20StoreCustom, | ||
}; | ||
|
||
for (let tokenAddress in store) { | ||
let token = store[tokenAddress]; | ||
if (token.chainId === activeNetwork?.evmChainID) { | ||
let bal = await token.balanceOf(address); | ||
balance[tokenAddress] = { | ||
name: token.name, | ||
symbol: token.symbol, | ||
denomination: token.decimals, | ||
balance: bal, | ||
balanceParsed: bnToLocaleString(bal, token.decimals), | ||
address: tokenAddress, | ||
}; | ||
} | ||
} | ||
|
||
return balance; | ||
} | ||
|
||
function initStore() { | ||
DEFAULT_TOKENS.forEach((token) => { | ||
addErc20TokenFromData(token, erc20Store); | ||
}); | ||
} | ||
initStore(); |
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
export { | ||
addErc20Token, | ||
addErc20TokenFromData, | ||
getErc20Token, | ||
balanceOf, | ||
getContractData, | ||
getErc20Store, | ||
getErc20StoreCustom, | ||
} from './Erc20'; | ||
export { getErc20Token, getContractDataErc20, getErc20Cache } from './Erc20'; | ||
export * from './Assets'; | ||
|
||
import Erc20Token from './Erc20Token'; | ||
|
||
export { Erc20Token }; |
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
Oops, something went wrong.