forked from paraswap/paraswap-dex-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-new-limit-order.ts
107 lines (94 loc) · 2.94 KB
/
generate-new-limit-order.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as dotenv from 'dotenv';
dotenv.config();
import { ethers } from 'ethers';
import { Address } from '@paraswap/core';
import { Network, NULL_ADDRESS } from '../src/constants';
import { ParaSwapLimitOrdersConfig } from '../src/dex/paraswap-limit-orders/config';
import { generateConfig } from '../src/config';
const network = Network.ROPSTEN;
const provider = ethers.getDefaultProvider(
generateConfig(network).privateHttpProvider,
);
const makerPK = process.env.MAKER_PK || '';
const taker = '0xCf8C4a46816b146Ed613d23f6D22e1711915d653';
const maker = new ethers.Wallet(makerPK, provider);
const dexKey = 'ParaSwapLimitOrders';
const rfqAddress =
ParaSwapLimitOrdersConfig[dexKey][network].rfqAddress.toLowerCase();
const wethAddress = '0xc778417e063141139fce010982780140aa0cd5ab';
const daiAddress = '0xad6d458402f60fd3bd25163575031acdce07538d';
const name = 'AUGUSTUS RFQ';
const version = '1';
const OrderSchema = [
{ name: 'nonceAndMeta', type: 'uint256' },
{ name: 'expiry', type: 'uint128' },
{ name: 'makerAsset', type: 'address' },
{ name: 'takerAsset', type: 'address' },
{ name: 'maker', type: 'address' },
{ name: 'taker', type: 'address' },
{ name: 'makerAmount', type: 'uint256' },
{ name: 'takerAmount', type: 'uint256' },
];
function getRandomInt(): number {
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
}
function buildOrderData(
chainId: number,
verifyingContract: Address,
nonceAndMeta: string,
expiry: number,
makerAsset: Address,
takerAsset: Address,
makerAmount: string,
takerAmount: string,
maker: Address,
taker: Address = NULL_ADDRESS,
) {
const order = {
nonceAndMeta,
expiry,
makerAsset,
takerAsset,
maker,
taker,
makerAmount,
takerAmount,
};
return {
types: { Order: OrderSchema },
domain: { name, version, chainId, verifyingContract },
order,
};
}
async function createOrder(makerAmount: string, takerAmount: string) {
const nonceAndMeta = (BigInt(getRandomInt()) << BigInt(160)).toString(10);
const { order, domain, types } = buildOrderData(
network,
rfqAddress,
nonceAndMeta,
0,
daiAddress,
wethAddress,
makerAmount,
takerAmount,
maker.address,
);
console.log('lo', domain, types, order);
const signature = await maker._signTypedData(domain, types, order);
const respOrder = {
...order,
nonceAndMeta: `${order.nonceAndMeta}`,
makerAmount: order.makerAmount.toString(),
takerAmount: order.takerAmount.toString(),
makerAsset: order.makerAsset.toString(),
takerAsset: order.takerAsset.toString(),
signature: signature,
};
console.log(JSON.stringify(respOrder));
}
(async function main() {
// These are the orders which are used in paraswap-limit-orders-e2e-test.ts
await createOrder('10000000000000000000', '20000000000000000');
await createOrder('50000000000000000000', '110000000000000000');
await createOrder('70000000000000000000', '170000000000000000');
})();