@aurigami/sdk 0.1.3 → 0.1.4
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.
- package/dist/MoneyMarket.d.ts +7 -7
- package/dist/SDK.d.ts +6 -5
- package/dist/constants.d.ts +1 -1
- package/dist/dummy.d.ts +6 -5
- package/dist/helpers.d.ts +2 -0
- package/dist/sdk.cjs.development.js +68 -79
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +65 -80
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +6 -0
- package/dist/tokenAmount.d.ts +8 -0
- package/package.json +2 -2
- package/src/MoneyMarket.ts +8 -11
- package/src/SDK.ts +36 -35
- package/src/constants.ts +4 -7
- package/src/dummy.ts +30 -44
- package/src/helpers.ts +15 -0
- package/src/token.ts +11 -0
- package/src/tokenAmount.ts +29 -0
package/src/MoneyMarket.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
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
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';
|
|
13
10
|
|
|
14
11
|
export class MoneyMarketRead extends BlockchainEntityRead {
|
|
15
12
|
protected _auToken: Contract;
|
|
16
|
-
constructor(providerOrSigner: ProviderOrSigner, auToken:
|
|
13
|
+
constructor(providerOrSigner: ProviderOrSigner, auToken: string) {
|
|
17
14
|
super(providerOrSigner);
|
|
18
15
|
this._auToken = new Contract(auToken, AuToken.abi, providerOrSigner);
|
|
19
16
|
}
|
|
@@ -40,16 +37,16 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
|
40
37
|
);
|
|
41
38
|
return await dummyErc20Token.approve(dummyToken.address, 123);
|
|
42
39
|
};
|
|
43
|
-
public async deposit(amount:
|
|
40
|
+
public async deposit(amount: TokenAmount): Promise<TransactionResponse> {
|
|
44
41
|
return this.dummyTransaction();
|
|
45
42
|
}
|
|
46
|
-
public async borrow(amount:
|
|
43
|
+
public async borrow(amount: TokenAmount): Promise<TransactionResponse> {
|
|
47
44
|
return this.dummyTransaction();
|
|
48
45
|
}
|
|
49
|
-
public async withdraw(amount:
|
|
46
|
+
public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
|
|
50
47
|
return this.dummyTransaction();
|
|
51
48
|
}
|
|
52
|
-
public async repay(amount:
|
|
49
|
+
public async repay(amount: TokenAmount): Promise<TransactionResponse> {
|
|
53
50
|
return this.dummyTransaction();
|
|
54
51
|
}
|
|
55
52
|
public async enableCollateral(): Promise<TransactionResponse> {
|
|
@@ -61,7 +58,7 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
export class MoneyMarket extends BlockchainEntity {
|
|
64
|
-
protected address:
|
|
61
|
+
protected address: string;
|
|
65
62
|
constructor(address: string) {
|
|
66
63
|
super();
|
|
67
64
|
this.address = validateAndParseAddress(address);
|
package/src/SDK.ts
CHANGED
|
@@ -13,11 +13,12 @@ import {
|
|
|
13
13
|
ProviderOrSigner,
|
|
14
14
|
UserDetails,
|
|
15
15
|
} from './types';
|
|
16
|
-
import { Token, CurrencyAmount } from '@pendle/sdk-core';
|
|
17
16
|
import { AVAX_DEFAULT_PROVIDER_URL, DOLLAR } from './constants';
|
|
18
17
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
19
18
|
import IERC20 from './abis/IERC20.json';
|
|
20
19
|
import { Contract } from 'ethers';
|
|
20
|
+
import { TokenAmount } from './tokenAmount';
|
|
21
|
+
import { Token } from './token';
|
|
21
22
|
const ethers = require('ethers');
|
|
22
23
|
|
|
23
24
|
export class SdkRead extends BlockchainEntityRead {
|
|
@@ -37,52 +38,52 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
37
38
|
return {
|
|
38
39
|
markets: [dummyUserMarketDetails],
|
|
39
40
|
borrowLimit: dummyTokenAmount3,
|
|
40
|
-
accruedPly: new
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
lockedPly: new
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
accruedPly: new TokenAmount(
|
|
42
|
+
dummyPly,
|
|
43
|
+
'100.12',
|
|
44
|
+
false,
|
|
45
|
+
),
|
|
46
|
+
lockedPly: new TokenAmount(
|
|
47
|
+
dummyPly,
|
|
48
|
+
'200.12',
|
|
49
|
+
false,
|
|
50
|
+
),
|
|
50
51
|
borrowableAmount: dummyTokenAmount2,
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
public async getPlyAuroraPoolDetails(): Promise<PlyAuroraPoolDetails> {
|
|
55
56
|
return {
|
|
56
|
-
totalStakedLiquidity: new
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
totalStakedLiquidity: new TokenAmount(
|
|
58
|
+
dummyPlyAurora,
|
|
59
|
+
'12.1',
|
|
60
|
+
false,
|
|
61
|
+
),
|
|
61
62
|
apy: 1.21,
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
public async getTokenPrice(token: Token): Promise<
|
|
66
|
+
public async getTokenPrice(token: Token): Promise<TokenAmount> {
|
|
66
67
|
if (token.address == dummyToken.address) {
|
|
67
|
-
return new
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
return new TokenAmount(
|
|
69
|
+
DOLLAR,
|
|
70
|
+
'1',
|
|
71
|
+
false,
|
|
72
|
+
);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
return new
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
return new TokenAmount(
|
|
76
|
+
DOLLAR,
|
|
77
|
+
'12.1',
|
|
78
|
+
false,
|
|
79
|
+
);
|
|
79
80
|
}
|
|
80
|
-
public async stakeBalanceOf(user: string): Promise<
|
|
81
|
-
return new
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
public async stakeBalanceOf(user: string): Promise<TokenAmount> {
|
|
82
|
+
return new TokenAmount(
|
|
83
|
+
dummyPlyAurora,
|
|
84
|
+
'103.4',
|
|
85
|
+
false,
|
|
86
|
+
);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
@@ -98,10 +99,10 @@ export class SdkReadWrite extends SdkRead {
|
|
|
98
99
|
public async claim(): Promise<TransactionResponse> {
|
|
99
100
|
return this.dummyTransaction();
|
|
100
101
|
}
|
|
101
|
-
public async stake(amount:
|
|
102
|
+
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
102
103
|
return this.dummyTransaction();
|
|
103
104
|
}
|
|
104
|
-
public async unstake(amount:
|
|
105
|
+
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
105
106
|
return this.dummyTransaction();
|
|
106
107
|
}
|
|
107
108
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { Token } from '
|
|
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
|
-
|
|
7
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 ".";
|
|
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
|
+
}
|