otomato-sdk 2.0.480 → 2.0.481
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
// Polymarket Safe Wallet (browser wallet: MetaMask, Rainbow, Coinbase Wallet, etc.)
|
|
3
|
+
const SAFE_FACTORY = '0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b';
|
|
4
|
+
const SAFE_INIT_CODE_HASH = '0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf';
|
|
5
|
+
const POLYMARKET_DATA_API_URL = 'https://data-api.polymarket.com';
|
|
6
|
+
/**
|
|
7
|
+
* Derives the Polymarket Safe wallet address from an EOA using CREATE2.
|
|
8
|
+
* Used for browser wallet users (MetaMask, Rainbow, Coinbase Wallet, etc.).
|
|
9
|
+
*
|
|
10
|
+
* CREATE2: keccak256(0xff ++ factory ++ salt ++ initCodeHash)[12:]
|
|
11
|
+
* Salt: keccak256(abi.encode(eoaAddress))
|
|
12
|
+
*
|
|
13
|
+
* @param eoaAddress - User's externally owned account address
|
|
14
|
+
* @returns The Polymarket Safe wallet address on Polygon
|
|
15
|
+
*/
|
|
16
|
+
export function derivePolymarketSafeAddress(eoaAddress) {
|
|
17
|
+
const salt = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(['address'], [eoaAddress]));
|
|
18
|
+
return ethers.getCreate2Address(SAFE_FACTORY, salt, SAFE_INIT_CODE_HASH);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Detects whether the given address is an EOA (from which we derive the Polymarket Safe)
|
|
22
|
+
* or a Polymarket wallet address provided directly by the user (Magic/email users).
|
|
23
|
+
*
|
|
24
|
+
* Detection logic:
|
|
25
|
+
* 1. Check if the address itself has positions on Polymarket → POLYMARKET_DIRECT
|
|
26
|
+
* 2. Derive the Safe address and check if it has positions → EOA
|
|
27
|
+
* 3. No activity on either → default to EOA
|
|
28
|
+
*
|
|
29
|
+
* @param address - The address to detect
|
|
30
|
+
* @returns The address type and the resolved Polymarket wallet address
|
|
31
|
+
*/
|
|
32
|
+
export async function detectAddressType(address) {
|
|
33
|
+
// Check if this address has positions on Polymarket directly
|
|
34
|
+
const directPositions = await fetchPolymarketPositions(address);
|
|
35
|
+
if (directPositions !== null && directPositions.length > 0) {
|
|
36
|
+
return { type: 'POLYMARKET_DIRECT', polymarketAddress: address };
|
|
37
|
+
}
|
|
38
|
+
// Derive the Safe address and check that
|
|
39
|
+
const derivedSafe = derivePolymarketSafeAddress(address);
|
|
40
|
+
const derivedPositions = await fetchPolymarketPositions(derivedSafe);
|
|
41
|
+
if (derivedPositions !== null && derivedPositions.length > 0) {
|
|
42
|
+
return { type: 'EOA', polymarketAddress: derivedSafe };
|
|
43
|
+
}
|
|
44
|
+
// No activity found on either → assume EOA (will be checked again later)
|
|
45
|
+
return { type: 'EOA', polymarketAddress: derivedSafe };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the Polymarket wallet address from any input address.
|
|
49
|
+
* Handles both EOA (derives Safe) and direct Polymarket addresses.
|
|
50
|
+
*
|
|
51
|
+
* @param address - EOA or direct Polymarket address
|
|
52
|
+
* @returns The Polymarket wallet address to use for API calls
|
|
53
|
+
*/
|
|
54
|
+
export async function resolvePolymarketAddress(address) {
|
|
55
|
+
const { polymarketAddress } = await detectAddressType(address);
|
|
56
|
+
return polymarketAddress;
|
|
57
|
+
}
|
|
58
|
+
async function fetchPolymarketPositions(address) {
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(`${POLYMARKET_DATA_API_URL}/positions?user=${address}`);
|
|
61
|
+
if (!response.ok)
|
|
62
|
+
return null;
|
|
63
|
+
return await response.json();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.481";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type PolymarketAddressType = 'EOA' | 'POLYMARKET_DIRECT';
|
|
2
|
+
/**
|
|
3
|
+
* Derives the Polymarket Safe wallet address from an EOA using CREATE2.
|
|
4
|
+
* Used for browser wallet users (MetaMask, Rainbow, Coinbase Wallet, etc.).
|
|
5
|
+
*
|
|
6
|
+
* CREATE2: keccak256(0xff ++ factory ++ salt ++ initCodeHash)[12:]
|
|
7
|
+
* Salt: keccak256(abi.encode(eoaAddress))
|
|
8
|
+
*
|
|
9
|
+
* @param eoaAddress - User's externally owned account address
|
|
10
|
+
* @returns The Polymarket Safe wallet address on Polygon
|
|
11
|
+
*/
|
|
12
|
+
export declare function derivePolymarketSafeAddress(eoaAddress: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Detects whether the given address is an EOA (from which we derive the Polymarket Safe)
|
|
15
|
+
* or a Polymarket wallet address provided directly by the user (Magic/email users).
|
|
16
|
+
*
|
|
17
|
+
* Detection logic:
|
|
18
|
+
* 1. Check if the address itself has positions on Polymarket → POLYMARKET_DIRECT
|
|
19
|
+
* 2. Derive the Safe address and check if it has positions → EOA
|
|
20
|
+
* 3. No activity on either → default to EOA
|
|
21
|
+
*
|
|
22
|
+
* @param address - The address to detect
|
|
23
|
+
* @returns The address type and the resolved Polymarket wallet address
|
|
24
|
+
*/
|
|
25
|
+
export declare function detectAddressType(address: string): Promise<{
|
|
26
|
+
type: PolymarketAddressType;
|
|
27
|
+
polymarketAddress: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the Polymarket wallet address from any input address.
|
|
31
|
+
* Handles both EOA (derives Safe) and direct Polymarket addresses.
|
|
32
|
+
*
|
|
33
|
+
* @param address - EOA or direct Polymarket address
|
|
34
|
+
* @returns The Polymarket wallet address to use for API calls
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolvePolymarketAddress(address: string): Promise<string>;
|