makeAtomicSwap method in bridge

This commit is contained in:
Aleksandr Kraiz
2023-08-23 15:44:20 +04:00
parent 98d1d0f704
commit 5c81ca55c7
2 changed files with 31 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.19.57",
"version": "0.19.58",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -1,4 +1,4 @@
import type { ethers } from 'ethers';
import { ethers } from 'ethers';
import {
type AtomicSwap, type SupportedChainId,
type Unit, INTERNAL_PROTOCOL_PRECISION
@@ -7,7 +7,10 @@ import getHistoryExt from './getHistory.js';
import swapExt from './swap.js';
import { BigNumber } from 'bignumber.js';
import generateSecret from '../../utils/generateSecret.js';
export const SECONDS_IN_DAY = 60 * 60 * 24;
export const EXPIRATION_DAYS = 4;
export default class Bridge {
constructor(
private readonly unitsArray: Unit[],
@@ -71,6 +74,32 @@ export default class Bridge {
});
}
makeAtomicSwap = (
walletAddress: string,
networkFrom: SupportedChainId,
networkTo: SupportedChainId,
amount: string,
asset: string,
env?: string | undefined,
) => {
const secret = generateSecret();
const secretHash = ethers.utils.keccak256(secret);
const lockExpiration = Date.now() + SECONDS_IN_DAY * EXPIRATION_DAYS * 1000;
return {
sourceChainId: networkFrom,
targetChainId: networkTo,
amount,
walletAddress,
secret,
secretHash,
assetName: asset,
creationDate: Date.now(),
lockExpiration,
env,
};
}
getHistory(address: string, limit = 1000) {
return getHistoryExt(this.unitsArray, address, limit);
}