Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
while (true) {
const sendTransactionTime = Date.now()
// randomly choose which token to use
const transferGold = Boolean(Math.round(Math.random()))
const transferFn = transferGold ? transferCeloGold : transferCeloDollars
baseLogMessage.tokenName = transferGold ? 'cGLD' : 'cUSD'
// randomly choose which gas currency to use
const feeCurrencyGold = Boolean(Math.round(Math.random()))
let feeCurrency
if (!feeCurrencyGold) {
try {
feeCurrency = await kit.registry.addressFor(CeloContract.StableToken)
} catch (error) {
tracerLog({
tag: LOG_TAG_CONTRACT_ADDRESS_ERROR,
error: error.toString(),
...baseLogMessage,
})
}
}
baseLogMessage.feeCurrency = feeCurrency || ''
// We purposely do not use await syntax so we sleep after sending the transaction,
// not after processing a transaction's result
transferFn(kit, senderAddress, recipientAddress, LOAD_TEST_TRANSFER_WEI, {
feeCurrency,
})
.then(async (txResult: TransactionResult) => {
describe('gasCurrency = CeloGold >', () => {
testTransferToken({
expectedGas: 40456,
transferToken: CeloContract.StableToken,
feeToken: CeloContract.GoldToken,
txOptions: {
gasFeeRecipient: FeeRecipientAddress,
},
})
})
})
before(async () => {
const gasCurrency =
feeToken === CeloContract.StableToken
? await kit.registry.addressFor(CeloContract.StableToken)
: undefined
const accounts = [FromAddress, ToAddress, validatorAddress, FeeRecipientAddress]
balances = await newBalanceWatcher(kit, accounts)
const transferFn =
transferToken === CeloContract.StableToken ? transferCeloDollars : transferCeloGold
const txResult = await transferFn(FromAddress, ToAddress, TransferAmount, {
...txOptions,
gasCurrency,
})
txRes = await runTestTransaction(txResult, expectedGas, gasCurrency)
await balances.update()
before(async () => {
const gasCurrency =
feeToken === CeloContract.StableToken
? await kit.registry.addressFor(CeloContract.StableToken)
: undefined
const accounts = [FromAddress, ToAddress, validatorAddress, FeeRecipientAddress]
balances = await newBalanceWatcher(kit, accounts)
const transferFn =
transferToken === CeloContract.StableToken ? transferCeloDollars : transferCeloGold
const txResult = await transferFn(FromAddress, ToAddress, TransferAmount, {
...txOptions,
gasCurrency,
})
txRes = await runTestTransaction(txResult, expectedGas, gasCurrency)
await balances.update()
})
describe('when setting a gas amount less than the amount of gas necessary but more than the intrinsic gas amount', () => {
const gas = intrinsicGas + 1000
testTransferToken({
expectedGas: gas,
transferToken: CeloContract.GoldToken,
feeToken: CeloContract.StableToken,
expectSuccess: false,
txOptions: {
gas,
gasFeeRecipient: FeeRecipientAddress,
},
})
})
export async function getTokenAddresses() {
if (goldTokenAddress && stableTokenAddress) {
return { goldTokenAddress, stableTokenAddress }
} else {
const kit = await getContractKit()
goldTokenAddress = await kit.registry.addressFor(CeloContract.GoldToken)
stableTokenAddress = await kit.registry.addressFor(CeloContract.StableToken)
return { goldTokenAddress, stableTokenAddress }
}
}
async function getFeeCurrencyContractAddress(
kit: ContractKit,
feeCurrency: FeeCurrency
): Promise {
switch (feeCurrency) {
case FeeCurrency.cUSD:
return kit.registry.addressFor(CeloContract.StableToken)
case FeeCurrency.cGLD:
return kit.registry.addressFor(CeloContract.GoldToken)
default:
return kit.registry.addressFor(CeloContract.StableToken)
}
}
import { BaseCommand } from '../../base'
export default class GetRates extends BaseCommand {
static description = 'Get the current set oracle-reported rates for the given token'
static flags = {
...BaseCommand.flags,
}
static args = [
{
name: 'token',
required: true,
description: 'Token to get the rates for',
options: [CeloContract.StableToken],
default: CeloContract.StableToken,
},
]
static example = ['rates StableToken', 'rates']
async run() {
const res = this.parse(GetRates)
const sortedOracles = await this.kit.contracts.getSortedOracles()
const rates = await sortedOracles.getRates(res.args.token)
cli.table(
rates,
{
address: {},
rate: { get: (r) => r.rate.toNumber() },
},
import { cli } from 'cli-ux'
import { BaseCommand } from '../../base'
export default class GetRates extends BaseCommand {
static description = 'Get the current set oracle-reported rates for the given token'
static flags = {
...BaseCommand.flags,
}
static args = [
{
name: 'token',
required: true,
description: 'Token to get the rates for',
options: [CeloContract.StableToken],
default: CeloContract.StableToken,
},
]
static example = ['rates StableToken', 'rates']
async run() {
const res = this.parse(GetRates)
const sortedOracles = await this.kit.contracts.getSortedOracles()
const rates = await sortedOracles.getRates(res.args.token)
cli.table(
rates,
{
address: {},
rate: { get: (r) => r.rate.toNumber() },