Skip to content

Commit

Permalink
Merge pull request #49 from BuiltByMom/bugfix/dstoken-support
Browse files Browse the repository at this point in the history
feat: add DStoken support
  • Loading branch information
Majorfi authored Mar 11, 2024
2 parents 4b202b7 + ecb7b54 commit ec7ece6
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
325 changes: 325 additions & 0 deletions src/abis/DSToken.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
15 changes: 11 additions & 4 deletions src/classes/FungiblePool.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 9 additions & 4 deletions src/classes/Pool.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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,
MAX_FENWICK_INDEX,
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,
Expand Down Expand Up @@ -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, '');
}
}

/**
Expand Down
Loading

0 comments on commit ec7ece6

Please sign in to comment.