Skip to content

Commit 6455de0

Browse files
authored
Merge pull request #10 from brainbot-com/feature/refund-on-failure
Feature/refund on failure
2 parents ad8ffde + fb48a77 commit 6455de0

24 files changed

+688
-467
lines changed

packages/bots/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"scripts": {},
66
"dependencies": {
77
"better-queue": "^3.8.11",
8+
"date-fns": "^2.29.3",
89
"ethers": "^5.6.9",
910
"yargs": "^17.5.1"
1011
},
1112
"devDependencies": {
13+
"@types/better-queue": "^3.8.3",
1214
"@types/node": "^18.7.6",
1315
"@types/yargs": "^17.0.11",
14-
"@types/better-queue": "^3.8.3",
1516
"ts-node": "^10.9.1",
1617
"typescript": "^4.7.4"
1718
}

packages/bots/src/commitments.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AddressZero } from "@ethersproject/constants";
55
import { getConfig } from "./config";
66
import { formatEther } from "ethers/lib/utils";
77
import Queue from "better-queue";
8+
import { fromUnixTime, getUnixTime, subSeconds } from "date-fns";
89

910
type SwapCommitment = {
1011
id: string;
@@ -152,10 +153,10 @@ const match = async (swapCommitment: SwapCommitment) => {
152153

153154
if (
154155
endTimeStamp.lt(
155-
BigNumber.from(Math.floor((Date.now() + 1000 * 60 * 3) / 1000))
156+
BigNumber.from(Math.floor((Date.now() + 1000 * 60 * 1) / 1000))
156157
)
157158
) {
158-
throw new Error(`> Source commitment ${id} appears to be expired`);
159+
throw new Error(`> Source commitment ${id} expires in less than 3 minutes`);
159160
}
160161

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

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

packages/website/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ NEXT_PUBLIC_DUMP_DISCOUNT_PERCENTAGE=2
88
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
99
NEXT_PUBLIC_PRICE_CURRENCY_ID=ethereum-pow-iou
1010
# Add the chain ids of the chains on which the user can start a swap. If multiple, separate them with a comma
11-
NEXT_PUBLIC_ENFORCE_SWAP_ON_CHAINS=10011
11+
NEXT_PUBLIC_ENFORCE_SWAP_ON_CHAINS=10011
12+
NEXT_PUBLIC_POS_CHAIN_ID=1
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {useWeb3React} from '@web3-react/core'
2+
import {Web3Provider} from '@ethersproject/providers'
3+
import {Button} from '../button'
4+
import {switchChain} from '../../utils/switchChain'
5+
import React from 'react'
6+
7+
export const ChangeChain = ({chainId}: { chainId: number }) => {
8+
const {connector} = useWeb3React<Web3Provider>()
9+
10+
return (
11+
<>
12+
<Button
13+
buttonType={'primary'}
14+
onClick={async () => {
15+
try {
16+
await switchChain(connector, chainId)
17+
} catch (e) {
18+
console.log('You need to switch the chain', e)
19+
}
20+
}}
21+
>
22+
Switch Chain
23+
</Button>
24+
</>
25+
)
26+
}

0 commit comments

Comments
 (0)