@aurigami/sdk 0.1.3 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,17 @@
1
1
  import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
2
2
  import { ProviderOrSigner, MoneyMarketDetails } from './types';
3
- import {
4
- validateAndParseAddress,
5
- Address,
6
- CurrencyAmount,
7
- } from '@pendle/sdk-core';
8
3
  import { Contract } from 'ethers';
9
4
  import AuToken from './abis/auToken.json';
10
- import IERC20 from './abis/IERC20.json';
5
+ // import IERC20 from './abis/IERC20.json';
11
6
  import { TransactionResponse } from '@ethersproject/abstract-provider';
12
7
  import { dummyToken, dummyTokenAmount, dummyTokenAmount2 } from './dummy';
8
+ import { TokenAmount } from './tokenAmount';
9
+ import { validateAndParseAddress } from './helpers';
10
+ import IERC20 from './abis/IERC20.json';
13
11
 
14
12
  export class MoneyMarketRead extends BlockchainEntityRead {
15
13
  protected _auToken: Contract;
16
- constructor(providerOrSigner: ProviderOrSigner, auToken: Address) {
14
+ constructor(providerOrSigner: ProviderOrSigner, auToken: string) {
17
15
  super(providerOrSigner);
18
16
  this._auToken = new Contract(auToken, AuToken.abi, providerOrSigner);
19
17
  }
@@ -40,16 +38,16 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
40
38
  );
41
39
  return await dummyErc20Token.approve(dummyToken.address, 123);
42
40
  };
43
- public async deposit(amount: CurrencyAmount): Promise<TransactionResponse> {
41
+ public async deposit(amount: TokenAmount): Promise<TransactionResponse> {
44
42
  return this.dummyTransaction();
45
43
  }
46
- public async borrow(amount: CurrencyAmount): Promise<TransactionResponse> {
44
+ public async borrow(amount: TokenAmount): Promise<TransactionResponse> {
47
45
  return this.dummyTransaction();
48
46
  }
49
- public async withdraw(amount: CurrencyAmount): Promise<TransactionResponse> {
47
+ public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
50
48
  return this.dummyTransaction();
51
49
  }
52
- public async repay(amount: CurrencyAmount): Promise<TransactionResponse> {
50
+ public async repay(amount: TokenAmount): Promise<TransactionResponse> {
53
51
  return this.dummyTransaction();
54
52
  }
55
53
  public async enableCollateral(): Promise<TransactionResponse> {
@@ -61,7 +59,7 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
61
59
  }
62
60
 
63
61
  export class MoneyMarket extends BlockchainEntity {
64
- protected address: Address;
62
+ protected address: string;
65
63
  constructor(address: string) {
66
64
  super();
67
65
  this.address = validateAndParseAddress(address);
package/src/SDK.ts CHANGED
@@ -13,11 +13,13 @@ import {
13
13
  ProviderOrSigner,
14
14
  UserDetails,
15
15
  } from './types';
16
- import { Token, CurrencyAmount } from '@pendle/sdk-core';
16
+
17
17
  import { AVAX_DEFAULT_PROVIDER_URL, DOLLAR } from './constants';
18
18
  import { TransactionResponse } from '@ethersproject/abstract-provider';
19
19
  import IERC20 from './abis/IERC20.json';
20
20
  import { Contract } from 'ethers';
21
+ import { TokenAmount } from './tokenAmount';
22
+ import { Token } from './token';
21
23
  const ethers = require('ethers');
22
24
 
23
25
  export class SdkRead extends BlockchainEntityRead {
@@ -37,52 +39,52 @@ export class SdkRead extends BlockchainEntityRead {
37
39
  return {
38
40
  markets: [dummyUserMarketDetails],
39
41
  borrowLimit: dummyTokenAmount3,
40
- accruedPly: new CurrencyAmount({
41
- currency: dummyPly,
42
- amount: '100.12',
43
- isRaw: false,
44
- }),
45
- lockedPly: new CurrencyAmount({
46
- currency: dummyPly,
47
- amount: '200.12',
48
- isRaw: false,
49
- }),
42
+ accruedPly: new TokenAmount(
43
+ dummyPly,
44
+ '100.12',
45
+ false,
46
+ ),
47
+ lockedPly: new TokenAmount(
48
+ dummyPly,
49
+ '200.12',
50
+ false,
51
+ ),
50
52
  borrowableAmount: dummyTokenAmount2,
51
53
  };
52
54
  }
53
55
 
54
56
  public async getPlyAuroraPoolDetails(): Promise<PlyAuroraPoolDetails> {
55
57
  return {
56
- totalStakedLiquidity: new CurrencyAmount({
57
- currency: dummyPlyAurora,
58
- amount: '12.1',
59
- isRaw: false,
60
- }),
58
+ totalStakedLiquidity: new TokenAmount(
59
+ dummyPlyAurora,
60
+ '12.1',
61
+ false,
62
+ ),
61
63
  apy: 1.21,
62
64
  };
63
65
  }
64
66
 
65
- public async getTokenPrice(token: Token): Promise<CurrencyAmount> {
67
+ public async getTokenPrice(token: Token): Promise<TokenAmount> {
66
68
  if (token.address == dummyToken.address) {
67
- return new CurrencyAmount({
68
- currency: DOLLAR,
69
- amount: '1',
70
- isRaw: false,
71
- });
69
+ return new TokenAmount(
70
+ DOLLAR,
71
+ '1',
72
+ false,
73
+ );
72
74
  }
73
75
 
74
- return new CurrencyAmount({
75
- currency: DOLLAR,
76
- amount: '12.1',
77
- isRaw: false,
78
- });
76
+ return new TokenAmount(
77
+ DOLLAR,
78
+ '12.1',
79
+ false,
80
+ );
79
81
  }
80
- public async stakeBalanceOf(user: string): Promise<CurrencyAmount> {
81
- return new CurrencyAmount({
82
- currency: dummyPlyAurora,
83
- amount: '103.4',
84
- isRaw: false,
85
- });
82
+ public async stakeBalanceOf(user: string): Promise<TokenAmount> {
83
+ return new TokenAmount(
84
+ dummyPlyAurora,
85
+ '103.4',
86
+ false,
87
+ );
86
88
  }
87
89
  }
88
90
 
@@ -98,10 +100,10 @@ export class SdkReadWrite extends SdkRead {
98
100
  public async claim(): Promise<TransactionResponse> {
99
101
  return this.dummyTransaction();
100
102
  }
101
- public async stake(amount: CurrencyAmount): Promise<TransactionResponse> {
103
+ public async stake(amount: TokenAmount): Promise<TransactionResponse> {
102
104
  return this.dummyTransaction();
103
105
  }
104
- public async unstake(amount: CurrencyAmount): Promise<TransactionResponse> {
106
+ public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
105
107
  return this.dummyTransaction();
106
108
  }
107
109
  }
package/src/constants.ts CHANGED
@@ -1,13 +1,10 @@
1
- import { Token } from '@pendle/sdk-core';
1
+ import { Token } from './token';
2
2
  // import ethers from 'ethers';
3
3
  const ethers = require('ethers');
4
4
  import { Signer } from 'ethers';
5
- export const DOLLAR = new Token({
6
- chainId: 43114,
7
- decimal: 2,
8
- symbol: 'USDC',
9
- address: '0x0000000000000000000000000000000000000001',
10
- });
5
+ export const DOLLAR = new Token(
6
+ '0x0000000000000000000000000000000000000001', 2
7
+ );
11
8
 
12
9
  export const AVAX_DEFAULT_PROVIDER_URL =
13
10
  'https://api.avax.network/ext/bc/C/rpc';
package/src/dummy.ts CHANGED
@@ -1,49 +1,35 @@
1
- import { Token, CurrencyAmount } from '@pendle/sdk-core';
1
+ import { Token } from './token';
2
+ import { TokenAmount } from './tokenAmount';
2
3
  import { UserMarketDetails } from './types';
3
4
 
4
- export const dummyToken = new Token({
5
- chainId: 43114,
6
- decimal: 6,
7
- symbol: 'USDC',
8
- address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
9
- });
10
-
11
- export const dummyPly = new Token({
12
- chainId: 43114,
13
- decimal: 18,
14
- symbol: 'QI',
15
- address: '0x8729438eb15e2c8b576fcc6aecda6a148776c0f5',
16
- });
17
-
18
- export const dummyPlyAurora = new Token({
19
- chainId: 43114,
20
- decimal: 18,
21
- symbol: 'QIWAVAX',
22
- address: '0xE530dC2095Ef5653205CF5ea79F8979a7028065c',
23
- });
24
-
25
- export const dummyTokenAmount = new CurrencyAmount({
26
- currency: dummyToken,
27
- amount: '123.456',
28
- isRaw: false,
29
- });
30
-
31
- export const dummyZeroTokenAmount = new CurrencyAmount({
32
- currency: dummyToken,
33
- amount: '0',
34
- });
35
-
36
- export const dummyTokenAmount2 = new CurrencyAmount({
37
- currency: dummyToken,
38
- amount: '456.123',
39
- isRaw: false,
40
- });
41
-
42
- export const dummyTokenAmount3 = new CurrencyAmount({
43
- currency: dummyToken,
44
- amount: '1000.123',
45
- isRaw: false,
46
- });
5
+ export const dummyToken = new Token('0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e', 6);
6
+
7
+ export const dummyPly = new Token('0x8729438eb15e2c8b576fcc6aecda6a148776c0f5', 18);
8
+
9
+ export const dummyPlyAurora = new Token('0xE530dC2095Ef5653205CF5ea79F8979a7028065c', 18);
10
+
11
+ export const dummyTokenAmount = new TokenAmount(
12
+ dummyToken,
13
+ '123.456',
14
+ false,
15
+ );
16
+
17
+ export const dummyZeroTokenAmount = new TokenAmount(
18
+ dummyToken,
19
+ '0',
20
+ );
21
+
22
+ export const dummyTokenAmount2 = new TokenAmount(
23
+ dummyToken,
24
+ '456.123',
25
+ false,
26
+ );
27
+
28
+ export const dummyTokenAmount3 = new TokenAmount(
29
+ dummyToken,
30
+ '1000.123',
31
+ false,
32
+ );
47
33
 
48
34
  export const dummyMarketAddress = '0xbeb5d47a3f720ec0a390d04b4d41ed7d9688bc7f'; // qiUSDC
49
35
 
package/src/helpers.ts CHANGED
@@ -1,3 +1,18 @@
1
+ import { BigNumber as BN, utils } from "ethers";
1
2
  export function formatObject(object: Object) {
2
3
  return JSON.stringify(object, null, ' ');
3
4
  }
5
+
6
+ export const decimalFactor = (decimal: number): string => {
7
+ return BN.from(10)
8
+ .pow(decimal)
9
+ .toString();
10
+ };
11
+
12
+ export function validateAndParseAddress(address: string): string {
13
+ try {
14
+ return utils.getAddress(address);
15
+ } catch (error) {
16
+ throw new Error("Invalid address " + address);
17
+ }
18
+ }
package/src/token.ts ADDED
@@ -0,0 +1,11 @@
1
+ export class Token {
2
+ public readonly address: string;
3
+ public readonly decimals: number;
4
+ public readonly expiry?: number;
5
+
6
+ public constructor(address: string, decimals: number, expiry?: number) {
7
+ this.address = address.toLowerCase();
8
+ this.decimals = decimals;
9
+ this.expiry = expiry;
10
+ }
11
+ }
@@ -0,0 +1,29 @@
1
+ import { Token } from "./token";
2
+ import BigNumber from 'bignumber.js';
3
+ import { decimalFactor } from "./helpers";
4
+
5
+ export class TokenAmount {
6
+ public readonly token: Token;
7
+ private rawAmnt: string;
8
+
9
+ public constructor(token: Token, amount: string, isRaw: boolean = true) {
10
+ if (isRaw) {
11
+ this.rawAmnt = amount;
12
+ } else {
13
+ this.rawAmnt = new BigNumber(amount)
14
+ .times(decimalFactor(token.decimals))
15
+ .toFixed(0);
16
+ }
17
+ this.token = token;
18
+ }
19
+
20
+ public formattedAmount(): string {
21
+ return new BigNumber(this.rawAmnt)
22
+ .div(decimalFactor(this.token.decimals))
23
+ .toString();
24
+ }
25
+
26
+ public rawAmount(): string {
27
+ return this.rawAmnt;
28
+ }
29
+ }
package/src/types.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { providers, Signer } from 'ethers';
2
- import { CurrencyAmount } from '@pendle/sdk-core';
2
+ import { TokenAmount } from './tokenAmount';
3
3
 
4
4
  export type ProviderOrSigner = providers.Provider | Signer;
5
5
 
6
6
  export type MoneyMarketDetails = {
7
7
  auTokenAddress: string;
8
- totalTokenDeposited: CurrencyAmount;
9
- totalTokenBorrowed: CurrencyAmount;
8
+ totalTokenDeposited: TokenAmount;
9
+ totalTokenBorrowed: TokenAmount;
10
10
  depositApy: number;
11
11
  depositPlyApy: number;
12
12
  borrowApy: number;
@@ -16,10 +16,10 @@ export type MoneyMarketDetails = {
16
16
 
17
17
  export type UserDetails = {
18
18
  markets: UserMarketDetails[];
19
- borrowLimit: CurrencyAmount;
20
- accruedPly: CurrencyAmount;
21
- lockedPly: CurrencyAmount;
22
- borrowableAmount: CurrencyAmount;
19
+ borrowLimit: TokenAmount;
20
+ accruedPly: TokenAmount;
21
+ lockedPly: TokenAmount;
22
+ borrowableAmount: TokenAmount;
23
23
  };
24
24
 
25
25
  export type LockingDetails = {
@@ -29,19 +29,19 @@ export type LockingDetails = {
29
29
  };
30
30
 
31
31
  export type PlyAuroraPool = {
32
- totalStakedLiquidity: CurrencyAmount;
32
+ totalStakedLiquidity: TokenAmount;
33
33
  apy: number;
34
34
  };
35
35
 
36
36
  export type UserMarketDetails = {
37
37
  market: string;
38
- depositBalance: CurrencyAmount;
39
- borrowBalance: CurrencyAmount;
38
+ depositBalance: TokenAmount;
39
+ borrowBalance: TokenAmount;
40
40
  isCollateral: boolean;
41
- maxWithdrawableAmount: CurrencyAmount;
41
+ maxWithdrawableAmount: TokenAmount;
42
42
  };
43
43
 
44
44
  export type PlyAuroraPoolDetails = {
45
- totalStakedLiquidity: CurrencyAmount;
45
+ totalStakedLiquidity: TokenAmount;
46
46
  apy: number;
47
47
  };