uniswapx-sdk 1.2.0
Install from the command line:
Learn more about npm packages
$ npm install @helix-bridge/uniswapx-sdk@1.2.0
Install via package.json:
"@helix-bridge/uniswapx-sdk": "1.2.0"
About this version
SDK for the UniswapX protocol
The SDK contains bindings for two main flows: parsing serialized orders & building new orders.
import { DutchOrder, NonceManager } from '@uniswap/uniswapx-sdk';
import { ethers } from 'ethers';
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const account = await provider.getSigner().getAddress();
const nonceMgr = new NonceManager(provider, 1);
const nonce = await nonceMgr.useNonce(account);
const chainId = 1;
const builder = new DutchOrderBuilder(chainId);
const order = builder
.deadline(deadline)
.decayEndTime(deadline)
.decayStartTime(deadline - 100)
.nonce(nonce)
.input({
token: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
amount: BigNumber.from('1000000'),
})
.output({
token: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
startAmount: BigNumber.from('1000000000000000000'),
endAmount: BigNumber.from('900000000000000000'),
recipient: '0x0000000000000000000000000000000000000000',
})
.build();
// Sign the built order
const { domain, types, values } = order.permitData();
const signature = wallet._signTypedData(domain, types, values);
const serializedOrder = order.serialize();
// submit serializedOrder and signature to order pool
import { DutchOrder, Order } from '@uniswap/uniswapx-sdk';
const serializedOrder = '0x1111222233334444555500000000234300234...';
const chainId = 1;
const order: Order = DutchOrder.parse(serializedOrder, chainId);
const orderData = order.info;
const orderHash = order.hash();
import { ethers } from 'ethers';
import { OrderValidator } from 'uniswapx-sdk';
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const validator = new OrderValidator(provider, CHAIN_ID);
const orders: SignedOrder[] = [
{
order: order1,
signature: signature1
},
{
order: order2,
signature: signature2
}
];
try {
const statusList: OrderValidation[] = await validator.validateBatch(orders);
// Do something with list of statuses
}
catch(e) {
// Handle error
}
serialize()
Returns an abi-encoded serialization of the order. This serialized format is passed into the corresponding reactor contract for execution.
getSigner(signature)
Recovers the address which created the given signature over the order. Used to determine the order maker.
permitData()
Returns the domain, types, and values used to generate an EIP-712 signature over the order. Note that this signature both approves the release of the order's input tokens and the execution of the order itself.
hash()
Returns the order hash. This is used as a key to track order fulfillment on-chain. It may also be useful as a unique order identifier for off-chain purposes.