mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-28 00:28:04 +03:00
makeAtomicSwap method in bridge
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user