@aurigami/sdk 1.2.6 → 1.3.1
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/README.md +0 -2
- package/dist/airdrop-lottery.d.ts +14 -0
- package/dist/constants.d.ts +3 -0
- package/dist/helpers.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/sdk.cjs.development.js +90414 -9
- 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 +90407 -10
- package/dist/sdk.esm.js.map +1 -1
- package/dist/transfer-event-query.d.ts +17 -0
- package/package.json +1 -1
- package/src/MoneyMarket.ts +2 -2
- package/src/airdrop-lottery.ts +229 -0
- package/src/airdrop_misc/auTokensInfo.json +34 -0
- package/src/airdrop_misc/whitelist.example.txt +4 -0
- package/src/airdrop_misc/whitelist.json +89828 -0
- package/src/constants.ts +6 -1
- package/src/helpers.ts +54 -1
- package/src/index.ts +2 -0
- package/src/priceFetcher.ts +1 -1
- package/src/transfer-event-query.ts +60 -0
package/src/constants.ts
CHANGED
|
@@ -91,4 +91,9 @@ export const ONE_DAY = 86400;
|
|
|
91
91
|
export const ONE_YEAR = ONE_DAY * 365;
|
|
92
92
|
|
|
93
93
|
export const AurPlyPid = 0;
|
|
94
|
-
export const INF = BN.from(2).pow(256).sub(1)
|
|
94
|
+
export const INF = BN.from(2).pow(256).sub(1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
export const AIRDROP_START_TIMESTAMP = 1649858400;
|
|
98
|
+
export const AIRDROP_END_TIMESTAMP = 1651068000;
|
|
99
|
+
export const AIRDROP_KEEP_THRESHOLD = 7 * 86400;
|
package/src/helpers.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Provider } from "@ethersproject/abstract-provider";
|
|
1
2
|
import BigNumber from "bignumber.js";
|
|
2
3
|
import { BigNumber as BN, providers, utils } from "ethers";
|
|
3
4
|
import { decimalRecords } from "./decimals";
|
|
4
|
-
import { Address } from "./types";
|
|
5
|
+
import { Address, NetworkConnection } from "./types";
|
|
5
6
|
|
|
6
7
|
export function formatObject(object: Object) {
|
|
7
8
|
return JSON.stringify(object, null, ' ');
|
|
@@ -36,3 +37,55 @@ export function calcLMRewardApr(rewardsValue: BigNumber, totalStakeValue: BigNum
|
|
|
36
37
|
}
|
|
37
38
|
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
export async function getBlockTimestamp(provider: Provider, blockNumber: number): Promise<number> {
|
|
42
|
+
const block = await provider.getBlock(blockNumber);
|
|
43
|
+
return block.timestamp;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the block number of the last block that has a timestamp before the given timestamp
|
|
48
|
+
*
|
|
49
|
+
* Note: For optimized reason, this function is not guaranteed to return the correct block number,
|
|
50
|
+
* it may differ from the actual block number at most 500 blocks.
|
|
51
|
+
*/
|
|
52
|
+
export async function getBlockBeforeTimestamp(provider: Provider, timestamp: number, startBlock?: number): Promise<number> {
|
|
53
|
+
// stop searching if the right - left < blockThreshold
|
|
54
|
+
const blockThreshold = 50 * 10; //50 is the average block in 1 minutes.
|
|
55
|
+
// Using K-search + promise all to speed up the search
|
|
56
|
+
const K = 8;
|
|
57
|
+
|
|
58
|
+
let leftBlock: number = (startBlock || 1);
|
|
59
|
+
let rightBlock = await provider.getBlockNumber();
|
|
60
|
+
|
|
61
|
+
if ((await getBlockTimestamp(provider, rightBlock)) < timestamp) {
|
|
62
|
+
return rightBlock;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
while (rightBlock - leftBlock >= blockThreshold) {
|
|
66
|
+
let size = Math.floor((rightBlock - leftBlock + 1) / K);
|
|
67
|
+
let promises = [];
|
|
68
|
+
|
|
69
|
+
for (let i = 1; i < K; i++) {
|
|
70
|
+
promises.push(getBlockTimestamp(provider, leftBlock + i * size));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let blockTimestamps = await Promise.all(promises);
|
|
74
|
+
let nextLeftBlock = leftBlock;
|
|
75
|
+
|
|
76
|
+
for (let i = 1; i < K; i++) {
|
|
77
|
+
if (blockTimestamps[i - 1] <= timestamp) {
|
|
78
|
+
nextLeftBlock = leftBlock + i * size;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (let i = K - 1; i >= 1; i--) {
|
|
83
|
+
if (blockTimestamps[i - 1] > timestamp) {
|
|
84
|
+
rightBlock = leftBlock + i * size - 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
leftBlock = nextLeftBlock;
|
|
89
|
+
}
|
|
90
|
+
return leftBlock;
|
|
91
|
+
}
|
package/src/index.ts
CHANGED
package/src/priceFetcher.ts
CHANGED
|
@@ -116,7 +116,7 @@ function shouldFetchFromCoingecko(address: string) {
|
|
|
116
116
|
export async function fetchPrice(address: Address, provider: providers.Provider): Promise<BigNumber> {
|
|
117
117
|
if (hardcodePLYPrice && isSameAddress(address, networkAddresses.tokens.PLY)) return new BigNumber(0);
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
if (isSameAddress(address, networkAddresses.tokens.stNEAR)) return fetchStNEARPrice();
|
|
120
120
|
if (shouldFetchFromCoingecko(address)) return fetchPriceFromCoingecko(address);
|
|
121
121
|
|
|
122
122
|
const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BlockchainEntityRead } from "./BlockchainEntity";
|
|
2
|
+
import { NetworkConnection } from "./types";
|
|
3
|
+
import { AuToken } from "@aurigami/contracts/typechain";
|
|
4
|
+
import AuTokenABI from '@aurigami/contracts/artifacts/contracts/AuToken.sol/AuToken.json';
|
|
5
|
+
import { BigNumber as BN, Contract } from "ethers";
|
|
6
|
+
|
|
7
|
+
type SimpleTransfer = {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
amount: BN;
|
|
11
|
+
blockNumber: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export class TransferEventQuery extends BlockchainEntityRead {
|
|
16
|
+
auToken: AuToken;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
tokenAddr: string,
|
|
20
|
+
networkConnection: NetworkConnection
|
|
21
|
+
) {
|
|
22
|
+
super(networkConnection);
|
|
23
|
+
this.auToken = new Contract(tokenAddr, AuTokenABI.abi, this._networkConnection.provider) as AuToken;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* query ERC20 transfers from/to an address & auto convert them into SimpleTransfer.
|
|
28
|
+
* The result will be sorted by blocknumber.
|
|
29
|
+
*/
|
|
30
|
+
async queryERC20TransfersOf(address: string, fromBlock: number, toBlock: number): Promise<SimpleTransfer[]> {
|
|
31
|
+
const filters = [
|
|
32
|
+
this.auToken.filters.Transfer(address, null),
|
|
33
|
+
this.auToken.filters.Transfer(null, address)
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
const events = (await Promise.all(filters.map(filter => this.auToken.queryFilter(filter, fromBlock, toBlock)))).flat();
|
|
37
|
+
|
|
38
|
+
let results: SimpleTransfer[] = events.map((event) => {
|
|
39
|
+
return {
|
|
40
|
+
from: event.args![0],
|
|
41
|
+
to: event.args![1],
|
|
42
|
+
amount: event.args![2],
|
|
43
|
+
blockNumber: event.blockNumber,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
results.sort((a, b) => a.blockNumber - b.blockNumber);
|
|
48
|
+
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the balance of an address at a given block number.
|
|
54
|
+
*
|
|
55
|
+
* Note that this will return the balance after the block get mined.
|
|
56
|
+
*/
|
|
57
|
+
async queryERC20BalanceAt(address: string, endBlock: number): Promise<BN> {
|
|
58
|
+
return this.auToken.balanceOf(address, {blockTag: endBlock + 1});
|
|
59
|
+
}
|
|
60
|
+
}
|