diff --git a/package.json b/package.json index e3179d3..6f6131e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@ajna-finance/sdk", "description": "A typescript SDK that can be used to create Dapps in Ajna ecosystem.", - "version": "0.4.1", + "version": "0.4.2", "repository": { "type": "git", "url": "https://github.com/ajna-finance/sdk.git" diff --git a/src/abis/DSToken.json b/src/abis/DSToken.json new file mode 100644 index 0000000..73c7d65 --- /dev/null +++ b/src/abis/DSToken.json @@ -0,0 +1,325 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "stop", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "guy", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "owner_", "type": "address" }], + "name": "setOwner", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "src", "type": "address" }, + { "name": "dst", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "guy", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "mint", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "wad", "type": "uint256" }], + "name": "burn", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "name_", "type": "bytes32" }], + "name": "setName", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "src", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "stopped", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "authority_", "type": "address" }], + "name": "setAuthority", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "name": "", "type": "bytes32" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "guy", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "wad", "type": "uint256" }], + "name": "mint", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "dst", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "dst", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "push", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "src", "type": "address" }, + { "name": "dst", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "move", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "start", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "authority", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "guy", "type": "address" }], + "name": "approve", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "src", "type": "address" }, + { "name": "guy", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "src", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "pull", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "name": "symbol_", "type": "bytes32" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "guy", "type": "address" }, + { "indexed": false, "name": "wad", "type": "uint256" } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "guy", "type": "address" }, + { "indexed": false, "name": "wad", "type": "uint256" } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "name": "authority", "type": "address" }], + "name": "LogSetAuthority", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "name": "owner", "type": "address" }], + "name": "LogSetOwner", + "type": "event" + }, + { + "anonymous": true, + "inputs": [ + { "indexed": true, "name": "sig", "type": "bytes4" }, + { "indexed": true, "name": "guy", "type": "address" }, + { "indexed": true, "name": "foo", "type": "bytes32" }, + { "indexed": true, "name": "bar", "type": "bytes32" }, + { "indexed": false, "name": "wad", "type": "uint256" }, + { "indexed": false, "name": "fax", "type": "bytes" } + ], + "name": "LogNote", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "from", "type": "address" }, + { "indexed": true, "name": "to", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "owner", "type": "address" }, + { "indexed": true, "name": "spender", "type": "address" }, + { "indexed": false, "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + } +] diff --git a/src/classes/FungiblePool.ts b/src/classes/FungiblePool.ts index 282efa6..4d733f0 100644 --- a/src/classes/FungiblePool.ts +++ b/src/classes/FungiblePool.ts @@ -1,6 +1,6 @@ -import { BigNumber, Signer, constants } from 'ethers'; +import { BigNumber, Signer, constants, utils } from 'ethers'; import { MAX_FENWICK_INDEX } from '../constants'; -import { getErc20Contract } from '../contracts/erc20'; +import { getErc20Contract, getDSTokenContract } from '../contracts/erc20'; import { addCollateral, approve, @@ -35,8 +35,15 @@ export class FungiblePool extends Pool { async initialize() { await super.initialize(); - const collateralToken = getErc20Contract(this.collateralAddress, this.provider); - this.collateralSymbol = (await collateralToken.symbol()).replace(/"+/g, ''); + try { + const collateralToken = getErc20Contract(this.collateralAddress, this.provider); + this.collateralSymbol = (await collateralToken.symbol()).replace(/"+/g, ''); + } catch (e) { + const collateralToken = getDSTokenContract(this.collateralAddress, this.provider); + this.collateralSymbol = utils + .parseBytes32String(await collateralToken.symbol()) + .replace(/"+/g, ''); + } this.name = this.collateralSymbol + '-' + this.quoteSymbol; } diff --git a/src/classes/Pool.ts b/src/classes/Pool.ts index 5ca0031..22baf43 100644 --- a/src/classes/Pool.ts +++ b/src/classes/Pool.ts @@ -1,5 +1,5 @@ import { Contract as ContractMulti, Provider as ProviderMulti } from 'ethcall'; -import { BigNumber, Contract, Signer, constants } from 'ethers'; +import { BigNumber, Contract, Signer, constants, utils } from 'ethers'; import { COLLATERALIZATION_FACTOR, ERC20_NON_SUBSET_HASH, @@ -7,7 +7,7 @@ import { MAX_INFLATED_PRICE_WAD, } from '../constants'; import { multicall } from '../contracts/common'; -import { getErc20Contract } from '../contracts/erc20'; +import { getErc20Contract, getDSTokenContract } from '../contracts/erc20'; import { approve } from '../contracts/erc20-pool'; import { collateralAddress, @@ -181,8 +181,13 @@ export abstract class Pool { this.quoteAddress = quoteAddressResponse; this.collateralAddress = collateralAddressResponse; - const quoteToken = getErc20Contract(this.quoteAddress, this.provider); - this.quoteSymbol = (await quoteToken.symbol()).replace(/"+/g, ''); + try { + const quoteToken = getErc20Contract(this.quoteAddress, this.provider); + this.quoteSymbol = (await quoteToken.symbol()).replace(/"+/g, ''); + } catch (e) { + const quoteToken = getDSTokenContract(this.quoteAddress, this.provider); + this.quoteSymbol = utils.parseBytes32String(await quoteToken.symbol()).replace(/"+/g, ''); + } } /** diff --git a/src/contracts/erc20.ts b/src/contracts/erc20.ts index 1ce36d9..a042ec4 100644 --- a/src/contracts/erc20.ts +++ b/src/contracts/erc20.ts @@ -1,4 +1,5 @@ import erc20Abi from '../abis/ERC20.json'; +import DSTokenAbi from '../abis/DSToken.json'; import { Address, SignerOrProvider, WrappedTransaction } from '../types'; import { BigNumber, Contract, Signer, ethers } from 'ethers'; import ajnaTokenAbi from '../abis/AjnaToken.json'; @@ -10,6 +11,10 @@ export const getErc20Contract = (contractAddress: Address, provider: SignerOrPro return new ethers.Contract(contractAddress, erc20Abi, provider); }; +export const getDSTokenContract = (contractAddress: Address, provider: SignerOrProvider) => { + return new ethers.Contract(contractAddress, DSTokenAbi, provider); +}; + export const getAjnaTokenContract = (provider: SignerOrProvider) => { return new ethers.Contract(checksumAddress(Config.ajnaToken), ajnaTokenAbi, provider); };