-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md.old
157 lines (140 loc) · 4 KB
/
README.md.old
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# mimicry-sdk
A node SDK designed to simplify interaction with the Mimicry Protocol smart contracts.
## Summary
Mimicry is working to release an NPM library that will provide convenient access to contract methods. The intended audience is professional traders and market makers who wish to programmatically manage positions, and application developers who wish to integrate Mimicry Markets.
## Setup
The SDK allows developers to instantiate an instance in a few lines of code. For example:
```typescript
import { MimicrySDK } from "@mimicry/mimicry-sdk";
import { ethers } from "ethers";
const pk = process.env.PRIVATE_KEY;
const providerUrl = process.env.PROVIDER_URL;
const provider = new ethers.providers.JsonRpcProvider(providerUrl);
const signer = new ethers.Wallet(pk as string, provider);
const mimicry = new MimicrySDK(signer);
```
## Types
```typescript
interface PositionInfo {
id: number,
createdAt: number, // unix timestamp
createdOn: number // block number
createdBy: Player,
direction: Direction,
market: Market,
player: Player,
transfers: Transfer[],
usdValue: number,
exitFee: 30, // basis points
doesEarnFees: false,
unrealizedProfit: BigNumber,
realizedProfit: BigNumber
}
interface Market {
id: number,
createdAt: Date,
createdBy: Player,
name: string,
oracle: Oracle,
positions: Position[],
players: Player[],
skew: Skew,
}
interface Skew {
long: Value;
short: Value;
}
interface Player {
address: string,
positions: Position[]
}
interface Oracle {
currency: Currency,
latestValue: Amount,
latestUpdateAt: Date,
}
// Deposit or Withdraw event
interface Transfer {
id: number,
cratedAt: Date,
direction: Direction,
type: TransferType,
values: Value[] // allows for multiple-currency withdraws
}
interface Value {
currency: CurrencyInfo,
amount: Amount
}
interface CurrencyInfo {
symbol: string, // e.g. WETH
decimals: number, // e.g. 18
chainId: Chain, // e.g. 137
address: string, // e.g. 0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619
}
interface Amount {
atomic: BigNumber, // e.g. 26476561042796000000000
decimal: number // e.g. 26476.561042796
}
```
## Currencies
```typescript
const currencyInfos: CurrencyInfo[] = await mimicry.getCurrencies();
console.log(currencyInfos[0]);
// {
// symbol: "WETH"
// decimals: 18
// chainId: 137
// address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619"
// }
```
## Positions
```typescript
const positions: Position[] = await mimicry.getPositions();
console.log(await positions[0].getInfo());
// {
// id: 123,
// createdAt: 1620594767,
// createdOn: 42512169,
// createdBy: {...},
// direction: "long",
// market: {...},
// player: {...},
// transfers: [{...}],
// usdValue: 10
// unrealizedProfit: 0
// realizedProfit: 0
// }
const position123: Position = await mimicry.getPosition(123);
const txId1: string = await position123.deposit(
Currency.USDC,
10800000 // position123 is now worth $20.8
);
const txId2: string = await position123.withdraw(500000); // 50%
const position123value: Value = await position123.value();
// {
// currency: {
// symbol: "USD",
// decimals: 8
// },
// amount: {
// atomic: 1040000000,
// decimal: 10.4
// }
// }
const txId3: string = await position123.close();
```
```typescript
/**
* Retrieves Positions opened by a wallet address.
*
* @param {string=} address - (Optional) The wallet address to retrieve the positions for. If omitted, the balance for the default wallet address will be retrieved.
* @returns {Position[]} A list of Positions
*/
function getPositions(address)
```
```typescript
// Gets a list of Positions
async function getPositions(address: string): Promise<Position[]>;
async function getPositions(address: string): Promise<Position[]>;
async function getPositions(address: string): Promise<Position[]>;
```