Created
May 11, 2021 20:46
-
-
Save nenadjaja/5b466c9b2397b00dd0c9f1e63deb31e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { Contract, BigNumber } from 'ethers' | |
| import { tokensToNSignal, tokensToSignal } from '@graphprotocol/common-ts' | |
| import { bigNumberify } from '../services/ethers' | |
| import { Subgraph, SubgraphDeployment, Network } from '../utils/types' | |
| const E18_100K = bigNumberify('100000000000000000000000') | |
| export const checkAllowance = async ( | |
| contractGraphToken: Contract, | |
| contractToCheckAddress: string, | |
| ethereumAccount: string, | |
| contractVestingAddress?: string, | |
| isVesting?: boolean, | |
| ) => { | |
| let approved = null | |
| try { | |
| if (isVesting) { | |
| approved = await contractGraphToken.allowance( | |
| contractVestingAddress, | |
| contractToCheckAddress, | |
| ) | |
| } else { | |
| approved = await contractGraphToken.allowance( | |
| ethereumAccount, | |
| contractToCheckAddress, | |
| ) | |
| } | |
| } catch (e) { | |
| console.error(`Failed to get allowance: ${e.message}`) | |
| } | |
| return approved | |
| } | |
| export const calculateTokensToSignal = async ( | |
| isNameSignal: boolean, | |
| curationTax: BigNumber, | |
| minimumCurationDeposit: BigNumber, | |
| nameSignalAmount: BigNumber, | |
| deployment: SubgraphDeployment, | |
| ) => { | |
| let signal = null | |
| try { | |
| if (isNameSignal) { | |
| signal = await tokensToNSignal( | |
| deployment.signalledTokens, | |
| bigNumberify(deployment.reserveRatio), | |
| deployment.signalAmount, | |
| E18_100K, | |
| curationTax, | |
| minimumCurationDeposit, | |
| nameSignalAmount, | |
| bigNumberify('123'), // this is Signal.signal | |
| ) | |
| } else { | |
| // add tokensToSignal | |
| } | |
| return signal | |
| } catch (e) { | |
| console.error(`Unable to calculate tokens to signal: ${e.message}`) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment