Typescript library for interacting with the UXD contracts on EVM.
- Build the package
npm run build
- Generate typing files from contract ABIs
sh ./scripts/generate-types.sh
- Run the linter to properly format typescript files.
npm run format
npm i "uxd-evm-client@0.2.3"
https://github.com/dethcrypto/TypeChain
Run the following command that will generate typing for contracts:
./scripts/generate-types.sh
You need to import the UXDController from the library as well as the ethers library
import { ethers } from "ethers";
import { UXDClient } from "uxd-evm-client";
The client must be initialized with following parameters:
- JSON RPC provider pointing to the kovan optimism RPC endpoint.
- UXD Controller contract address on kovan optimism.
- The address of the depository
- UXD token on kovan optimism.
The provider can be injected when using Metamask or other browser wallet
const controller = "..."; // controller address
const depository = "..."; // depository address
const redeemable = "..."; // redeemable address
const provider = new ethers.providers.JsonRpcProvider("https://goerli.optimism.io");
const client = new UXDClient({
provider,
controller,
depository
redeemable
});
You can then start calling functions on the controller
const controller = client.controller();
const totalSupply = await controller.getRedeemableMintCirculatingSupply();
console.log("totalsupply = ", totalSupply);
To mint with WETH can call the mint()
function:
await controller.mint(
ethAmount,
targetePrice,
signer,
collateralAddress
)
Note: The controller must be approved to access the users WETH otherwise the call with revert with an error.
To approve the controller to spend WETH:
await controller.approveToken(contractAddress, spender, amount, signer);
await controller.mintWithEth(ethAmount, targetPrice, signer);
No prior approval is required to mint with native ETH.
await controller.redeem(wethAddress, uxdAmount, targetPrice, signer);
await controller.redeemEth(uxdAmount, targetPrice, signer);
Check here to see the list of public functions availale on the controller.
Version 1.0.0 has been unpublished. Current version are tagged as beta 0.0.1-beta.X