-
Notifications
You must be signed in to change notification settings - Fork 4
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 #108 from madfish-solutions/development
Release latest changes to production
- Loading branch information
Showing
18 changed files
with
828 additions
and
493 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
PORT=3000 | ||
QUIPUSWAP_FA12_FACTORIES=KT1K7whn5yHucGXMN7ymfKiX5r534QeaJM29,KT1Lw8hCoaBrHeTeMXbqHPG4sS4K1xn7yKcD,KT1FWHLMk5tHbwuSsp31S4Jum4dTVmkXpfJw | ||
QUIPUSWAP_FA2_FACTORIES=KT1MMLb2FVrrE9Do74J3FH1RNNc4QhDuVCNX,KT1SwH9P1Tx8a58Mm6qBExQFTcy2rwZyZiXS,KT1PvEyN1xCFCgorN92QCfYjw3axS6jawCiJ | ||
SHOULD_APP_CHECK_BLOCK_THE_APP=false | ||
IOS_APP_ID= | ||
ANDROID_APP_ID= | ||
MOONPAY_SECRET_KEY= | ||
ALICE_BOB_PUBLIC_KEY= | ||
ALICE_BOB_PRIVATE_KEY= | ||
THREE_ROUTE_API_URL= | ||
THREE_ROUTE_API_AUTH_TOKEN= |
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,2 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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,16 +1,24 @@ | ||
import { getEnv } from './utils/env'; | ||
import { isDefined } from './utils/helpers'; | ||
|
||
export const MIN_IOS_APP_VERSION = '1.10.445'; | ||
export const MIN_ANDROID_APP_VERSION = '1.10.445'; | ||
|
||
export const QUIPUSWAP_FA12_FACTORIES = getEnv('QUIPUSWAP_FA12_FACTORIES'); | ||
export const QUIPUSWAP_FA2_FACTORIES = getEnv('QUIPUSWAP_FA2_FACTORIES'); | ||
export const MOONPAY_SECRET_KEY = getEnv('MOONPAY_SECRET_KEY'); | ||
export const ALICE_BOB_PRIVATE_KEY = getEnv('ALICE_BOB_PRIVATE_KEY'); | ||
export const ALICE_BOB_PUBLIC_KEY = getEnv('ALICE_BOB_PUBLIC_KEY'); | ||
export const THREE_ROUTE_API_URL = getEnv('THREE_ROUTE_API_URL'); | ||
export const THREE_ROUTE_API_AUTH_TOKEN = getEnv('THREE_ROUTE_API_AUTH_TOKEN'); | ||
|
||
if (!Boolean(QUIPUSWAP_FA12_FACTORIES)) throw new Error('process.env.QUIPUSWAP_FA12_FACTORIES not found.'); | ||
if (!Boolean(QUIPUSWAP_FA2_FACTORIES)) throw new Error('process.env.QUIPUSWAP_FA2_FACTORIES not found.'); | ||
if (!Boolean(MOONPAY_SECRET_KEY)) throw new Error('process.env.MOONPAY_SECRET_KEY not found.'); | ||
if (!Boolean(ALICE_BOB_PRIVATE_KEY)) throw new Error('process.env.ALICE_BOB_PRIVATE_KEY not found.'); | ||
if (!Boolean(ALICE_BOB_PUBLIC_KEY)) throw new Error('process.env.ALICE_BOB_PUBLIC_KEY not found.'); | ||
const variablesToAssert = [ | ||
{ name: 'MOONPAY_SECRET_KEY', value: MOONPAY_SECRET_KEY }, | ||
{ name: 'ALICE_BOB_PRIVATE_KEY', value: ALICE_BOB_PRIVATE_KEY }, | ||
{ name: 'ALICE_BOB_PUBLIC_KEY', value: ALICE_BOB_PUBLIC_KEY }, | ||
{ name: 'THREE_ROUTE_API_URL', value: THREE_ROUTE_API_URL }, | ||
{ name: 'THREE_ROUTE_API_AUTH_TOKEN', value: THREE_ROUTE_API_AUTH_TOKEN } | ||
]; | ||
variablesToAssert.forEach(({ name, value }) => { | ||
if (!isDefined(value)) { | ||
throw new Error(`process.env.${name} not found.`); | ||
} | ||
}); |
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,57 @@ | ||
import { BlockResponse, BlockFullHeader } from '@taquito/rpc'; | ||
|
||
import { sleep } from './helpers'; | ||
import logger from './logger'; | ||
import { tezosToolkit } from './tezos'; | ||
|
||
export interface BlockInterface extends Pick<BlockResponse, 'protocol' | 'chain_id' | 'hash'> { | ||
header: Pick<BlockFullHeader, 'level' | 'timestamp'>; | ||
} | ||
|
||
export const EMPTY_BLOCK: BlockInterface = { | ||
protocol: '', | ||
chain_id: '', | ||
hash: '', | ||
header: { | ||
level: 0, | ||
timestamp: '' | ||
} | ||
}; | ||
|
||
export const blockFinder = async ( | ||
prevBlock: BlockInterface, | ||
onNewBlock: (block: BlockInterface) => Promise<unknown> | ||
): Promise<unknown> => { | ||
const block = await tezosToolkit.rpc | ||
.getBlock() | ||
.then( | ||
(blockResponse): BlockInterface => ({ | ||
protocol: blockResponse.protocol, | ||
chain_id: blockResponse.chain_id, | ||
hash: blockResponse.hash, | ||
header: { | ||
level: blockResponse.header.level, | ||
timestamp: blockResponse.header.timestamp | ||
} | ||
}) | ||
) | ||
.catch(e => { | ||
logger.error(e); | ||
|
||
return prevBlock; | ||
}); | ||
|
||
const isNewBlock = block.header.level > prevBlock.header.level; | ||
const realBlock = isNewBlock ? block : prevBlock; | ||
|
||
if (isNewBlock) { | ||
await onNewBlock(realBlock).catch(e => { | ||
logger.error('blockFinder error'); | ||
logger.error(e); | ||
}); | ||
} else { | ||
await sleep(200); | ||
} | ||
|
||
return blockFinder(realBlock, onNewBlock); | ||
}; |
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,35 @@ | ||
import { isDefined } from './helpers'; | ||
import logger from './logger'; | ||
import { makeBlockQuery } from './tzkt'; | ||
|
||
const PAST_BLOCKS_DEPTH = 4; | ||
|
||
export const getRecentDestinations = (currentBlockLevel: number) => | ||
Promise.all( | ||
new Array(PAST_BLOCKS_DEPTH).fill(0).map(async (_, index) => { | ||
const pastBlockLevel = currentBlockLevel - index; | ||
|
||
const { transactions } = await makeBlockQuery({ level: pastBlockLevel, operations: true }); | ||
|
||
if (isDefined(transactions)) { | ||
return transactions | ||
.map(transaction => { | ||
if (transaction?.type === 'transaction') { | ||
return transaction.target?.address ?? undefined; | ||
} | ||
|
||
return undefined; | ||
}) | ||
.filter(isDefined); | ||
} | ||
|
||
return []; | ||
}) | ||
).then( | ||
destinationsArray => destinationsArray.flat(), | ||
(error): string[] => { | ||
logger.error('getRecentDestinations error:', error); | ||
|
||
return []; | ||
} | ||
); |
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,16 +1,45 @@ | ||
import { AxiosError } from 'axios'; | ||
import { BigNumber } from 'bignumber.js'; | ||
|
||
export function range(start: number, end: number, step = 1) { | ||
return Array(Math.ceil((end - start) / step)) | ||
export const range = (start: number, end: number, step = 1) => | ||
Array(Math.ceil((end - start) / step)) | ||
.fill(0) | ||
.map((_x, index) => start + step * index); | ||
} | ||
|
||
export function rangeBn(start: number, end: number, step = 1): Array<BigNumber> { | ||
return Array(Math.ceil((end - start) / step)) | ||
export const rangeBn = (start: number, end: number, step = 1) => | ||
Array(Math.ceil((end - start) / step)) | ||
.fill(0) | ||
.map((_x, index) => new BigNumber(start + step * index)); | ||
} | ||
|
||
export const pick = <T extends object, U extends keyof T>(obj: T, keys: U[]) => { | ||
const newObj: Partial<T> = {}; | ||
keys.forEach(key => { | ||
if (key in obj) { | ||
newObj[key] = obj[key]; | ||
} | ||
}); | ||
|
||
return newObj as Pick<T, U>; | ||
}; | ||
|
||
export const isAbsoluteURL = (url: string) => { | ||
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL). | ||
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed | ||
// by any combination of letters, digits, plus, period, or hyphen. | ||
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
export const emptyFn = () => {}; | ||
|
||
export const isDefined = <T>(value: T | undefined | null): value is T => value !== undefined && value !== null; | ||
|
||
export const sleep = (ms: number) => new Promise(resolve => setTimeout(() => resolve('wake'), ms)); | ||
|
||
export const getExternalApiErrorPayload = (error: unknown) => { | ||
const response = error instanceof AxiosError ? error.response : undefined; | ||
const status = response?.status ?? 500; | ||
const data = response?.data ?? { error: error instanceof Error ? error.message : error }; | ||
|
||
return { status, data }; | ||
}; |
Oops, something went wrong.