Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/bots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"scripts": {},
"dependencies": {
"better-queue": "^3.8.11",
"date-fns": "^2.29.3",
"ethers": "^5.6.9",
"yargs": "^17.5.1"
},
"devDependencies": {
"@types/better-queue": "^3.8.3",
"@types/node": "^18.7.6",
"@types/yargs": "^17.0.11",
"@types/better-queue": "^3.8.3",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
Expand Down
9 changes: 6 additions & 3 deletions packages/bots/src/commitments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AddressZero } from "@ethersproject/constants";
import { getConfig } from "./config";
import { formatEther } from "ethers/lib/utils";
import Queue from "better-queue";
import { fromUnixTime, getUnixTime, subSeconds } from "date-fns";

type SwapCommitment = {
id: string;
Expand Down Expand Up @@ -152,10 +153,10 @@ const match = async (swapCommitment: SwapCommitment) => {

if (
endTimeStamp.lt(
BigNumber.from(Math.floor((Date.now() + 1000 * 60 * 3) / 1000))
BigNumber.from(Math.floor((Date.now() + 1000 * 60 * 1) / 1000))
)
) {
throw new Error(`> Source commitment ${id} appears to be expired`);
throw new Error(`> Source commitment ${id} expires in less than 3 minutes`);
}

const sourceContract = config.source.contract;
Expand Down Expand Up @@ -192,9 +193,11 @@ const match = async (swapCommitment: SwapCommitment) => {

console.log(`> Trying to add commitment ${id} on target chain`);
const fee = await ethSwapContractOnTarget.feeFromSwapValue(expectedAmount);
// 3 minutes should be more than enough time for the bot to reveal the secret on the PoS chain
const expireAt = getUnixTime(subSeconds(fromUnixTime(endTimeStamp.toNumber()), 1*60))
const commitmentOnTargetResponse = await ethSwapContractOnTarget[
"commit(uint64,bytes32,uint256,uint256,address)"
](endTimeStamp, hashedSecret, expectedAmount, value, initiator, {
](expireAt, hashedSecret, expectedAmount, value, initiator, {
value: expectedAmount.add(fee)
});

Expand Down
3 changes: 2 additions & 1 deletion packages/website/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ NEXT_PUBLIC_DUMP_DISCOUNT_PERCENTAGE=2
NEXT_PUBLIC_PRICE_FEED_API_URL=https://api.coingecko.com/api/v3/simple/price?ids=ethereum-pow-iou&vs_currencies=eth&include_last_updated_at=true
NEXT_PUBLIC_PRICE_CURRENCY_ID=ethereum-pow-iou
# Add the chain ids of the chains on which the user can start a swap. If multiple, separate them with a comma
NEXT_PUBLIC_ENFORCE_SWAP_ON_CHAINS=10011
NEXT_PUBLIC_ENFORCE_SWAP_ON_CHAINS=10011
NEXT_PUBLIC_POS_CHAIN_ID=1
26 changes: 26 additions & 0 deletions packages/website/components/dump-box/change-chain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {useWeb3React} from '@web3-react/core'
import {Web3Provider} from '@ethersproject/providers'
import {Button} from '../button'
import {switchChain} from '../../utils/switchChain'
import React from 'react'

export const ChangeChain = ({chainId}: { chainId: number }) => {
const {connector} = useWeb3React<Web3Provider>()

return (
<>
<Button
buttonType={'primary'}
onClick={async () => {
try {
await switchChain(connector, chainId)
} catch (e) {
console.log('You need to switch the chain', e)
}
}}
>
Switch Chain
</Button>
</>
)
}
Loading