-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hicommonwealth/snap.aave
Snap.aave
- Loading branch information
Showing
142 changed files
with
5,897 additions
and
1,140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,7 @@ yarn-error.log | |
coverage/ | ||
*.sw* | ||
.env | ||
.yalc | ||
yalc.lock | ||
*yalc* | ||
|
||
# Database downloads | ||
latest.dump | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
client/scripts/controllers/chain/ethereum/snapshot/adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { EthereumCoin } from 'adapters/chain/ethereum/types'; | ||
|
||
import { ERC20__factory } from 'eth/types'; | ||
import EthereumAccount from 'controllers/chain/ethereum/account'; | ||
import EthereumAccounts from 'controllers/chain/ethereum/accounts'; | ||
import { ChainBase, IChainAdapter, NodeInfo } from 'models'; | ||
|
||
import ChainEntityController from 'controllers/server/chain_entities'; | ||
import { IApp } from 'state'; | ||
|
||
import SnapshotTokenChain from './chain'; | ||
import SnapshotApi from './api'; | ||
|
||
export default class Snapshot extends IChainAdapter<EthereumCoin, EthereumAccount> { | ||
public readonly base = ChainBase.Ethereum; | ||
// TODO: ensure this chainnetwork -> chainclass | ||
public readonly class; | ||
public readonly contractAddress: string; | ||
public readonly isToken = true; | ||
|
||
public chain: SnapshotTokenChain; | ||
public accounts: EthereumAccounts; | ||
public hasToken: boolean = false; | ||
|
||
constructor(meta: NodeInfo, app: IApp) { | ||
super(meta, app); | ||
this.chain = new SnapshotTokenChain(this.app); | ||
this.accounts = new EthereumAccounts(this.app); | ||
this.class = meta.chain.network; | ||
this.contractAddress = meta.address; | ||
} | ||
|
||
public async initApi() { | ||
await this.chain.resetApi(this.meta); | ||
await this.chain.initMetadata(); | ||
await this.accounts.init(this.chain); | ||
const api = new SnapshotApi(ERC20__factory.connect, this.meta.address, this.chain.api.currentProvider as any); | ||
await api.init(); | ||
this.chain.contractApi = api; | ||
await super.initApi(); | ||
} | ||
|
||
public async initData() { | ||
await this.chain.initEventLoop(); | ||
await super.initData(); | ||
await this.activeAddressHasToken(this.app.user?.activeAccount?.address); | ||
} | ||
|
||
public async deinit() { | ||
await super.deinit(); | ||
this.accounts.deinit(); | ||
this.chain.deinitMetadata(); | ||
this.chain.deinitEventLoop(); | ||
this.chain.deinitApi(); | ||
} | ||
|
||
public async activeAddressHasToken(activeAddress?: string) { | ||
if (!activeAddress) return false; | ||
const account = this.accounts.get(activeAddress); | ||
const balance = await account.tokenBalance(this.contractAddress); | ||
this.hasToken = balance && !balance.isZero(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ERC20 } from 'eth/types'; | ||
|
||
import ContractApi from 'controllers/chain/ethereum/contractApi'; | ||
|
||
export default class SnapshotApi extends ContractApi<ERC20> { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import EthereumChain from '../chain'; | ||
import ContractApi from './api'; | ||
|
||
// Thin wrapper over EthereumChain to guarantee the `init()` implementation | ||
// on the Governance module works as expected. | ||
export default class SnapshotTokenChain extends EthereumChain { | ||
public contractApi: ContractApi; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.