@aurigami/sdk 1.6.0 → 1.6.2
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/SDK.d.ts +9 -0
- package/dist/contracts/Multicall.d.ts +18 -0
- package/dist/contracts/Papermill.d.ts +8 -0
- package/dist/contracts/Referral.d.ts +44 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/sdk.cjs.development.js +449 -40
- 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 +447 -41
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/SDK.ts +66 -0
- package/src/consts/constants.ts +4 -0
- package/src/contracts/Multicall.ts +55 -0
- package/src/contracts/Papermill.ts +13 -0
- package/src/contracts/Referral.ts +98 -0
- package/src/contracts/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.6.
|
|
2
|
+
"version": "1.6.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"typescript": "^4.5.4"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@aurigami/contracts": "3.
|
|
63
|
+
"@aurigami/contracts": "3.5.0",
|
|
64
64
|
"axios": "^0.26.1",
|
|
65
65
|
"bignumber.js": "^9.0.2",
|
|
66
66
|
"dotenv": "^16.0.0",
|
package/src/SDK.ts
CHANGED
|
@@ -2,10 +2,12 @@ import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairL
|
|
|
2
2
|
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
3
3
|
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
4
4
|
import FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
|
|
5
|
+
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
5
6
|
import {
|
|
6
7
|
AuriFairLaunch,
|
|
7
8
|
AuriLens,
|
|
8
9
|
Comptroller,
|
|
10
|
+
IERC20,
|
|
9
11
|
} from '@aurigami/contracts/typechain';
|
|
10
12
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
11
13
|
import BigNumber from 'bignumber.js';
|
|
@@ -20,12 +22,14 @@ import {
|
|
|
20
22
|
import {
|
|
21
23
|
BlockchainEntity,
|
|
22
24
|
BlockchainEntityRead,
|
|
25
|
+
PLYToken,
|
|
23
26
|
Token,
|
|
24
27
|
TokenAmount,
|
|
25
28
|
} from './entities';
|
|
26
29
|
import { decimalFactor, isSameAddress } from './helpers/helpers';
|
|
27
30
|
import { calcValuation, fetchPrice } from './helpers/priceFetcher';
|
|
28
31
|
import * as types from './types';
|
|
32
|
+
import { MulticallRead } from './contracts/Multicall';
|
|
29
33
|
|
|
30
34
|
export class SdkRead extends BlockchainEntityRead {
|
|
31
35
|
protected _comptroller: Comptroller;
|
|
@@ -307,6 +311,68 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
307
311
|
: newBorrowValuation!.div(newBorrowLimit!).toNumber(),
|
|
308
312
|
};
|
|
309
313
|
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Get ply circulating supply.
|
|
317
|
+
* It is calculated by the total supply, minus:
|
|
318
|
+
* - Ply in team multisig contract
|
|
319
|
+
* - Ply in comptroller contract
|
|
320
|
+
* - Ply in fairlaunch contract
|
|
321
|
+
* - Ply in vesting contract
|
|
322
|
+
*/
|
|
323
|
+
public async getPlyCirculatingSupply(): Promise<TokenAmount> {
|
|
324
|
+
const plyContract: IERC20 = new Contract(
|
|
325
|
+
consts.networkAddresses.tokens.PLY,
|
|
326
|
+
EIP20InterfaceABI.abi,
|
|
327
|
+
this._networkConnection.provider
|
|
328
|
+
) as IERC20;
|
|
329
|
+
|
|
330
|
+
const multicallRead = new MulticallRead(this._networkConnection);
|
|
331
|
+
const baseBalanceOfCall = {
|
|
332
|
+
contract: plyContract,
|
|
333
|
+
method: 'balanceOf',
|
|
334
|
+
returnTypes: ['uint256'],
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const callResults = (await multicallRead.aggregate([
|
|
338
|
+
// Get total supply
|
|
339
|
+
{
|
|
340
|
+
...baseBalanceOfCall,
|
|
341
|
+
method: 'totalSupply',
|
|
342
|
+
args: [],
|
|
343
|
+
},
|
|
344
|
+
// balance in team multisig
|
|
345
|
+
{
|
|
346
|
+
...baseBalanceOfCall,
|
|
347
|
+
args: [consts.networkAddresses.misc.TEAM_MULTISIG],
|
|
348
|
+
},
|
|
349
|
+
// balance in comptroller
|
|
350
|
+
{
|
|
351
|
+
...baseBalanceOfCall,
|
|
352
|
+
args: [consts.networkAddresses.misc.COMPTROLLER],
|
|
353
|
+
},
|
|
354
|
+
// balance in fair launch
|
|
355
|
+
{
|
|
356
|
+
...baseBalanceOfCall,
|
|
357
|
+
args: [consts.networkAddresses.misc.AURIFAIRLAUNCH],
|
|
358
|
+
},
|
|
359
|
+
// balance in vesting contract
|
|
360
|
+
{
|
|
361
|
+
...baseBalanceOfCall,
|
|
362
|
+
args: [consts.networkAddresses.misc.PLY_TOKEN_LOCK],
|
|
363
|
+
},
|
|
364
|
+
])) as BN[][];
|
|
365
|
+
let circulatingSupply: BN = BN.from(0);
|
|
366
|
+
callResults.forEach((result, i) => {
|
|
367
|
+
if (i === 0) {
|
|
368
|
+
circulatingSupply = result[0];
|
|
369
|
+
} else {
|
|
370
|
+
circulatingSupply = circulatingSupply.sub(result[0]);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
return new TokenAmount(PLYToken, circulatingSupply.toString());
|
|
375
|
+
}
|
|
310
376
|
}
|
|
311
377
|
|
|
312
378
|
export class SdkReadWrite extends SdkRead {
|
package/src/consts/constants.ts
CHANGED
|
@@ -78,6 +78,10 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
78
78
|
AURILENS: MAINNET_ADDRESSES.auriLens.toLowerCase(),
|
|
79
79
|
ETHREPAYHELPER: MAINNET_ADDRESSES.ethRepayHelper.toLowerCase(),
|
|
80
80
|
AURI_AIRDROP: MAINNET_ADDRESSES.auriAirdrop.toLowerCase(),
|
|
81
|
+
MULTICALL: MAINNET_ADDRESSES.multicall.toLowerCase(),
|
|
82
|
+
TEAM_MULTISIG: '0x2D05FfFE70CE64c5954710D4C308dB31C8dBd8dE'.toLowerCase(),
|
|
83
|
+
PLY_TOKEN_LOCK: MAINNET_ADDRESSES.plyTokenLock.toLowerCase(),
|
|
84
|
+
REFERRAL: MAINNET_ADDRESSES.referralDirectory.toLocaleLowerCase(),
|
|
81
85
|
},
|
|
82
86
|
tokens: {
|
|
83
87
|
AURORA: '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase(),
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Multicall2ABI from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
|
|
2
|
+
import { Multicall2 } from '@aurigami/contracts/typechain';
|
|
3
|
+
import { Contract, ethers } from 'ethers';
|
|
4
|
+
import * as consts from '../consts';
|
|
5
|
+
import { BlockchainEntityRead } from '../entities';
|
|
6
|
+
import { NetworkConnection } from '../types';
|
|
7
|
+
import { Result } from 'ethers/lib/utils';
|
|
8
|
+
|
|
9
|
+
export class MulticallRead extends BlockchainEntityRead {
|
|
10
|
+
protected _multicall: Multicall2;
|
|
11
|
+
constructor(networkConnection: NetworkConnection) {
|
|
12
|
+
super(networkConnection);
|
|
13
|
+
this._multicall = new Contract(
|
|
14
|
+
consts.networkAddresses.misc.MULTICALL,
|
|
15
|
+
Multicall2ABI.abi,
|
|
16
|
+
networkConnection.provider
|
|
17
|
+
) as Multicall2;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Run multiple calls via multicall contract
|
|
22
|
+
*/
|
|
23
|
+
public async aggregate(
|
|
24
|
+
calls: {
|
|
25
|
+
contract: Contract;
|
|
26
|
+
method: string;
|
|
27
|
+
args: any[];
|
|
28
|
+
returnTypes: string[];
|
|
29
|
+
}[]
|
|
30
|
+
): Promise<Result[]> {
|
|
31
|
+
const txns = [];
|
|
32
|
+
// prepare transactions
|
|
33
|
+
for (let i = 0; i < calls.length; i++) {
|
|
34
|
+
const call = calls[i];
|
|
35
|
+
let txn = await call.contract.populateTransaction[call.method](
|
|
36
|
+
...call.args
|
|
37
|
+
);
|
|
38
|
+
txns.push({ target: txn.to!, callData: txn.data! });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const response = await this._multicall.callStatic.aggregate(txns);
|
|
42
|
+
|
|
43
|
+
// parse results
|
|
44
|
+
const decodedReturn = [];
|
|
45
|
+
for (let i = 0; i < calls.length; i++) {
|
|
46
|
+
decodedReturn.push(
|
|
47
|
+
ethers.utils.defaultAbiCoder.decode(
|
|
48
|
+
calls[i].returnTypes,
|
|
49
|
+
response.returnData[i]
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return decodedReturn;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -104,6 +104,7 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
104
104
|
.div(consts.ONE_WEEK)
|
|
105
105
|
.toNumber();
|
|
106
106
|
}
|
|
107
|
+
|
|
107
108
|
/**
|
|
108
109
|
* Get all locking details of the user in all markets + all staking pools
|
|
109
110
|
*/
|
|
@@ -197,6 +198,18 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
197
198
|
return consts.REWARD_CLAIM_START + consts.ONE_WEEK * weekId.toNumber();
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Get the start timestamp of next week of the papermill contract.
|
|
203
|
+
*
|
|
204
|
+
* This is a sync function!
|
|
205
|
+
*
|
|
206
|
+
* @returns the timestamp in seconds
|
|
207
|
+
*/
|
|
208
|
+
public getNextWeekTimestamp(): number {
|
|
209
|
+
const nextWeek = this.getWeek(helpers.getCurrentTimestamp()) + 1;
|
|
210
|
+
return consts.REWARD_CLAIM_START + consts.ONE_WEEK * nextWeek;
|
|
211
|
+
}
|
|
212
|
+
|
|
200
213
|
public async getUnlockPortionAt(
|
|
201
214
|
userAddress: Address,
|
|
202
215
|
timestamp: number
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import ReferralDirectoryABI from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
|
|
2
|
+
import { ReferralDirectory } from '@aurigami/contracts/typechain';
|
|
3
|
+
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
4
|
+
import { Contract, ethers } from 'ethers';
|
|
5
|
+
import * as consts from '../consts';
|
|
6
|
+
import { BlockchainEntity, BlockchainEntityRead } from '../entities';
|
|
7
|
+
import { Address, NetworkConnection } from '../types';
|
|
8
|
+
|
|
9
|
+
export class ReferralRead extends BlockchainEntityRead {
|
|
10
|
+
protected _referral: ReferralDirectory;
|
|
11
|
+
constructor(networkConnection: NetworkConnection) {
|
|
12
|
+
super(networkConnection);
|
|
13
|
+
this._referral = new Contract(
|
|
14
|
+
consts.networkAddresses.misc.REFERRAL,
|
|
15
|
+
ReferralDirectoryABI.abi,
|
|
16
|
+
networkConnection.provider
|
|
17
|
+
) as ReferralDirectory;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generate a 10-character referral code
|
|
22
|
+
* containing alphanumeric characters.
|
|
23
|
+
*/
|
|
24
|
+
protected generateReferralCode(): string {
|
|
25
|
+
let letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
26
|
+
let numbers = '1234567890';
|
|
27
|
+
let charset = letters + letters.toUpperCase() + numbers;
|
|
28
|
+
let R = '';
|
|
29
|
+
for (var i = 0; i < 10; i++)
|
|
30
|
+
R += charset[Math.floor(Math.random() * charset.length)];
|
|
31
|
+
return R;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the referral code for a given address, returns empty string if not found.
|
|
36
|
+
*
|
|
37
|
+
* Called to check if a user has a referral code.
|
|
38
|
+
*/
|
|
39
|
+
public async getUserReferralCode(userAddr: Address): Promise<string> {
|
|
40
|
+
const result = await this._referral.userReferralCode(userAddr);
|
|
41
|
+
return ethers.utils.parseBytes32String(result);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get referral code that a user was referred by, returns empty string if not found.
|
|
46
|
+
*/
|
|
47
|
+
public async getReferralCodeUsed(userAddr: Address): Promise<string> {
|
|
48
|
+
const result = await this._referral.referralCodeUsed(userAddr);
|
|
49
|
+
return ethers.utils.parseBytes32String(result);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get owner of a referral code, returns zero address if not found.
|
|
54
|
+
*/
|
|
55
|
+
public async getReferralCodeOwner(code: string): Promise<Address> {
|
|
56
|
+
const referralCode = ethers.utils.formatBytes32String(code);
|
|
57
|
+
return this._referral.referralCodeOwner(referralCode);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class ReferralReadWrite extends ReferralRead {
|
|
62
|
+
/**
|
|
63
|
+
* Generate a referral code for a given address.
|
|
64
|
+
*
|
|
65
|
+
* Called when an user want to creates his own referral code
|
|
66
|
+
*/
|
|
67
|
+
public async registerNewReferralCode(): Promise<TransactionResponse> {
|
|
68
|
+
const referralCode = ethers.utils.formatBytes32String(
|
|
69
|
+
this.generateReferralCode()
|
|
70
|
+
);
|
|
71
|
+
return this._referral
|
|
72
|
+
.connect(this._networkConnection.signer!)
|
|
73
|
+
.registerNewUserReferralCode(referralCode);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Called when an user confirms he is referred by a specified code
|
|
78
|
+
*/
|
|
79
|
+
public async useReferralCode(code: string): Promise<TransactionResponse> {
|
|
80
|
+
const referralCode = ethers.utils.formatBytes32String(code);
|
|
81
|
+
return this._referral
|
|
82
|
+
.connect(this._networkConnection.signer!)
|
|
83
|
+
.registerReferralCodeUsed(referralCode);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class Referral extends BlockchainEntity {
|
|
88
|
+
constructor() {
|
|
89
|
+
super();
|
|
90
|
+
}
|
|
91
|
+
public read(networkConnection: NetworkConnection): ReferralRead {
|
|
92
|
+
return new ReferralRead(networkConnection);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public readWrite(networkConnection: NetworkConnection): ReferralReadWrite {
|
|
96
|
+
return new ReferralReadWrite(networkConnection);
|
|
97
|
+
}
|
|
98
|
+
}
|