Smart Wallet Integration
How to open and close leveraged positions from Polymarket smart-contract wallets — Safe, Proxy, and the push-funded deposit wallet flow used by new API users.
Which wallet type?
Polymarket Safe
import {ethers} from "ethers";
const SAFE_ABI = [
"function nonce() view returns (uint256)",
"function getTransactionHash(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,uint256) view returns (bytes32)",
"function execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes) returns (bool)",
];
const safe = new ethers.Contract(safeAddress, SAFE_ABI, provider);
const vault = new ethers.Contract(vaultAddress, VAULT_ABI, provider);
// Encode the vault call
const data = vault.interface.encodeFunctionData("createPosition", [
quote.position_seed_hex,
quote.polymarket_market_id,
BigInt(quote.polymarket_token_id),
BigInt(quote.collateral_usdc_units),
quote.leverage_bps,
BigInt(quote.notional_usdc_units),
quote.origination_fee_bps,
quote.lifetime_fee_apr_bps,
quote.liquidation_fee_bps,
BigInt(quote.expected_open_trading_fee_usdc_units),
quote.contract_signature,
BigInt(quote.signature_expiry),
]);
// Build SafeTx and get the hash
const nonce = await safe.nonce();
const safeTxHash = await safe.getTransactionHash(
vaultAddress, 0, data, 0, 0, 0, 0, ethers.ZeroAddress, ethers.ZeroAddress, nonce,
);
// Owner signs the hash
const signature = await ownerSigner.signMessage(ethers.getBytes(safeTxHash));
// Anyone can submit (owner, partner backend, or relayer)
const tx = await safe.connect(submitterSigner).execTransaction(
vaultAddress, 0, data, 0, 0, 0, 0, ethers.ZeroAddress, ethers.ZeroAddress, signature,
);
await tx.wait();Polymarket Proxy
Polymarket Deposit Wallet
Why deposit wallets need the push-funded flow
The deposit wallet batch
Constant
Value
Opening a position
Closing a position
Relayer submission
Constraints
Last updated

